| 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/ime_bridge.h" | 12 #include "ui/base/ime/ime_bridge.h" |
| 13 #include "ui/base/ime/ime_engine_handler_interface.h" | 13 #include "ui/base/ime/ime_engine_handler_interface.h" |
| 14 #include "ui/base/ime/text_input_client.h" | 14 #include "ui/base/ime/text_input_client.h" |
| 15 #include "ui/base/ime/win/tsf_input_scope.h" | 15 #include "ui/base/ime/win/tsf_input_scope.h" |
| 16 #include "ui/base/ui_base_switches.h" | 16 #include "ui/base/ui_base_switches.h" |
| 17 #include "ui/events/event.h" | 17 #include "ui/events/event.h" |
| 18 #include "ui/events/event_constants.h" | 18 #include "ui/events/event_constants.h" |
| 19 #include "ui/events/event_utils.h" | 19 #include "ui/events/event_utils.h" |
| 20 #include "ui/events/keycodes/keyboard_codes.h" | 20 #include "ui/events/keycodes/keyboard_codes.h" |
| 21 #include "ui/gfx/win/dpi.h" | 21 #include "ui/gfx/screen_win.h" |
| 22 #include "ui/gfx/win/hwnd_util.h" | 22 #include "ui/gfx/win/hwnd_util.h" |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 ui::IMEEngineHandlerInterface* GetEngine() { | 26 ui::IMEEngineHandlerInterface* GetEngine() { |
| 27 if (ui::IMEBridge::Get()) | 27 if (ui::IMEBridge::Get()) |
| 28 return ui::IMEBridge::Get()->GetCurrentEngineHandler(); | 28 return ui::IMEBridge::Get()->GetCurrentEngineHandler(); |
| 29 return nullptr; | 29 return nullptr; |
| 30 } | 30 } |
| 31 | 31 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 void InputMethodWin::OnCaretBoundsChanged(const TextInputClient* client) { | 216 void InputMethodWin::OnCaretBoundsChanged(const TextInputClient* client) { |
| 217 if (!enabled_ || !IsTextInputClientFocused(client) || | 217 if (!enabled_ || !IsTextInputClientFocused(client) || |
| 218 !IsWindowFocused(client)) { | 218 !IsWindowFocused(client)) { |
| 219 return; | 219 return; |
| 220 } | 220 } |
| 221 // The current text input type should not be NONE if |client| is focused. | 221 // The current text input type should not be NONE if |client| is focused. |
| 222 DCHECK(!IsTextInputTypeNone()); | 222 DCHECK(!IsTextInputTypeNone()); |
| 223 // Tentatively assume that the returned value is DIP (Density Independent | 223 // Tentatively assume that the returned value is DIP (Density Independent |
| 224 // Pixel). See the comment in text_input_client.h and http://crbug.com/360334. | 224 // Pixel). See the comment in text_input_client.h and http://crbug.com/360334. |
| 225 const gfx::Rect dip_screen_bounds(GetTextInputClient()->GetCaretBounds()); | 225 const gfx::Rect dip_screen_bounds(GetTextInputClient()->GetCaretBounds()); |
| 226 const gfx::Rect screen_bounds = gfx::win::DIPToScreenRect(dip_screen_bounds); | 226 const gfx::Rect screen_bounds = gfx::ScreenWin::DIPToScreenRect( |
| 227 toplevel_window_handle_, dip_screen_bounds); |
| 227 | 228 |
| 228 HWND attached_window = toplevel_window_handle_; | 229 HWND attached_window = toplevel_window_handle_; |
| 229 // TODO(ime): see comment in TextInputClient::GetCaretBounds(), this | 230 // TODO(ime): see comment in TextInputClient::GetCaretBounds(), this |
| 230 // conversion shouldn't be necessary. | 231 // conversion shouldn't be necessary. |
| 231 RECT r = {}; | 232 RECT r = {}; |
| 232 GetClientRect(attached_window, &r); | 233 GetClientRect(attached_window, &r); |
| 233 POINT window_point = { screen_bounds.x(), screen_bounds.y() }; | 234 POINT window_point = { screen_bounds.x(), screen_bounds.y() }; |
| 234 ScreenToClient(attached_window, &window_point); | 235 ScreenToClient(attached_window, &window_point); |
| 235 gfx::Rect caret_rect(gfx::Point(window_point.x, window_point.y), | 236 gfx::Rect caret_rect(gfx::Point(window_point.x, window_point.y), |
| 236 screen_bounds.size()); | 237 screen_bounds.size()); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 &dip_rect)) { | 592 &dip_rect)) { |
| 592 return 0; | 593 return 0; |
| 593 } | 594 } |
| 594 } else { | 595 } else { |
| 595 // If there is no composition and the first character is queried, returns | 596 // If there is no composition and the first character is queried, returns |
| 596 // the caret bounds. This behavior is the same to that of RichEdit control. | 597 // the caret bounds. This behavior is the same to that of RichEdit control. |
| 597 if (char_positon->dwCharPos != 0) | 598 if (char_positon->dwCharPos != 0) |
| 598 return 0; | 599 return 0; |
| 599 dip_rect = client->GetCaretBounds(); | 600 dip_rect = client->GetCaretBounds(); |
| 600 } | 601 } |
| 601 const gfx::Rect rect = gfx::win::DIPToScreenRect(dip_rect); | 602 const gfx::Rect rect = |
| 603 gfx::ScreenWin::DIPToScreenRect(toplevel_window_handle_, dip_rect); |
| 602 | 604 |
| 603 char_positon->pt.x = rect.x(); | 605 char_positon->pt.x = rect.x(); |
| 604 char_positon->pt.y = rect.y(); | 606 char_positon->pt.y = rect.y(); |
| 605 char_positon->cLineHeight = rect.height(); | 607 char_positon->cLineHeight = rect.height(); |
| 606 return 1; // returns non-zero value when succeeded. | 608 return 1; // returns non-zero value when succeeded. |
| 607 } | 609 } |
| 608 | 610 |
| 609 bool InputMethodWin::IsWindowFocused(const TextInputClient* client) const { | 611 bool InputMethodWin::IsWindowFocused(const TextInputClient* client) const { |
| 610 if (!client) | 612 if (!client) |
| 611 return false; | 613 return false; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 if (old_text_input_type != ui::TEXT_INPUT_TYPE_NONE) | 680 if (old_text_input_type != ui::TEXT_INPUT_TYPE_NONE) |
| 679 engine->FocusOut(); | 681 engine->FocusOut(); |
| 680 if (text_input_type != ui::TEXT_INPUT_TYPE_NONE) | 682 if (text_input_type != ui::TEXT_INPUT_TYPE_NONE) |
| 681 engine->FocusIn(context); | 683 engine->FocusIn(context); |
| 682 | 684 |
| 683 ui::IMEBridge::Get()->SetCurrentInputContext(context); | 685 ui::IMEBridge::Get()->SetCurrentInputContext(context); |
| 684 } | 686 } |
| 685 } | 687 } |
| 686 | 688 |
| 687 } // namespace ui | 689 } // namespace ui |
| OLD | NEW |