diff --git a/accessible/base/NotificationController.cpp b/accessible/base/NotificationController.cpp index 0bae0db3a00..6ca5280ec10 100644 --- a/accessible/base/NotificationController.cpp +++ b/accessible/base/NotificationController.cpp @@ -204,7 +204,89 @@ NotificationController::WillRefresh(mozilla::TimeStamp aTime) } // Process rendered text change notifications. - mTextHash.EnumerateEntries(TextEnumerator, mDocument); + for (auto iter = mTextHash.Iter(); !iter.Done(); iter.Next()) { + nsCOMPtrHashKey* entry = iter.Get(); + nsIContent* textNode = entry->GetKey(); + Accessible* textAcc = mDocument->GetAccessible(textNode); + + // If the text node is not in tree or doesn't have frame then this case should + // have been handled already by content removal notifications. + nsINode* containerNode = textNode->GetParentNode(); + if (!containerNode) { + NS_ASSERTION(!textAcc, + "Text node was removed but accessible is kept alive!"); + continue; + } + + nsIFrame* textFrame = textNode->GetPrimaryFrame(); + if (!textFrame) { + NS_ASSERTION(!textAcc, + "Text node isn't rendered but accessible is kept alive!"); + continue; + } + + nsIContent* containerElm = containerNode->IsElement() ? + containerNode->AsElement() : nullptr; + + nsAutoString text; + textFrame->GetRenderedText(&text); + + // Remove text accessible if rendered text is empty. + if (textAcc) { + if (text.IsEmpty()) { + #ifdef A11Y_LOG + if (logging::IsEnabled(logging::eTree | logging::eText)) { + logging::MsgBegin("TREE", "text node lost its content"); + logging::Node("container", containerElm); + logging::Node("content", textNode); + logging::MsgEnd(); + } + #endif + + mDocument->ContentRemoved(containerElm, textNode); + continue; + } + + // Update text of the accessible and fire text change events. + #ifdef A11Y_LOG + if (logging::IsEnabled(logging::eText)) { + logging::MsgBegin("TEXT", "text may be changed"); + logging::Node("container", containerElm); + logging::Node("content", textNode); + logging::MsgEntry("old text '%s'", + NS_ConvertUTF16toUTF8(textAcc->AsTextLeaf()->Text()).get()); + logging::MsgEntry("new text: '%s'", + NS_ConvertUTF16toUTF8(text).get()); + logging::MsgEnd(); + } + #endif + + TextUpdater::Run(mDocument, textAcc->AsTextLeaf(), text); + continue; + } + + // Append an accessible if rendered text is not empty. + if (!text.IsEmpty()) { + #ifdef A11Y_LOG + if (logging::IsEnabled(logging::eTree | logging::eText)) { + logging::MsgBegin("TREE", "text node gains new content"); + logging::Node("container", containerElm); + logging::Node("content", textNode); + logging::MsgEnd(); + } + #endif + + // Make sure the text node is in accessible document still. + Accessible* container = mDocument->GetAccessibleOrContainer(containerNode); + NS_ASSERTION(container, + "Text node having rendered text hasn't accessible document!"); + if (container) { + nsTArray > insertedContents; + insertedContents.AppendElement(textNode); + mDocument->ProcessContentInserted(container, &insertedContents); + } + } + } mTextHash.Clear(); // Bind hanging child documents. @@ -314,99 +396,6 @@ NotificationController::WillRefresh(mozilla::TimeStamp aTime) } } -//////////////////////////////////////////////////////////////////////////////// -// Notification controller: text leaf accessible text update - -PLDHashOperator -NotificationController::TextEnumerator(nsCOMPtrHashKey* aEntry, - void* aUserArg) -{ - DocAccessible* document = static_cast(aUserArg); - nsIContent* textNode = aEntry->GetKey(); - Accessible* textAcc = document->GetAccessible(textNode); - - // If the text node is not in tree or doesn't have frame then this case should - // have been handled already by content removal notifications. - nsINode* containerNode = textNode->GetParentNode(); - if (!containerNode) { - NS_ASSERTION(!textAcc, - "Text node was removed but accessible is kept alive!"); - return PL_DHASH_NEXT; - } - - nsIFrame* textFrame = textNode->GetPrimaryFrame(); - if (!textFrame) { - NS_ASSERTION(!textAcc, - "Text node isn't rendered but accessible is kept alive!"); - return PL_DHASH_NEXT; - } - - nsIContent* containerElm = containerNode->IsElement() ? - containerNode->AsElement() : nullptr; - - nsAutoString text; - textFrame->GetRenderedText(&text); - - // Remove text accessible if rendered text is empty. - if (textAcc) { - if (text.IsEmpty()) { -#ifdef A11Y_LOG - if (logging::IsEnabled(logging::eTree | logging::eText)) { - logging::MsgBegin("TREE", "text node lost its content"); - logging::Node("container", containerElm); - logging::Node("content", textNode); - logging::MsgEnd(); - } -#endif - - document->ContentRemoved(containerElm, textNode); - return PL_DHASH_NEXT; - } - - // Update text of the accessible and fire text change events. -#ifdef A11Y_LOG - if (logging::IsEnabled(logging::eText)) { - logging::MsgBegin("TEXT", "text may be changed"); - logging::Node("container", containerElm); - logging::Node("content", textNode); - logging::MsgEntry("old text '%s'", - NS_ConvertUTF16toUTF8(textAcc->AsTextLeaf()->Text()).get()); - logging::MsgEntry("new text: '%s'", - NS_ConvertUTF16toUTF8(text).get()); - logging::MsgEnd(); - } -#endif - - TextUpdater::Run(document, textAcc->AsTextLeaf(), text); - return PL_DHASH_NEXT; - } - - // Append an accessible if rendered text is not empty. - if (!text.IsEmpty()) { -#ifdef A11Y_LOG - if (logging::IsEnabled(logging::eTree | logging::eText)) { - logging::MsgBegin("TREE", "text node gains new content"); - logging::Node("container", containerElm); - logging::Node("content", textNode); - logging::MsgEnd(); - } -#endif - - // Make sure the text node is in accessible document still. - Accessible* container = document->GetAccessibleOrContainer(containerNode); - NS_ASSERTION(container, - "Text node having rendered text hasn't accessible document!"); - if (container) { - nsTArray > insertedContents; - insertedContents.AppendElement(textNode); - document->ProcessContentInserted(container, &insertedContents); - } - } - - return PL_DHASH_NEXT; -} - - //////////////////////////////////////////////////////////////////////////////// // NotificationController: content inserted notification diff --git a/accessible/base/NotificationController.h b/accessible/base/NotificationController.h index d4f7c98208b..fcb41e0308c 100644 --- a/accessible/base/NotificationController.h +++ b/accessible/base/NotificationController.h @@ -297,12 +297,6 @@ private: */ nsTHashtable > mTextHash; - /** - * Update the accessible tree for pending rendered text change notifications. - */ - static PLDHashOperator TextEnumerator(nsCOMPtrHashKey* aEntry, - void* aUserArg); - /** * Other notifications like DOM events. Don't make this an nsAutoTArray; we * use SwapElements() on it. diff --git a/accessible/ipc/DocAccessibleParent.cpp b/accessible/ipc/DocAccessibleParent.cpp index 8246b860bf2..d8d3180d2ec 100644 --- a/accessible/ipc/DocAccessibleParent.cpp +++ b/accessible/ipc/DocAccessibleParent.cpp @@ -221,13 +221,6 @@ DocAccessibleParent::AddChildDoc(DocAccessibleParent* aChildDoc, return true; } -PLDHashOperator -DocAccessibleParent::ShutdownAccessibles(ProxyEntry* entry, void*) -{ - ProxyDestroyed(entry->mProxy); - return PL_DHASH_REMOVE; -} - bool DocAccessibleParent::RecvShutdown() { @@ -252,7 +245,10 @@ DocAccessibleParent::Destroy() for (uint32_t i = childDocCount - 1; i < childDocCount; i--) mChildDocs[i]->Destroy(); - mAccessibles.EnumerateEntries(ShutdownAccessibles, nullptr); + for (auto iter = mAccessibles.Iter(); !iter.Done(); iter.Next()) { + ProxyDestroyed(iter.Get()->mProxy); + iter.Remove(); + } ProxyDestroyed(this); if (mParentDoc) mParentDoc->RemoveChildDoc(this); diff --git a/accessible/ipc/DocAccessibleParent.h b/accessible/ipc/DocAccessibleParent.h index 7d59582e775..095cb9570a2 100644 --- a/accessible/ipc/DocAccessibleParent.h +++ b/accessible/ipc/DocAccessibleParent.h @@ -152,8 +152,6 @@ private: uint32_t aIdxInParent); void CheckDocTree() const; - static PLDHashOperator ShutdownAccessibles(ProxyEntry* entry, void* unused); - nsTArray mChildDocs; DocAccessibleParent* mParentDoc;