Skip to content
Permalink
Browse files
Adopt is/toHTMLOptGroupElement for code cleanup
https://bugs.webkit.org/show_bug.cgi?id=118213

Reviewed by Andreas Kling.

To enhance readability, this patch adopts is/toHTMLOptGroupElement.
This also helps out to reduce duplicated use of static_cast.

Source/WebCore:

* accessibility/AccessibilityListBoxOption.cpp:
(WebCore::AccessibilityListBoxOption::isEnabled):
(WebCore::AccessibilityListBoxOption::stringValue):
(WebCore::AccessibilityListBoxOption::listBoxOptionParentNode):
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::canShareStyleWithElement):
* html/HTMLOptGroupElement.h:
(WebCore::isHTMLOptGroupElement):
(WebCore::toHTMLOptGroupElement):
* html/HTMLOptionElement.cpp:
(WebCore::HTMLOptionElement::textIndentedToRespectGroupLabel):
(WebCore::HTMLOptionElement::isDisabledFormControl):
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::childShouldCreateRenderer):
(WebCore::HTMLSelectElement::recalcListItems):
* html/parser/HTMLConstructionSite.cpp:
(WebCore::hasImpliedEndTag):
* html/parser/HTMLElementStack.cpp:
(WebCore::HTMLNames::isSelectScopeMarker):
* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::processStartTag):
(WebCore::HTMLTreeBuilder::processEndTag):
* rendering/RenderListBox.cpp:
(WebCore::RenderListBox::updateFromElement):
(WebCore::RenderListBox::paintItemForeground):
* rendering/RenderMenuList.cpp:
(WebCore::RenderMenuList::itemText):
(WebCore::RenderMenuList::itemIsEnabled):
(WebCore::RenderMenuList::itemIsLabel):

Source/WebKit/blackberry:

* WebKitSupport/InputHandler.cpp:
(BlackBerry::WebKit::InputHandler::openSelectPopup):


Canonical link: https://commits.webkit.org/136264@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@152211 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Kangil Han committed Jun 29, 2013
1 parent b0f1bd7 commit e5068a6968a61c566b96825a89e1e619feb19a5f
Showing 14 changed files with 101 additions and 29 deletions.
@@ -1,3 +1,45 @@
2013-06-29 Kangil Han <kangil.han@samsung.com>

Adopt is/toHTMLOptGroupElement for code cleanup
https://bugs.webkit.org/show_bug.cgi?id=118213

Reviewed by Andreas Kling.

To enhance readability, this patch adopts is/toHTMLOptGroupElement.
This also helps out to reduce duplicated use of static_cast.

* accessibility/AccessibilityListBoxOption.cpp:
(WebCore::AccessibilityListBoxOption::isEnabled):
(WebCore::AccessibilityListBoxOption::stringValue):
(WebCore::AccessibilityListBoxOption::listBoxOptionParentNode):
* css/SelectorChecker.cpp:
(WebCore::SelectorChecker::checkOne):
* css/StyleResolver.cpp:
(WebCore::StyleResolver::canShareStyleWithElement):
* html/HTMLOptGroupElement.h:
(WebCore::isHTMLOptGroupElement):
(WebCore::toHTMLOptGroupElement):
* html/HTMLOptionElement.cpp:
(WebCore::HTMLOptionElement::textIndentedToRespectGroupLabel):
(WebCore::HTMLOptionElement::isDisabledFormControl):
* html/HTMLSelectElement.cpp:
(WebCore::HTMLSelectElement::childShouldCreateRenderer):
(WebCore::HTMLSelectElement::recalcListItems):
* html/parser/HTMLConstructionSite.cpp:
(WebCore::hasImpliedEndTag):
* html/parser/HTMLElementStack.cpp:
(WebCore::HTMLNames::isSelectScopeMarker):
* html/parser/HTMLTreeBuilder.cpp:
(WebCore::HTMLTreeBuilder::processStartTag):
(WebCore::HTMLTreeBuilder::processEndTag):
* rendering/RenderListBox.cpp:
(WebCore::RenderListBox::updateFromElement):
(WebCore::RenderListBox::paintItemForeground):
* rendering/RenderMenuList.cpp:
(WebCore::RenderMenuList::itemText):
(WebCore::RenderMenuList::itemIsEnabled):
(WebCore::RenderMenuList::itemIsLabel):

2013-06-29 ChangSeok Oh <changseok.oh@collabora.com>

Build fix for unguarded SVGGraphicsElement
@@ -66,7 +66,7 @@ bool AccessibilityListBoxOption::isEnabled() const
if (!m_optionElement)
return false;

if (m_optionElement->hasTagName(optgroupTag))
if (isHTMLOptGroupElement(m_optionElement))
return false;

if (equalIgnoringCase(getAttribute(aria_disabledAttr), "true"))
@@ -161,8 +161,8 @@ String AccessibilityListBoxOption::stringValue() const
if (isHTMLOptionElement(m_optionElement))
return toHTMLOptionElement(m_optionElement)->text();

if (m_optionElement->hasTagName(optgroupTag))
return static_cast<HTMLOptGroupElement*>(m_optionElement)->groupLabelText();
if (isHTMLOptGroupElement(m_optionElement))
return toHTMLOptGroupElement(m_optionElement)->groupLabelText();

return String();
}
@@ -207,8 +207,8 @@ HTMLSelectElement* AccessibilityListBoxOption::listBoxOptionParentNode() const
if (isHTMLOptionElement(m_optionElement))
return toHTMLOptionElement(m_optionElement)->ownerSelectElement();

if (m_optionElement->hasTagName(optgroupTag))
return static_cast<HTMLOptGroupElement*>(m_optionElement)->ownerSelectElement();
if (isHTMLOptGroupElement(m_optionElement))
return toHTMLOptGroupElement(m_optionElement)->ownerSelectElement();

return 0;
}
@@ -39,6 +39,7 @@
#include "HTMLFrameElementBase.h"
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "HTMLOptGroupElement.h"
#include "HTMLOptionElement.h"
#include "HTMLProgressElement.h"
#include "HTMLStyleElement.h"
@@ -656,7 +657,7 @@ bool SelectorChecker::checkOne(const SelectorCheckingContext& context) const
}
break;
case CSSSelector::PseudoEnabled:
if (element->isFormControlElement() || isHTMLOptionElement(element) || element->hasTagName(optgroupTag))
if (element->isFormControlElement() || isHTMLOptionElement(element) || isHTMLOptGroupElement(element))
return !element->isDisabledFormControl();
break;
case CSSSelector::PseudoFullPageMedia:
@@ -665,7 +666,7 @@ bool SelectorChecker::checkOne(const SelectorCheckingContext& context) const
case CSSSelector::PseudoDefault:
return element->isDefaultButtonForForm();
case CSSSelector::PseudoDisabled:
if (element->isFormControlElement() || isHTMLOptionElement(element) || element->hasTagName(optgroupTag))
if (element->isFormControlElement() || isHTMLOptionElement(element) || isHTMLOptGroupElement(element))
return element->isDisabledFormControl();
break;
case CSSSelector::PseudoReadOnly:
@@ -68,6 +68,7 @@
#include "HTMLIFrameElement.h"
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "HTMLOptGroupElement.h"
#include "HTMLOptionElement.h"
#include "HTMLProgressElement.h"
#include "HTMLStyleElement.h"
@@ -659,7 +660,7 @@ bool StyleResolver::canShareStyleWithElement(StyledElement* element) const
// FIXME: We should share style for option and optgroup whenever possible.
// Before doing so, we need to resolve issues in HTMLSelectElement::recalcListItems
// and RenderMenuList::setText. See also https://bugs.webkit.org/show_bug.cgi?id=88405
if (isHTMLOptionElement(element) || element->hasTagName(optgroupTag))
if (isHTMLOptionElement(element) || isHTMLOptGroupElement(element))
return false;

bool isControl = element->isFormControlElement();
@@ -63,6 +63,17 @@ class HTMLOptGroupElement FINAL : public HTMLElement {
RefPtr<RenderStyle> m_style;
};

inline bool isHTMLOptGroupElement(Node* node)
{
return node->hasTagName(HTMLNames::optgroupTag);
}

inline HTMLOptGroupElement* toHTMLOptGroupElement(Node* node)
{
ASSERT_WITH_SECURITY_IMPLICATION(!node || isHTMLOptGroupElement(node));
return static_cast<HTMLOptGroupElement*>(node);
}

} //namespace

#endif
@@ -32,6 +32,7 @@
#include "ExceptionCode.h"
#include "HTMLDataListElement.h"
#include "HTMLNames.h"
#include "HTMLOptGroupElement.h"
#include "HTMLParserIdioms.h"
#include "HTMLSelectElement.h"
#include "NodeRenderStyle.h"
@@ -335,7 +336,7 @@ void HTMLOptionElement::didRecalcStyle(StyleChange)
String HTMLOptionElement::textIndentedToRespectGroupLabel() const
{
ContainerNode* parent = parentNode();
if (parent && parent->hasTagName(optgroupTag))
if (parent && isHTMLOptGroupElement(parent))
return " " + text();
return text();
}
@@ -349,7 +350,7 @@ bool HTMLOptionElement::isDisabledFormControl() const
return false;

HTMLElement* parentElement = static_cast<HTMLElement*>(parentNode());
return parentElement->hasTagName(optgroupTag) && parentElement->isDisabledFormControl();
return isHTMLOptGroupElement(parentElement) && parentElement->isDisabledFormControl();
}

Node::InsertionNotificationRequest HTMLOptionElement::insertedInto(ContainerNode* insertionPoint)
@@ -350,7 +350,7 @@ bool HTMLSelectElement::childShouldCreateRenderer(const NodeRenderingContext& ch
if (!HTMLFormControlElementWithState::childShouldCreateRenderer(childContext))
return false;
if (!usesMenuList())
return isHTMLOptionElement(childContext.node()) || childContext.node()->hasTagName(HTMLNames::optgroupTag) || validationMessageShadowTreeContains(childContext.node());
return isHTMLOptionElement(childContext.node()) || isHTMLOptGroupElement(childContext.node()) || validationMessageShadowTreeContains(childContext.node());
return validationMessageShadowTreeContains(childContext.node());
}

@@ -751,7 +751,7 @@ void HTMLSelectElement::recalcListItems(bool updateSelectedStates) const
// optgroup tags may not nest. However, both FireFox and IE will
// flatten the tree automatically, so we follow suit.
// (http://www.w3.org/TR/html401/interact/forms.html#h-17.6)
if (current->hasTagName(optgroupTag)) {
if (isHTMLOptGroupElement(current)) {
m_listItems.append(current);
if (Element* nextElement = ElementTraversal::firstWithin(current)) {
currentElement = nextElement;
@@ -39,6 +39,7 @@
#include "HTMLFormElement.h"
#include "HTMLHtmlElement.h"
#include "HTMLNames.h"
#include "HTMLOptGroupElement.h"
#include "HTMLOptionElement.h"
#include "HTMLParserIdioms.h"
#include "HTMLScriptElement.h"
@@ -65,7 +66,7 @@ static bool hasImpliedEndTag(const HTMLStackItem* item)
|| item->hasTagName(dtTag)
|| item->hasTagName(liTag)
|| isHTMLOptionElement(item->node())
|| item->hasTagName(optgroupTag)
|| isHTMLOptGroupElement(item->node())
|| item->hasTagName(pTag)
|| item->hasTagName(rpTag)
|| item->hasTagName(rtTag);
@@ -30,6 +30,7 @@
#include "DocumentFragment.h"
#include "Element.h"
#include "HTMLNames.h"
#include "HTMLOptGroupElement.h"
#include "HTMLOptionElement.h"
#include "MathMLNames.h"
#include "SVGNames.h"
@@ -123,7 +124,7 @@ inline bool isButtonScopeMarker(HTMLStackItem* item)

inline bool isSelectScopeMarker(HTMLStackItem* item)
{
return !item->hasTagName(optgroupTag) && !isHTMLOptionElement(item->node());
return !isHTMLOptGroupElement(item->node()) && !isHTMLOptionElement(item->node());
}

}
@@ -33,6 +33,7 @@
#include "HTMLDocumentParser.h"
#include "HTMLFormElement.h"
#include "HTMLNames.h"
#include "HTMLOptGroupElement.h"
#include "HTMLOptionElement.h"
#include "HTMLParserIdioms.h"
#include "HTMLStackItem.h"
@@ -1387,7 +1388,7 @@ void HTMLTreeBuilder::processStartTag(AtomicHTMLToken* token)
AtomicHTMLToken endOption(HTMLToken::EndTag, optionTag.localName());
processEndTag(&endOption);
}
if (m_tree.currentStackItem()->hasTagName(optgroupTag)) {
if (isHTMLOptGroupElement(m_tree.currentStackItem()->node())) {
AtomicHTMLToken endOptgroup(HTMLToken::EndTag, optgroupTag.localName());
processEndTag(&endOptgroup);
}
@@ -2251,9 +2252,9 @@ void HTMLTreeBuilder::processEndTag(AtomicHTMLToken* token)
case InSelectMode:
ASSERT(insertionMode() == InSelectMode || insertionMode() == InSelectInTableMode);
if (token->name() == optgroupTag) {
if (isHTMLOptionElement(m_tree.currentStackItem()->node()) && m_tree.oneBelowTop() && m_tree.oneBelowTop()->hasTagName(optgroupTag))
if (isHTMLOptionElement(m_tree.currentStackItem()->node()) && m_tree.oneBelowTop() && isHTMLOptGroupElement(m_tree.oneBelowTop()->node()))
processFakeEndTag(optionTag);
if (m_tree.currentStackItem()->hasTagName(optgroupTag)) {
if (isHTMLOptGroupElement(m_tree.currentStackItem()->node())) {
m_tree.openElements()->pop();
return;
}
@@ -126,8 +126,8 @@ void RenderListBox::updateFromElement()
Font itemFont = style()->font();
if (isHTMLOptionElement(element))
text = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel();
else if (element->hasTagName(optgroupTag)) {
text = static_cast<const HTMLOptGroupElement*>(element)->groupLabelText();
else if (isHTMLOptGroupElement(element)) {
text = toHTMLOptGroupElement(element)->groupLabelText();
FontDescription d = itemFont.fontDescription();
d.setWeight(d.bolderWeight());
itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing());
@@ -406,8 +406,8 @@ void RenderListBox::paintItemForeground(PaintInfo& paintInfo, const LayoutPoint&
bool isOptionElement = isHTMLOptionElement(element);
if (isOptionElement)
itemText = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel();
else if (element->hasTagName(optgroupTag))
itemText = static_cast<const HTMLOptGroupElement*>(element)->groupLabelText();
else if (isHTMLOptGroupElement(element))
itemText = toHTMLOptGroupElement(element)->groupLabelText();
applyTextTransform(style(), itemText, ' ');

Color textColor = element->renderStyle() ? element->renderStyle()->visitedDependentColor(CSSPropertyColor) : style()->visitedDependentColor(CSSPropertyColor);
@@ -427,7 +427,7 @@ void RenderListBox::paintItemForeground(PaintInfo& paintInfo, const LayoutPoint&
LayoutRect r = itemBoundingBoxRect(paintOffset, listIndex);
r.move(itemOffsetForAlignment(textRun, itemStyle, itemFont, r));

if (element->hasTagName(optgroupTag)) {
if (isHTMLOptGroupElement(element)) {
FontDescription d = itemFont.fontDescription();
d.setWeight(d.bolderWeight());
itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing());
@@ -405,8 +405,8 @@ String RenderMenuList::itemText(unsigned listIndex) const

String itemString;
Element* element = listItems[listIndex];
if (element->hasTagName(optgroupTag))
itemString = static_cast<const HTMLOptGroupElement*>(element)->groupLabelText();
if (isHTMLOptGroupElement(element))
itemString = toHTMLOptGroupElement(element)->groupLabelText();
else if (isHTMLOptionElement(element))
itemString = toHTMLOptionElement(element)->textIndentedToRespectGroupLabel();

@@ -452,7 +452,7 @@ bool RenderMenuList::itemIsEnabled(unsigned listIndex) const

bool groupEnabled = true;
if (Element* parentElement = element->parentElement()) {
if (parentElement->hasTagName(optgroupTag))
if (isHTMLOptGroupElement(parentElement))
groupEnabled = !parentElement->isDisabledFormControl();
}
if (!groupEnabled)
@@ -596,7 +596,7 @@ bool RenderMenuList::itemIsSeparator(unsigned listIndex) const
bool RenderMenuList::itemIsLabel(unsigned listIndex) const
{
const Vector<HTMLElement*>& listItems = selectElement()->listItems();
return listIndex < listItems.size() && listItems[listIndex]->hasTagName(optgroupTag);
return listIndex < listItems.size() && isHTMLOptGroupElement(listItems[listIndex]);
}

bool RenderMenuList::itemIsSelected(unsigned listIndex) const
@@ -1,3 +1,16 @@
2013-06-29 Kangil Han <kangil.han@samsung.com>

Adopt is/toHTMLOptGroupElement for code cleanup
https://bugs.webkit.org/show_bug.cgi?id=118213

Reviewed by Andreas Kling.

To enhance readability, this patch adopts is/toHTMLOptGroupElement.
This also helps out to reduce duplicated use of static_cast.

* WebKitSupport/InputHandler.cpp:
(BlackBerry::WebKit::InputHandler::openSelectPopup):

2013-06-29 Kangil Han <kangil.han@samsung.com>

Adopt is/toHTMLOptionElement for code cleanup
@@ -2061,9 +2061,9 @@ bool InputHandler::openSelectPopup(HTMLSelectElement* select)
labels[i] = option->textIndentedToRespectGroupLabel();
enableds[i] = option->isDisabledFormControl() ? 0 : 1;
selecteds[i] = option->selected();
itemTypes[i] = option->parentNode() && option->parentNode()->hasTagName(HTMLNames::optgroupTag) ? TypeOptionInGroup : TypeOption;
} else if (listItems[i]->hasTagName(HTMLNames::optgroupTag)) {
HTMLOptGroupElement* optGroup = static_cast<HTMLOptGroupElement*>(listItems[i]);
itemTypes[i] = option->parentNode() && isHTMLOptGroupElement(option->parentNode()) ? TypeOptionInGroup : TypeOption;
} else if (isHTMLOptGroupElement(listItems[i])) {
HTMLOptGroupElement* optGroup = toHTMLOptGroupElement(listItems[i]);
labels[i] = optGroup->groupLabelText();
enableds[i] = optGroup->isDisabledFormControl() ? 0 : 1;
selecteds[i] = false;

0 comments on commit e5068a6

Please sign in to comment.