Migrate accessibility/ to using nullptr instead of 0
[WebKit-https.git] / Source / WebCore / accessibility / AccessibilityScrollView.cpp
index 19b4482..7c6a82d 100644 (file)
@@ -31,7 +31,7 @@
 #include "Frame.h"
 #include "FrameView.h"
 #include "HTMLFrameOwnerElement.h"
-#include "RenderPart.h"
+#include "RenderElement.h"
 #include "ScrollView.h"
 #include "Widget.h"
 
@@ -48,10 +48,10 @@ AccessibilityScrollView::~AccessibilityScrollView()
     ASSERT(isDetached());
 }
 
-void AccessibilityScrollView::detach()
+void AccessibilityScrollView::detach(AccessibilityDetachmentType detachmentType, AXObjectCache* cache)
 {
-    AccessibilityObject::detach();
-    m_scrollView = 0;
+    AccessibilityObject::detach(detachmentType, cache);
+    m_scrollView = nullptr;
 }
 
 PassRefPtr<AccessibilityScrollView> AccessibilityScrollView::create(ScrollView* view)
@@ -70,7 +70,7 @@ AccessibilityObject* AccessibilityScrollView::scrollBar(AccessibilityOrientation
         return m_horizontalScrollbar ? m_horizontalScrollbar.get() : 0;
     }
     
-    return 0;
+    return nullptr;
 }
 
 // If this is WebKit1 then the native scroll view needs to return the
@@ -86,6 +86,24 @@ Widget* AccessibilityScrollView::widgetForAttachmentView() const
     return m_scrollView;
 }
     
+bool AccessibilityScrollView::canSetFocusAttribute() const
+{
+    AccessibilityObject* webArea = webAreaObject();
+    return webArea && webArea->canSetFocusAttribute();
+}
+    
+bool AccessibilityScrollView::isFocused() const
+{
+    AccessibilityObject* webArea = webAreaObject();
+    return webArea && webArea->isFocused();
+}
+    
+void AccessibilityScrollView::setFocused(bool focused)
+{
+    if (AccessibilityObject* webArea = webAreaObject())
+        webArea->setFocused(focused);
+}
+
 void AccessibilityScrollView::updateChildrenIfNecessary()
 {
     if (m_childrenDirty)
@@ -106,14 +124,14 @@ void AccessibilityScrollView::updateScrollbars()
         m_horizontalScrollbar = addChildScrollbar(m_scrollView->horizontalScrollbar());
     else if (!m_scrollView->horizontalScrollbar() && m_horizontalScrollbar) {
         removeChildScrollbar(m_horizontalScrollbar.get());
-        m_horizontalScrollbar = 0;
+        m_horizontalScrollbar = nullptr;
     }
 
     if (m_scrollView->verticalScrollbar() && !m_verticalScrollbar)
         m_verticalScrollbar = addChildScrollbar(m_scrollView->verticalScrollbar());
     else if (!m_scrollView->verticalScrollbar() && m_verticalScrollbar) {
         removeChildScrollbar(m_verticalScrollbar.get());
-        m_verticalScrollbar = 0;
+        m_verticalScrollbar = nullptr;
     }
 }
     
@@ -129,9 +147,13 @@ void AccessibilityScrollView::removeChildScrollbar(AccessibilityObject* scrollba
 AccessibilityScrollbar* AccessibilityScrollView::addChildScrollbar(Scrollbar* scrollbar)
 {
     if (!scrollbar)
-        return 0;
+        return nullptr;
     
-    AccessibilityScrollbar* scrollBarObject = static_cast<AccessibilityScrollbar*>(axObjectCache()->getOrCreate(scrollbar));
+    AXObjectCache* cache = axObjectCache();
+    if (!cache)
+        return nullptr;
+
+    AccessibilityScrollbar* scrollBarObject = toAccessibilityScrollbar(cache->getOrCreate(scrollbar));
     scrollBarObject->setParent(this);
     m_children.append(scrollBarObject);
     return scrollBarObject;
@@ -140,8 +162,8 @@ AccessibilityScrollbar* AccessibilityScrollView::addChildScrollbar(Scrollbar* sc
 void AccessibilityScrollView::clearChildren()
 {
     AccessibilityObject::clearChildren();
-    m_verticalScrollbar = 0;
-    m_horizontalScrollbar = 0;
+    m_verticalScrollbar = nullptr;
+    m_horizontalScrollbar = nullptr;
 }
 
 bool AccessibilityScrollView::computeAccessibilityIsIgnored() const
@@ -168,20 +190,23 @@ void AccessibilityScrollView::addChildren()
 AccessibilityObject* AccessibilityScrollView::webAreaObject() const
 {
     if (!m_scrollView || !m_scrollView->isFrameView())
-        return 0;
+        return nullptr;
     
-    Document* doc = static_cast<FrameView*>(m_scrollView)->frame()->document();
-    if (!doc || !doc->renderer())
-        return 0;
+    Document* doc = toFrameView(m_scrollView)->frame().document();
+    if (!doc || !doc->hasLivingRenderTree())
+        return nullptr;
 
-    return axObjectCache()->getOrCreate(doc);
+    if (AXObjectCache* cache = axObjectCache())
+        return cache->getOrCreate(doc);
+    
+    return nullptr;
 }
 
 AccessibilityObject* AccessibilityScrollView::accessibilityHitTest(const IntPoint& point) const
 {
     AccessibilityObject* webArea = webAreaObject();
     if (!webArea)
-        return 0;
+        return nullptr;
     
     if (m_horizontalScrollbar && m_horizontalScrollbar->elementRect().contains(point))
         return m_horizontalScrollbar.get();
@@ -196,39 +221,49 @@ LayoutRect AccessibilityScrollView::elementRect() const
     if (!m_scrollView)
         return LayoutRect();
 
-    return m_scrollView->frameRect();
+    LayoutRect rect = m_scrollView->frameRect();
+    rect.setY(rect.y() + m_scrollView->topContentInset());
+    return rect;
 }
 
 FrameView* AccessibilityScrollView::documentFrameView() const
 {
     if (!m_scrollView || !m_scrollView->isFrameView())
-        return 0;
+        return nullptr;
     
-    return static_cast<FrameView*>(m_scrollView);
+    return toFrameView(m_scrollView);
 }    
 
 AccessibilityObject* AccessibilityScrollView::parentObject() const
 {
     if (!m_scrollView || !m_scrollView->isFrameView())
-        return 0;
-    
-    HTMLFrameOwnerElement* owner = static_cast<FrameView*>(m_scrollView)->frame()->ownerElement();
+        return nullptr;
+
+    AXObjectCache* cache = axObjectCache();
+    if (!cache)
+        return nullptr;
+
+    HTMLFrameOwnerElement* owner = toFrameView(m_scrollView)->frame().ownerElement();
     if (owner && owner->renderer())
-        return axObjectCache()->getOrCreate(owner);
+        return cache->getOrCreate(owner);
 
-    return 0;
+    return nullptr;
 }
     
 AccessibilityObject* AccessibilityScrollView::parentObjectIfExists() const
 {
     if (!m_scrollView || !m_scrollView->isFrameView())
-        return 0;
+        return nullptr;
     
-    HTMLFrameOwnerElement* owner = static_cast<FrameView*>(m_scrollView)->frame()->ownerElement();
+    AXObjectCache* cache = axObjectCache();
+    if (!cache)
+        return nullptr;
+
+    HTMLFrameOwnerElement* owner = toFrameView(m_scrollView)->frame().ownerElement();
     if (owner && owner->renderer())
-        return axObjectCache()->get(owner);
+        return cache->get(owner);
     
-    return 0;
+    return nullptr;
 }
 
 ScrollableArea* AccessibilityScrollView::getScrollableAreaIfScrollable() const