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 1925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1936 // Only change the focus when clicking scrollbars if it can transfered to a | 1936 // Only change the focus when clicking scrollbars if it can transfered to a |
1937 // mouse focusable node. | 1937 // mouse focusable node. |
1938 if (!element && targetedEvent.hitTestResult().scrollbar()) | 1938 if (!element && targetedEvent.hitTestResult().scrollbar()) |
1939 return true; | 1939 return true; |
1940 | 1940 |
1941 if (Page* page = m_frame->page()) { | 1941 if (Page* page = m_frame->page()) { |
1942 // If focus shift is blocked, we eat the event. Note we should never | 1942 // If focus shift is blocked, we eat the event. Note we should never |
1943 // clear swallowEvent if the page already set it (e.g., by canceling | 1943 // clear swallowEvent if the page already set it (e.g., by canceling |
1944 // default behavior). | 1944 // default behavior). |
1945 if (element) { | 1945 if (element) { |
1946 if (!page->focusController().setFocusedElement(element, m_frame, Foc
usTypeMouse)) | 1946 if (!page->focusController().setFocusedElement(element, m_frame, Web
FocusTypeMouse)) |
1947 return true; | 1947 return true; |
1948 } else { | 1948 } else { |
1949 // We call setFocusedElement even with !element in order to blur | 1949 // We call setFocusedElement even with !element in order to blur |
1950 // current focus element when a link is clicked; this is expected by | 1950 // current focus element when a link is clicked; this is expected by |
1951 // some sites that rely on onChange handlers running from form | 1951 // some sites that rely on onChange handlers running from form |
1952 // fields before the button click is processed. | 1952 // fields before the button click is processed. |
1953 if (!page->focusController().setFocusedElement(0, m_frame)) | 1953 if (!page->focusController().setFocusedElement(0, m_frame)) |
1954 return true; | 1954 return true; |
1955 } | 1955 } |
1956 } | 1956 } |
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3093 return keydownResult; | 3093 return keydownResult; |
3094 RefPtrWillBeRawPtr<KeyboardEvent> keypress = KeyboardEvent::create(keyPressE
vent, m_frame->document()->domWindow()); | 3094 RefPtrWillBeRawPtr<KeyboardEvent> keypress = KeyboardEvent::create(keyPressE
vent, m_frame->document()->domWindow()); |
3095 keypress->setTarget(node); | 3095 keypress->setTarget(node); |
3096 if (keydownResult) | 3096 if (keydownResult) |
3097 keypress->setDefaultPrevented(true); | 3097 keypress->setDefaultPrevented(true); |
3098 node->dispatchEvent(keypress, IGNORE_EXCEPTION); | 3098 node->dispatchEvent(keypress, IGNORE_EXCEPTION); |
3099 | 3099 |
3100 return keydownResult || keypress->defaultPrevented() || keypress->defaultHan
dled(); | 3100 return keydownResult || keypress->defaultPrevented() || keypress->defaultHan
dled(); |
3101 } | 3101 } |
3102 | 3102 |
3103 static FocusType focusDirectionForKey(const AtomicString& keyIdentifier) | 3103 static WebFocusType focusDirectionForKey(const AtomicString& keyIdentifier) |
3104 { | 3104 { |
3105 DEFINE_STATIC_LOCAL(AtomicString, Down, ("Down", AtomicString::ConstructFrom
Literal)); | 3105 DEFINE_STATIC_LOCAL(AtomicString, Down, ("Down", AtomicString::ConstructFrom
Literal)); |
3106 DEFINE_STATIC_LOCAL(AtomicString, Up, ("Up", AtomicString::ConstructFromLite
ral)); | 3106 DEFINE_STATIC_LOCAL(AtomicString, Up, ("Up", AtomicString::ConstructFromLite
ral)); |
3107 DEFINE_STATIC_LOCAL(AtomicString, Left, ("Left", AtomicString::ConstructFrom
Literal)); | 3107 DEFINE_STATIC_LOCAL(AtomicString, Left, ("Left", AtomicString::ConstructFrom
Literal)); |
3108 DEFINE_STATIC_LOCAL(AtomicString, Right, ("Right", AtomicString::ConstructFr
omLiteral)); | 3108 DEFINE_STATIC_LOCAL(AtomicString, Right, ("Right", AtomicString::ConstructFr
omLiteral)); |
3109 | 3109 |
3110 FocusType retVal = FocusTypeNone; | 3110 WebFocusType retVal = WebFocusTypeNone; |
3111 | 3111 |
3112 if (keyIdentifier == Down) | 3112 if (keyIdentifier == Down) |
3113 retVal = FocusTypeDown; | 3113 retVal = WebFocusTypeDown; |
3114 else if (keyIdentifier == Up) | 3114 else if (keyIdentifier == Up) |
3115 retVal = FocusTypeUp; | 3115 retVal = WebFocusTypeUp; |
3116 else if (keyIdentifier == Left) | 3116 else if (keyIdentifier == Left) |
3117 retVal = FocusTypeLeft; | 3117 retVal = WebFocusTypeLeft; |
3118 else if (keyIdentifier == Right) | 3118 else if (keyIdentifier == Right) |
3119 retVal = FocusTypeRight; | 3119 retVal = WebFocusTypeRight; |
3120 | 3120 |
3121 return retVal; | 3121 return retVal; |
3122 } | 3122 } |
3123 | 3123 |
3124 void EventHandler::defaultKeyboardEventHandler(KeyboardEvent* event) | 3124 void EventHandler::defaultKeyboardEventHandler(KeyboardEvent* event) |
3125 { | 3125 { |
3126 if (event->type() == EventTypeNames::keydown) { | 3126 if (event->type() == EventTypeNames::keydown) { |
3127 // Clear caret blinking suspended state to make sure that caret blinks | 3127 // Clear caret blinking suspended state to make sure that caret blinks |
3128 // when we type again after long pressing on an empty input field. | 3128 // when we type again after long pressing on an empty input field. |
3129 if (m_frame && m_frame->selection().isCaretBlinkingSuspended()) | 3129 if (m_frame && m_frame->selection().isCaretBlinkingSuspended()) |
3130 m_frame->selection().setCaretBlinkingSuspended(false); | 3130 m_frame->selection().setCaretBlinkingSuspended(false); |
3131 | 3131 |
3132 m_frame->editor().handleKeyboardEvent(event); | 3132 m_frame->editor().handleKeyboardEvent(event); |
3133 if (event->defaultHandled()) | 3133 if (event->defaultHandled()) |
3134 return; | 3134 return; |
3135 if (event->keyIdentifier() == "U+0009") | 3135 if (event->keyIdentifier() == "U+0009") |
3136 defaultTabEventHandler(event); | 3136 defaultTabEventHandler(event); |
3137 else if (event->keyIdentifier() == "U+0008") | 3137 else if (event->keyIdentifier() == "U+0008") |
3138 defaultBackspaceEventHandler(event); | 3138 defaultBackspaceEventHandler(event); |
3139 else if (event->keyIdentifier() == "U+001B") | 3139 else if (event->keyIdentifier() == "U+001B") |
3140 defaultEscapeEventHandler(event); | 3140 defaultEscapeEventHandler(event); |
3141 else { | 3141 else { |
3142 FocusType type = focusDirectionForKey(AtomicString(event->keyIdentif
ier())); | 3142 WebFocusType type = focusDirectionForKey(AtomicString(event->keyIden
tifier())); |
3143 if (type != FocusTypeNone) | 3143 if (type != WebFocusTypeNone) |
3144 defaultArrowEventHandler(type, event); | 3144 defaultArrowEventHandler(type, event); |
3145 } | 3145 } |
3146 } | 3146 } |
3147 if (event->type() == EventTypeNames::keypress) { | 3147 if (event->type() == EventTypeNames::keypress) { |
3148 m_frame->editor().handleKeyboardEvent(event); | 3148 m_frame->editor().handleKeyboardEvent(event); |
3149 if (event->defaultHandled()) | 3149 if (event->defaultHandled()) |
3150 return; | 3150 return; |
3151 if (event->charCode() == ' ') | 3151 if (event->charCode() == ' ') |
3152 defaultSpaceEventHandler(event); | 3152 defaultSpaceEventHandler(event); |
3153 } | 3153 } |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3380 if (event->ctrlKey() || event->metaKey() || event->altKey()) | 3380 if (event->ctrlKey() || event->metaKey() || event->altKey()) |
3381 return; | 3381 return; |
3382 | 3382 |
3383 if (!m_frame->editor().behavior().shouldNavigateBackOnBackspace()) | 3383 if (!m_frame->editor().behavior().shouldNavigateBackOnBackspace()) |
3384 return; | 3384 return; |
3385 bool handledEvent = m_frame->loader().client()->navigateBackForward(event->s
hiftKey() ? 1 : -1); | 3385 bool handledEvent = m_frame->loader().client()->navigateBackForward(event->s
hiftKey() ? 1 : -1); |
3386 if (handledEvent) | 3386 if (handledEvent) |
3387 event->setDefaultHandled(); | 3387 event->setDefaultHandled(); |
3388 } | 3388 } |
3389 | 3389 |
3390 void EventHandler::defaultArrowEventHandler(FocusType focusType, KeyboardEvent*
event) | 3390 void EventHandler::defaultArrowEventHandler(WebFocusType focusType, KeyboardEven
t* event) |
3391 { | 3391 { |
3392 ASSERT(event->type() == EventTypeNames::keydown); | 3392 ASSERT(event->type() == EventTypeNames::keydown); |
3393 | 3393 |
3394 if (event->ctrlKey() || event->metaKey() || event->shiftKey()) | 3394 if (event->ctrlKey() || event->metaKey() || event->shiftKey()) |
3395 return; | 3395 return; |
3396 | 3396 |
3397 Page* page = m_frame->page(); | 3397 Page* page = m_frame->page(); |
3398 if (!page) | 3398 if (!page) |
3399 return; | 3399 return; |
3400 | 3400 |
(...skipping 23 matching lines...) Expand all Loading... |
3424 if (event->altKey()) | 3424 if (event->altKey()) |
3425 return; | 3425 return; |
3426 #endif | 3426 #endif |
3427 | 3427 |
3428 Page* page = m_frame->page(); | 3428 Page* page = m_frame->page(); |
3429 if (!page) | 3429 if (!page) |
3430 return; | 3430 return; |
3431 if (!page->tabKeyCyclesThroughElements()) | 3431 if (!page->tabKeyCyclesThroughElements()) |
3432 return; | 3432 return; |
3433 | 3433 |
3434 FocusType focusType = event->shiftKey() ? FocusTypeBackward : FocusTypeForwa
rd; | 3434 WebFocusType focusType = event->shiftKey() ? WebFocusTypeBackward : WebFocus
TypeForward; |
3435 | 3435 |
3436 // Tabs can be used in design mode editing. | 3436 // Tabs can be used in design mode editing. |
3437 if (m_frame->document()->inDesignMode()) | 3437 if (m_frame->document()->inDesignMode()) |
3438 return; | 3438 return; |
3439 | 3439 |
3440 if (page->focusController().advanceFocus(focusType)) | 3440 if (page->focusController().advanceFocus(focusType)) |
3441 event->setDefaultHandled(); | 3441 event->setDefaultHandled(); |
3442 } | 3442 } |
3443 | 3443 |
3444 void EventHandler::defaultEscapeEventHandler(KeyboardEvent* event) | 3444 void EventHandler::defaultEscapeEventHandler(KeyboardEvent* event) |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3879 unsigned EventHandler::accessKeyModifiers() | 3879 unsigned EventHandler::accessKeyModifiers() |
3880 { | 3880 { |
3881 #if OS(MACOSX) | 3881 #if OS(MACOSX) |
3882 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; | 3882 return PlatformEvent::CtrlKey | PlatformEvent::AltKey; |
3883 #else | 3883 #else |
3884 return PlatformEvent::AltKey; | 3884 return PlatformEvent::AltKey; |
3885 #endif | 3885 #endif |
3886 } | 3886 } |
3887 | 3887 |
3888 } // namespace blink | 3888 } // namespace blink |
OLD | NEW |