diff --git a/accessible/src/atk/AtkSocketAccessible.cpp b/accessible/src/atk/AtkSocketAccessible.cpp index 3a6c13ac4d6..8d32c35c6b6 100644 --- a/accessible/src/atk/AtkSocketAccessible.cpp +++ b/accessible/src/atk/AtkSocketAccessible.cpp @@ -162,9 +162,9 @@ mai_atk_socket_get_extents(AtkComponent* aComponent, } AtkSocketAccessible::AtkSocketAccessible(nsIContent* aContent, - nsDocAccessible* aDoc, + nsIWeakReference* aShell, const nsCString& aPlugId) : - nsAccessibleWrap(aContent, aDoc) + nsAccessibleWrap(aContent, aShell) { mAtkObject = mai_atk_socket_new(this); if (!mAtkObject) diff --git a/accessible/src/atk/AtkSocketAccessible.h b/accessible/src/atk/AtkSocketAccessible.h index 2a049f74cb2..dd3cc5aa672 100644 --- a/accessible/src/atk/AtkSocketAccessible.h +++ b/accessible/src/atk/AtkSocketAccessible.h @@ -72,7 +72,7 @@ public: */ static bool gCanEmbed; - AtkSocketAccessible(nsIContent* aContent, nsDocAccessible* aDoc, + AtkSocketAccessible(nsIContent* aContent, nsIWeakReference* aShell, const nsCString& aPlugId); // nsAccessNode diff --git a/accessible/src/atk/nsAccessNodeWrap.cpp b/accessible/src/atk/nsAccessNodeWrap.cpp index 92f502d4eca..bdc8f3a0b3b 100644 --- a/accessible/src/atk/nsAccessNodeWrap.cpp +++ b/accessible/src/atk/nsAccessNodeWrap.cpp @@ -55,8 +55,8 @@ //----------------------------------------------------- nsAccessNodeWrap:: - nsAccessNodeWrap(nsIContent* aContent, nsDocAccessible* aDoc) : - nsAccessNode(aContent, aDoc) + nsAccessNodeWrap(nsIContent *aContent, nsIWeakReference *aShell) : + nsAccessNode(aContent, aShell) { } diff --git a/accessible/src/atk/nsAccessNodeWrap.h b/accessible/src/atk/nsAccessNodeWrap.h index deb048a0adc..7258ae53038 100644 --- a/accessible/src/atk/nsAccessNodeWrap.h +++ b/accessible/src/atk/nsAccessNodeWrap.h @@ -49,11 +49,12 @@ class nsAccessNodeWrap : public nsAccessNode { public: // construction, destruction - nsAccessNodeWrap(nsIContent* aContent, nsDocAccessible* aDoc); - virtual ~nsAccessNodeWrap(); + nsAccessNodeWrap(nsIContent *aContent, nsIWeakReference *aShell); + virtual ~nsAccessNodeWrap(); + + static void InitAccessibility(); + static void ShutdownAccessibility(); - static void InitAccessibility(); - static void ShutdownAccessibility(); }; #endif diff --git a/accessible/src/atk/nsAccessibleWrap.cpp b/accessible/src/atk/nsAccessibleWrap.cpp index 64cfc554db7..00430256de8 100644 --- a/accessible/src/atk/nsAccessibleWrap.cpp +++ b/accessible/src/atk/nsAccessibleWrap.cpp @@ -281,8 +281,8 @@ PRInt32 nsAccessibleWrap::mAccWrapDeleted = 0; #endif nsAccessibleWrap:: - nsAccessibleWrap(nsIContent* aContent, nsDocAccessible* aDoc) : - nsAccessible(aContent, aDoc), mAtkObject(nsnull) + nsAccessibleWrap(nsIContent *aContent, nsIWeakReference *aShell) : + nsAccessible(aContent, aShell), mAtkObject(nsnull) { #ifdef MAI_LOGGING ++mAccWrapCreated; @@ -362,7 +362,7 @@ NS_IMETHODIMP nsAccessibleWrap::GetNativeInterface(void **aOutAccessible) *aOutAccessible = nsnull; if (!mAtkObject) { - if (IsDefunct() || !nsAccUtils::IsEmbeddedObject(this)) { + if (!mWeakShell || !nsAccUtils::IsEmbeddedObject(this)) { // We don't create ATK objects for node which has been shutdown, or // nsIAccessible plain text leaves return NS_ERROR_FAILURE; diff --git a/accessible/src/atk/nsAccessibleWrap.h b/accessible/src/atk/nsAccessibleWrap.h index 6e4e200eb73..4f8a9c4717b 100644 --- a/accessible/src/atk/nsAccessibleWrap.h +++ b/accessible/src/atk/nsAccessibleWrap.h @@ -84,7 +84,7 @@ class MaiHyperlink; class nsAccessibleWrap: public nsAccessible { public: - nsAccessibleWrap(nsIContent* aContent, nsDocAccessible* aDoc); + nsAccessibleWrap(nsIContent *aContent, nsIWeakReference *aShell); virtual ~nsAccessibleWrap(); void ShutdownAtkObject(); diff --git a/accessible/src/base/FocusManager.cpp b/accessible/src/base/FocusManager.cpp index b85cbd39a4b..627ec014b65 100644 --- a/accessible/src/base/FocusManager.cpp +++ b/accessible/src/base/FocusManager.cpp @@ -63,11 +63,8 @@ FocusManager::FocusedAccessible() const return mActiveItem; nsINode* focusedNode = FocusedDOMNode(); - if (focusedNode) { - nsDocAccessible* doc = - GetAccService()->GetDocAccessible(focusedNode->OwnerDoc()); - return doc ? doc->GetAccessibleOrContainer(focusedNode) : nsnull; - } + if (focusedNode) + return GetAccService()->GetAccessibleOrContainer(focusedNode, nsnull); return nsnull; } @@ -87,10 +84,8 @@ FocusManager::IsFocused(const nsAccessible* aAccessible) const // FocusedAccessible() method call. Make sure this issue is fixed in // bug 638465. if (focusedNode->OwnerDoc() == aAccessible->GetNode()->OwnerDoc()) { - nsDocAccessible* doc = - GetAccService()->GetDocAccessible(focusedNode->OwnerDoc()); return aAccessible == - (doc ? doc->GetAccessibleOrContainer(focusedNode) : nsnull); + GetAccService()->GetAccessibleOrContainer(focusedNode, nsnull); } } return false; @@ -214,7 +209,7 @@ FocusManager::ActiveItemChanged(nsAccessible* aItem, bool aCheckIfActive) // DOM focus. nsAccessible* target = FocusedAccessible(); if (target) - DispatchFocusEvent(target->Document(), target); + DispatchFocusEvent(target->GetDocAccessible(), target); } void @@ -256,11 +251,11 @@ FocusManager::ProcessDOMFocus(nsINode* aTarget) GetAccService()->GetDocAccessible(aTarget->OwnerDoc()); nsAccessible* target = document->GetAccessibleOrContainer(aTarget); - if (target && document) { + if (target) { // Check if still focused. Otherwise we can end up with storing the active // item for control that isn't focused anymore. nsAccessible* DOMFocus = - document->GetAccessibleOrContainer(FocusedDOMNode()); + GetAccService()->GetAccessibleOrContainer(FocusedDOMNode(), nsnull); if (target != DOMFocus) return; @@ -290,8 +285,7 @@ FocusManager::ProcessFocusEvent(AccEvent* aEvent) // Check if still focused. Otherwise we can end up with storing the active // item for control that isn't focused anymore. nsAccessible* DOMFocus = - GetAccService()->GetAccessibleOrContainer(FocusedDOMNode(), - aEvent->GetDocAccessible()); + GetAccService()->GetAccessibleOrContainer(FocusedDOMNode(), nsnull); if (target != DOMFocus) return; @@ -347,7 +341,7 @@ FocusManager::ProcessFocusEvent(AccEvent* aEvent) // Fire scrolling_start event when the document receives the focus if it has // an anchor jump. If an accessible within the document receive the focus // then null out the anchor jump because it no longer applies. - nsDocAccessible* targetDocument = target->Document(); + nsDocAccessible* targetDocument = target->GetDocAccessible(); nsAccessible* anchorJump = targetDocument->AnchorJump(); if (anchorJump) { if (target == targetDocument) { diff --git a/accessible/src/base/NotificationController.cpp b/accessible/src/base/NotificationController.cpp index eb3c67e578a..670796fa124 100644 --- a/accessible/src/base/NotificationController.cpp +++ b/accessible/src/base/NotificationController.cpp @@ -671,7 +671,7 @@ NotificationController::CreateTextChangeEventFor(AccMutationEvent* aEvent) { nsAccessible* container = GetAccService()->GetContainerAccessible(aEvent->mNode, - aEvent->GetDocAccessible()); + aEvent->mAccessible->GetWeakShell()); if (!container) return; diff --git a/accessible/src/base/nsARIAGridAccessible.cpp b/accessible/src/base/nsARIAGridAccessible.cpp index ed7304d59aa..ed0dc98aa64 100644 --- a/accessible/src/base/nsARIAGridAccessible.cpp +++ b/accessible/src/base/nsARIAGridAccessible.cpp @@ -57,8 +57,8 @@ using namespace mozilla::a11y; // Constructor nsARIAGridAccessible:: - nsARIAGridAccessible(nsIContent* aContent, nsDocAccessible* aDoc) : - nsAccessibleWrap(aContent, aDoc) + nsARIAGridAccessible(nsIContent *aContent, nsIWeakReference *aShell) : + nsAccessibleWrap(aContent, aShell) { } @@ -932,8 +932,8 @@ nsARIAGridAccessible::GetSelectedColumnsArray(PRUint32 *acolumnCount, // Constructor nsARIAGridCellAccessible:: - nsARIAGridCellAccessible(nsIContent* aContent, nsDocAccessible* aDoc) : - nsHyperTextAccessibleWrap(aContent, aDoc) + nsARIAGridCellAccessible(nsIContent *aContent, nsIWeakReference *aShell) : + nsHyperTextAccessibleWrap(aContent, aShell) { } diff --git a/accessible/src/base/nsARIAGridAccessible.h b/accessible/src/base/nsARIAGridAccessible.h index 9a1806bc701..b8d0062885e 100644 --- a/accessible/src/base/nsARIAGridAccessible.h +++ b/accessible/src/base/nsARIAGridAccessible.h @@ -50,7 +50,7 @@ class nsARIAGridAccessible : public nsAccessibleWrap, public nsIAccessibleTable { public: - nsARIAGridAccessible(nsIContent* aContent, nsDocAccessible* aDoc); + nsARIAGridAccessible(nsIContent *aContent, nsIWeakReference *aShell); // nsISupports NS_DECL_ISUPPORTS_INHERITED @@ -110,7 +110,7 @@ class nsARIAGridCellAccessible : public nsHyperTextAccessibleWrap, public nsIAccessibleTableCell { public: - nsARIAGridCellAccessible(nsIContent* aContent, nsDocAccessible* aDoc); + nsARIAGridCellAccessible(nsIContent *aContent, nsIWeakReference *aShell); // nsISupports NS_DECL_ISUPPORTS_INHERITED diff --git a/accessible/src/base/nsAccUtils.cpp b/accessible/src/base/nsAccUtils.cpp index c99650885b3..05e56796f1b 100644 --- a/accessible/src/base/nsAccUtils.cpp +++ b/accessible/src/base/nsAccUtils.cpp @@ -353,11 +353,11 @@ nsAccUtils::GetARIAToken(dom::Element* aElement, nsIAtom* aAttr) return nsnull; } -nsAccessible* +nsAccessible * nsAccUtils::GetAncestorWithRole(nsAccessible *aDescendant, PRUint32 aRole) { - nsAccessible* document = aDescendant->Document(); - nsAccessible* parent = aDescendant; + nsAccessible *document = aDescendant->GetDocAccessible(); + nsAccessible *parent = aDescendant; while ((parent = parent->Parent())) { PRUint32 testRole = parent->Role(); if (testRole == aRole) @@ -425,12 +425,11 @@ nsAccUtils::GetTextAccessibleFromSelection(nsISelection* aSelection) nsCOMPtr focusNode(do_QueryInterface(focusDOMNode)); nsCOMPtr resultNode = nsCoreUtils::GetDOMNodeFromDOMPoint(focusNode, focusOffset); + nsCOMPtr weakShell(nsCoreUtils::GetWeakShellFor(resultNode)); // Get text accessible containing the result node. - nsDocAccessible* doc = - GetAccService()->GetDocAccessible(resultNode->OwnerDoc()); - nsAccessible* accessible = doc ? - doc->GetAccessibleOrContainer(resultNode) : nsnull; + nsAccessible* accessible = + GetAccService()->GetAccessibleOrContainer(resultNode, weakShell); if (!accessible) { NS_NOTREACHED("No nsIAccessibleText for selection change event!"); return nsnull; @@ -526,8 +525,9 @@ nsAccUtils::GetScreenCoordsForWindow(nsAccessNode *aAccessNode) nsIntPoint nsAccUtils::GetScreenCoordsForParent(nsAccessNode *aAccessNode) { - nsDocAccessible* document = aAccessNode->Document(); - nsAccessible* parent = document->GetContainerAccessible(aAccessNode->GetNode()); + nsAccessible *parent = + GetAccService()->GetContainerAccessible(aAccessNode->GetNode(), + aAccessNode->GetWeakShell()); if (!parent) return nsIntPoint(0, 0); diff --git a/accessible/src/base/nsAccUtils.h b/accessible/src/base/nsAccUtils.h index b7369902114..2fd8a1ec230 100644 --- a/accessible/src/base/nsAccUtils.h +++ b/accessible/src/base/nsAccUtils.h @@ -156,10 +156,11 @@ public: /** * Return document accessible for the given presshell. */ - static nsDocAccessible* GetDocAccessibleFor(const nsIPresShell* aPresShell) + static nsDocAccessible *GetDocAccessibleFor(nsIWeakReference *aWeakShell) { - return aPresShell ? - GetAccService()->GetDocAccessible(aPresShell->GetDocument()) : nsnull; + nsCOMPtr presShell(do_QueryReferent(aWeakShell)); + return presShell ? + GetAccService()->GetDocAccessible(presShell->GetDocument()) : nsnull; } /** diff --git a/accessible/src/base/nsAccessNode.cpp b/accessible/src/base/nsAccessNode.cpp index 25b3bd96123..1449678273e 100644 --- a/accessible/src/base/nsAccessNode.cpp +++ b/accessible/src/base/nsAccessNode.cpp @@ -89,8 +89,8 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_DESTROY(nsAccessNode, LastRelease()) // nsAccessNode construction/desctruction nsAccessNode:: - nsAccessNode(nsIContent* aContent, nsDocAccessible* aDoc) : - mContent(aContent), mDoc(aDoc) + nsAccessNode(nsIContent *aContent, nsIWeakReference *aShell) : + mContent(aContent), mWeakShell(aShell) { #ifdef DEBUG_A11Y mIsInitialized = false; @@ -99,15 +99,15 @@ nsAccessNode:: nsAccessNode::~nsAccessNode() { - NS_ASSERTION(!mDoc, "LastRelease was never called!?!"); + NS_ASSERTION(!mWeakShell, "LastRelease was never called!?!"); } void nsAccessNode::LastRelease() { // First cleanup if needed... - if (mDoc) { + if (mWeakShell) { Shutdown(); - NS_ASSERTION(!mDoc, "A Shutdown() impl forgot to call its parent's Shutdown?"); + NS_ASSERTION(!mWeakShell, "A Shutdown() impl forgot to call its parent's Shutdown?"); } // ... then die. delete this; @@ -133,7 +133,7 @@ void nsAccessNode::Shutdown() { mContent = nsnull; - mDoc = nsnull; + mWeakShell = nsnull; } nsApplicationAccessible* @@ -215,15 +215,31 @@ void nsAccessNode::ShutdownXPAccessibility() NotifyA11yInitOrShutdown(false); } +already_AddRefed +nsAccessNode::GetPresShell() +{ + nsIPresShell* presShell = nsnull; + if (mWeakShell) + CallQueryReferent(mWeakShell.get(), &presShell); + + return presShell; +} + // nsAccessNode protected nsPresContext* nsAccessNode::GetPresContext() { - if (IsDefunct()) + nsCOMPtr presShell(GetPresShell()); + if (!presShell) { return nsnull; + } + return presShell->GetPresContext(); +} - nsIPresShell* presShell(mDoc->PresShell()); - - return presShell ? presShell->GetPresContext() : nsnull; +nsDocAccessible * +nsAccessNode::GetDocAccessible() const +{ + return mContent ? + GetAccService()->GetDocAccessible(mContent->OwnerDoc()) : nsnull; } nsRootAccessible* @@ -265,7 +281,7 @@ nsAccessNode::ScrollTo(PRUint32 aScrollType) if (IsDefunct()) return; - nsIPresShell* shell = mDoc->PresShell(); + nsCOMPtr shell(GetPresShell()); if (!shell) return; @@ -289,7 +305,9 @@ nsAccessNode::GetCurrentFocus() { // XXX: consider to use nsFocusManager directly, it allows us to avoid // unnecessary query interface calls. - nsIDocument* doc = GetDocumentNode(); + nsCOMPtr shell = GetPresShell(); + NS_ENSURE_TRUE(shell, nsnull); + nsIDocument *doc = shell->GetDocument(); NS_ENSURE_TRUE(doc, nsnull); nsIDOMWindow* win = doc->GetWindow(); diff --git a/accessible/src/base/nsAccessNode.h b/accessible/src/base/nsAccessNode.h index 92d8429347a..1f42653c0af 100644 --- a/accessible/src/base/nsAccessNode.h +++ b/accessible/src/base/nsAccessNode.h @@ -71,7 +71,7 @@ class nsAccessNode: public nsISupports { public: - nsAccessNode(nsIContent* aContent, nsDocAccessible* aDoc); + nsAccessNode(nsIContent *aContent, nsIWeakReference *aShell); virtual ~nsAccessNode(); NS_DECL_CYCLE_COLLECTING_ISUPPORTS @@ -88,7 +88,7 @@ public: /** * Return the document accessible for this access node. */ - nsDocAccessible* Document() const { return mDoc; } + nsDocAccessible *GetDocAccessible() const; /** * Return the root document accessible for this accessnode. @@ -147,6 +147,16 @@ public: return GetNode() && GetNode()->IsNodeOfType(nsINode::eDOCUMENT); } + /** + * Return the corresponding press shell for this accessible. + */ + already_AddRefed GetPresShell(); + + /** + * Return presentation shell for the accessible. + */ + nsIWeakReference* GetWeakShell() const { return mWeakShell; } + /** * Return the unique identifier of the accessible. */ @@ -179,7 +189,7 @@ protected: void LastRelease(); nsCOMPtr mContent; - nsDocAccessible* mDoc; + nsCOMPtr mWeakShell; /** * Notify global nsIObserver's that a11y is getting init'd or shutdown diff --git a/accessible/src/base/nsAccessibilityService.cpp b/accessible/src/base/nsAccessibilityService.cpp index 251ab5c0a08..7c14df58b36 100644 --- a/accessible/src/base/nsAccessibilityService.cpp +++ b/accessible/src/base/nsAccessibilityService.cpp @@ -205,15 +205,14 @@ nsAccessibilityService::GetRootDocumentAccessible(nsIPresShell* aPresShell, } return nsnull; } - + already_AddRefed nsAccessibilityService::CreateOuterDocAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsOuterDocAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsOuterDocAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -221,10 +220,9 @@ already_AddRefed nsAccessibilityService::CreateHTML4ButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTML4ButtonAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTML4ButtonAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -232,10 +230,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLButtonAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLButtonAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -243,10 +240,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLLIAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLLIAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLLIAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -254,10 +250,9 @@ already_AddRefed nsAccessibilityService::CreateHyperTextAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHyperTextAccessibleWrap(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHyperTextAccessibleWrap(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -265,10 +260,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLCheckboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLCheckboxAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLCheckboxAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -276,10 +270,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLComboboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLComboboxAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLComboboxAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -287,10 +280,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLCanvasAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLCanvasAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLCanvasAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -298,10 +290,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLFileInputAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLFileInputAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLFileInputAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -316,13 +307,11 @@ nsAccessibilityService::CreateHTMLImageAccessible(nsIContent* aContent, mapElm = do_QueryInterface(document->FindImageMap(mapElmName)); } + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); nsAccessible* accessible = mapElm ? - new nsHTMLImageMapAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell), - mapElm) : - new nsHTMLImageAccessibleWrap(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + new nsHTMLImageMapAccessible(aContent, weakShell, mapElm) : + new nsHTMLImageAccessibleWrap(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -330,10 +319,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLGroupboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLGroupboxAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLGroupboxAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -341,10 +329,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLListboxAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLSelectListAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLSelectListAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -352,11 +339,10 @@ already_AddRefed nsAccessibilityService::CreateHTMLMediaAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsEnumRoleAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell), - roles::GROUPING); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsEnumRoleAccessible(aContent, weakShell, + roles::GROUPING); + NS_IF_ADDREF(accessible); return accessible; } @@ -376,6 +362,7 @@ nsAccessibilityService::CreateHTMLObjectFrameAccessible(nsObjectFrame* aFrame, if (aFrame->GetRect().IsEmpty()) return nsnull; + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); // 1) for object elements containing either HTML or TXT documents nsCOMPtr obj(do_QueryInterface(aContent)); @@ -396,11 +383,10 @@ nsAccessibilityService::CreateHTMLObjectFrameAccessible(nsObjectFrame* aFrame, HWND pluginPort = nsnull; aFrame->GetPluginPort(&pluginPort); - nsAccessible* accessible = - new nsHTMLWin32ObjectOwnerAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell), - pluginPort); - NS_ADDREF(accessible); + nsAccessible* accessible = new nsHTMLWin32ObjectOwnerAccessible(aContent, + weakShell, + pluginPort); + NS_IF_ADDREF(accessible); return accessible; #elif MOZ_ACCESSIBILITY_ATK @@ -412,11 +398,9 @@ nsAccessibilityService::CreateHTMLObjectFrameAccessible(nsObjectFrame* aFrame, NPPVpluginNativeAccessibleAtkPlugId, &plugId); if (NS_SUCCEEDED(rv) && !plugId.IsEmpty()) { AtkSocketAccessible* socketAccessible = - new AtkSocketAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell), - plugId); + new AtkSocketAccessible(aContent, weakShell, plugId); - NS_ADDREF(socketAccessible); + NS_IF_ADDREF(socketAccessible); return socketAccessible; } #endif @@ -433,10 +417,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLRadioButtonAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLRadioButtonAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLRadioButtonAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -444,10 +427,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLTableAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLTableAccessibleWrap(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLTableAccessibleWrap(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -455,10 +437,10 @@ already_AddRefed nsAccessibilityService::CreateHTMLTableCellAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLTableCellAccessibleWrap(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLTableCellAccessibleWrap(aContent, + weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -466,10 +448,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLTextAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLTextAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLTextAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -477,10 +458,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLTextFieldAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLTextFieldAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLTextFieldAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -488,10 +468,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLLabelAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLLabelAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLLabelAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -499,10 +478,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLHRAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLHRAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLHRAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -510,10 +488,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLBRAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLBRAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLBRAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -521,10 +498,9 @@ already_AddRefed nsAccessibilityService::CreateHTMLCaptionAccessible(nsIContent* aContent, nsIPresShell* aPresShell) { - nsAccessible* accessible = - new nsHTMLCaptionAccessible(aContent, - nsAccUtils::GetDocAccessibleFor(aPresShell)); - NS_ADDREF(accessible); + nsCOMPtr weakShell(do_GetWeakReference(aPresShell)); + nsAccessible* accessible = new nsHTMLCaptionAccessible(aContent, weakShell); + NS_IF_ADDREF(accessible); return accessible; } @@ -931,14 +907,15 @@ nsAccessibilityService::GetAccessible(nsINode* aNode) } nsAccessible* -nsAccessibilityService::GetAccessibleOrContainer(nsINode* aNode, nsDocAccessible* aDoc) +nsAccessibilityService::GetAccessibleOrContainer(nsINode* aNode, + nsIWeakReference* aWeakShell) { if (!aNode) return nsnull; - NS_PRECONDITION(aDoc, "Must pass a document accessible."); - - return aDoc ? aDoc->GetAccessibleOrContainer(aNode) : nsnull; + // XXX: weak shell is ignored until multiple shell documents are supported. + nsDocAccessible* document = GetDocAccessible(aNode->OwnerDoc()); + return document ? document->GetAccessibleOrContainer(aNode) : nsnull; } static bool HasRelatedContent(nsIContent *aContent) @@ -1080,7 +1057,7 @@ nsAccessibilityService::GetOrCreateAccessible(nsINode* aNode, return nsnull; } - newAcc = new nsHyperTextAccessibleWrap(content, docAcc); + newAcc = new nsHyperTextAccessibleWrap(content, aWeakShell); if (docAcc->BindToDocument(newAcc, nsAccUtils::GetRoleMapEntry(aNode))) return newAcc; return nsnull; @@ -1174,12 +1151,12 @@ nsAccessibilityService::GetOrCreateAccessible(nsINode* aNode, if (roleMapEntry->role == roles::TABLE || roleMapEntry->role == roles::TREE_TABLE) { - newAcc = new nsARIAGridAccessibleWrap(content, docAcc); + newAcc = new nsARIAGridAccessibleWrap(content, aWeakShell); } else if (roleMapEntry->role == roles::GRID_CELL || roleMapEntry->role == roles::ROWHEADER || roleMapEntry->role == roles::COLUMNHEADER) { - newAcc = new nsARIAGridCellAccessibleWrap(content, docAcc); + newAcc = new nsARIAGridCellAccessibleWrap(content, aWeakShell); } } } @@ -1191,7 +1168,7 @@ nsAccessibilityService::GetOrCreateAccessible(nsINode* aNode, // we do not call it if accessibles for table related content are // prevented above. newAcc = CreateHTMLAccessibleByMarkup(weakFrame.GetFrame(), content, - docAcc); + aWeakShell); if (!newAcc) { // Do not create accessible object subtrees for non-rendered table @@ -1223,24 +1200,24 @@ nsAccessibilityService::GetOrCreateAccessible(nsINode* aNode, if (!newAcc) { // Elements may implement nsIAccessibleProvider via XBL. This allows them to // say what kind of accessible to create. - newAcc = CreateAccessibleByType(content, docAcc); + newAcc = CreateAccessibleByType(content, aWeakShell); } if (!newAcc) { // Create generic accessibles for SVG and MathML nodes. if (content->IsSVG(nsGkAtoms::svg)) { - newAcc = new nsEnumRoleAccessible(content, docAcc, + newAcc = new nsEnumRoleAccessible(content, aWeakShell, roles::DIAGRAM); } else if (content->IsMathML(nsGkAtoms::math)) { - newAcc = new nsEnumRoleAccessible(content, docAcc, + newAcc = new nsEnumRoleAccessible(content, aWeakShell, roles::EQUATION); } } if (!newAcc) { newAcc = CreateAccessibleForDeckChild(weakFrame.GetFrame(), content, - docAcc); + aWeakShell); } // If no accessible, see if we need to create a generic accessible because @@ -1257,11 +1234,11 @@ nsAccessibilityService::GetOrCreateAccessible(nsINode* aNode, // other accessibles can point to it, or so that it can hold a state, etc. if (isHTML) { // Interesting HTML container which may have selectable text and/or embedded objects - newAcc = new nsHyperTextAccessibleWrap(content, docAcc); + newAcc = new nsHyperTextAccessibleWrap(content, aWeakShell); } else { // XUL, SVG, MathML etc. // Interesting generic non-HTML container - newAcc = new nsAccessibleWrap(content, docAcc); + newAcc = new nsAccessibleWrap(content, aWeakShell); } } @@ -1342,7 +1319,7 @@ nsAccessibilityService::HasUniversalAriaProperty(nsIContent *aContent) already_AddRefed nsAccessibilityService::CreateAccessibleByType(nsIContent* aContent, - nsDocAccessible* aDoc) + nsIWeakReference* aWeakShell) { nsCOMPtr accessibleProvider(do_QueryInterface(aContent)); if (!accessibleProvider) @@ -1354,7 +1331,7 @@ nsAccessibilityService::CreateAccessibleByType(nsIContent* aContent, return nsnull; if (type == nsIAccessibleProvider::OuterDoc) { - nsAccessible* accessible = new nsOuterDocAccessible(aContent, aDoc); + nsAccessible* accessible = new nsOuterDocAccessible(aContent, aWeakShell); NS_IF_ADDREF(accessible); return accessible; } @@ -1368,35 +1345,35 @@ nsAccessibilityService::CreateAccessibleByType(nsIContent* aContent, // XUL controls case nsIAccessibleProvider::XULAlert: - accessible = new nsXULAlertAccessible(aContent, aDoc); + accessible = new nsXULAlertAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULButton: - accessible = new nsXULButtonAccessible(aContent, aDoc); + accessible = new nsXULButtonAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULCheckbox: - accessible = new nsXULCheckboxAccessible(aContent, aDoc); + accessible = new nsXULCheckboxAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULColorPicker: - accessible = new nsXULColorPickerAccessible(aContent, aDoc); + accessible = new nsXULColorPickerAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULColorPickerTile: - accessible = new nsXULColorPickerTileAccessible(aContent, aDoc); + accessible = new nsXULColorPickerTileAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULCombobox: - accessible = new nsXULComboboxAccessible(aContent, aDoc); + accessible = new nsXULComboboxAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULDropmarker: - accessible = new nsXULDropmarkerAccessible(aContent, aDoc); + accessible = new nsXULDropmarkerAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULGroupbox: - accessible = new nsXULGroupboxAccessible(aContent, aDoc); + accessible = new nsXULGroupboxAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULImage: @@ -1406,40 +1383,40 @@ nsAccessibilityService::CreateAccessibleByType(nsIContent* aContent, nsGkAtoms::tooltiptext)) return nsnull; - accessible = new nsHTMLImageAccessibleWrap(aContent, aDoc); + accessible = new nsHTMLImageAccessibleWrap(aContent, aWeakShell); break; } case nsIAccessibleProvider::XULLink: - accessible = new nsXULLinkAccessible(aContent, aDoc); + accessible = new nsXULLinkAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULListbox: - accessible = new nsXULListboxAccessibleWrap(aContent, aDoc); + accessible = new nsXULListboxAccessibleWrap(aContent, aWeakShell); break; case nsIAccessibleProvider::XULListCell: - accessible = new nsXULListCellAccessibleWrap(aContent, aDoc); + accessible = new nsXULListCellAccessibleWrap(aContent, aWeakShell); break; case nsIAccessibleProvider::XULListHead: - accessible = new nsXULColumnsAccessible(aContent, aDoc); + accessible = new nsXULColumnsAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULListHeader: - accessible = new nsXULColumnItemAccessible(aContent, aDoc); + accessible = new nsXULColumnItemAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULListitem: - accessible = new nsXULListitemAccessible(aContent, aDoc); + accessible = new nsXULListitemAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULMenubar: - accessible = new nsXULMenubarAccessible(aContent, aDoc); + accessible = new nsXULMenubarAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULMenuitem: - accessible = new nsXULMenuitemAccessibleWrap(aContent, aDoc); + accessible = new nsXULMenuitemAccessibleWrap(aContent, aWeakShell); break; case nsIAccessibleProvider::XULMenupopup: @@ -1455,167 +1432,167 @@ nsAccessibilityService::CreateAccessibleByType(nsIContent* aContent, kNameSpaceID_XUL)) return nsnull; #endif - accessible = new nsXULMenupopupAccessible(aContent, aDoc); + accessible = new nsXULMenupopupAccessible(aContent, aWeakShell); break; } case nsIAccessibleProvider::XULMenuSeparator: - accessible = new nsXULMenuSeparatorAccessible(aContent, aDoc); + accessible = new nsXULMenuSeparatorAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULPane: - accessible = new nsEnumRoleAccessible(aContent, aDoc, + accessible = new nsEnumRoleAccessible(aContent, aWeakShell, roles::PANE); break; case nsIAccessibleProvider::XULProgressMeter: - accessible = new XULProgressMeterAccessible(aContent, aDoc); + accessible = new XULProgressMeterAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULStatusBar: - accessible = new nsXULStatusBarAccessible(aContent, aDoc); + accessible = new nsXULStatusBarAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULScale: - accessible = new nsXULSliderAccessible(aContent, aDoc); + accessible = new nsXULSliderAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULRadioButton: - accessible = new nsXULRadioButtonAccessible(aContent, aDoc); + accessible = new nsXULRadioButtonAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULRadioGroup: - accessible = new nsXULRadioGroupAccessible(aContent, aDoc); + accessible = new nsXULRadioGroupAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULTab: - accessible = new nsXULTabAccessible(aContent, aDoc); + accessible = new nsXULTabAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULTabs: - accessible = new nsXULTabsAccessible(aContent, aDoc); + accessible = new nsXULTabsAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULTabpanels: - accessible = new nsXULTabpanelsAccessible(aContent, aDoc); + accessible = new nsXULTabpanelsAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULText: - accessible = new nsXULTextAccessible(aContent, aDoc); + accessible = new nsXULTextAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULTextBox: - accessible = new nsXULTextFieldAccessible(aContent, aDoc); + accessible = new nsXULTextFieldAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULThumb: - accessible = new nsXULThumbAccessible(aContent, aDoc); + accessible = new nsXULThumbAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULTree: - return CreateAccessibleForXULTree(aContent, aDoc); + return CreateAccessibleForXULTree(aContent, aWeakShell); case nsIAccessibleProvider::XULTreeColumns: - accessible = new nsXULTreeColumnsAccessible(aContent, aDoc); + accessible = new nsXULTreeColumnsAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULTreeColumnItem: - accessible = new nsXULColumnItemAccessible(aContent, aDoc); + accessible = new nsXULColumnItemAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULToolbar: - accessible = new nsXULToolbarAccessible(aContent, aDoc); + accessible = new nsXULToolbarAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULToolbarSeparator: - accessible = new nsXULToolbarSeparatorAccessible(aContent, aDoc); + accessible = new nsXULToolbarSeparatorAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULTooltip: - accessible = new nsXULTooltipAccessible(aContent, aDoc); + accessible = new nsXULTooltipAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XULToolbarButton: - accessible = new nsXULToolbarButtonAccessible(aContent, aDoc); + accessible = new nsXULToolbarButtonAccessible(aContent, aWeakShell); break; #endif // MOZ_XUL // XForms elements case nsIAccessibleProvider::XFormsContainer: - accessible = new nsXFormsContainerAccessible(aContent, aDoc); + accessible = new nsXFormsContainerAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsLabel: - accessible = new nsXFormsLabelAccessible(aContent, aDoc); + accessible = new nsXFormsLabelAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsOutput: - accessible = new nsXFormsOutputAccessible(aContent, aDoc); + accessible = new nsXFormsOutputAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsTrigger: - accessible = new nsXFormsTriggerAccessible(aContent, aDoc); + accessible = new nsXFormsTriggerAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsInput: - accessible = new nsXFormsInputAccessible(aContent, aDoc); + accessible = new nsXFormsInputAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsInputBoolean: - accessible = new nsXFormsInputBooleanAccessible(aContent, aDoc); + accessible = new nsXFormsInputBooleanAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsInputDate: - accessible = new nsXFormsInputDateAccessible(aContent, aDoc); + accessible = new nsXFormsInputDateAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsSecret: - accessible = new nsXFormsSecretAccessible(aContent, aDoc); + accessible = new nsXFormsSecretAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsSliderRange: - accessible = new nsXFormsRangeAccessible(aContent, aDoc); + accessible = new nsXFormsRangeAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsSelect: - accessible = new nsXFormsSelectAccessible(aContent, aDoc); + accessible = new nsXFormsSelectAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsChoices: - accessible = new nsXFormsChoicesAccessible(aContent, aDoc); + accessible = new nsXFormsChoicesAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsSelectFull: - accessible = new nsXFormsSelectFullAccessible(aContent, aDoc); + accessible = new nsXFormsSelectFullAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsItemCheckgroup: - accessible = new nsXFormsItemCheckgroupAccessible(aContent, aDoc); + accessible = new nsXFormsItemCheckgroupAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsItemRadiogroup: - accessible = new nsXFormsItemRadiogroupAccessible(aContent, aDoc); + accessible = new nsXFormsItemRadiogroupAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsSelectCombobox: - accessible = new nsXFormsSelectComboboxAccessible(aContent, aDoc); + accessible = new nsXFormsSelectComboboxAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsItemCombobox: - accessible = new nsXFormsItemComboboxAccessible(aContent, aDoc); + accessible = new nsXFormsItemComboboxAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsDropmarkerWidget: - accessible = new nsXFormsDropmarkerWidgetAccessible(aContent, aDoc); + accessible = new nsXFormsDropmarkerWidgetAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsCalendarWidget: - accessible = new nsXFormsCalendarWidgetAccessible(aContent, aDoc); + accessible = new nsXFormsCalendarWidgetAccessible(aContent, aWeakShell); break; case nsIAccessibleProvider::XFormsComboboxPopupWidget: - accessible = new nsXFormsComboboxPopupWidgetAccessible(aContent, aDoc); + accessible = new nsXFormsComboboxPopupWidgetAccessible(aContent, aWeakShell); break; default: @@ -1629,45 +1606,46 @@ nsAccessibilityService::CreateAccessibleByType(nsIContent* aContent, already_AddRefed nsAccessibilityService::CreateHTMLAccessibleByMarkup(nsIFrame* aFrame, nsIContent* aContent, - nsDocAccessible* aDoc) + nsIWeakReference* aWeakShell) { // This method assumes we're in an HTML namespace. nsIAtom* tag = aContent->Tag(); if (tag == nsGkAtoms::figcaption) { nsAccessible* accessible = - new nsHTMLFigcaptionAccessible(aContent, aDoc); + new nsHTMLFigcaptionAccessible(aContent, aWeakShell); NS_IF_ADDREF(accessible); return accessible; } if (tag == nsGkAtoms::figure) { - nsAccessible* accessible = new nsHTMLFigureAccessible(aContent, aDoc); + nsAccessible* accessible = new nsHTMLFigureAccessible(aContent, aWeakShell); NS_IF_ADDREF(accessible); return accessible; } if (tag == nsGkAtoms::legend) { - nsAccessible* accessible = new nsHTMLLegendAccessible(aContent, aDoc); + nsAccessible* accessible = new nsHTMLLegendAccessible(aContent, aWeakShell); NS_IF_ADDREF(accessible); return accessible; } if (tag == nsGkAtoms::option) { - nsAccessible* accessible = new nsHTMLSelectOptionAccessible(aContent, aDoc); + nsAccessible* accessible = new nsHTMLSelectOptionAccessible(aContent, + aWeakShell); NS_IF_ADDREF(accessible); return accessible; } if (tag == nsGkAtoms::optgroup) { nsAccessible* accessible = new nsHTMLSelectOptGroupAccessible(aContent, - aDoc); + aWeakShell); NS_IF_ADDREF(accessible); return accessible; } if (tag == nsGkAtoms::ul || tag == nsGkAtoms::ol || tag == nsGkAtoms::dl) { - nsAccessible* accessible = new nsHTMLListAccessible(aContent, aDoc); + nsAccessible* accessible = new nsHTMLListAccessible(aContent, aWeakShell); NS_IF_ADDREF(accessible); return accessible; } @@ -1678,12 +1656,13 @@ nsAccessibilityService::CreateHTMLAccessibleByMarkup(nsIFrame* aFrame, nsRoleMapEntry *roleMapEntry = nsAccUtils::GetRoleMapEntry(aContent); if (roleMapEntry && roleMapEntry->role != roles::NOTHING && roleMapEntry->role != roles::LINK) { - nsAccessible* accessible = new nsHyperTextAccessibleWrap(aContent, aDoc); + nsAccessible* accessible = new nsHyperTextAccessibleWrap(aContent, + aWeakShell); NS_IF_ADDREF(accessible); return accessible; } - nsAccessible* accessible = new nsHTMLLinkAccessible(aContent, aDoc); + nsAccessible* accessible = new nsHTMLLinkAccessible(aContent, aWeakShell); NS_IF_ADDREF(accessible); return accessible; } @@ -1694,7 +1673,7 @@ nsAccessibilityService::CreateHTMLAccessibleByMarkup(nsIFrame* aFrame, // Normally for li, it is created by the list item frame (in nsBlockFrame) // which knows about the bullet frame; however, in this case the list item // must have been styled using display: foo - nsAccessible* accessible = new nsHTMLLIAccessible(aContent, aDoc); + nsAccessible* accessible = new nsHTMLLIAccessible(aContent, aWeakShell); NS_IF_ADDREF(accessible); return accessible; } @@ -1711,13 +1690,13 @@ nsAccessibilityService::CreateHTMLAccessibleByMarkup(nsIFrame* aFrame, tag == nsGkAtoms::h5 || tag == nsGkAtoms::h6 || tag == nsGkAtoms::q) { - nsAccessible* accessible = new nsHyperTextAccessibleWrap(aContent, aDoc); + nsAccessible* accessible = new nsHyperTextAccessibleWrap(aContent, aWeakShell); NS_IF_ADDREF(accessible); return accessible; } if (tag == nsGkAtoms::tr) { - nsAccessible* accessible = new nsEnumRoleAccessible(aContent, aDoc, + nsAccessible* accessible = new nsEnumRoleAccessible(aContent, aWeakShell, roles::ROW); NS_IF_ADDREF(accessible); return accessible; @@ -1725,20 +1704,20 @@ nsAccessibilityService::CreateHTMLAccessibleByMarkup(nsIFrame* aFrame, if (nsCoreUtils::IsHTMLTableHeader(aContent)) { nsAccessible* accessible = new nsHTMLTableHeaderCellAccessibleWrap(aContent, - aDoc); + aWeakShell); NS_IF_ADDREF(accessible); return accessible; } if (tag == nsGkAtoms::output) { - nsAccessible* accessible = new nsHTMLOutputAccessible(aContent, aDoc); + nsAccessible* accessible = new nsHTMLOutputAccessible(aContent, aWeakShell); NS_IF_ADDREF(accessible); return accessible; } if (tag == nsGkAtoms::progress) { nsAccessible* accessible = - new HTMLProgressMeterAccessible(aContent, aDoc); + new HTMLProgressMeterAccessible(aContent, aWeakShell); NS_IF_ADDREF(accessible); return accessible; } @@ -1822,7 +1801,7 @@ NS_GetAccessibilityService(nsIAccessibilityService** aResult) already_AddRefed nsAccessibilityService::CreateAccessibleForDeckChild(nsIFrame* aFrame, nsIContent* aContent, - nsDocAccessible* aDoc) + nsIWeakReference* aWeakShell) { if (aFrame->GetType() == nsGkAtoms::boxFrame || aFrame->GetType() == nsGkAtoms::scrollFrame) { @@ -1835,12 +1814,13 @@ nsAccessibilityService::CreateAccessibleForDeckChild(nsIFrame* aFrame, #ifdef MOZ_XUL if (parentContent->NodeInfo()->Equals(nsGkAtoms::tabpanels, kNameSpaceID_XUL)) { - nsAccessible* accessible = new nsXULTabpanelAccessible(aContent, aDoc); + nsAccessible* accessible = new nsXULTabpanelAccessible(aContent, + aWeakShell); NS_IF_ADDREF(accessible); return accessible; } #endif - nsAccessible* accessible = new nsEnumRoleAccessible(aContent, aDoc, + nsAccessible* accessible = new nsEnumRoleAccessible(aContent, aWeakShell, roles::PROPERTYPAGE); NS_IF_ADDREF(accessible); return accessible; @@ -1853,7 +1833,7 @@ nsAccessibilityService::CreateAccessibleForDeckChild(nsIFrame* aFrame, #ifdef MOZ_XUL already_AddRefed nsAccessibilityService::CreateAccessibleForXULTree(nsIContent* aContent, - nsDocAccessible* aDoc) + nsIWeakReference* aWeakShell) { nsCOMPtr treeBoxObj = nsCoreUtils::GetTreeBoxObject(aContent); if (!treeBoxObj) @@ -1869,13 +1849,13 @@ nsAccessibilityService::CreateAccessibleForXULTree(nsIContent* aContent, // Outline of list accessible. if (count == 1) { - nsAccessible* accessible = new nsXULTreeAccessible(aContent, aDoc); + nsAccessible* accessible = new nsXULTreeAccessible(aContent, aWeakShell); NS_IF_ADDREF(accessible); return accessible; } // Table or tree table accessible. - nsAccessible* accessible = new nsXULTreeGridAccessibleWrap(aContent, aDoc); + nsAccessible* accessible = new nsXULTreeGridAccessibleWrap(aContent, aWeakShell); NS_IF_ADDREF(accessible); return accessible; } diff --git a/accessible/src/base/nsAccessibilityService.h b/accessible/src/base/nsAccessibilityService.h index e0290699f4d..50016ae7859 100644 --- a/accessible/src/base/nsAccessibilityService.h +++ b/accessible/src/base/nsAccessibilityService.h @@ -216,19 +216,18 @@ public: /** * Return an accessible for the given DOM node or container accessible if * the node is not accessible. - * - * @param aNode [in] the given node - * @param aDoc [in] the document accessible. Can't be null. */ - nsAccessible* GetAccessibleOrContainer(nsINode* aNode, nsDocAccessible* aDoc); + nsAccessible* GetAccessibleOrContainer(nsINode* aNode, + nsIWeakReference* aWeakShell); /** * Return a container accessible for the given DOM node. */ - nsAccessible* GetContainerAccessible(nsINode* aNode, nsDocAccessible* aDoc) + inline nsAccessible* GetContainerAccessible(nsINode* aNode, + nsIWeakReference* aWeakShell) { return aNode ? - GetAccessibleOrContainer(aNode->GetNodeParent(), aDoc) : nsnull; + GetAccessibleOrContainer(aNode->GetNodeParent(), aWeakShell) : nsnull; } private: @@ -254,28 +253,28 @@ private: * interface. */ already_AddRefed - CreateAccessibleByType(nsIContent* aContent, nsDocAccessible* aDoc); + CreateAccessibleByType(nsIContent* aContent, nsIWeakReference* aWeakShell); /** * Create accessible for HTML node by tag name. */ already_AddRefed CreateHTMLAccessibleByMarkup(nsIFrame* aFrame, nsIContent* aContent, - nsDocAccessible* aDoc); + nsIWeakReference* aWeakShell); /** * Create accessible if parent is a deck frame. */ already_AddRefed CreateAccessibleForDeckChild(nsIFrame* aFrame, nsIContent* aContent, - nsDocAccessible* aDoc); + nsIWeakReference* aWeakShell); #ifdef MOZ_XUL /** * Create accessible for XUL tree element. */ already_AddRefed - CreateAccessibleForXULTree(nsIContent* aContent, nsDocAccessible* aDoc); + CreateAccessibleForXULTree(nsIContent* aContent, nsIWeakReference* aWeakShell); #endif /** diff --git a/accessible/src/base/nsAccessible.cpp b/accessible/src/base/nsAccessible.cpp index 0f142525a72..fee4778348b 100644 --- a/accessible/src/base/nsAccessible.cpp +++ b/accessible/src/base/nsAccessible.cpp @@ -193,8 +193,8 @@ nsresult nsAccessible::QueryInterface(REFNSIID aIID, void** aInstancePtr) return nsAccessNodeWrap::QueryInterface(aIID, aInstancePtr); } -nsAccessible::nsAccessible(nsIContent* aContent, nsDocAccessible* aDoc) : - nsAccessNodeWrap(aContent, aDoc), +nsAccessible::nsAccessible(nsIContent *aContent, nsIWeakReference *aShell) : + nsAccessNodeWrap(aContent, aShell), mParent(nsnull), mIndexInParent(-1), mFlags(eChildrenUninitialized), mIndexOfEmbeddedChild(-1), mRoleMapEntry(nsnull) { @@ -273,7 +273,7 @@ nsAccessible::GetDocument(nsIAccessibleDocument **aDocument) { NS_ENSURE_ARG_POINTER(aDocument); - NS_IF_ADDREF(*aDocument = Document()); + NS_IF_ADDREF(*aDocument = GetDocAccessible()); return NS_OK; } @@ -400,7 +400,7 @@ nsAccessible::Description(nsString& aDescription) bool isXUL = mContent->IsXUL(); if (isXUL) { // Try XUL description text - XULDescriptionIterator iter(Document(), mContent); + XULDescriptionIterator iter(GetDocAccessible(), mContent); nsAccessible* descr = nsnull; while ((descr = iter.Next())) nsTextEquivUtils::AppendTextEquivFromContent(this, descr->GetContent(), @@ -446,12 +446,12 @@ nsAccessible::AccessKey() const if (mContent->IsHTML()) { // Unless it is labeled via an ancestor