Changeset 90885 in webkit


Ignore:
Timestamp:
Jul 12, 2011 9:23:03 PM (13 years ago)
Author:
rniwa@webkit.org
Message:

Move RenderTextControl::indexForVisiblePosition to HTMLTextFormControlElement
https://bugs.webkit.org/show_bug.cgi?id=64403

Reviewed by Hajime Morita.

Moved indexForVisiblePosition from RenderTextControl to HTMLTextFormControlElement.

Also replaced the call to RenderTextControl::isSelectableElement by a call to enclosingTextFormControl
(moved from htmlediting to HTMLTextFormControlElement) because we are only interested in checking
whether the given position is inside the current text form control or not.

In addition, modernized the code in indexForVisiblePosition by calling parentAnchoredEquivalent on the
given position and replacing calls to deprecateNode and deprecatedEditingOffset by calls to containerNode
and offsetInContainer.

  • accessibility/AccessibilityRenderObject.cpp:

(WebCore::AccessibilityRenderObject::indexForVisiblePosition): Calls indexForVisiblePosition.

  • editing/htmlediting.cpp: Removed enclosingTextFromControl.
  • editing/htmlediting.h: Removed enclosingTextFromControl.
  • html/HTMLTextFormControlElement.cpp:

(WebCore::HTMLTextFormControlElement::indexForVisiblePosition): Moved from RenderTextControl.
(WebCore::HTMLTextFormControlElement::computeSelectionStart): Calls indexForVisiblePosition.
(WebCore::HTMLTextFormControlElement::computeSelectionEnd): Calls indexForVisiblePosition.
(WebCore::enclosingTextFormControl): Moved from htmlediting.cpp

  • html/HTMLTextFormControlElement.h:
  • rendering/RenderTextControl.cpp:
  • rendering/RenderTextControl.h:
Location:
trunk/Source/WebCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r90882 r90885  
     12011-07-12  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Move RenderTextControl::indexForVisiblePosition to HTMLTextFormControlElement
     4        https://bugs.webkit.org/show_bug.cgi?id=64403
     5
     6        Reviewed by Hajime Morita.
     7
     8        Moved indexForVisiblePosition from RenderTextControl to HTMLTextFormControlElement.
     9
     10        Also replaced the call to RenderTextControl::isSelectableElement by a call to enclosingTextFormControl
     11        (moved from htmlediting to HTMLTextFormControlElement) because we are only interested in checking
     12        whether the given position is inside the current text form control or not.
     13
     14        In addition, modernized the code in indexForVisiblePosition by calling parentAnchoredEquivalent on the
     15        given position and replacing calls to deprecateNode and deprecatedEditingOffset by calls to containerNode
     16        and offsetInContainer.
     17
     18        * accessibility/AccessibilityRenderObject.cpp:
     19        (WebCore::AccessibilityRenderObject::indexForVisiblePosition): Calls indexForVisiblePosition.
     20        * editing/htmlediting.cpp: Removed enclosingTextFromControl.
     21        * editing/htmlediting.h: Removed enclosingTextFromControl.
     22        * html/HTMLTextFormControlElement.cpp:
     23        (WebCore::HTMLTextFormControlElement::indexForVisiblePosition): Moved from RenderTextControl.
     24        (WebCore::HTMLTextFormControlElement::computeSelectionStart): Calls indexForVisiblePosition.
     25        (WebCore::HTMLTextFormControlElement::computeSelectionEnd): Calls indexForVisiblePosition.
     26        (WebCore::enclosingTextFormControl): Moved from htmlediting.cpp
     27        * html/HTMLTextFormControlElement.h:
     28        * rendering/RenderTextControl.cpp:
     29        * rendering/RenderTextControl.h:
     30
    1312011-07-12  Julien Chaffraix  <jchaffraix@webkit.org>
    232
  • trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp

    r90775 r90885  
    24962496    if (isNativeTextControl()) {
    24972497        HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
    2498         return RenderTextControl::indexForVisiblePosition(textControl->innerTextElement(), pos);
     2498        return textControl->indexForVisiblePosition(pos);
    24992499    }
    25002500
  • trunk/Source/WebCore/editing/htmlediting.cpp

    r90849 r90885  
    857857    return isTabSpanTextNode(node) ? node->parentNode() : 0;
    858858}
    859 
    860 HTMLTextFormControlElement* enclosingTextFormControl(const Position& position)
    861 {
    862     ASSERT(position.isNull() || position.anchorType() == Position::PositionIsOffsetInAnchor
    863            || position.containerNode() || !position.anchorNode()->shadowAncestorNode());
    864     Node* container = position.containerNode();
    865     if (!container)
    866         return 0;
    867     Node* ancestor = container->shadowAncestorNode();
    868     return ancestor != container ? toTextFormControl(ancestor) : 0;
    869 }
    870859   
    871860Position positionOutsideTabSpan(const Position& pos)
  • trunk/Source/WebCore/editing/htmlediting.h

    r90098 r90885  
    219219Element* editableRootForPosition(const Position&);
    220220Element* unsplittableElementForPosition(const Position&);
    221 HTMLTextFormControlElement* enclosingTextFormControl(const Position&);
    222221
    223222// Boolean functions on Element
  • trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp

    r90849 r90885  
    3838#include "RenderTheme.h"
    3939#include "ScriptEventListener.h"
     40#include "TextIterator.h"
    4041#include <wtf/Vector.h>
    4142
     
    214215}
    215216
     217int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& pos) const
     218{
     219    Position indexPosition = pos.deepEquivalent().parentAnchoredEquivalent();
     220    if (enclosingTextFormControl(indexPosition) != this)
     221        return 0;
     222    ExceptionCode ec = 0;
     223    RefPtr<Range> range = Range::create(indexPosition.document());
     224    range->setStart(innerTextElement(), 0, ec);
     225    ASSERT(!ec);
     226    range->setEnd(indexPosition.containerNode(), indexPosition.offsetInContainerNode(), ec);
     227    ASSERT(!ec);
     228    return TextIterator::rangeLength(range.get());
     229}
     230
    216231int HTMLTextFormControlElement::selectionStart() const
    217232{
     
    230245        return 0;
    231246
    232     return RenderTextControl::indexForVisiblePosition(innerTextElement(), frame->selection()->start());
     247    return indexForVisiblePosition(frame->selection()->start());
    233248}
    234249
     
    248263        return 0;
    249264
    250     return RenderTextControl::indexForVisiblePosition(innerTextElement(), frame->selection()->end());
     265    return indexForVisiblePosition(frame->selection()->end());
    251266}
    252267
     
    334349}
    335350
     351HTMLTextFormControlElement* enclosingTextFormControl(const Position& position)
     352{
     353    ASSERT(position.isNull() || position.anchorType() == Position::PositionIsOffsetInAnchor
     354           || position.containerNode() || !position.anchorNode()->shadowAncestorNode());
     355    Node* container = position.containerNode();
     356    if (!container)
     357        return 0;
     358    Node* ancestor = container->shadowAncestorNode();
     359    return ancestor != container ? toTextFormControl(ancestor) : 0;
     360}
     361
    336362} // namespace Webcore
  • trunk/Source/WebCore/html/HTMLTextFormControlElement.h

    r90849 r90885  
    2929namespace WebCore {
    3030
     31class Position;
    3132class RenderTextControl;
     33class VisiblePosition;
    3234
    3335class HTMLTextFormControlElement : public HTMLFormControlElementWithState {
     
    4547    bool placeholderShouldBeVisible() const;
    4648
     49    int indexForVisiblePosition(const VisiblePosition&) const;
    4750    int selectionStart() const;
    4851    int selectionEnd() const;
     
    116119}
    117120
     121HTMLTextFormControlElement* enclosingTextFormControl(const Position&);
     122
    118123} // namespace
    119124
  • trunk/Source/WebCore/rendering/RenderTextControl.cpp

    r90775 r90885  
    3030#include "FrameSelection.h"
    3131#include "HTMLBRElement.h"
    32 #include "HTMLFormControlElement.h"
    3332#include "HTMLInputElement.h"
    3433#include "HTMLNames.h"
     
    3938#include "ScrollbarTheme.h"
    4039#include "Text.h"
    41 #include "TextControlInnerElements.h"
    4240#include "TextIterator.h"
    4341#include <wtf/text/StringBuilder.h>
     
    184182}
    185183
    186 bool RenderTextControl::isSelectableElement(HTMLElement* innerText, Node* node)
    187 {
    188     if (!node || !innerText)
    189         return false;
    190 
    191     if (node->rootEditableElement() == innerText)
    192         return true;
    193    
    194     if (!innerText->contains(node))
    195         return false;
    196    
    197     Node* shadowAncestor = node->shadowAncestorNode();
    198     return shadowAncestor && (shadowAncestor->hasTagName(textareaTag)
    199         || (shadowAncestor->hasTagName(inputTag) && static_cast<HTMLInputElement*>(shadowAncestor)->isTextField()));
    200 }
    201 
    202184VisiblePosition RenderTextControl::visiblePositionForIndex(int index) const
    203185{
     
    211193    it.advance(index - 1);
    212194    return VisiblePosition(it.range()->endPosition(), UPSTREAM);
    213 }
    214 
    215 int RenderTextControl::indexForVisiblePosition(HTMLElement* innerTextElement, const VisiblePosition& pos)
    216 {
    217     Position indexPosition = pos.deepEquivalent();
    218     if (!RenderTextControl::isSelectableElement(innerTextElement, indexPosition.deprecatedNode()))
    219         return 0;
    220     ExceptionCode ec = 0;
    221     RefPtr<Range> range = Range::create(indexPosition.document());
    222     range->setStart(innerTextElement, 0, ec);
    223     ASSERT(!ec);
    224     range->setEnd(indexPosition.deprecatedNode(), indexPosition.deprecatedEditingOffset(), ec);
    225     ASSERT(!ec);
    226     return TextIterator::rangeLength(range.get());
    227195}
    228196
  • trunk/Source/WebCore/rendering/RenderTextControl.h

    r90791 r90885  
    2828
    2929class HTMLTextFormControlElement;
    30 class VisibleSelection;
    31 class TextControlInnerElement;
    32 class TextControlInnerTextElement;
    3330
    3431class RenderTextControl : public RenderBlock {
     
    4744
    4845    VisiblePosition visiblePositionForIndex(int index) const;
    49     static int indexForVisiblePosition(HTMLElement*, const VisiblePosition&);
    5046
    5147    void updatePlaceholderVisibility(bool, bool);
Note: See TracChangeset for help on using the changeset viewer.