Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: ui/aura/remote_root_window_host_win.cc

Issue 83233002: Enable basic IME functionality under Ash on Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comment from ananta. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/aura/remote_root_window_host_win.h" 5 #include "ui/aura/remote_root_window_host_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "ipc/ipc_message.h" 12 #include "ipc/ipc_message.h"
13 #include "ipc/ipc_sender.h" 13 #include "ipc/ipc_sender.h"
14 #include "ui/aura/client/aura_constants.h"
14 #include "ui/aura/client/cursor_client.h" 15 #include "ui/aura/client/cursor_client.h"
15 #include "ui/aura/root_window.h" 16 #include "ui/aura/root_window.h"
17 #include "ui/aura/window_property.h"
16 #include "ui/base/cursor/cursor_loader_win.h" 18 #include "ui/base/cursor/cursor_loader_win.h"
19 #include "ui/base/ime/composition_text.h"
20 #include "ui/base/ime/input_method.h"
21 #include "ui/base/ime/remote_input_method_win.h"
22 #include "ui/base/ime/text_input_client.h"
17 #include "ui/events/event_utils.h" 23 #include "ui/events/event_utils.h"
18 #include "ui/events/keycodes/keyboard_code_conversion_win.h" 24 #include "ui/events/keycodes/keyboard_code_conversion_win.h"
19 #include "ui/base/view_prop.h" 25 #include "ui/base/view_prop.h"
20 #include "ui/gfx/insets.h" 26 #include "ui/gfx/insets.h"
21 #include "ui/metro_viewer/metro_viewer_messages.h" 27 #include "ui/metro_viewer/metro_viewer_messages.h"
22 28
23 namespace aura { 29 namespace aura {
24 30
25 namespace { 31 namespace {
26 32
(...skipping 20 matching lines...) Expand all
47 SetKeyState(keyboard_state, !!(flags & ui::EF_CAPS_LOCK_DOWN), VK_CAPITAL); 53 SetKeyState(keyboard_state, !!(flags & ui::EF_CAPS_LOCK_DOWN), VK_CAPITAL);
48 SetKeyState(keyboard_state, !!(flags & ui::EF_LEFT_MOUSE_BUTTON), VK_LBUTTON); 54 SetKeyState(keyboard_state, !!(flags & ui::EF_LEFT_MOUSE_BUTTON), VK_LBUTTON);
49 SetKeyState(keyboard_state, !!(flags & ui::EF_RIGHT_MOUSE_BUTTON), 55 SetKeyState(keyboard_state, !!(flags & ui::EF_RIGHT_MOUSE_BUTTON),
50 VK_RBUTTON); 56 VK_RBUTTON);
51 SetKeyState(keyboard_state, !!(flags & ui::EF_MIDDLE_MOUSE_BUTTON), 57 SetKeyState(keyboard_state, !!(flags & ui::EF_MIDDLE_MOUSE_BUTTON),
52 VK_MBUTTON); 58 VK_MBUTTON);
53 59
54 ::SetKeyboardState(keyboard_state); 60 ::SetKeyboardState(keyboard_state);
55 } 61 }
56 62
63 void FillCompositionText(
64 const string16& text,
65 int32 selection_start,
66 int32 selection_end,
67 const std::vector<metro_viewer::UnderlineInfo>& underlines,
68 ui::CompositionText* composition_text) {
69 composition_text->Clear();
70 composition_text->text = text;
71 composition_text->selection.set_start(selection_start);
72 composition_text->selection.set_end(selection_end);
73 composition_text->underlines.resize(underlines.size());
74 for (size_t i = 0; i < underlines.size(); ++i) {
75 composition_text->underlines[i].start_offset = underlines[i].start_offset;
76 composition_text->underlines[i].end_offset = underlines[i].end_offset;
77 composition_text->underlines[i].color = SK_ColorBLACK;
78 composition_text->underlines[i].thick = underlines[i].thick;
79 }
80 }
81
57 } // namespace 82 } // namespace
58 83
59 void HandleOpenFile(const base::string16& title, 84 void HandleOpenFile(const base::string16& title,
60 const base::FilePath& default_path, 85 const base::FilePath& default_path,
61 const base::string16& filter, 86 const base::string16& filter,
62 const OpenFileCompletion& on_success, 87 const OpenFileCompletion& on_success,
63 const FileSelectionCanceled& on_failure) { 88 const FileSelectionCanceled& on_failure) {
64 DCHECK(aura::RemoteRootWindowHostWin::Instance()); 89 DCHECK(aura::RemoteRootWindowHostWin::Instance());
65 aura::RemoteRootWindowHostWin::Instance()->HandleOpenFile(title, 90 aura::RemoteRootWindowHostWin::Instance()->HandleOpenFile(title,
66 default_path, 91 default_path,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 169
145 void RemoteRootWindowHostWin::Connected(IPC::Sender* host, HWND remote_window) { 170 void RemoteRootWindowHostWin::Connected(IPC::Sender* host, HWND remote_window) {
146 CHECK(host_ == NULL); 171 CHECK(host_ == NULL);
147 host_ = host; 172 host_ = host;
148 remote_window_ = remote_window; 173 remote_window_ = remote_window;
149 } 174 }
150 175
151 void RemoteRootWindowHostWin::Disconnected() { 176 void RemoteRootWindowHostWin::Disconnected() {
152 // Don't CHECK here, Disconnected is called on a channel error which can 177 // Don't CHECK here, Disconnected is called on a channel error which can
153 // happen before we're successfully Connected. 178 // happen before we're successfully Connected.
179 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
180 GetRemoteInputMethodPrivate();
181 if (remote_input_method_private)
182 remote_input_method_private->SetRemoteDelegate(NULL);
154 host_ = NULL; 183 host_ = NULL;
155 remote_window_ = NULL; 184 remote_window_ = NULL;
156 } 185 }
157 186
158 bool RemoteRootWindowHostWin::OnMessageReceived(const IPC::Message& message) { 187 bool RemoteRootWindowHostWin::OnMessageReceived(const IPC::Message& message) {
159 bool handled = true; 188 bool handled = true;
160 IPC_BEGIN_MESSAGE_MAP(RemoteRootWindowHostWin, message) 189 IPC_BEGIN_MESSAGE_MAP(RemoteRootWindowHostWin, message)
161 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseMoved, OnMouseMoved) 190 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseMoved, OnMouseMoved)
162 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseButton, OnMouseButton) 191 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseButton, OnMouseButton)
163 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyDown, OnKeyDown) 192 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyDown, OnKeyDown)
(...skipping 14 matching lines...) Expand all
178 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MultiFileOpenDone, 207 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MultiFileOpenDone,
179 OnMultiFileOpenDone) 208 OnMultiFileOpenDone)
180 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SelectFolderDone, 209 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SelectFolderDone,
181 OnSelectFolderDone) 210 OnSelectFolderDone)
182 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursorPosAck, 211 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursorPosAck,
183 OnSetCursorPosAck) 212 OnSetCursorPosAck)
184 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_WindowSizeChanged, 213 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_WindowSizeChanged,
185 OnWindowSizeChanged) 214 OnWindowSizeChanged)
186 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ActivateDesktopDone, 215 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ActivateDesktopDone,
187 OnDesktopActivated) 216 OnDesktopActivated)
217 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeCompositionChanged,
218 OnImeCompositionChanged)
219 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeTextCommitted,
220 OnImeTextCommitted)
188 IPC_MESSAGE_UNHANDLED(handled = false) 221 IPC_MESSAGE_UNHANDLED(handled = false)
189 IPC_END_MESSAGE_MAP() 222 IPC_END_MESSAGE_MAP()
190 return handled; 223 return handled;
191 } 224 }
192 225
193 void RemoteRootWindowHostWin::HandleOpenURLOnDesktop( 226 void RemoteRootWindowHostWin::HandleOpenURLOnDesktop(
194 const base::FilePath& shortcut, 227 const base::FilePath& shortcut,
195 const base::string16& url) { 228 const base::string16& url) {
196 if (!host_) 229 if (!host_)
197 return; 230 return;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 } 340 }
308 341
309 gfx::AcceleratedWidget RemoteRootWindowHostWin::GetAcceleratedWidget() { 342 gfx::AcceleratedWidget RemoteRootWindowHostWin::GetAcceleratedWidget() {
310 if (remote_window_) 343 if (remote_window_)
311 return remote_window_; 344 return remote_window_;
312 // Getting here should only happen for ash_unittests.exe and related code. 345 // Getting here should only happen for ash_unittests.exe and related code.
313 return ::GetDesktopWindow(); 346 return ::GetDesktopWindow();
314 } 347 }
315 348
316 void RemoteRootWindowHostWin::Show() { 349 void RemoteRootWindowHostWin::Show() {
350 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
351 GetRemoteInputMethodPrivate();
352 if (remote_input_method_private)
353 remote_input_method_private->SetRemoteDelegate(this);
317 } 354 }
318 355
319 void RemoteRootWindowHostWin::Hide() { 356 void RemoteRootWindowHostWin::Hide() {
320 NOTIMPLEMENTED(); 357 NOTIMPLEMENTED();
321 } 358 }
322 359
323 void RemoteRootWindowHostWin::ToggleFullScreen() { 360 void RemoteRootWindowHostWin::ToggleFullScreen() {
324 } 361 }
325 362
326 gfx::Rect RemoteRootWindowHostWin::GetBounds() const { 363 gfx::Rect RemoteRootWindowHostWin::GetBounds() const {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 448 }
412 449
413 void RemoteRootWindowHostWin::OnDeviceScaleFactorChanged( 450 void RemoteRootWindowHostWin::OnDeviceScaleFactorChanged(
414 float device_scale_factor) { 451 float device_scale_factor) {
415 NOTIMPLEMENTED(); 452 NOTIMPLEMENTED();
416 } 453 }
417 454
418 void RemoteRootWindowHostWin::PrepareForShutdown() { 455 void RemoteRootWindowHostWin::PrepareForShutdown() {
419 } 456 }
420 457
458 void RemoteRootWindowHostWin::CancelComposition() {
459 host_->Send(new MetroViewerHostMsg_ImeCancelComposition);
460 }
461
462 void RemoteRootWindowHostWin::OnTextInputClientUpdated(
463 const std::vector<int32>& input_scopes,
464 const std::vector<gfx::Rect>& composition_character_bounds) {
465 std::vector<metro_viewer::CharacterBounds> character_bounds;
466 for (size_t i = 0; i < composition_character_bounds.size(); ++i) {
467 const gfx::Rect& rect = composition_character_bounds[i];
468 metro_viewer::CharacterBounds bounds;
469 bounds.left = rect.x();
470 bounds.top = rect.y();
471 bounds.right = rect.right();
472 bounds.bottom = rect.bottom();
473 character_bounds.push_back(bounds);
474 }
475 host_->Send(new MetroViewerHostMsg_ImeTextInputClientUpdated(
476 input_scopes, character_bounds));
477 }
478
421 void RemoteRootWindowHostWin::OnMouseMoved(int32 x, int32 y, int32 flags) { 479 void RemoteRootWindowHostWin::OnMouseMoved(int32 x, int32 y, int32 flags) {
422 if (ignore_mouse_moves_until_set_cursor_ack_) 480 if (ignore_mouse_moves_until_set_cursor_ack_)
423 return; 481 return;
424 482
425 gfx::Point location(x, y); 483 gfx::Point location(x, y);
426 ui::MouseEvent event(ui::ET_MOUSE_MOVED, location, location, flags); 484 ui::MouseEvent event(ui::ET_MOUSE_MOVED, location, location, flags);
427 delegate_->OnHostMouseEvent(&event); 485 delegate_->OnHostMouseEvent(&event);
428 } 486 }
429 487
430 void RemoteRootWindowHostWin::OnMouseButton( 488 void RemoteRootWindowHostWin::OnMouseButton(
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 void RemoteRootWindowHostWin::OnWindowSizeChanged(uint32 width, uint32 height) { 632 void RemoteRootWindowHostWin::OnWindowSizeChanged(uint32 width, uint32 height) {
575 SetBounds(gfx::Rect(0, 0, width, height)); 633 SetBounds(gfx::Rect(0, 0, width, height));
576 } 634 }
577 635
578 void RemoteRootWindowHostWin::OnDesktopActivated() { 636 void RemoteRootWindowHostWin::OnDesktopActivated() {
579 ActivateDesktopCompleted temp = activate_completed_callback_; 637 ActivateDesktopCompleted temp = activate_completed_callback_;
580 activate_completed_callback_.Reset(); 638 activate_completed_callback_.Reset();
581 temp.Run(); 639 temp.Run();
582 } 640 }
583 641
642 ui::RemoteInputMethodPrivateWin*
643 RemoteRootWindowHostWin::GetRemoteInputMethodPrivate() {
644 ui::InputMethod* input_method = GetAshWindow()->GetProperty(
645 aura::client::kRootWindowInputMethodKey);
646 return ui::RemoteInputMethodPrivateWin::Get(input_method);
647 }
648
649 void RemoteRootWindowHostWin::OnImeCompositionChanged(
650 const string16& text,
651 int32 selection_start,
652 int32 selection_end,
653 const std::vector<metro_viewer::UnderlineInfo>& underlines) {
654 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
655 GetRemoteInputMethodPrivate();
656 if (!remote_input_method_private)
657 return;
658 ui::CompositionText composition_text;
659 FillCompositionText(
660 text, selection_start, selection_end, underlines, &composition_text);
661 remote_input_method_private->OnCompositionChanged(composition_text);
662 }
663
664 void RemoteRootWindowHostWin::OnImeTextCommitted(const string16& text) {
665 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
666 GetRemoteInputMethodPrivate();
667 if (!remote_input_method_private)
668 return;
669 remote_input_method_private->OnTextCommitted(text);
670 }
671
584 void RemoteRootWindowHostWin::DispatchKeyboardMessage(ui::EventType type, 672 void RemoteRootWindowHostWin::DispatchKeyboardMessage(ui::EventType type,
585 uint32 vkey, 673 uint32 vkey,
586 uint32 repeat_count, 674 uint32 repeat_count,
587 uint32 scan_code, 675 uint32 scan_code,
588 uint32 flags, 676 uint32 flags,
589 bool is_character) { 677 bool is_character) {
590 SetEventFlags(flags | mouse_event_flags()); 678 SetEventFlags(flags | mouse_event_flags());
591 if (base::MessageLoop::current()->IsNested()) { 679 if (base::MessageLoop::current()->IsNested()) {
592 uint32 message = is_character ? WM_CHAR : 680 uint32 message = is_character ? WM_CHAR :
593 (type == ui::ET_KEY_PRESSED ? WM_KEYDOWN : WM_KEYUP); 681 (type == ui::ET_KEY_PRESSED ? WM_KEYDOWN : WM_KEYUP);
(...skipping 11 matching lines...) Expand all
605 } 693 }
606 694
607 void RemoteRootWindowHostWin::SetEventFlags(uint32 flags) { 695 void RemoteRootWindowHostWin::SetEventFlags(uint32 flags) {
608 if (flags == event_flags_) 696 if (flags == event_flags_)
609 return; 697 return;
610 event_flags_ = flags; 698 event_flags_ = flags;
611 SetVirtualKeyStates(event_flags_); 699 SetVirtualKeyStates(event_flags_);
612 } 700 }
613 701
614 } // namespace aura 702 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698