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

Side by Side Diff: ui/base/ime/input_method_win.cc

Issue 227073002: Treats the returned value from ui::TextInputClient as DIP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/base/ime/input_method_win.h" 5 #include "ui/base/ime/input_method_win.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "ui/base/ime/text_input_client.h" 8 #include "ui/base/ime/text_input_client.h"
9 #include "ui/base/ime/win/tsf_input_scope.h" 9 #include "ui/base/ime/win/tsf_input_scope.h"
10 #include "ui/events/event.h" 10 #include "ui/events/event.h"
11 #include "ui/events/event_constants.h" 11 #include "ui/events/event_constants.h"
12 #include "ui/events/event_utils.h" 12 #include "ui/events/event_utils.h"
13 #include "ui/events/keycodes/keyboard_codes.h" 13 #include "ui/events/keycodes/keyboard_codes.h"
14 #include "ui/gfx/win/dpi.h"
14 #include "ui/gfx/win/hwnd_util.h" 15 #include "ui/gfx/win/hwnd_util.h"
15 16
16 namespace ui { 17 namespace ui {
17 namespace { 18 namespace {
18 19
19 // Extra number of chars before and after selection (or composition) range which 20 // Extra number of chars before and after selection (or composition) range which
20 // is returned to IME for improving conversion accuracy. 21 // is returned to IME for improving conversion accuracy.
21 static const size_t kExtraNumberOfChars = 20; 22 static const size_t kExtraNumberOfChars = 20;
22 23
23 } // namespace 24 } // namespace
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 UpdateIMEState(); 149 UpdateIMEState();
149 } 150 }
150 151
151 void InputMethodWin::OnCaretBoundsChanged(const TextInputClient* client) { 152 void InputMethodWin::OnCaretBoundsChanged(const TextInputClient* client) {
152 if (!enabled_ || !IsTextInputClientFocused(client) || 153 if (!enabled_ || !IsTextInputClientFocused(client) ||
153 !IsWindowFocused(client)) { 154 !IsWindowFocused(client)) {
154 return; 155 return;
155 } 156 }
156 // The current text input type should not be NONE if |client| is focused. 157 // The current text input type should not be NONE if |client| is focused.
157 DCHECK(!IsTextInputTypeNone()); 158 DCHECK(!IsTextInputTypeNone());
158 gfx::Rect screen_bounds(GetTextInputClient()->GetCaretBounds()); 159 // Tentatively assume that the returned value is DIP (Density Independent
160 // Pixel). See the comment in text_input_client.h and http://crbug.com/360334.
161 const gfx::Rect dip_screen_bounds(GetTextInputClient()->GetCaretBounds());
162 const gfx::Rect screen_bounds = gfx::win::DIPToScreenRect(dip_screen_bounds);
159 163
160 HWND attached_window = GetAttachedWindowHandle(client); 164 HWND attached_window = GetAttachedWindowHandle(client);
161 // TODO(ime): see comment in TextInputClient::GetCaretBounds(), this 165 // TODO(ime): see comment in TextInputClient::GetCaretBounds(), this
162 // conversion shouldn't be necessary. 166 // conversion shouldn't be necessary.
163 RECT r = {}; 167 RECT r = {};
164 GetClientRect(attached_window, &r); 168 GetClientRect(attached_window, &r);
165 POINT window_point = { screen_bounds.x(), screen_bounds.y() }; 169 POINT window_point = { screen_bounds.x(), screen_bounds.y() };
166 ScreenToClient(attached_window, &window_point); 170 ScreenToClient(attached_window, &window_point);
167 gfx::Rect caret_rect(gfx::Point(window_point.x, window_point.y), 171 gfx::Rect caret_rect(gfx::Point(window_point.x, window_point.y),
168 screen_bounds.size()); 172 screen_bounds.size());
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 if (!char_positon) 515 if (!char_positon)
512 return 0; 516 return 0;
513 517
514 if (char_positon->dwSize < sizeof(IMECHARPOSITION)) 518 if (char_positon->dwSize < sizeof(IMECHARPOSITION))
515 return 0; 519 return 0;
516 520
517 ui::TextInputClient* client = GetTextInputClient(); 521 ui::TextInputClient* client = GetTextInputClient();
518 if (!client) 522 if (!client)
519 return 0; 523 return 0;
520 524
521 gfx::Rect rect; 525 // Tentatively assume that the returned value from |client| is DIP (Density
526 // Independent Pixel). See the comment in text_input_client.h and
527 // http://crbug.com/360334.
528 gfx::Rect dip_rect;
522 if (client->HasCompositionText()) { 529 if (client->HasCompositionText()) {
523 if (!client->GetCompositionCharacterBounds(char_positon->dwCharPos, 530 if (!client->GetCompositionCharacterBounds(char_positon->dwCharPos,
524 &rect)) { 531 &dip_rect)) {
525 return 0; 532 return 0;
526 } 533 }
527 } else { 534 } else {
528 // If there is no composition and the first character is queried, returns 535 // If there is no composition and the first character is queried, returns
529 // the caret bounds. This behavior is the same to that of RichEdit control. 536 // the caret bounds. This behavior is the same to that of RichEdit control.
530 if (char_positon->dwCharPos != 0) 537 if (char_positon->dwCharPos != 0)
531 return 0; 538 return 0;
532 rect = client->GetCaretBounds(); 539 dip_rect = client->GetCaretBounds();
533 } 540 }
541 const gfx::Rect rect = gfx::win::DIPToScreenRect(dip_rect);
534 542
535 char_positon->pt.x = rect.x(); 543 char_positon->pt.x = rect.x();
536 char_positon->pt.y = rect.y(); 544 char_positon->pt.y = rect.y();
537 char_positon->cLineHeight = rect.height(); 545 char_positon->cLineHeight = rect.height();
538 return 1; // returns non-zero value when succeeded. 546 return 1; // returns non-zero value when succeeded.
539 } 547 }
540 548
541 HWND InputMethodWin::GetAttachedWindowHandle( 549 HWND InputMethodWin::GetAttachedWindowHandle(
542 const TextInputClient* text_input_client) const { 550 const TextInputClient* text_input_client) const {
543 // On Aura environment, we can assume that |toplevel_window_handle_| always 551 // On Aura environment, we can assume that |toplevel_window_handle_| always
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
600 enabled_ = true; 608 enabled_ = true;
601 break; 609 break;
602 } 610 }
603 611
604 imm32_manager_.SetTextInputMode(window_handle, text_input_mode); 612 imm32_manager_.SetTextInputMode(window_handle, text_input_mode);
605 tsf_inputscope::SetInputScopeForTsfUnawareWindow( 613 tsf_inputscope::SetInputScopeForTsfUnawareWindow(
606 window_handle, text_input_type, text_input_mode); 614 window_handle, text_input_type, text_input_mode);
607 } 615 }
608 616
609 } // namespace ui 617 } // namespace ui
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