Commit 8e9caa38 authored by adele@apple.com's avatar adele@apple.com

WebCore:

2008-06-30  Adele Peterson  <adele@apple.com>

        Reviewed by Anders.

        Fix for <rdar://problem/5301322> REGRESSION: Select All selects the whole page when used in readonly textareas

        Test: editing/selection/select-all-textarea.html

        * dom/Node.cpp:
        (WebCore::Node::shadowAncestorNode): Break out code to find the root of the shadow tree into a new helper function.
        (WebCore::Node::shadowTreeRootNode): Added helper function.
        * dom/Node.h:
        * dom/Range.cpp: (WebCore::Range::shadowTreeRootNode): Added helper function.
        * dom/Range.h:
        * editing/Selection.cpp: (WebCore::Selection::shadowTreeRootNode): ditto.
        * editing/Selection.h:
        * editing/SelectionController.h: (WebCore::SelectionController::shadowTreeRootNode): ditto.
        * editing/SelectionController.cpp: (WebCore::SelectionController::selectAll):
        If the selection is in a shadow tree, only select the contents of that shadow tree, not the whole document.
        * page/Frame.cpp:
        (WebCore::Frame::findString): Use the new shadowTreeRootNode helper functions.
        (WebCore::Frame::markAllMatchesForText): ditto.

LayoutTests:

2008-06-30  Adele Peterson  <adele@apple.com>

        Reviewed by Anders.

        Test for <rdar://problem/5301322> REGRESSION: Select All selects the whole page when used in readonly textareas

        * editing/selection/select-all-textarea-expected.txt: Added.
        * editing/selection/select-all-textarea.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@34900 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7f0c186c
2008-06-30 Adele Peterson <adele@apple.com>
Reviewed by Anders.
Test for <rdar://problem/5301322> REGRESSION: Select All selects the whole page when used in readonly textareas
* editing/selection/select-all-textarea-expected.txt: Added.
* editing/selection/select-all-textarea.html: Added.
2008-06-30 chris fleizach <cfleizach@apple.com>
Reviewed by Beth Dakin
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of #text > DIV to 0 of #text > DIV toDOMRange:range from 0 of #text > DIV to 28 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
This tests that select all works in a readonly textarea, without selecting the surrounding text.
<html>
<head>
<script>
function test()
{
if (window.layoutTestController) {
layoutTestController.dumpAsText();
layoutTestController.dumpEditingCallbacks();
}
var ta = document.getElementById('ta');
ta.focus();
document.execCommand("SelectAll");
}
</script>
</head>
<body onload="test()">
This tests that select all works in a readonly textarea, without selecting the surrounding text.
<br>
<textarea id="ta" readonly>This text should be selected</textarea>
</body>
</html>
2008-06-30 Adele Peterson <adele@apple.com>
Reviewed by Anders.
Fix for <rdar://problem/5301322> REGRESSION: Select All selects the whole page when used in readonly textareas
Test: editing/selection/select-all-textarea.html
* dom/Node.cpp:
(WebCore::Node::shadowAncestorNode): Break out code to find the root of the shadow tree into a new helper function.
(WebCore::Node::shadowTreeRootNode): Added helper function.
* dom/Node.h:
* dom/Range.cpp: (WebCore::Range::shadowTreeRootNode): Added helper function.
* dom/Range.h:
* editing/Selection.cpp: (WebCore::Selection::shadowTreeRootNode): ditto.
* editing/Selection.h:
* editing/SelectionController.h: (WebCore::SelectionController::shadowTreeRootNode): ditto.
* editing/SelectionController.cpp: (WebCore::SelectionController::selectAll):
If the selection is in a shadow tree, only select the contents of that shadow tree, not the whole document.
* page/Frame.cpp:
(WebCore::Frame::findString): Use the new shadowTreeRootNode helper functions.
(WebCore::Frame::markAllMatchesForText): ditto.
2008-06-30 chris fleizach <cfleizach@apple.com>
Reviewed by Beth Dakin
......@@ -1094,15 +1094,23 @@ Node* Node::shadowAncestorNode()
return this;
#endif
Node *n = this;
while (n) {
if (n->isShadowNode())
return n->shadowParentNode();
n = n->parentNode();
}
Node* root = shadowTreeRootNode();
if (root)
return root->shadowParentNode();
return this;
}
Node* Node::shadowTreeRootNode()
{
Node *root = this;
while (root) {
if (root->isShadowNode())
return root;
root = root->parentNode();
}
return 0;
}
bool Node::isBlockFlow() const
{
return renderer() && renderer()->isBlockFlow();
......
......@@ -162,6 +162,7 @@ public:
virtual bool isShadowNode() const { return false; }
virtual Node* shadowParentNode() { return 0; }
Node* shadowAncestorNode();
Node* shadowTreeRootNode();
// The node's parent for the purpose of event capture and bubbling.
virtual Node* eventParentNode() { return parentNode(); }
......
......@@ -1571,6 +1571,11 @@ Position Range::editingStartPosition() const
return visiblePosition.deepEquivalent().downstream();
}
Node* Range::shadowTreeRootNode() const
{
return startContainer() ? startContainer()->shadowTreeRootNode() : 0;
}
Node* Range::pastLastNode() const
{
if (!m_start.container() || !m_end.container())
......
......@@ -99,6 +99,8 @@ public:
Position editingStartPosition() const;
Node* shadowTreeRootNode() const;
IntRect boundingBox();
void addLineBoxRects(Vector<IntRect>&, bool useSelectionHeight = false);
......
......@@ -519,6 +519,11 @@ Element* Selection::rootEditableElement() const
return editableRootForPosition(start());
}
Node* Selection::shadowTreeRootNode() const
{
return start().node() ? start().node()->shadowTreeRootNode() : 0;
}
void Selection::debugPosition() const
{
if (!m_start.node())
......
......@@ -85,7 +85,8 @@ public:
Element* rootEditableElement() const;
bool isContentEditable() const;
bool isContentRichlyEditable() const;
Node* shadowTreeRootNode() const;
void debugPosition() const;
#ifndef NDEBUG
......
......@@ -1017,7 +1017,14 @@ void SelectionController::selectAll()
return;
}
Node* root = isContentEditable() ? highestEditableRoot(m_sel.start()) : document->documentElement();
Node* root = 0;
if (isContentEditable())
root = highestEditableRoot(m_sel.start());
else {
root = shadowTreeRootNode();
if (!root)
root = document->documentElement();
}
if (!root)
return;
Selection newSelection(Selection::selectionFromContentsOfNode(root));
......
......@@ -48,7 +48,8 @@ public:
Element* rootEditableElement() const { return m_sel.rootEditableElement(); }
bool isContentEditable() const { return m_sel.isContentEditable(); }
bool isContentRichlyEditable() const { return m_sel.isContentRichlyEditable(); }
Node* shadowTreeRootNode() const { return m_sel.shadowTreeRootNode(); }
void moveTo(const Range*, EAffinity, bool userTriggered = false);
void moveTo(const VisiblePosition&, bool userTriggered = false);
void moveTo(const VisiblePosition&, const VisiblePosition&, bool userTriggered = false);
......
......@@ -1606,21 +1606,13 @@ bool Frame::findString(const String& target, bool forward, bool caseFlag, bool w
// is used depends on whether we're searching forward or backward, and whether startInSelection is set.
RefPtr<Range> searchRange(rangeOfContents(document()));
Selection selection = this->selection()->selection();
Node* selectionBaseNode = selection.base().node();
if (forward)
setStart(searchRange.get(), startInSelection ? selection.visibleStart() : selection.visibleEnd());
else
setEnd(searchRange.get(), startInSelection ? selection.visibleEnd() : selection.visibleStart());
bool selectionIsInMainContent = selectionBaseNode && !isInShadowTree(selectionBaseNode);
Node* shadowTreeRoot = 0;
if (!selectionIsInMainContent) {
shadowTreeRoot = selectionBaseNode;
while (shadowTreeRoot && !shadowTreeRoot->isShadowNode())
shadowTreeRoot = shadowTreeRoot->parentNode();
}
Node* shadowTreeRoot = selection.shadowTreeRootNode();
if (shadowTreeRoot) {
ExceptionCode ec = 0;
if (forward)
......@@ -1717,13 +1709,9 @@ unsigned Frame::markAllMatchesForText(const String& target, bool caseFlag, unsig
break;
setStart(searchRange.get(), newStart);
if (searchRange->collapsed(exception) && isInShadowTree(searchRange->startContainer())) {
Node* shadowTreeRoot = searchRange->startContainer();
while (shadowTreeRoot && !shadowTreeRoot->isShadowNode())
shadowTreeRoot = shadowTreeRoot->parentNode();
if (shadowTreeRoot)
searchRange->setEnd(shadowTreeRoot, shadowTreeRoot->childNodeCount(), exception);
}
Node* shadowTreeRoot = searchRange->shadowTreeRootNode();
if (searchRange->collapsed(exception) && shadowTreeRoot)
searchRange->setEnd(shadowTreeRoot, shadowTreeRoot->childNodeCount(), exception);
} while (true);
// Do a "fake" paint in order to execute the code that computes the rendered rect for
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment