Diff
Modified: trunk/Source/WebCore/ChangeLog (90774 => 90775)
--- trunk/Source/WebCore/ChangeLog 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/ChangeLog 2011-07-11 19:06:34 UTC (rev 90775)
@@ -1,3 +1,46 @@
+2011-07-08 Ryosuke Niwa <rn...@webkit.org>
+
+ 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:
+
2011-07-11 Tony Chang <t...@chromium.org>
rename RenderObject::isFlexibleBox to isDeprecatedFlexibleBox
Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (90774 => 90775)
--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2011-07-11 19:06:34 UTC (rev 90775)
@@ -2493,9 +2493,11 @@
int AccessibilityRenderObject::indexForVisiblePosition(const VisiblePosition& pos) const
{
- if (isNativeTextControl())
- return RenderTextControl::indexForVisiblePosition(toRenderTextControl(m_renderer)->innerTextElement(), pos);
-
+ if (isNativeTextControl()) {
+ HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
+ return RenderTextControl::indexForVisiblePosition(textControl->innerTextElement(), pos);
+ }
+
if (!isTextControl())
return 0;
Modified: trunk/Source/WebCore/dom/Node.cpp (90774 => 90775)
--- trunk/Source/WebCore/dom/Node.cpp 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/dom/Node.cpp 2011-07-11 19:06:34 UTC (rev 90775)
@@ -2343,9 +2343,6 @@
ContainerNode* rootNode = shadowRoot(const_cast<Node*>(node));
- if (!rootNode && node->renderer() && node->renderer()->isTextControl())
- rootNode = static_cast<RenderTextControl*>(node->renderer())->innerTextElement();
-
if (rootNode) {
indent += "\t";
traverseTreeAndMark(indent, rootNode, markedNode1, markedLabel1, markedNode2, markedLabel2);
Modified: trunk/Source/WebCore/editing/TextIterator.cpp (90774 => 90775)
--- trunk/Source/WebCore/editing/TextIterator.cpp 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/editing/TextIterator.cpp 2011-07-11 19:06:34 UTC (rev 90775)
@@ -30,6 +30,7 @@
#include "Document.h"
#include "Frame.h"
#include "HTMLElement.h"
+#include "HTMLFormControlElement.h"
#include "HTMLNames.h"
#include "htmlediting.h"
#include "InlineTextBox.h"
@@ -637,7 +638,7 @@
}
if (m_entersTextControls && renderer->isTextControl()) {
- if (HTMLElement* innerTextElement = toRenderTextControl(renderer)->innerTextElement()) {
+ if (HTMLElement* innerTextElement = toRenderTextControl(renderer)->textFormControlElement()->innerTextElement()) {
m_node = innerTextElement->shadowTreeRootNode();
pushFullyClippedState(m_fullyClippedStack, m_node);
m_offset = 0;
Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (90774 => 90775)
--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp 2011-07-11 19:06:34 UTC (rev 90775)
@@ -681,11 +681,10 @@
setChangedSinceLastFormControlChangeEvent(false);
}
-static inline bool hasVisibleTextArea(RenderTextControl* textControl)
+static inline bool hasVisibleTextArea(RenderTextControl* textControl, HTMLElement* innerText)
{
ASSERT(textControl);
- HTMLElement* innerText = textControl->innerTextElement();
- return textControl->style()->visibility() == HIDDEN || !innerText || !innerText->renderer() || !innerText->renderBox()->height();
+ return textControl->style()->visibility() != HIDDEN && innerText && innerText->renderer() && innerText->renderBox()->height();
}
void HTMLTextFormControlElement::setSelectionRange(int start, int end)
@@ -699,7 +698,7 @@
start = min(max(start, 0), end);
RenderTextControl* control = toRenderTextControl(renderer());
- if (hasVisibleTextArea(control)) {
+ if (!hasVisibleTextArea(control, innerTextElement())) {
cacheSelection(start, end);
return;
}
@@ -735,14 +734,10 @@
int HTMLTextFormControlElement::computeSelectionStart() const
{
Frame* frame = document()->frame();
- if (!renderer() || !frame)
+ if (!frame)
return 0;
- HTMLElement* innerText = toRenderTextControl(renderer())->innerTextElement();
- // Do not call innerTextElement() in the function arguments as creating a VisiblePosition
- // from frame->selection->start() can blow us from underneath. Also, function ordering is
- // usually dependent on the compiler.
- return RenderTextControl::indexForVisiblePosition(innerText, frame->selection()->start());
+ return RenderTextControl::indexForVisiblePosition(innerTextElement(), frame->selection()->start());
}
int HTMLTextFormControlElement::selectionEnd() const
@@ -757,14 +752,10 @@
int HTMLTextFormControlElement::computeSelectionEnd() const
{
Frame* frame = document()->frame();
- if (!renderer() || !frame)
+ if (!frame)
return 0;
- HTMLElement* innerText = toRenderTextControl(renderer())->innerTextElement();
- // Do not call innerTextElement() in the function arguments as creating a VisiblePosition
- // from frame->selection->end() can blow us from underneath. Also, function ordering is
- // usually dependent on the compiler.
- return RenderTextControl::indexForVisiblePosition(innerText, frame->selection()->end());
+ return RenderTextControl::indexForVisiblePosition(innerTextElement(), frame->selection()->end());
}
static inline void setContainerAndOffsetForRange(Node* node, int offset, Node*& containerNode, int& offsetInContainer)
@@ -787,7 +778,7 @@
int end = m_cachedSelectionEnd;
ASSERT(start <= end);
- HTMLElement* innerText = toRenderTextControl(renderer())->innerTextElement();
+ HTMLElement* innerText = innerTextElement();
if (!innerText)
return 0;
Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (90774 => 90775)
--- trunk/Source/WebCore/html/HTMLFormControlElement.h 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h 2011-07-11 19:06:34 UTC (rev 90775)
@@ -214,6 +214,8 @@
virtual int maxLength() const = 0;
virtual String value() const = 0;
+ virtual HTMLElement* innerTextElement() const = 0;
+
void cacheSelection(int start, int end)
{
m_cachedSelectionStart = start;
Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (90774 => 90775)
--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp 2011-07-11 19:06:34 UTC (rev 90775)
@@ -269,6 +269,13 @@
return proposedValue.left(numCharactersInGraphemeClusters(proposedValue, maxLength));
}
+HTMLElement* HTMLTextAreaElement::innerTextElement() const
+{
+ Node* node = shadowRoot()->firstChild();
+ ASSERT(!node || node->hasTagName(divTag));
+ return static_cast<HTMLElement*>(node);
+}
+
void HTMLTextAreaElement::rendererWillBeDestroyed()
{
updateValue();
Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.h (90774 => 90775)
--- trunk/Source/WebCore/html/HTMLTextAreaElement.h 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.h 2011-07-11 19:06:34 UTC (rev 90775)
@@ -51,8 +51,10 @@
bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
bool isValidValue(const String&) const;
+ virtual HTMLElement* innerTextElement() const;
+
void rendererWillBeDestroyed();
-
+
void setCols(int);
void setRows(int);
Modified: trunk/Source/WebCore/rendering/RenderTextControl.cpp (90774 => 90775)
--- trunk/Source/WebCore/rendering/RenderTextControl.cpp 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/rendering/RenderTextControl.cpp 2011-07-11 19:06:34 UTC (rev 90775)
@@ -82,11 +82,16 @@
{
}
-HTMLTextFormControlElement* RenderTextControl::textFormControlElement()
+HTMLTextFormControlElement* RenderTextControl::textFormControlElement() const
{
return static_cast<HTMLTextFormControlElement*>(node());
}
+HTMLElement* RenderTextControl::innerTextElement() const
+{
+ return textFormControlElement()->innerTextElement();
+}
+
void RenderTextControl::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
RenderBlock::styleDidChange(diff, oldStyle);
Modified: trunk/Source/WebCore/rendering/RenderTextControl.h (90774 => 90775)
--- trunk/Source/WebCore/rendering/RenderTextControl.h 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/rendering/RenderTextControl.h 2011-07-11 19:06:34 UTC (rev 90775)
@@ -35,8 +35,7 @@
public:
virtual ~RenderTextControl();
- HTMLTextFormControlElement* textFormControlElement();
- virtual HTMLElement* innerTextElement() const = 0;
+ HTMLTextFormControlElement* textFormControlElement() const;
virtual PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const = 0;
bool lastChangeWasUserEdit() const { return m_lastChangeWasUserEdit; }
@@ -54,6 +53,9 @@
protected:
RenderTextControl(Node*, bool);
+ // This convenience function should not be made public because innerTextElement may outlive the render tree.
+ HTMLElement* innerTextElement() const;
+
int scrollbarThickness() const;
void adjustInnerTextStyle(const RenderStyle* startStyle, RenderStyle* textBlockStyle) const;
void setInnerTextValue(const String&);
Modified: trunk/Source/WebCore/rendering/RenderTextControlMultiLine.cpp (90774 => 90775)
--- trunk/Source/WebCore/rendering/RenderTextControlMultiLine.cpp 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/rendering/RenderTextControlMultiLine.cpp 2011-07-11 19:06:34 UTC (rev 90775)
@@ -44,11 +44,6 @@
static_cast<HTMLTextAreaElement*>(node())->rendererWillBeDestroyed();
}
-HTMLElement* RenderTextControlMultiLine::innerTextElement() const
-{
- return toHTMLElement(toElement(node())->shadowRoot()->firstChild());
-}
-
void RenderTextControlMultiLine::subtreeHasChanged()
{
RenderTextControl::subtreeHasChanged();
Modified: trunk/Source/WebCore/rendering/RenderTextControlMultiLine.h (90774 => 90775)
--- trunk/Source/WebCore/rendering/RenderTextControlMultiLine.h 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/rendering/RenderTextControlMultiLine.h 2011-07-11 19:06:34 UTC (rev 90775)
@@ -31,8 +31,6 @@
RenderTextControlMultiLine(Node*, bool);
virtual ~RenderTextControlMultiLine();
- virtual HTMLElement* innerTextElement() const;
-
void forwardEvent(Event*);
private:
Modified: trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp (90774 => 90775)
--- trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/rendering/RenderTextControlSingleLine.cpp 2011-07-11 19:06:34 UTC (rev 90775)
@@ -94,11 +94,6 @@
return inputElement()->containerElement();
}
-inline HTMLElement* RenderTextControlSingleLine::innerTextElement() const
-{
- return inputElement()->innerTextElement();
-}
-
inline HTMLElement* RenderTextControlSingleLine::innerBlockElement() const
{
return inputElement()->innerBlockElement();
Modified: trunk/Source/WebCore/rendering/RenderTextControlSingleLine.h (90774 => 90775)
--- trunk/Source/WebCore/rendering/RenderTextControlSingleLine.h 2011-07-11 19:04:10 UTC (rev 90774)
+++ trunk/Source/WebCore/rendering/RenderTextControlSingleLine.h 2011-07-11 19:06:34 UTC (rev 90775)
@@ -131,7 +131,6 @@
virtual int textBlockInsetTop() const;
HTMLElement* containerElement() const;
- virtual HTMLElement* innerTextElement() const;
HTMLElement* innerBlockElement() const;
HTMLElement* innerSpinButtonElement() const;
HTMLElement* resultsButtonElement() const;