Introduce isHTMLTextFormControlElement and toHTMLTextFormControlElement instead of...
authorshinyak@chromium.org <shinyak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 19 Jan 2013 00:12:54 +0000 (00:12 +0000)
committershinyak@chromium.org <shinyak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 19 Jan 2013 00:12:54 +0000 (00:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=107089

Reviewed by Kent Tamura.

Source/WebCore:

toTextFormControl(node) returns 0 if node is not HTMLTextFormControl. In recent coding convention,
we only have ASSERT and statc_cast in this kind of conversion function. So this code looks like
having a bad cast, though it does not.

In this patch, we convert toTextFromControl to isHTMLTextFormControlElement and toHTMLFormControlElement,
which aligns our coding convention.

No new tests, simple refactoring.

* editing/Editor.cpp:
(WebCore::Editor::selectionForCommand):
(WebCore::Editor::setBaseWritingDirection):
* html/HTMLElement.cpp:
(WebCore::HTMLElement::directionality):
* html/HTMLTextFormControlElement.cpp:
(WebCore::enclosingTextFormControl):
* html/HTMLTextFormControlElement.h:
(WebCore::isHTMLTextFormControlElement):
(WebCore):
(WebCore::toHTMLTextFormControlElement):
* rendering/RenderTextControl.cpp:
(WebCore::RenderTextControl::RenderTextControl):
(WebCore::RenderTextControl::layoutSpecialExcludedChild):
* testing/Internals.cpp:
(WebCore::Internals::visiblePlaceholder):

Source/WebKit/qt:

Updated code to use isHTMLTextFormControlElement and toHTMLTextFormControlElement combination instead of
toTextFormControl.

* WebCoreSupport/QWebPageAdapter.cpp:
(QWebPageAdapter::inputMethodEvent):

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

Source/WebCore/ChangeLog
Source/WebCore/editing/Editor.cpp
Source/WebCore/html/HTMLElement.cpp
Source/WebCore/html/HTMLTextFormControlElement.cpp
Source/WebCore/html/HTMLTextFormControlElement.h
Source/WebCore/rendering/RenderTextControl.cpp
Source/WebCore/testing/Internals.cpp
Source/WebKit/qt/ChangeLog
Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp

index e4431dc..5895a9c 100644 (file)
@@ -1,3 +1,36 @@
+2013-01-18  Shinya Kawanaka  <shinyak@chromium.org>
+
+        Introduce isHTMLTextFormControlElement and toHTMLTextFormControlElement instead of toTextFormControl
+        https://bugs.webkit.org/show_bug.cgi?id=107089
+
+        Reviewed by Kent Tamura.
+
+        toTextFormControl(node) returns 0 if node is not HTMLTextFormControl. In recent coding convention,
+        we only have ASSERT and statc_cast in this kind of conversion function. So this code looks like
+        having a bad cast, though it does not.
+
+        In this patch, we convert toTextFromControl to isHTMLTextFormControlElement and toHTMLFormControlElement,
+        which aligns our coding convention.
+
+        No new tests, simple refactoring.
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::selectionForCommand):
+        (WebCore::Editor::setBaseWritingDirection):
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::directionality):
+        * html/HTMLTextFormControlElement.cpp:
+        (WebCore::enclosingTextFormControl):
+        * html/HTMLTextFormControlElement.h:
+        (WebCore::isHTMLTextFormControlElement):
+        (WebCore):
+        (WebCore::toHTMLTextFormControlElement):
+        * rendering/RenderTextControl.cpp:
+        (WebCore::RenderTextControl::RenderTextControl):
+        (WebCore::RenderTextControl::layoutSpecialExcludedChild):
+        * testing/Internals.cpp:
+        (WebCore::Internals::visiblePlaceholder):
+
 2013-01-18  Emil A Eklund  <eae@chromium.org>
 
         Change RenderStyle::getRoundedInnerBorderFor to take ints for border widths
index 5a22bb0..3221467 100644 (file)
@@ -110,7 +110,7 @@ VisibleSelection Editor::selectionForCommand(Event* event)
     // If the target is a text control, and the current selection is outside of its shadow tree,
     // then use the saved selection for that text control.
     HTMLTextFormControlElement* textFormControlOfSelectionStart = enclosingTextFormControl(selection.start());
-    HTMLTextFormControlElement* textFromControlOfTarget = toTextFormControl(event->target()->toNode());
+    HTMLTextFormControlElement* textFromControlOfTarget = isHTMLTextFormControlElement(event->target()->toNode()) ? toHTMLTextFormControlElement(event->target()->toNode()) : 0;
     if (textFromControlOfTarget && (selection.start().isNull() || textFromControlOfTarget != textFormControlOfSelectionStart)) {
         if (RefPtr<Range> range = textFromControlOfTarget->selection())
             return VisibleSelection(range.get(), DOWNSTREAM, selection.isDirectional());
@@ -1294,7 +1294,7 @@ void Editor::toggleUnderline()
 void Editor::setBaseWritingDirection(WritingDirection direction)
 {
     Node* focusedNode = frame()->document()->focusedNode();
-    if (toTextFormControl(focusedNode)) {
+    if (focusedNode && isHTMLTextFormControlElement(focusedNode)) {
         if (direction == NaturalWritingDirection)
             return;
         toHTMLElement(focusedNode)->setAttribute(dirAttr, direction == LeftToRightWritingDirection ? "ltr" : "rtl");
index 172fae5..6b4ad30 100644 (file)
@@ -854,7 +854,8 @@ TextDirection HTMLElement::directionalityIfhasDirAutoAttribute(bool& isAuto) con
 
 TextDirection HTMLElement::directionality(Node** strongDirectionalityTextNode) const
 {
-    if (HTMLTextFormControlElement* textElement = toTextFormControl(const_cast<HTMLElement*>(this))) {
+    if (isHTMLTextFormControlElement(this)) {
+        HTMLTextFormControlElement* textElement = toHTMLTextFormControlElement(const_cast<HTMLElement*>(this));
         bool hasStrongDirectionality;
         Unicode::Direction textDirection = textElement->value().defaultWritingDirection(&hasStrongDirectionality);
         if (strongDirectionalityTextNode)
index ac3c954..8cc029a 100644 (file)
@@ -645,8 +645,8 @@ HTMLTextFormControlElement* enclosingTextFormControl(const Position& position)
     Node* container = position.containerNode();
     if (!container)
         return 0;
-    Node* ancestor = container->shadowHost();
-    return ancestor ? toTextFormControl(ancestor) : 0;
+    Element* ancestor = container->shadowHost();
+    return ancestor && isHTMLTextFormControlElement(ancestor) ? toHTMLTextFormControlElement(ancestor) : 0;
 }
 
 static const Element* parentHTMLElement(const Element* element)
index ed95228..b9b43d5 100644 (file)
@@ -141,10 +141,15 @@ private:
     TextFieldSelectionDirection m_cachedSelectionDirection;
 };
 
-// This function returns 0 when node is an input element and not a text field.
-inline HTMLTextFormControlElement* toTextFormControl(Node* node)
+inline bool isHTMLTextFormControlElement(const Node* node)
 {
-    return (node && node->isElementNode() && static_cast<Element*>(node)->isTextFormControl()) ? static_cast<HTMLTextFormControlElement*>(node) : 0;
+    return node->isElementNode() && toElement(node)->isTextFormControl();
+}
+
+inline HTMLTextFormControlElement* toHTMLTextFormControlElement(Node* node)
+{
+    ASSERT(!node || isHTMLTextFormControlElement(node));
+    return static_cast<HTMLTextFormControlElement*>(node);
 }
 
 HTMLTextFormControlElement* enclosingTextFormControl(const Position&);
index f0c64e7..e649d15 100644 (file)
@@ -39,7 +39,7 @@ namespace WebCore {
 RenderTextControl::RenderTextControl(ContainerNode* node)
     : RenderBlock(node)
 {
-    ASSERT(toTextFormControl(node));
+    ASSERT(isHTMLTextFormControlElement(node));
 }
 
 RenderTextControl::~RenderTextControl()
@@ -303,7 +303,7 @@ void RenderTextControl::addFocusRingRects(Vector<IntRect>& rects, const LayoutPo
 
 RenderObject* RenderTextControl::layoutSpecialExcludedChild(bool relayoutChildren)
 {
-    HTMLElement* placeholder = toTextFormControl(node())->placeholderElement();
+    HTMLElement* placeholder = toHTMLTextFormControlElement(node())->placeholderElement();
     RenderObject* placeholderRenderer = placeholder ? placeholder->renderer() : 0;
     if (!placeholderRenderer)
         return 0;
index 7c51c12..bee8204 100644 (file)
@@ -685,9 +685,11 @@ void Internals::setShadowPseudoId(Element* element, const String& id, ExceptionC
 
 String Internals::visiblePlaceholder(Element* element)
 {
-    HTMLTextFormControlElement* textControl = toTextFormControl(element);
-    if (textControl && textControl->placeholderShouldBeVisible())
-        return textControl->placeholderElement()->textContent();
+    if (element && isHTMLTextFormControlElement(element)) {
+        if (toHTMLTextFormControlElement(element)->placeholderShouldBeVisible())
+            return toHTMLTextFormControlElement(element)->placeholderElement()->textContent();
+    }
+
     return String();
 }
 
index afc15d7..e09e5f3 100644 (file)
@@ -1,3 +1,16 @@
+2013-01-18  Shinya Kawanaka  <shinyak@chromium.org>
+
+        Introduce isHTMLTextFormControlElement and toHTMLTextFormControlElement instead of toTextFormControl
+        https://bugs.webkit.org/show_bug.cgi?id=107089
+
+        Reviewed by Kent Tamura.
+
+        Updated code to use isHTMLTextFormControlElement and toHTMLTextFormControlElement combination instead of
+        toTextFormControl.
+
+        * WebCoreSupport/QWebPageAdapter.cpp:
+        (QWebPageAdapter::inputMethodEvent):
+
 2013-01-18  Seokju Kwon  <seokju.kwon@gmail.com>
 
         Add explicit keyword to constructors in platform-specific InspectorClient
index c20a246..63f442a 100644 (file)
@@ -676,8 +676,8 @@ void QWebPageAdapter::inputMethodEvent(QInputMethodEvent *ev)
             hasSelection = true;
             // A selection in the inputMethodEvent is always reflected in the visible text
             if (node) {
-                if (HTMLTextFormControlElement* textControl = toTextFormControl(node))
-                    textControl->setSelectionRange(qMin(a.start, (a.start + a.length)), qMax(a.start, (a.start + a.length)));
+                if (isHTMLTextFormControlElement(node))
+                    toHTMLTextFormControlElement(node)->setSelectionRange(qMin(a.start, (a.start + a.length)), qMax(a.start, (a.start + a.length)));
             }
 
             if (!ev->preeditString().isEmpty())
@@ -698,8 +698,8 @@ void QWebPageAdapter::inputMethodEvent(QInputMethodEvent *ev)
     if (node && ev->replacementLength() > 0) {
         int cursorPos = frame->selection()->extent().offsetInContainerNode();
         int start = cursorPos + ev->replacementStart();
-        if (HTMLTextFormControlElement* textControl = toTextFormControl(node))
-            textControl->setSelectionRange(start, start + ev->replacementLength());
+        if (isHTMLTextFormControlElement(node))
+            toHTMLTextFormControlElement(node)->setSelectionRange(start, start + ev->replacementLength());
         // Commit regardless of whether commitString is empty, to get rid of selection.
         editor->confirmComposition(ev->commitString());
     } else if (!ev->commitString().isEmpty()) {