Commit 00b7e557 authored by justing's avatar justing
Browse files

LayoutTests:

        Reviewed by oliver

        <rdar://problem/5213963> 
        REGRESSION(r21467): Active selection remains in text field after clicking on a button

        Demonstrates bug:
        * editing/selection/5213963-expected.checksum: Added.
        * editing/selection/5213963-expected.png: Added.
        * editing/selection/5213963-expected.txt: Added.
        * editing/selection/5213963.html: Added.
        We now clear the selection on mouse down (but not before
        the mousedown event is fired):
        * fast/forms/focus-selection-input-expected.txt:
        * fast/forms/focus-selection-textarea-expected.txt:

WebCore:

        Reviewed by oliver

        <rdar://problem/5213963>
        REGRESSION(r21467): Active selection remains in text field after clicking on a button

        * page/EventHandler.cpp:
        (WebCore::EventHandler::dispatchMouseEvent): Call
        FocusController::setFocusedNode, because Document::setFocusedNode
        no longer clears the selection.
        Begin passing the new focused frame to 
        FocusController::setFocusedNode, because when the 
        new focus node is null, the selection should only be 
        cleared if the focused frame isn't changing.
        (WebCore::Element::focus): Begin passing the new focused
        frame.
        (WebCore::Element::blur): Ditto.
        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::focus): Ditto.
        * html/HTMLTextAreaElement.cpp:
        (WebCore::HTMLTextAreaElement::focus): Ditto.
        * page/Frame.cpp:
        (WebCore::Frame::setFocusedNodeIfNeeded): Ditto.
        * page/FocusController.cpp:
        (WebCore::clearSelectionIfNeeded): Take in the new
        focused frame.  If it's not changing, don't clear the
        selection.
        (WebCore::FocusController::setFocusedNode): Take
        in the new focused frame.
        * page/FocusController.h:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@21642 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent cc652ea3
2007-05-22 Justin Garcia <justin.garcia@apple.com>
Reviewed by oliver
<rdar://problem/5213963>
REGRESSION(r21467): Active selection remains in text field after clicking on a button
Demonstrates bug:
* editing/selection/5213963-expected.checksum: Added.
* editing/selection/5213963-expected.png: Added.
* editing/selection/5213963-expected.txt: Added.
* editing/selection/5213963.html: Added.
We now clear the selection on mouse down (but not before
the mousedown event is fired):
* fast/forms/focus-selection-input-expected.txt:
* fast/forms/focus-selection-textarea-expected.txt:
2007-05-21 Oliver Hunt <oliver@apple.com>
 
Reviewed by Sam.
ec9d3b0a77c7c0d1988746b932225ebb
\ No newline at end of file
layer at (0,0) size 800x600
RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x576
RenderBlock {P} at (0,0) size 784x18
RenderText {#text} at (0,0) size 759x18
text run at (0,0) width 759: "This tests to see that a selection inside an input field is removed when clicking (and focusing) a button in the same frame."
RenderBlock (anonymous) at (0,34) size 784x45
RenderTextControl {INPUT} at (2,2) size 426x19 [bgcolor=#FFFFFF] [border: (2px inset #000000)]
RenderBR {BR} at (430,16) size 0x0
RenderButton {INPUT} at (2,25) size 62x18 [bgcolor=#C0C0C0]
RenderBlock (anonymous) at (8,2) size 46x13
RenderText at (0,0) size 46x13
text run at (0,0) width 46: "Click Me"
RenderBR {BR} at (66,38) size 0x0
RenderBlock {UL} at (0,95) size 784x0
layer at (13,47) size 420x13
RenderBlock {DIV} at (3,3) size 420x13
RenderText {#text} at (1,0) size 372x13
text run at (1,0) width 372: "After you click the button below, this content should not be selected."
<p>This tests to see that a selection inside an input field is removed when clicking (and focusing) a button in the same frame.</p>
<input id="input" type="text" value="After you click the button below, this content should not be selected." size="60"><br>
<input id="button" type="button" value="Click Me"><br>
<ul id="console"></ul>
<script>
function log(msg) {
console = document.getElementById("console");
li = document.createElement("li");
text = document.createTextNode(msg);
console.appendChild(li);
li.appendChild(text);
}
var input = document.getElementById("input");
input.focus();
input.setSelectionRange(0, input.value.length);
if (window.layoutTestController) {
if (window.getSelection().type == "None")
log("Failure: There was no selection inside the input field when the test began.")
var button = document.getElementById("button");
var x = button.offsetParent.offsetLeft + button.offsetLeft + button.offsetWidth / 2;
var y = button.offsetParent.offsetTop + button.offsetTop + button.offsetHeight / 2;
eventSender.mouseMoveTo(x, y);
eventSender.mouseDown();
eventSender.mouseUp();
if (window.getSelection().type != "None")
log("Failure: There was still a selection after clicking a button.")
}
</script>
\ No newline at end of file
......@@ -6,7 +6,8 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > DIV to 0 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of #text > DIV to 0 of #text > DIV toDOMRange:range from 0 of #text > LABEL > BODY > HTML > #document to 5 of #text > LABEL > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > LABEL > BODY > HTML > #document to 5 of #text > LABEL > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
......
......@@ -6,7 +6,8 @@ EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotificatio
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > DIV to 0 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of #text > DIV to 0 of #text > DIV toDOMRange:range from 0 of #text > LABEL > BODY > HTML > #document to 5 of #text > LABEL > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: shouldChangeSelectedDOMRange:(null) toDOMRange:range from 0 of #text > LABEL > BODY > HTML > #document to 5 of #text > LABEL > BODY > HTML > #document affinity:NSSelectionAffinityDownstream stillSelecting:FALSE
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification
......
2007-05-22 Justin Garcia <justin.garcia@apple.com>
Reviewed by oliver
<rdar://problem/5213963>
REGRESSION(r21467): Active selection remains in text field after clicking on a button
* page/EventHandler.cpp:
(WebCore::EventHandler::dispatchMouseEvent): Call
FocusController::setFocusedNode, because Document::setFocusedNode
no longer clears the selection.
Begin passing the new focused frame to
FocusController::setFocusedNode, because when the
new focus node is null, the selection should only be
cleared if the focused frame isn't changing.
(WebCore::Element::focus): Begin passing the new focused
frame.
(WebCore::Element::blur): Ditto.
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::focus): Ditto.
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::focus): Ditto.
* page/Frame.cpp:
(WebCore::Frame::setFocusedNodeIfNeeded): Ditto.
* page/FocusController.cpp:
(WebCore::clearSelectionIfNeeded): Take in the new
focused frame. If it's not changing, don't clear the
selection.
(WebCore::FocusController::setFocusedNode): Take
in the new focused frame.
* page/FocusController.h:
2007-05-22 Marius Bugge Monsen <mbm@trolltech.com>
 
Reviewed by Zack.
......@@ -971,7 +971,7 @@ void Element::focus(bool restorePreviousSelection)
return;
if (Page* page = doc->page())
page->focusController()->setFocusedNode(this);
page->focusController()->setFocusedNode(this, doc->frame());
if (!isFocusable()) {
setNeedsFocusAppearanceUpdate(true);
......@@ -1014,7 +1014,7 @@ void Element::blur()
Document* doc = document();
if (doc->focusedNode() == this) {
if (doc->frame())
doc->frame()->page()->focusController()->setFocusedNode(0);
doc->frame()->page()->focusController()->setFocusedNode(0, doc->frame());
else
doc->setFocusedNode(0);
}
......
......@@ -195,7 +195,7 @@ void HTMLInputElement::focus(bool restorePreviousSelection)
if (!supportsFocus())
return;
if (Page* page = doc->page())
page->focusController()->setFocusedNode(this);
page->focusController()->setFocusedNode(this, doc->frame());
// FIXME: Should isFocusable do the updateLayout?
if (!isFocusable()) {
setNeedsFocusAppearanceUpdate(true);
......
......@@ -209,7 +209,7 @@ void HTMLTextAreaElement::focus(bool)
if (!supportsFocus())
return;
if (Page* page = doc->page())
page->focusController()->setFocusedNode(this);
page->focusController()->setFocusedNode(this, doc->frame());
// FIXME: Should isFocusable do the updateLayout?
if (!isFocusable()) {
setNeedsFocusAppearanceUpdate(true);
......
......@@ -1187,10 +1187,10 @@ bool EventHandler::dispatchMouseEvent(const AtomicString& eventType, Node* targe
// If focus shift is blocked, we eat the event. Note we should never clear swallowEvent
// if the page already set it (e.g., by canceling default behavior).
if (node && node->isMouseFocusable()) {
if (!m_frame->page()->focusController()->setFocusedNode(node))
if (!m_frame->page()->focusController()->setFocusedNode(node, m_frame))
swallowEvent = true;
} else if (!node || !node->focused()) {
if (!m_frame->document()->setFocusedNode(0))
if (!m_frame->page()->focusController()->setFocusedNode(0, m_frame))
swallowEvent = true;
}
}
......
......@@ -220,12 +220,12 @@ static bool relinquishesEditingFocus(Node *node)
return frame->editor()->shouldEndEditing(rangeOfContents(root).get());
}
static void clearSelectionIfNeeded(Frame* oldFocusedFrame, Node* newFocusedNode)
static void clearSelectionIfNeeded(Frame* oldFocusedFrame, Frame* newFocusedFrame, Node* newFocusedNode)
{
if (!oldFocusedFrame)
if (!oldFocusedFrame || !newFocusedFrame)
return;
if (newFocusedNode && oldFocusedFrame->document() != newFocusedNode->document())
if (oldFocusedFrame->document() != newFocusedFrame->document())
return;
SelectionController* s = oldFocusedFrame->selectionController();
......@@ -239,7 +239,7 @@ static void clearSelectionIfNeeded(Frame* oldFocusedFrame, Node* newFocusedNode)
s->clear();
}
bool FocusController::setFocusedNode(Node* node)
bool FocusController::setFocusedNode(Node* node, PassRefPtr<Frame> newFocusedFrame)
{
RefPtr<Frame> oldFocusedFrame = focusedFrame();
RefPtr<Document> oldDocument = oldFocusedFrame ? oldFocusedFrame->document() : 0;
......@@ -251,7 +251,7 @@ bool FocusController::setFocusedNode(Node* node)
if (oldFocusedNode && oldFocusedNode->rootEditableElement() == oldFocusedNode && !relinquishesEditingFocus(oldFocusedNode))
return false;
clearSelectionIfNeeded(oldFocusedFrame.get(), node);
clearSelectionIfNeeded(oldFocusedFrame.get(), newFocusedFrame.get(), node);
if (!node) {
if (oldDocument)
......@@ -260,7 +260,6 @@ bool FocusController::setFocusedNode(Node* node)
}
RefPtr<Document> newDocument = node ? node->document() : 0;
RefPtr<Frame> newFocusedFrame = newDocument ? newDocument->frame() : 0;
if (newDocument && newDocument->focusedNode() == node)
return true;
......
......@@ -48,7 +48,7 @@ namespace WebCore {
bool advanceFocus(KeyboardEvent*);
bool advanceFocus(FocusDirection, KeyboardEvent*);
bool setFocusedNode(Node*);
bool setFocusedNode(Node*, PassRefPtr<Frame>);
private:
Page* m_page;
......
......@@ -569,7 +569,7 @@ void Frame::setFocusedNodeIfNeeded()
// so add the !isFrameElement check here. There's probably a better way to make this
// work in the long term, but this is the safest fix at this time.
if (target && target->isMouseFocusable() && !isFrameElement(target)) {
page()->focusController()->setFocusedNode(target);
page()->focusController()->setFocusedNode(target, this);
return;
}
renderer = renderer->parent();
......
Supports Markdown
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