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
3 // found in the LICENSE file.
5 #include "ui/aura/remote_window_tree_host_win.h"
11 #include "base/message_loop/message_loop.h"
12 #include "ipc/ipc_message.h"
13 #include "ipc/ipc_sender.h"
14 #include "ui/aura/client/aura_constants.h"
15 #include "ui/aura/client/cursor_client.h"
16 #include "ui/aura/root_window.h"
17 #include "ui/aura/window_property.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"
23 #include "ui/base/view_prop.h"
24 #include "ui/events/event_utils.h"
25 #include "ui/events/keycodes/keyboard_code_conversion_win.h"
26 #include "ui/gfx/insets.h"
27 #include "ui/gfx/win/dpi.h"
28 #include "ui/metro_viewer/metro_viewer_messages.h"
34 const char* kWindowTreeHostWinKey = "__AURA_REMOTE_WINDOW_TREE_HOST_WIN__";
36 // Sets the keystate for the virtual key passed in to down or up.
37 void SetKeyState(uint8* key_states, bool key_down, uint32 virtual_key_code) {
41 key_states[virtual_key_code] |= 0x80;
43 key_states[virtual_key_code] &= 0x7F;
46 // Sets the keyboard states for the Shift/Control/Alt/Caps lock keys.
47 void SetVirtualKeyStates(uint32 flags) {
48 uint8 keyboard_state[256] = {0};
49 ::GetKeyboardState(keyboard_state);
51 SetKeyState(keyboard_state, !!(flags & ui::EF_SHIFT_DOWN), VK_SHIFT);
52 SetKeyState(keyboard_state, !!(flags & ui::EF_CONTROL_DOWN), VK_CONTROL);
53 SetKeyState(keyboard_state, !!(flags & ui::EF_ALT_DOWN), VK_MENU);
54 SetKeyState(keyboard_state, !!(flags & ui::EF_CAPS_LOCK_DOWN), VK_CAPITAL);
55 SetKeyState(keyboard_state, !!(flags & ui::EF_LEFT_MOUSE_BUTTON), VK_LBUTTON);
56 SetKeyState(keyboard_state, !!(flags & ui::EF_RIGHT_MOUSE_BUTTON),
58 SetKeyState(keyboard_state, !!(flags & ui::EF_MIDDLE_MOUSE_BUTTON),
61 ::SetKeyboardState(keyboard_state);
64 void FillCompositionText(
65 const base::string16& text,
66 int32 selection_start,
68 const std::vector<metro_viewer::UnderlineInfo>& underlines,
69 ui::CompositionText* composition_text) {
70 composition_text->Clear();
71 composition_text->text = text;
72 composition_text->selection.set_start(selection_start);
73 composition_text->selection.set_end(selection_end);
74 composition_text->underlines.resize(underlines.size());
75 for (size_t i = 0; i < underlines.size(); ++i) {
76 composition_text->underlines[i].start_offset = underlines[i].start_offset;
77 composition_text->underlines[i].end_offset = underlines[i].end_offset;
78 composition_text->underlines[i].color = SK_ColorBLACK;
79 composition_text->underlines[i].thick = underlines[i].thick;
85 void HandleOpenFile(const base::string16& title,
86 const base::FilePath& default_path,
87 const base::string16& filter,
88 const OpenFileCompletion& on_success,
89 const FileSelectionCanceled& on_failure) {
90 DCHECK(aura::RemoteWindowTreeHostWin::Instance());
91 aura::RemoteWindowTreeHostWin::Instance()->HandleOpenFile(title,
98 void HandleOpenMultipleFiles(const base::string16& title,
99 const base::FilePath& default_path,
100 const base::string16& filter,
101 const OpenMultipleFilesCompletion& on_success,
102 const FileSelectionCanceled& on_failure) {
103 DCHECK(aura::RemoteWindowTreeHostWin::Instance());
104 aura::RemoteWindowTreeHostWin::Instance()->HandleOpenMultipleFiles(
112 void HandleSaveFile(const base::string16& title,
113 const base::FilePath& default_path,
114 const base::string16& filter,
116 const base::string16& default_extension,
117 const SaveFileCompletion& on_success,
118 const FileSelectionCanceled& on_failure) {
119 DCHECK(aura::RemoteWindowTreeHostWin::Instance());
120 aura::RemoteWindowTreeHostWin::Instance()->HandleSaveFile(title,
129 void HandleSelectFolder(const base::string16& title,
130 const SelectFolderCompletion& on_success,
131 const FileSelectionCanceled& on_failure) {
132 DCHECK(aura::RemoteWindowTreeHostWin::Instance());
133 aura::RemoteWindowTreeHostWin::Instance()->HandleSelectFolder(title,
138 void HandleActivateDesktop(const base::FilePath& shortcut,
140 DCHECK(aura::RemoteWindowTreeHostWin::Instance());
141 aura::RemoteWindowTreeHostWin::Instance()->HandleActivateDesktop(shortcut,
145 void HandleMetroExit() {
146 DCHECK(aura::RemoteWindowTreeHostWin::Instance());
147 aura::RemoteWindowTreeHostWin::Instance()->HandleMetroExit();
150 RemoteWindowTreeHostWin* g_instance = NULL;
152 RemoteWindowTreeHostWin* RemoteWindowTreeHostWin::Instance() {
155 return Create(gfx::Rect());
158 RemoteWindowTreeHostWin* RemoteWindowTreeHostWin::Create(
159 const gfx::Rect& bounds) {
160 g_instance = g_instance ? g_instance : new RemoteWindowTreeHostWin(bounds);
164 RemoteWindowTreeHostWin::RemoteWindowTreeHostWin(const gfx::Rect& bounds)
165 : remote_window_(NULL),
167 ignore_mouse_moves_until_set_cursor_ack_(false),
169 window_size_(aura::WindowTreeHost::GetNativeScreenSize()) {
170 prop_.reset(new ui::ViewProp(NULL, kWindowTreeHostWinKey, this));
171 CreateCompositor(GetAcceleratedWidget());
174 RemoteWindowTreeHostWin::~RemoteWindowTreeHostWin() {
180 bool RemoteWindowTreeHostWin::IsValid() {
181 return Instance()->remote_window_ != NULL;
184 void RemoteWindowTreeHostWin::SetRemoteWindowHandle(HWND remote_window) {
185 remote_window_ = remote_window;
186 // Do not create compositor here, but in Connected() below.
187 // See http://crbug.com/330179 and http://crbug.com/334380.
190 void RemoteWindowTreeHostWin::Connected(IPC::Sender* host) {
191 CHECK(host_ == NULL);
192 DCHECK(remote_window_);
194 // Recreate the compositor for the target surface represented by the
195 // remote_window HWND.
196 CreateCompositor(remote_window_);
200 void RemoteWindowTreeHostWin::Disconnected() {
201 // Don't CHECK here, Disconnected is called on a channel error which can
202 // happen before we're successfully Connected.
205 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
206 GetRemoteInputMethodPrivate();
207 if (remote_input_method_private)
208 remote_input_method_private->SetRemoteDelegate(NULL);
210 remote_window_ = NULL;
213 bool RemoteWindowTreeHostWin::OnMessageReceived(const IPC::Message& message) {
215 IPC_BEGIN_MESSAGE_MAP(RemoteWindowTreeHostWin, message)
216 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseMoved, OnMouseMoved)
217 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseButton, OnMouseButton)
218 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyDown, OnKeyDown)
219 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyUp, OnKeyUp)
220 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_Character, OnChar)
221 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_WindowActivated,
223 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_EdgeGesture, OnEdgeGesture)
224 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchDown,
226 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchUp,
228 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchMoved,
230 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileSaveAsDone,
232 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileOpenDone,
234 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MultiFileOpenDone,
236 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SelectFolderDone,
238 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursorPosAck,
240 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeCandidatePopupChanged,
241 OnImeCandidatePopupChanged)
242 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeCompositionChanged,
243 OnImeCompositionChanged)
244 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeTextCommitted,
246 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeInputSourceChanged,
247 OnImeInputSourceChanged)
248 IPC_MESSAGE_UNHANDLED(handled = false)
249 IPC_END_MESSAGE_MAP()
253 void RemoteWindowTreeHostWin::HandleOpenURLOnDesktop(
254 const base::FilePath& shortcut,
255 const base::string16& url) {
258 host_->Send(new MetroViewerHostMsg_OpenURLOnDesktop(shortcut, url));
261 void RemoteWindowTreeHostWin::HandleActivateDesktop(
262 const base::FilePath& shortcut,
266 host_->Send(new MetroViewerHostMsg_ActivateDesktop(shortcut, ash_exit));
269 void RemoteWindowTreeHostWin::HandleMetroExit() {
272 host_->Send(new MetroViewerHostMsg_MetroExit());
275 void RemoteWindowTreeHostWin::HandleOpenFile(
276 const base::string16& title,
277 const base::FilePath& default_path,
278 const base::string16& filter,
279 const OpenFileCompletion& on_success,
280 const FileSelectionCanceled& on_failure) {
284 // Can only have one of these operations in flight.
285 DCHECK(file_open_completion_callback_.is_null());
286 DCHECK(failure_callback_.is_null());
288 file_open_completion_callback_ = on_success;
289 failure_callback_ = on_failure;
291 host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title,
297 void RemoteWindowTreeHostWin::HandleOpenMultipleFiles(
298 const base::string16& title,
299 const base::FilePath& default_path,
300 const base::string16& filter,
301 const OpenMultipleFilesCompletion& on_success,
302 const FileSelectionCanceled& on_failure) {
306 // Can only have one of these operations in flight.
307 DCHECK(multi_file_open_completion_callback_.is_null());
308 DCHECK(failure_callback_.is_null());
309 multi_file_open_completion_callback_ = on_success;
310 failure_callback_ = on_failure;
312 host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title,
318 void RemoteWindowTreeHostWin::HandleSaveFile(
319 const base::string16& title,
320 const base::FilePath& default_path,
321 const base::string16& filter,
323 const base::string16& default_extension,
324 const SaveFileCompletion& on_success,
325 const FileSelectionCanceled& on_failure) {
329 MetroViewerHostMsg_SaveAsDialogParams params;
330 params.title = title;
331 params.default_extension = default_extension;
332 params.filter = filter;
333 params.filter_index = filter_index;
334 params.suggested_name = default_path;
336 // Can only have one of these operations in flight.
337 DCHECK(file_saveas_completion_callback_.is_null());
338 DCHECK(failure_callback_.is_null());
339 file_saveas_completion_callback_ = on_success;
340 failure_callback_ = on_failure;
342 host_->Send(new MetroViewerHostMsg_DisplayFileSaveAs(params));
345 void RemoteWindowTreeHostWin::HandleSelectFolder(
346 const base::string16& title,
347 const SelectFolderCompletion& on_success,
348 const FileSelectionCanceled& on_failure) {
352 // Can only have one of these operations in flight.
353 DCHECK(select_folder_completion_callback_.is_null());
354 DCHECK(failure_callback_.is_null());
355 select_folder_completion_callback_ = on_success;
356 failure_callback_ = on_failure;
358 host_->Send(new MetroViewerHostMsg_DisplaySelectFolder(title));
361 void RemoteWindowTreeHostWin::HandleWindowSizeChanged(uint32 width,
363 SetBounds(gfx::Rect(0, 0, width, height));
366 bool RemoteWindowTreeHostWin::IsForegroundWindow() {
367 return ::GetForegroundWindow() == remote_window_;
370 Window* RemoteWindowTreeHostWin::GetAshWindow() {
371 return GetRootWindow()->window();
374 RootWindow* RemoteWindowTreeHostWin::GetRootWindow() {
375 return delegate_->AsRootWindow();
378 gfx::AcceleratedWidget RemoteWindowTreeHostWin::GetAcceleratedWidget() {
380 return remote_window_;
381 // Getting here should only happen for ash_unittests.exe and related code.
382 return ::GetDesktopWindow();
385 void RemoteWindowTreeHostWin::Show() {
386 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
387 GetRemoteInputMethodPrivate();
388 if (remote_input_method_private)
389 remote_input_method_private->SetRemoteDelegate(this);
392 void RemoteWindowTreeHostWin::Hide() {
396 void RemoteWindowTreeHostWin::ToggleFullScreen() {
399 gfx::Rect RemoteWindowTreeHostWin::GetBounds() const {
400 return gfx::Rect(window_size_);
403 void RemoteWindowTreeHostWin::SetBounds(const gfx::Rect& bounds) {
404 window_size_ = bounds.size();
405 NotifyHostResized(bounds.size());
408 gfx::Insets RemoteWindowTreeHostWin::GetInsets() const {
409 return gfx::Insets();
412 void RemoteWindowTreeHostWin::SetInsets(const gfx::Insets& insets) {
415 gfx::Point RemoteWindowTreeHostWin::GetLocationOnNativeScreen() const {
416 return gfx::Point(0, 0);
419 void RemoteWindowTreeHostWin::SetCapture() {
422 void RemoteWindowTreeHostWin::ReleaseCapture() {
425 bool RemoteWindowTreeHostWin::QueryMouseLocation(gfx::Point* location_return) {
426 aura::client::CursorClient* cursor_client =
427 aura::client::GetCursorClient(GetRootWindow()->window());
428 if (cursor_client && !cursor_client->IsMouseEventsEnabled()) {
429 *location_return = gfx::Point(0, 0);
435 gfx::Point(static_cast<int>(pt.x), static_cast<int>(pt.y));
439 bool RemoteWindowTreeHostWin::ConfineCursorToRootWindow() {
443 void RemoteWindowTreeHostWin::UnConfineCursor() {
446 void RemoteWindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) {
450 new MetroViewerHostMsg_SetCursor(uint64(native_cursor.platform())));
453 void RemoteWindowTreeHostWin::MoveCursorToNative(const gfx::Point& location) {
454 VLOG(1) << "In MoveCursorTo: " << location.x() << ", " << location.y();
458 // This function can be called in cases like when the mouse cursor is
459 // restricted within a viewport (For e.g. LockCursor) which assumes that
460 // subsequent mouse moves would be received starting with the new cursor
461 // coordinates. This is a challenge for Windows ASH for the reasons
463 // Other cases which don't expect this behavior should continue to work
466 // The mouse events are received by the viewer process and sent to the
467 // browser. If we invoke the SetCursor API here we continue to receive
468 // mouse messages from the viewer which were posted before the SetCursor
469 // API executes which messes up the state in the browser. To workaround
470 // this we invoke the SetCursor API in the viewer process and ignore
471 // mouse messages until we received an ACK from the viewer indicating that
472 // the SetCursor operation completed.
473 ignore_mouse_moves_until_set_cursor_ack_ = true;
474 VLOG(1) << "In MoveCursorTo. Sending IPC";
475 host_->Send(new MetroViewerHostMsg_SetCursorPos(location.x(), location.y()));
478 void RemoteWindowTreeHostWin::OnCursorVisibilityChangedNative(bool show) {
482 void RemoteWindowTreeHostWin::PostNativeEvent(
483 const base::NativeEvent& native_event) {
486 void RemoteWindowTreeHostWin::OnDeviceScaleFactorChanged(
487 float device_scale_factor) {
491 void RemoteWindowTreeHostWin::PrepareForShutdown() {
494 ui::EventProcessor* RemoteWindowTreeHostWin::GetEventProcessor() {
495 return delegate_->GetEventProcessor();
498 void RemoteWindowTreeHostWin::CancelComposition() {
501 host_->Send(new MetroViewerHostMsg_ImeCancelComposition);
504 void RemoteWindowTreeHostWin::OnTextInputClientUpdated(
505 const std::vector<int32>& input_scopes,
506 const std::vector<gfx::Rect>& composition_character_bounds) {
509 std::vector<metro_viewer::CharacterBounds> character_bounds;
510 for (size_t i = 0; i < composition_character_bounds.size(); ++i) {
511 const gfx::Rect& rect = composition_character_bounds[i];
512 metro_viewer::CharacterBounds bounds;
513 bounds.left = rect.x();
514 bounds.top = rect.y();
515 bounds.right = rect.right();
516 bounds.bottom = rect.bottom();
517 character_bounds.push_back(bounds);
519 host_->Send(new MetroViewerHostMsg_ImeTextInputClientUpdated(
520 input_scopes, character_bounds));
523 gfx::Point PointFromNativeEvent(int32 x, int32 y) {
524 static float scale_factor = gfx::GetModernUIScale();
525 gfx::Point result( x * scale_factor, y * scale_factor);
529 void RemoteWindowTreeHostWin::OnMouseMoved(int32 x, int32 y, int32 flags) {
530 if (ignore_mouse_moves_until_set_cursor_ack_)
533 gfx::Point location = PointFromNativeEvent(x, y);
534 ui::MouseEvent event(ui::ET_MOUSE_MOVED, location, location, flags, 0);
535 SendEventToProcessor(&event);
538 void RemoteWindowTreeHostWin::OnMouseButton(
539 const MetroViewerHostMsg_MouseButtonParams& params) {
540 gfx::Point location = PointFromNativeEvent(params.x, params.y);
541 ui::MouseEvent mouse_event(params.event_type, location, location,
542 static_cast<int>(params.flags),
543 static_cast<int>(params.changed_button));
545 SetEventFlags(params.flags | key_event_flags());
546 if (params.event_type == ui::ET_MOUSEWHEEL) {
547 int x_offset = params.is_horizontal_wheel ? params.extra : 0;
548 int y_offset = !params.is_horizontal_wheel ? params.extra : 0;
549 ui::MouseWheelEvent wheel_event(mouse_event, x_offset, y_offset);
550 SendEventToProcessor(&wheel_event);
551 } else if (params.event_type == ui::ET_MOUSE_PRESSED) {
552 // TODO(shrikant): Ideally modify code in event.cc by adding automatic
553 // tracking of double clicks in synthetic MouseEvent constructor code.
554 // Non-synthetic MouseEvent constructor code does automatically track
555 // this. Need to use some caution while modifying synthetic constructor
556 // as many tests and other code paths depend on it and apparently
557 // specifically depend on non implicit tracking of previous mouse event.
558 if (last_mouse_click_event_ &&
559 ui::MouseEvent::IsRepeatedClickEvent(mouse_event,
560 *last_mouse_click_event_)) {
561 mouse_event.SetClickCount(2);
563 mouse_event.SetClickCount(1);
565 last_mouse_click_event_ .reset(new ui::MouseEvent(mouse_event));
566 SendEventToProcessor(&mouse_event);
568 SendEventToProcessor(&mouse_event);
572 void RemoteWindowTreeHostWin::OnKeyDown(uint32 vkey,
576 DispatchKeyboardMessage(ui::ET_KEY_PRESSED, vkey, repeat_count, scan_code,
580 void RemoteWindowTreeHostWin::OnKeyUp(uint32 vkey,
584 DispatchKeyboardMessage(ui::ET_KEY_RELEASED, vkey, repeat_count, scan_code,
588 void RemoteWindowTreeHostWin::OnChar(uint32 key_code,
592 DispatchKeyboardMessage(ui::ET_KEY_PRESSED, key_code, repeat_count,
593 scan_code, flags, true);
596 void RemoteWindowTreeHostWin::OnWindowActivated() {
597 delegate_->OnHostActivated();
600 void RemoteWindowTreeHostWin::OnEdgeGesture() {
601 ui::GestureEvent event(
602 ui::ET_GESTURE_WIN8_EDGE_SWIPE,
606 ui::EventTimeForNow(),
607 ui::GestureEventDetails(ui::ET_GESTURE_WIN8_EDGE_SWIPE, 0, 0),
609 SendEventToProcessor(&event);
612 void RemoteWindowTreeHostWin::OnTouchDown(int32 x,
616 gfx::Point location = PointFromNativeEvent(x, y);
617 ui::TouchEvent event(ui::ET_TOUCH_PRESSED,
620 base::TimeDelta::FromMicroseconds(timestamp));
621 SendEventToProcessor(&event);
624 void RemoteWindowTreeHostWin::OnTouchUp(int32 x,
628 gfx::Point location = PointFromNativeEvent(x, y);
629 ui::TouchEvent event(ui::ET_TOUCH_RELEASED,
632 base::TimeDelta::FromMicroseconds(timestamp));
633 SendEventToProcessor(&event);
636 void RemoteWindowTreeHostWin::OnTouchMoved(int32 x,
640 gfx::Point location = PointFromNativeEvent(x, y);
641 ui::TouchEvent event(ui::ET_TOUCH_MOVED,
644 base::TimeDelta::FromMicroseconds(timestamp));
645 SendEventToProcessor(&event);
648 void RemoteWindowTreeHostWin::OnFileSaveAsDone(bool success,
649 const base::FilePath& filename,
652 file_saveas_completion_callback_.Run(filename, filter_index, NULL);
654 failure_callback_.Run(NULL);
655 file_saveas_completion_callback_.Reset();
656 failure_callback_.Reset();
660 void RemoteWindowTreeHostWin::OnFileOpenDone(bool success,
661 const base::FilePath& filename) {
663 file_open_completion_callback_.Run(base::FilePath(filename), 0, NULL);
665 failure_callback_.Run(NULL);
666 file_open_completion_callback_.Reset();
667 failure_callback_.Reset();
670 void RemoteWindowTreeHostWin::OnMultiFileOpenDone(
672 const std::vector<base::FilePath>& files) {
674 multi_file_open_completion_callback_.Run(files, NULL);
676 failure_callback_.Run(NULL);
677 multi_file_open_completion_callback_.Reset();
678 failure_callback_.Reset();
681 void RemoteWindowTreeHostWin::OnSelectFolderDone(
683 const base::FilePath& folder) {
685 select_folder_completion_callback_.Run(base::FilePath(folder), 0, NULL);
687 failure_callback_.Run(NULL);
688 select_folder_completion_callback_.Reset();
689 failure_callback_.Reset();
692 void RemoteWindowTreeHostWin::OnSetCursorPosAck() {
693 DCHECK(ignore_mouse_moves_until_set_cursor_ack_);
694 ignore_mouse_moves_until_set_cursor_ack_ = false;
697 ui::RemoteInputMethodPrivateWin*
698 RemoteWindowTreeHostWin::GetRemoteInputMethodPrivate() {
699 ui::InputMethod* input_method = GetAshWindow()->GetProperty(
700 aura::client::kRootWindowInputMethodKey);
701 return ui::RemoteInputMethodPrivateWin::Get(input_method);
704 void RemoteWindowTreeHostWin::OnImeCandidatePopupChanged(bool visible) {
705 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
706 GetRemoteInputMethodPrivate();
707 if (!remote_input_method_private)
709 remote_input_method_private->OnCandidatePopupChanged(visible);
712 void RemoteWindowTreeHostWin::OnImeCompositionChanged(
713 const base::string16& text,
714 int32 selection_start,
716 const std::vector<metro_viewer::UnderlineInfo>& underlines) {
717 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
718 GetRemoteInputMethodPrivate();
719 if (!remote_input_method_private)
721 ui::CompositionText composition_text;
723 text, selection_start, selection_end, underlines, &composition_text);
724 remote_input_method_private->OnCompositionChanged(composition_text);
727 void RemoteWindowTreeHostWin::OnImeTextCommitted(const base::string16& text) {
728 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
729 GetRemoteInputMethodPrivate();
730 if (!remote_input_method_private)
732 remote_input_method_private->OnTextCommitted(text);
735 void RemoteWindowTreeHostWin::OnImeInputSourceChanged(uint16 language_id,
737 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
738 GetRemoteInputMethodPrivate();
739 if (!remote_input_method_private)
741 remote_input_method_private->OnInputSourceChanged(language_id, is_ime);
744 void RemoteWindowTreeHostWin::DispatchKeyboardMessage(ui::EventType type,
750 SetEventFlags(flags | mouse_event_flags());
751 if (base::MessageLoop::current()->IsNested()) {
752 int index = (flags & ui::EF_ALT_DOWN) ? 1 : 0;
753 const int char_message[] = {WM_CHAR, WM_SYSCHAR};
754 const int keydown_message[] = {WM_KEYDOWN, WM_SYSKEYDOWN};
755 const int keyup_message[] = {WM_KEYUP, WM_SYSKEYUP};
756 uint32 message = is_character
757 ? char_message[index]
758 : (type == ui::ET_KEY_PRESSED ? keydown_message[index]
759 : keyup_message[index]);
760 ::PostThreadMessage(::GetCurrentThreadId(),
763 repeat_count | scan_code >> 15);
765 ui::KeyEvent event(type,
766 ui::KeyboardCodeForWindowsKeyCode(vkey),
769 SendEventToProcessor(&event);
773 void RemoteWindowTreeHostWin::SetEventFlags(uint32 flags) {
774 if (flags == event_flags_)
776 event_flags_ = flags;
777 SetVirtualKeyStates(event_flags_);