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.h" | 6 #include "win8/metro_driver/chrome_app_view.h" |
7 #include "win8/metro_driver/direct3d_helper.h" | 7 #include "win8/metro_driver/direct3d_helper.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <windows.applicationModel.datatransfer.h> | 10 #include <windows.applicationModel.datatransfer.h> |
(...skipping 30 matching lines...) Expand all Loading... |
41 | 41 |
42 typedef winfoundtn::ITypedEventHandler< | 42 typedef winfoundtn::ITypedEventHandler< |
43 winapp::DataTransfer::DataTransferManager*, | 43 winapp::DataTransfer::DataTransferManager*, |
44 winapp::DataTransfer::DataRequestedEventArgs*> ShareDataRequestedHandler; | 44 winapp::DataTransfer::DataRequestedEventArgs*> ShareDataRequestedHandler; |
45 | 45 |
46 typedef winfoundtn::ITypedEventHandler< | 46 typedef winfoundtn::ITypedEventHandler< |
47 winui::ViewManagement::InputPane*, | 47 winui::ViewManagement::InputPane*, |
48 winui::ViewManagement::InputPaneVisibilityEventArgs*> | 48 winui::ViewManagement::InputPaneVisibilityEventArgs*> |
49 InputPaneEventHandler; | 49 InputPaneEventHandler; |
50 | 50 |
| 51 typedef winfoundtn::ITypedEventHandler< |
| 52 winui::Core::CoreWindow*, |
| 53 winui::Core::PointerEventArgs*> PointerEventHandler; |
| 54 |
51 struct Globals globals; | 55 struct Globals globals; |
52 | 56 |
53 // TODO(ananta) | 57 // TODO(ananta) |
54 // Remove this once we consolidate metro driver with chrome. | 58 // Remove this once we consolidate metro driver with chrome. |
55 const wchar_t kMetroGetCurrentTabInfoMessage[] = | 59 const wchar_t kMetroGetCurrentTabInfoMessage[] = |
56 L"CHROME_METRO_GET_CURRENT_TAB_INFO"; | 60 L"CHROME_METRO_GET_CURRENT_TAB_INFO"; |
57 | 61 |
58 static const int kFlipWindowsHotKeyId = 0x0000baba; | 62 static const int kFlipWindowsHotKeyId = 0x0000baba; |
59 | 63 |
60 static const int kAnimateWindowTimeoutMs = 200; | 64 static const int kAnimateWindowTimeoutMs = 200; |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
659 reinterpret_cast<long>(ChromeAppView::CoreWindowProc))); | 663 reinterpret_cast<long>(ChromeAppView::CoreWindowProc))); |
660 DWORD exit_code = globals.host_main(globals.host_context); | 664 DWORD exit_code = globals.host_main(globals.host_context); |
661 | 665 |
662 DVLOG(1) << "host thread done, exit_code=" << exit_code; | 666 DVLOG(1) << "host thread done, exit_code=" << exit_code; |
663 MetroExit(); | 667 MetroExit(); |
664 return exit_code; | 668 return exit_code; |
665 } | 669 } |
666 | 670 |
667 ChromeAppView::ChromeAppView() | 671 ChromeAppView::ChromeAppView() |
668 : osk_visible_notification_received_(false), | 672 : osk_visible_notification_received_(false), |
669 osk_offset_adjustment_(0) { | 673 osk_offset_adjustment_(0), |
| 674 ui_channel_(nullptr), |
| 675 ui_channel_listener_(nullptr) { |
670 globals.previous_state = | 676 globals.previous_state = |
671 winapp::Activation::ApplicationExecutionState_NotRunning; | 677 winapp::Activation::ApplicationExecutionState_NotRunning; |
672 } | 678 } |
673 | 679 |
674 ChromeAppView::~ChromeAppView() { | 680 ChromeAppView::~ChromeAppView() { |
675 DVLOG(1) << __FUNCTION__; | 681 DVLOG(1) << __FUNCTION__; |
676 } | 682 } |
677 | 683 |
678 IFACEMETHODIMP | 684 IFACEMETHODIMP |
679 ChromeAppView::Initialize(winapp::Core::ICoreApplicationView* view) { | 685 ChromeAppView::Initialize(winapp::Core::ICoreApplicationView* view) { |
(...skipping 15 matching lines...) Expand all Loading... |
695 | 701 |
696 HRESULT hr = url_launch_handler_.Initialize(); | 702 HRESULT hr = url_launch_handler_.Initialize(); |
697 CheckHR(hr, "Failed to initialize url launch handler."); | 703 CheckHR(hr, "Failed to initialize url launch handler."); |
698 | 704 |
699 // Register for size notifications. | 705 // Register for size notifications. |
700 hr = window_->add_SizeChanged(mswr::Callback<SizeChangedHandler>( | 706 hr = window_->add_SizeChanged(mswr::Callback<SizeChangedHandler>( |
701 this, &ChromeAppView::OnSizeChanged).Get(), | 707 this, &ChromeAppView::OnSizeChanged).Get(), |
702 &sizechange_token_); | 708 &sizechange_token_); |
703 CheckHR(hr); | 709 CheckHR(hr); |
704 | 710 |
| 711 #if defined(USE_AURA) |
| 712 // Register for pointer notifications. |
| 713 hr = window_->add_PointerMoved(mswr::Callback<PointerEventHandler>( |
| 714 this, &ChromeAppView::OnPointerMoved).Get(), |
| 715 &pointermoved_token_); |
| 716 CheckHR(hr); |
| 717 |
| 718 hr = window_->add_PointerPressed(mswr::Callback<PointerEventHandler>( |
| 719 this, &ChromeAppView::OnPointerPressed).Get(), |
| 720 &pointerpressed_token_); |
| 721 CheckHR(hr); |
| 722 |
| 723 hr = window_->add_PointerReleased(mswr::Callback<PointerEventHandler>( |
| 724 this, &ChromeAppView::OnPointerReleased).Get(), |
| 725 &pointerreleased_token_); |
| 726 CheckHR(hr); |
| 727 #endif |
| 728 |
705 // Register for edge gesture notifications. | 729 // Register for edge gesture notifications. |
706 mswr::ComPtr<winui::Input::IEdgeGestureStatics> edge_gesture_statics; | 730 mswr::ComPtr<winui::Input::IEdgeGestureStatics> edge_gesture_statics; |
707 hr = winrt_utils::CreateActivationFactory( | 731 hr = winrt_utils::CreateActivationFactory( |
708 RuntimeClass_Windows_UI_Input_EdgeGesture, | 732 RuntimeClass_Windows_UI_Input_EdgeGesture, |
709 edge_gesture_statics.GetAddressOf()); | 733 edge_gesture_statics.GetAddressOf()); |
710 CheckHR(hr, "Failed to activate IEdgeGestureStatics."); | 734 CheckHR(hr, "Failed to activate IEdgeGestureStatics."); |
711 | 735 |
712 mswr::ComPtr<winui::Input::IEdgeGesture> edge_gesture; | 736 mswr::ComPtr<winui::Input::IEdgeGesture> edge_gesture; |
713 hr = edge_gesture_statics->GetForCurrentView(&edge_gesture); | 737 hr = edge_gesture_statics->GetForCurrentView(&edge_gesture); |
714 CheckHR(hr); | 738 CheckHR(hr); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 | 864 |
841 // Announce our message loop to the world. | 865 // Announce our message loop to the world. |
842 globals.appview_msg_loop = msg_loop.message_loop_proxy(); | 866 globals.appview_msg_loop = msg_loop.message_loop_proxy(); |
843 | 867 |
844 // The thread needs to out-live the ChannelProxy. | 868 // The thread needs to out-live the ChannelProxy. |
845 base::Thread thread("metro_IO_thread"); | 869 base::Thread thread("metro_IO_thread"); |
846 base::Thread::Options options; | 870 base::Thread::Options options; |
847 options.message_loop_type = MessageLoop::TYPE_IO; | 871 options.message_loop_type = MessageLoop::TYPE_IO; |
848 thread.StartWithOptions(options); | 872 thread.StartWithOptions(options); |
849 | 873 |
850 // The viewer channel opened below only applies when we are launched as an | 874 |
851 // AURA viewer process. | |
852 #if defined(USE_AURA) | 875 #if defined(USE_AURA) |
853 ChromeChannelListener channel_listener; | 876 // In Aura mode we create an IPC channel to the browser which should |
854 IPC::ChannelProxy chan("viewer", IPC::Channel::MODE_NAMED_CLIENT, | 877 // be already running. |
855 &channel_listener, thread.message_loop_proxy()); | 878 ChromeChannelListener ui_channel_listener; |
856 channel_listener.Init(&chan); | 879 IPC::ChannelProxy ui_channel("viewer", |
857 chan.Send(new MetroViewerHostMsg_SetTargetSurface( | 880 IPC::Channel::MODE_NAMED_CLIENT, |
858 gfx::NativeViewId(globals.core_window))); | 881 &ui_channel_listener, |
| 882 thread.message_loop_proxy()); |
| 883 ui_channel_listener.Init(&ui_channel); |
| 884 |
| 885 ui_channel_listener_ = &ui_channel_listener; |
| 886 ui_channel_ = &ui_channel; |
| 887 |
| 888 ui_channel_->Send(new MetroViewerHostMsg_SetTargetSurface( |
| 889 gfx::NativeViewId(globals.core_window))); |
859 | 890 |
860 DVLOG(1) << "ICoreWindow sent " << globals.core_window; | 891 DVLOG(1) << "ICoreWindow sent " << globals.core_window; |
861 #endif | 892 #endif |
862 // And post the task that'll do the inner Metro message pumping to it. | 893 // And post the task that'll do the inner Metro message pumping to it. |
863 msg_loop.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); | 894 msg_loop.PostTask(FROM_HERE, base::Bind(&RunMessageLoop, dispatcher.Get())); |
864 | 895 |
865 // Post the recurring task which checks for OSK activation in metro chrome. | 896 // Post the recurring task which checks for OSK activation in metro chrome. |
866 // Please refer to the comments in the CheckForOSKActivation function for why | 897 // Please refer to the comments in the CheckForOSKActivation function for why |
867 // this is needed. | 898 // this is needed. |
868 // TODO(ananta) | 899 // TODO(ananta) |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 HWND top_level_frame = globals.host_windows.front().first; | 1080 HWND top_level_frame = globals.host_windows.front().first; |
1050 if (view_state == winui::ViewManagement::ApplicationViewState_Snapped) { | 1081 if (view_state == winui::ViewManagement::ApplicationViewState_Snapped) { |
1051 DVLOG(1) << "Enabling metro snap mode."; | 1082 DVLOG(1) << "Enabling metro snap mode."; |
1052 ::PostMessageW(top_level_frame, WM_SYSCOMMAND, IDC_METRO_SNAP_ENABLE, 0); | 1083 ::PostMessageW(top_level_frame, WM_SYSCOMMAND, IDC_METRO_SNAP_ENABLE, 0); |
1053 } else { | 1084 } else { |
1054 ::PostMessageW(top_level_frame, WM_SYSCOMMAND, IDC_METRO_SNAP_DISABLE, 0); | 1085 ::PostMessageW(top_level_frame, WM_SYSCOMMAND, IDC_METRO_SNAP_DISABLE, 0); |
1055 } | 1086 } |
1056 return S_OK; | 1087 return S_OK; |
1057 } | 1088 } |
1058 | 1089 |
| 1090 HRESULT ChromeAppView::OnPointerMoved(winui::Core::ICoreWindow* sender, |
| 1091 winui::Core::IPointerEventArgs* args) { |
| 1092 metro_driver::PointerEventHandler pointer; |
| 1093 HRESULT hr = pointer.Init(args); |
| 1094 if (FAILED(hr)) |
| 1095 return hr; |
| 1096 if (!pointer.is_mouse()) |
| 1097 return S_OK; |
| 1098 |
| 1099 ui_channel_->Send(new MetroViewerHostMsg_MouseMoved(pointer.x(), |
| 1100 pointer.y(), |
| 1101 0)); |
| 1102 return S_OK; |
| 1103 } |
| 1104 |
| 1105 HRESULT ChromeAppView::OnPointerPressed(winui::Core::ICoreWindow* sender, |
| 1106 winui::Core::IPointerEventArgs* args) { |
| 1107 metro_driver::PointerEventHandler pointer; |
| 1108 HRESULT hr = pointer.Init(args); |
| 1109 if (FAILED(hr)) |
| 1110 return hr; |
| 1111 if (!pointer.is_mouse()) |
| 1112 return S_OK; |
| 1113 |
| 1114 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(pointer.x(), |
| 1115 pointer.y(), |
| 1116 1)); |
| 1117 return S_OK; |
| 1118 } |
| 1119 |
| 1120 HRESULT ChromeAppView::OnPointerReleased(winui::Core::ICoreWindow* sender, |
| 1121 winui::Core::IPointerEventArgs* args) { |
| 1122 metro_driver::PointerEventHandler pointer; |
| 1123 HRESULT hr = pointer.Init(args); |
| 1124 if (FAILED(hr)) |
| 1125 return hr; |
| 1126 if (!pointer.is_mouse()) |
| 1127 return S_OK; |
| 1128 |
| 1129 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(pointer.x(), |
| 1130 pointer.y(), |
| 1131 0)); |
| 1132 return S_OK; |
| 1133 } |
| 1134 |
1059 HRESULT ChromeAppView::OnPositionChanged(int x, int y) { | 1135 HRESULT ChromeAppView::OnPositionChanged(int x, int y) { |
1060 DVLOG(1) << __FUNCTION__; | 1136 DVLOG(1) << __FUNCTION__; |
1061 | 1137 |
1062 ::SetWindowPos(globals.host_windows.front().first, NULL, x, y, 0, 0, | 1138 ::SetWindowPos(globals.host_windows.front().first, NULL, x, y, 0, 0, |
1063 SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSIZE); | 1139 SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSIZE); |
1064 return S_OK; | 1140 return S_OK; |
1065 } | 1141 } |
1066 | 1142 |
1067 HRESULT ChromeAppView::OnEdgeGestureCompleted( | 1143 HRESULT ChromeAppView::OnEdgeGestureCompleted( |
1068 winui::Input::IEdgeGesture* gesture, | 1144 winui::Input::IEdgeGesture* gesture, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 CheckHR(core_app.As(&app_exit)); | 1328 CheckHR(core_app.As(&app_exit)); |
1253 globals.app_exit = app_exit.Detach(); | 1329 globals.app_exit = app_exit.Detach(); |
1254 } | 1330 } |
1255 | 1331 |
1256 IFACEMETHODIMP | 1332 IFACEMETHODIMP |
1257 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { | 1333 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { |
1258 globals.view = mswr::Make<ChromeAppView>().Detach(); | 1334 globals.view = mswr::Make<ChromeAppView>().Detach(); |
1259 *view = globals.view; | 1335 *view = globals.view; |
1260 return (*view) ? S_OK : E_OUTOFMEMORY; | 1336 return (*view) ? S_OK : E_OUTOFMEMORY; |
1261 } | 1337 } |
OLD | NEW |