Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: Source/core/dom/Document.cpp

Issue 26149002: Don't dispatch blur/focus events if the element's page is not focused. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Disallow focus event dispatch too. Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 #include "core/loader/FrameLoader.h" 138 #include "core/loader/FrameLoader.h"
139 #include "core/loader/FrameLoaderClient.h" 139 #include "core/loader/FrameLoaderClient.h"
140 #include "core/loader/ImageLoader.h" 140 #include "core/loader/ImageLoader.h"
141 #include "core/loader/appcache/ApplicationCacheHost.h" 141 #include "core/loader/appcache/ApplicationCacheHost.h"
142 #include "core/page/Chrome.h" 142 #include "core/page/Chrome.h"
143 #include "core/page/ChromeClient.h" 143 #include "core/page/ChromeClient.h"
144 #include "core/page/ContentSecurityPolicy.h" 144 #include "core/page/ContentSecurityPolicy.h"
145 #include "core/page/DOMSecurityPolicy.h" 145 #include "core/page/DOMSecurityPolicy.h"
146 #include "core/page/DOMWindow.h" 146 #include "core/page/DOMWindow.h"
147 #include "core/page/EventHandler.h" 147 #include "core/page/EventHandler.h"
148 #include "core/page/FocusController.h"
148 #include "core/page/Frame.h" 149 #include "core/page/Frame.h"
149 #include "core/page/FrameTree.h" 150 #include "core/page/FrameTree.h"
150 #include "core/page/FrameView.h" 151 #include "core/page/FrameView.h"
151 #include "core/page/History.h" 152 #include "core/page/History.h"
152 #include "core/page/MouseEventWithHitTestResults.h" 153 #include "core/page/MouseEventWithHitTestResults.h"
153 #include "core/page/Page.h" 154 #include "core/page/Page.h"
154 #include "core/page/PageConsole.h" 155 #include "core/page/PageConsole.h"
155 #include "core/page/PointerLockController.h" 156 #include "core/page/PointerLockController.h"
156 #include "core/page/Settings.h" 157 #include "core/page/Settings.h"
157 #include "core/page/animation/AnimationController.h" 158 #include "core/page/animation/AnimationController.h"
(...skipping 3141 matching lines...) Expand 10 before | Expand all | Expand 10 after
3299 if (oldFocusedElement->active()) 3300 if (oldFocusedElement->active())
3300 oldFocusedElement->setActive(false); 3301 oldFocusedElement->setActive(false);
3301 3302
3302 oldFocusedElement->setFocus(false); 3303 oldFocusedElement->setFocus(false);
3303 3304
3304 // Dispatch a change event for text fields or textareas that have been e dited 3305 // Dispatch a change event for text fields or textareas that have been e dited
3305 if (oldFocusedElement->wasChangedSinceLastFormControlChangeEvent()) 3306 if (oldFocusedElement->wasChangedSinceLastFormControlChangeEvent())
3306 oldFocusedElement->dispatchFormControlChangeEvent(); 3307 oldFocusedElement->dispatchFormControlChangeEvent();
3307 3308
3308 // Dispatch the blur event and let the node do any other blur related ac tivities (important for text fields) 3309 // Dispatch the blur event and let the node do any other blur related ac tivities (important for text fields)
3309 oldFocusedElement->dispatchBlurEvent(newFocusedElement.get()); 3310 // If old element's page is unfocused, blur event will have already been dispatched
3311 Page* oldPage = oldFocusedElement->document().page();
tkent 2013/10/08 08:41:43 page() is enough because oldFocusedElement belongs
3312 if (oldPage && oldPage->focusController().isFocused()) {
3313 oldFocusedElement->dispatchBlurEvent(newFocusedElement.get());
3310 3314
3311 if (m_focusedElement) { 3315 if (m_focusedElement) {
3312 // handler shifted focus 3316 // handler shifted focus
3313 focusChangeBlocked = true; 3317 focusChangeBlocked = true;
3314 newFocusedElement = 0; 3318 newFocusedElement = 0;
3315 } 3319 }
3316 3320
3317 oldFocusedElement->dispatchFocusOutEvent(eventNames().focusoutEvent, new FocusedElement.get()); // DOM level 3 name for the bubbling blur event. 3321 oldFocusedElement->dispatchFocusOutEvent(eventNames().focusoutEvent, newFocusedElement.get()); // DOM level 3 name for the bubbling blur event.
3318 // FIXME: We should remove firing DOMFocusOutEvent event when we are sur e no content depends 3322 // FIXME: We should remove firing DOMFocusOutEvent event when we are sure no content depends
3319 // on it, probably when <rdar://problem/8503958> is resolved. 3323 // on it, probably when <rdar://problem/8503958> is resolved.
3320 oldFocusedElement->dispatchFocusOutEvent(eventNames().DOMFocusOutEvent, newFocusedElement.get()); // DOM level 2 name for compatibility. 3324 oldFocusedElement->dispatchFocusOutEvent(eventNames().DOMFocusOutEve nt, newFocusedElement.get()); // DOM level 2 name for compatibility.
3321 3325
3322 if (m_focusedElement) { 3326 if (m_focusedElement) {
3323 // handler shifted focus 3327 // handler shifted focus
3324 focusChangeBlocked = true; 3328 focusChangeBlocked = true;
3325 newFocusedElement = 0; 3329 newFocusedElement = 0;
3330 }
3326 } 3331 }
3327 3332
3328 if (oldFocusedElement->isRootEditableElement()) 3333 if (oldFocusedElement->isRootEditableElement())
3329 frame()->editor().didEndEditing(); 3334 frame()->editor().didEndEditing();
3330 3335
3331 if (view()) { 3336 if (view()) {
3332 Widget* oldWidget = widgetForElement(oldFocusedElement.get()); 3337 Widget* oldWidget = widgetForElement(oldFocusedElement.get());
3333 if (oldWidget) 3338 if (oldWidget)
3334 oldWidget->setFocus(false); 3339 oldWidget->setFocus(false);
3335 else 3340 else
3336 view()->setFocus(false); 3341 view()->setFocus(false);
3337 } 3342 }
3338 3343
3339 // Autofill client may have modified the value of newFocusedElement, thu s require 3344 // Autofill client may have modified the value of newFocusedElement, thu s require
3340 // a layout update here, otherwise it will assert at newFocusedElement-> isFocusable(). 3345 // a layout update here, otherwise it will assert at newFocusedElement-> isFocusable().
3341 // See crbug.com/251163. 3346 // See crbug.com/251163.
3342 updateLayoutIgnorePendingStylesheets(); 3347 updateLayoutIgnorePendingStylesheets();
3343 } 3348 }
3344 3349
3345 if (newFocusedElement && newFocusedElement->isFocusable()) { 3350 if (newFocusedElement && newFocusedElement->isFocusable()) {
3346 if (newFocusedElement->isRootEditableElement() && !acceptsEditingFocus(n ewFocusedElement.get())) { 3351 if (newFocusedElement->isRootEditableElement() && !acceptsEditingFocus(n ewFocusedElement.get())) {
3347 // delegate blocks focus change 3352 // delegate blocks focus change
3348 focusChangeBlocked = true; 3353 focusChangeBlocked = true;
3349 goto SetFocusedElementDone; 3354 goto SetFocusedElementDone;
3350 } 3355 }
3351 // Set focus on the new node 3356 // Set focus on the new node
3352 m_focusedElement = newFocusedElement; 3357 m_focusedElement = newFocusedElement;
3353 3358
3354 // Dispatch the focus event and let the node do any other focus related activities (important for text fields) 3359 // Dispatch the focus event and let the node do any other focus related activities (important for text fields)
3355 m_focusedElement->dispatchFocusEvent(oldFocusedElement.get(), direction) ; 3360 // If page is unfocused, focus event will be dispatched on page focus, d on't duplicate
3361 if (!page() || page()->focusController().isFocused()) {
tkent 2013/10/08 08:41:43 !page() is inconsistent with the blur handling abo
3362 m_focusedElement->dispatchFocusEvent(oldFocusedElement.get(), direct ion);
3356 3363
3357 if (m_focusedElement != newFocusedElement) { 3364 if (m_focusedElement != newFocusedElement) {
3358 // handler shifted focus 3365 // handler shifted focus
3359 focusChangeBlocked = true; 3366 focusChangeBlocked = true;
3360 goto SetFocusedElementDone; 3367 goto SetFocusedElementDone;
3368 }
3369
3370 m_focusedElement->dispatchFocusInEvent(eventNames().focusinEvent, ol dFocusedElement.get()); // DOM level 3 bubbling focus event.
3371
3372 if (m_focusedElement != newFocusedElement) {
3373 // handler shifted focus
3374 focusChangeBlocked = true;
3375 goto SetFocusedElementDone;
3376 }
3377
3378 // FIXME: We should remove firing DOMFocusInEvent event when we are sure no content depends
3379 // on it, probably when <rdar://problem/8503958> is m.
3380 m_focusedElement->dispatchFocusInEvent(eventNames().DOMFocusInEvent, oldFocusedElement.get()); // DOM level 2 for compatibility.
3381
3382 if (m_focusedElement != newFocusedElement) {
3383 // handler shifted focus
3384 focusChangeBlocked = true;
3385 goto SetFocusedElementDone;
3386 }
3361 } 3387 }
3362 3388
3363 m_focusedElement->dispatchFocusInEvent(eventNames().focusinEvent, oldFoc usedElement.get()); // DOM level 3 bubbling focus event.
3364
3365 if (m_focusedElement != newFocusedElement) {
3366 // handler shifted focus
3367 focusChangeBlocked = true;
3368 goto SetFocusedElementDone;
3369 }
3370
3371 // FIXME: We should remove firing DOMFocusInEvent event when we are sure no content depends
3372 // on it, probably when <rdar://problem/8503958> is m.
3373 m_focusedElement->dispatchFocusInEvent(eventNames().DOMFocusInEvent, old FocusedElement.get()); // DOM level 2 for compatibility.
3374
3375 if (m_focusedElement != newFocusedElement) {
3376 // handler shifted focus
3377 focusChangeBlocked = true;
3378 goto SetFocusedElementDone;
3379 }
3380 m_focusedElement->setFocus(true); 3389 m_focusedElement->setFocus(true);
3381 3390
3382 if (m_focusedElement->isRootEditableElement()) 3391 if (m_focusedElement->isRootEditableElement())
3383 frame()->editor().didBeginEditing(m_focusedElement.get()); 3392 frame()->editor().didBeginEditing(m_focusedElement.get());
3384 3393
3385 // eww, I suck. set the qt focus correctly 3394 // eww, I suck. set the qt focus correctly
3386 // ### find a better place in the code for this 3395 // ### find a better place in the code for this
3387 if (view()) { 3396 if (view()) {
3388 Widget* focusWidget = widgetForElement(m_focusedElement.get()); 3397 Widget* focusWidget = widgetForElement(m_focusedElement.get());
3389 if (focusWidget) { 3398 if (focusWidget) {
(...skipping 1924 matching lines...) Expand 10 before | Expand all | Expand 10 after
5314 { 5323 {
5315 return DocumentLifecycleNotifier::create(this); 5324 return DocumentLifecycleNotifier::create(this);
5316 } 5325 }
5317 5326
5318 DocumentLifecycleNotifier* Document::lifecycleNotifier() 5327 DocumentLifecycleNotifier* Document::lifecycleNotifier()
5319 { 5328 {
5320 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier()); 5329 return static_cast<DocumentLifecycleNotifier*>(ScriptExecutionContext::lifec ycleNotifier());
5321 } 5330 }
5322 5331
5323 } // namespace WebCore 5332 } // namespace WebCore
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698