Chromium Code Reviews| Index: Source/core/dom/Document.cpp |
| diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp |
| index ca2a38eec1d370bf36a464a553084f8bf83a89f5..ce8c007c4f6ae795ba51bd33424a158b35ae5417 100644 |
| --- a/Source/core/dom/Document.cpp |
| +++ b/Source/core/dom/Document.cpp |
| @@ -145,6 +145,7 @@ |
| #include "core/page/DOMSecurityPolicy.h" |
| #include "core/page/DOMWindow.h" |
| #include "core/page/EventHandler.h" |
| +#include "core/page/FocusController.h" |
| #include "core/page/Frame.h" |
| #include "core/page/FrameTree.h" |
| #include "core/page/FrameView.h" |
| @@ -3304,23 +3305,26 @@ bool Document::setFocusedElement(PassRefPtr<Element> prpNewFocusedElement, Focus |
| oldFocusedElement->dispatchFormControlChangeEvent(); |
| // Dispatch the blur event and let the node do any other blur related activities (important for text fields) |
| - oldFocusedElement->dispatchBlurEvent(newFocusedElement.get()); |
| - |
| - if (m_focusedElement) { |
| - // handler shifted focus |
| - focusChangeBlocked = true; |
| - newFocusedElement = 0; |
| - } |
| + // If old element's page is unfocused, blur event will have already been dispatched |
| + if (page() && page()->focusController().isFocused()) { |
|
tkent
2013/10/08 22:47:20
I remembered no elements could be focusable if a d
|
| + oldFocusedElement->dispatchBlurEvent(newFocusedElement.get()); |
| + |
| + if (m_focusedElement) { |
| + // handler shifted focus |
| + focusChangeBlocked = true; |
| + newFocusedElement = 0; |
| + } |
| - oldFocusedElement->dispatchFocusOutEvent(eventNames().focusoutEvent, newFocusedElement.get()); // DOM level 3 name for the bubbling blur event. |
| - // FIXME: We should remove firing DOMFocusOutEvent event when we are sure no content depends |
| - // on it, probably when <rdar://problem/8503958> is resolved. |
| - oldFocusedElement->dispatchFocusOutEvent(eventNames().DOMFocusOutEvent, newFocusedElement.get()); // DOM level 2 name for compatibility. |
| + oldFocusedElement->dispatchFocusOutEvent(eventNames().focusoutEvent, newFocusedElement.get()); // DOM level 3 name for the bubbling blur event. |
| + // FIXME: We should remove firing DOMFocusOutEvent event when we are sure no content depends |
| + // on it, probably when <rdar://problem/8503958> is resolved. |
| + oldFocusedElement->dispatchFocusOutEvent(eventNames().DOMFocusOutEvent, newFocusedElement.get()); // DOM level 2 name for compatibility. |
| - if (m_focusedElement) { |
| - // handler shifted focus |
| - focusChangeBlocked = true; |
| - newFocusedElement = 0; |
| + if (m_focusedElement) { |
| + // handler shifted focus |
| + focusChangeBlocked = true; |
| + newFocusedElement = 0; |
| + } |
| } |
| if (oldFocusedElement->isRootEditableElement()) |
| @@ -3350,31 +3354,35 @@ bool Document::setFocusedElement(PassRefPtr<Element> prpNewFocusedElement, Focus |
| m_focusedElement = newFocusedElement; |
| // Dispatch the focus event and let the node do any other focus related activities (important for text fields) |
| - m_focusedElement->dispatchFocusEvent(oldFocusedElement.get(), direction); |
| - |
| - if (m_focusedElement != newFocusedElement) { |
| - // handler shifted focus |
| - focusChangeBlocked = true; |
| - goto SetFocusedElementDone; |
| - } |
| + // If page is unfocused, focus event will be dispatched on page focus, don't duplicate |
| + if (page() && page()->focusController().isFocused()) { |
| + m_focusedElement->dispatchFocusEvent(oldFocusedElement.get(), direction); |
| + |
| + if (m_focusedElement != newFocusedElement) { |
| + // handler shifted focus |
| + focusChangeBlocked = true; |
| + goto SetFocusedElementDone; |
| + } |
| - m_focusedElement->dispatchFocusInEvent(eventNames().focusinEvent, oldFocusedElement.get()); // DOM level 3 bubbling focus event. |
| + m_focusedElement->dispatchFocusInEvent(eventNames().focusinEvent, oldFocusedElement.get()); // DOM level 3 bubbling focus event. |
| - if (m_focusedElement != newFocusedElement) { |
| - // handler shifted focus |
| - focusChangeBlocked = true; |
| - goto SetFocusedElementDone; |
| - } |
| + if (m_focusedElement != newFocusedElement) { |
| + // handler shifted focus |
| + focusChangeBlocked = true; |
| + goto SetFocusedElementDone; |
| + } |
| - // FIXME: We should remove firing DOMFocusInEvent event when we are sure no content depends |
| - // on it, probably when <rdar://problem/8503958> is m. |
| - m_focusedElement->dispatchFocusInEvent(eventNames().DOMFocusInEvent, oldFocusedElement.get()); // DOM level 2 for compatibility. |
| + // FIXME: We should remove firing DOMFocusInEvent event when we are sure no content depends |
| + // on it, probably when <rdar://problem/8503958> is m. |
| + m_focusedElement->dispatchFocusInEvent(eventNames().DOMFocusInEvent, oldFocusedElement.get()); // DOM level 2 for compatibility. |
| - if (m_focusedElement != newFocusedElement) { |
| - // handler shifted focus |
| - focusChangeBlocked = true; |
| - goto SetFocusedElementDone; |
| + if (m_focusedElement != newFocusedElement) { |
| + // handler shifted focus |
| + focusChangeBlocked = true; |
| + goto SetFocusedElementDone; |
| + } |
| } |
| + |
| m_focusedElement->setFocus(true); |
| if (m_focusedElement->isRootEditableElement()) |