OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/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 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 | 12 |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/third_party/icu/icu_utf.h" | |
16 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
17 #include "chrome/app/chrome_command_ids.h" | |
18 #include "chrome/browser/ui/gtk/gtk_util.h" | |
19 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" | |
20 #include "chrome/common/render_messages.h" | |
21 #include "content/browser/renderer_host/render_widget_host.h" | 16 #include "content/browser/renderer_host/render_widget_host.h" |
| 17 #include "content/browser/renderer_host/render_widget_host_view_gtk.h" |
22 #include "content/common/native_web_keyboard_event.h" | 18 #include "content/common/native_web_keyboard_event.h" |
23 #include "grit/generated_resources.h" | |
24 #include "third_party/skia/include/core/SkColor.h" | |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" |
26 #include "ui/base/gtk/gtk_im_context_util.h" | 20 #include "ui/base/gtk/gtk_im_context_util.h" |
27 #include "ui/base/l10n/l10n_util.h" | |
28 #include "ui/gfx/gtk_util.h" | 21 #include "ui/gfx/gtk_util.h" |
29 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
30 | 23 |
31 #if !defined(TOOLKIT_VIEWS) | |
32 #include "chrome/browser/ui/gtk/menu_gtk.h" | |
33 #endif | |
34 | |
35 namespace { | 24 namespace { |
36 // Copied from third_party/WebKit/Source/WebCore/page/EventHandler.cpp | 25 // Copied from third_party/WebKit/Source/WebCore/page/EventHandler.cpp |
37 // | 26 // |
38 // Match key code of composition keydown event on windows. | 27 // Match key code of composition keydown event on windows. |
39 // IE sends VK_PROCESSKEY which has value 229; | 28 // IE sends VK_PROCESSKEY which has value 229; |
40 // | 29 // |
41 // Please refer to following documents for detals: | 30 // Please refer to following documents for detals: |
42 // - Virtual-Key Codes | 31 // - Virtual-Key Codes |
43 // http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx | 32 // http://msdn.microsoft.com/en-us/library/ms645540(VS.85).aspx |
44 // - How the IME System Works | 33 // - How the IME System Works |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 is_composing_text_ = false; | 301 is_composing_text_ = false; |
313 | 302 |
314 // Disable RenderWidget's IME related events to save bandwidth. | 303 // Disable RenderWidget's IME related events to save bandwidth. |
315 if (host_view_->GetRenderWidgetHost()) | 304 if (host_view_->GetRenderWidgetHost()) |
316 host_view_->GetRenderWidgetHost()->SetInputMethodActive(false); | 305 host_view_->GetRenderWidgetHost()->SetInputMethodActive(false); |
317 } | 306 } |
318 | 307 |
319 #if !defined(TOOLKIT_VIEWS) | 308 #if !defined(TOOLKIT_VIEWS) |
320 // Not defined for views because the views context menu doesn't | 309 // Not defined for views because the views context menu doesn't |
321 // implement input methods yet. | 310 // implement input methods yet. |
322 void GtkIMContextWrapper::AppendInputMethodsContextMenu(MenuGtk* menu) { | 311 GtkWidget* GtkIMContextWrapper::BuildInputMethodsGtkMenu() { |
323 gboolean show_input_method_menu = TRUE; | |
324 | |
325 g_object_get(gtk_widget_get_settings(GTK_WIDGET(host_view_->native_view())), | |
326 "gtk-show-input-method-menu", &show_input_method_menu, NULL); | |
327 if (!show_input_method_menu) | |
328 return; | |
329 | |
330 std::string label = gfx::ConvertAcceleratorsFromWindowsStyle( | |
331 l10n_util::GetStringUTF8(IDS_CONTENT_CONTEXT_INPUT_METHODS_MENU)); | |
332 GtkWidget* menuitem = gtk_menu_item_new_with_mnemonic(label.c_str()); | |
333 GtkWidget* submenu = gtk_menu_new(); | 312 GtkWidget* submenu = gtk_menu_new(); |
334 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu); | |
335 gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(context_), | 313 gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(context_), |
336 GTK_MENU_SHELL(submenu)); | 314 GTK_MENU_SHELL(submenu)); |
337 menu->AppendSeparator(); | 315 return submenu; |
338 menu->AppendMenuItem(IDC_INPUT_METHODS_MENU, menuitem); | |
339 } | 316 } |
340 #endif | 317 #endif |
341 | 318 |
342 void GtkIMContextWrapper::CancelComposition() { | 319 void GtkIMContextWrapper::CancelComposition() { |
343 if (!is_enabled_) | 320 if (!is_enabled_) |
344 return; | 321 return; |
345 | 322 |
346 DCHECK(!is_in_key_event_handler_); | 323 DCHECK(!is_in_key_event_handler_); |
347 | 324 |
348 // To prevent any text from being committed when resetting the |context_|; | 325 // To prevent any text from being committed when resetting the |context_|; |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 | 610 |
634 void GtkIMContextWrapper::HandleHostViewRealizeThunk( | 611 void GtkIMContextWrapper::HandleHostViewRealizeThunk( |
635 GtkWidget* widget, GtkIMContextWrapper* self) { | 612 GtkWidget* widget, GtkIMContextWrapper* self) { |
636 self->HandleHostViewRealize(widget); | 613 self->HandleHostViewRealize(widget); |
637 } | 614 } |
638 | 615 |
639 void GtkIMContextWrapper::HandleHostViewUnrealizeThunk( | 616 void GtkIMContextWrapper::HandleHostViewUnrealizeThunk( |
640 GtkWidget* widget, GtkIMContextWrapper* self) { | 617 GtkWidget* widget, GtkIMContextWrapper* self) { |
641 self->HandleHostViewUnrealize(); | 618 self->HandleHostViewUnrealize(); |
642 } | 619 } |
OLD | NEW |