Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 "HTMLImageMapAccessible.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "ARIAMap.h" |
michael@0 | 9 | #include "nsAccUtils.h" |
michael@0 | 10 | #include "DocAccessible-inl.h" |
michael@0 | 11 | #include "Role.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "nsIDOMHTMLCollection.h" |
michael@0 | 14 | #include "nsIServiceManager.h" |
michael@0 | 15 | #include "nsIDOMElement.h" |
michael@0 | 16 | #include "nsIDOMHTMLAreaElement.h" |
michael@0 | 17 | #include "nsIFrame.h" |
michael@0 | 18 | #include "nsImageFrame.h" |
michael@0 | 19 | #include "nsImageMap.h" |
michael@0 | 20 | #include "nsIURI.h" |
michael@0 | 21 | |
michael@0 | 22 | using namespace mozilla::a11y; |
michael@0 | 23 | |
michael@0 | 24 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 25 | // HTMLImageMapAccessible |
michael@0 | 26 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 27 | |
michael@0 | 28 | HTMLImageMapAccessible:: |
michael@0 | 29 | HTMLImageMapAccessible(nsIContent* aContent, DocAccessible* aDoc) : |
michael@0 | 30 | ImageAccessibleWrap(aContent, aDoc) |
michael@0 | 31 | { |
michael@0 | 32 | mType = eImageMapType; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 36 | // HTMLImageMapAccessible: nsISupports |
michael@0 | 37 | |
michael@0 | 38 | NS_IMPL_ISUPPORTS_INHERITED0(HTMLImageMapAccessible, ImageAccessible) |
michael@0 | 39 | |
michael@0 | 40 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 41 | // HTMLImageMapAccessible: Accessible public |
michael@0 | 42 | |
michael@0 | 43 | role |
michael@0 | 44 | HTMLImageMapAccessible::NativeRole() |
michael@0 | 45 | { |
michael@0 | 46 | return roles::IMAGE_MAP; |
michael@0 | 47 | } |
michael@0 | 48 | |
michael@0 | 49 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 50 | // HTMLImageMapAccessible: HyperLinkAccessible |
michael@0 | 51 | |
michael@0 | 52 | uint32_t |
michael@0 | 53 | HTMLImageMapAccessible::AnchorCount() |
michael@0 | 54 | { |
michael@0 | 55 | return ChildCount(); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | Accessible* |
michael@0 | 59 | HTMLImageMapAccessible::AnchorAt(uint32_t aAnchorIndex) |
michael@0 | 60 | { |
michael@0 | 61 | return GetChildAt(aAnchorIndex); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | already_AddRefed<nsIURI> |
michael@0 | 65 | HTMLImageMapAccessible::AnchorURIAt(uint32_t aAnchorIndex) |
michael@0 | 66 | { |
michael@0 | 67 | Accessible* area = GetChildAt(aAnchorIndex); |
michael@0 | 68 | if (!area) |
michael@0 | 69 | return nullptr; |
michael@0 | 70 | |
michael@0 | 71 | nsIContent* linkContent = area->GetContent(); |
michael@0 | 72 | return linkContent ? linkContent->GetHrefURI() : nullptr; |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 76 | // HTMLImageMapAccessible: public |
michael@0 | 77 | |
michael@0 | 78 | void |
michael@0 | 79 | HTMLImageMapAccessible::UpdateChildAreas(bool aDoFireEvents) |
michael@0 | 80 | { |
michael@0 | 81 | nsImageFrame* imageFrame = do_QueryFrame(mContent->GetPrimaryFrame()); |
michael@0 | 82 | |
michael@0 | 83 | // If image map is not initialized yet then we trigger one time more later. |
michael@0 | 84 | nsImageMap* imageMapObj = imageFrame->GetExistingImageMap(); |
michael@0 | 85 | if (!imageMapObj) |
michael@0 | 86 | return; |
michael@0 | 87 | |
michael@0 | 88 | bool doReorderEvent = false; |
michael@0 | 89 | nsRefPtr<AccReorderEvent> reorderEvent = new AccReorderEvent(this); |
michael@0 | 90 | |
michael@0 | 91 | // Remove areas that are not a valid part of the image map anymore. |
michael@0 | 92 | for (int32_t childIdx = mChildren.Length() - 1; childIdx >= 0; childIdx--) { |
michael@0 | 93 | Accessible* area = mChildren.ElementAt(childIdx); |
michael@0 | 94 | if (area->GetContent()->GetPrimaryFrame()) |
michael@0 | 95 | continue; |
michael@0 | 96 | |
michael@0 | 97 | if (aDoFireEvents) { |
michael@0 | 98 | nsRefPtr<AccHideEvent> event = new AccHideEvent(area, area->GetContent()); |
michael@0 | 99 | mDoc->FireDelayedEvent(event); |
michael@0 | 100 | reorderEvent->AddSubMutationEvent(event); |
michael@0 | 101 | doReorderEvent = true; |
michael@0 | 102 | } |
michael@0 | 103 | |
michael@0 | 104 | RemoveChild(area); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | // Insert new areas into the tree. |
michael@0 | 108 | uint32_t areaElmCount = imageMapObj->AreaCount(); |
michael@0 | 109 | for (uint32_t idx = 0; idx < areaElmCount; idx++) { |
michael@0 | 110 | nsIContent* areaContent = imageMapObj->GetAreaAt(idx); |
michael@0 | 111 | |
michael@0 | 112 | Accessible* area = mChildren.SafeElementAt(idx); |
michael@0 | 113 | if (!area || area->GetContent() != areaContent) { |
michael@0 | 114 | nsRefPtr<Accessible> area = new HTMLAreaAccessible(areaContent, mDoc); |
michael@0 | 115 | mDoc->BindToDocument(area, aria::GetRoleMap(areaContent)); |
michael@0 | 116 | |
michael@0 | 117 | if (!InsertChildAt(idx, area)) { |
michael@0 | 118 | mDoc->UnbindFromDocument(area); |
michael@0 | 119 | break; |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | if (aDoFireEvents) { |
michael@0 | 123 | nsRefPtr<AccShowEvent> event = new AccShowEvent(area, areaContent); |
michael@0 | 124 | mDoc->FireDelayedEvent(event); |
michael@0 | 125 | reorderEvent->AddSubMutationEvent(event); |
michael@0 | 126 | doReorderEvent = true; |
michael@0 | 127 | } |
michael@0 | 128 | } |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | // Fire reorder event if needed. |
michael@0 | 132 | if (doReorderEvent) |
michael@0 | 133 | mDoc->FireDelayedEvent(reorderEvent); |
michael@0 | 134 | } |
michael@0 | 135 | |
michael@0 | 136 | Accessible* |
michael@0 | 137 | HTMLImageMapAccessible::GetChildAccessibleFor(const nsINode* aNode) const |
michael@0 | 138 | { |
michael@0 | 139 | uint32_t length = mChildren.Length(); |
michael@0 | 140 | for (uint32_t i = 0; i < length; i++) { |
michael@0 | 141 | Accessible* area = mChildren[i]; |
michael@0 | 142 | if (area->GetContent() == aNode) |
michael@0 | 143 | return area; |
michael@0 | 144 | } |
michael@0 | 145 | |
michael@0 | 146 | return nullptr; |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 150 | // HTMLImageMapAccessible: Accessible protected |
michael@0 | 151 | |
michael@0 | 152 | void |
michael@0 | 153 | HTMLImageMapAccessible::CacheChildren() |
michael@0 | 154 | { |
michael@0 | 155 | UpdateChildAreas(false); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | |
michael@0 | 159 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 160 | // HTMLAreaAccessible |
michael@0 | 161 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 162 | |
michael@0 | 163 | HTMLAreaAccessible:: |
michael@0 | 164 | HTMLAreaAccessible(nsIContent* aContent, DocAccessible* aDoc) : |
michael@0 | 165 | HTMLLinkAccessible(aContent, aDoc) |
michael@0 | 166 | { |
michael@0 | 167 | // Make HTML area DOM element not accessible. HTML image map accessible |
michael@0 | 168 | // manages its tree itself. |
michael@0 | 169 | mStateFlags |= eNotNodeMapEntry; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 173 | // HTMLAreaAccessible: nsIAccessible |
michael@0 | 174 | |
michael@0 | 175 | ENameValueFlag |
michael@0 | 176 | HTMLAreaAccessible::NativeName(nsString& aName) |
michael@0 | 177 | { |
michael@0 | 178 | ENameValueFlag nameFlag = Accessible::NativeName(aName); |
michael@0 | 179 | if (!aName.IsEmpty()) |
michael@0 | 180 | return nameFlag; |
michael@0 | 181 | |
michael@0 | 182 | if (!mContent->GetAttr(kNameSpaceID_None, nsGkAtoms::alt, aName)) |
michael@0 | 183 | GetValue(aName); |
michael@0 | 184 | |
michael@0 | 185 | return eNameOK; |
michael@0 | 186 | } |
michael@0 | 187 | |
michael@0 | 188 | void |
michael@0 | 189 | HTMLAreaAccessible::Description(nsString& aDescription) |
michael@0 | 190 | { |
michael@0 | 191 | aDescription.Truncate(); |
michael@0 | 192 | |
michael@0 | 193 | // Still to do - follow IE's standard here |
michael@0 | 194 | nsCOMPtr<nsIDOMHTMLAreaElement> area(do_QueryInterface(mContent)); |
michael@0 | 195 | if (area) |
michael@0 | 196 | area->GetShape(aDescription); |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 200 | // HTMLAreaAccessible: Accessible public |
michael@0 | 201 | |
michael@0 | 202 | Accessible* |
michael@0 | 203 | HTMLAreaAccessible::ChildAtPoint(int32_t aX, int32_t aY, |
michael@0 | 204 | EWhichChildAtPoint aWhichChild) |
michael@0 | 205 | { |
michael@0 | 206 | // Don't walk into area accessibles. |
michael@0 | 207 | return this; |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 211 | // HTMLImageMapAccessible: HyperLinkAccessible |
michael@0 | 212 | |
michael@0 | 213 | uint32_t |
michael@0 | 214 | HTMLAreaAccessible::StartOffset() |
michael@0 | 215 | { |
michael@0 | 216 | // Image map accessible is not hypertext accessible therefore |
michael@0 | 217 | // StartOffset/EndOffset implementations of Accessible doesn't work here. |
michael@0 | 218 | // We return index in parent because image map contains area links only which |
michael@0 | 219 | // are embedded objects. |
michael@0 | 220 | // XXX: image map should be a hypertext accessible. |
michael@0 | 221 | return IndexInParent(); |
michael@0 | 222 | } |
michael@0 | 223 | |
michael@0 | 224 | uint32_t |
michael@0 | 225 | HTMLAreaAccessible::EndOffset() |
michael@0 | 226 | { |
michael@0 | 227 | return IndexInParent() + 1; |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 231 | // HTMLAreaAccessible: Accessible protected |
michael@0 | 232 | |
michael@0 | 233 | void |
michael@0 | 234 | HTMLAreaAccessible::CacheChildren() |
michael@0 | 235 | { |
michael@0 | 236 | // No children for aria accessible. |
michael@0 | 237 | } |
michael@0 | 238 | |
michael@0 | 239 | void |
michael@0 | 240 | HTMLAreaAccessible::GetBoundsRect(nsRect& aBounds, nsIFrame** aBoundingFrame) |
michael@0 | 241 | { |
michael@0 | 242 | nsIFrame* frame = GetFrame(); |
michael@0 | 243 | if (!frame) |
michael@0 | 244 | return; |
michael@0 | 245 | |
michael@0 | 246 | nsImageFrame* imageFrame = do_QueryFrame(frame); |
michael@0 | 247 | nsImageMap* map = imageFrame->GetImageMap(); |
michael@0 | 248 | |
michael@0 | 249 | nsresult rv = map->GetBoundsForAreaContent(mContent, aBounds); |
michael@0 | 250 | if (NS_FAILED(rv)) |
michael@0 | 251 | return; |
michael@0 | 252 | |
michael@0 | 253 | // XXX Areas are screwy; they return their rects as a pair of points, one pair |
michael@0 | 254 | // stored into the width and height. |
michael@0 | 255 | aBounds.width -= aBounds.x; |
michael@0 | 256 | aBounds.height -= aBounds.y; |
michael@0 | 257 | |
michael@0 | 258 | *aBoundingFrame = frame; |
michael@0 | 259 | } |