Changeset 90775 in webkit


Ignore:
Timestamp:
Jul 11, 2011, 12:06:34 PM (14 years ago)
Author:
rniwa@webkit.org
Message:

Move innerTextElement() from RenderTextControl to HTMLTextFormControlElement
https://bugs.webkit.org/show_bug.cgi?id=64134

Reviewed by Kent Tamura.

Moved innerTextElement from RenderTextControl to HTMLTextFormControlElement. It is implemented by
HTMLInputElement and HTMLTextAreaElement instead of RenderTextControlSingleLine and
RenderTextControlMultiLine.

This refactoring removes the indirection through RenderTextControl and makes the ownership of
shadow DOM for input and textarea elements clear. Accessing the shadow DOM of input and textarea elements
are now less error prone because it no longer depends on the lifetime of the render tree.

  • accessibility/AccessibilityRenderObject.cpp:

(WebCore::AccessibilityRenderObject::indexForVisiblePosition): Access innerTextElement via
HTMLTextFormControlElement.

  • dom/Node.cpp:

(WebCore::traverseTreeAndMark): No longer calls innerTextElement because this was a work-around
needed before making input and textarea elements use the new shadow DOM model.

  • editing/TextIterator.cpp:

(WebCore::TextIterator::handleReplacedElement): Access innerTextElement via HTMLTextFormControlElement.

  • html/HTMLFormControlElement.cpp:

(WebCore::hasVisibleTextArea): Takes innerTextElement.
(WebCore::HTMLTextFormControlElement::setSelectionRange): Calls innerTextElement().
(WebCore::HTMLTextFormControlElement::selection): Ditto.
(WebCore::HTMLTextFormControlElement::selectionStart): Ditto; no longer uses a temporary local variable
for innerTextElement because innerTextElement() no longer depends on the lifetime of the render tree.
(WebCore::HTMLTextFormControlElement::selectionEnd): Ditto.

  • html/HTMLFormControlElement.h:
  • html/HTMLTextAreaElement.cpp:

(WebCore::HTMLTextAreaElement::innerTextElement): Added.

  • html/HTMLTextAreaElement.h:
  • rendering/RenderTextControl.cpp:

(WebCore::RenderTextControl::textFormControlElement): Made this function a const member.
(WebCore::RenderTextControl::innerTextElement): Added.

  • rendering/RenderTextControl.h:
  • rendering/RenderTextControlMultiLine.cpp:
  • rendering/RenderTextControlMultiLine.h:
  • rendering/RenderTextControlSingleLine.cpp:
  • rendering/RenderTextControlSingleLine.h:
Location:
trunk/Source/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r90773 r90775  
     12011-07-08  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Move innerTextElement() from RenderTextControl to HTMLTextFormControlElement
     4        https://bugs.webkit.org/show_bug.cgi?id=64134
     5
     6        Reviewed by Kent Tamura.
     7
     8        Moved innerTextElement from RenderTextControl to HTMLTextFormControlElement. It is implemented by
     9        HTMLInputElement and HTMLTextAreaElement instead of RenderTextControlSingleLine and
     10        RenderTextControlMultiLine.
     11
     12        This refactoring removes the indirection through RenderTextControl and makes the ownership of
     13        shadow DOM for input and textarea elements clear. Accessing the shadow DOM of input and textarea elements
     14        are now less error prone because it no longer depends on the lifetime of the render tree.
     15
     16        * accessibility/AccessibilityRenderObject.cpp:
     17        (WebCore::AccessibilityRenderObject::indexForVisiblePosition): Access innerTextElement via
     18        HTMLTextFormControlElement.
     19        * dom/Node.cpp:
     20        (WebCore::traverseTreeAndMark): No longer calls innerTextElement because this was a work-around
     21        needed before making input and textarea elements use the new shadow DOM model.
     22        * editing/TextIterator.cpp:
     23        (WebCore::TextIterator::handleReplacedElement): Access innerTextElement via HTMLTextFormControlElement.
     24        * html/HTMLFormControlElement.cpp:
     25        (WebCore::hasVisibleTextArea): Takes innerTextElement.
     26        (WebCore::HTMLTextFormControlElement::setSelectionRange): Calls innerTextElement().
     27        (WebCore::HTMLTextFormControlElement::selection): Ditto.
     28        (WebCore::HTMLTextFormControlElement::selectionStart): Ditto; no longer uses a temporary local variable
     29        for innerTextElement because innerTextElement() no longer depends on the lifetime of the render tree.
     30        (WebCore::HTMLTextFormControlElement::selectionEnd): Ditto.
     31        * html/HTMLFormControlElement.h:
     32        * html/HTMLTextAreaElement.cpp:
     33        (WebCore::HTMLTextAreaElement::innerTextElement): Added.
     34        * html/HTMLTextAreaElement.h:
     35        * rendering/RenderTextControl.cpp:
     36        (WebCore::RenderTextControl::textFormControlElement): Made this function a const member.
     37        (WebCore::RenderTextControl::innerTextElement): Added.
     38        * rendering/RenderTextControl.h:
     39        * rendering/RenderTextControlMultiLine.cpp:
     40        * rendering/RenderTextControlMultiLine.h:
     41        * rendering/RenderTextControlSingleLine.cpp:
     42        * rendering/RenderTextControlSingleLine.h:
     43
    1442011-07-11  Tony Chang  <tony@chromium.org>
    245
  • trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp

    r90763 r90775  
    24942494int AccessibilityRenderObject::indexForVisiblePosition(const VisiblePosition& pos) const
    24952495{
    2496     if (isNativeTextControl())
    2497         return RenderTextControl::indexForVisiblePosition(toRenderTextControl(m_renderer)->innerTextElement(), pos);
    2498    
     2496    if (isNativeTextControl()) {
     2497        HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
     2498        return RenderTextControl::indexForVisiblePosition(textControl->innerTextElement(), pos);
     2499    }
     2500
    24992501    if (!isTextControl())
    25002502        return 0;
  • trunk/Source/WebCore/dom/Node.cpp

    r90378 r90775  
    23442344        ContainerNode* rootNode = shadowRoot(const_cast<Node*>(node));
    23452345
    2346         if (!rootNode && node->renderer() && node->renderer()->isTextControl())
    2347             rootNode = static_cast<RenderTextControl*>(node->renderer())->innerTextElement();
    2348 
    23492346        if (rootNode) {
    23502347            indent += "\t";
  • trunk/Source/WebCore/editing/TextIterator.cpp

    r89831 r90775  
    3131#include "Frame.h"
    3232#include "HTMLElement.h"
     33#include "HTMLFormControlElement.h"
    3334#include "HTMLNames.h"
    3435#include "htmlediting.h"
     
    638639
    639640    if (m_entersTextControls && renderer->isTextControl()) {
    640         if (HTMLElement* innerTextElement = toRenderTextControl(renderer)->innerTextElement()) {
     641        if (HTMLElement* innerTextElement = toRenderTextControl(renderer)->textFormControlElement()->innerTextElement()) {
    641642            m_node = innerTextElement->shadowTreeRootNode();
    642643            pushFullyClippedState(m_fullyClippedStack, m_node);
  • trunk/Source/WebCore/html/HTMLFormControlElement.cpp

    r90763 r90775  
    682682}
    683683
    684 static inline bool hasVisibleTextArea(RenderTextControl* textControl)
     684static inline bool hasVisibleTextArea(RenderTextControl* textControl, HTMLElement* innerText)
    685685{
    686686    ASSERT(textControl);
    687     HTMLElement* innerText = textControl->innerTextElement();
    688     return textControl->style()->visibility() == HIDDEN || !innerText || !innerText->renderer() || !innerText->renderBox()->height();
     687    return textControl->style()->visibility() != HIDDEN && innerText && innerText->renderer() && innerText->renderBox()->height();
    689688}
    690689
     
    700699
    701700    RenderTextControl* control = toRenderTextControl(renderer());
    702     if (hasVisibleTextArea(control)) {
     701    if (!hasVisibleTextArea(control, innerTextElement())) {
    703702        cacheSelection(start, end);
    704703        return;
     
    736735{
    737736    Frame* frame = document()->frame();
    738     if (!renderer() || !frame)
    739         return 0;
    740 
    741     HTMLElement* innerText = toRenderTextControl(renderer())->innerTextElement();
    742     // Do not call innerTextElement() in the function arguments as creating a VisiblePosition
    743     // from frame->selection->start() can blow us from underneath. Also, function ordering is
    744     // usually dependent on the compiler.
    745     return RenderTextControl::indexForVisiblePosition(innerText, frame->selection()->start());
     737    if (!frame)
     738        return 0;
     739
     740    return RenderTextControl::indexForVisiblePosition(innerTextElement(), frame->selection()->start());
    746741}
    747742
     
    758753{
    759754    Frame* frame = document()->frame();
    760     if (!renderer() || !frame)
    761         return 0;
    762 
    763     HTMLElement* innerText = toRenderTextControl(renderer())->innerTextElement();
    764     // Do not call innerTextElement() in the function arguments as creating a VisiblePosition
    765     // from frame->selection->end() can blow us from underneath. Also, function ordering is
    766     // usually dependent on the compiler.
    767     return RenderTextControl::indexForVisiblePosition(innerText, frame->selection()->end());
     755    if (!frame)
     756        return 0;
     757
     758    return RenderTextControl::indexForVisiblePosition(innerTextElement(), frame->selection()->end());
    768759}
    769760
     
    788779
    789780    ASSERT(start <= end);
    790     HTMLElement* innerText = toRenderTextControl(renderer())->innerTextElement();
     781    HTMLElement* innerText = innerTextElement();
    791782    if (!innerText)
    792783        return 0;
  • trunk/Source/WebCore/html/HTMLFormControlElement.h

    r90763 r90775  
    215215    virtual String value() const = 0;
    216216
     217    virtual HTMLElement* innerTextElement() const = 0;
     218
    217219    void cacheSelection(int start, int end)
    218220    {
  • trunk/Source/WebCore/html/HTMLTextAreaElement.cpp

    r90591 r90775  
    270270}
    271271
     272HTMLElement* HTMLTextAreaElement::innerTextElement() const
     273{
     274    Node* node = shadowRoot()->firstChild();
     275    ASSERT(!node || node->hasTagName(divTag));
     276    return static_cast<HTMLElement*>(node);
     277}
     278
    272279void HTMLTextAreaElement::rendererWillBeDestroyed()
    273280{
  • trunk/Source/WebCore/html/HTMLTextAreaElement.h

    r90591 r90775  
    5252    bool isValidValue(const String&) const;
    5353   
     54    virtual HTMLElement* innerTextElement() const;
     55
    5456    void rendererWillBeDestroyed();
    55    
     57
    5658    void setCols(int);
    5759    void setRows(int);
  • trunk/Source/WebCore/rendering/RenderTextControl.cpp

    r90763 r90775  
    8383}
    8484
    85 HTMLTextFormControlElement* RenderTextControl::textFormControlElement()
     85HTMLTextFormControlElement* RenderTextControl::textFormControlElement() const
    8686{
    8787    return static_cast<HTMLTextFormControlElement*>(node());
     88}
     89
     90HTMLElement* RenderTextControl::innerTextElement() const
     91{
     92    return textFormControlElement()->innerTextElement();
    8893}
    8994
  • trunk/Source/WebCore/rendering/RenderTextControl.h

    r90763 r90775  
    3636    virtual ~RenderTextControl();
    3737
    38     HTMLTextFormControlElement* textFormControlElement();
    39     virtual HTMLElement* innerTextElement() const = 0;
     38    HTMLTextFormControlElement* textFormControlElement() const;
    4039    virtual PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const = 0;
    4140
     
    5453protected:
    5554    RenderTextControl(Node*, bool);
     55
     56    // This convenience function should not be made public because innerTextElement may outlive the render tree.
     57    HTMLElement* innerTextElement() const;
    5658
    5759    int scrollbarThickness() const;
  • trunk/Source/WebCore/rendering/RenderTextControlMultiLine.cpp

    r90591 r90775  
    4343    if (node() && node()->inDocument())
    4444        static_cast<HTMLTextAreaElement*>(node())->rendererWillBeDestroyed();
    45 }
    46 
    47 HTMLElement* RenderTextControlMultiLine::innerTextElement() const
    48 {
    49     return toHTMLElement(toElement(node())->shadowRoot()->firstChild());
    5045}
    5146
  • trunk/Source/WebCore/rendering/RenderTextControlMultiLine.h

    r90591 r90775  
    3131    RenderTextControlMultiLine(Node*, bool);
    3232    virtual ~RenderTextControlMultiLine();
    33 
    34     virtual HTMLElement* innerTextElement() const;
    3533
    3634    void forwardEvent(Event*);
  • trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp

    r90667 r90775  
    9595}
    9696
    97 inline HTMLElement* RenderTextControlSingleLine::innerTextElement() const
    98 {
    99     return inputElement()->innerTextElement();
    100 }
    101 
    10297inline HTMLElement* RenderTextControlSingleLine::innerBlockElement() const
    10398{
  • trunk/Source/WebCore/rendering/RenderTextControlSingleLine.h

    r90591 r90775  
    132132
    133133    HTMLElement* containerElement() const;
    134     virtual HTMLElement* innerTextElement() const;
    135134    HTMLElement* innerBlockElement() const;
    136135    HTMLElement* innerSpinButtonElement() const;
Note: See TracChangeset for help on using the changeset viewer.