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/window_event_dispatcher.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;
153 RemoteWindowTreeHostWin* RemoteWindowTreeHostWin::Instance() {
155 g_instance = new RemoteWindowTreeHostWin(gfx::Rect());
160 void RemoteWindowTreeHostWin::SetInstance(RemoteWindowTreeHostWin* instance) {
162 g_instance = instance;
165 RemoteWindowTreeHostWin::RemoteWindowTreeHostWin(const gfx::Rect& bounds)
166 : remote_window_(NULL),
168 ignore_mouse_moves_until_set_cursor_ack_(false),
170 window_size_(aura::WindowTreeHost::GetNativeScreenSize()) {
171 prop_.reset(new ui::ViewProp(NULL, kWindowTreeHostWinKey, this));
172 CreateCompositor(GetAcceleratedWidget());
175 RemoteWindowTreeHostWin::~RemoteWindowTreeHostWin() {
182 bool RemoteWindowTreeHostWin::IsValid() {
183 return Instance()->remote_window_ != NULL;
186 void RemoteWindowTreeHostWin::SetRemoteWindowHandle(HWND remote_window) {
187 remote_window_ = remote_window;
188 // Do not create compositor here, but in Connected() below.
189 // See http://crbug.com/330179 and http://crbug.com/334380.
192 void RemoteWindowTreeHostWin::Connected(IPC::Sender* host) {
193 CHECK(host_ == NULL);
194 DCHECK(remote_window_);
196 // Recreate the compositor for the target surface represented by the
197 // remote_window HWND.
198 CreateCompositor(remote_window_);
202 void RemoteWindowTreeHostWin::Disconnected() {
203 // Don't CHECK here, Disconnected is called on a channel error which can
204 // happen before we're successfully Connected.
207 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
208 GetRemoteInputMethodPrivate();
209 if (remote_input_method_private)
210 remote_input_method_private->SetRemoteDelegate(NULL);
212 remote_window_ = NULL;
215 bool RemoteWindowTreeHostWin::OnMessageReceived(const IPC::Message& message) {
217 IPC_BEGIN_MESSAGE_MAP(RemoteWindowTreeHostWin, message)
218 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseMoved, OnMouseMoved)
219 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseButton, OnMouseButton)
220 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyDown, OnKeyDown)
221 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyUp, OnKeyUp)
222 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_Character, OnChar)
223 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_WindowActivated,
225 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_EdgeGesture, OnEdgeGesture)
226 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchDown,
228 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchUp,
230 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchMoved,
232 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileSaveAsDone,
234 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileOpenDone,
236 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MultiFileOpenDone,
238 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SelectFolderDone,
240 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetCursorPosAck,
242 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeCandidatePopupChanged,
243 OnImeCandidatePopupChanged)
244 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeCompositionChanged,
245 OnImeCompositionChanged)
246 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeTextCommitted,
248 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_ImeInputSourceChanged,
249 OnImeInputSourceChanged)
250 IPC_MESSAGE_UNHANDLED(handled = false)
251 IPC_END_MESSAGE_MAP()
255 void RemoteWindowTreeHostWin::HandleOpenURLOnDesktop(
256 const base::FilePath& shortcut,
257 const base::string16& url) {
260 host_->Send(new MetroViewerHostMsg_OpenURLOnDesktop(shortcut, url));
263 void RemoteWindowTreeHostWin::HandleActivateDesktop(
264 const base::FilePath& shortcut,
268 host_->Send(new MetroViewerHostMsg_ActivateDesktop(shortcut, ash_exit));
271 void RemoteWindowTreeHostWin::HandleMetroExit() {
274 host_->Send(new MetroViewerHostMsg_MetroExit());
277 void RemoteWindowTreeHostWin::HandleOpenFile(
278 const base::string16& title,
279 const base::FilePath& default_path,
280 const base::string16& filter,
281 const OpenFileCompletion& on_success,
282 const FileSelectionCanceled& on_failure) {
286 // Can only have one of these operations in flight.
287 DCHECK(file_open_completion_callback_.is_null());
288 DCHECK(failure_callback_.is_null());
290 file_open_completion_callback_ = on_success;
291 failure_callback_ = on_failure;
293 host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title,
299 void RemoteWindowTreeHostWin::HandleOpenMultipleFiles(
300 const base::string16& title,
301 const base::FilePath& default_path,
302 const base::string16& filter,
303 const OpenMultipleFilesCompletion& on_success,
304 const FileSelectionCanceled& on_failure) {
308 // Can only have one of these operations in flight.
309 DCHECK(multi_file_open_completion_callback_.is_null());
310 DCHECK(failure_callback_.is_null());
311 multi_file_open_completion_callback_ = on_success;
312 failure_callback_ = on_failure;
314 host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title,
320 void RemoteWindowTreeHostWin::HandleSaveFile(
321 const base::string16& title,
322 const base::FilePath& default_path,
323 const base::string16& filter,
325 const base::string16& default_extension,
326 const SaveFileCompletion& on_success,
327 const FileSelectionCanceled& on_failure) {
331 MetroViewerHostMsg_SaveAsDialogParams params;
332 params.title = title;
333 params.default_extension = default_extension;
334 params.filter = filter;
335 params.filter_index = filter_index;
336 params.suggested_name = default_path;
338 // Can only have one of these operations in flight.
339 DCHECK(file_saveas_completion_callback_.is_null());
340 DCHECK(failure_callback_.is_null());
341 file_saveas_completion_callback_ = on_success;
342 failure_callback_ = on_failure;
344 host_->Send(new MetroViewerHostMsg_DisplayFileSaveAs(params));
347 void RemoteWindowTreeHostWin::HandleSelectFolder(
348 const base::string16& title,
349 const SelectFolderCompletion& on_success,
350 const FileSelectionCanceled& on_failure) {
354 // Can only have one of these operations in flight.
355 DCHECK(select_folder_completion_callback_.is_null());
356 DCHECK(failure_callback_.is_null());
357 select_folder_completion_callback_ = on_success;
358 failure_callback_ = on_failure;
360 host_->Send(new MetroViewerHostMsg_DisplaySelectFolder(title));
363 void RemoteWindowTreeHostWin::HandleWindowSizeChanged(uint32 width,
365 SetBounds(gfx::Rect(0, 0, width, height));
368 bool RemoteWindowTreeHostWin::IsForegroundWindow() {
369 return ::GetForegroundWindow() == remote_window_;
372 Window* RemoteWindowTreeHostWin::GetAshWindow() {
376 ui::EventSource* RemoteWindowTreeHostWin::GetEventSource() {
380 gfx::AcceleratedWidget RemoteWindowTreeHostWin::GetAcceleratedWidget() {
382 return remote_window_;
383 // Getting here should only happen for ash_unittests.exe and related code.
384 return ::GetDesktopWindow();
387 void RemoteWindowTreeHostWin::Show() {
388 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
389 GetRemoteInputMethodPrivate();
390 if (remote_input_method_private)
391 remote_input_method_private->SetRemoteDelegate(this);
394 void RemoteWindowTreeHostWin::Hide() {
398 gfx::Rect RemoteWindowTreeHostWin::GetBounds() const {
399 return gfx::Rect(window_size_);
402 void RemoteWindowTreeHostWin::SetBounds(const gfx::Rect& bounds) {
403 window_size_ = bounds.size();
404 OnHostResized(bounds.size());
407 gfx::Point RemoteWindowTreeHostWin::GetLocationOnNativeScreen() const {
408 return gfx::Point(0, 0);
411 void RemoteWindowTreeHostWin::SetCapture() {
414 void RemoteWindowTreeHostWin::ReleaseCapture() {
417 void RemoteWindowTreeHostWin::SetCursorNative(gfx::NativeCursor native_cursor) {
421 new MetroViewerHostMsg_SetCursor(uint64(native_cursor.platform())));
424 void RemoteWindowTreeHostWin::MoveCursorToNative(const gfx::Point& location) {
425 VLOG(1) << "In MoveCursorTo: " << location.x() << ", " << location.y();
429 // This function can be called in cases like when the mouse cursor is
430 // restricted within a viewport (For e.g. LockCursor) which assumes that
431 // subsequent mouse moves would be received starting with the new cursor
432 // coordinates. This is a challenge for Windows ASH for the reasons
434 // Other cases which don't expect this behavior should continue to work
437 // The mouse events are received by the viewer process and sent to the
438 // browser. If we invoke the SetCursor API here we continue to receive
439 // mouse messages from the viewer which were posted before the SetCursor
440 // API executes which messes up the state in the browser. To workaround
441 // this we invoke the SetCursor API in the viewer process and ignore
442 // mouse messages until we received an ACK from the viewer indicating that
443 // the SetCursor operation completed.
444 ignore_mouse_moves_until_set_cursor_ack_ = true;
445 VLOG(1) << "In MoveCursorTo. Sending IPC";
446 host_->Send(new MetroViewerHostMsg_SetCursorPos(location.x(), location.y()));
449 void RemoteWindowTreeHostWin::OnCursorVisibilityChangedNative(bool show) {
453 void RemoteWindowTreeHostWin::PostNativeEvent(
454 const base::NativeEvent& native_event) {
457 void RemoteWindowTreeHostWin::OnDeviceScaleFactorChanged(
458 float device_scale_factor) {
462 ui::EventProcessor* RemoteWindowTreeHostWin::GetEventProcessor() {
466 void RemoteWindowTreeHostWin::CancelComposition() {
469 host_->Send(new MetroViewerHostMsg_ImeCancelComposition);
472 void RemoteWindowTreeHostWin::OnTextInputClientUpdated(
473 const std::vector<int32>& input_scopes,
474 const std::vector<gfx::Rect>& composition_character_bounds) {
477 std::vector<metro_viewer::CharacterBounds> character_bounds;
478 for (size_t i = 0; i < composition_character_bounds.size(); ++i) {
479 const gfx::Rect& rect = composition_character_bounds[i];
480 metro_viewer::CharacterBounds bounds;
481 bounds.left = rect.x();
482 bounds.top = rect.y();
483 bounds.right = rect.right();
484 bounds.bottom = rect.bottom();
485 character_bounds.push_back(bounds);
487 host_->Send(new MetroViewerHostMsg_ImeTextInputClientUpdated(
488 input_scopes, character_bounds));
491 gfx::Point PointFromNativeEvent(int32 x, int32 y) {
492 static float scale_factor = gfx::GetModernUIScale();
493 gfx::Point result( x * scale_factor, y * scale_factor);
497 void RemoteWindowTreeHostWin::OnMouseMoved(int32 x, int32 y, int32 flags) {
498 if (ignore_mouse_moves_until_set_cursor_ack_)
501 gfx::Point location = PointFromNativeEvent(x, y);
502 ui::MouseEvent event(ui::ET_MOUSE_MOVED, location, location, flags, 0);
503 SendEventToProcessor(&event);
506 void RemoteWindowTreeHostWin::OnMouseButton(
507 const MetroViewerHostMsg_MouseButtonParams& params) {
508 gfx::Point location = PointFromNativeEvent(params.x, params.y);
509 ui::MouseEvent mouse_event(params.event_type, location, location,
510 static_cast<int>(params.flags),
511 static_cast<int>(params.changed_button));
513 SetEventFlags(params.flags | key_event_flags());
514 if (params.event_type == ui::ET_MOUSEWHEEL) {
515 int x_offset = params.is_horizontal_wheel ? params.extra : 0;
516 int y_offset = !params.is_horizontal_wheel ? params.extra : 0;
517 ui::MouseWheelEvent wheel_event(mouse_event, x_offset, y_offset);
518 SendEventToProcessor(&wheel_event);
519 } else if (params.event_type == ui::ET_MOUSE_PRESSED) {
520 // TODO(shrikant): Ideally modify code in event.cc by adding automatic
521 // tracking of double clicks in synthetic MouseEvent constructor code.
522 // Non-synthetic MouseEvent constructor code does automatically track
523 // this. Need to use some caution while modifying synthetic constructor
524 // as many tests and other code paths depend on it and apparently
525 // specifically depend on non implicit tracking of previous mouse event.
526 if (last_mouse_click_event_ &&
527 ui::MouseEvent::IsRepeatedClickEvent(mouse_event,
528 *last_mouse_click_event_)) {
529 mouse_event.SetClickCount(2);
531 mouse_event.SetClickCount(1);
533 last_mouse_click_event_ .reset(new ui::MouseEvent(mouse_event));
534 SendEventToProcessor(&mouse_event);
536 SendEventToProcessor(&mouse_event);
540 void RemoteWindowTreeHostWin::OnKeyDown(uint32 vkey,
544 DispatchKeyboardMessage(ui::ET_KEY_PRESSED, vkey, repeat_count, scan_code,
548 void RemoteWindowTreeHostWin::OnKeyUp(uint32 vkey,
552 DispatchKeyboardMessage(ui::ET_KEY_RELEASED, vkey, repeat_count, scan_code,
556 void RemoteWindowTreeHostWin::OnChar(uint32 key_code,
560 DispatchKeyboardMessage(ui::ET_KEY_PRESSED, key_code, repeat_count,
561 scan_code, flags, true);
564 void RemoteWindowTreeHostWin::OnWindowActivated() {
568 void RemoteWindowTreeHostWin::OnEdgeGesture() {
569 ui::GestureEvent event(
570 ui::ET_GESTURE_WIN8_EDGE_SWIPE,
574 ui::EventTimeForNow(),
575 ui::GestureEventDetails(ui::ET_GESTURE_WIN8_EDGE_SWIPE, 0, 0),
577 SendEventToProcessor(&event);
580 void RemoteWindowTreeHostWin::OnTouchDown(int32 x,
584 gfx::Point location = PointFromNativeEvent(x, y);
585 ui::TouchEvent event(ui::ET_TOUCH_PRESSED,
588 base::TimeDelta::FromMicroseconds(timestamp));
589 SendEventToProcessor(&event);
592 void RemoteWindowTreeHostWin::OnTouchUp(int32 x,
596 gfx::Point location = PointFromNativeEvent(x, y);
597 ui::TouchEvent event(ui::ET_TOUCH_RELEASED,
600 base::TimeDelta::FromMicroseconds(timestamp));
601 SendEventToProcessor(&event);
604 void RemoteWindowTreeHostWin::OnTouchMoved(int32 x,
608 gfx::Point location = PointFromNativeEvent(x, y);
609 ui::TouchEvent event(ui::ET_TOUCH_MOVED,
612 base::TimeDelta::FromMicroseconds(timestamp));
613 SendEventToProcessor(&event);
616 void RemoteWindowTreeHostWin::OnFileSaveAsDone(bool success,
617 const base::FilePath& filename,
620 file_saveas_completion_callback_.Run(filename, filter_index, NULL);
622 failure_callback_.Run(NULL);
623 file_saveas_completion_callback_.Reset();
624 failure_callback_.Reset();
628 void RemoteWindowTreeHostWin::OnFileOpenDone(bool success,
629 const base::FilePath& filename) {
631 file_open_completion_callback_.Run(base::FilePath(filename), 0, NULL);
633 failure_callback_.Run(NULL);
634 file_open_completion_callback_.Reset();
635 failure_callback_.Reset();
638 void RemoteWindowTreeHostWin::OnMultiFileOpenDone(
640 const std::vector<base::FilePath>& files) {
642 multi_file_open_completion_callback_.Run(files, NULL);
644 failure_callback_.Run(NULL);
645 multi_file_open_completion_callback_.Reset();
646 failure_callback_.Reset();
649 void RemoteWindowTreeHostWin::OnSelectFolderDone(
651 const base::FilePath& folder) {
653 select_folder_completion_callback_.Run(base::FilePath(folder), 0, NULL);
655 failure_callback_.Run(NULL);
656 select_folder_completion_callback_.Reset();
657 failure_callback_.Reset();
660 void RemoteWindowTreeHostWin::OnSetCursorPosAck() {
661 DCHECK(ignore_mouse_moves_until_set_cursor_ack_);
662 ignore_mouse_moves_until_set_cursor_ack_ = false;
665 ui::RemoteInputMethodPrivateWin*
666 RemoteWindowTreeHostWin::GetRemoteInputMethodPrivate() {
667 ui::InputMethod* input_method = GetAshWindow()->GetProperty(
668 aura::client::kRootWindowInputMethodKey);
669 return ui::RemoteInputMethodPrivateWin::Get(input_method);
672 void RemoteWindowTreeHostWin::OnImeCandidatePopupChanged(bool visible) {
673 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
674 GetRemoteInputMethodPrivate();
675 if (!remote_input_method_private)
677 remote_input_method_private->OnCandidatePopupChanged(visible);
680 void RemoteWindowTreeHostWin::OnImeCompositionChanged(
681 const base::string16& text,
682 int32 selection_start,
684 const std::vector<metro_viewer::UnderlineInfo>& underlines) {
685 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
686 GetRemoteInputMethodPrivate();
687 if (!remote_input_method_private)
689 ui::CompositionText composition_text;
691 text, selection_start, selection_end, underlines, &composition_text);
692 remote_input_method_private->OnCompositionChanged(composition_text);
695 void RemoteWindowTreeHostWin::OnImeTextCommitted(const base::string16& text) {
696 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
697 GetRemoteInputMethodPrivate();
698 if (!remote_input_method_private)
700 remote_input_method_private->OnTextCommitted(text);
703 void RemoteWindowTreeHostWin::OnImeInputSourceChanged(uint16 language_id,
705 ui::RemoteInputMethodPrivateWin* remote_input_method_private =
706 GetRemoteInputMethodPrivate();
707 if (!remote_input_method_private)
709 remote_input_method_private->OnInputSourceChanged(language_id, is_ime);
712 void RemoteWindowTreeHostWin::DispatchKeyboardMessage(ui::EventType type,
718 SetEventFlags(flags | mouse_event_flags());
719 if (base::MessageLoop::current()->IsNested()) {
720 int index = (flags & ui::EF_ALT_DOWN) ? 1 : 0;
721 const int char_message[] = {WM_CHAR, WM_SYSCHAR};
722 const int keydown_message[] = {WM_KEYDOWN, WM_SYSKEYDOWN};
723 const int keyup_message[] = {WM_KEYUP, WM_SYSKEYUP};
724 uint32 message = is_character
725 ? char_message[index]
726 : (type == ui::ET_KEY_PRESSED ? keydown_message[index]
727 : keyup_message[index]);
728 ::PostThreadMessage(::GetCurrentThreadId(),
731 repeat_count | scan_code >> 15);
733 ui::KeyEvent event(type,
734 ui::KeyboardCodeForWindowsKeyCode(vkey),
737 SendEventToProcessor(&event);
741 void RemoteWindowTreeHostWin::SetEventFlags(uint32 flags) {
742 if (flags == event_flags_)
744 event_flags_ = flags;
745 SetVirtualKeyStates(event_flags_);