| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2011 Apple Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * | |
| 8 * 1. Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | |
| 11 * notice, this list of conditions and the following disclaimer in the | |
| 12 * documentation and/or other materials provided with the distribution. | |
| 13 * | |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | |
| 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
| 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
| 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #include "modules/accessibility/AXScrollView.h" | |
| 27 | |
| 28 #include "core/frame/FrameView.h" | |
| 29 #include "core/frame/LocalFrame.h" | |
| 30 #include "core/html/HTMLFrameOwnerElement.h" | |
| 31 #include "modules/accessibility/AXObjectCacheImpl.h" | |
| 32 #include "modules/accessibility/AXScrollbar.h" | |
| 33 | |
| 34 namespace blink { | |
| 35 | |
| 36 AXScrollView::AXScrollView(FrameView* view, AXObjectCacheImpl& axObjectCache) | |
| 37 : AXObject(axObjectCache) | |
| 38 , m_scrollView(view) | |
| 39 , m_childrenDirty(false) | |
| 40 { | |
| 41 } | |
| 42 | |
| 43 AXScrollView::~AXScrollView() | |
| 44 { | |
| 45 ASSERT(!m_scrollView); | |
| 46 } | |
| 47 | |
| 48 void AXScrollView::detach() | |
| 49 { | |
| 50 AXObject::detach(); | |
| 51 m_scrollView = nullptr; | |
| 52 } | |
| 53 | |
| 54 AXScrollView* AXScrollView::create(FrameView* view, AXObjectCacheImpl& axObjectC
ache) | |
| 55 { | |
| 56 return new AXScrollView(view, axObjectCache); | |
| 57 } | |
| 58 | |
| 59 AXObject* AXScrollView::scrollBar(AccessibilityOrientation orientation) | |
| 60 { | |
| 61 updateScrollbars(); | |
| 62 | |
| 63 switch (orientation) { | |
| 64 case AccessibilityOrientationVertical: | |
| 65 return m_verticalScrollbar ? m_verticalScrollbar.get() : 0; | |
| 66 case AccessibilityOrientationHorizontal: | |
| 67 return m_horizontalScrollbar ? m_horizontalScrollbar.get() : 0; | |
| 68 case AccessibilityOrientationUndefined: | |
| 69 return 0; | |
| 70 } | |
| 71 | |
| 72 return 0; | |
| 73 } | |
| 74 | |
| 75 // If this is WebKit1 then the native scroll view needs to return the | |
| 76 // AX information (because there are no scroll bar children in the FrameView obj
ect in WK1). | |
| 77 // In WebKit2, the FrameView object will return the AX information (because ther
e are no platform widgets). | |
| 78 bool AXScrollView::isAttachment() const | |
| 79 { | |
| 80 return false; | |
| 81 } | |
| 82 | |
| 83 Widget* AXScrollView::widgetForAttachmentView() const | |
| 84 { | |
| 85 return m_scrollView; | |
| 86 } | |
| 87 | |
| 88 void AXScrollView::updateChildrenIfNecessary() | |
| 89 { | |
| 90 if (m_childrenDirty) | |
| 91 clearChildren(); | |
| 92 | |
| 93 if (!m_haveChildren) | |
| 94 addChildren(); | |
| 95 | |
| 96 updateScrollbars(); | |
| 97 } | |
| 98 | |
| 99 void AXScrollView::updateScrollbars() | |
| 100 { | |
| 101 if (!m_scrollView) | |
| 102 return; | |
| 103 | |
| 104 if (m_scrollView->horizontalScrollbar() && !m_horizontalScrollbar) { | |
| 105 m_horizontalScrollbar = addChildScrollbar(m_scrollView->horizontalScroll
bar()); | |
| 106 } else if (!m_scrollView->horizontalScrollbar() && m_horizontalScrollbar) { | |
| 107 removeChildScrollbar(m_horizontalScrollbar.get()); | |
| 108 m_horizontalScrollbar = nullptr; | |
| 109 } | |
| 110 | |
| 111 if (m_scrollView->verticalScrollbar() && !m_verticalScrollbar) { | |
| 112 m_verticalScrollbar = addChildScrollbar(m_scrollView->verticalScrollbar(
)); | |
| 113 } else if (!m_scrollView->verticalScrollbar() && m_verticalScrollbar) { | |
| 114 removeChildScrollbar(m_verticalScrollbar.get()); | |
| 115 m_verticalScrollbar = nullptr; | |
| 116 } | |
| 117 } | |
| 118 | |
| 119 void AXScrollView::removeChildScrollbar(AXObject* scrollbar) | |
| 120 { | |
| 121 size_t pos = m_children.find(scrollbar); | |
| 122 if (pos != kNotFound) { | |
| 123 m_children[pos]->detachFromParent(); | |
| 124 m_children.remove(pos); | |
| 125 } | |
| 126 } | |
| 127 | |
| 128 AXScrollbar* AXScrollView::addChildScrollbar(Scrollbar* scrollbar) | |
| 129 { | |
| 130 if (!scrollbar) | |
| 131 return 0; | |
| 132 | |
| 133 AXScrollbar* scrollBarObject = toAXScrollbar(axObjectCache().getOrCreate(scr
ollbar)); | |
| 134 scrollBarObject->setParent(this); | |
| 135 m_children.append(scrollBarObject); | |
| 136 return scrollBarObject; | |
| 137 } | |
| 138 | |
| 139 void AXScrollView::clearChildren() | |
| 140 { | |
| 141 AXObject::clearChildren(); | |
| 142 m_verticalScrollbar = nullptr; | |
| 143 m_horizontalScrollbar = nullptr; | |
| 144 } | |
| 145 | |
| 146 bool AXScrollView::computeAccessibilityIsIgnored(IgnoredReasons* ignoredReasons)
const | |
| 147 { | |
| 148 // We just want to match whatever's returned by our web area, which is a chi
ld of this | |
| 149 // object. Normally cached attribute values may only search up the tree. We
can't just | |
| 150 // call accessibilityIsIgnored on the web area, because the web area may sea
rch up its | |
| 151 // ancestors and call this function recursively, and we'd loop until a stack
overflow. | |
| 152 | |
| 153 // Instead, we first update the cached accessibilityIsIgnored value for this
node to | |
| 154 // false, call accessibilityIsIgnored on the web area, then return the mathc
ing value. | |
| 155 m_cachedIsIgnored = false; | |
| 156 m_lastModificationCount = axObjectCache().modificationCount(); | |
| 157 | |
| 158 AXObject* webArea = webAreaObject(); | |
| 159 if (!webArea) | |
| 160 return true; | |
| 161 | |
| 162 if (!webArea->accessibilityIsIgnored()) | |
| 163 return false; | |
| 164 | |
| 165 if (ignoredReasons) | |
| 166 return webArea->computeAccessibilityIsIgnored(ignoredReasons); | |
| 167 | |
| 168 return true; | |
| 169 } | |
| 170 | |
| 171 void AXScrollView::addChildren() | |
| 172 { | |
| 173 ASSERT(!isDetached()); | |
| 174 ASSERT(!m_haveChildren); | |
| 175 m_haveChildren = true; | |
| 176 | |
| 177 AXObject* webArea = webAreaObject(); | |
| 178 if (webArea && !webArea->accessibilityIsIgnored()) | |
| 179 m_children.append(webArea); | |
| 180 | |
| 181 updateScrollbars(); | |
| 182 } | |
| 183 | |
| 184 AXObject* AXScrollView::webAreaObject() const | |
| 185 { | |
| 186 if (!m_scrollView || !m_scrollView->isFrameView()) | |
| 187 return 0; | |
| 188 | |
| 189 Document* doc = m_scrollView->frame().document(); | |
| 190 if (!doc || !doc->layoutView()) | |
| 191 return 0; | |
| 192 | |
| 193 return axObjectCache().getOrCreate(doc); | |
| 194 } | |
| 195 | |
| 196 AXObject* AXScrollView::accessibilityHitTest(const IntPoint& point) const | |
| 197 { | |
| 198 AXObject* webArea = webAreaObject(); | |
| 199 if (!webArea) | |
| 200 return 0; | |
| 201 | |
| 202 if (m_horizontalScrollbar && m_horizontalScrollbar->elementRect().contains(p
oint)) | |
| 203 return m_horizontalScrollbar.get(); | |
| 204 if (m_verticalScrollbar && m_verticalScrollbar->elementRect().contains(point
)) | |
| 205 return m_verticalScrollbar.get(); | |
| 206 | |
| 207 return webArea->accessibilityHitTest(point); | |
| 208 } | |
| 209 | |
| 210 LayoutRect AXScrollView::elementRect() const | |
| 211 { | |
| 212 if (!m_scrollView) | |
| 213 return LayoutRect(); | |
| 214 | |
| 215 return LayoutRect(m_scrollView->frameRect()); | |
| 216 } | |
| 217 | |
| 218 FrameView* AXScrollView::documentFrameView() const | |
| 219 { | |
| 220 if (!m_scrollView || !m_scrollView->isFrameView()) | |
| 221 return 0; | |
| 222 | |
| 223 return m_scrollView; | |
| 224 } | |
| 225 | |
| 226 AXObject* AXScrollView::computeParent() const | |
| 227 { | |
| 228 ASSERT(!isDetached()); | |
| 229 if (!m_scrollView || !m_scrollView->isFrameView()) | |
| 230 return 0; | |
| 231 | |
| 232 // FIXME: Broken for OOPI. | |
| 233 HTMLFrameOwnerElement* owner = m_scrollView->frame().deprecatedLocalOwner(); | |
| 234 if (owner && owner->layoutObject()) | |
| 235 return axObjectCache().getOrCreate(owner); | |
| 236 | |
| 237 return axObjectCache().getOrCreate(m_scrollView->frame().pagePopupOwner()); | |
| 238 } | |
| 239 | |
| 240 AXObject* AXScrollView::computeParentIfExists() const | |
| 241 { | |
| 242 if (!m_scrollView || !m_scrollView->isFrameView()) | |
| 243 return 0; | |
| 244 | |
| 245 HTMLFrameOwnerElement* owner = m_scrollView->frame().deprecatedLocalOwner(); | |
| 246 if (owner && owner->layoutObject()) | |
| 247 return axObjectCache().get(owner); | |
| 248 | |
| 249 return axObjectCache().get(m_scrollView->frame().pagePopupOwner()); | |
| 250 } | |
| 251 | |
| 252 DEFINE_TRACE(AXScrollView) | |
| 253 { | |
| 254 visitor->trace(m_scrollView); | |
| 255 visitor->trace(m_horizontalScrollbar); | |
| 256 visitor->trace(m_verticalScrollbar); | |
| 257 AXObject::trace(visitor); | |
| 258 } | |
| 259 | |
| 260 } // namespace blink | |
| OLD | NEW |