Dispatch change and blur event for input type=text when window focus is changed

FocusController::dispatchEventsOnWindowAndFocusedNode now dispatches setFocus(false) when window loses focus and setFocus(true) when window focus is back. 

R=tkent, keishi1
BUG=102830
TEST=Window focus is lost and text is updated by user, dispatch both blur and change event

Review URL: https://codereview.chromium.org/205033004

git-svn-id: svn://svn.chromium.org/blink/trunk@170511 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4da6703f
Test when window out of focus, should dispatch both blur and change event
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS blurEventCounter is 0
PASS changeEventCounter is 0
PASS blurEventCounter is 1
PASS changeEventCounter is 1
PASS successfullyParsed is true
TEST COMPLETE
<html>
<head>
<script src = "../../../resources/js-test.js"> </script>
</head>
<body onload="runTest()">
<input type="text" id="text"/>
<script>
var blurEventCounter = 0;
var changeEventCounter = 0;
function runTest() {
description('Test when window out of focus, should dispatch both blur and change event');
var text = document.getElementById('text');
text.addEventListener('change', function() {
changeEventCounter++;
});
text.addEventListener('blur', function() {
blurEventCounter++;
shouldEvaluateTo('blurEventCounter', 1);
shouldEvaluateTo('changeEventCounter', 1);
finishJSTest();
});
text.focus();
document.execCommand('InsertText', false, 'hello world');
shouldEvaluateTo('blurEventCounter', 0);
shouldEvaluateTo('changeEventCounter', 0);
window.testRunner.setMainFrameIsFirstResponder(true);
window.testRunner.setWindowIsKey(false);
}
if (window.testRunner)
window.jsTestIsAsync = true;
</script>
</body>
</html>
......@@ -144,6 +144,7 @@ static inline void dispatchEventsOnWindowAndFocusedNode(Document* document, bool
if (!focused && document->focusedElement()) {
RefPtr<Element> focusedElement(document->focusedElement());
focusedElement->setFocus(false);
focusedElement->dispatchBlurEvent(0);
if (focusedElement == document->focusedElement()) {
focusedElement->dispatchFocusOutEvent(EventTypeNames::focusout, 0);
......@@ -156,6 +157,7 @@ static inline void dispatchEventsOnWindowAndFocusedNode(Document* document, bool
window->dispatchEvent(Event::create(focused ? EventTypeNames::focus : EventTypeNames::blur));
if (focused && document->focusedElement()) {
RefPtr<Element> focusedElement(document->focusedElement());
focusedElement->setFocus(true);
focusedElement->dispatchFocusEvent(0, FocusTypePage);
if (focusedElement == document->focusedElement()) {
document->focusedElement()->dispatchFocusInEvent(EventTypeNames::focusin, 0);
......
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