Commit 72f1f511 authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

Add DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION() macro

Add DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION() macro that generates better
type helpers for HTML Elements:
- Generates more isHTML*Element() helpers that are consistent with the ones
  in HTMLElementTypeHelpers.h so that there is no different in behavior /
  supported arguments.
- Supports more efficient isHTML*Element() helpers that take an HTMLElement
  in argument and thus don't need to check the namespace URI, only the local
  name.

R=esprehn, adamk
BUG=346095

Review URL: https://codereview.chromium.org/202813005

git-svn-id: svn://svn.chromium.org/blink/trunk@169466 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent ac6db3d0
...@@ -954,11 +954,11 @@ void Editor::redo() ...@@ -954,11 +954,11 @@ void Editor::redo()
void Editor::setBaseWritingDirection(WritingDirection direction) void Editor::setBaseWritingDirection(WritingDirection direction)
{ {
Node* focusedElement = frame().document()->focusedElement(); Element* focusedElement = frame().document()->focusedElement();
if (focusedElement && isHTMLTextFormControlElement(*focusedElement)) { if (isHTMLTextFormControlElement(focusedElement)) {
if (direction == NaturalWritingDirection) if (direction == NaturalWritingDirection)
return; return;
toHTMLElement(focusedElement)->setAttribute(dirAttr, direction == LeftToRightWritingDirection ? "ltr" : "rtl"); focusedElement->setAttribute(dirAttr, direction == LeftToRightWritingDirection ? "ltr" : "rtl");
focusedElement->dispatchInputEvent(); focusedElement->dispatchInputEvent();
frame().document()->updateStyleIfNeeded(); frame().document()->updateStyleIfNeeded();
return; return;
......
...@@ -137,6 +137,20 @@ inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document& document ...@@ -137,6 +137,20 @@ inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document& document
ScriptWrappable::init(this); ScriptWrappable::init(this);
} }
// This requires isHTML*Element(const Element&) and isHTML*Element(const HTMLElement&).
// When the input element is an HTMLElement, we don't need to check the namespace URI, just the local name.
#define DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) \
inline bool is##thisType(const thisType* element); \
inline bool is##thisType(const thisType& element); \
inline bool is##thisType(const HTMLElement* element) { return element && is##thisType(*element); } \
inline bool is##thisType(const Element* element) { return element && is##thisType(*element); } \
inline bool is##thisType(const Node& node) { return node.isElementNode() ? is##thisType(toElement(node)) : false; } \
inline bool is##thisType(const Node* node) { return node && node->isElementNode() ? is##thisType(*toElement(node)) : false; } \
template<typename T> inline bool is##thisType(const PassRefPtr<T>& node) { return is##thisType(node.get()); } \
template<typename T> inline bool is##thisType(const RefPtr<T>& node) { return is##thisType(node.get()); } \
template <> inline bool isElementOfType<const thisType>(const HTMLElement& element) { return is##thisType(element); } \
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType)
} // namespace WebCore } // namespace WebCore
#include "HTMLElementTypeHelpers.h" #include "HTMLElementTypeHelpers.h"
......
...@@ -181,12 +181,12 @@ private: ...@@ -181,12 +181,12 @@ private:
bool m_wasFocusedByMouse : 1; bool m_wasFocusedByMouse : 1;
}; };
inline bool isHTMLFormControlElement(const Node& node) inline bool isHTMLFormControlElement(const Element& element)
{ {
return node.isElementNode() && toElement(node).isFormControlElement(); return element.isFormControlElement();
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLFormControlElement); DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLFormControlElement);
DEFINE_TYPE_CASTS(HTMLFormControlElement, FormAssociatedElement, control, control->isFormControlElement(), control.isFormControlElement()); DEFINE_TYPE_CASTS(HTMLFormControlElement, FormAssociatedElement, control, control->isFormControlElement(), control.isFormControlElement());
} // namespace } // namespace
......
...@@ -76,17 +76,17 @@ private: ...@@ -76,17 +76,17 @@ private:
int m_marginHeight; int m_marginHeight;
}; };
inline bool isHTMLFrameElementBase(const Node& node) inline bool isHTMLFrameElementBase(const Element& element)
{ {
return isHTMLFrameElement(node) || isHTMLIFrameElement(node); return isHTMLFrameElement(element) || isHTMLIFrameElement(element);
} }
inline bool isHTMLFrameElementBase(const Node* node) inline bool isHTMLFrameElementBase(const HTMLElement& element)
{ {
return node && isHTMLFrameElementBase(*node); return isHTMLFrameElement(element) || isHTMLIFrameElement(element);
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLFrameElementBase); DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLFrameElementBase);
} // namespace WebCore } // namespace WebCore
......
...@@ -543,17 +543,17 @@ struct ValueToString<TextTrackCue*> { ...@@ -543,17 +543,17 @@ struct ValueToString<TextTrackCue*> {
}; };
#endif #endif
inline bool isHTMLMediaElement(const Node& node) inline bool isHTMLMediaElement(const Element& element)
{ {
return isHTMLAudioElement(node) || isHTMLVideoElement(node); return isHTMLAudioElement(element) || isHTMLVideoElement(element);
} }
inline bool isHTMLMediaElement(const Node* node) inline bool isHTMLMediaElement(const HTMLElement& element)
{ {
return node && isHTMLMediaElement(*node); return isHTMLAudioElement(element) || isHTMLVideoElement(element);
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLMediaElement); DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLMediaElement);
} //namespace } //namespace
......
...@@ -62,12 +62,17 @@ private: ...@@ -62,12 +62,17 @@ private:
virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE; virtual bool hasLegalLinkAttribute(const QualifiedName&) const OVERRIDE;
}; };
inline bool isHTMLTableCellElement(const Node& node) inline bool isHTMLTableCellElement(const Element& element)
{ {
return node.hasTagName(HTMLNames::tdTag) || node.hasTagName(HTMLNames::thTag); return element.hasTagName(HTMLNames::tdTag) || element.hasTagName(HTMLNames::thTag);
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLTableCellElement); inline bool isHTMLTableCellElement(const HTMLElement& element)
{
return element.hasLocalName(HTMLNames::tdTag) || element.hasLocalName(HTMLNames::thTag);
}
DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLTableCellElement);
} // namespace } // namespace
......
...@@ -50,12 +50,17 @@ private: ...@@ -50,12 +50,17 @@ private:
int m_span; int m_span;
}; };
inline bool isHTMLTableColElement(const Node& node) inline bool isHTMLTableColElement(const Element& element)
{ {
return node.hasTagName(HTMLNames::colTag) || node.hasTagName(HTMLNames::colgroupTag); return element.hasTagName(HTMLNames::colTag) || element.hasTagName(HTMLNames::colgroupTag);
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLTableColElement); inline bool isHTMLTableColElement(const HTMLElement& element)
{
return element.hasLocalName(HTMLNames::colTag) || element.hasLocalName(HTMLNames::colgroupTag);
}
DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLTableColElement);
} // namespace WebCore } // namespace WebCore
......
...@@ -49,12 +49,17 @@ private: ...@@ -49,12 +49,17 @@ private:
virtual const StylePropertySet* additionalPresentationAttributeStyle() OVERRIDE; virtual const StylePropertySet* additionalPresentationAttributeStyle() OVERRIDE;
}; };
inline bool isHTMLTableSectionElement(const Node& node) inline bool isHTMLTableSectionElement(const Element& element)
{ {
return node.hasTagName(HTMLNames::tbodyTag) || node.hasTagName(HTMLNames::tfootTag) || node.hasTagName(HTMLNames::theadTag); return element.hasTagName(HTMLNames::tbodyTag) || element.hasTagName(HTMLNames::tfootTag) || element.hasTagName(HTMLNames::theadTag);
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLTableSectionElement); inline bool isHTMLTableSectionElement(const HTMLElement& element)
{
return element.hasLocalName(HTMLNames::tbodyTag) || element.hasLocalName(HTMLNames::tfootTag) || element.hasLocalName(HTMLNames::theadTag);
}
DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLTableSectionElement);
} //namespace } //namespace
......
...@@ -135,12 +135,12 @@ private: ...@@ -135,12 +135,12 @@ private:
TextFieldSelectionDirection m_cachedSelectionDirection; TextFieldSelectionDirection m_cachedSelectionDirection;
}; };
inline bool isHTMLTextFormControlElement(const Node& node) inline bool isHTMLTextFormControlElement(const Element& element)
{ {
return node.isElementNode() && toElement(node).isTextFormControl(); return element.isTextFormControl();
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLTextFormControlElement); DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLTextFormControlElement);
HTMLTextFormControlElement* enclosingTextFormControl(const Position&); HTMLTextFormControlElement* enclosingTextFormControl(const Position&);
......
...@@ -51,12 +51,17 @@ private: ...@@ -51,12 +51,17 @@ private:
} }
}; };
inline bool isHTMLUnknownElement(const Node& node) inline bool isHTMLUnknownElement(const Element& element)
{ {
return node.isElementNode() && toHTMLElement(node).isHTMLUnknownElement(); return element.isHTMLElement() && toHTMLElement(element).isHTMLUnknownElement();
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLUnknownElement); inline bool isHTMLUnknownElement(const HTMLElement& element)
{
return element.isHTMLUnknownElement();
}
DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(HTMLUnknownElement);
} // namespace } // namespace
......
...@@ -50,12 +50,17 @@ private: ...@@ -50,12 +50,17 @@ private:
virtual bool isLabelable() const OVERRIDE FINAL { return true; } virtual bool isLabelable() const OVERRIDE FINAL { return true; }
}; };
inline bool isLabelableElement(const Node& node) inline bool isLabelableElement(const Element& element)
{ {
return node.isHTMLElement() && toHTMLElement(node).isLabelable(); return element.isHTMLElement() && toHTMLElement(element).isLabelable();
} }
DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(LabelableElement); inline bool isLabelableElement(const HTMLElement& element)
{
return element.isLabelable();
}
DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(LabelableElement);
} // namespace WebCore } // namespace WebCore
......
...@@ -60,7 +60,7 @@ void RenderTableCol::updateFromElement() ...@@ -60,7 +60,7 @@ void RenderTableCol::updateFromElement()
{ {
unsigned oldSpan = m_span; unsigned oldSpan = m_span;
Node* n = node(); Node* n = node();
if (n && isHTMLTableColElement(*n)) { if (isHTMLTableColElement(n)) {
HTMLTableColElement& tc = toHTMLTableColElement(*n); HTMLTableColElement& tc = toHTMLTableColElement(*n);
m_span = tc.span(); m_span = tc.span();
} else } else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment