2007-03-27 16:17:11 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-27 16:17:11 +04:00
|
|
|
|
2008-10-16 05:52:58 +04:00
|
|
|
#include "nsCoreUtils.h"
|
2007-07-05 20:02:55 +04:00
|
|
|
|
2007-08-24 08:54:45 +04:00
|
|
|
#include "nsIAccessibleTypes.h"
|
2007-07-05 20:02:55 +04:00
|
|
|
|
2012-10-19 19:10:28 +04:00
|
|
|
#include "nsIBaseWindow.h"
|
|
|
|
#include "nsIDocShellTreeOwner.h"
|
2007-09-05 11:39:09 +04:00
|
|
|
#include "nsIDocument.h"
|
2008-10-08 16:50:36 +04:00
|
|
|
#include "nsIDOMHTMLDocument.h"
|
|
|
|
#include "nsIDOMHTMLElement.h"
|
2012-01-10 18:19:54 +04:00
|
|
|
#include "nsRange.h"
|
2013-09-11 02:18:59 +04:00
|
|
|
#include "nsIBoxObject.h"
|
2017-02-02 18:32:58 +03:00
|
|
|
#include "nsXULElement.h"
|
|
|
|
#include "mozilla/dom/BoxObject.h"
|
2008-10-17 14:10:43 +04:00
|
|
|
#include "nsIDocShell.h"
|
2016-01-21 04:52:43 +03:00
|
|
|
#include "nsIObserverService.h"
|
2007-08-29 10:52:46 +04:00
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsPresContext.h"
|
2007-09-25 09:48:51 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
2011-08-08 00:17:00 +04:00
|
|
|
#include "nsISelectionPrivate.h"
|
2007-08-24 08:54:45 +04:00
|
|
|
#include "nsISelectionController.h"
|
2016-01-21 04:52:43 +03:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2014-02-28 18:58:42 +04:00
|
|
|
#include "mozilla/dom/TouchEvent.h"
|
2017-02-02 18:32:58 +03:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2014-03-17 10:56:53 +04:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2014-04-01 08:09:23 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2013-09-25 15:21:18 +04:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-09-25 15:21:16 +04:00
|
|
|
#include "mozilla/TouchEvents.h"
|
2013-01-03 17:23:11 +04:00
|
|
|
#include "nsView.h"
|
2012-10-29 08:33:51 +04:00
|
|
|
#include "nsGkAtoms.h"
|
2007-08-24 08:54:45 +04:00
|
|
|
|
|
|
|
#include "nsComponentManagerUtils.h"
|
|
|
|
|
2012-08-01 22:31:10 +04:00
|
|
|
#include "nsITreeBoxObject.h"
|
|
|
|
#include "nsITreeColumns.h"
|
2014-01-21 01:52:04 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2016-01-14 23:37:15 +03:00
|
|
|
#include "mozilla/dom/HTMLLabelElement.h"
|
2012-08-01 22:31:10 +04:00
|
|
|
|
2013-08-02 11:05:16 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2010-04-27 10:52:03 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsCoreUtils
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2016-01-14 23:37:15 +03:00
|
|
|
bool
|
|
|
|
nsCoreUtils::IsLabelWithControl(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
dom::HTMLLabelElement* label = dom::HTMLLabelElement::FromContent(aContent);
|
|
|
|
if (label && label->GetControl())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-02-03 18:00:25 +03:00
|
|
|
nsCoreUtils::HasClickListener(nsIContent *aContent)
|
2007-05-09 01:44:04 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(aContent, false);
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager* listenerManager =
|
2013-10-23 03:32:04 +04:00
|
|
|
aContent->GetExistingListenerManager();
|
2007-05-09 01:44:04 +04:00
|
|
|
|
2010-02-03 18:00:25 +03:00
|
|
|
return listenerManager &&
|
2012-10-29 08:33:51 +04:00
|
|
|
(listenerManager->HasListenersFor(nsGkAtoms::onclick) ||
|
|
|
|
listenerManager->HasListenersFor(nsGkAtoms::onmousedown) ||
|
|
|
|
listenerManager->HasListenersFor(nsGkAtoms::onmouseup));
|
2007-05-09 01:44:04 +04:00
|
|
|
}
|
|
|
|
|
2009-08-20 10:45:19 +04:00
|
|
|
void
|
|
|
|
nsCoreUtils::DispatchClickEvent(nsITreeBoxObject *aTreeBoxObj,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aRowIndex, nsITreeColumn *aColumn,
|
2014-10-15 00:15:21 +04:00
|
|
|
const nsAString& aPseudoElt)
|
2009-08-20 10:45:19 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> tcElm;
|
|
|
|
aTreeBoxObj->GetTreeBody(getter_AddRefs(tcElm));
|
|
|
|
if (!tcElm)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> tcContent(do_QueryInterface(tcElm));
|
2016-03-31 14:46:32 +03:00
|
|
|
nsIDocument *document = tcContent->GetUncomposedDoc();
|
2009-08-20 10:45:19 +04:00
|
|
|
if (!document)
|
|
|
|
return;
|
|
|
|
|
2013-08-05 08:00:08 +04:00
|
|
|
nsCOMPtr<nsIPresShell> presShell = document->GetShell();
|
2009-08-20 10:45:19 +04:00
|
|
|
if (!presShell)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Ensure row is visible.
|
|
|
|
aTreeBoxObj->EnsureRowIsVisible(aRowIndex);
|
|
|
|
|
|
|
|
// Calculate x and y coordinates.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t x = 0, y = 0, width = 0, height = 0;
|
2009-08-20 10:45:19 +04:00
|
|
|
nsresult rv = aTreeBoxObj->GetCoordsForCellItem(aRowIndex, aColumn,
|
|
|
|
aPseudoElt,
|
|
|
|
&x, &y, &width, &height);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return;
|
|
|
|
|
2017-02-02 18:32:58 +03:00
|
|
|
nsCOMPtr<nsIContent> tcXULElm(do_QueryInterface(tcElm));
|
|
|
|
IgnoredErrorResult ignored;
|
|
|
|
nsCOMPtr<nsIBoxObject> tcBoxObj =
|
|
|
|
nsXULElement::FromContent(tcXULElm)->GetBoxObject(ignored);
|
2009-08-20 10:45:19 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t tcX = 0;
|
2009-08-20 10:45:19 +04:00
|
|
|
tcBoxObj->GetX(&tcX);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t tcY = 0;
|
2009-08-20 10:45:19 +04:00
|
|
|
tcBoxObj->GetY(&tcY);
|
|
|
|
|
|
|
|
// Dispatch mouse events.
|
2017-03-01 20:03:14 +03:00
|
|
|
AutoWeakFrame tcFrame = tcContent->GetPrimaryFrame();
|
2009-08-20 10:45:19 +04:00
|
|
|
nsIFrame* rootFrame = presShell->GetRootFrame();
|
|
|
|
|
|
|
|
nsPoint offset;
|
|
|
|
nsIWidget *rootWidget =
|
2016-04-16 02:37:35 +03:00
|
|
|
rootFrame->GetView()->GetNearestWidget(&offset);
|
2009-08-20 10:45:19 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPresContext> presContext = presShell->GetPresContext();
|
2009-08-20 10:45:19 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t cnvdX = presContext->CSSPixelsToDevPixels(tcX + x + 1) +
|
2009-08-20 10:45:19 +04:00
|
|
|
presContext->AppUnitsToDevPixels(offset.x);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t cnvdY = presContext->CSSPixelsToDevPixels(tcY + y + 1) +
|
2009-08-20 10:45:19 +04:00
|
|
|
presContext->AppUnitsToDevPixels(offset.y);
|
|
|
|
|
2013-07-25 19:59:08 +04:00
|
|
|
// XUL is just desktop, so there is no real reason for senfing touch events.
|
2015-08-29 02:58:30 +03:00
|
|
|
DispatchMouseEvent(eMouseDown, cnvdX, cnvdY,
|
2009-08-20 10:45:19 +04:00
|
|
|
tcContent, tcFrame, presShell, rootWidget);
|
|
|
|
|
2015-08-29 02:58:30 +03:00
|
|
|
DispatchMouseEvent(eMouseUp, cnvdX, cnvdY,
|
2009-08-20 10:45:19 +04:00
|
|
|
tcContent, tcFrame, presShell, rootWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-08-26 15:56:59 +03:00
|
|
|
nsCoreUtils::DispatchMouseEvent(EventMessage aMessage, int32_t aX, int32_t aY,
|
2009-08-20 10:45:19 +04:00
|
|
|
nsIContent *aContent, nsIFrame *aFrame,
|
|
|
|
nsIPresShell *aPresShell, nsIWidget *aRootWidget)
|
|
|
|
{
|
2015-08-26 15:56:59 +03:00
|
|
|
WidgetMouseEvent event(true, aMessage, aRootWidget,
|
2013-10-02 10:38:27 +04:00
|
|
|
WidgetMouseEvent::eReal, WidgetMouseEvent::eNormal);
|
2008-08-06 16:16:54 +04:00
|
|
|
|
2016-04-18 17:09:02 +03:00
|
|
|
event.mRefPoint = LayoutDeviceIntPoint(aX, aY);
|
2009-08-20 10:45:19 +04:00
|
|
|
|
2016-05-10 17:29:14 +03:00
|
|
|
event.mClickCount = 1;
|
2013-10-02 10:38:27 +04:00
|
|
|
event.button = WidgetMouseEvent::eLeftButton;
|
2016-03-28 07:29:42 +03:00
|
|
|
event.mTime = PR_IntervalNow();
|
2013-04-25 20:16:10 +04:00
|
|
|
event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
|
2008-08-06 16:16:54 +04:00
|
|
|
|
2009-08-20 10:45:19 +04:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
aPresShell->HandleEventWithTarget(&event, aFrame, aContent, &status);
|
2008-08-06 16:16:54 +04:00
|
|
|
}
|
|
|
|
|
2013-07-25 19:59:08 +04:00
|
|
|
void
|
2015-08-26 15:56:59 +03:00
|
|
|
nsCoreUtils::DispatchTouchEvent(EventMessage aMessage, int32_t aX, int32_t aY,
|
2013-07-25 19:59:08 +04:00
|
|
|
nsIContent* aContent, nsIFrame* aFrame,
|
|
|
|
nsIPresShell* aPresShell, nsIWidget* aRootWidget)
|
|
|
|
{
|
2016-07-18 17:26:38 +03:00
|
|
|
nsIDocShell* docShell = nullptr;
|
|
|
|
if (aPresShell->GetDocument()) {
|
|
|
|
docShell = aPresShell->GetDocument()->GetDocShell();
|
|
|
|
}
|
|
|
|
if (!dom::TouchEvent::PrefEnabled(docShell)) {
|
2013-07-25 19:59:08 +04:00
|
|
|
return;
|
2016-07-18 17:26:38 +03:00
|
|
|
}
|
2013-07-25 19:59:08 +04:00
|
|
|
|
2015-08-26 15:56:59 +03:00
|
|
|
WidgetTouchEvent event(true, aMessage, aRootWidget);
|
2013-07-25 19:59:08 +04:00
|
|
|
|
2016-03-28 07:29:42 +03:00
|
|
|
event.mTime = PR_IntervalNow();
|
2013-07-25 19:59:08 +04:00
|
|
|
|
|
|
|
// XXX: Touch has an identifier of -1 to hint that it is synthesized.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<dom::Touch> t = new dom::Touch(-1, LayoutDeviceIntPoint(aX, aY),
|
2015-11-10 08:37:31 +03:00
|
|
|
LayoutDeviceIntPoint(1, 1), 0.0f, 1.0f);
|
2013-07-25 19:59:08 +04:00
|
|
|
t->SetTarget(aContent);
|
2016-03-30 12:44:28 +03:00
|
|
|
event.mTouches.AppendElement(t);
|
2013-07-25 19:59:08 +04:00
|
|
|
nsEventStatus status = nsEventStatus_eIgnore;
|
|
|
|
aPresShell->HandleEventWithTarget(&event, aFrame, aContent, &status);
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2012-10-13 10:34:21 +04:00
|
|
|
nsCoreUtils::GetAccessKeyFor(nsIContent* aContent)
|
2007-08-29 10:52:46 +04:00
|
|
|
{
|
|
|
|
// Accesskeys are registered by @accesskey attribute only. At first check
|
|
|
|
// whether it is presented on the given element to avoid the slow
|
2014-04-01 08:09:23 +04:00
|
|
|
// EventStateManager::GetRegisteredAccessKey() method.
|
2011-06-04 01:35:17 +04:00
|
|
|
if (!aContent->HasAttr(kNameSpaceID_None, nsGkAtoms::accesskey))
|
2007-08-29 10:52:46 +04:00
|
|
|
return 0;
|
|
|
|
|
2012-04-05 07:11:39 +04:00
|
|
|
nsIPresShell* presShell = aContent->OwnerDoc()->GetShell();
|
2007-08-29 10:52:46 +04:00
|
|
|
if (!presShell)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nsPresContext *presContext = presShell->GetPresContext();
|
|
|
|
if (!presContext)
|
|
|
|
return 0;
|
|
|
|
|
2014-04-01 08:09:23 +04:00
|
|
|
EventStateManager *esm = presContext->EventStateManager();
|
2007-08-29 10:52:46 +04:00
|
|
|
if (!esm)
|
|
|
|
return 0;
|
|
|
|
|
2011-04-21 21:35:52 +04:00
|
|
|
return esm->GetRegisteredAccessKey(aContent);
|
2007-08-29 10:52:46 +04:00
|
|
|
}
|
|
|
|
|
2010-06-11 12:23:18 +04:00
|
|
|
nsIContent *
|
|
|
|
nsCoreUtils::GetDOMElementFor(nsIContent *aContent)
|
2008-07-17 16:06:24 +04:00
|
|
|
{
|
2010-06-11 12:23:18 +04:00
|
|
|
if (aContent->IsElement())
|
|
|
|
return aContent;
|
2008-10-08 16:50:36 +04:00
|
|
|
|
2010-06-11 12:23:18 +04:00
|
|
|
if (aContent->IsNodeOfType(nsINode::eTEXT))
|
2013-05-02 02:50:08 +04:00
|
|
|
return aContent->GetFlattenedTreeParent();
|
2008-10-08 16:50:36 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-07-17 16:06:24 +04:00
|
|
|
}
|
|
|
|
|
2010-05-25 12:12:43 +04:00
|
|
|
nsINode *
|
2012-08-22 19:56:38 +04:00
|
|
|
nsCoreUtils::GetDOMNodeFromDOMPoint(nsINode *aNode, uint32_t aOffset)
|
2008-12-16 13:14:20 +03:00
|
|
|
{
|
2010-05-25 12:12:43 +04:00
|
|
|
if (aNode && aNode->IsElement()) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t childCount = aNode->GetChildCount();
|
2012-07-22 14:35:49 +04:00
|
|
|
NS_ASSERTION(aOffset <= childCount, "Wrong offset of the DOM point!");
|
2008-12-16 13:14:20 +03:00
|
|
|
|
|
|
|
// The offset can be after last child of container node that means DOM point
|
|
|
|
// is placed immediately after the last child. In this case use the DOM node
|
|
|
|
// from the given DOM point is used as result node.
|
2010-05-25 12:12:43 +04:00
|
|
|
if (aOffset != childCount)
|
|
|
|
return aNode->GetChildAt(aOffset);
|
2008-12-16 13:14:20 +03:00
|
|
|
}
|
|
|
|
|
2010-05-25 12:12:43 +04:00
|
|
|
return aNode;
|
2008-12-16 13:14:20 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-01-27 14:43:25 +03:00
|
|
|
nsCoreUtils::IsAncestorOf(nsINode *aPossibleAncestorNode,
|
2010-06-10 07:29:56 +04:00
|
|
|
nsINode *aPossibleDescendantNode,
|
|
|
|
nsINode *aRootNode)
|
2007-08-14 22:47:49 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_TRUE(aPossibleAncestorNode && aPossibleDescendantNode, false);
|
2007-08-14 22:47:49 +04:00
|
|
|
|
2010-01-27 14:43:25 +03:00
|
|
|
nsINode *parentNode = aPossibleDescendantNode;
|
2012-10-09 16:31:24 +04:00
|
|
|
while ((parentNode = parentNode->GetParentNode()) &&
|
2010-06-11 12:23:04 +04:00
|
|
|
parentNode != aRootNode) {
|
2010-01-27 14:43:25 +03:00
|
|
|
if (parentNode == aPossibleAncestorNode)
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-08-14 22:47:49 +04:00
|
|
|
}
|
2010-01-27 14:43:25 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-08-14 22:47:49 +04:00
|
|
|
}
|
|
|
|
|
2007-08-24 08:54:45 +04:00
|
|
|
nsresult
|
2012-04-06 22:08:24 +04:00
|
|
|
nsCoreUtils::ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aScrollType)
|
2007-09-25 09:48:51 +04:00
|
|
|
{
|
2012-03-20 06:09:50 +04:00
|
|
|
nsIPresShell::ScrollAxis vertical, horizontal;
|
|
|
|
ConvertScrollTypeToPercents(aScrollType, &vertical, &horizontal);
|
2007-09-25 09:48:51 +04:00
|
|
|
|
2012-04-06 22:08:24 +04:00
|
|
|
return ScrollSubstringTo(aFrame, aRange, vertical, horizontal);
|
2007-09-25 09:48:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-04-06 22:08:24 +04:00
|
|
|
nsCoreUtils::ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange,
|
2012-03-20 06:09:50 +04:00
|
|
|
nsIPresShell::ScrollAxis aVertical,
|
|
|
|
nsIPresShell::ScrollAxis aHorizontal)
|
2007-08-24 08:54:45 +04:00
|
|
|
{
|
2012-04-06 22:08:24 +04:00
|
|
|
if (!aFrame)
|
2007-08-24 08:54:45 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsPresContext *presContext = aFrame->PresContext();
|
|
|
|
|
|
|
|
nsCOMPtr<nsISelectionController> selCon;
|
|
|
|
aFrame->GetSelectionController(presContext, getter_AddRefs(selCon));
|
|
|
|
NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
|
|
|
|
|
2011-08-08 00:17:00 +04:00
|
|
|
nsCOMPtr<nsISelection> selection;
|
2007-08-24 08:54:45 +04:00
|
|
|
selCon->GetSelection(nsISelectionController::SELECTION_ACCESSIBILITY,
|
2011-08-08 00:17:00 +04:00
|
|
|
getter_AddRefs(selection));
|
2007-08-24 08:54:45 +04:00
|
|
|
|
2011-08-08 00:17:00 +04:00
|
|
|
nsCOMPtr<nsISelectionPrivate> privSel(do_QueryInterface(selection));
|
|
|
|
selection->RemoveAllRanges();
|
2012-04-06 22:08:24 +04:00
|
|
|
selection->AddRange(aRange);
|
2007-08-24 08:54:45 +04:00
|
|
|
|
2012-03-20 06:09:50 +04:00
|
|
|
privSel->ScrollIntoViewInternal(
|
|
|
|
nsISelectionController::SELECTION_ANCHOR_REGION,
|
|
|
|
true, aVertical, aHorizontal);
|
2007-08-24 08:54:45 +04:00
|
|
|
|
2011-08-08 00:17:00 +04:00
|
|
|
selection->CollapseToStart();
|
2007-08-24 08:54:45 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-09-25 09:48:51 +04:00
|
|
|
void
|
2008-10-16 05:52:58 +04:00
|
|
|
nsCoreUtils::ScrollFrameToPoint(nsIFrame *aScrollableFrame,
|
|
|
|
nsIFrame *aFrame,
|
|
|
|
const nsIntPoint& aPoint)
|
2007-09-25 09:48:51 +04:00
|
|
|
{
|
2012-10-19 19:10:28 +04:00
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(aScrollableFrame);
|
2007-09-25 09:48:51 +04:00
|
|
|
if (!scrollableFrame)
|
|
|
|
return;
|
|
|
|
|
2012-10-19 19:10:28 +04:00
|
|
|
nsPoint point =
|
2015-04-21 18:04:57 +03:00
|
|
|
ToAppUnits(aPoint, aFrame->PresContext()->AppUnitsPerDevPixel());
|
2012-10-19 19:10:28 +04:00
|
|
|
nsRect frameRect = aFrame->GetScreenRectInAppUnits();
|
|
|
|
nsPoint deltaPoint(point.x - frameRect.x, point.y - frameRect.y);
|
2007-09-25 09:48:51 +04:00
|
|
|
|
|
|
|
nsPoint scrollPoint = scrollableFrame->GetScrollPosition();
|
|
|
|
scrollPoint -= deltaPoint;
|
|
|
|
|
2009-09-01 08:11:11 +04:00
|
|
|
scrollableFrame->ScrollTo(scrollPoint, nsIScrollableFrame::INSTANT);
|
2007-09-25 09:48:51 +04:00
|
|
|
}
|
|
|
|
|
2007-08-24 08:54:45 +04:00
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsCoreUtils::ConvertScrollTypeToPercents(uint32_t aScrollType,
|
2012-03-20 06:09:50 +04:00
|
|
|
nsIPresShell::ScrollAxis *aVertical,
|
|
|
|
nsIPresShell::ScrollAxis *aHorizontal)
|
2007-08-24 08:54:45 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t whereY, whereX;
|
2012-03-20 06:09:50 +04:00
|
|
|
nsIPresShell::WhenToScroll whenY, whenX;
|
2007-08-24 08:54:45 +04:00
|
|
|
switch (aScrollType)
|
|
|
|
{
|
|
|
|
case nsIAccessibleScrollType::SCROLL_TYPE_TOP_LEFT:
|
2012-03-20 06:09:50 +04:00
|
|
|
whereY = nsIPresShell::SCROLL_TOP;
|
|
|
|
whenY = nsIPresShell::SCROLL_ALWAYS;
|
|
|
|
whereX = nsIPresShell::SCROLL_LEFT;
|
|
|
|
whenX = nsIPresShell::SCROLL_ALWAYS;
|
2007-08-24 08:54:45 +04:00
|
|
|
break;
|
|
|
|
case nsIAccessibleScrollType::SCROLL_TYPE_BOTTOM_RIGHT:
|
2012-03-20 06:09:50 +04:00
|
|
|
whereY = nsIPresShell::SCROLL_BOTTOM;
|
|
|
|
whenY = nsIPresShell::SCROLL_ALWAYS;
|
|
|
|
whereX = nsIPresShell::SCROLL_RIGHT;
|
|
|
|
whenX = nsIPresShell::SCROLL_ALWAYS;
|
2007-08-24 08:54:45 +04:00
|
|
|
break;
|
|
|
|
case nsIAccessibleScrollType::SCROLL_TYPE_TOP_EDGE:
|
2012-03-20 06:09:50 +04:00
|
|
|
whereY = nsIPresShell::SCROLL_TOP;
|
|
|
|
whenY = nsIPresShell::SCROLL_ALWAYS;
|
|
|
|
whereX = nsIPresShell::SCROLL_MINIMUM;
|
|
|
|
whenX = nsIPresShell::SCROLL_IF_NOT_FULLY_VISIBLE;
|
2007-08-24 08:54:45 +04:00
|
|
|
break;
|
|
|
|
case nsIAccessibleScrollType::SCROLL_TYPE_BOTTOM_EDGE:
|
2012-03-20 06:09:50 +04:00
|
|
|
whereY = nsIPresShell::SCROLL_BOTTOM;
|
|
|
|
whenY = nsIPresShell::SCROLL_ALWAYS;
|
|
|
|
whereX = nsIPresShell::SCROLL_MINIMUM;
|
|
|
|
whenX = nsIPresShell::SCROLL_IF_NOT_FULLY_VISIBLE;
|
2007-08-24 08:54:45 +04:00
|
|
|
break;
|
|
|
|
case nsIAccessibleScrollType::SCROLL_TYPE_LEFT_EDGE:
|
2012-03-20 06:09:50 +04:00
|
|
|
whereY = nsIPresShell::SCROLL_MINIMUM;
|
|
|
|
whenY = nsIPresShell::SCROLL_IF_NOT_FULLY_VISIBLE;
|
|
|
|
whereX = nsIPresShell::SCROLL_LEFT;
|
|
|
|
whenX = nsIPresShell::SCROLL_ALWAYS;
|
2007-08-24 08:54:45 +04:00
|
|
|
break;
|
|
|
|
case nsIAccessibleScrollType::SCROLL_TYPE_RIGHT_EDGE:
|
2012-03-20 06:09:50 +04:00
|
|
|
whereY = nsIPresShell::SCROLL_MINIMUM;
|
|
|
|
whenY = nsIPresShell::SCROLL_IF_NOT_FULLY_VISIBLE;
|
|
|
|
whereX = nsIPresShell::SCROLL_RIGHT;
|
|
|
|
whenX = nsIPresShell::SCROLL_ALWAYS;
|
2007-08-24 08:54:45 +04:00
|
|
|
break;
|
|
|
|
default:
|
2012-03-20 06:09:50 +04:00
|
|
|
whereY = nsIPresShell::SCROLL_MINIMUM;
|
|
|
|
whenY = nsIPresShell::SCROLL_IF_NOT_FULLY_VISIBLE;
|
|
|
|
whereX = nsIPresShell::SCROLL_MINIMUM;
|
|
|
|
whenX = nsIPresShell::SCROLL_IF_NOT_FULLY_VISIBLE;
|
2007-08-24 08:54:45 +04:00
|
|
|
}
|
2012-03-20 06:09:50 +04:00
|
|
|
*aVertical = nsIPresShell::ScrollAxis(whereY, whenY);
|
|
|
|
*aHorizontal = nsIPresShell::ScrollAxis(whereX, whenX);
|
2007-08-24 08:54:45 +04:00
|
|
|
}
|
|
|
|
|
2007-09-05 11:39:09 +04:00
|
|
|
nsIntPoint
|
2010-06-11 12:23:18 +04:00
|
|
|
nsCoreUtils::GetScreenCoordsForWindow(nsINode *aNode)
|
2007-09-05 11:39:09 +04:00
|
|
|
{
|
|
|
|
nsIntPoint coords(0, 0);
|
2013-02-13 02:02:51 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem(GetDocShellFor(aNode));
|
2007-09-05 11:39:09 +04:00
|
|
|
if (!treeItem)
|
|
|
|
return coords;
|
|
|
|
|
2012-10-19 19:10:28 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
|
|
|
treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
|
|
|
if (!treeOwner)
|
2007-09-05 11:39:09 +04:00
|
|
|
return coords;
|
|
|
|
|
2012-10-19 19:10:28 +04:00
|
|
|
nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(treeOwner);
|
|
|
|
if (baseWindow)
|
|
|
|
baseWindow->GetPosition(&coords.x, &coords.y); // in device pixels
|
2007-09-05 11:39:09 +04:00
|
|
|
|
|
|
|
return coords;
|
|
|
|
}
|
|
|
|
|
2013-02-13 02:02:51 +04:00
|
|
|
already_AddRefed<nsIDocShell>
|
|
|
|
nsCoreUtils::GetDocShellFor(nsINode *aNode)
|
2007-09-05 11:39:09 +04:00
|
|
|
{
|
|
|
|
if (!aNode)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2007-09-05 11:39:09 +04:00
|
|
|
|
2013-11-15 20:32:12 +04:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = aNode->OwnerDoc()->GetDocShell();
|
2013-02-13 02:02:51 +04:00
|
|
|
return docShell.forget();
|
2007-09-05 11:39:09 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-06-08 20:39:58 +04:00
|
|
|
nsCoreUtils::IsRootDocument(nsIDocument *aDocument)
|
|
|
|
{
|
2013-11-15 20:32:12 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem = aDocument->GetDocShell();
|
2010-06-08 20:39:58 +04:00
|
|
|
NS_ASSERTION(docShellTreeItem, "No document shell for document!");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentTreeItem;
|
|
|
|
docShellTreeItem->GetParent(getter_AddRefs(parentTreeItem));
|
|
|
|
|
|
|
|
return !parentTreeItem;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-06-08 20:39:58 +04:00
|
|
|
nsCoreUtils::IsContentDocument(nsIDocument *aDocument)
|
|
|
|
{
|
2013-11-15 20:32:12 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem = aDocument->GetDocShell();
|
2010-06-08 20:39:58 +04:00
|
|
|
NS_ASSERTION(docShellTreeItem, "No document shell tree item for document!");
|
|
|
|
|
2014-01-20 11:58:26 +04:00
|
|
|
return (docShellTreeItem->ItemType() == nsIDocShellTreeItem::typeContent);
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
2011-07-22 04:49:35 +04:00
|
|
|
bool
|
|
|
|
nsCoreUtils::IsTabDocument(nsIDocument* aDocumentNode)
|
|
|
|
{
|
2013-11-15 20:32:12 +04:00
|
|
|
nsCOMPtr<nsIDocShellTreeItem> treeItem(aDocumentNode->GetDocShell());
|
2011-07-22 04:49:35 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> parentTreeItem;
|
|
|
|
treeItem->GetParent(getter_AddRefs(parentTreeItem));
|
|
|
|
|
|
|
|
// Tab document running in own process doesn't have parent.
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsContentProcess())
|
2011-07-22 04:49:35 +04:00
|
|
|
return !parentTreeItem;
|
|
|
|
|
|
|
|
// Parent of docshell for tab document running in chrome process is root.
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> rootTreeItem;
|
|
|
|
treeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem));
|
|
|
|
|
|
|
|
return parentTreeItem == rootTreeItem;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-06-08 20:39:58 +04:00
|
|
|
nsCoreUtils::IsErrorPage(nsIDocument *aDocument)
|
|
|
|
{
|
|
|
|
nsIURI *uri = aDocument->GetDocumentURI();
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isAboutScheme = false;
|
2010-06-08 20:39:58 +04:00
|
|
|
uri->SchemeIs("about", &isAboutScheme);
|
|
|
|
if (!isAboutScheme)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString path;
|
2010-06-08 20:39:58 +04:00
|
|
|
uri->GetPath(path);
|
|
|
|
|
|
|
|
NS_NAMED_LITERAL_CSTRING(neterror, "neterror");
|
2011-05-21 11:00:14 +04:00
|
|
|
NS_NAMED_LITERAL_CSTRING(certerror, "certerror");
|
|
|
|
|
|
|
|
return StringBeginsWith(path, neterror) || StringBeginsWith(path, certerror);
|
2010-06-08 20:39:58 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-10-16 05:52:58 +04:00
|
|
|
nsCoreUtils::GetID(nsIContent *aContent, nsAString& aID)
|
2007-09-19 01:36:41 +04:00
|
|
|
{
|
2014-05-30 11:36:53 +04:00
|
|
|
return aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::id, aID);
|
2007-09-19 01:36:41 +04:00
|
|
|
}
|
2007-09-25 05:19:03 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsCoreUtils::GetUIntAttr(nsIContent *aContent, nsIAtom *aAttr, int32_t *aUInt)
|
2010-01-12 22:07:38 +03:00
|
|
|
{
|
|
|
|
nsAutoString value;
|
|
|
|
aContent->GetAttr(kNameSpaceID_None, aAttr, value);
|
|
|
|
if (!value.IsEmpty()) {
|
2012-07-27 17:59:29 +04:00
|
|
|
nsresult error = NS_OK;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t integer = value.ToInteger(&error);
|
2010-01-12 22:07:38 +03:00
|
|
|
if (NS_SUCCEEDED(error) && integer > 0) {
|
|
|
|
*aUInt = integer;
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-01-12 22:07:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-01-12 22:07:38 +03:00
|
|
|
}
|
|
|
|
|
2008-07-17 16:06:24 +04:00
|
|
|
void
|
2008-10-16 05:52:58 +04:00
|
|
|
nsCoreUtils::GetLanguageFor(nsIContent *aContent, nsIContent *aRootContent,
|
|
|
|
nsAString& aLanguage)
|
2008-07-17 16:06:24 +04:00
|
|
|
{
|
|
|
|
aLanguage.Truncate();
|
|
|
|
|
|
|
|
nsIContent *walkUp = aContent;
|
|
|
|
while (walkUp && walkUp != aRootContent &&
|
2011-06-04 01:35:17 +04:00
|
|
|
!walkUp->GetAttr(kNameSpaceID_None, nsGkAtoms::lang, aLanguage))
|
2008-07-17 16:06:24 +04:00
|
|
|
walkUp = walkUp->GetParent();
|
|
|
|
}
|
2008-10-17 14:10:43 +04:00
|
|
|
|
2009-05-06 13:54:26 +04:00
|
|
|
already_AddRefed<nsIBoxObject>
|
|
|
|
nsCoreUtils::GetTreeBodyBoxObject(nsITreeBoxObject *aTreeBoxObj)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> tcElm;
|
|
|
|
aTreeBoxObj->GetTreeBody(getter_AddRefs(tcElm));
|
2017-02-02 18:32:58 +03:00
|
|
|
nsCOMPtr<nsIContent> tcContent(do_QueryInterface(tcElm));
|
|
|
|
RefPtr<nsXULElement> tcXULElm = nsXULElement::FromContentOrNull(tcContent);
|
2009-05-06 13:54:26 +04:00
|
|
|
if (!tcXULElm)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-05-06 13:54:26 +04:00
|
|
|
|
2017-02-02 18:32:58 +03:00
|
|
|
IgnoredErrorResult ignored;
|
|
|
|
return tcXULElm->GetBoxObject(ignored);
|
2009-05-06 13:54:26 +04:00
|
|
|
}
|
2009-08-20 10:45:19 +04:00
|
|
|
|
2010-06-11 12:23:18 +04:00
|
|
|
already_AddRefed<nsITreeBoxObject>
|
|
|
|
nsCoreUtils::GetTreeBoxObject(nsIContent *aContent)
|
2009-08-20 10:45:19 +04:00
|
|
|
{
|
|
|
|
// Find DOMNode's parents recursively until reach the <tree> tag
|
2010-06-11 12:23:18 +04:00
|
|
|
nsIContent* currentContent = aContent;
|
|
|
|
while (currentContent) {
|
2011-06-04 01:35:17 +04:00
|
|
|
if (currentContent->NodeInfo()->Equals(nsGkAtoms::tree,
|
2010-06-11 12:23:18 +04:00
|
|
|
kNameSpaceID_XUL)) {
|
2009-08-20 10:45:19 +04:00
|
|
|
// We will get the nsITreeBoxObject from the tree node
|
2017-02-02 18:32:58 +03:00
|
|
|
RefPtr<nsXULElement> xulElement =
|
|
|
|
nsXULElement::FromContent(currentContent);
|
|
|
|
IgnoredErrorResult ignored;
|
|
|
|
nsCOMPtr<nsIBoxObject> box = xulElement->GetBoxObject(ignored);
|
|
|
|
nsCOMPtr<nsITreeBoxObject> treeBox(do_QueryInterface(box));
|
|
|
|
if (treeBox)
|
|
|
|
return treeBox.forget();
|
2009-08-20 10:45:19 +04:00
|
|
|
}
|
2013-05-02 02:50:08 +04:00
|
|
|
currentContent = currentContent->GetFlattenedTreeParent();
|
2009-08-20 10:45:19 +04:00
|
|
|
}
|
2010-06-11 12:23:18 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-08-20 10:45:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsITreeColumn>
|
|
|
|
nsCoreUtils::GetFirstSensibleColumn(nsITreeBoxObject *aTree)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITreeColumns> cols;
|
|
|
|
aTree->GetColumns(getter_AddRefs(cols));
|
|
|
|
if (!cols)
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-08-20 10:45:19 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsITreeColumn> column;
|
|
|
|
cols->GetFirstColumn(getter_AddRefs(column));
|
|
|
|
if (column && IsColumnHidden(column))
|
|
|
|
return GetNextSensibleColumn(column);
|
|
|
|
|
|
|
|
return column.forget();
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2009-12-10 22:12:19 +03:00
|
|
|
nsCoreUtils::GetSensibleColumnCount(nsITreeBoxObject *aTree)
|
2009-08-20 10:45:19 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t count = 0;
|
2009-08-20 10:45:19 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsITreeColumns> cols;
|
|
|
|
aTree->GetColumns(getter_AddRefs(cols));
|
|
|
|
if (!cols)
|
|
|
|
return count;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITreeColumn> column;
|
|
|
|
cols->GetFirstColumn(getter_AddRefs(column));
|
|
|
|
|
|
|
|
while (column) {
|
|
|
|
if (!IsColumnHidden(column))
|
|
|
|
count++;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITreeColumn> nextColumn;
|
|
|
|
column->GetNext(getter_AddRefs(nextColumn));
|
|
|
|
column.swap(nextColumn);
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsITreeColumn>
|
2012-08-22 19:56:38 +04:00
|
|
|
nsCoreUtils::GetSensibleColumnAt(nsITreeBoxObject *aTree, uint32_t aIndex)
|
2009-08-20 10:45:19 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t idx = aIndex;
|
2009-08-20 10:45:19 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsITreeColumn> column = GetFirstSensibleColumn(aTree);
|
|
|
|
while (column) {
|
|
|
|
if (idx == 0)
|
|
|
|
return column.forget();
|
|
|
|
|
|
|
|
idx--;
|
|
|
|
column = GetNextSensibleColumn(column);
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2009-08-20 10:45:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsITreeColumn>
|
|
|
|
nsCoreUtils::GetNextSensibleColumn(nsITreeColumn *aColumn)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITreeColumn> nextColumn;
|
|
|
|
aColumn->GetNext(getter_AddRefs(nextColumn));
|
|
|
|
|
|
|
|
while (nextColumn && IsColumnHidden(nextColumn)) {
|
|
|
|
nsCOMPtr<nsITreeColumn> tempColumn;
|
|
|
|
nextColumn->GetNext(getter_AddRefs(tempColumn));
|
|
|
|
nextColumn.swap(tempColumn);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nextColumn.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsITreeColumn>
|
|
|
|
nsCoreUtils::GetPreviousSensibleColumn(nsITreeColumn *aColumn)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITreeColumn> prevColumn;
|
|
|
|
aColumn->GetPrevious(getter_AddRefs(prevColumn));
|
|
|
|
|
|
|
|
while (prevColumn && IsColumnHidden(prevColumn)) {
|
|
|
|
nsCOMPtr<nsITreeColumn> tempColumn;
|
|
|
|
prevColumn->GetPrevious(getter_AddRefs(tempColumn));
|
|
|
|
prevColumn.swap(tempColumn);
|
|
|
|
}
|
|
|
|
|
|
|
|
return prevColumn.forget();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2009-08-20 10:45:19 +04:00
|
|
|
nsCoreUtils::IsColumnHidden(nsITreeColumn *aColumn)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> element;
|
|
|
|
aColumn->GetElement(getter_AddRefs(element));
|
|
|
|
nsCOMPtr<nsIContent> content = do_QueryInterface(element);
|
2011-06-04 01:35:17 +04:00
|
|
|
return content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::hidden,
|
|
|
|
nsGkAtoms::_true, eCaseMatters);
|
2009-08-20 10:45:19 +04:00
|
|
|
}
|
2009-11-10 08:58:52 +03:00
|
|
|
|
2012-04-10 04:39:00 +04:00
|
|
|
void
|
|
|
|
nsCoreUtils::ScrollTo(nsIPresShell* aPresShell, nsIContent* aContent,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aScrollType)
|
2012-04-10 04:39:00 +04:00
|
|
|
{
|
|
|
|
nsIPresShell::ScrollAxis vertical, horizontal;
|
|
|
|
ConvertScrollTypeToPercents(aScrollType, &vertical, &horizontal);
|
|
|
|
aPresShell->ScrollContentIntoView(aContent, vertical, horizontal,
|
|
|
|
nsIPresShell::SCROLL_OVERFLOW_HIDDEN);
|
|
|
|
}
|
|
|
|
|
2013-07-18 19:09:45 +04:00
|
|
|
bool
|
2017-06-20 12:19:52 +03:00
|
|
|
nsCoreUtils::IsWhitespaceString(const nsAString& aString)
|
2013-07-18 19:09:45 +04:00
|
|
|
{
|
2017-06-20 12:19:52 +03:00
|
|
|
nsAString::const_char_iterator iterBegin, iterEnd;
|
2013-07-18 19:09:45 +04:00
|
|
|
|
|
|
|
aString.BeginReading(iterBegin);
|
|
|
|
aString.EndReading(iterEnd);
|
|
|
|
|
|
|
|
while (iterBegin != iterEnd && IsWhitespace(*iterBegin))
|
|
|
|
++iterBegin;
|
|
|
|
|
|
|
|
return iterBegin == iterEnd;
|
|
|
|
}
|
2016-01-21 04:52:43 +03:00
|
|
|
|
|
|
|
bool
|
|
|
|
nsCoreUtils::AccEventObserversExist()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
|
|
|
|
NS_ENSURE_TRUE(obsService, false);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> observers;
|
|
|
|
obsService->EnumerateObservers(NS_ACCESSIBLE_EVENT_TOPIC,
|
|
|
|
getter_AddRefs(observers));
|
|
|
|
NS_ENSURE_TRUE(observers, false);
|
|
|
|
|
|
|
|
bool hasObservers = false;
|
|
|
|
observers->HasMoreElements(&hasObservers);
|
|
|
|
|
|
|
|
return hasObservers;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCoreUtils::DispatchAccEvent(RefPtr<nsIAccessibleEvent> event)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obsService = services::GetObserverService();
|
|
|
|
NS_ENSURE_TRUE_VOID(obsService);
|
|
|
|
|
|
|
|
obsService->NotifyObservers(event, NS_ACCESSIBLE_EVENT_TOPIC, nullptr);
|
|
|
|
}
|
2016-02-24 16:01:21 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
nsCoreUtils::XBLBindingRole(const nsIContent* aEl, nsAString& aRole)
|
|
|
|
{
|
|
|
|
for (const nsXBLBinding* binding = aEl->GetXBLBinding(); binding;
|
|
|
|
binding = binding->GetBaseBinding()) {
|
|
|
|
nsIContent* bindingElm = binding->PrototypeBinding()->GetBindingElement();
|
|
|
|
bindingElm->GetAttr(kNameSpaceID_None, nsGkAtoms::role, aRole);
|
|
|
|
if (!aRole.IsEmpty())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|