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