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 #include <cwctype> | 9 #include <cwctype> |
10 | 10 |
11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "ui/base/ime/ime_bridge.h" | 14 #include "ui/base/ime/ime_bridge.h" |
15 #include "ui/base/ime/ime_engine_handler_interface.h" | 15 #include "ui/base/ime/ime_engine_handler_interface.h" |
16 #include "ui/base/ime/text_input_client.h" | 16 #include "ui/base/ime/text_input_client.h" |
17 #include "ui/base/ime/win/tsf_input_scope.h" | 17 #include "ui/base/ime/win/tsf_input_scope.h" |
18 #include "ui/base/ui_base_switches.h" | 18 #include "ui/base/ui_base_switches.h" |
19 #include "ui/display/win/screen_win.h" | |
20 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
21 #include "ui/events/event_constants.h" | 20 #include "ui/events/event_constants.h" |
22 #include "ui/events/event_utils.h" | 21 #include "ui/events/event_utils.h" |
23 #include "ui/events/keycodes/keyboard_codes.h" | 22 #include "ui/events/keycodes/keyboard_codes.h" |
23 #include "ui/gfx/geometry/rect.h" | |
24 #include "ui/gfx/win/hwnd_util.h" | 24 #include "ui/gfx/win/hwnd_util.h" |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 ui::IMEEngineHandlerInterface* GetEngine() { | 28 ui::IMEEngineHandlerInterface* GetEngine() { |
29 if (ui::IMEBridge::Get()) | 29 if (ui::IMEBridge::Get()) |
30 return ui::IMEBridge::Get()->GetCurrentEngineHandler(); | 30 return ui::IMEBridge::Get()->GetCurrentEngineHandler(); |
31 return nullptr; | 31 return nullptr; |
32 } | 32 } |
33 | 33 |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 text_input_type != TEXT_INPUT_TYPE_PASSWORD && GetEngine()) { | 226 text_input_type != TEXT_INPUT_TYPE_PASSWORD && GetEngine()) { |
227 // |enabled_| == false could be faked, and the engine should rely on the | 227 // |enabled_| == false could be faked, and the engine should rely on the |
228 // real type from GetTextInputType(). | 228 // real type from GetTextInputType(). |
229 GetEngine()->SetCompositionBounds(GetCompositionBounds(client)); | 229 GetEngine()->SetCompositionBounds(GetCompositionBounds(client)); |
230 } | 230 } |
231 if (!enabled_) | 231 if (!enabled_) |
232 return; | 232 return; |
233 | 233 |
234 // The current text input type should not be NONE if |client| is focused. | 234 // The current text input type should not be NONE if |client| is focused. |
235 DCHECK(!IsTextInputTypeNone()); | 235 DCHECK(!IsTextInputTypeNone()); |
236 // Tentatively assume that the returned value is DIP (Density Independent | 236 // Windows IME uses the non-dip coordinates. |
237 // Pixel). See the comment in text_input_client.h and http://crbug.com/360334. | 237 // See the comment in text_input_client.h and http://crbug.com/360334. |
238 const gfx::Rect dip_screen_bounds(GetTextInputClient()->GetCaretBounds()); | 238 const gfx::Rect dip_screen_bounds(GetTextInputClient()->GetCaretBounds()); |
239 const gfx::Rect screen_bounds = | 239 const gfx::Rect screen_bounds = |
240 display::win::ScreenWin::DIPToScreenRect(toplevel_window_handle_, | 240 gfx::ScaleToEnclosingRect( |
sadrul
2016/12/22 01:30:22
Does the old code not do the right thing, because
Shu Chen
2016/12/22 03:02:27
The old code does the right thing but I think it w
| |
241 dip_screen_bounds); | 241 dip_screen_bounds, GetTextInputClient()->GetScaleFactor()); |
242 | 242 |
243 HWND attached_window = toplevel_window_handle_; | 243 HWND attached_window = toplevel_window_handle_; |
244 // TODO(ime): see comment in TextInputClient::GetCaretBounds(), this | 244 // TODO(ime): see comment in TextInputClient::GetCaretBounds(), this |
245 // conversion shouldn't be necessary. | 245 // conversion shouldn't be necessary. |
246 RECT r = {}; | 246 RECT r = {}; |
247 GetClientRect(attached_window, &r); | 247 GetClientRect(attached_window, &r); |
248 POINT window_point = { screen_bounds.x(), screen_bounds.y() }; | 248 POINT window_point = { screen_bounds.x(), screen_bounds.y() }; |
249 ScreenToClient(attached_window, &window_point); | 249 ScreenToClient(attached_window, &window_point); |
250 gfx::Rect caret_rect(gfx::Point(window_point.x, window_point.y), | 250 gfx::Rect caret_rect(gfx::Point(window_point.x, window_point.y), |
251 screen_bounds.size()); | 251 screen_bounds.size()); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 if (!char_positon) | 623 if (!char_positon) |
624 return 0; | 624 return 0; |
625 | 625 |
626 if (char_positon->dwSize < sizeof(IMECHARPOSITION)) | 626 if (char_positon->dwSize < sizeof(IMECHARPOSITION)) |
627 return 0; | 627 return 0; |
628 | 628 |
629 ui::TextInputClient* client = GetTextInputClient(); | 629 ui::TextInputClient* client = GetTextInputClient(); |
630 if (!client) | 630 if (!client) |
631 return 0; | 631 return 0; |
632 | 632 |
633 // Tentatively assume that the returned value from |client| is DIP (Density | |
634 // Independent Pixel). See the comment in text_input_client.h and | |
635 // http://crbug.com/360334. | |
636 gfx::Rect dip_rect; | 633 gfx::Rect dip_rect; |
637 if (client->HasCompositionText()) { | 634 if (client->HasCompositionText()) { |
638 if (!client->GetCompositionCharacterBounds(char_positon->dwCharPos, | 635 if (!client->GetCompositionCharacterBounds(char_positon->dwCharPos, |
639 &dip_rect)) { | 636 &dip_rect)) { |
640 return 0; | 637 return 0; |
641 } | 638 } |
642 } else { | 639 } else { |
643 // If there is no composition and the first character is queried, returns | 640 // If there is no composition and the first character is queried, returns |
644 // the caret bounds. This behavior is the same to that of RichEdit control. | 641 // the caret bounds. This behavior is the same to that of RichEdit control. |
645 if (char_positon->dwCharPos != 0) | 642 if (char_positon->dwCharPos != 0) |
646 return 0; | 643 return 0; |
647 dip_rect = client->GetCaretBounds(); | 644 dip_rect = client->GetCaretBounds(); |
648 } | 645 } |
646 // Windows IME uses the non-dip coordinates. | |
647 // See the comment in text_input_client.h and http://crbug.com/360334. | |
649 const gfx::Rect rect = | 648 const gfx::Rect rect = |
650 display::win::ScreenWin::DIPToScreenRect(toplevel_window_handle_, | 649 gfx::ScaleToEnclosingRect(dip_rect, client->GetScaleFactor()); |
sadrul
2016/12/22 01:30:22
Can you use ConvertRectToDIP/ConvertRectToPixel in
Shu Chen
2016/12/22 03:02:27
I don't think so, because that would require a Lay
| |
651 dip_rect); | |
652 | 650 |
653 char_positon->pt.x = rect.x(); | 651 char_positon->pt.x = rect.x(); |
654 char_positon->pt.y = rect.y(); | 652 char_positon->pt.y = rect.y(); |
655 char_positon->cLineHeight = rect.height(); | 653 char_positon->cLineHeight = rect.height(); |
656 return 1; // returns non-zero value when succeeded. | 654 return 1; // returns non-zero value when succeeded. |
657 } | 655 } |
658 | 656 |
659 bool InputMethodWin::IsWindowFocused(const TextInputClient* client) const { | 657 bool InputMethodWin::IsWindowFocused(const TextInputClient* client) const { |
660 if (!client) | 658 if (!client) |
661 return false; | 659 return false; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 ui::IMEEngineHandlerInterface* engine = GetEngine(); | 731 ui::IMEEngineHandlerInterface* engine = GetEngine(); |
734 if (engine) { | 732 if (engine) { |
735 if (old_text_input_type != ui::TEXT_INPUT_TYPE_NONE) | 733 if (old_text_input_type != ui::TEXT_INPUT_TYPE_NONE) |
736 engine->FocusOut(); | 734 engine->FocusOut(); |
737 if (GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) | 735 if (GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE) |
738 engine->FocusIn(context); | 736 engine->FocusIn(context); |
739 } | 737 } |
740 } | 738 } |
741 | 739 |
742 } // namespace ui | 740 } // namespace ui |
OLD | NEW |