diff options
Diffstat (limited to 'src/3rdparty/webkit/WebCore/page/FocusController.cpp')
-rw-r--r-- | src/3rdparty/webkit/WebCore/page/FocusController.cpp | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/3rdparty/webkit/WebCore/page/FocusController.cpp b/src/3rdparty/webkit/WebCore/page/FocusController.cpp index 8dad84650d..817801c27c 100644 --- a/src/3rdparty/webkit/WebCore/page/FocusController.cpp +++ b/src/3rdparty/webkit/WebCore/page/FocusController.cpp @@ -58,6 +58,7 @@ using namespace HTMLNames; FocusController::FocusController(Page* page) : m_page(page) , m_isActive(false) + , m_isFocused(false) { } @@ -66,16 +67,20 @@ void FocusController::setFocusedFrame(PassRefPtr<Frame> frame) if (m_focusedFrame == frame) return; - if (m_focusedFrame && m_focusedFrame->view()) { - m_focusedFrame->selection()->setFocused(false); - m_focusedFrame->document()->dispatchWindowEvent(eventNames().blurEvent, false, false); - } + RefPtr<Frame> oldFrame = m_focusedFrame; + RefPtr<Frame> newFrame = frame; - m_focusedFrame = frame; + m_focusedFrame = newFrame; - if (m_focusedFrame && m_focusedFrame->view()) { - m_focusedFrame->selection()->setFocused(true); - m_focusedFrame->document()->dispatchWindowEvent(eventNames().focusEvent, false, false); + // Now that the frame is updated, fire events and update the selection focused states of both frames. + if (oldFrame && oldFrame->view()) { + oldFrame->selection()->setFocused(false); + oldFrame->document()->dispatchWindowEvent(eventNames().blurEvent, false, false); + } + + if (newFrame && newFrame->view() && isFocused()) { + newFrame->selection()->setFocused(true); + newFrame->document()->dispatchWindowEvent(eventNames().focusEvent, false, false); } } @@ -86,6 +91,19 @@ Frame* FocusController::focusedOrMainFrame() return m_page->mainFrame(); } +void FocusController::setFocused(bool focused) +{ + if (isFocused() == focused) + return; + + m_isFocused = focused; + + if (m_focusedFrame && m_focusedFrame->view()) { + m_focusedFrame->selection()->setFocused(focused); + m_focusedFrame->document()->dispatchWindowEvent(focused ? eventNames().focusEvent : eventNames().blurEvent, false, false); + } +} + static Node* deepFocusableNode(FocusDirection direction, Node* node, KeyboardEvent* event) { // The node we found might be a HTMLFrameOwnerElement, so descend down the frame tree until we find either: @@ -322,7 +340,7 @@ void FocusController::setActive(bool active) focusedOrMainFrame()->selection()->pageActivationChanged(); - if (m_focusedFrame) + if (m_focusedFrame && isFocused()) m_focusedFrame->document()->dispatchWindowEvent(active ? eventNames().focusEvent : eventNames().blurEvent, false, false); } |