Changeset 140215 in webkit


Ignore:
Timestamp:
Jan 18, 2013 4:12:54 PM (11 years ago)
Author:
shinyak@chromium.org
Message:

Introduce isHTMLTextFormControlElement and toHTMLTextFormControlElement instead of toTextFormControl
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):

Location:
trunk/Source
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r140213 r140215  
     12013-01-18  Shinya Kawanaka  <shinyak@chromium.org>
     2
     3        Introduce isHTMLTextFormControlElement and toHTMLTextFormControlElement instead of toTextFormControl
     4        https://bugs.webkit.org/show_bug.cgi?id=107089
     5
     6        Reviewed by Kent Tamura.
     7
     8        toTextFormControl(node) returns 0 if node is not HTMLTextFormControl. In recent coding convention,
     9        we only have ASSERT and statc_cast in this kind of conversion function. So this code looks like
     10        having a bad cast, though it does not.
     11
     12        In this patch, we convert toTextFromControl to isHTMLTextFormControlElement and toHTMLFormControlElement,
     13        which aligns our coding convention.
     14
     15        No new tests, simple refactoring.
     16
     17        * editing/Editor.cpp:
     18        (WebCore::Editor::selectionForCommand):
     19        (WebCore::Editor::setBaseWritingDirection):
     20        * html/HTMLElement.cpp:
     21        (WebCore::HTMLElement::directionality):
     22        * html/HTMLTextFormControlElement.cpp:
     23        (WebCore::enclosingTextFormControl):
     24        * html/HTMLTextFormControlElement.h:
     25        (WebCore::isHTMLTextFormControlElement):
     26        (WebCore):
     27        (WebCore::toHTMLTextFormControlElement):
     28        * rendering/RenderTextControl.cpp:
     29        (WebCore::RenderTextControl::RenderTextControl):
     30        (WebCore::RenderTextControl::layoutSpecialExcludedChild):
     31        * testing/Internals.cpp:
     32        (WebCore::Internals::visiblePlaceholder):
     33
    1342013-01-18  Emil A Eklund  <eae@chromium.org>
    235
  • trunk/Source/WebCore/editing/Editor.cpp

    r139796 r140215  
    111111    // then use the saved selection for that text control.
    112112    HTMLTextFormControlElement* textFormControlOfSelectionStart = enclosingTextFormControl(selection.start());
    113     HTMLTextFormControlElement* textFromControlOfTarget = toTextFormControl(event->target()->toNode());
     113    HTMLTextFormControlElement* textFromControlOfTarget = isHTMLTextFormControlElement(event->target()->toNode()) ? toHTMLTextFormControlElement(event->target()->toNode()) : 0;
    114114    if (textFromControlOfTarget && (selection.start().isNull() || textFromControlOfTarget != textFormControlOfSelectionStart)) {
    115115        if (RefPtr<Range> range = textFromControlOfTarget->selection())
     
    12951295{
    12961296    Node* focusedNode = frame()->document()->focusedNode();
    1297     if (toTextFormControl(focusedNode)) {
     1297    if (focusedNode && isHTMLTextFormControlElement(focusedNode)) {
    12981298        if (direction == NaturalWritingDirection)
    12991299            return;
  • trunk/Source/WebCore/html/HTMLElement.cpp

    r140010 r140215  
    855855TextDirection HTMLElement::directionality(Node** strongDirectionalityTextNode) const
    856856{
    857     if (HTMLTextFormControlElement* textElement = toTextFormControl(const_cast<HTMLElement*>(this))) {
     857    if (isHTMLTextFormControlElement(this)) {
     858        HTMLTextFormControlElement* textElement = toHTMLTextFormControlElement(const_cast<HTMLElement*>(this));
    858859        bool hasStrongDirectionality;
    859860        Unicode::Direction textDirection = textElement->value().defaultWritingDirection(&hasStrongDirectionality);
  • trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp

    r139999 r140215  
    646646    if (!container)
    647647        return 0;
    648     Node* ancestor = container->shadowHost();
    649     return ancestor ? toTextFormControl(ancestor) : 0;
     648    Element* ancestor = container->shadowHost();
     649    return ancestor && isHTMLTextFormControlElement(ancestor) ? toHTMLTextFormControlElement(ancestor) : 0;
    650650}
    651651
  • trunk/Source/WebCore/html/HTMLTextFormControlElement.h

    r135069 r140215  
    142142};
    143143
    144 // This function returns 0 when node is an input element and not a text field.
    145 inline HTMLTextFormControlElement* toTextFormControl(Node* node)
     144inline bool isHTMLTextFormControlElement(const Node* node)
    146145{
    147     return (node && node->isElementNode() && static_cast<Element*>(node)->isTextFormControl()) ? static_cast<HTMLTextFormControlElement*>(node) : 0;
     146    return node->isElementNode() && toElement(node)->isTextFormControl();
     147}
     148
     149inline HTMLTextFormControlElement* toHTMLTextFormControlElement(Node* node)
     150{
     151    ASSERT(!node || isHTMLTextFormControlElement(node));
     152    return static_cast<HTMLTextFormControlElement*>(node);
    148153}
    149154
  • trunk/Source/WebCore/rendering/RenderTextControl.cpp

    r140039 r140215  
    4040    : RenderBlock(node)
    4141{
    42     ASSERT(toTextFormControl(node));
     42    ASSERT(isHTMLTextFormControlElement(node));
    4343}
    4444
     
    304304RenderObject* RenderTextControl::layoutSpecialExcludedChild(bool relayoutChildren)
    305305{
    306     HTMLElement* placeholder = toTextFormControl(node())->placeholderElement();
     306    HTMLElement* placeholder = toHTMLTextFormControlElement(node())->placeholderElement();
    307307    RenderObject* placeholderRenderer = placeholder ? placeholder->renderer() : 0;
    308308    if (!placeholderRenderer)
  • trunk/Source/WebCore/testing/Internals.cpp

    r140105 r140215  
    686686String Internals::visiblePlaceholder(Element* element)
    687687{
    688     HTMLTextFormControlElement* textControl = toTextFormControl(element);
    689     if (textControl && textControl->placeholderShouldBeVisible())
    690         return textControl->placeholderElement()->textContent();
     688    if (element && isHTMLTextFormControlElement(element)) {
     689        if (toHTMLTextFormControlElement(element)->placeholderShouldBeVisible())
     690            return toHTMLTextFormControlElement(element)->placeholderElement()->textContent();
     691    }
     692
    691693    return String();
    692694}
  • trunk/Source/WebKit/qt/ChangeLog

    r140148 r140215  
     12013-01-18  Shinya Kawanaka  <shinyak@chromium.org>
     2
     3        Introduce isHTMLTextFormControlElement and toHTMLTextFormControlElement instead of toTextFormControl
     4        https://bugs.webkit.org/show_bug.cgi?id=107089
     5
     6        Reviewed by Kent Tamura.
     7
     8        Updated code to use isHTMLTextFormControlElement and toHTMLTextFormControlElement combination instead of
     9        toTextFormControl.
     10
     11        * WebCoreSupport/QWebPageAdapter.cpp:
     12        (QWebPageAdapter::inputMethodEvent):
     13
    1142013-01-18  Seokju Kwon  <seokju.kwon@gmail.com>
    215
  • trunk/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp

    r138413 r140215  
    677677            // A selection in the inputMethodEvent is always reflected in the visible text
    678678            if (node) {
    679                 if (HTMLTextFormControlElement* textControl = toTextFormControl(node))
    680                     textControl->setSelectionRange(qMin(a.start, (a.start + a.length)), qMax(a.start, (a.start + a.length)));
     679                if (isHTMLTextFormControlElement(node))
     680                    toHTMLTextFormControlElement(node)->setSelectionRange(qMin(a.start, (a.start + a.length)), qMax(a.start, (a.start + a.length)));
    681681            }
    682682
     
    699699        int cursorPos = frame->selection()->extent().offsetInContainerNode();
    700700        int start = cursorPos + ev->replacementStart();
    701         if (HTMLTextFormControlElement* textControl = toTextFormControl(node))
    702             textControl->setSelectionRange(start, start + ev->replacementLength());
     701        if (isHTMLTextFormControlElement(node))
     702            toHTMLTextFormControlElement(node)->setSelectionRange(start, start + ev->replacementLength());
    703703        // Commit regardless of whether commitString is empty, to get rid of selection.
    704704        editor->confirmComposition(ev->commitString());
Note: See TracChangeset for help on using the changeset viewer.