Use is<>() / downcast<>() for list-related render objects
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Oct 2014 06:04:36 +0000 (06:04 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Oct 2014 06:04:36 +0000 (06:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137764

Reviewed by Benjamin Poulain.

Use is<>() / downcast<>() for list-related render objects and clean up
the surrounding code.

No new tests, no behavior change.

* accessibility/AccessibilityListBox.cpp:
(WebCore::AccessibilityListBox::visibleChildren):
(WebCore::AccessibilityListBox::elementAccessibilityHitTest):
* accessibility/AccessibilityListBoxOption.cpp:
(WebCore::AccessibilityListBoxOption::elementRect):
* accessibility/AccessibilityObject.cpp:
(WebCore::renderListItemContainerForNode):
* accessibility/atk/WebKitAccessibleHyperlink.cpp:
(getRangeLengthForObject):
* accessibility/atk/WebKitAccessibleInterfaceText.cpp:
(accessibilityObjectLength):
(offsetAdjustmentForListItem):
(webkitAccessibleTextGetText):
* editing/BreakBlockquoteCommand.cpp:
(WebCore::BreakBlockquoteCommand::doApply):
* html/HTMLLIElement.cpp:
(WebCore::HTMLLIElement::didAttachRenderers):
(WebCore::HTMLLIElement::parseValue):
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::nextSelectableListIndexPageAway):
(WebCore::HTMLSelectElement::scrollToSelection):
(WebCore::HTMLSelectElement::setOptionsChangedOnRenderer):
(WebCore::HTMLSelectElement::selectOption):
(WebCore::HTMLSelectElement::platformHandleKeydownEvent):
(WebCore::HTMLSelectElement::menuListDefaultEventHandler):
(WebCore::HTMLSelectElement::listBoxDefaultEventHandler):
* html/HTMLSelectElementWin.cpp:
(WebCore::HTMLSelectElement::platformHandleKeydownEvent):
* page/mac/EventHandlerMac.mm:
(WebCore::EventHandler::platformPrepareForWheelEvents):
* rendering/InlineFlowBox.cpp:
(WebCore::InlineFlowBox::addToLine):
(WebCore::InlineFlowBox::placeBoxRangeInInlineDirection):
* rendering/RenderCounter.cpp:
(WebCore::planCounter):
* rendering/RenderListBox.h:
* rendering/RenderListItem.cpp:
(WebCore::nextListItem):
(WebCore::previousListItem):
* rendering/RenderListItem.h:
* rendering/RenderListMarker.h:
* rendering/RenderMenuList.h:
* rendering/RenderTreeAsText.cpp:
(WebCore::markerTextForListItem):
* rendering/TextAutoSizing.cpp:
(WebCore::TextAutoSizingValue::adjustNodeSizes):
* rendering/line/BreakingContextInlineHeaders.h:
(WebCore::BreakingContext::handleReplaced):
(WebCore::BreakingContext::commitAndUpdateLineBreakIfNeeded):
* testing/Internals.cpp:
(WebCore::Internals::isSelectPopupVisible):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@174759 268f45cc-cd09-0410-ab3c-d52691b4dbfc

22 files changed:
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityListBox.cpp
Source/WebCore/accessibility/AccessibilityListBoxOption.cpp
Source/WebCore/accessibility/AccessibilityObject.cpp
Source/WebCore/accessibility/atk/WebKitAccessibleHyperlink.cpp
Source/WebCore/accessibility/atk/WebKitAccessibleInterfaceText.cpp
Source/WebCore/editing/BreakBlockquoteCommand.cpp
Source/WebCore/html/HTMLLIElement.cpp
Source/WebCore/html/HTMLSelectElement.cpp
Source/WebCore/html/HTMLSelectElementWin.cpp
Source/WebCore/page/mac/EventHandlerMac.mm
Source/WebCore/rendering/InlineFlowBox.cpp
Source/WebCore/rendering/RenderCounter.cpp
Source/WebCore/rendering/RenderListBox.h
Source/WebCore/rendering/RenderListItem.cpp
Source/WebCore/rendering/RenderListItem.h
Source/WebCore/rendering/RenderListMarker.h
Source/WebCore/rendering/RenderMenuList.h
Source/WebCore/rendering/RenderTreeAsText.cpp
Source/WebCore/rendering/TextAutoSizing.cpp
Source/WebCore/rendering/line/BreakingContextInlineHeaders.h
Source/WebCore/testing/Internals.cpp

index 25ee5c0..3f2fc1b 100644 (file)
@@ -1,3 +1,67 @@
+2014-10-15  Chris Dumez  <cdumez@apple.com>
+
+        Use is<>() / downcast<>() for list-related render objects
+        https://bugs.webkit.org/show_bug.cgi?id=137764
+
+        Reviewed by Benjamin Poulain.
+
+        Use is<>() / downcast<>() for list-related render objects and clean up
+        the surrounding code.
+
+        No new tests, no behavior change.
+
+        * accessibility/AccessibilityListBox.cpp:
+        (WebCore::AccessibilityListBox::visibleChildren):
+        (WebCore::AccessibilityListBox::elementAccessibilityHitTest):
+        * accessibility/AccessibilityListBoxOption.cpp:
+        (WebCore::AccessibilityListBoxOption::elementRect):
+        * accessibility/AccessibilityObject.cpp:
+        (WebCore::renderListItemContainerForNode):
+        * accessibility/atk/WebKitAccessibleHyperlink.cpp:
+        (getRangeLengthForObject):
+        * accessibility/atk/WebKitAccessibleInterfaceText.cpp:
+        (accessibilityObjectLength):
+        (offsetAdjustmentForListItem):
+        (webkitAccessibleTextGetText):
+        * editing/BreakBlockquoteCommand.cpp:
+        (WebCore::BreakBlockquoteCommand::doApply):
+        * html/HTMLLIElement.cpp:
+        (WebCore::HTMLLIElement::didAttachRenderers):
+        (WebCore::HTMLLIElement::parseValue):
+        * html/HTMLSelectElement.cpp:
+        (WebCore::HTMLSelectElement::nextSelectableListIndexPageAway):
+        (WebCore::HTMLSelectElement::scrollToSelection):
+        (WebCore::HTMLSelectElement::setOptionsChangedOnRenderer):
+        (WebCore::HTMLSelectElement::selectOption):
+        (WebCore::HTMLSelectElement::platformHandleKeydownEvent):
+        (WebCore::HTMLSelectElement::menuListDefaultEventHandler):
+        (WebCore::HTMLSelectElement::listBoxDefaultEventHandler):
+        * html/HTMLSelectElementWin.cpp:
+        (WebCore::HTMLSelectElement::platformHandleKeydownEvent):
+        * page/mac/EventHandlerMac.mm:
+        (WebCore::EventHandler::platformPrepareForWheelEvents):
+        * rendering/InlineFlowBox.cpp:
+        (WebCore::InlineFlowBox::addToLine):
+        (WebCore::InlineFlowBox::placeBoxRangeInInlineDirection):
+        * rendering/RenderCounter.cpp:
+        (WebCore::planCounter):
+        * rendering/RenderListBox.h:
+        * rendering/RenderListItem.cpp:
+        (WebCore::nextListItem):
+        (WebCore::previousListItem):
+        * rendering/RenderListItem.h:
+        * rendering/RenderListMarker.h:
+        * rendering/RenderMenuList.h:
+        * rendering/RenderTreeAsText.cpp:
+        (WebCore::markerTextForListItem):
+        * rendering/TextAutoSizing.cpp:
+        (WebCore::TextAutoSizingValue::adjustNodeSizes):
+        * rendering/line/BreakingContextInlineHeaders.h:
+        (WebCore::BreakingContext::handleReplaced):
+        (WebCore::BreakingContext::commitAndUpdateLineBreakIfNeeded):
+        * testing/Internals.cpp:
+        (WebCore::Internals::isSelectPopupVisible):
+
 2014-10-15  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
 
         Use std::unique_ptr for CachedResource
index 0f8e1d9..3561ee6 100644 (file)
@@ -127,7 +127,7 @@ void AccessibilityListBox::visibleChildren(AccessibilityChildrenVector& result)
     
     unsigned length = m_children.size();
     for (unsigned i = 0; i < length; i++) {
-        if (toRenderListBox(m_renderer)->listIndexIsVisible(i))
+        if (downcast<RenderListBox>(*m_renderer).listIndexIsVisible(i))
             result.append(m_children[i]);
     }
 }
@@ -159,8 +159,8 @@ AccessibilityObject* AccessibilityListBox::elementAccessibilityHitTest(const Int
     
     AccessibilityObject* listBoxOption = nullptr;
     unsigned length = m_children.size();
-    for (unsigned i = 0; i < length; i++) {
-        LayoutRect rect = toRenderListBox(m_renderer)->itemBoundingBoxRect(parentRect.location(), i);
+    for (unsigned i = 0; i < length; ++i) {
+        LayoutRect rect = downcast<RenderListBox>(*m_renderer).itemBoundingBoxRect(parentRect.location(), i);
         // The cast to HTMLElement below is safe because the only other possible listItem type
         // would be a WMLElement, but WML builds don't use accessibility features at all.
         if (rect.contains(point)) {
index dca0ea6..caa6db0 100644 (file)
@@ -100,14 +100,14 @@ LayoutRect AccessibilityListBoxOption::elementRect() const
     if (!listBoxParentNode)
         return rect;
     
-    RenderObject* listBoxRenderer = listBoxParentNode->renderer();
+    RenderElement* listBoxRenderer = listBoxParentNode->renderer();
     if (!listBoxRenderer)
         return rect;
     
     LayoutRect parentRect = listBoxRenderer->document().axObjectCache()->getOrCreate(listBoxRenderer)->boundingBoxRect();
     int index = listBoxOptionIndex();
     if (index != -1)
-        rect = toRenderListBox(listBoxRenderer)->itemBoundingBoxRect(parentRect.location(), index);
+        rect = downcast<RenderListBox>(*listBoxRenderer).itemBoundingBoxRect(parentRect.location(), index);
     
     return rect;
 }
index e47ba94..e7c7d2c 100644 (file)
@@ -1160,8 +1160,8 @@ static RenderListItem* renderListItemContainerForNode(Node* node)
 {
     for (; node; node = node->parentNode()) {
         RenderBoxModelObject* renderer = node->renderBoxModelObject();
-        if (renderer && renderer->isListItem())
-            return toRenderListItem(renderer);
+        if (is<RenderListItem>(renderer))
+            return downcast<RenderListItem>(renderer);
     }
     return nullptr;
 }
index 0e4a0c8..cd79c4b 100644 (file)
@@ -231,10 +231,10 @@ static gint getRangeLengthForObject(AccessibilityObject* obj, Range* range)
         return baseLength;
 
     RenderObject* renderer = markerObj->renderer();
-    if (!renderer || !renderer->isListMarker())
+    if (!is<RenderListMarker>(renderer))
         return baseLength;
 
-    RenderListMarker& marker = toRenderListMarker(*renderer);
+    auto& marker = downcast<RenderListMarker>(*renderer);
     return baseLength + marker.text().length() + marker.suffix().length();
 }
 
index 394928b..d1419d8 100644 (file)
@@ -270,8 +270,8 @@ static guint accessibilityObjectLength(const AccessibilityObject* object)
     // for those cases when it's needed to take it into account
     // separately (as in getAccessibilityObjectForOffset)
     RenderObject* renderer = object->renderer();
-    if (renderer && renderer->isListMarker()) {
-        RenderListMarker& marker = toRenderListMarker(*renderer);
+    if (is<RenderListMarker>(renderer)) {
+        auto& marker = downcast<RenderListMarker>(*renderer);
         return marker.text().length() + marker.suffix().length();
     }
 
@@ -363,8 +363,8 @@ static int offsetAdjustmentForListItem(const AccessibilityObject* object)
     // We need to adjust the offsets for the list item marker in
     // Left-To-Right text, since we expose it together with the text.
     RenderObject* renderer = object->renderer();
-    if (renderer && renderer->isListItem() && renderer->style().direction() == LTR)
-        return toRenderListItem(renderer)->markerTextWithSuffix().length();
+    if (is<RenderListItem>(renderer) && renderer->style().direction() == LTR)
+        return downcast<RenderListItem>(*renderer).markerTextWithSuffix().length();
 
     return 0;
 }
@@ -495,8 +495,8 @@ static gchar* webkitAccessibleTextGetText(AtkText* text, gint startOffset, gint
     int actualEndOffset = endOffset == -1 ? ret.length() : endOffset;
     if (coreObject->roleValue() == ListItemRole) {
         RenderObject* objRenderer = coreObject->renderer();
-        if (objRenderer && objRenderer->isListItem()) {
-            String markerText = toRenderListItem(objRenderer)->markerTextWithSuffix();
+        if (is<RenderListItem>(objRenderer)) {
+            String markerText = downcast<RenderListItem>(*objRenderer).markerTextWithSuffix();
             ret = objRenderer->style().direction() == LTR ? markerText + ret : ret + markerText;
             if (endOffset == -1)
                 actualEndOffset = ret.length() + markerText.length();
index 644d345..294adb6 100644 (file)
@@ -148,8 +148,8 @@ void BreakBlockquoteCommand::doApply()
             // find the first one so that we know where to start numbering.
             while (listChildNode && !listChildNode->hasTagName(liTag))
                 listChildNode = listChildNode->nextSibling();
-            if (listChildNode && listChildNode->renderer() && listChildNode->renderer()->isListItem())
-                setNodeAttribute(clonedChild, startAttr, AtomicString::number(toRenderListItem(listChildNode->renderer())->value()));
+            if (listChildNode && is<RenderListItem>(listChildNode->renderer()))
+                setNodeAttribute(clonedChild, startAttr, AtomicString::number(downcast<RenderListItem>(*listChildNode->renderer()).value()));
         }
             
         appendNode(clonedChild.get(), clonedAncestor.get());
index ab2df91..827b361 100644 (file)
@@ -26,6 +26,7 @@
 #include "Attribute.h"
 #include "CSSPropertyNames.h"
 #include "CSSValueKeywords.h"
+#include "ElementAncestorIterator.h"
 #include "HTMLNames.h"
 #include "RenderListItem.h"
 
@@ -87,39 +88,37 @@ void HTMLLIElement::parseAttribute(const QualifiedName& name, const AtomicString
 
 void HTMLLIElement::didAttachRenderers()
 {
-    if (!renderer() || !renderer()->isListItem())
+    if (!is<RenderListItem>(renderer()))
         return;
-    RenderListItem* listItemRenderer = toRenderListItem(renderer());
-
-    // Find the enclosing list node.
-    Element* listNode = 0;
-    Element* current = this;
-    while (!listNode) {
-        current = current->parentElement();
-        if (!current)
+    auto& listItemRenderer = downcast<RenderListItem>(*renderer());
+
+    // Check if there is an enclosing list.
+    bool isInList = false;
+    for (auto& ancestor : ancestorsOfType<HTMLElement>(*this)) {
+        if (is<HTMLUListElement>(ancestor) || is<HTMLOListElement>(ancestor)) {
+            isInList = true;
             break;
-        if (current->hasTagName(ulTag) || current->hasTagName(olTag))
-            listNode = current;
+        }
     }
 
     // If we are not in a list, tell the renderer so it can position us inside.
     // We don't want to change our style to say "inside" since that would affect nested nodes.
-    if (!listNode)
-        listItemRenderer->setNotInList(true);
+    if (!isInList)
+        listItemRenderer.setNotInList(true);
 
     parseValue(fastGetAttribute(valueAttr));
 }
 
 inline void HTMLLIElement::parseValue(const AtomicString& value)
 {
-    ASSERT(renderer() && renderer()->isListItem());
+    ASSERT(renderer());
 
     bool valueOK;
     int requestedValue = value.toInt(&valueOK);
     if (valueOK)
-        toRenderListItem(renderer())->setExplicitValue(requestedValue);
+        downcast<RenderListItem>(*renderer()).setExplicitValue(requestedValue);
     else
-        toRenderListItem(renderer())->clearExplicitValue();
+        downcast<RenderListItem>(*renderer()).clearExplicitValue();
 }
 
 }
index c4d1265..4f89836 100644 (file)
@@ -562,14 +562,14 @@ int HTMLSelectElement::nextSelectableListIndexPageAway(int startIndex, SkipDirec
     const Vector<HTMLElement*>& items = listItems();
     // Can't use m_size because renderer forces a minimum size.
     int pageSize = 0;
-    if (renderer()->isListBox())
-        pageSize = toRenderListBox(renderer())->size() - 1; // -1 so we still show context.
+    if (is<RenderListBox>(*renderer()))
+        pageSize = downcast<RenderListBox>(*renderer()).size() - 1; // -1 so we still show context.
 
     // One page away, but not outside valid bounds.
     // If there is a valid option item one page away, the index is chosen.
     // If there is no exact one page away valid option, returns startIndex or the most far index.
-    int edgeIndex = (direction == SkipForwards) ? 0 : (items.size() - 1);
-    int skipAmount = pageSize + ((direction == SkipForwards) ? startIndex : (edgeIndex - startIndex));
+    int edgeIndex = direction == SkipForwards ? 0 : items.size() - 1;
+    int skipAmount = pageSize + (direction == SkipForwards ? startIndex : edgeIndex - startIndex);
     return nextValidIndex(edgeIndex, direction, skipAmount);
 }
 
@@ -707,26 +707,26 @@ void HTMLSelectElement::scrollToSelection()
     if (usesMenuList())
         return;
 
-    auto renderer = this->renderer();
-    if (!renderer || !renderer->isListBox())
+    auto* renderer = this->renderer();
+    if (!is<RenderListBox>(renderer))
         return;
-    toRenderListBox(renderer)->selectionChanged();
+    downcast<RenderListBox>(*renderer).selectionChanged();
 #else
-    if (auto renderer = this->renderer())
+    if (auto* renderer = this->renderer())
         renderer->repaint();
 #endif
 }
 
 void HTMLSelectElement::setOptionsChangedOnRenderer()
 {
-    if (auto renderer = this->renderer()) {
+    if (auto* renderer = this->renderer()) {
 #if !PLATFORM(IOS)
-        if (renderer->isMenuList())
-            toRenderMenuList(renderer)->setOptionsChanged(true);
+        if (is<RenderMenuList>(*renderer))
+            downcast<RenderMenuList>(*renderer).setOptionsChanged(true);
         else
-            toRenderListBox(renderer)->setOptionsChanged(true);
+            downcast<RenderListBox>(*renderer).setOptionsChanged(true);
 #else
-        toRenderMenuList(renderer)->setOptionsChanged(true);
+        downcast<RenderMenuList>(*renderer).setOptionsChanged(true);
 #endif
     }
 }
@@ -889,7 +889,7 @@ void HTMLSelectElement::selectOption(int optionIndex, SelectOptionFlags flags)
         deselectItemsWithoutValidation(element);
 
     // For the menu list case, this is what makes the selected element appear.
-    if (auto renderer = this->renderer())
+    if (auto* renderer = this->renderer())
         renderer->updateFromElement();
 
     scrollToSelection();
@@ -898,11 +898,11 @@ void HTMLSelectElement::selectOption(int optionIndex, SelectOptionFlags flags)
         m_isProcessingUserDrivenChange = flags & UserDriven;
         if (flags & DispatchChangeEvent)
             dispatchChangeEventForMenuList();
-        if (auto renderer = this->renderer()) {
-            if (renderer->isMenuList())
-                toRenderMenuList(renderer)->didSetSelectedIndex(listIndex);
+        if (auto* renderer = this->renderer()) {
+            if (is<RenderMenuList>(*renderer))
+                downcast<RenderMenuList>(*renderer).didSetSelectedIndex(listIndex);
             else
-                toRenderListBox(renderer)->selectionChanged();
+                downcast<RenderListBox>(*renderer).selectionChanged();
         }
     }
 
@@ -1120,7 +1120,7 @@ bool HTMLSelectElement::platformHandleKeydownEvent(KeyboardEvent* event)
             // Calling focus() may cause us to lose our renderer. Return true so
             // that our caller doesn't process the event further, but don't set
             // the event as handled.
-            if (!renderer() || !renderer()->isMenuList())
+            if (!is<RenderMenuList>(renderer()))
                 return true;
 
             // Save the selection so it can be compared to the new selection
@@ -1128,7 +1128,7 @@ bool HTMLSelectElement::platformHandleKeydownEvent(KeyboardEvent* event)
             // gets called from RenderMenuList::valueChanged, which gets called
             // after the user makes a selection from the menu.
             saveLastSelection();
-            toRenderMenuList(renderer())->showPopup();
+            downcast<RenderMenuList>(*renderer()).showPopup();
             event->setDefaultHandled();
         }
         return true;
@@ -1219,7 +1219,7 @@ void HTMLSelectElement::menuListDefaultEventHandler(Event* event)
 
                 // Calling focus() may remove the renderer or change the
                 // renderer type.
-                if (!renderer() || !renderer()->isMenuList())
+                if (!is<RenderMenuList>(renderer()))
                     return;
 
                 // Save the selection so it can be compared to the new selection
@@ -1227,7 +1227,7 @@ void HTMLSelectElement::menuListDefaultEventHandler(Event* event)
                 // gets called from RenderMenuList::valueChanged, which gets called
                 // after the user makes a selection from the menu.
                 saveLastSelection();
-                toRenderMenuList(renderer())->showPopup();
+                downcast<RenderMenuList>(*renderer()).showPopup();
                 handled = true;
             }
         } else if (renderTheme->popsMenuByArrowKeys()) {
@@ -1236,7 +1236,7 @@ void HTMLSelectElement::menuListDefaultEventHandler(Event* event)
 
                 // Calling focus() may remove the renderer or change the
                 // renderer type.
-                if (!renderer() || !renderer()->isMenuList())
+                if (!is<RenderMenuList>(renderer()))
                     return;
 
                 // Save the selection so it can be compared to the new selection
@@ -1244,7 +1244,7 @@ void HTMLSelectElement::menuListDefaultEventHandler(Event* event)
                 // gets called from RenderMenuList::valueChanged, which gets called
                 // after the user makes a selection from the menu.
                 saveLastSelection();
-                toRenderMenuList(renderer())->showPopup();
+                downcast<RenderMenuList>(*renderer()).showPopup();
                 handled = true;
             } else if (keyCode == '\r') {
                 if (form())
@@ -1261,8 +1261,8 @@ void HTMLSelectElement::menuListDefaultEventHandler(Event* event)
     if (event->type() == eventNames().mousedownEvent && is<MouseEvent>(*event) && downcast<MouseEvent>(*event).button() == LeftButton) {
         focus();
 #if !PLATFORM(IOS)
-        if (renderer() && renderer()->isMenuList()) {
-            auto& menuList = toRenderMenuList(*renderer());
+        if (is<RenderMenuList>(renderer())) {
+            auto& menuList = downcast<RenderMenuList>(*renderer());
             ASSERT(!menuList.popupIsVisible());
             // Save the selection so it can be compared to the new
             // selection when we call onChange during selectOption,
@@ -1278,7 +1278,7 @@ void HTMLSelectElement::menuListDefaultEventHandler(Event* event)
 
 #if !PLATFORM(IOS)
     if (event->type() == eventNames().blurEvent && !focused()) {
-        auto& menuList = toRenderMenuList(*renderer());
+        auto& menuList = downcast<RenderMenuList>(*renderer());
         if (menuList.popupIsVisible())
             menuList.hidePopup();
     }
@@ -1341,13 +1341,13 @@ void HTMLSelectElement::listBoxDefaultEventHandler(Event* event)
     if (event->type() == eventNames().mousedownEvent && is<MouseEvent>(*event) && downcast<MouseEvent>(*event).button() == LeftButton) {
         focus();
         // Calling focus() may remove or change our renderer, in which case we don't want to handle the event further.
-        if (!renderer() || !renderer()->isListBox())
+        if (!is<RenderListBox>(renderer()))
             return;
 
         // Convert to coords relative to the list box if needed.
         MouseEvent& mouseEvent = downcast<MouseEvent>(*event);
         IntPoint localOffset = roundedIntPoint(renderer()->absoluteToLocal(mouseEvent.absoluteLocation(), UseTransforms));
-        int listIndex = toRenderListBox(renderer())->listIndexAtOffset(toIntSize(localOffset));
+        int listIndex = downcast<RenderListBox>(*renderer()).listIndexAtOffset(toIntSize(localOffset));
         if (listIndex >= 0) {
             if (!isDisabledFormControl()) {
 #if PLATFORM(COCOA)
@@ -1367,7 +1367,7 @@ void HTMLSelectElement::listBoxDefaultEventHandler(Event* event)
             return;
 
         IntPoint localOffset = roundedIntPoint(renderer()->absoluteToLocal(mouseEvent.absoluteLocation(), UseTransforms));
-        int listIndex = toRenderListBox(renderer())->listIndexAtOffset(toIntSize(localOffset));
+        int listIndex = downcast<RenderListBox>(*renderer()).listIndexAtOffset(toIntSize(localOffset));
         if (listIndex >= 0) {
             if (!isDisabledFormControl()) {
                 if (m_multiple) {
@@ -1475,7 +1475,7 @@ void HTMLSelectElement::listBoxDefaultEventHandler(Event* event)
                 setActiveSelectionAnchorIndex(m_activeSelectionEndIndex);
             }
 
-            toRenderListBox(renderer())->scrollToRevealElementAtListIndex(endIndex);
+            downcast<RenderListBox>(*renderer()).scrollToRevealElementAtListIndex(endIndex);
             if (selectNewItem) {
                 updateListBoxSelection(deselectOthers);
                 listBoxOnChange();
index 201c6a5..90f6ef7 100644 (file)
@@ -45,7 +45,7 @@ bool HTMLSelectElement::platformHandleKeydownEvent(KeyboardEvent* event)
     // Save the selection so it can be compared to the new selection when dispatching change events during setSelectedIndex,
     // which gets called from RenderMenuList::valueChanged, which gets called after the user makes a selection from the menu.
     saveLastSelection();
-    if (RenderMenuList* menuList = toRenderMenuList(renderer()))
+    if (auto* menuList = downcast<RenderMenuList>(renderer()))
         menuList->showPopup();
 
     int index = selectedIndex();
index 3d75148..42abc38 100644 (file)
@@ -842,8 +842,8 @@ void EventHandler::platformPrepareForWheelEvents(const PlatformWheelEvent& wheel
             scrollableContainer = findEnclosingScrollableContainer(*wheelEventTarget);
             if (scrollableContainer) {
                 if (RenderBox* box = scrollableContainer->renderBox()) {
-                    if (box->isListBox())
-                        scrollableArea = toRenderListBox(box);
+                    if (is<RenderListBox>(*box))
+                        scrollableArea = downcast<RenderListBox>(box);
                     else
                         scrollableArea = box->layer();
                 }
index 812dd0d..c89d02b 100644 (file)
@@ -161,7 +161,7 @@ void InlineFlowBox::addToLine(InlineBox* child)
             if (box.hasRenderOverflow() || box.hasSelfPaintingLayer())
                 child->clearKnownToHaveNoOverflow();
         } else if (!child->renderer().isLineBreak() && (childStyle.boxShadow() || child->boxModelObject()->hasSelfPaintingLayer()
-            || (child->renderer().isListMarker() && !toRenderListMarker(child->renderer()).isInside())
+            || (is<RenderListMarker>(child->renderer()) && !downcast<RenderListMarker>(child->renderer()).isInside())
             || childStyle.hasBorderImageOutsets()))
             child->clearKnownToHaveNoOverflow();
         
@@ -408,7 +408,7 @@ float InlineFlowBox::placeBoxRangeInInlineDirection(InlineBox* firstChild, Inlin
                 if (knownToHaveNoOverflow())
                     maxLogicalRight = std::max(logicalLeft, maxLogicalRight);
                 logicalLeft += flow.marginLogicalRight();
-            } else if (!child->renderer().isListMarker() || toRenderListMarker(child->renderer()).isInside()) {
+            } else if (!is<RenderListMarker>(child->renderer()) || downcast<RenderListMarker>(child->renderer()).isInside()) {
                 // The box can have a different writing-mode than the overall line, so this is a bit complicated.
                 // Just get all the physical margin and overflow values by hand based off |isVertical|.
                 LayoutUnit logicalLeftMargin = isHorizontal() ? child->boxModelObject()->marginLeft() : child->boxModelObject()->marginTop();
index 4878b6f..5d57069 100644 (file)
@@ -131,9 +131,9 @@ static bool planCounter(RenderElement& renderer, const AtomicString& identifier,
     }
 
     if (identifier == "list-item") {
-        if (renderer.isListItem()) {
-            if (toRenderListItem(renderer).hasExplicitValue()) {
-                value = toRenderListItem(renderer).explicitValue();
+        if (is<RenderListItem>(renderer)) {
+            if (downcast<RenderListItem>(renderer).hasExplicitValue()) {
+                value = downcast<RenderListItem>(renderer).explicitValue();
                 isReset = true;
                 return true;
             }
index 5220b82..8ae69db 100644 (file)
@@ -161,8 +161,6 @@ private:
     RefPtr<Scrollbar> m_vBar;
 };
 
-RENDER_OBJECT_TYPE_CASTS(RenderListBox, isListBox())
-
 } // namepace WebCore
 
 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderListBox, isListBox())
index 62f745f..324bb0c 100644 (file)
@@ -118,10 +118,10 @@ static Element* enclosingList(const RenderListItem* listItem)
 }
 
 // Returns the next list item with respect to the DOM order.
-static RenderListItem* nextListItem(const Element* listNode, const RenderListItem* item = 0)
+static RenderListItem* nextListItem(const Element* listNode, const RenderListItem* item = nullptr)
 {
     if (!listNode)
-        return 0;
+        return nullptr;
 
     const Element* current = item ? &item->element() : listNode;
     current = ElementTraversal::nextIncludingPseudo(current, listNode);
@@ -133,15 +133,15 @@ static RenderListItem* nextListItem(const Element* listNode, const RenderListIte
             continue;
         }
 
-        RenderObject* renderer = current->renderer();
-        if (renderer && renderer->isListItem())
-            return toRenderListItem(renderer);
+        RenderElement* renderer = current->renderer();
+        if (is<RenderListItem>(renderer))
+            return downcast<RenderListItem>(renderer);
 
         // FIXME: Can this be optimized to skip the children of the elements without a renderer?
         current = ElementTraversal::nextIncludingPseudo(current, listNode);
     }
 
-    return 0;
+    return nullptr;
 }
 
 // Returns the previous list item with respect to the DOM order.
@@ -149,13 +149,13 @@ static RenderListItem* previousListItem(const Element* listNode, const RenderLis
 {
     Element* current = &item->element();
     for (current = ElementTraversal::previousIncludingPseudo(current, listNode); current; current = ElementTraversal::previousIncludingPseudo(current, listNode)) {
-        RenderObject* renderer = current->renderer();
-        if (!renderer || (renderer && !renderer->isListItem()))
+        RenderElement* renderer = current->renderer();
+        if (!is<RenderListItem>(renderer))
             continue;
-        Node* otherList = enclosingList(toRenderListItem(renderer));
+        Element* otherList = enclosingList(downcast<RenderListItem>(renderer));
         // This item is part of our current list, so it's what we're looking for.
         if (listNode == otherList)
-            return toRenderListItem(renderer);
+            return downcast<RenderListItem>(renderer);
         // We found ourself inside another list; lets skip the rest of it.
         // Use nextIncludingPseudo() here because the other list itself may actually
         // be a list item itself. We need to examine it, so we do this to counteract
@@ -163,7 +163,7 @@ static RenderListItem* previousListItem(const Element* listNode, const RenderLis
         if (otherList)
             current = ElementTraversal::nextIncludingPseudo(otherList);
     }
-    return 0;
+    return nullptr;
 }
 
 void RenderListItem::updateItemValuesForOrderedList(const HTMLOListElement* listNode)
index 0a81a38..73da6fb 100644 (file)
@@ -93,8 +93,6 @@ private:
     bool m_notInList : 1;
 };
 
-RENDER_OBJECT_TYPE_CASTS(RenderListItem, isListItem())
-
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderListItem, isListItem())
index ea8d32f..1a7fb70 100644 (file)
@@ -85,8 +85,6 @@ private:
     RenderListItem& m_listItem;
 };
 
-RENDER_OBJECT_TYPE_CASTS(RenderListMarker, isListMarker())
-
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderListMarker, isListMarker())
index 93e6bb2..750e6af 100644 (file)
@@ -152,8 +152,6 @@ private:
 #endif
 };
 
-RENDER_OBJECT_TYPE_CASTS(RenderMenuList, isMenuList())
-
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderMenuList, isMenuList())
index b7cde74..a64be62 100644 (file)
@@ -934,11 +934,11 @@ String markerTextForListItem(Element* element)
     RefPtr<Element> elementRef(element);
     element->document().updateLayout();
 
-    RenderObject* renderer = element->renderer();
-    if (!renderer || !renderer->isListItem())
+    RenderElement* renderer = element->renderer();
+    if (!is<RenderListItem>(renderer))
         return String();
 
-    return toRenderListItem(renderer)->markerText();
+    return downcast<RenderListItem>(*renderer).markerText();
 }
 
 } // namespace WebCore
index a3727e9..cb91c1d 100644 (file)
@@ -177,7 +177,7 @@ bool TextAutoSizingValue::adjustNodeSizes()
                 RefPtr<RenderStyle> style = cloneRenderStyleWithState(listMarkerRenderer->style());
                 style->setFontDescription(fontDescription);
                 style->font().update(autoSizingNode->document().ensureStyleResolver().fontSelector());
-                toRenderListMarker(*listMarkerRenderer).setStyle(style.releaseNonNull());
+                downcast<RenderListMarker>(*listMarkerRenderer).setStyle(style.releaseNonNull());
             }
             
             // Resize the line height of the parent.
index 9aeffb4..09e80a3 100644 (file)
@@ -430,7 +430,7 @@ inline void BreakingContext::handleReplaced()
     // Optimize for a common case. If we can't find whitespace after the list
     // item, then this is all moot.
     LayoutUnit replacedLogicalWidth = m_block.logicalWidthForChild(replacedBox) + m_block.marginStartForChild(replacedBox) + m_block.marginEndForChild(replacedBox) + inlineLogicalWidth(m_current.renderer());
-    if (m_current.renderer()->isListMarker()) {
+    if (is<RenderListMarker>(*m_current.renderer())) {
         if (m_blockStyle.collapseWhiteSpace() && shouldSkipWhitespaceAfterStartObject(m_block, m_current.renderer(), m_lineMidpointState)) {
             // Like with inline flows, we start ignoring spaces to make sure that any
             // additional spaces we see will be discarded.
@@ -438,12 +438,12 @@ inline void BreakingContext::handleReplaced()
             m_currentCharacterIsWS = false;
             m_ignoringSpaces = true;
         }
-        if (toRenderListMarker(*m_current.renderer()).isInside())
+        if (downcast<RenderListMarker>(*m_current.renderer()).isInside())
             m_width.addUncommittedWidth(replacedLogicalWidth);
     } else
         m_width.addUncommittedWidth(replacedLogicalWidth);
-    if (m_current.renderer()->isRubyRun())
-        m_width.applyOverhang(toRenderRubyRun(m_current.renderer()), m_lastObject, m_nextObject);
+    if (is<RenderRubyRun>(*m_current.renderer()))
+        m_width.applyOverhang(downcast<RenderRubyRun>(m_current.renderer()), m_lastObject, m_nextObject);
     // Update prior line break context characters, using U+FFFD (OBJECT REPLACEMENT CHARACTER) for replaced element.
     m_renderTextInfo.m_lineBreakIterator.updatePriorContext(replacementCharacter);
 }
@@ -995,7 +995,7 @@ inline void BreakingContext::commitAndUpdateLineBreakIfNeeded()
 
     if (!m_current.renderer()->isFloatingOrOutOfFlowPositioned()) {
         m_lastObject = m_current.renderer();
-        if (m_lastObject->isReplaced() && m_autoWrap && (!m_lastObject->isImage() || m_allowImagesToBreak) && (!m_lastObject->isListMarker() || toRenderListMarker(*m_lastObject).isInside())) {
+        if (m_lastObject->isReplaced() && m_autoWrap && (!m_lastObject->isImage() || m_allowImagesToBreak) && (!is<RenderListMarker>(*m_lastObject) || downcast<RenderListMarker>(*m_lastObject).isInside())) {
             m_width.commit();
             m_lineBreak.moveToStartOf(m_nextObject);
         }
index 3e3ba33..148d3c2 100644 (file)
@@ -2092,13 +2092,13 @@ bool Internals::isSelectPopupVisible(Node* node)
 
     HTMLSelectElement& select = downcast<HTMLSelectElement>(*node);
 
-    auto renderer = select.renderer();
-    if (!renderer->isMenuList())
+    auto* renderer = select.renderer();
+    ASSERT(renderer);
+    if (!is<RenderMenuList>(*renderer))
         return false;
 
 #if !PLATFORM(IOS)
-    RenderMenuList* menuList = toRenderMenuList(renderer);
-    return menuList->popupIsVisible();
+    return downcast<RenderMenuList>(*renderer).popupIsVisible();
 #else
     return false;
 #endif // !PLATFORM(IOS)