OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 2144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2155 PlatformKeyboardEvent keyDownEvent = initialKeyEvent; | 2155 PlatformKeyboardEvent keyDownEvent = initialKeyEvent; |
2156 if (keyDownEvent.type() != PlatformKeyboardEvent::RawKeyDown) | 2156 if (keyDownEvent.type() != PlatformKeyboardEvent::RawKeyDown) |
2157 keyDownEvent.disambiguateKeyDownEvent(PlatformKeyboardEvent::RawKeyDown,
backwardCompatibilityMode); | 2157 keyDownEvent.disambiguateKeyDownEvent(PlatformKeyboardEvent::RawKeyDown,
backwardCompatibilityMode); |
2158 RefPtr<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEvent, m_frame-
>document()->defaultView()); | 2158 RefPtr<KeyboardEvent> keydown = KeyboardEvent::create(keyDownEvent, m_frame-
>document()->defaultView()); |
2159 if (matchedAnAccessKey) | 2159 if (matchedAnAccessKey) |
2160 keydown->setDefaultPrevented(true); | 2160 keydown->setDefaultPrevented(true); |
2161 keydown->setTarget(node); | 2161 keydown->setTarget(node); |
2162 | 2162 |
2163 if (initialKeyEvent.type() == PlatformKeyboardEvent::RawKeyDown) { | 2163 if (initialKeyEvent.type() == PlatformKeyboardEvent::RawKeyDown) { |
2164 node->dispatchEvent(keydown, ec); | 2164 node->dispatchEvent(keydown, ec); |
2165 return keydown->defaultHandled() || keydown->defaultPrevented(); | 2165 // If frame changed as a result of keydown dispatch, then return true to
avoid sending a subsequent keypress message to the new frame. |
| 2166 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()
->focusController()->focusedOrMainFrame(); |
| 2167 return keydown->defaultHandled() || keydown->defaultPrevented() || chang
edFocusedFrame; |
2166 } | 2168 } |
2167 | 2169 |
2168 // Run input method in advance of DOM event handling. This may result in th
e IM | 2170 // Run input method in advance of DOM event handling. This may result in th
e IM |
2169 // modifying the page prior the keydown event, but this behaviour is necessa
ry | 2171 // modifying the page prior the keydown event, but this behaviour is necessa
ry |
2170 // in order to match IE: | 2172 // in order to match IE: |
2171 // 1. preventing default handling of keydown and keypress events has no effe
ct on IM input; | 2173 // 1. preventing default handling of keydown and keypress events has no effe
ct on IM input; |
2172 // 2. if an input method handles the event, its keyCode is set to 229 in key
down event. | 2174 // 2. if an input method handles the event, its keyCode is set to 229 in key
down event. |
2173 m_frame->editor()->handleInputMethodKeydown(keydown.get()); | 2175 m_frame->editor()->handleInputMethodKeydown(keydown.get()); |
2174 | 2176 |
2175 bool handledByInputMethod = keydown->defaultHandled(); | 2177 bool handledByInputMethod = keydown->defaultHandled(); |
2176 | 2178 |
2177 if (handledByInputMethod) { | 2179 if (handledByInputMethod) { |
2178 keyDownEvent.setWindowsVirtualKeyCode(CompositionEventKeyCode); | 2180 keyDownEvent.setWindowsVirtualKeyCode(CompositionEventKeyCode); |
2179 keydown = KeyboardEvent::create(keyDownEvent, m_frame->document()->defau
ltView()); | 2181 keydown = KeyboardEvent::create(keyDownEvent, m_frame->document()->defau
ltView()); |
2180 keydown->setTarget(node); | 2182 keydown->setTarget(node); |
2181 keydown->setDefaultHandled(); | 2183 keydown->setDefaultHandled(); |
2182 } | 2184 } |
2183 | 2185 |
2184 node->dispatchEvent(keydown, ec); | 2186 node->dispatchEvent(keydown, ec); |
2185 bool keydownResult = keydown->defaultHandled() || keydown->defaultPrevented(
); | 2187 // If frame changed as a result of keydown dispatch, then return early to av
oid sending a subsequent keypress message to the new frame. |
| 2188 bool changedFocusedFrame = m_frame->page() && m_frame != m_frame->page()->fo
cusController()->focusedOrMainFrame(); |
| 2189 bool keydownResult = keydown->defaultHandled() || keydown->defaultPrevented(
) || changedFocusedFrame; |
2186 if (handledByInputMethod || (keydownResult && !backwardCompatibilityMode)) | 2190 if (handledByInputMethod || (keydownResult && !backwardCompatibilityMode)) |
2187 return keydownResult; | 2191 return keydownResult; |
2188 | 2192 |
2189 // Focus may have changed during keydown handling, so refetch node. | 2193 // Focus may have changed during keydown handling, so refetch node. |
2190 // But if we are dispatching a fake backward compatibility keypress, then we
pretend that the keypress happened on the original node. | 2194 // But if we are dispatching a fake backward compatibility keypress, then we
pretend that the keypress happened on the original node. |
2191 if (!keydownResult) { | 2195 if (!keydownResult) { |
2192 node = eventTargetNodeForDocument(m_frame->document()); | 2196 node = eventTargetNodeForDocument(m_frame->document()); |
2193 if (!node) | 2197 if (!node) |
2194 return false; | 2198 return false; |
2195 } | 2199 } |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2838 ExceptionCode ec = 0; | 2842 ExceptionCode ec = 0; |
2839 touchEventTarget->dispatchEvent(moveEv.get(), ec); | 2843 touchEventTarget->dispatchEvent(moveEv.get(), ec); |
2840 defaultPrevented |= moveEv->defaultPrevented(); | 2844 defaultPrevented |= moveEv->defaultPrevented(); |
2841 } | 2845 } |
2842 | 2846 |
2843 return defaultPrevented; | 2847 return defaultPrevented; |
2844 } | 2848 } |
2845 #endif | 2849 #endif |
2846 | 2850 |
2847 } | 2851 } |
OLD | NEW |