Chromium Code Reviews| Index: Source/core/dom/Document.cpp |
| diff --git a/Source/core/dom/Document.cpp b/Source/core/dom/Document.cpp |
| index be863c71004cf1fe959e28f95dff5876ceaecaaa..a7bf8f2dbd54e68a5025f3562c4fa746e30af7f6 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" |
| @@ -3306,23 +3307,27 @@ 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 |
| + Page* oldPage = oldFocusedElement->document().page(); |
|
tkent
2013/10/08 08:41:43
page() is enough because oldFocusedElement belongs
|
| + if (oldPage && oldPage->focusController().isFocused()) { |
| + 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()) |
| @@ -3352,31 +3357,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()) { |
|
tkent
2013/10/08 08:41:43
!page() is inconsistent with the blur handling abo
|
| + 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()) |