- Revision
- 90885
- Author
- [email protected]
- Date
- 2011-07-12 21:23:03 -0700 (Tue, 12 Jul 2011)
Log 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:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (90884 => 90885)
--- trunk/Source/WebCore/ChangeLog 2011-07-13 04:05:51 UTC (rev 90884)
+++ trunk/Source/WebCore/ChangeLog 2011-07-13 04:23:03 UTC (rev 90885)
@@ -1,3 +1,33 @@
+2011-07-12 Ryosuke Niwa <[email protected]>
+
+ 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:
+
2011-07-12 Julien Chaffraix <[email protected]>
Make RenderObject::containingBlock virtual for better speed and clarity
Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (90884 => 90885)
--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2011-07-13 04:05:51 UTC (rev 90884)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2011-07-13 04:23:03 UTC (rev 90885)
@@ -2495,7 +2495,7 @@
{
if (isNativeTextControl()) {
HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
- return RenderTextControl::indexForVisiblePosition(textControl->innerTextElement(), pos);
+ return textControl->indexForVisiblePosition(pos);
}
if (!isTextControl())
Modified: trunk/Source/WebCore/editing/htmlediting.cpp (90884 => 90885)
--- trunk/Source/WebCore/editing/htmlediting.cpp 2011-07-13 04:05:51 UTC (rev 90884)
+++ trunk/Source/WebCore/editing/htmlediting.cpp 2011-07-13 04:23:03 UTC (rev 90885)
@@ -856,17 +856,6 @@
{
return isTabSpanTextNode(node) ? node->parentNode() : 0;
}
-
-HTMLTextFormControlElement* enclosingTextFormControl(const Position& position)
-{
- ASSERT(position.isNull() || position.anchorType() == Position::PositionIsOffsetInAnchor
- || position.containerNode() || !position.anchorNode()->shadowAncestorNode());
- Node* container = position.containerNode();
- if (!container)
- return 0;
- Node* ancestor = container->shadowAncestorNode();
- return ancestor != container ? toTextFormControl(ancestor) : 0;
-}
Position positionOutsideTabSpan(const Position& pos)
{
Modified: trunk/Source/WebCore/editing/htmlediting.h (90884 => 90885)
--- trunk/Source/WebCore/editing/htmlediting.h 2011-07-13 04:05:51 UTC (rev 90884)
+++ trunk/Source/WebCore/editing/htmlediting.h 2011-07-13 04:23:03 UTC (rev 90885)
@@ -218,7 +218,6 @@
Element* editableRootForPosition(const Position&);
Element* unsplittableElementForPosition(const Position&);
-HTMLTextFormControlElement* enclosingTextFormControl(const Position&);
// Boolean functions on Element
Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp (90884 => 90885)
--- trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp 2011-07-13 04:05:51 UTC (rev 90884)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.cpp 2011-07-13 04:23:03 UTC (rev 90885)
@@ -37,6 +37,7 @@
#include "RenderTextControl.h"
#include "RenderTheme.h"
#include "ScriptEventListener.h"
+#include "TextIterator.h"
#include <wtf/Vector.h>
namespace WebCore {
@@ -213,6 +214,20 @@
frame->selection()->setSelection(newSelection);
}
+int HTMLTextFormControlElement::indexForVisiblePosition(const VisiblePosition& pos) const
+{
+ Position indexPosition = pos.deepEquivalent().parentAnchoredEquivalent();
+ if (enclosingTextFormControl(indexPosition) != this)
+ return 0;
+ ExceptionCode ec = 0;
+ RefPtr<Range> range = Range::create(indexPosition.document());
+ range->setStart(innerTextElement(), 0, ec);
+ ASSERT(!ec);
+ range->setEnd(indexPosition.containerNode(), indexPosition.offsetInContainerNode(), ec);
+ ASSERT(!ec);
+ return TextIterator::rangeLength(range.get());
+}
+
int HTMLTextFormControlElement::selectionStart() const
{
if (!isTextFormControl())
@@ -229,7 +244,7 @@
if (!frame)
return 0;
- return RenderTextControl::indexForVisiblePosition(innerTextElement(), frame->selection()->start());
+ return indexForVisiblePosition(frame->selection()->start());
}
int HTMLTextFormControlElement::selectionEnd() const
@@ -247,7 +262,7 @@
if (!frame)
return 0;
- return RenderTextControl::indexForVisiblePosition(innerTextElement(), frame->selection()->end());
+ return indexForVisiblePosition(frame->selection()->end());
}
static inline void setContainerAndOffsetForRange(Node* node, int offset, Node*& containerNode, int& offsetInContainer)
@@ -333,4 +348,15 @@
HTMLFormControlElementWithState::parseMappedAttribute(attr);
}
+HTMLTextFormControlElement* enclosingTextFormControl(const Position& position)
+{
+ ASSERT(position.isNull() || position.anchorType() == Position::PositionIsOffsetInAnchor
+ || position.containerNode() || !position.anchorNode()->shadowAncestorNode());
+ Node* container = position.containerNode();
+ if (!container)
+ return 0;
+ Node* ancestor = container->shadowAncestorNode();
+ return ancestor != container ? toTextFormControl(ancestor) : 0;
+}
+
} // namespace Webcore
Modified: trunk/Source/WebCore/html/HTMLTextFormControlElement.h (90884 => 90885)
--- trunk/Source/WebCore/html/HTMLTextFormControlElement.h 2011-07-13 04:05:51 UTC (rev 90884)
+++ trunk/Source/WebCore/html/HTMLTextFormControlElement.h 2011-07-13 04:23:03 UTC (rev 90885)
@@ -28,7 +28,9 @@
namespace WebCore {
+class Position;
class RenderTextControl;
+class VisiblePosition;
class HTMLTextFormControlElement : public HTMLFormControlElementWithState {
public:
@@ -44,6 +46,7 @@
String strippedPlaceholder() const;
bool placeholderShouldBeVisible() const;
+ int indexForVisiblePosition(const VisiblePosition&) const;
int selectionStart() const;
int selectionEnd() const;
void setSelectionStart(int);
@@ -115,6 +118,8 @@
return (node && node->isElementNode() && static_cast<Element*>(node)->isTextFormControl()) ? static_cast<HTMLTextFormControlElement*>(node) : 0;
}
+HTMLTextFormControlElement* enclosingTextFormControl(const Position&);
+
} // namespace
#endif
Modified: trunk/Source/WebCore/rendering/RenderTextControl.cpp (90884 => 90885)
--- trunk/Source/WebCore/rendering/RenderTextControl.cpp 2011-07-13 04:05:51 UTC (rev 90884)
+++ trunk/Source/WebCore/rendering/RenderTextControl.cpp 2011-07-13 04:23:03 UTC (rev 90885)
@@ -29,7 +29,6 @@
#include "Frame.h"
#include "FrameSelection.h"
#include "HTMLBRElement.h"
-#include "HTMLFormControlElement.h"
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "HitTestResult.h"
@@ -38,7 +37,6 @@
#include "RenderText.h"
#include "ScrollbarTheme.h"
#include "Text.h"
-#include "TextControlInnerElements.h"
#include "TextIterator.h"
#include <wtf/text/StringBuilder.h>
#include <wtf/unicode/CharacterNames.h>
@@ -183,22 +181,6 @@
document()->setIgnoreAutofocus(lastChangeWasUserEdit);
}
-bool RenderTextControl::isSelectableElement(HTMLElement* innerText, Node* node)
-{
- if (!node || !innerText)
- return false;
-
- if (node->rootEditableElement() == innerText)
- return true;
-
- if (!innerText->contains(node))
- return false;
-
- Node* shadowAncestor = node->shadowAncestorNode();
- return shadowAncestor && (shadowAncestor->hasTagName(textareaTag)
- || (shadowAncestor->hasTagName(inputTag) && static_cast<HTMLInputElement*>(shadowAncestor)->isTextField()));
-}
-
VisiblePosition RenderTextControl::visiblePositionForIndex(int index) const
{
if (index <= 0)
@@ -212,20 +194,6 @@
return VisiblePosition(it.range()->endPosition(), UPSTREAM);
}
-int RenderTextControl::indexForVisiblePosition(HTMLElement* innerTextElement, const VisiblePosition& pos)
-{
- Position indexPosition = pos.deepEquivalent();
- if (!RenderTextControl::isSelectableElement(innerTextElement, indexPosition.deprecatedNode()))
- return 0;
- ExceptionCode ec = 0;
- RefPtr<Range> range = Range::create(indexPosition.document());
- range->setStart(innerTextElement, 0, ec);
- ASSERT(!ec);
- range->setEnd(indexPosition.deprecatedNode(), indexPosition.deprecatedEditingOffset(), ec);
- ASSERT(!ec);
- return TextIterator::rangeLength(range.get());
-}
-
void RenderTextControl::subtreeHasChanged()
{
m_lastChangeWasUserEdit = true;
Modified: trunk/Source/WebCore/rendering/RenderTextControl.h (90884 => 90885)
--- trunk/Source/WebCore/rendering/RenderTextControl.h 2011-07-13 04:05:51 UTC (rev 90884)
+++ trunk/Source/WebCore/rendering/RenderTextControl.h 2011-07-13 04:23:03 UTC (rev 90885)
@@ -27,9 +27,6 @@
namespace WebCore {
class HTMLTextFormControlElement;
-class VisibleSelection;
-class TextControlInnerElement;
-class TextControlInnerTextElement;
class RenderTextControl : public RenderBlock {
public:
@@ -46,7 +43,6 @@
String textWithHardLineBreaks();
VisiblePosition visiblePositionForIndex(int index) const;
- static int indexForVisiblePosition(HTMLElement*, const VisiblePosition&);
void updatePlaceholderVisibility(bool, bool);