Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "OuterDocAccessible.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "Accessible-inl.h" |
michael@0 | 9 | #include "nsAccUtils.h" |
michael@0 | 10 | #include "DocAccessible-inl.h" |
michael@0 | 11 | #include "Role.h" |
michael@0 | 12 | #include "States.h" |
michael@0 | 13 | |
michael@0 | 14 | #ifdef A11Y_LOG |
michael@0 | 15 | #include "Logging.h" |
michael@0 | 16 | #endif |
michael@0 | 17 | |
michael@0 | 18 | using namespace mozilla; |
michael@0 | 19 | using namespace mozilla::a11y; |
michael@0 | 20 | |
michael@0 | 21 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 22 | // OuterDocAccessible |
michael@0 | 23 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 24 | |
michael@0 | 25 | OuterDocAccessible:: |
michael@0 | 26 | OuterDocAccessible(nsIContent* aContent, DocAccessible* aDoc) : |
michael@0 | 27 | AccessibleWrap(aContent, aDoc) |
michael@0 | 28 | { |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | OuterDocAccessible::~OuterDocAccessible() |
michael@0 | 32 | { |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 36 | // nsISupports |
michael@0 | 37 | |
michael@0 | 38 | NS_IMPL_ISUPPORTS_INHERITED0(OuterDocAccessible, |
michael@0 | 39 | Accessible) |
michael@0 | 40 | |
michael@0 | 41 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 42 | // Accessible public (DON'T add methods here) |
michael@0 | 43 | |
michael@0 | 44 | role |
michael@0 | 45 | OuterDocAccessible::NativeRole() |
michael@0 | 46 | { |
michael@0 | 47 | return roles::INTERNAL_FRAME; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | Accessible* |
michael@0 | 51 | OuterDocAccessible::ChildAtPoint(int32_t aX, int32_t aY, |
michael@0 | 52 | EWhichChildAtPoint aWhichChild) |
michael@0 | 53 | { |
michael@0 | 54 | int32_t docX = 0, docY = 0, docWidth = 0, docHeight = 0; |
michael@0 | 55 | nsresult rv = GetBounds(&docX, &docY, &docWidth, &docHeight); |
michael@0 | 56 | NS_ENSURE_SUCCESS(rv, nullptr); |
michael@0 | 57 | |
michael@0 | 58 | if (aX < docX || aX >= docX + docWidth || aY < docY || aY >= docY + docHeight) |
michael@0 | 59 | return nullptr; |
michael@0 | 60 | |
michael@0 | 61 | // Always return the inner doc as direct child accessible unless bounds |
michael@0 | 62 | // outside of it. |
michael@0 | 63 | Accessible* child = GetChildAt(0); |
michael@0 | 64 | NS_ENSURE_TRUE(child, nullptr); |
michael@0 | 65 | |
michael@0 | 66 | if (aWhichChild == eDeepestChild) |
michael@0 | 67 | return child->ChildAtPoint(aX, aY, eDeepestChild); |
michael@0 | 68 | return child; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 72 | // nsIAccessible |
michael@0 | 73 | |
michael@0 | 74 | uint8_t |
michael@0 | 75 | OuterDocAccessible::ActionCount() |
michael@0 | 76 | { |
michael@0 | 77 | // Internal frame, which is the doc's parent, should not have a click action. |
michael@0 | 78 | return 0; |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | NS_IMETHODIMP |
michael@0 | 82 | OuterDocAccessible::GetActionName(uint8_t aIndex, nsAString& aName) |
michael@0 | 83 | { |
michael@0 | 84 | aName.Truncate(); |
michael@0 | 85 | |
michael@0 | 86 | return NS_ERROR_INVALID_ARG; |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | NS_IMETHODIMP |
michael@0 | 90 | OuterDocAccessible::GetActionDescription(uint8_t aIndex, |
michael@0 | 91 | nsAString& aDescription) |
michael@0 | 92 | { |
michael@0 | 93 | aDescription.Truncate(); |
michael@0 | 94 | |
michael@0 | 95 | return NS_ERROR_INVALID_ARG; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | NS_IMETHODIMP |
michael@0 | 99 | OuterDocAccessible::DoAction(uint8_t aIndex) |
michael@0 | 100 | { |
michael@0 | 101 | return NS_ERROR_INVALID_ARG; |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 105 | // Accessible public |
michael@0 | 106 | |
michael@0 | 107 | void |
michael@0 | 108 | OuterDocAccessible::Shutdown() |
michael@0 | 109 | { |
michael@0 | 110 | // XXX: sometimes outerdoc accessible is shutdown because of layout style |
michael@0 | 111 | // change however the presshell of underlying document isn't destroyed and |
michael@0 | 112 | // the document doesn't get pagehide events. Schedule a document rebind |
michael@0 | 113 | // to its parent document. Otherwise a document accessible may be lost if its |
michael@0 | 114 | // outerdoc has being recreated (see bug 862863 for details). |
michael@0 | 115 | |
michael@0 | 116 | #ifdef A11Y_LOG |
michael@0 | 117 | if (logging::IsEnabled(logging::eDocDestroy)) |
michael@0 | 118 | logging::OuterDocDestroy(this); |
michael@0 | 119 | #endif |
michael@0 | 120 | |
michael@0 | 121 | Accessible* child = mChildren.SafeElementAt(0, nullptr); |
michael@0 | 122 | if (child) { |
michael@0 | 123 | #ifdef A11Y_LOG |
michael@0 | 124 | if (logging::IsEnabled(logging::eDocDestroy)) { |
michael@0 | 125 | logging::DocDestroy("outerdoc's child document rebind is scheduled", |
michael@0 | 126 | child->AsDoc()->DocumentNode()); |
michael@0 | 127 | } |
michael@0 | 128 | #endif |
michael@0 | 129 | RemoveChild(child); |
michael@0 | 130 | mDoc->BindChildDocument(child->AsDoc()); |
michael@0 | 131 | } |
michael@0 | 132 | |
michael@0 | 133 | AccessibleWrap::Shutdown(); |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | void |
michael@0 | 137 | OuterDocAccessible::InvalidateChildren() |
michael@0 | 138 | { |
michael@0 | 139 | // Do not invalidate children because DocManager is responsible for |
michael@0 | 140 | // document accessible lifetime when DOM document is created or destroyed. If |
michael@0 | 141 | // DOM document isn't destroyed but its presshell is destroyed (for example, |
michael@0 | 142 | // when DOM node of outerdoc accessible is hidden), then outerdoc accessible |
michael@0 | 143 | // notifies DocManager about this. If presshell is created for existing |
michael@0 | 144 | // DOM document (for example when DOM node of outerdoc accessible is shown) |
michael@0 | 145 | // then allow DocManager to handle this case since the document |
michael@0 | 146 | // accessible is created and appended as a child when it's requested. |
michael@0 | 147 | |
michael@0 | 148 | SetChildrenFlag(eChildrenUninitialized); |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | bool |
michael@0 | 152 | OuterDocAccessible::InsertChildAt(uint32_t aIdx, Accessible* aAccessible) |
michael@0 | 153 | { |
michael@0 | 154 | NS_ASSERTION(aAccessible->IsDoc(), |
michael@0 | 155 | "OuterDocAccessible should only have document child!"); |
michael@0 | 156 | // We keep showing the old document for a bit after creating the new one, |
michael@0 | 157 | // and while building the new DOM and frame tree. That's done on purpose |
michael@0 | 158 | // to avoid weird flashes of default background color. |
michael@0 | 159 | // The old viewer will be destroyed after the new one is created. |
michael@0 | 160 | // For a11y, it should be safe to shut down the old document now. |
michael@0 | 161 | if (mChildren.Length()) |
michael@0 | 162 | mChildren[0]->Shutdown(); |
michael@0 | 163 | |
michael@0 | 164 | if (!AccessibleWrap::InsertChildAt(0, aAccessible)) |
michael@0 | 165 | return false; |
michael@0 | 166 | |
michael@0 | 167 | #ifdef A11Y_LOG |
michael@0 | 168 | if (logging::IsEnabled(logging::eDocCreate)) { |
michael@0 | 169 | logging::DocCreate("append document to outerdoc", |
michael@0 | 170 | aAccessible->AsDoc()->DocumentNode()); |
michael@0 | 171 | logging::Address("outerdoc", this); |
michael@0 | 172 | } |
michael@0 | 173 | #endif |
michael@0 | 174 | |
michael@0 | 175 | return true; |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | bool |
michael@0 | 179 | OuterDocAccessible::RemoveChild(Accessible* aAccessible) |
michael@0 | 180 | { |
michael@0 | 181 | Accessible* child = mChildren.SafeElementAt(0, nullptr); |
michael@0 | 182 | if (child != aAccessible) { |
michael@0 | 183 | NS_ERROR("Wrong child to remove!"); |
michael@0 | 184 | return false; |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | #ifdef A11Y_LOG |
michael@0 | 188 | if (logging::IsEnabled(logging::eDocDestroy)) { |
michael@0 | 189 | logging::DocDestroy("remove document from outerdoc", |
michael@0 | 190 | child->AsDoc()->DocumentNode(), child->AsDoc()); |
michael@0 | 191 | logging::Address("outerdoc", this); |
michael@0 | 192 | } |
michael@0 | 193 | #endif |
michael@0 | 194 | |
michael@0 | 195 | bool wasRemoved = AccessibleWrap::RemoveChild(child); |
michael@0 | 196 | |
michael@0 | 197 | NS_ASSERTION(!mChildren.Length(), |
michael@0 | 198 | "This child document of outerdoc accessible wasn't removed!"); |
michael@0 | 199 | |
michael@0 | 200 | return wasRemoved; |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | |
michael@0 | 204 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 205 | // Accessible protected |
michael@0 | 206 | |
michael@0 | 207 | void |
michael@0 | 208 | OuterDocAccessible::CacheChildren() |
michael@0 | 209 | { |
michael@0 | 210 | // Request document accessible for the content document to make sure it's |
michael@0 | 211 | // created. It will appended to outerdoc accessible children asynchronously. |
michael@0 | 212 | nsIDocument* outerDoc = mContent->GetCurrentDoc(); |
michael@0 | 213 | if (outerDoc) { |
michael@0 | 214 | nsIDocument* innerDoc = outerDoc->GetSubDocumentFor(mContent); |
michael@0 | 215 | if (innerDoc) |
michael@0 | 216 | GetAccService()->GetDocAccessible(innerDoc); |
michael@0 | 217 | } |
michael@0 | 218 | } |