Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1598)

Side by Side Diff: chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk.cc

Issue 2593323002: Use the physical-pixel space for native IME on linux platform. (Closed)
Patch Set: Use the physical-pixel space for native IME on linux platform. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/base/ime/text_input_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/ui/libgtkui/x11_input_method_context_impl_gtk.h" 5 #include "chrome/browser/ui/libgtkui/x11_input_method_context_impl_gtk.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 <gdk/gdkx.h> 9 #include <gdk/gdkx.h>
10 #include <stddef.h> 10 #include <stddef.h>
11 11
12 #include <gtk/gtk.h> 12 #include <gtk/gtk.h>
13 13
14 #include <X11/X.h> 14 #include <X11/X.h>
15 #include <X11/Xlib.h> 15 #include <X11/Xlib.h>
16 16
17 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "ui/base/ime/composition_text.h" 19 #include "ui/base/ime/composition_text.h"
20 #include "ui/base/ime/composition_text_util_pango.h" 20 #include "ui/base/ime/composition_text_util_pango.h"
21 #include "ui/base/ime/text_input_client.h" 21 #include "ui/base/ime/text_input_client.h"
22 #include "ui/events/event.h" 22 #include "ui/events/event.h"
23 #include "ui/events/keycodes/keyboard_code_conversion_x.h" 23 #include "ui/events/keycodes/keyboard_code_conversion_x.h"
24 #include "ui/gfx/geometry/dip_util.h"
24 #include "ui/gfx/x/x11_types.h" 25 #include "ui/gfx/x/x11_types.h"
26 #include "ui/views/linux_ui/linux_ui.h"
25 27
26 namespace libgtkui { 28 namespace libgtkui {
27 29
28 X11InputMethodContextImplGtk2::X11InputMethodContextImplGtk2( 30 X11InputMethodContextImplGtk2::X11InputMethodContextImplGtk2(
29 ui::LinuxInputMethodContextDelegate* delegate, 31 ui::LinuxInputMethodContextDelegate* delegate,
30 bool is_simple) 32 bool is_simple)
31 : delegate_(delegate), 33 : delegate_(delegate),
32 gtk_context_(NULL), 34 gtk_context_(NULL),
33 gdk_last_set_client_window_(NULL) { 35 gdk_last_set_client_window_(NULL) {
34 CHECK(delegate_); 36 CHECK(delegate_);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 if (event->key.window != gdk_last_set_client_window_) { 76 if (event->key.window != gdk_last_set_client_window_) {
75 gtk_im_context_set_client_window(gtk_context_, event->key.window); 77 gtk_im_context_set_client_window(gtk_context_, event->key.window);
76 gdk_last_set_client_window_ = event->key.window; 78 gdk_last_set_client_window_ = event->key.window;
77 } 79 }
78 80
79 // Convert the last known caret bounds relative to the screen coordinates 81 // Convert the last known caret bounds relative to the screen coordinates
80 // to a GdkRectangle relative to the client window. 82 // to a GdkRectangle relative to the client window.
81 gint x = 0; 83 gint x = 0;
82 gint y = 0; 84 gint y = 0;
83 gdk_window_get_origin(event->key.window, &x, &y); 85 gdk_window_get_origin(event->key.window, &x, &y);
84 GdkRectangle rect = {last_caret_bounds_.x() - x, last_caret_bounds_.y() - y, 86
85 last_caret_bounds_.width(), last_caret_bounds_.height()}; 87 GdkRectangle gdk_rect = {
86 gtk_im_context_set_cursor_location(gtk_context_, &rect); 88 last_caret_bounds_.x() - x, last_caret_bounds_.y() - y,
89 last_caret_bounds_.width(), last_caret_bounds_.height()};
90 gtk_im_context_set_cursor_location(gtk_context_, &gdk_rect);
87 91
88 const bool handled = 92 const bool handled =
89 gtk_im_context_filter_keypress(gtk_context_, &event->key); 93 gtk_im_context_filter_keypress(gtk_context_, &event->key);
90 gdk_event_free(event); 94 gdk_event_free(event);
91 return handled; 95 return handled;
92 } 96 }
93 97
94 void X11InputMethodContextImplGtk2::Reset() { 98 void X11InputMethodContextImplGtk2::Reset() {
95 gtk_im_context_reset(gtk_context_); 99 gtk_im_context_reset(gtk_context_);
96 } 100 }
97 101
98 void X11InputMethodContextImplGtk2::Focus() { 102 void X11InputMethodContextImplGtk2::Focus() {
99 gtk_im_context_focus_in(gtk_context_); 103 gtk_im_context_focus_in(gtk_context_);
100 } 104 }
101 105
102 void X11InputMethodContextImplGtk2::Blur() { 106 void X11InputMethodContextImplGtk2::Blur() {
103 gtk_im_context_focus_out(gtk_context_); 107 gtk_im_context_focus_out(gtk_context_);
104 } 108 }
105 109
106 void X11InputMethodContextImplGtk2::SetCursorLocation(const gfx::Rect& rect) { 110 void X11InputMethodContextImplGtk2::SetCursorLocation(const gfx::Rect& rect) {
107 // Remember the caret bounds so that we can set the cursor location later. 111 // Remember the caret bounds so that we can set the cursor location later.
108 // gtk_im_context_set_cursor_location() takes the location relative to the 112 // gtk_im_context_set_cursor_location() takes the location relative to the
109 // client window, which is unknown at this point. So we'll call 113 // client window, which is unknown at this point. So we'll call
110 // gtk_im_context_set_cursor_location() later in ProcessKeyEvent() where 114 // gtk_im_context_set_cursor_location() later in ProcessKeyEvent() where
111 // (and only where) we know the client window. 115 // (and only where) we know the client window.
112 last_caret_bounds_ = rect; 116 if (views::LinuxUI::instance()) {
117 last_caret_bounds_ = gfx::ConvertRectToPixel(
118 views::LinuxUI::instance()->GetDeviceScaleFactor(), rect);
119 } else {
120 last_caret_bounds_ = rect;
121 }
113 } 122 }
114 123
115 // private: 124 // private:
116 125
117 void X11InputMethodContextImplGtk2::ResetXModifierKeycodesCache() { 126 void X11InputMethodContextImplGtk2::ResetXModifierKeycodesCache() {
118 modifier_keycodes_.clear(); 127 modifier_keycodes_.clear();
119 meta_keycodes_.clear(); 128 meta_keycodes_.clear();
120 super_keycodes_.clear(); 129 super_keycodes_.clear();
121 hyper_keycodes_.clear(); 130 hyper_keycodes_.clear();
122 131
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 313 }
305 314
306 void X11InputMethodContextImplGtk2::OnPreeditStart(GtkIMContext* context) { 315 void X11InputMethodContextImplGtk2::OnPreeditStart(GtkIMContext* context) {
307 if (context != gtk_context_) 316 if (context != gtk_context_)
308 return; 317 return;
309 318
310 delegate_->OnPreeditStart(); 319 delegate_->OnPreeditStart();
311 } 320 }
312 321
313 } // namespace libgtkui 322 } // namespace libgtkui
OLDNEW
« no previous file with comments | « no previous file | ui/base/ime/text_input_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698