| 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 "win8/metro_driver/stdafx.h" | 5 #include "win8/metro_driver/stdafx.h" |
| 6 #include "win8/metro_driver/chrome_app_view_ash.h" | 6 #include "win8/metro_driver/chrome_app_view_ash.h" |
| 7 | 7 |
| 8 #include <corewindow.h> | 8 #include <corewindow.h> |
| 9 #include <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <windows.foundation.h> | 10 #include <windows.foundation.h> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/threading/thread.h" | |
| 18 #include "base/win/metro.h" | 17 #include "base/win/metro.h" |
| 19 #include "base/win/win_util.h" | 18 #include "base/win/win_util.h" |
| 20 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
| 21 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 22 #include "ipc/ipc_channel.h" | 21 #include "ipc/ipc_channel.h" |
| 23 #include "ipc/ipc_channel_proxy.h" | 22 #include "ipc/ipc_channel_proxy.h" |
| 24 #include "ipc/ipc_sender.h" | 23 #include "ipc/ipc_sender.h" |
| 25 #include "ui/events/gesture_detection/motion_event.h" | 24 #include "ui/events/gesture_detection/motion_event.h" |
| 26 #include "ui/gfx/geometry/point_conversions.h" | 25 #include "ui/gfx/geometry/point_conversions.h" |
| 27 #include "ui/gfx/win/dpi.h" | 26 #include "ui/gfx/win/dpi.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 | 79 |
| 81 namespace { | 80 namespace { |
| 82 | 81 |
| 83 enum KeyModifier { | 82 enum KeyModifier { |
| 84 NONE, | 83 NONE, |
| 85 SHIFT = 1, | 84 SHIFT = 1, |
| 86 CONTROL = 2, | 85 CONTROL = 2, |
| 87 ALT = 4 | 86 ALT = 4 |
| 88 }; | 87 }; |
| 89 | 88 |
| 89 const int kChromeChannelPollTimerMs = 100; |
| 90 |
| 90 // Helper function to send keystrokes via the SendInput function. | 91 // Helper function to send keystrokes via the SendInput function. |
| 91 // mnemonic_char: The keystroke to be sent. | 92 // mnemonic_char: The keystroke to be sent. |
| 92 // modifiers: Combination with Alt, Ctrl, Shift, etc. | 93 // modifiers: Combination with Alt, Ctrl, Shift, etc. |
| 93 void SendKeySequence( | 94 void SendKeySequence( |
| 94 WORD mnemonic_char, KeyModifier modifiers) { | 95 WORD mnemonic_char, KeyModifier modifiers) { |
| 95 INPUT keys[4] = {0}; // Keyboard events | 96 INPUT keys[4] = {0}; // Keyboard events |
| 96 int key_count = 0; // Number of generated events | 97 int key_count = 0; // Number of generated events |
| 97 | 98 |
| 98 if (modifiers & SHIFT) { | 99 if (modifiers & SHIFT) { |
| 99 keys[key_count].type = INPUT_KEYBOARD; | 100 keys[key_count].type = INPUT_KEYBOARD; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 base::Bind(&ChromeAppViewAsh::OnImeUpdateTextInputClient, | 267 base::Bind(&ChromeAppViewAsh::OnImeUpdateTextInputClient, |
| 267 base::Unretained(app_view_), | 268 base::Unretained(app_view_), |
| 268 input_scopes, | 269 input_scopes, |
| 269 character_bounds)); | 270 character_bounds)); |
| 270 } | 271 } |
| 271 | 272 |
| 272 scoped_refptr<base::MessageLoopProxy> ui_proxy_; | 273 scoped_refptr<base::MessageLoopProxy> ui_proxy_; |
| 273 ChromeAppViewAsh* app_view_; | 274 ChromeAppViewAsh* app_view_; |
| 274 }; | 275 }; |
| 275 | 276 |
| 276 bool WaitForChromeIPCConnection(const std::string& channel_name) { | |
| 277 int ms_elapsed = 0; | |
| 278 while (!IPC::Channel::IsNamedServerInitialized(channel_name) && | |
| 279 ms_elapsed < 10000) { | |
| 280 ms_elapsed += 100; | |
| 281 Sleep(100); | |
| 282 } | |
| 283 return IPC::Channel::IsNamedServerInitialized(channel_name); | |
| 284 } | |
| 285 | |
| 286 void RunMessageLoop(winui::Core::ICoreDispatcher* dispatcher) { | 277 void RunMessageLoop(winui::Core::ICoreDispatcher* dispatcher) { |
| 287 // We're entering a nested message loop, let's allow dispatching | 278 // We're entering a nested message loop, let's allow dispatching |
| 288 // tasks while we're in there. | 279 // tasks while we're in there. |
| 289 base::MessageLoop::current()->SetNestableTasksAllowed(true); | 280 base::MessageLoop::current()->SetNestableTasksAllowed(true); |
| 290 | 281 |
| 291 // Enter main core message loop. There are several ways to exit it | 282 // Enter main core message loop. There are several ways to exit it |
| 292 // Nicely: | 283 // Nicely: |
| 293 // 1 - User action like ALT-F4. | 284 // 1 - User action like ALT-F4. |
| 294 // 2 - Calling ICoreApplicationExit::Exit(). | 285 // 2 - Calling ICoreApplicationExit::Exit(). |
| 295 // 3- Posting WM_CLOSE to the core window. | 286 // 3- Posting WM_CLOSE to the core window. |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 | 515 |
| 525 DISALLOW_COPY_AND_ASSIGN(PointerInfoHandler); | 516 DISALLOW_COPY_AND_ASSIGN(PointerInfoHandler); |
| 526 }; | 517 }; |
| 527 | 518 |
| 528 ChromeAppViewAsh::ChromeAppViewAsh() | 519 ChromeAppViewAsh::ChromeAppViewAsh() |
| 529 : mouse_down_flags_(ui::EF_NONE), | 520 : mouse_down_flags_(ui::EF_NONE), |
| 530 ui_channel_(nullptr), | 521 ui_channel_(nullptr), |
| 531 core_window_hwnd_(NULL), | 522 core_window_hwnd_(NULL), |
| 532 metro_dpi_scale_(0), | 523 metro_dpi_scale_(0), |
| 533 win32_dpi_scale_(0), | 524 win32_dpi_scale_(0), |
| 534 last_cursor_(NULL) { | 525 last_cursor_(NULL), |
| 526 channel_listener_(NULL) { |
| 535 DVLOG(1) << __FUNCTION__; | 527 DVLOG(1) << __FUNCTION__; |
| 536 globals.previous_state = | 528 globals.previous_state = |
| 537 winapp::Activation::ApplicationExecutionState_NotRunning; | 529 winapp::Activation::ApplicationExecutionState_NotRunning; |
| 538 } | 530 } |
| 539 | 531 |
| 540 ChromeAppViewAsh::~ChromeAppViewAsh() { | 532 ChromeAppViewAsh::~ChromeAppViewAsh() { |
| 541 DVLOG(1) << __FUNCTION__; | 533 DVLOG(1) << __FUNCTION__; |
| 542 } | 534 } |
| 543 | 535 |
| 544 IFACEMETHODIMP | 536 IFACEMETHODIMP |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 } | 663 } |
| 672 | 664 |
| 673 IFACEMETHODIMP | 665 IFACEMETHODIMP |
| 674 ChromeAppViewAsh::Run() { | 666 ChromeAppViewAsh::Run() { |
| 675 DVLOG(1) << __FUNCTION__; | 667 DVLOG(1) << __FUNCTION__; |
| 676 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher; | 668 mswr::ComPtr<winui::Core::ICoreDispatcher> dispatcher; |
| 677 HRESULT hr = window_->get_Dispatcher(dispatcher.GetAddressOf()); | 669 HRESULT hr = window_->get_Dispatcher(dispatcher.GetAddressOf()); |
| 678 CheckHR(hr, "Dispatcher failed."); | 670 CheckHR(hr, "Dispatcher failed."); |
| 679 | 671 |
| 680 // Create the IPC channel IO thread. It needs to out-live the ChannelProxy. | 672 // Create the IPC channel IO thread. It needs to out-live the ChannelProxy. |
| 681 base::Thread io_thread("metro_IO_thread"); | 673 io_thread_.reset(new base::Thread("metro_IO_thread")); |
| 682 base::Thread::Options options; | 674 base::Thread::Options options; |
| 683 options.message_loop_type = base::MessageLoop::TYPE_IO; | 675 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 684 io_thread.StartWithOptions(options); | 676 io_thread_->StartWithOptions(options); |
| 685 | 677 |
| 686 // Start up Chrome and wait for the desired IPC server connection to exist. | 678 ChromeChannelListener ui_channel_listener(&ui_loop_, this); |
| 687 WaitForChromeIPCConnection(win8::kMetroViewerIPCChannelName); | 679 channel_listener_ = &ui_channel_listener; |
| 688 | 680 |
| 689 // In Aura mode we create an IPC channel to the browser, then ask it to | 681 // We can't do anything until the Chrome browser IPC channel is initialized. |
| 690 // connect to us. | 682 // Lazy initialization in a timer. |
| 691 ChromeChannelListener ui_channel_listener(&ui_loop_, this); | 683 ui_loop_.PostDelayedTask(FROM_HERE, |
| 692 scoped_ptr<IPC::ChannelProxy> channel = | 684 base::Bind(base::IgnoreResult(&ChromeAppViewAsh::StartChromeOSMode), |
| 693 IPC::ChannelProxy::Create(win8::kMetroViewerIPCChannelName, | 685 base::Unretained(this)), |
| 694 IPC::Channel::MODE_NAMED_CLIENT, | 686 base::TimeDelta::FromMilliseconds(kChromeChannelPollTimerMs)); |
| 695 &ui_channel_listener, | |
| 696 io_thread.message_loop_proxy()); | |
| 697 ui_channel_ = channel.get(); | |
| 698 | 687 |
| 699 // Upon receipt of the MetroViewerHostMsg_SetTargetSurface message the | 688 // Post the task that'll do the inner Metro message pumping to it. |
| 700 // browser will use D3D from the browser process to present to our Window. | |
| 701 ui_channel_->Send(new MetroViewerHostMsg_SetTargetSurface( | |
| 702 gfx::NativeViewId(core_window_hwnd_), win32_dpi_scale_)); | |
| 703 DVLOG(1) << "ICoreWindow sent " << core_window_hwnd_; | |
| 704 | |
| 705 // Send an initial size message so that the Ash root window host gets sized | |
| 706 // correctly. | |
| 707 RECT rect = {0}; | |
| 708 ::GetWindowRect(core_window_hwnd_, &rect); | |
| 709 ui_channel_->Send( | |
| 710 new MetroViewerHostMsg_WindowSizeChanged(rect.right - rect.left, | |
| 711 rect.bottom - rect.top)); | |
| 712 | |
| 713 input_source_ = metro_driver::InputSource::Create(); | |
| 714 if (input_source_) { | |
| 715 input_source_->AddObserver(this); | |
| 716 // Send an initial input source. | |
| 717 OnInputSourceChanged(); | |
| 718 } | |
| 719 | |
| 720 // Start receiving IME popup window notifications. | |
| 721 metro_driver::AddImePopupObserver(this); | |
| 722 | |
| 723 // And post the task that'll do the inner Metro message pumping to it. | |
| 724 ui_loop_.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); | 689 ui_loop_.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); |
| 725 ui_loop_.Run(); | 690 ui_loop_.Run(); |
| 726 | 691 |
| 692 io_thread_.reset(NULL); |
| 693 ui_channel_.reset(NULL); |
| 694 channel_listener_ = NULL; |
| 695 |
| 727 DVLOG(0) << "ProcessEvents done, hr=" << hr; | 696 DVLOG(0) << "ProcessEvents done, hr=" << hr; |
| 728 return hr; | 697 return hr; |
| 729 } | 698 } |
| 730 | 699 |
| 731 IFACEMETHODIMP | 700 IFACEMETHODIMP |
| 732 ChromeAppViewAsh::Uninitialize() { | 701 ChromeAppViewAsh::Uninitialize() { |
| 733 DVLOG(1) << __FUNCTION__; | 702 DVLOG(1) << __FUNCTION__; |
| 734 metro_driver::RemoveImePopupObserver(this); | 703 metro_driver::RemoveImePopupObserver(this); |
| 735 input_source_.reset(); | 704 input_source_.reset(); |
| 736 text_service_.reset(); | 705 text_service_.reset(); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 969 ::PostMessage(core_window, WM_CLOSE, 0, 0); | 938 ::PostMessage(core_window, WM_CLOSE, 0, 0); |
| 970 | 939 |
| 971 globals.app_exit->Exit(); | 940 globals.app_exit->Exit(); |
| 972 } | 941 } |
| 973 } | 942 } |
| 974 | 943 |
| 975 void ChromeAppViewAsh::OnInputSourceChanged() { | 944 void ChromeAppViewAsh::OnInputSourceChanged() { |
| 976 if (!input_source_) | 945 if (!input_source_) |
| 977 return; | 946 return; |
| 978 | 947 |
| 948 DCHECK(ui_channel_); |
| 949 |
| 979 LANGID langid = 0; | 950 LANGID langid = 0; |
| 980 bool is_ime = false; | 951 bool is_ime = false; |
| 981 if (!input_source_->GetActiveSource(&langid, &is_ime)) { | 952 if (!input_source_->GetActiveSource(&langid, &is_ime)) { |
| 982 LOG(ERROR) << "GetActiveSource failed"; | 953 LOG(ERROR) << "GetActiveSource failed"; |
| 983 return; | 954 return; |
| 984 } | 955 } |
| 985 ui_channel_->Send(new MetroViewerHostMsg_ImeInputSourceChanged(langid, | 956 ui_channel_->Send(new MetroViewerHostMsg_ImeInputSourceChanged(langid, |
| 986 is_ime)); | 957 is_ime)); |
| 987 } | 958 } |
| 988 | 959 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 999 ui_channel_->Send(new MetroViewerHostMsg_ImeTextCommitted(text)); | 970 ui_channel_->Send(new MetroViewerHostMsg_ImeTextCommitted(text)); |
| 1000 } | 971 } |
| 1001 | 972 |
| 1002 void ChromeAppViewAsh::SendMouseButton(int x, | 973 void ChromeAppViewAsh::SendMouseButton(int x, |
| 1003 int y, | 974 int y, |
| 1004 int extra, | 975 int extra, |
| 1005 ui::EventType event_type, | 976 ui::EventType event_type, |
| 1006 uint32 flags, | 977 uint32 flags, |
| 1007 ui::EventFlags changed_button, | 978 ui::EventFlags changed_button, |
| 1008 bool is_horizontal_wheel) { | 979 bool is_horizontal_wheel) { |
| 980 if (!ui_channel_) |
| 981 return; |
| 1009 MetroViewerHostMsg_MouseButtonParams params; | 982 MetroViewerHostMsg_MouseButtonParams params; |
| 1010 params.x = static_cast<int32>(x); | 983 params.x = static_cast<int32>(x); |
| 1011 params.y = static_cast<int32>(y); | 984 params.y = static_cast<int32>(y); |
| 1012 params.extra = static_cast<int32>(extra); | 985 params.extra = static_cast<int32>(extra); |
| 1013 params.event_type = event_type; | 986 params.event_type = event_type; |
| 1014 params.flags = static_cast<int32>(flags); | 987 params.flags = static_cast<int32>(flags); |
| 1015 params.changed_button = changed_button; | 988 params.changed_button = changed_button; |
| 1016 params.is_horizontal_wheel = is_horizontal_wheel; | 989 params.is_horizontal_wheel = is_horizontal_wheel; |
| 1017 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(params)); | 990 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(params)); |
| 1018 } | 991 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 // in turn launches the chrome browser process in desktop mode via | 1041 // in turn launches the chrome browser process in desktop mode via |
| 1069 // ShellExecute. If we call ICoreWindow::Activate before this, then | 1042 // ShellExecute. If we call ICoreWindow::Activate before this, then |
| 1070 // Windows kills the metro chrome process when it calls ShellExecute. Seems | 1043 // Windows kills the metro chrome process when it calls ShellExecute. Seems |
| 1071 // to be a bug. | 1044 // to be a bug. |
| 1072 window_->Activate(); | 1045 window_->Activate(); |
| 1073 return S_OK; | 1046 return S_OK; |
| 1074 } | 1047 } |
| 1075 | 1048 |
| 1076 HRESULT ChromeAppViewAsh::OnPointerMoved(winui::Core::ICoreWindow* sender, | 1049 HRESULT ChromeAppViewAsh::OnPointerMoved(winui::Core::ICoreWindow* sender, |
| 1077 winui::Core::IPointerEventArgs* args) { | 1050 winui::Core::IPointerEventArgs* args) { |
| 1051 if (!ui_channel_) |
| 1052 return S_OK; |
| 1053 |
| 1078 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); | 1054 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); |
| 1079 HRESULT hr = pointer.Init(args); | 1055 HRESULT hr = pointer.Init(args); |
| 1080 if (FAILED(hr)) | 1056 if (FAILED(hr)) |
| 1081 return hr; | 1057 return hr; |
| 1082 | 1058 |
| 1083 if (pointer.IsMouse()) { | 1059 if (pointer.IsMouse()) { |
| 1084 // If the mouse was moved towards the charms or the OS specific section, | 1060 // If the mouse was moved towards the charms or the OS specific section, |
| 1085 // the cursor may change from what the browser last set. Restore it here. | 1061 // the cursor may change from what the browser last set. Restore it here. |
| 1086 if (::GetCursor() != last_cursor_) | 1062 if (::GetCursor() != last_cursor_) |
| 1087 SetCursor(last_cursor_); | 1063 SetCursor(last_cursor_); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1103 | 1079 |
| 1104 // NOTE: From experimentation, it seems like Metro only sends a PointerPressed | 1080 // NOTE: From experimentation, it seems like Metro only sends a PointerPressed |
| 1105 // event for the first button pressed and the last button released in a sequence | 1081 // event for the first button pressed and the last button released in a sequence |
| 1106 // of mouse events. | 1082 // of mouse events. |
| 1107 // For example, a sequence of LEFT_DOWN, RIGHT_DOWN, LEFT_UP, RIGHT_UP results | 1083 // For example, a sequence of LEFT_DOWN, RIGHT_DOWN, LEFT_UP, RIGHT_UP results |
| 1108 // only in PointerPressed(LEFT)/PointerReleased(RIGHT) events. Intermediary | 1084 // only in PointerPressed(LEFT)/PointerReleased(RIGHT) events. Intermediary |
| 1109 // presses and releases are tracked in OnPointMoved(). | 1085 // presses and releases are tracked in OnPointMoved(). |
| 1110 HRESULT ChromeAppViewAsh::OnPointerPressed( | 1086 HRESULT ChromeAppViewAsh::OnPointerPressed( |
| 1111 winui::Core::ICoreWindow* sender, | 1087 winui::Core::ICoreWindow* sender, |
| 1112 winui::Core::IPointerEventArgs* args) { | 1088 winui::Core::IPointerEventArgs* args) { |
| 1089 if (!ui_channel_) |
| 1090 return S_OK; |
| 1091 |
| 1113 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); | 1092 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); |
| 1114 HRESULT hr = pointer.Init(args); | 1093 HRESULT hr = pointer.Init(args); |
| 1115 if (FAILED(hr)) | 1094 if (FAILED(hr)) |
| 1116 return hr; | 1095 return hr; |
| 1117 | 1096 |
| 1118 if (pointer.IsMouse()) { | 1097 if (pointer.IsMouse()) { |
| 1119 mouse_down_flags_ = pointer.mouse_down_flags(); | 1098 mouse_down_flags_ = pointer.mouse_down_flags(); |
| 1120 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_PRESSED, | 1099 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_PRESSED, |
| 1121 mouse_down_flags_ | GetKeyboardEventFlags(), | 1100 mouse_down_flags_ | GetKeyboardEventFlags(), |
| 1122 pointer.changed_button(), pointer.is_horizontal_wheel()); | 1101 pointer.changed_button(), pointer.is_horizontal_wheel()); |
| 1123 } else { | 1102 } else { |
| 1124 DCHECK(pointer.IsTouch()); | 1103 DCHECK(pointer.IsTouch()); |
| 1125 ui_channel_->Send(new MetroViewerHostMsg_TouchDown(pointer.x(), | 1104 ui_channel_->Send(new MetroViewerHostMsg_TouchDown(pointer.x(), |
| 1126 pointer.y(), | 1105 pointer.y(), |
| 1127 pointer.timestamp(), | 1106 pointer.timestamp(), |
| 1128 pointer.pointer_id())); | 1107 pointer.pointer_id())); |
| 1129 } | 1108 } |
| 1130 return S_OK; | 1109 return S_OK; |
| 1131 } | 1110 } |
| 1132 | 1111 |
| 1133 HRESULT ChromeAppViewAsh::OnPointerReleased( | 1112 HRESULT ChromeAppViewAsh::OnPointerReleased( |
| 1134 winui::Core::ICoreWindow* sender, | 1113 winui::Core::ICoreWindow* sender, |
| 1135 winui::Core::IPointerEventArgs* args) { | 1114 winui::Core::IPointerEventArgs* args) { |
| 1115 if (!ui_channel_) |
| 1116 return S_OK; |
| 1117 |
| 1136 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); | 1118 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); |
| 1137 HRESULT hr = pointer.Init(args); | 1119 HRESULT hr = pointer.Init(args); |
| 1138 if (FAILED(hr)) | 1120 if (FAILED(hr)) |
| 1139 return hr; | 1121 return hr; |
| 1140 | 1122 |
| 1141 if (pointer.IsMouse()) { | 1123 if (pointer.IsMouse()) { |
| 1142 mouse_down_flags_ = ui::EF_NONE; | 1124 mouse_down_flags_ = ui::EF_NONE; |
| 1143 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_RELEASED, | 1125 SendMouseButton(pointer.x(), pointer.y(), 0, ui::ET_MOUSE_RELEASED, |
| 1144 static_cast<uint32>(pointer.changed_button()) | | 1126 static_cast<uint32>(pointer.changed_button()) | |
| 1145 GetKeyboardEventFlags(), | 1127 GetKeyboardEventFlags(), |
| 1146 pointer.changed_button(), | 1128 pointer.changed_button(), |
| 1147 pointer.is_horizontal_wheel()); | 1129 pointer.is_horizontal_wheel()); |
| 1148 } else { | 1130 } else { |
| 1149 DCHECK(pointer.IsTouch()); | 1131 DCHECK(pointer.IsTouch()); |
| 1150 ui_channel_->Send(new MetroViewerHostMsg_TouchUp(pointer.x(), | 1132 ui_channel_->Send(new MetroViewerHostMsg_TouchUp(pointer.x(), |
| 1151 pointer.y(), | 1133 pointer.y(), |
| 1152 pointer.timestamp(), | 1134 pointer.timestamp(), |
| 1153 pointer.pointer_id())); | 1135 pointer.pointer_id())); |
| 1154 } | 1136 } |
| 1155 return S_OK; | 1137 return S_OK; |
| 1156 } | 1138 } |
| 1157 | 1139 |
| 1158 HRESULT ChromeAppViewAsh::OnWheel( | 1140 HRESULT ChromeAppViewAsh::OnWheel( |
| 1159 winui::Core::ICoreWindow* sender, | 1141 winui::Core::ICoreWindow* sender, |
| 1160 winui::Core::IPointerEventArgs* args) { | 1142 winui::Core::IPointerEventArgs* args) { |
| 1143 if (!ui_channel_) |
| 1144 return S_OK; |
| 1145 |
| 1161 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); | 1146 PointerInfoHandler pointer(metro_dpi_scale_, win32_dpi_scale_); |
| 1162 HRESULT hr = pointer.Init(args); | 1147 HRESULT hr = pointer.Init(args); |
| 1163 if (FAILED(hr)) | 1148 if (FAILED(hr)) |
| 1164 return hr; | 1149 return hr; |
| 1165 DCHECK(pointer.IsMouse()); | 1150 DCHECK(pointer.IsMouse()); |
| 1166 SendMouseButton(pointer.x(), pointer.y(), pointer.wheel_delta(), | 1151 SendMouseButton(pointer.x(), pointer.y(), pointer.wheel_delta(), |
| 1167 ui::ET_MOUSEWHEEL, GetKeyboardEventFlags(), ui::EF_NONE, | 1152 ui::ET_MOUSEWHEEL, GetKeyboardEventFlags(), ui::EF_NONE, |
| 1168 pointer.is_horizontal_wheel()); | 1153 pointer.is_horizontal_wheel()); |
| 1169 return S_OK; | 1154 return S_OK; |
| 1170 } | 1155 } |
| 1171 | 1156 |
| 1172 HRESULT ChromeAppViewAsh::OnKeyDown( | 1157 HRESULT ChromeAppViewAsh::OnKeyDown( |
| 1173 winui::Core::ICoreWindow* sender, | 1158 winui::Core::ICoreWindow* sender, |
| 1174 winui::Core::IKeyEventArgs* args) { | 1159 winui::Core::IKeyEventArgs* args) { |
| 1160 if (!ui_channel_) |
| 1161 return S_OK; |
| 1162 |
| 1175 winsys::VirtualKey virtual_key; | 1163 winsys::VirtualKey virtual_key; |
| 1176 HRESULT hr = args->get_VirtualKey(&virtual_key); | 1164 HRESULT hr = args->get_VirtualKey(&virtual_key); |
| 1177 if (FAILED(hr)) | 1165 if (FAILED(hr)) |
| 1178 return hr; | 1166 return hr; |
| 1179 winui::Core::CorePhysicalKeyStatus status; | 1167 winui::Core::CorePhysicalKeyStatus status; |
| 1180 hr = args->get_KeyStatus(&status); | 1168 hr = args->get_KeyStatus(&status); |
| 1181 if (FAILED(hr)) | 1169 if (FAILED(hr)) |
| 1182 return hr; | 1170 return hr; |
| 1183 | 1171 |
| 1184 ui_channel_->Send(new MetroViewerHostMsg_KeyDown(virtual_key, | 1172 ui_channel_->Send(new MetroViewerHostMsg_KeyDown(virtual_key, |
| 1185 status.RepeatCount, | 1173 status.RepeatCount, |
| 1186 status.ScanCode, | 1174 status.ScanCode, |
| 1187 GetKeyboardEventFlags())); | 1175 GetKeyboardEventFlags())); |
| 1188 return S_OK; | 1176 return S_OK; |
| 1189 } | 1177 } |
| 1190 | 1178 |
| 1191 HRESULT ChromeAppViewAsh::OnKeyUp( | 1179 HRESULT ChromeAppViewAsh::OnKeyUp( |
| 1192 winui::Core::ICoreWindow* sender, | 1180 winui::Core::ICoreWindow* sender, |
| 1193 winui::Core::IKeyEventArgs* args) { | 1181 winui::Core::IKeyEventArgs* args) { |
| 1182 if (!ui_channel_) |
| 1183 return S_OK; |
| 1184 |
| 1194 winsys::VirtualKey virtual_key; | 1185 winsys::VirtualKey virtual_key; |
| 1195 HRESULT hr = args->get_VirtualKey(&virtual_key); | 1186 HRESULT hr = args->get_VirtualKey(&virtual_key); |
| 1196 if (FAILED(hr)) | 1187 if (FAILED(hr)) |
| 1197 return hr; | 1188 return hr; |
| 1198 winui::Core::CorePhysicalKeyStatus status; | 1189 winui::Core::CorePhysicalKeyStatus status; |
| 1199 hr = args->get_KeyStatus(&status); | 1190 hr = args->get_KeyStatus(&status); |
| 1200 if (FAILED(hr)) | 1191 if (FAILED(hr)) |
| 1201 return hr; | 1192 return hr; |
| 1202 | 1193 |
| 1203 ui_channel_->Send(new MetroViewerHostMsg_KeyUp(virtual_key, | 1194 ui_channel_->Send(new MetroViewerHostMsg_KeyUp(virtual_key, |
| 1204 status.RepeatCount, | 1195 status.RepeatCount, |
| 1205 status.ScanCode, | 1196 status.ScanCode, |
| 1206 GetKeyboardEventFlags())); | 1197 GetKeyboardEventFlags())); |
| 1207 return S_OK; | 1198 return S_OK; |
| 1208 } | 1199 } |
| 1209 | 1200 |
| 1210 HRESULT ChromeAppViewAsh::OnAcceleratorKeyDown( | 1201 HRESULT ChromeAppViewAsh::OnAcceleratorKeyDown( |
| 1211 winui::Core::ICoreDispatcher* sender, | 1202 winui::Core::ICoreDispatcher* sender, |
| 1212 winui::Core::IAcceleratorKeyEventArgs* args) { | 1203 winui::Core::IAcceleratorKeyEventArgs* args) { |
| 1204 if (!ui_channel_) |
| 1205 return S_OK; |
| 1206 |
| 1213 winsys::VirtualKey virtual_key; | 1207 winsys::VirtualKey virtual_key; |
| 1214 HRESULT hr = args->get_VirtualKey(&virtual_key); | 1208 HRESULT hr = args->get_VirtualKey(&virtual_key); |
| 1215 if (FAILED(hr)) | 1209 if (FAILED(hr)) |
| 1216 return hr; | 1210 return hr; |
| 1217 winui::Core::CorePhysicalKeyStatus status; | 1211 winui::Core::CorePhysicalKeyStatus status; |
| 1218 hr = args->get_KeyStatus(&status); | 1212 hr = args->get_KeyStatus(&status); |
| 1219 if (FAILED(hr)) | 1213 if (FAILED(hr)) |
| 1220 return hr; | 1214 return hr; |
| 1221 | 1215 |
| 1222 winui::Core::CoreAcceleratorKeyEventType event_type; | 1216 winui::Core::CoreAcceleratorKeyEventType event_type; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1257 | 1251 |
| 1258 default: | 1252 default: |
| 1259 break; | 1253 break; |
| 1260 } | 1254 } |
| 1261 return S_OK; | 1255 return S_OK; |
| 1262 } | 1256 } |
| 1263 | 1257 |
| 1264 HRESULT ChromeAppViewAsh::OnCharacterReceived( | 1258 HRESULT ChromeAppViewAsh::OnCharacterReceived( |
| 1265 winui::Core::ICoreWindow* sender, | 1259 winui::Core::ICoreWindow* sender, |
| 1266 winui::Core::ICharacterReceivedEventArgs* args) { | 1260 winui::Core::ICharacterReceivedEventArgs* args) { |
| 1261 if (!ui_channel_) |
| 1262 return S_OK; |
| 1263 |
| 1267 unsigned int char_code = 0; | 1264 unsigned int char_code = 0; |
| 1268 HRESULT hr = args->get_KeyCode(&char_code); | 1265 HRESULT hr = args->get_KeyCode(&char_code); |
| 1269 if (FAILED(hr)) | 1266 if (FAILED(hr)) |
| 1270 return hr; | 1267 return hr; |
| 1271 | 1268 |
| 1272 winui::Core::CorePhysicalKeyStatus status; | 1269 winui::Core::CorePhysicalKeyStatus status; |
| 1273 hr = args->get_KeyStatus(&status); | 1270 hr = args->get_KeyStatus(&status); |
| 1274 if (FAILED(hr)) | 1271 if (FAILED(hr)) |
| 1275 return hr; | 1272 return hr; |
| 1276 | 1273 |
| 1277 ui_channel_->Send(new MetroViewerHostMsg_Character(char_code, | 1274 ui_channel_->Send(new MetroViewerHostMsg_Character(char_code, |
| 1278 status.RepeatCount, | 1275 status.RepeatCount, |
| 1279 status.ScanCode, | 1276 status.ScanCode, |
| 1280 GetKeyboardEventFlags())); | 1277 GetKeyboardEventFlags())); |
| 1281 return S_OK; | 1278 return S_OK; |
| 1282 } | 1279 } |
| 1283 | 1280 |
| 1284 HRESULT ChromeAppViewAsh::OnWindowActivated( | 1281 HRESULT ChromeAppViewAsh::OnWindowActivated( |
| 1285 winui::Core::ICoreWindow* sender, | 1282 winui::Core::ICoreWindow* sender, |
| 1286 winui::Core::IWindowActivatedEventArgs* args) { | 1283 winui::Core::IWindowActivatedEventArgs* args) { |
| 1284 if (!ui_channel_) |
| 1285 return S_OK; |
| 1286 |
| 1287 if (args) { | 1287 if (args) { |
| 1288 winui::Core::CoreWindowActivationState state; | 1288 winui::Core::CoreWindowActivationState state; |
| 1289 HRESULT hr = args->get_WindowActivationState(&state); | 1289 HRESULT hr = args->get_WindowActivationState(&state); |
| 1290 if (FAILED(hr)) | 1290 if (FAILED(hr)) |
| 1291 return hr; | 1291 return hr; |
| 1292 | 1292 |
| 1293 // Treat both full activation (Ash was reopened from the Start Screen or | 1293 // Treat both full activation (Ash was reopened from the Start Screen or |
| 1294 // from any other Metro entry point in Windows) and pointer activation | 1294 // from any other Metro entry point in Windows) and pointer activation |
| 1295 // (user clicked back in Ash after using another app on another monitor) | 1295 // (user clicked back in Ash after using another app on another monitor) |
| 1296 // the same. | 1296 // the same. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 ui_loop_.PostTask(FROM_HERE, | 1351 ui_loop_.PostTask(FROM_HERE, |
| 1352 base::Bind(&ChromeAppViewAsh::OnNavigateToUrl, | 1352 base::Bind(&ChromeAppViewAsh::OnNavigateToUrl, |
| 1353 base::Unretained(this), | 1353 base::Unretained(this), |
| 1354 actual_url)); | 1354 actual_url)); |
| 1355 return S_OK; | 1355 return S_OK; |
| 1356 } | 1356 } |
| 1357 | 1357 |
| 1358 HRESULT ChromeAppViewAsh::OnEdgeGestureCompleted( | 1358 HRESULT ChromeAppViewAsh::OnEdgeGestureCompleted( |
| 1359 winui::Input::IEdgeGesture* gesture, | 1359 winui::Input::IEdgeGesture* gesture, |
| 1360 winui::Input::IEdgeGestureEventArgs* args) { | 1360 winui::Input::IEdgeGestureEventArgs* args) { |
| 1361 ui_channel_->Send(new MetroViewerHostMsg_EdgeGesture()); | 1361 if (ui_channel_) |
| 1362 ui_channel_->Send(new MetroViewerHostMsg_EdgeGesture()); |
| 1362 return S_OK; | 1363 return S_OK; |
| 1363 } | 1364 } |
| 1364 | 1365 |
| 1365 void ChromeAppViewAsh::OnSearchRequest(const base::string16& search_string) { | 1366 void ChromeAppViewAsh::OnSearchRequest(const base::string16& search_string) { |
| 1366 DCHECK(ui_channel_); | 1367 if (ui_channel_) |
| 1367 ui_channel_->Send(new MetroViewerHostMsg_SearchRequest(search_string)); | 1368 ui_channel_->Send(new MetroViewerHostMsg_SearchRequest(search_string)); |
| 1368 } | 1369 } |
| 1369 | 1370 |
| 1370 void ChromeAppViewAsh::OnNavigateToUrl(const base::string16& url) { | 1371 void ChromeAppViewAsh::OnNavigateToUrl(const base::string16& url) { |
| 1371 DCHECK(ui_channel_); | 1372 if (ui_channel_) |
| 1372 ui_channel_->Send(new MetroViewerHostMsg_OpenURL(url)); | 1373 ui_channel_->Send(new MetroViewerHostMsg_OpenURL(url)); |
| 1373 } | 1374 } |
| 1374 | 1375 |
| 1375 HRESULT ChromeAppViewAsh::OnSizeChanged(winui::Core::ICoreWindow* sender, | 1376 HRESULT ChromeAppViewAsh::OnSizeChanged(winui::Core::ICoreWindow* sender, |
| 1376 winui::Core::IWindowSizeChangedEventArgs* args) { | 1377 winui::Core::IWindowSizeChangedEventArgs* args) { |
| 1377 if (!window_) { | 1378 if (!window_) { |
| 1378 return S_OK; | 1379 return S_OK; |
| 1379 } | 1380 } |
| 1380 | 1381 |
| 1381 // winui::Core::IWindowSizeChangedEventArgs args->Size appears to return | 1382 // winui::Core::IWindowSizeChangedEventArgs args->Size appears to return |
| 1382 // scaled values under HiDPI. We will instead use GetWindowRect() which | 1383 // scaled values under HiDPI. We will instead use GetWindowRect() which |
| 1383 // should always return values in Pixels. | 1384 // should always return values in Pixels. |
| 1384 RECT rect = {0}; | 1385 RECT rect = {0}; |
| 1385 ::GetWindowRect(core_window_hwnd_, &rect); | 1386 ::GetWindowRect(core_window_hwnd_, &rect); |
| 1386 | 1387 |
| 1387 uint32 cx = static_cast<uint32>(rect.right - rect.left); | 1388 uint32 cx = static_cast<uint32>(rect.right - rect.left); |
| 1388 uint32 cy = static_cast<uint32>(rect.bottom - rect.top); | 1389 uint32 cy = static_cast<uint32>(rect.bottom - rect.top); |
| 1389 | 1390 |
| 1390 DVLOG(1) << "Window size changed: width=" << cx << ", height=" << cy; | 1391 DVLOG(1) << "Window size changed: width=" << cx << ", height=" << cy; |
| 1391 ui_channel_->Send(new MetroViewerHostMsg_WindowSizeChanged(cx, cy)); | 1392 ui_channel_->Send(new MetroViewerHostMsg_WindowSizeChanged(cx, cy)); |
| 1392 return S_OK; | 1393 return S_OK; |
| 1393 } | 1394 } |
| 1394 | 1395 |
| 1396 void ChromeAppViewAsh::StartChromeOSMode() { |
| 1397 static int ms_elapsed = 0; |
| 1398 |
| 1399 if (!IPC::Channel::IsNamedServerInitialized( |
| 1400 win8::kMetroViewerIPCChannelName) && ms_elapsed < 10000) { |
| 1401 ms_elapsed += 100; |
| 1402 ui_loop_.PostDelayedTask(FROM_HERE, |
| 1403 base::Bind(base::IgnoreResult(&ChromeAppViewAsh::StartChromeOSMode), |
| 1404 base::Unretained(this)), |
| 1405 base::TimeDelta::FromMilliseconds(kChromeChannelPollTimerMs)); |
| 1406 return; |
| 1407 } |
| 1408 |
| 1409 if (!IPC::Channel::IsNamedServerInitialized( |
| 1410 win8::kMetroViewerIPCChannelName)) { |
| 1411 DVLOG(1) << "Failed to connect to chrome channel : " |
| 1412 << win8::kMetroViewerIPCChannelName; |
| 1413 DVLOG(1) << "Exiting. Elapsed time :" << ms_elapsed; |
| 1414 PostMessage(core_window_hwnd_, WM_CLOSE, 0, 0); |
| 1415 return; |
| 1416 } |
| 1417 |
| 1418 DVLOG(1) << "Found channel : " << win8::kMetroViewerIPCChannelName; |
| 1419 |
| 1420 DCHECK(channel_listener_); |
| 1421 |
| 1422 // In Aura mode we create an IPC channel to the browser, then ask it to |
| 1423 // connect to us. |
| 1424 ui_channel_ = |
| 1425 IPC::ChannelProxy::Create(win8::kMetroViewerIPCChannelName, |
| 1426 IPC::Channel::MODE_NAMED_CLIENT, |
| 1427 channel_listener_, |
| 1428 io_thread_->message_loop_proxy()); |
| 1429 DVLOG(1) << "Created channel proxy"; |
| 1430 |
| 1431 // Upon receipt of the MetroViewerHostMsg_SetTargetSurface message the |
| 1432 // browser will use D3D from the browser process to present to our Window. |
| 1433 ui_channel_->Send(new MetroViewerHostMsg_SetTargetSurface( |
| 1434 gfx::NativeViewId(core_window_hwnd_), |
| 1435 win32_dpi_scale_)); |
| 1436 DVLOG(1) << "ICoreWindow sent " << core_window_hwnd_; |
| 1437 |
| 1438 // Send an initial size message so that the Ash root window host gets sized |
| 1439 // correctly. |
| 1440 RECT rect = {0}; |
| 1441 ::GetWindowRect(core_window_hwnd_, &rect); |
| 1442 ui_channel_->Send( |
| 1443 new MetroViewerHostMsg_WindowSizeChanged(rect.right - rect.left, |
| 1444 rect.bottom - rect.top)); |
| 1445 |
| 1446 input_source_ = metro_driver::InputSource::Create(); |
| 1447 if (input_source_) { |
| 1448 input_source_->AddObserver(this); |
| 1449 // Send an initial input source. |
| 1450 OnInputSourceChanged(); |
| 1451 } |
| 1452 |
| 1453 // Start receiving IME popup window notifications. |
| 1454 metro_driver::AddImePopupObserver(this); |
| 1455 |
| 1456 DVLOG(1) << "Channel setup complete"; |
| 1457 } |
| 1458 |
| 1395 /////////////////////////////////////////////////////////////////////////////// | 1459 /////////////////////////////////////////////////////////////////////////////// |
| 1396 | 1460 |
| 1397 ChromeAppViewFactory::ChromeAppViewFactory( | 1461 ChromeAppViewFactory::ChromeAppViewFactory( |
| 1398 winapp::Core::ICoreApplication* icore_app) { | 1462 winapp::Core::ICoreApplication* icore_app) { |
| 1399 mswr::ComPtr<winapp::Core::ICoreApplication> core_app(icore_app); | 1463 mswr::ComPtr<winapp::Core::ICoreApplication> core_app(icore_app); |
| 1400 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; | 1464 mswr::ComPtr<winapp::Core::ICoreApplicationExit> app_exit; |
| 1401 CheckHR(core_app.As(&app_exit)); | 1465 CheckHR(core_app.As(&app_exit)); |
| 1402 globals.app_exit = app_exit.Detach(); | 1466 globals.app_exit = app_exit.Detach(); |
| 1403 } | 1467 } |
| 1404 | 1468 |
| 1405 IFACEMETHODIMP | 1469 IFACEMETHODIMP |
| 1406 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { | 1470 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { |
| 1407 *view = mswr::Make<ChromeAppViewAsh>().Detach(); | 1471 *view = mswr::Make<ChromeAppViewAsh>().Detach(); |
| 1408 return (*view) ? S_OK : E_OUTOFMEMORY; | 1472 return (*view) ? S_OK : E_OUTOFMEMORY; |
| 1409 } | 1473 } |
| OLD | NEW |