| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/renderer_host/gtk_im_context_wrapper.h" | 5 #include "chrome/browser/renderer_host/gtk_im_context_wrapper.h" |
| 6 | 6 |
| 7 #include <gdk/gdk.h> | 7 #include <gdk/gdk.h> |
| 8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 filtered = gtk_im_context_filter_keypress(context_, event); | 125 filtered = gtk_im_context_filter_keypress(context_, event); |
| 126 } else { | 126 } else { |
| 127 filtered = gtk_im_context_filter_keypress(context_simple_, event); | 127 filtered = gtk_im_context_filter_keypress(context_simple_, event); |
| 128 } | 128 } |
| 129 | 129 |
| 130 // Reset this flag here, as it's only used in input method callbacks. | 130 // Reset this flag here, as it's only used in input method callbacks. |
| 131 is_in_key_event_handler_ = false; | 131 is_in_key_event_handler_ = false; |
| 132 | 132 |
| 133 NativeWebKeyboardEvent wke(event); | 133 NativeWebKeyboardEvent wke(event); |
| 134 | 134 |
| 135 // If the key event was handled by the input method, then we need to prevent |
| 136 // RenderView::UnhandledKeyboardEvent() from processing it. |
| 137 // Otherwise unexpected result may occur. For example if it's a |
| 138 // Backspace key event, the browser may go back to previous page. |
| 139 if (filtered) |
| 140 wke.skip_in_browser = true; |
| 141 |
| 135 // Send filtered keydown event before sending IME result. | 142 // Send filtered keydown event before sending IME result. |
| 136 if (event->type == GDK_KEY_PRESS && filtered) | 143 if (event->type == GDK_KEY_PRESS && filtered) |
| 137 ProcessFilteredKeyPressEvent(&wke); | 144 ProcessFilteredKeyPressEvent(&wke); |
| 138 | 145 |
| 139 // Send IME results. In most cases, it's only available if the key event | 146 // Send IME results. In most cases, it's only available if the key event |
| 140 // is filtered by IME. But in rare cases, an unfiltered key event may also | 147 // is filtered by IME. But in rare cases, an unfiltered key event may also |
| 141 // generate IME results. | 148 // generate IME results. |
| 142 // Any IME results generated by a unfiltered key down event must be sent | 149 // Any IME results generated by a unfiltered key down event must be sent |
| 143 // before the key down event, to avoid some tricky issues. For example, | 150 // before the key down event, to avoid some tricky issues. For example, |
| 144 // when using latin-post input method, pressing 'a' then Backspace, may | 151 // when using latin-post input method, pressing 'a' then Backspace, may |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 // If IME has filtered this event, then replace virtual key code with | 321 // If IME has filtered this event, then replace virtual key code with |
| 315 // VK_PROCESSKEY. See comment in ProcessKeyEvent() for details. | 322 // VK_PROCESSKEY. See comment in ProcessKeyEvent() for details. |
| 316 // It's only required for keydown events. | 323 // It's only required for keydown events. |
| 317 // To emulate windows behavior, when input method is enabled, if the commit | 324 // To emulate windows behavior, when input method is enabled, if the commit |
| 318 // text can be emulated by a Char event, then don't do this replacement. | 325 // text can be emulated by a Char event, then don't do this replacement. |
| 319 if (!NeedCommitByForwardingCharEvent()) { | 326 if (!NeedCommitByForwardingCharEvent()) { |
| 320 wke->windowsKeyCode = kCompositionEventKeyCode; | 327 wke->windowsKeyCode = kCompositionEventKeyCode; |
| 321 // keyidentifier must be updated accordingly, otherwise this key event may | 328 // keyidentifier must be updated accordingly, otherwise this key event may |
| 322 // still be processed by webkit. | 329 // still be processed by webkit. |
| 323 wke->setKeyIdentifierFromWindowsKeyCode(); | 330 wke->setKeyIdentifierFromWindowsKeyCode(); |
| 324 // Prevent RenderView::UnhandledKeyboardEvent() from processing it. | |
| 325 // Otherwise unexpected result may occur. For example if it's a | |
| 326 // Backspace key event, the browser may go back to previous page. | |
| 327 wke->skip_in_browser = true; | |
| 328 } | 331 } |
| 329 host_view_->ForwardKeyboardEvent(*wke); | 332 host_view_->ForwardKeyboardEvent(*wke); |
| 330 } | 333 } |
| 331 | 334 |
| 332 void GtkIMContextWrapper::ProcessUnfilteredKeyPressEvent( | 335 void GtkIMContextWrapper::ProcessUnfilteredKeyPressEvent( |
| 333 NativeWebKeyboardEvent* wke) { | 336 NativeWebKeyboardEvent* wke) { |
| 334 // Send keydown event as it, because it's not filtered by IME. | 337 // Send keydown event as it, because it's not filtered by IME. |
| 335 host_view_->ForwardKeyboardEvent(*wke); | 338 host_view_->ForwardKeyboardEvent(*wke); |
| 336 | 339 |
| 337 // IME is disabled by WebKit or the GtkIMContext object cannot handle | 340 // IME is disabled by WebKit or the GtkIMContext object cannot handle |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 } while (pango_attr_iterator_next(iter)); | 625 } while (pango_attr_iterator_next(iter)); |
| 623 pango_attr_iterator_destroy(iter); | 626 pango_attr_iterator_destroy(iter); |
| 624 } | 627 } |
| 625 | 628 |
| 626 // Use a black thin underline by default. | 629 // Use a black thin underline by default. |
| 627 if (underlines->empty()) { | 630 if (underlines->empty()) { |
| 628 underlines->push_back( | 631 underlines->push_back( |
| 629 WebKit::WebCompositionUnderline(0, length, SK_ColorBLACK, false)); | 632 WebKit::WebCompositionUnderline(0, length, SK_ColorBLACK, false)); |
| 630 } | 633 } |
| 631 } | 634 } |
| OLD | NEW |