OLD | NEW |
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/dpi.h" |
15 #include "ui/gfx/win/hwnd_util.h" | 15 #include "ui/gfx/win/hwnd_util.h" |
16 | 16 |
17 namespace ui { | 17 namespace ui { |
18 namespace { | 18 namespace { |
19 | 19 |
20 // 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 |
21 // is returned to IME for improving conversion accuracy. | 21 // is returned to IME for improving conversion accuracy. |
22 static const size_t kExtraNumberOfChars = 20; | 22 static const size_t kExtraNumberOfChars = 20; |
23 | 23 |
24 } // namespace | 24 } // namespace |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 void InputMethodWin::OnCaretBoundsChanged(const TextInputClient* client) { | 151 void InputMethodWin::OnCaretBoundsChanged(const TextInputClient* client) { |
152 if (!enabled_ || !IsTextInputClientFocused(client) || | 152 if (!enabled_ || !IsTextInputClientFocused(client) || |
153 !IsWindowFocused(client)) { | 153 !IsWindowFocused(client)) { |
154 return; | 154 return; |
155 } | 155 } |
156 // The current text input type should not be NONE if |client| is focused. | 156 // The current text input type should not be NONE if |client| is focused. |
157 DCHECK(!IsTextInputTypeNone()); | 157 DCHECK(!IsTextInputTypeNone()); |
158 // Tentatively assume that the returned value is DIP (Density Independent | 158 // Tentatively assume that the returned value is DIP (Density Independent |
159 // Pixel). See the comment in text_input_client.h and http://crbug.com/360334. | 159 // Pixel). See the comment in text_input_client.h and http://crbug.com/360334. |
160 const gfx::Rect dip_screen_bounds(GetTextInputClient()->GetCaretBounds()); | 160 const gfx::Rect dip_screen_bounds(GetTextInputClient()->GetCaretBounds()); |
161 const gfx::Rect screen_bounds = gfx::win::DIPToScreenRect(dip_screen_bounds); | 161 const gfx::Rect screen_bounds = gfx::DIPToScreenRect(dip_screen_bounds); |
162 | 162 |
163 HWND attached_window = GetAttachedWindowHandle(client); | 163 HWND attached_window = GetAttachedWindowHandle(client); |
164 // TODO(ime): see comment in TextInputClient::GetCaretBounds(), this | 164 // TODO(ime): see comment in TextInputClient::GetCaretBounds(), this |
165 // conversion shouldn't be necessary. | 165 // conversion shouldn't be necessary. |
166 RECT r = {}; | 166 RECT r = {}; |
167 GetClientRect(attached_window, &r); | 167 GetClientRect(attached_window, &r); |
168 POINT window_point = { screen_bounds.x(), screen_bounds.y() }; | 168 POINT window_point = { screen_bounds.x(), screen_bounds.y() }; |
169 ScreenToClient(attached_window, &window_point); | 169 ScreenToClient(attached_window, &window_point); |
170 gfx::Rect caret_rect(gfx::Point(window_point.x, window_point.y), | 170 gfx::Rect caret_rect(gfx::Point(window_point.x, window_point.y), |
171 screen_bounds.size()); | 171 screen_bounds.size()); |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 &dip_rect)) { | 530 &dip_rect)) { |
531 return 0; | 531 return 0; |
532 } | 532 } |
533 } else { | 533 } else { |
534 // If there is no composition and the first character is queried, returns | 534 // If there is no composition and the first character is queried, returns |
535 // the caret bounds. This behavior is the same to that of RichEdit control. | 535 // the caret bounds. This behavior is the same to that of RichEdit control. |
536 if (char_positon->dwCharPos != 0) | 536 if (char_positon->dwCharPos != 0) |
537 return 0; | 537 return 0; |
538 dip_rect = client->GetCaretBounds(); | 538 dip_rect = client->GetCaretBounds(); |
539 } | 539 } |
540 const gfx::Rect rect = gfx::win::DIPToScreenRect(dip_rect); | 540 const gfx::Rect rect = gfx::DIPToScreenRect(dip_rect); |
541 | 541 |
542 char_positon->pt.x = rect.x(); | 542 char_positon->pt.x = rect.x(); |
543 char_positon->pt.y = rect.y(); | 543 char_positon->pt.y = rect.y(); |
544 char_positon->cLineHeight = rect.height(); | 544 char_positon->cLineHeight = rect.height(); |
545 return 1; // returns non-zero value when succeeded. | 545 return 1; // returns non-zero value when succeeded. |
546 } | 546 } |
547 | 547 |
548 HWND InputMethodWin::GetAttachedWindowHandle( | 548 HWND InputMethodWin::GetAttachedWindowHandle( |
549 const TextInputClient* text_input_client) const { | 549 const TextInputClient* text_input_client) const { |
550 // On Aura environment, we can assume that |toplevel_window_handle_| always | 550 // On Aura environment, we can assume that |toplevel_window_handle_| always |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 enabled_ = true; | 607 enabled_ = true; |
608 break; | 608 break; |
609 } | 609 } |
610 | 610 |
611 imm32_manager_.SetTextInputMode(window_handle, text_input_mode); | 611 imm32_manager_.SetTextInputMode(window_handle, text_input_mode); |
612 tsf_inputscope::SetInputScopeForTsfUnawareWindow( | 612 tsf_inputscope::SetInputScopeForTsfUnawareWindow( |
613 window_handle, text_input_type, text_input_mode); | 613 window_handle, text_input_type, text_input_mode); |
614 } | 614 } |
615 | 615 |
616 } // namespace ui | 616 } // namespace ui |
OLD | NEW |