зеркало из https://github.com/mozilla/gecko-dev.git
bug 377302 - implement nsIAccessNode::scrollToPoint, r=aaronlev, sr=roc, a=dsicore
This commit is contained in:
Родитель
5f1e8bc717
Коммит
c881ad990f
|
@ -111,32 +111,11 @@ getExtentsCB(AtkComponent *aComponent,
|
|||
if (NS_FAILED(rv))
|
||||
return;
|
||||
if (aCoordType == ATK_XY_WINDOW) {
|
||||
// Make coordinates relative to top level window instead of screen
|
||||
nsCOMPtr<nsIDOMNode> domNode;
|
||||
accWrap->GetDOMNode(getter_AddRefs(domNode));
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem = nsAccessNode::GetDocShellTreeItemFor(domNode);
|
||||
nsCOMPtr<nsIDocShellTreeItem> rootTreeItem;
|
||||
treeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem));
|
||||
nsCOMPtr<nsIDOMDocument> domDoc = do_GetInterface(rootTreeItem);
|
||||
nsCOMPtr<nsIDOMDocumentView> docView(do_QueryInterface(domDoc));
|
||||
if (!docView) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMAbstractView> abstractView;
|
||||
docView->GetDefaultView(getter_AddRefs(abstractView));
|
||||
nsCOMPtr<nsIDOMWindowInternal> windowInter(do_QueryInterface(abstractView));
|
||||
if (!windowInter) {
|
||||
return;
|
||||
}
|
||||
|
||||
PRInt32 screenX, screenY;
|
||||
if (NS_FAILED(windowInter->GetScreenX(&screenX)) ||
|
||||
NS_FAILED(windowInter->GetScreenY(&screenY))) {
|
||||
return;
|
||||
}
|
||||
nsAccX -= screenX;
|
||||
nsAccY -= screenY;
|
||||
nsCOMPtr<nsIDOMNode> domNode;
|
||||
accWrap->GetDOMNode(getter_AddRefs(domNode));
|
||||
nsIntPoint winCoords = nsAccUtils::GetScreenCoordsForWindow(domNode);
|
||||
nsAccX -= winCoords.x;
|
||||
nsAccY -= winCoords.y;
|
||||
}
|
||||
|
||||
*aAccX = nsAccX;
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIScrollableFrame.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsPresContext.h"
|
||||
|
@ -336,8 +337,8 @@ already_AddRefed<nsIAccessibleDocument> nsAccessNode::GetDocAccessible()
|
|||
|
||||
already_AddRefed<nsRootAccessible> nsAccessNode::GetRootAccessible()
|
||||
{
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
|
||||
GetDocShellTreeItemFor(mDOMNode);
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
|
||||
nsAccUtils::GetDocShellTreeItemFor(mDOMNode);
|
||||
NS_ASSERTION(docShellTreeItem, "No docshell tree item for mDOMNode");
|
||||
if (!docShellTreeItem) {
|
||||
return nsnull;
|
||||
|
@ -434,7 +435,77 @@ nsAccessNode::ScrollTo(PRUint32 aScrollType)
|
|||
NS_IMETHODIMP
|
||||
nsAccessNode::ScrollToPoint(PRUint32 aCoordinateType, PRInt32 aX, PRInt32 aY)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
nsIFrame *frame = GetFrame();
|
||||
if (!frame)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsPresContext *presContext = frame->PresContext();
|
||||
|
||||
switch (aCoordinateType) {
|
||||
case nsIAccessibleCoordinateType::COORDTYPE_SCREEN_RELATIVE:
|
||||
break;
|
||||
|
||||
case nsIAccessibleCoordinateType::COORDTYPE_WINDOW_RELATIVE:
|
||||
{
|
||||
nsIntPoint wndCoords = nsAccUtils::GetScreenCoordsForWindow(mDOMNode);
|
||||
aX += wndCoords.x;
|
||||
aY += wndCoords.y;
|
||||
break;
|
||||
}
|
||||
|
||||
case nsIAccessibleCoordinateType::COORDTYPE_PARENT_RELATIVE:
|
||||
{
|
||||
nsCOMPtr<nsPIAccessNode> parent;
|
||||
|
||||
nsCOMPtr<nsIAccessible> accessible;
|
||||
nsresult rv = QueryInterface(NS_GET_IID(nsIAccessible),
|
||||
getter_AddRefs(accessible));
|
||||
if (NS_SUCCEEDED(rv) && accessible) {
|
||||
nsCOMPtr<nsIAccessible> parentAccessible;
|
||||
accessible->GetParent(getter_AddRefs(parentAccessible));
|
||||
parent = do_QueryInterface(parentAccessible);
|
||||
} else {
|
||||
nsCOMPtr<nsIAccessNode> parentAccessNode;
|
||||
GetParentNode(getter_AddRefs(parentAccessNode));
|
||||
parent = do_QueryInterface(parentAccessNode);
|
||||
}
|
||||
|
||||
NS_ENSURE_STATE(parent);
|
||||
nsIFrame *parentFrame = parent->GetFrame();
|
||||
NS_ENSURE_STATE(parentFrame);
|
||||
|
||||
nsIntRect parentRect = parentFrame->GetScreenRectExternal();
|
||||
aX += parentRect.x;
|
||||
aY += parentRect.y;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
nsIFrame *parentFrame = frame;
|
||||
while (parentFrame = parentFrame->GetParent()) {
|
||||
nsIScrollableFrame *scrollableFrame = nsnull;
|
||||
CallQueryInterface(parentFrame, &scrollableFrame);
|
||||
if (scrollableFrame) {
|
||||
nsIntRect frameRect = frame->GetScreenRectExternal();
|
||||
PRInt32 devDeltaX = aX - frameRect.x;
|
||||
PRInt32 devDeltaY = aY - frameRect.y;
|
||||
|
||||
nsPoint deltaPoint;
|
||||
deltaPoint.x = presContext->DevPixelsToAppUnits(devDeltaX);
|
||||
deltaPoint.y = presContext->DevPixelsToAppUnits(devDeltaY);
|
||||
|
||||
nsPoint scrollPoint = scrollableFrame->GetScrollPosition();
|
||||
|
||||
scrollPoint -= deltaPoint;
|
||||
|
||||
scrollableFrame->ScrollTo(scrollPoint);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -681,30 +752,6 @@ nsAccessNode::GetPresShellFor(nsIDOMNode *aNode)
|
|||
return presShell;
|
||||
}
|
||||
|
||||
|
||||
already_AddRefed<nsIDocShellTreeItem>
|
||||
nsAccessNode::GetDocShellTreeItemFor(nsIDOMNode *aStartNode)
|
||||
{
|
||||
if (!aStartNode) {
|
||||
return nsnull;
|
||||
}
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
aStartNode->GetOwnerDocument(getter_AddRefs(domDoc));
|
||||
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
|
||||
if (!doc) {
|
||||
doc = do_QueryInterface(aStartNode);
|
||||
}
|
||||
NS_ASSERTION(doc, "No document for node passed in");
|
||||
NS_ENSURE_TRUE(doc, nsnull);
|
||||
nsCOMPtr<nsISupports> container = doc->GetContainer();
|
||||
nsIDocShellTreeItem *docShellTreeItem = nsnull;
|
||||
if (container) {
|
||||
CallQueryInterface(container, &docShellTreeItem);
|
||||
}
|
||||
|
||||
return docShellTreeItem;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDOMNode>
|
||||
nsAccessNode::GetDOMNodeForContainer(nsISupports *aContainer)
|
||||
{
|
||||
|
|
|
@ -49,7 +49,6 @@
|
|||
#include "nsIAccessNode.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsPIAccessNode.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIStringBundle.h"
|
||||
|
@ -104,7 +103,6 @@ class nsAccessNode: public nsIAccessNode, public nsPIAccessNode
|
|||
static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsISupports *aContainer, PRBool aCanCreate = PR_FALSE);
|
||||
static already_AddRefed<nsIAccessibleDocument> GetDocAccessibleFor(nsIDOMNode *aNode);
|
||||
|
||||
static already_AddRefed<nsIDocShellTreeItem> GetDocShellTreeItemFor(nsIDOMNode *aStartNode);
|
||||
static already_AddRefed<nsIDOMNode> GetDOMNodeForContainer(nsISupports *aContainer);
|
||||
static already_AddRefed<nsIPresShell> GetPresShellFor(nsIDOMNode *aStartNode);
|
||||
|
||||
|
|
|
@ -42,9 +42,14 @@
|
|||
#include "nsPIAccessible.h"
|
||||
#include "nsAccessibleEventData.h"
|
||||
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMAbstractView.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDOMDocumentView.h"
|
||||
#include "nsIDOMRange.h"
|
||||
#include "nsIDOMXULSelectCntrlEl.h"
|
||||
#include "nsIDOMXULSelectCntrlItemEl.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsIEventListenerManager.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsPresContext.h"
|
||||
|
@ -54,6 +59,7 @@
|
|||
|
||||
#include "nsContentCID.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
|
||||
static NS_DEFINE_IID(kRangeCID, NS_RANGE_CID);
|
||||
|
||||
|
@ -347,3 +353,52 @@ nsAccUtils::ConvertScrollTypeToPercents(PRUint32 aScrollType,
|
|||
}
|
||||
}
|
||||
|
||||
nsIntPoint
|
||||
nsAccUtils::GetScreenCoordsForWindow(nsIDOMNode *aNode)
|
||||
{
|
||||
nsIntPoint coords(0, 0);
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem(GetDocShellTreeItemFor(aNode));
|
||||
if (!treeItem)
|
||||
return coords;
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> rootTreeItem;
|
||||
treeItem->GetRootTreeItem(getter_AddRefs(rootTreeItem));
|
||||
nsCOMPtr<nsIDOMDocument> domDoc = do_GetInterface(rootTreeItem);
|
||||
nsCOMPtr<nsIDOMDocumentView> docView(do_QueryInterface(domDoc));
|
||||
if (!docView)
|
||||
return coords;
|
||||
|
||||
nsCOMPtr<nsIDOMAbstractView> abstractView;
|
||||
docView->GetDefaultView(getter_AddRefs(abstractView));
|
||||
nsCOMPtr<nsIDOMWindowInternal> windowInter(do_QueryInterface(abstractView));
|
||||
if (!windowInter)
|
||||
return coords;
|
||||
|
||||
windowInter->GetScreenX(&coords.x);
|
||||
windowInter->GetScreenY(&coords.y);
|
||||
return coords;
|
||||
}
|
||||
|
||||
already_AddRefed<nsIDocShellTreeItem>
|
||||
nsAccUtils::GetDocShellTreeItemFor(nsIDOMNode *aNode)
|
||||
{
|
||||
if (!aNode)
|
||||
return nsnull;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
aNode->GetOwnerDocument(getter_AddRefs(domDoc));
|
||||
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
|
||||
if (!doc)
|
||||
doc = do_QueryInterface(aNode);
|
||||
|
||||
NS_ASSERTION(doc, "No document for node passed in");
|
||||
NS_ENSURE_TRUE(doc, nsnull);
|
||||
|
||||
nsCOMPtr<nsISupports> container = doc->GetContainer();
|
||||
nsIDocShellTreeItem *docShellTreeItem = nsnull;
|
||||
if (container)
|
||||
CallQueryInterface(container, &docShellTreeItem);
|
||||
|
||||
return docShellTreeItem;
|
||||
}
|
||||
|
||||
|
|
|
@ -46,6 +46,8 @@
|
|||
#include "nsIPersistentProperties2.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsPoint.h"
|
||||
|
||||
class nsAccUtils
|
||||
{
|
||||
|
@ -165,6 +167,19 @@ public:
|
|||
static void ConvertScrollTypeToPercents(PRUint32 aScrollType,
|
||||
PRInt16 *aVPercent,
|
||||
PRInt16 *aHPercent);
|
||||
|
||||
/**
|
||||
* Returns coordinates relative screen for the top level window.
|
||||
*
|
||||
* @param - aNode - the DOM node hosted in the window.
|
||||
*/
|
||||
static nsIntPoint GetScreenCoordsForWindow(nsIDOMNode *aNode);
|
||||
|
||||
/**
|
||||
* Return document shell tree item for the given DOM node.
|
||||
*/
|
||||
static already_AddRefed<nsIDocShellTreeItem>
|
||||
GetDocShellTreeItemFor(nsIDOMNode *aNode);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -109,8 +109,8 @@ nsDocAccessible::nsDocAccessible(nsIDOMNode *aDOMNode, nsIWeakReference* aShell)
|
|||
// XXX aaronl should we use an algorithm for the initial cache size?
|
||||
mAccessNodeCache.Init(kDefaultCacheSize);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
|
||||
GetDocShellTreeItemFor(mDOMNode);
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
|
||||
nsAccUtils::GetDocShellTreeItemFor(mDOMNode);
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(docShellTreeItem);
|
||||
if (docShell) {
|
||||
PRUint32 busyFlags;
|
||||
|
@ -164,7 +164,7 @@ NS_IMETHODIMP nsDocAccessible::GetRole(PRUint32 *aRole)
|
|||
*aRole = nsIAccessibleRole::ROLE_PANE; // Fall back
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
|
||||
GetDocShellTreeItemFor(mDOMNode);
|
||||
nsAccUtils::GetDocShellTreeItemFor(mDOMNode);
|
||||
if (docShellTreeItem) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
|
||||
docShellTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
|
||||
|
@ -278,7 +278,8 @@ NS_IMETHODIMP nsDocAccessible::TakeFocus()
|
|||
return NS_ERROR_FAILURE; // Not focusable
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem = GetDocShellTreeItemFor(mDOMNode);
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem =
|
||||
nsAccUtils::GetDocShellTreeItemFor(mDOMNode);
|
||||
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(treeItem);
|
||||
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
||||
|
||||
|
@ -525,7 +526,8 @@ NS_IMETHODIMP nsDocAccessible::Shutdown()
|
|||
return NS_OK; // Already shutdown
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem = GetDocShellTreeItemFor(mDOMNode);
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem =
|
||||
nsAccUtils::GetDocShellTreeItemFor(mDOMNode);
|
||||
ShutdownChildDocuments(treeItem);
|
||||
|
||||
if (mDocLoadTimer) {
|
||||
|
@ -787,7 +789,8 @@ NS_IMETHODIMP nsDocAccessible::FireDocLoadEvents(PRUint32 aEventType)
|
|||
nsITimer::TYPE_ONE_SHOT);
|
||||
}
|
||||
} else {
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem = GetDocShellTreeItemFor(mDOMNode);
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem =
|
||||
nsAccUtils::GetDocShellTreeItemFor(mDOMNode);
|
||||
if (!treeItem) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -1852,7 +1855,7 @@ void nsDocAccessible::DocLoadCallback(nsITimer *aTimer, void *aClosure)
|
|||
// Fire STATE_CHANGE event for doc load finish if focus is in same doc tree
|
||||
if (gLastFocusedNode) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> focusedTreeItem =
|
||||
GetDocShellTreeItemFor(gLastFocusedNode);
|
||||
nsAccUtils::GetDocShellTreeItemFor(gLastFocusedNode);
|
||||
if (focusedTreeItem) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> sameTypeRootOfFocus;
|
||||
focusedTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRootOfFocus));
|
||||
|
|
|
@ -132,7 +132,7 @@ NS_IMETHODIMP nsRootAccessible::GetName(nsAString& aName)
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem =
|
||||
GetDocShellTreeItemFor(mDOMNode);
|
||||
nsAccUtils::GetDocShellTreeItemFor(mDOMNode);
|
||||
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
|
@ -191,7 +191,8 @@ PRUint32 nsRootAccessible::GetChromeFlags()
|
|||
// Return the flag set for the top level window as defined
|
||||
// by nsIWebBrowserChrome::CHROME_WINDOW_[FLAGNAME]
|
||||
// Not simple: nsIXULWindow is not just a QI from nsIDOMWindow
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem = GetDocShellTreeItemFor(mDOMNode);
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem =
|
||||
nsAccUtils::GetDocShellTreeItemFor(mDOMNode);
|
||||
NS_ENSURE_TRUE(treeItem, 0);
|
||||
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
||||
treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
||||
|
@ -377,7 +378,7 @@ void nsRootAccessible::TryFireEarlyLoadEvent(nsIDOMNode *aDocNode)
|
|||
// This also works for firing events for error pages
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem =
|
||||
GetDocShellTreeItemFor(aDocNode);
|
||||
nsAccUtils::GetDocShellTreeItemFor(aDocNode);
|
||||
NS_ASSERTION(treeItem, "No docshelltreeitem for aDocNode");
|
||||
if (!treeItem) {
|
||||
return;
|
||||
|
@ -975,7 +976,8 @@ NS_IMETHODIMP nsRootAccessible::GetAccessibleRelated(PRUint32 aRelationType,
|
|||
return nsDocAccessibleWrap::GetAccessibleRelated(aRelationType, aRelated);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem = GetDocShellTreeItemFor(mDOMNode);
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem =
|
||||
nsAccUtils::GetDocShellTreeItemFor(mDOMNode);
|
||||
nsCOMPtr<nsIDocShellTreeItem> contentTreeItem = GetContentDocShell(treeItem);
|
||||
// there may be no content area, so we need a null check
|
||||
if (contentTreeItem) {
|
||||
|
@ -996,7 +998,7 @@ NS_IMETHODIMP nsRootAccessible::FireDocLoadEvents(PRUint32 aEventType)
|
|||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
|
||||
nsAccessNode::GetDocShellTreeItemFor(mDOMNode);
|
||||
nsAccUtils::GetDocShellTreeItemFor(mDOMNode);
|
||||
NS_ASSERTION(docShellTreeItem, "No doc shell tree item for document");
|
||||
NS_ENSURE_TRUE(docShellTreeItem, NS_ERROR_FAILURE);
|
||||
PRInt32 contentType;
|
||||
|
|
|
@ -1268,7 +1268,8 @@ nsHyperTextAccessible::GetAssociatedEditor(nsIEditor **aEditor)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem = GetDocShellTreeItemFor(mDOMNode);
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellTreeItem =
|
||||
nsAccUtils::GetDocShellTreeItemFor(mDOMNode);
|
||||
nsCOMPtr<nsIEditingSession> editingSession(do_GetInterface(docShellTreeItem));
|
||||
if (!editingSession)
|
||||
return NS_OK; // No editing session interface
|
||||
|
|
Загрузка…
Ссылка в новой задаче