Title: [90591] trunk/Source/WebCore
Revision
90591
Author
[email protected]
Date
2011-07-07 14:37:26 -0700 (Thu, 07 Jul 2011)

Log Message

Move all code related to cachedSelection to HTMLTextFormControlElement
https://bugs.webkit.org/show_bug.cgi?id=64118

Reviewed by Alexey Proskuryakov.

Moved m_cachedSelectionStart and m_cachedSelectionEnd from HTMLInputElement
and HTMLTextAreaElement to HTMLTextFormControlElement

Also removed cached selection related functions from RenderTextControl,
RenderTextControlSingleLine, and RenderTextControlMultiLine because they were
merely providing wrapper functions to enable polymorphism between
input and textarea elements and their WML equivalents.

* editing/FrameSelection.cpp:
(WebCore::FrameSelection::notifyRendererOfSelectionChange): Calls HTMLTextFormControlElement's
selectionChanged instead of RenderTextControl's.
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::HTMLTextFormControlElement): Initialize
m_cachedSelectionStart and m_cachedSelectionEnd.
(WebCore::HTMLTextFormControlElement::selectionStart):
(WebCore::HTMLTextFormControlElement::selectionEnd):
(WebCore::HTMLTextFormControlElement::selection):
(WebCore::HTMLTextFormControlElement::restoreCachedSelection): Added.
(WebCore::HTMLTextFormControlElement::selectionChanged): Extracted from
RenderTextControl::selectionChanged.
* html/HTMLFormControlElement.h:
(WebCore::HTMLTextFormControlElement::cacheSelection): Extracted from HTMLInputElement
and HTMLTextAreaElement.
(WebCore::HTMLTextFormControlElement::hasCachedSelectionStart): Added.
(WebCore::HTMLTextFormControlElement::hasCachedSelectionEnd): Added.
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::HTMLInputElement):
(WebCore::HTMLInputElement::updateFocusAppearance):
* html/HTMLInputElement.h:
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::HTMLTextAreaElement):
(WebCore::HTMLTextAreaElement::updateFocusAppearance):
* html/HTMLTextAreaElement.h:
(WebCore::HTMLTextAreaElement::isEmptyValue):
* rendering/RenderTextControl.cpp:
(WebCore::setSelectionRange):
* rendering/RenderTextControl.h:
* rendering/RenderTextControlMultiLine.cpp:
* rendering/RenderTextControlMultiLine.h:
* rendering/RenderTextControlSingleLine.cpp:
* rendering/RenderTextControlSingleLine.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (90590 => 90591)


--- trunk/Source/WebCore/ChangeLog	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/ChangeLog	2011-07-07 21:37:26 UTC (rev 90591)
@@ -1,3 +1,52 @@
+2011-07-07  Ryosuke Niwa  <[email protected]>
+
+        Move all code related to cachedSelection to HTMLTextFormControlElement
+        https://bugs.webkit.org/show_bug.cgi?id=64118
+
+        Reviewed by Alexey Proskuryakov.
+
+        Moved m_cachedSelectionStart and m_cachedSelectionEnd from HTMLInputElement
+        and HTMLTextAreaElement to HTMLTextFormControlElement
+
+        Also removed cached selection related functions from RenderTextControl,
+        RenderTextControlSingleLine, and RenderTextControlMultiLine because they were
+        merely providing wrapper functions to enable polymorphism between
+        input and textarea elements and their WML equivalents.
+
+        * editing/FrameSelection.cpp:
+        (WebCore::FrameSelection::notifyRendererOfSelectionChange): Calls HTMLTextFormControlElement's
+        selectionChanged instead of RenderTextControl's.
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLTextFormControlElement::HTMLTextFormControlElement): Initialize
+        m_cachedSelectionStart and m_cachedSelectionEnd.
+        (WebCore::HTMLTextFormControlElement::selectionStart):
+        (WebCore::HTMLTextFormControlElement::selectionEnd):
+        (WebCore::HTMLTextFormControlElement::selection):
+        (WebCore::HTMLTextFormControlElement::restoreCachedSelection): Added.
+        (WebCore::HTMLTextFormControlElement::selectionChanged): Extracted from
+        RenderTextControl::selectionChanged.
+        * html/HTMLFormControlElement.h:
+        (WebCore::HTMLTextFormControlElement::cacheSelection): Extracted from HTMLInputElement
+        and HTMLTextAreaElement.
+        (WebCore::HTMLTextFormControlElement::hasCachedSelectionStart): Added.
+        (WebCore::HTMLTextFormControlElement::hasCachedSelectionEnd): Added.
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::HTMLInputElement):
+        (WebCore::HTMLInputElement::updateFocusAppearance):
+        * html/HTMLInputElement.h:
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::HTMLTextAreaElement):
+        (WebCore::HTMLTextAreaElement::updateFocusAppearance):
+        * html/HTMLTextAreaElement.h:
+        (WebCore::HTMLTextAreaElement::isEmptyValue):
+        * rendering/RenderTextControl.cpp:
+        (WebCore::setSelectionRange):
+        * rendering/RenderTextControl.h:
+        * rendering/RenderTextControlMultiLine.cpp:
+        * rendering/RenderTextControlMultiLine.h:
+        * rendering/RenderTextControlSingleLine.cpp:
+        * rendering/RenderTextControlSingleLine.h:
+
 2011-07-07  Emil A Eklund  <[email protected]>
 
         Switch addFocusRingRects to to new layout types

Modified: trunk/Source/WebCore/editing/FrameSelection.cpp (90590 => 90591)


--- trunk/Source/WebCore/editing/FrameSelection.cpp	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/editing/FrameSelection.cpp	2011-07-07 21:37:26 UTC (rev 90591)
@@ -1658,11 +1658,8 @@
     if (!rootEditableElement())
         return;
 
-    RenderObject* renderer = rootEditableElement()->shadowAncestorNode()->renderer();
-    if (!renderer || !renderer->isTextControl())
-        return;
-
-    toRenderTextControl(renderer)->selectionChanged(userTriggered == UserTriggered);
+    if (HTMLTextFormControlElement* textControl = enclosingTextFormControl(start()))
+        textControl->selectionChanged(userTriggered == UserTriggered);
 }
 
 // Helper function that tells whether a particular node is an element that has an entire

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (90590 => 90591)


--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2011-07-07 21:37:26 UTC (rev 90591)
@@ -564,6 +564,8 @@
 
 HTMLTextFormControlElement::HTMLTextFormControlElement(const QualifiedName& tagName, Document* doc, HTMLFormElement* form)
     : HTMLFormControlElementWithState(tagName, doc, form)
+    , m_cachedSelectionStart(-1)
+    , m_cachedSelectionEnd(-1)
 {
 }
 
@@ -678,8 +680,8 @@
 {
     if (!isTextFormControl())
         return 0;
-    if (document()->focusedNode() != this && cachedSelectionStart() >= 0)
-        return cachedSelectionStart();
+    if (document()->focusedNode() != this && hasCachedSelectionStart())
+        return m_cachedSelectionStart;
     if (!renderer())
         return 0;
     return toRenderTextControl(renderer())->selectionStart();
@@ -689,8 +691,8 @@
 {
     if (!isTextFormControl())
         return 0;
-    if (document()->focusedNode() != this && cachedSelectionEnd() >= 0)
-        return cachedSelectionEnd();
+    if (document()->focusedNode() != this && hasCachedSelectionEnd())
+        return m_cachedSelectionEnd;
     if (!renderer())
         return 0;
     return toRenderTextControl(renderer())->selectionEnd();
@@ -698,11 +700,30 @@
 
 PassRefPtr<Range> HTMLTextFormControlElement::selection() const
 {
-    if (!renderer() || !isTextFormControl() || cachedSelectionStart() < 0 || cachedSelectionEnd() < 0)
+    if (!renderer() || !isTextFormControl() || !hasCachedSelectionStart() || !hasCachedSelectionEnd())
         return 0;
-    return toRenderTextControl(renderer())->selection(cachedSelectionStart(), cachedSelectionEnd());
+    return toRenderTextControl(renderer())->selection(m_cachedSelectionStart, m_cachedSelectionEnd);
 }
 
+void HTMLTextFormControlElement::restoreCachedSelection()
+{
+    WebCore::setSelectionRange(this, m_cachedSelectionStart, m_cachedSelectionEnd);
+}
+
+void HTMLTextFormControlElement::selectionChanged(bool userTriggered)
+{
+    if (!renderer() || !isTextFormControl())
+        return;
+
+    RenderTextControl* renderTextControl = toRenderTextControl(renderer());
+    cacheSelection(renderTextControl->selectionStart(), renderTextControl->selectionEnd());
+
+    if (Frame* frame = document()->frame()) {
+        if (frame->selection()->isRange() && userTriggered)
+            dispatchEvent(Event::create(eventNames().selectEvent, true, false));
+    }
+}
+
 void HTMLTextFormControlElement::parseMappedAttribute(Attribute* attr)
 {
     if (attr->name() == placeholderAttr)

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (90590 => 90591)


--- trunk/Source/WebCore/html/HTMLFormControlElement.h	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h	2011-07-07 21:37:26 UTC (rev 90591)
@@ -213,6 +213,14 @@
     virtual int maxLength() const = 0;
     virtual String value() const = 0;
 
+    void cacheSelection(int start, int end)
+    {
+        m_cachedSelectionStart = start;
+        m_cachedSelectionEnd = end;
+    }
+
+    void selectionChanged(bool userTriggered);
+
 protected:
     HTMLTextFormControlElement(const QualifiedName&, Document*, HTMLFormElement*);
 
@@ -222,15 +230,16 @@
 
     void setTextAsOfLastFormControlChangeEvent(const String& text) { m_textAsOfLastFormControlChangeEvent = text; }
 
+    void restoreCachedSelection();
+    bool hasCachedSelectionStart() const { return m_cachedSelectionStart >= 0; }
+    bool hasCachedSelectionEnd() const { return m_cachedSelectionEnd >= 0; }
+
 private:
     virtual void dispatchFocusEvent();
     virtual void dispatchBlurEvent();
 
     bool isPlaceholderEmpty() const;
 
-    virtual int cachedSelectionStart() const = 0;
-    virtual int cachedSelectionEnd() const = 0;
-
     // Returns true if user-editable value is empty. Used to check placeholder visibility.
     virtual bool isEmptyValue() const = 0;
     // Returns true if suggested value is empty. Used to check placeholder visibility.
@@ -243,6 +252,9 @@
     RenderTextControl* textRendererAfterUpdateLayout();
 
     String m_textAsOfLastFormControlChangeEvent;
+    
+    int m_cachedSelectionStart;
+    int m_cachedSelectionEnd;
 };
 
 // This function returns 0 when node is an input element and not a text field.

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (90590 => 90591)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2011-07-07 21:37:26 UTC (rev 90591)
@@ -78,8 +78,6 @@
     : HTMLTextFormControlElement(tagName, document, form)
     , m_size(defaultSize)
     , m_maxLength(maximumLength)
-    , m_cachedSelectionStart(-1)
-    , m_cachedSelectionEnd(-1)
 #if ENABLE(WCSS)
     , m_inputFormatMask("*m")
     , m_maxInputCharsAllowed(maximumLength)
@@ -473,12 +471,10 @@
 void HTMLInputElement::updateFocusAppearance(bool restorePreviousSelection)
 {
     if (isTextField()) {
-        if (!restorePreviousSelection || m_cachedSelectionStart == -1)
+        if (!restorePreviousSelection || !hasCachedSelectionStart())
             select();
-        else {
-            // Restore the cached selection.
-            WebCore::setSelectionRange(this, m_cachedSelectionStart, m_cachedSelectionEnd);
-        }
+        else
+            restoreCachedSelection();
         if (document()->frame())
             document()->frame()->selection()->revealSelection();
     } else
@@ -1363,12 +1359,6 @@
     return m_inputType->supportsRequired() && required();
 }
 
-void HTMLInputElement::cacheSelection(int start, int end)
-{
-    m_cachedSelectionStart = start;
-    m_cachedSelectionEnd = end;
-}
-
 void HTMLInputElement::addSearchResult()
 {
     ASSERT(isSearchField());

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (90590 => 90591)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2011-07-07 21:37:26 UTC (rev 90591)
@@ -228,7 +228,6 @@
 #endif
 
     bool lastChangeWasUserEdit() const;
-    void cacheSelection(int start, int end);
     void notifyFormStateChanged();
 
     static const int maximumLength;
@@ -308,8 +307,6 @@
     virtual void handleFocusEvent();
     virtual void willBlur();
     virtual void handleBlurEvent();
-    virtual int cachedSelectionStart() const { return m_cachedSelectionStart; }
-    virtual int cachedSelectionEnd() const { return m_cachedSelectionEnd; }
 
     virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); }
     virtual bool isRequiredFormControl() const;
@@ -337,8 +334,6 @@
     String m_suggestedValue;
     int m_size;
     int m_maxLength;
-    int m_cachedSelectionStart;
-    int m_cachedSelectionEnd;
 #if ENABLE(WCSS)
     String m_inputFormatMask;
     unsigned m_maxInputCharsAllowed;

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (90590 => 90591)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2011-07-07 21:37:26 UTC (rev 90591)
@@ -70,8 +70,6 @@
     , m_rows(defaultRows)
     , m_cols(defaultCols)
     , m_wrap(SoftWrap)
-    , m_cachedSelectionStart(-1)
-    , m_cachedSelectionEnd(-1)
     , m_isDirty(false)
     , m_wasModifiedByUser(false)
 {
@@ -215,7 +213,7 @@
     ASSERT(renderer());
     ASSERT(!document()->childNeedsAndNotInStyleRecalc());
 
-    if (!restorePreviousSelection || m_cachedSelectionStart < 0) {
+    if (!restorePreviousSelection || !hasCachedSelectionStart()) {
 #if ENABLE(ON_FIRST_TEXTAREA_FOCUS_SELECT_ALL)
         // Devices with trackballs or d-pads may focus on a textarea in route
         // to another focusable node. By selecting all text, the next movement
@@ -227,10 +225,8 @@
         // http://bugs.webkit.org/show_bug.cgi?id=11746#c15
         setSelectionRange(0, 0);
 #endif
-    } else {
-        // Restore the cached selection.  This matches other browsers' behavior.
-        setSelectionRange(m_cachedSelectionStart, m_cachedSelectionEnd);
-    }
+    } else
+        restoreCachedSelection();
 
     if (document()->frame())
         document()->frame()->selection()->revealSelection();

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.h (90590 => 90591)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.h	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.h	2011-07-07 21:37:26 UTC (rev 90591)
@@ -58,8 +58,6 @@
 
     bool lastChangeWasUserEdit() const;
 
-    void cacheSelection(int s, int e) { m_cachedSelectionStart = s; m_cachedSelectionEnd = e; };
-
 private:
     HTMLTextAreaElement(const QualifiedName&, Document*, HTMLFormElement*);
 
@@ -75,8 +73,6 @@
 
     virtual bool supportsPlaceholder() const { return true; }
     virtual bool isEmptyValue() const { return value().isEmpty(); }
-    virtual int cachedSelectionStart() const { return m_cachedSelectionStart; }
-    virtual int cachedSelectionEnd() const { return m_cachedSelectionEnd; }
 
     virtual bool isOptionalFormControl() const { return !isRequiredFormControl(); }
     virtual bool isRequiredFormControl() const { return required(); }
@@ -109,8 +105,6 @@
     int m_cols;
     WrapMethod m_wrap;
     mutable String m_value;
-    int m_cachedSelectionStart;
-    int m_cachedSelectionEnd;
     mutable bool m_isDirty;
     bool m_wasModifiedByUser;
 };

Modified: trunk/Source/WebCore/rendering/RenderTextControl.cpp (90590 => 90591)


--- trunk/Source/WebCore/rendering/RenderTextControl.cpp	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/rendering/RenderTextControl.cpp	2011-07-07 21:37:26 UTC (rev 90591)
@@ -219,7 +219,7 @@
     RenderTextControl* control = toRenderTextControl(node->renderer());
 
     if (control->hasVisibleTextArea()) {
-        control->cacheSelection(start, end);
+        static_cast<HTMLTextFormControlElement*>(node)->cacheSelection(start, end);
         return;
     }
     VisiblePosition startPosition = control->visiblePositionForIndex(start);
@@ -573,16 +573,6 @@
     setPreferredLogicalWidthsDirty(false);
 }
 
-void RenderTextControl::selectionChanged(bool userTriggered)
-{
-    cacheSelection(selectionStart(), selectionEnd());
-
-    if (Frame* frame = this->frame()) {
-        if (frame->selection()->isRange() && userTriggered)
-            node()->dispatchEvent(Event::create(eventNames().selectEvent, true, false));
-    }
-}
-
 void RenderTextControl::addFocusRingRects(Vector<LayoutRect>& rects, const LayoutPoint& additionalOffset)
 {
     if (!size().isEmpty())

Modified: trunk/Source/WebCore/rendering/RenderTextControl.h (90590 => 90591)


--- trunk/Source/WebCore/rendering/RenderTextControl.h	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/rendering/RenderTextControl.h	2011-07-07 21:37:26 UTC (rev 90591)
@@ -47,7 +47,6 @@
     virtual void subtreeHasChanged();
     String text();
     String textWithHardLineBreaks();
-    void selectionChanged(bool userTriggered);
 
     VisiblePosition visiblePositionForIndex(int index) const;
     static int indexForVisiblePosition(HTMLElement*, const VisiblePosition&);
@@ -75,7 +74,6 @@
     virtual float getAvgCharWidth(AtomicString family);
     virtual int preferredContentWidth(float charWidth) const = 0;
     virtual void adjustControlHeightBasedOnLineHeight(int lineHeight) = 0;
-    virtual void cacheSelection(int start, int end) = 0;
     virtual RenderStyle* textBaseStyle() const = 0;
 
     virtual void updateFromElement();

Modified: trunk/Source/WebCore/rendering/RenderTextControlMultiLine.cpp (90590 => 90591)


--- trunk/Source/WebCore/rendering/RenderTextControlMultiLine.cpp	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/rendering/RenderTextControlMultiLine.cpp	2011-07-07 21:37:26 UTC (rev 90591)
@@ -114,11 +114,6 @@
     setInnerTextValue(static_cast<HTMLTextAreaElement*>(node())->value());
 }
 
-void RenderTextControlMultiLine::cacheSelection(int start, int end)
-{
-    static_cast<HTMLTextAreaElement*>(node())->cacheSelection(start, end);
-}
-
 PassRefPtr<RenderStyle> RenderTextControlMultiLine::createInnerTextStyle(const RenderStyle* startStyle) const
 {
     RefPtr<RenderStyle> textBlockStyle = RenderStyle::create();

Modified: trunk/Source/WebCore/rendering/RenderTextControlMultiLine.h (90590 => 90591)


--- trunk/Source/WebCore/rendering/RenderTextControlMultiLine.h	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/rendering/RenderTextControlMultiLine.h	2011-07-07 21:37:26 UTC (rev 90591)
@@ -48,7 +48,6 @@
     virtual int baselinePosition(FontBaseline, bool firstLine, LineDirectionMode, LinePositionMode = PositionOnContainingLine) const;
 
     virtual void updateFromElement();
-    virtual void cacheSelection(int start, int end);
 
     virtual RenderStyle* textBaseStyle() const;
     virtual PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const;

Modified: trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp (90590 => 90591)


--- trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp	2011-07-07 21:37:26 UTC (rev 90591)
@@ -532,11 +532,6 @@
         m_searchPopup->popupMenu()->updateFromElement();
 }
 
-void RenderTextControlSingleLine::cacheSelection(int start, int end)
-{
-    inputElement()->cacheSelection(start, end);
-}
-
 PassRefPtr<RenderStyle> RenderTextControlSingleLine::createInnerTextStyle(const RenderStyle* startStyle) const
 {
     RefPtr<RenderStyle> textBlockStyle = RenderStyle::create();   

Modified: trunk/Source/WebCore/rendering/RenderTextControlSingleLine.h (90590 => 90591)


--- trunk/Source/WebCore/rendering/RenderTextControlSingleLine.h	2011-07-07 21:16:15 UTC (rev 90590)
+++ trunk/Source/WebCore/rendering/RenderTextControlSingleLine.h	2011-07-07 21:37:26 UTC (rev 90591)
@@ -84,7 +84,6 @@
     virtual void adjustControlHeightBasedOnLineHeight(int lineHeight);
 
     virtual void updateFromElement();
-    virtual void cacheSelection(int start, int end);
     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle);
 
     virtual RenderStyle* textBaseStyle() const;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to