| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. |
| 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) | 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 2046 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2057 } | 2057 } |
| 2058 | 2058 |
| 2059 void EventHandler::notifyElementActivated() | 2059 void EventHandler::notifyElementActivated() |
| 2060 { | 2060 { |
| 2061 // Since another element has been set to active, stop current timer and clea
r reference. | 2061 // Since another element has been set to active, stop current timer and clea
r reference. |
| 2062 if (m_activeIntervalTimer.isActive()) | 2062 if (m_activeIntervalTimer.isActive()) |
| 2063 m_activeIntervalTimer.stop(); | 2063 m_activeIntervalTimer.stop(); |
| 2064 m_lastDeferredTapElement = nullptr; | 2064 m_lastDeferredTapElement = nullptr; |
| 2065 } | 2065 } |
| 2066 | 2066 |
| 2067 bool EventHandler::handleAccessKey(const PlatformKeyboardEvent& evt) | |
| 2068 { | |
| 2069 // FIXME: Ignoring the state of Shift key is what neither IE nor Firefox do. | |
| 2070 // IE matches lower and upper case access keys regardless of Shift key state
- but if both upper and | |
| 2071 // lower case variants are present in a document, the correct element is mat
ched based on Shift key state. | |
| 2072 // Firefox only matches an access key if Shift is not pressed, and does that
case-insensitively. | |
| 2073 ASSERT(!(accessKeyModifiers() & PlatformEvent::ShiftKey)); | |
| 2074 if ((evt.modifiers() & ~PlatformEvent::ShiftKey) != accessKeyModifiers()) | |
| 2075 return false; | |
| 2076 String key = evt.unmodifiedText(); | |
| 2077 Element* elem = m_frame->document()->getElementByAccessKey(key.lower()); | |
| 2078 if (!elem) | |
| 2079 return false; | |
| 2080 // FIXME(sky): We should probably pass SendMouseUpDownEvents here, not | |
| 2081 // firing mouseup and mousedown is IE legacy. | |
| 2082 elem->dispatchSimulatedClick(0, SendNoEvents); | |
| 2083 return true; | |
| 2084 } | |
| 2085 | |
| 2086 bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent) | 2067 bool EventHandler::keyEvent(const PlatformKeyboardEvent& initialKeyEvent) |
| 2087 { | 2068 { |
| 2088 RefPtr<FrameView> protector(m_frame->view()); | 2069 RefPtr<FrameView> protector(m_frame->view()); |
| 2089 | 2070 |
| 2090 if (initialKeyEvent.windowsVirtualKeyCode() == VK_CAPITAL) | 2071 if (initialKeyEvent.windowsVirtualKeyCode() == VK_CAPITAL) |
| 2091 capsLockStateMayHaveChanged(); | 2072 capsLockStateMayHaveChanged(); |
| 2092 | 2073 |
| 2093 // Check for cases where we are too early for events -- possible unmatched k
ey up | 2074 // Check for cases where we are too early for events -- possible unmatched k
ey up |
| 2094 // from pressing return in the location bar. | 2075 // from pressing return in the location bar. |
| 2095 RefPtr<Node> node = eventTargetNodeForDocument(m_frame->document()); | 2076 RefPtr<Node> node = eventTargetNodeForDocument(m_frame->document()); |
| 2096 if (!node) | 2077 if (!node) |
| 2097 return false; | 2078 return false; |
| 2098 | 2079 |
| 2099 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture); | 2080 UserGestureIndicator gestureIndicator(DefinitelyProcessingUserGesture); |
| 2100 | 2081 |
| 2101 // In IE, access keys are special, they are handled after default keydown pr
ocessing, but cannot be canceled - this is hard to match. | |
| 2102 // On Mac OS X, we process them before dispatching keydown, as the default k
eydown handler implements Emacs key bindings, which may conflict | |
| 2103 // with access keys. Then we dispatch keydown, but suppress its default hand
ling. | |
| 2104 // On Windows, WebKit explicitly calls handleAccessKey() instead of dispatch
ing a keypress event for WM_SYSCHAR messages. | |
| 2105 // Other platforms currently match either Mac or Windows behavior, depending
on whether they send combined KeyDown events. | |
| 2106 bool matchedAnAccessKey = false; | |
| 2107 if (initialKeyEvent.type() == PlatformEvent::KeyDown) | |
| 2108 matchedAnAccessKey = handleAccessKey(initialKeyEvent); | |
| 2109 | |
| 2110 // FIXME: it would be fair to let an input method handle KeyUp events before
DOM dispatch. | 2082 // FIXME: it would be fair to let an input method handle KeyUp events before
DOM dispatch. |
| 2111 if (initialKeyEvent.type() == PlatformEvent::KeyUp || initialKeyEvent.type()
== PlatformEvent::Char) | 2083 if (initialKeyEvent.type() == PlatformEvent::KeyUp || initialKeyEvent.type()
== PlatformEvent::Char) |
| 2112 return !node->dispatchKeyEvent(initialKeyEvent); | 2084 return !node->dispatchKeyEvent(initialKeyEvent); |
| 2113 | 2085 |
| 2114 PlatformKeyboardEvent keyDownEvent = initialKeyEvent; | 2086 PlatformKeyboardEvent keyDownEvent = initialKeyEvent; |
| 2115 if (keyDownEvent.type() != PlatformEvent::RawKeyDown) | 2087 if (keyDownEvent.type() != PlatformEvent::RawKeyDown) |
| 2116 keyDownEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown); | 2088 keyDownEvent.disambiguateKeyDownEvent(PlatformEvent::RawKeyDown); |
| 2117 RefPtr<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEvent, m_frame-
>document()->domWindow()); | 2089 RefPtr<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEvent, m_frame-
>document()->domWindow()); |
| 2118 if (matchedAnAccessKey) | 2090 |
| 2119 keydown->setDefaultPrevented(true); | |
| 2120 keydown->setTarget(node); | 2091 keydown->setTarget(node); |
| 2121 | 2092 |
| 2122 if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) { | 2093 if (initialKeyEvent.type() == PlatformEvent::RawKeyDown) { |
| 2123 node->dispatchEvent(keydown, IGNORE_EXCEPTION); | 2094 node->dispatchEvent(keydown, IGNORE_EXCEPTION); |
| 2124 // If frame changed as a result of keydown dispatch, then return true to
avoid sending a subsequent keypress message to the new frame. | 2095 // If frame changed as a result of keydown dispatch, then return true to
avoid sending a subsequent keypress message to the new frame. |
| 2125 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()
->focusController().focusedOrMainFrame(); | 2096 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()
->focusController().focusedOrMainFrame(); |
| 2126 return keydown->defaultHandled() || keydown->defaultPrevented() || chang
edFocusedFrame; | 2097 return keydown->defaultHandled() || keydown->defaultPrevented() || chang
edFocusedFrame; |
| 2127 } | 2098 } |
| 2128 | 2099 |
| 2129 node->dispatchEvent(keydown, IGNORE_EXCEPTION); | 2100 node->dispatchEvent(keydown, IGNORE_EXCEPTION); |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2601 } | 2572 } |
| 2602 | 2573 |
| 2603 void EventHandler::focusDocumentView() | 2574 void EventHandler::focusDocumentView() |
| 2604 { | 2575 { |
| 2605 Page* page = m_frame->page(); | 2576 Page* page = m_frame->page(); |
| 2606 if (!page) | 2577 if (!page) |
| 2607 return; | 2578 return; |
| 2608 page->focusController().focusDocumentView(m_frame); | 2579 page->focusController().focusDocumentView(m_frame); |
| 2609 } | 2580 } |
| 2610 | 2581 |
| 2611 unsigned EventHandler::accessKeyModifiers() | |
| 2612 { | |
| 2613 #if OS(MACOSX) | |
| 2614 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; | |
| 2615 #else | |
| 2616 return PlatformEvent::AltKey; | |
| 2617 #endif | |
| 2618 } | |
| 2619 | |
| 2620 } // namespace blink | 2582 } // namespace blink |
| OLD | NEW |