Diff
Modified: trunk/Source/WebCore/ChangeLog (90670 => 90671)
--- trunk/Source/WebCore/ChangeLog 2011-07-08 22:32:31 UTC (rev 90670)
+++ trunk/Source/WebCore/ChangeLog 2011-07-08 22:57:00 UTC (rev 90671)
@@ -1,3 +1,35 @@
+2011-07-08 Adam Barth <[email protected]>
+
+ Unreviewed, rolling out r90662.
+ http://trac.webkit.org/changeset/90662
+ https://bugs.webkit.org/show_bug.cgi?id=64210
+
+ Introduced regressions in Chromium browser tests (Requested by
+ rniwa on #webkit).
+
+ * accessibility/AccessibilityRenderObject.cpp:
+ (WebCore::AccessibilityRenderObject::selectedText):
+ (WebCore::AccessibilityRenderObject::selectedTextRange):
+ (WebCore::AccessibilityRenderObject::setSelectedTextRange):
+ * html/HTMLFormControlElement.cpp:
+ (WebCore::HTMLTextFormControlElement::setSelectionRange):
+ (WebCore::HTMLTextFormControlElement::selectionStart):
+ (WebCore::HTMLTextFormControlElement::selectionEnd):
+ (WebCore::HTMLTextFormControlElement::selection):
+ (WebCore::HTMLTextFormControlElement::restoreCachedSelection):
+ (WebCore::HTMLTextFormControlElement::selectionChanged):
+ * html/HTMLFormControlElement.h:
+ * html/HTMLInputElement.cpp:
+ (WebCore::HTMLInputElement::setValue):
+ * rendering/RenderTextControl.cpp:
+ (WebCore::RenderTextControl::selectionStart):
+ (WebCore::RenderTextControl::selectionEnd):
+ (WebCore::RenderTextControl::hasVisibleTextArea):
+ (WebCore::setSelectionRange):
+ (WebCore::setContainerAndOffsetForRange):
+ (WebCore::RenderTextControl::selection):
+ * rendering/RenderTextControl.h:
+
2011-07-08 Brian Salomon <[email protected]>
Make GL context current before updating layer texture using skia-gpu
Modified: trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp (90670 => 90671)
--- trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2011-07-08 22:32:31 UTC (rev 90670)
+++ trunk/Source/WebCore/accessibility/AccessibilityRenderObject.cpp 2011-07-08 22:57:00 UTC (rev 90671)
@@ -1994,8 +1994,8 @@
return String(); // need to return something distinct from empty string
if (isNativeTextControl()) {
- HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
- return textControl->selectedText();
+ RenderTextControl* textControl = toRenderTextControl(m_renderer);
+ return textControl->text().substring(textControl->selectionStart(), textControl->selectionEnd() - textControl->selectionStart());
}
if (ariaRoleAttribute() == UnknownRole)
@@ -2028,7 +2028,7 @@
AccessibilityRole ariaRole = ariaRoleAttribute();
if (isNativeTextControl() && ariaRole == UnknownRole) {
- HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
+ RenderTextControl* textControl = toRenderTextControl(m_renderer);
return PlainTextRange(textControl->selectionStart(), textControl->selectionEnd() - textControl->selectionStart());
}
@@ -2041,8 +2041,7 @@
void AccessibilityRenderObject::setSelectedTextRange(const PlainTextRange& range)
{
if (isNativeTextControl()) {
- HTMLTextFormControlElement* textControl = toRenderTextControl(m_renderer)->textFormControlElement();
- textControl->setSelectionRange(range.start, range.start + range.length);
+ setSelectionRange(m_renderer->node(), range.start, range.start + range.length);
return;
}
Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (90670 => 90671)
--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp 2011-07-08 22:32:31 UTC (rev 90670)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp 2011-07-08 22:57:00 UTC (rev 90671)
@@ -662,16 +662,6 @@
setSelectionRange(0, numeric_limits<int>::max());
}
-String HTMLTextFormControlElement::selectedText() const
-{
- // FIXME: We should be able to extract selected contents even if there were no renderer.
- if (!renderer() || renderer()->isTextControl())
- return String();
-
- RenderTextControl* textControl = toRenderTextControl(renderer());
- return textControl->text().substring(selectionStart(), selectionEnd() - selectionStart());
-}
-
void HTMLTextFormControlElement::dispatchFormControlChangeEvent()
{
if (m_textAsOfLastFormControlChangeEvent != value()) {
@@ -681,46 +671,9 @@
setChangedSinceLastFormControlChangeEvent(false);
}
-static inline bool hasVisibleTextArea(RenderTextControl* textControl)
-{
- ASSERT(textControl);
- HTMLElement* innerText = textControl->innerTextElement();
- return textControl->style()->visibility() != HIDDEN && innerText && innerText->renderer() && innerText->renderBox()->height();
-}
-
void HTMLTextFormControlElement::setSelectionRange(int start, int end)
{
- document()->updateLayoutIgnorePendingStylesheets();
-
- if (!renderer() || !renderer()->isTextControl())
- return;
-
- end = max(end, 0);
- start = min(max(start, 0), end);
-
- RenderTextControl* control = toRenderTextControl(renderer());
- if (!hasVisibleTextArea(control)) {
- cacheSelection(start, end);
- return;
- }
-
- VisiblePosition startPosition = control->visiblePositionForIndex(start);
- VisiblePosition endPosition;
- if (start == end)
- endPosition = startPosition;
- else
- endPosition = control->visiblePositionForIndex(end);
-
- // startPosition and endPosition can be null position for example when
- // "-webkit-user-select: none" style attribute is specified.
- if (startPosition.isNotNull() && endPosition.isNotNull()) {
- ASSERT(startPosition.deepEquivalent().deprecatedNode()->shadowAncestorNode() == this
- && endPosition.deepEquivalent().deprecatedNode()->shadowAncestorNode() == this);
- }
-
- VisibleSelection newSelection = VisibleSelection(startPosition, endPosition);
- if (Frame* frame = document()->frame())
- frame->selection()->setSelection(newSelection);
+ WebCore::setSelectionRange(this, start, end);
}
int HTMLTextFormControlElement::selectionStart() const
@@ -729,16 +682,9 @@
return 0;
if (document()->focusedNode() != this && hasCachedSelectionStart())
return m_cachedSelectionStart;
-
- Frame* frame = document()->frame();
- if (!renderer() || !frame)
+ if (!renderer())
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 toRenderTextControl(renderer())->selectionStart();
}
int HTMLTextFormControlElement::selectionEnd() const
@@ -747,68 +693,21 @@
return 0;
if (document()->focusedNode() != this && hasCachedSelectionEnd())
return m_cachedSelectionEnd;
-
- Frame* frame = document()->frame();
- if (!renderer() || !frame)
+ if (!renderer())
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()->end());
+ return toRenderTextControl(renderer())->selectionEnd();
}
-static inline void setContainerAndOffsetForRange(Node* node, int offset, Node*& containerNode, int& offsetInContainer)
-{
- if (node->isTextNode()) {
- containerNode = node;
- offsetInContainer = offset;
- } else {
- containerNode = node->parentNode();
- offsetInContainer = node->nodeIndex() + offset;
- }
-}
-
PassRefPtr<Range> HTMLTextFormControlElement::selection() const
{
if (!renderer() || !isTextFormControl() || !hasCachedSelectionStart() || !hasCachedSelectionEnd())
return 0;
-
- int start = m_cachedSelectionStart;
- int end = m_cachedSelectionEnd;
+ return toRenderTextControl(renderer())->selection(m_cachedSelectionStart, m_cachedSelectionEnd);
+}
- ASSERT(start <= end);
- HTMLElement* innerText = toRenderTextControl(renderer())->innerTextElement();
- if (!innerText)
- return 0;
-
- if (!innerText->firstChild())
- return Range::create(document(), innerText, 0, innerText, 0);
-
- int offset = 0;
- Node* startNode = 0;
- Node* endNode = 0;
- for (Node* node = innerText->firstChild(); node; node = node->traverseNextNode(innerText)) {
- ASSERT(!node->firstChild());
- ASSERT(node->isTextNode() || node->hasTagName(brTag));
- int length = node->isTextNode() ? lastOffsetInNode(node) : 1;
-
- if (offset <= start && start <= offset + length)
- setContainerAndOffsetForRange(node, start - offset, startNode, start);
-
- if (offset <= end && end <= offset + length) {
- setContainerAndOffsetForRange(node, end - offset, endNode, end);
- break;
- }
-
- offset += length;
- }
-
- if (!startNode || !endNode)
- return 0;
-
- return Range::create(document(), startNode, start, endNode, end);
+void HTMLTextFormControlElement::restoreCachedSelection()
+{
+ WebCore::setSelectionRange(this, m_cachedSelectionStart, m_cachedSelectionEnd);
}
void HTMLTextFormControlElement::selectionChanged(bool userTriggered)
@@ -816,7 +715,8 @@
if (!renderer() || !isTextFormControl())
return;
- cacheSelection(selectionStart(), selectionEnd());
+ RenderTextControl* renderTextControl = toRenderTextControl(renderer());
+ cacheSelection(renderTextControl->selectionStart(), renderTextControl->selectionEnd());
if (Frame* frame = document()->frame()) {
if (frame->selection()->isRange() && userTriggered)
Modified: trunk/Source/WebCore/html/HTMLFormControlElement.h (90670 => 90671)
--- trunk/Source/WebCore/html/HTMLFormControlElement.h 2011-07-08 22:32:31 UTC (rev 90670)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.h 2011-07-08 22:57:00 UTC (rev 90671)
@@ -207,7 +207,6 @@
void select();
void setSelectionRange(int start, int end);
PassRefPtr<Range> selection() const;
- String selectedText() const;
virtual void dispatchFormControlChangeEvent();
@@ -231,7 +230,7 @@
void setTextAsOfLastFormControlChangeEvent(const String& text) { m_textAsOfLastFormControlChangeEvent = text; }
- void restoreCachedSelection() { setSelectionRange(m_cachedSelectionStart, m_cachedSelectionEnd); }
+ void restoreCachedSelection();
bool hasCachedSelectionStart() const { return m_cachedSelectionStart >= 0; }
bool hasCachedSelectionEnd() const { return m_cachedSelectionEnd >= 0; }
Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (90670 => 90671)
--- trunk/Source/WebCore/html/HTMLInputElement.cpp 2011-07-08 22:32:31 UTC (rev 90670)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp 2011-07-08 22:57:00 UTC (rev 90671)
@@ -1016,7 +1016,7 @@
if (isTextField()) {
unsigned max = visibleValue().length();
if (document()->focusedNode() == this)
- setSelectionRange(max, max);
+ WebCore::setSelectionRange(this, max, max);
else
cacheSelection(max, max);
m_suggestedValue = String();
Modified: trunk/Source/WebCore/rendering/RenderTextControl.cpp (90670 => 90671)
--- trunk/Source/WebCore/rendering/RenderTextControl.cpp 2011-07-08 22:32:31 UTC (rev 90670)
+++ trunk/Source/WebCore/rendering/RenderTextControl.cpp 2011-07-08 22:57:00 UTC (rev 90671)
@@ -27,6 +27,7 @@
#include "Event.h"
#include "EventNames.h"
#include "Frame.h"
+#include "FrameSelection.h"
#include "HTMLBRElement.h"
#include "HTMLFormControlElement.h"
#include "HTMLInputElement.h"
@@ -81,11 +82,6 @@
{
}
-HTMLTextFormControlElement* RenderTextControl::textFormControlElement()
-{
- return static_cast<HTMLTextFormControlElement*>(node());
-}
-
void RenderTextControl::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
{
RenderBlock::styleDidChange(diff, oldStyle);
@@ -177,6 +173,73 @@
document()->setIgnoreAutofocus(lastChangeWasUserEdit);
}
+int RenderTextControl::selectionStart() const
+{
+ Frame* frame = this->frame();
+ if (!frame)
+ return 0;
+
+ HTMLElement* innerText = 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());
+}
+
+int RenderTextControl::selectionEnd() const
+{
+ Frame* frame = this->frame();
+ if (!frame)
+ return 0;
+
+ HTMLElement* innerText = 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());
+}
+
+bool RenderTextControl::hasVisibleTextArea() const
+{
+ HTMLElement* innerText = innerTextElement();
+ return style()->visibility() == HIDDEN || !innerText || !innerText->renderer() || !innerText->renderBox()->height();
+}
+
+void setSelectionRange(Node* node, int start, int end)
+{
+ ASSERT(node);
+ node->document()->updateLayoutIgnorePendingStylesheets();
+
+ if (!node->renderer() || !node->renderer()->isTextControl())
+ return;
+
+ end = max(end, 0);
+ start = min(max(start, 0), end);
+
+ RenderTextControl* control = toRenderTextControl(node->renderer());
+
+ if (control->hasVisibleTextArea()) {
+ static_cast<HTMLTextFormControlElement*>(node)->cacheSelection(start, end);
+ return;
+ }
+ VisiblePosition startPosition = control->visiblePositionForIndex(start);
+ VisiblePosition endPosition;
+ if (start == end)
+ endPosition = startPosition;
+ else
+ endPosition = control->visiblePositionForIndex(end);
+
+ // startPosition and endPosition can be null position for example when
+ // "-webkit-user-select: none" style attribute is specified.
+ if (startPosition.isNotNull() && endPosition.isNotNull()) {
+ ASSERT(startPosition.deepEquivalent().deprecatedNode()->shadowAncestorNode() == node && endPosition.deepEquivalent().deprecatedNode()->shadowAncestorNode() == node);
+ }
+ VisibleSelection newSelection = VisibleSelection(startPosition, endPosition);
+
+ if (Frame* frame = node->document()->frame())
+ frame->selection()->setSelection(newSelection);
+}
+
bool RenderTextControl::isSelectableElement(HTMLElement* innerText, Node* node)
{
if (!node || !innerText)
@@ -193,6 +256,52 @@
|| (shadowAncestor->hasTagName(inputTag) && static_cast<HTMLInputElement*>(shadowAncestor)->isTextField()));
}
+static inline void setContainerAndOffsetForRange(Node* node, int offset, Node*& containerNode, int& offsetInContainer)
+{
+ if (node->isTextNode()) {
+ containerNode = node;
+ offsetInContainer = offset;
+ } else {
+ containerNode = node->parentNode();
+ offsetInContainer = node->nodeIndex() + offset;
+ }
+}
+
+PassRefPtr<Range> RenderTextControl::selection(int start, int end) const
+{
+ ASSERT(start <= end);
+ HTMLElement* innerText = innerTextElement();
+ if (!innerText)
+ return 0;
+
+ if (!innerText->firstChild())
+ return Range::create(document(), innerText, 0, innerText, 0);
+
+ int offset = 0;
+ Node* startNode = 0;
+ Node* endNode = 0;
+ for (Node* node = innerText->firstChild(); node; node = node->traverseNextNode(innerText)) {
+ ASSERT(!node->firstChild());
+ ASSERT(node->isTextNode() || node->hasTagName(brTag));
+ int length = node->isTextNode() ? lastOffsetInNode(node) : 1;
+
+ if (offset <= start && start <= offset + length)
+ setContainerAndOffsetForRange(node, start - offset, startNode, start);
+
+ if (offset <= end && end <= offset + length) {
+ setContainerAndOffsetForRange(node, end - offset, endNode, end);
+ break;
+ }
+
+ offset += length;
+ }
+
+ if (!startNode || !endNode)
+ return 0;
+
+ return Range::create(document(), startNode, start, endNode, end);
+}
+
VisiblePosition RenderTextControl::visiblePositionForIndex(int index) const
{
if (index <= 0)
Modified: trunk/Source/WebCore/rendering/RenderTextControl.h (90670 => 90671)
--- trunk/Source/WebCore/rendering/RenderTextControl.h 2011-07-08 22:32:31 UTC (rev 90670)
+++ trunk/Source/WebCore/rendering/RenderTextControl.h 2011-07-08 22:57:00 UTC (rev 90671)
@@ -26,7 +26,6 @@
namespace WebCore {
-class HTMLTextFormControlElement;
class VisibleSelection;
class TextControlInnerElement;
class TextControlInnerTextElement;
@@ -35,13 +34,16 @@
public:
virtual ~RenderTextControl();
- HTMLTextFormControlElement* textFormControlElement();
virtual HTMLElement* innerTextElement() const = 0;
virtual PassRefPtr<RenderStyle> createInnerTextStyle(const RenderStyle* startStyle) const = 0;
bool lastChangeWasUserEdit() const { return m_lastChangeWasUserEdit; }
void setLastChangeWasUserEdit(bool lastChangeWasUserEdit);
+ int selectionStart() const;
+ int selectionEnd() const;
+ PassRefPtr<Range> selection(int start, int end) const;
+
virtual void subtreeHasChanged();
String text();
String textWithHardLineBreaks();
@@ -94,6 +96,7 @@
virtual bool requiresForcedStyleRecalcPropagation() const { return true; }
+ bool hasVisibleTextArea() const;
friend void setSelectionRange(Node*, int start, int end);
static bool isSelectableElement(HTMLElement*, Node*);
@@ -106,6 +109,8 @@
bool m_lastChangeWasUserEdit;
};
+void setSelectionRange(Node*, int start, int end);
+
inline RenderTextControl* toRenderTextControl(RenderObject* object)
{
ASSERT(!object || object->isTextControl());
Modified: trunk/Source/WebKit/qt/Api/qwebpage.cpp (90670 => 90671)
--- trunk/Source/WebKit/qt/Api/qwebpage.cpp 2011-07-08 22:32:31 UTC (rev 90670)
+++ trunk/Source/WebKit/qt/Api/qwebpage.cpp 2011-07-08 22:57:00 UTC (rev 90671)
@@ -1111,10 +1111,8 @@
case QInputMethodEvent::Selection: {
hasSelection = true;
// A selection in the inputMethodEvent is always reflected in the visible text
- if (node) {
- if (HTMLTextFormControlElement* textControl = toTextFormControl(node))
- textControl->setSelectionRange(qMin(a.start, (a.start + a.length)), qMax(a.start, (a.start + a.length)));
- }
+ if (node)
+ setSelectionRange(node, qMin(a.start, (a.start + a.length)), qMax(a.start, (a.start + a.length)));
if (!ev->preeditString().isEmpty())
editor->setComposition(ev->preeditString(), underlines, qMin(a.start, (a.start + a.length)), qMax(a.start, (a.start + a.length)));
@@ -1134,8 +1132,7 @@
if (node && ev->replacementLength() > 0) {
int cursorPos = frame->selection()->extent().offsetInContainerNode();
int start = cursorPos + ev->replacementStart();
- if (HTMLTextFormControlElement* textControl = toTextFormControl(node))
- textControl->setSelectionRange(start, start + ev->replacementLength());
+ setSelectionRange(node, start, start + ev->replacementLength());
// Commit regardless of whether commitString is empty, to get rid of selection.
editor->confirmComposition(ev->commitString());
} else if (!ev->commitString().isEmpty()) {
Modified: trunk/Source/WebKit/qt/ChangeLog (90670 => 90671)
--- trunk/Source/WebKit/qt/ChangeLog 2011-07-08 22:32:31 UTC (rev 90670)
+++ trunk/Source/WebKit/qt/ChangeLog 2011-07-08 22:57:00 UTC (rev 90671)
@@ -1,3 +1,15 @@
+2011-07-08 Adam Barth <[email protected]>
+
+ Unreviewed, rolling out r90662.
+ http://trac.webkit.org/changeset/90662
+ https://bugs.webkit.org/show_bug.cgi?id=64210
+
+ Introduced regressions in Chromium browser tests (Requested by
+ rniwa on #webkit).
+
+ * Api/qwebpage.cpp:
+ (QWebPagePrivate::inputMethodEvent):
+
2011-07-08 Ryosuke Niwa <[email protected]>
Move selection related code from RenderTextControl to HTMLTextFormControlElement