| 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/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "ui/base/ime/text_input_client.h" | 10 #include "ui/base/ime/text_input_client.h" |
| 11 #include "ui/base/ime/win/tsf_input_scope.h" | 11 #include "ui/base/ime/win/tsf_input_scope.h" |
| 12 #include "ui/base/ui_base_switches.h" | 12 #include "ui/base/ui_base_switches.h" |
| 13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 14 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
| 15 #include "ui/events/event_utils.h" | 15 #include "ui/events/event_utils.h" |
| 16 #include "ui/events/keycodes/keyboard_codes.h" | 16 #include "ui/events/keycodes/keyboard_codes.h" |
| 17 #include "ui/gfx/win/dpi.h" | 17 #include "ui/gfx/screen_win.h" |
| 18 #include "ui/gfx/win/hwnd_util.h" | 18 #include "ui/gfx/win/hwnd_util.h" |
| 19 | 19 |
| 20 namespace ui { | 20 namespace ui { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 // Extra number of chars before and after selection (or composition) range which | 23 // Extra number of chars before and after selection (or composition) range which |
| 24 // is returned to IME for improving conversion accuracy. | 24 // is returned to IME for improving conversion accuracy. |
| 25 static const size_t kExtraNumberOfChars = 20; | 25 static const size_t kExtraNumberOfChars = 20; |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 void InputMethodWin::OnCaretBoundsChanged(const TextInputClient* client) { | 190 void InputMethodWin::OnCaretBoundsChanged(const TextInputClient* client) { |
| 191 if (!enabled_ || !IsTextInputClientFocused(client) || | 191 if (!enabled_ || !IsTextInputClientFocused(client) || |
| 192 !IsWindowFocused(client)) { | 192 !IsWindowFocused(client)) { |
| 193 return; | 193 return; |
| 194 } | 194 } |
| 195 // The current text input type should not be NONE if |client| is focused. | 195 // The current text input type should not be NONE if |client| is focused. |
| 196 DCHECK(!IsTextInputTypeNone()); | 196 DCHECK(!IsTextInputTypeNone()); |
| 197 // Tentatively assume that the returned value is DIP (Density Independent | 197 // Tentatively assume that the returned value is DIP (Density Independent |
| 198 // Pixel). See the comment in text_input_client.h and http://crbug.com/360334. | 198 // Pixel). See the comment in text_input_client.h and http://crbug.com/360334. |
| 199 const gfx::Rect dip_screen_bounds(GetTextInputClient()->GetCaretBounds()); | 199 const gfx::Rect dip_screen_bounds(GetTextInputClient()->GetCaretBounds()); |
| 200 const gfx::Rect screen_bounds = gfx::win::DIPToScreenRect(dip_screen_bounds); | 200 const gfx::Rect screen_bounds = gfx::ScreenWin::DIPToScreenRect( |
| 201 toplevel_window_handle_, dip_screen_bounds); |
| 201 | 202 |
| 202 HWND attached_window = toplevel_window_handle_; | 203 HWND attached_window = toplevel_window_handle_; |
| 203 // TODO(ime): see comment in TextInputClient::GetCaretBounds(), this | 204 // TODO(ime): see comment in TextInputClient::GetCaretBounds(), this |
| 204 // conversion shouldn't be necessary. | 205 // conversion shouldn't be necessary. |
| 205 RECT r = {}; | 206 RECT r = {}; |
| 206 GetClientRect(attached_window, &r); | 207 GetClientRect(attached_window, &r); |
| 207 POINT window_point = { screen_bounds.x(), screen_bounds.y() }; | 208 POINT window_point = { screen_bounds.x(), screen_bounds.y() }; |
| 208 ScreenToClient(attached_window, &window_point); | 209 ScreenToClient(attached_window, &window_point); |
| 209 gfx::Rect caret_rect(gfx::Point(window_point.x, window_point.y), | 210 gfx::Rect caret_rect(gfx::Point(window_point.x, window_point.y), |
| 210 screen_bounds.size()); | 211 screen_bounds.size()); |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 &dip_rect)) { | 564 &dip_rect)) { |
| 564 return 0; | 565 return 0; |
| 565 } | 566 } |
| 566 } else { | 567 } else { |
| 567 // If there is no composition and the first character is queried, returns | 568 // If there is no composition and the first character is queried, returns |
| 568 // the caret bounds. This behavior is the same to that of RichEdit control. | 569 // the caret bounds. This behavior is the same to that of RichEdit control. |
| 569 if (char_positon->dwCharPos != 0) | 570 if (char_positon->dwCharPos != 0) |
| 570 return 0; | 571 return 0; |
| 571 dip_rect = client->GetCaretBounds(); | 572 dip_rect = client->GetCaretBounds(); |
| 572 } | 573 } |
| 573 const gfx::Rect rect = gfx::win::DIPToScreenRect(dip_rect); | 574 const gfx::Rect rect = |
| 575 gfx::ScreenWin::DIPToScreenRect(toplevel_window_handle_, dip_rect); |
| 574 | 576 |
| 575 char_positon->pt.x = rect.x(); | 577 char_positon->pt.x = rect.x(); |
| 576 char_positon->pt.y = rect.y(); | 578 char_positon->pt.y = rect.y(); |
| 577 char_positon->cLineHeight = rect.height(); | 579 char_positon->cLineHeight = rect.height(); |
| 578 return 1; // returns non-zero value when succeeded. | 580 return 1; // returns non-zero value when succeeded. |
| 579 } | 581 } |
| 580 | 582 |
| 581 bool InputMethodWin::IsWindowFocused(const TextInputClient* client) const { | 583 bool InputMethodWin::IsWindowFocused(const TextInputClient* client) const { |
| 582 if (!client) | 584 if (!client) |
| 583 return false; | 585 return false; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 enabled_ = true; | 634 enabled_ = true; |
| 633 break; | 635 break; |
| 634 } | 636 } |
| 635 | 637 |
| 636 imm32_manager_.SetTextInputMode(window_handle, text_input_mode); | 638 imm32_manager_.SetTextInputMode(window_handle, text_input_mode); |
| 637 tsf_inputscope::SetInputScopeForTsfUnawareWindow( | 639 tsf_inputscope::SetInputScopeForTsfUnawareWindow( |
| 638 window_handle, text_input_type, text_input_mode); | 640 window_handle, text_input_type, text_input_mode); |
| 639 } | 641 } |
| 640 | 642 |
| 641 } // namespace ui | 643 } // namespace ui |
| OLD | NEW |