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

Side by Side Diff: win8/metro_driver/chrome_app_view.cc

Issue 11194044: Add keyboard events to metro aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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< 51 typedef winfoundtn::ITypedEventHandler<
52 winui::Core::CoreWindow*, 52 winui::Core::CoreWindow*,
53 winui::Core::PointerEventArgs*> PointerEventHandler; 53 winui::Core::PointerEventArgs*> PointerEventHandler;
54 54
55 typedef winfoundtn::ITypedEventHandler<
56 winui::Core::CoreWindow*,
57 winui::Core::KeyEventArgs*> KeyEventHandler;
58
55 struct Globals globals; 59 struct Globals globals;
56 60
57 // TODO(ananta) 61 // TODO(ananta)
58 // Remove this once we consolidate metro driver with chrome. 62 // Remove this once we consolidate metro driver with chrome.
59 const wchar_t kMetroGetCurrentTabInfoMessage[] = 63 const wchar_t kMetroGetCurrentTabInfoMessage[] =
60 L"CHROME_METRO_GET_CURRENT_TAB_INFO"; 64 L"CHROME_METRO_GET_CURRENT_TAB_INFO";
61 65
62 static const int kFlipWindowsHotKeyId = 0x0000baba; 66 static const int kFlipWindowsHotKeyId = 0x0000baba;
63 67
64 static const int kAnimateWindowTimeoutMs = 200; 68 static const int kAnimateWindowTimeoutMs = 200;
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 } 699 }
696 700
697 IFACEMETHODIMP 701 IFACEMETHODIMP
698 ChromeAppView::SetWindow(winui::Core::ICoreWindow* window) { 702 ChromeAppView::SetWindow(winui::Core::ICoreWindow* window) {
699 window_ = window; 703 window_ = window;
700 DVLOG(1) << __FUNCTION__; 704 DVLOG(1) << __FUNCTION__;
701 705
702 HRESULT hr = url_launch_handler_.Initialize(); 706 HRESULT hr = url_launch_handler_.Initialize();
703 CheckHR(hr, "Failed to initialize url launch handler."); 707 CheckHR(hr, "Failed to initialize url launch handler.");
704 708
705 // Register for size notifications.
706 hr = window_->add_SizeChanged(mswr::Callback<SizeChangedHandler>(
707 this, &ChromeAppView::OnSizeChanged).Get(),
708 &sizechange_token_);
709 CheckHR(hr);
710
711 #if defined(USE_AURA) 709 #if defined(USE_AURA)
712 // Register for pointer notifications. 710 // Register for pointer and keyboard notifications. We forward
711 // them to the browser process via IPC.
713 hr = window_->add_PointerMoved(mswr::Callback<PointerEventHandler>( 712 hr = window_->add_PointerMoved(mswr::Callback<PointerEventHandler>(
714 this, &ChromeAppView::OnPointerMoved).Get(), 713 this, &ChromeAppView::OnPointerMoved).Get(),
715 &pointermoved_token_); 714 &pointermoved_token_);
716 CheckHR(hr); 715 CheckHR(hr);
717 716
718 hr = window_->add_PointerPressed(mswr::Callback<PointerEventHandler>( 717 hr = window_->add_PointerPressed(mswr::Callback<PointerEventHandler>(
719 this, &ChromeAppView::OnPointerPressed).Get(), 718 this, &ChromeAppView::OnPointerPressed).Get(),
720 &pointerpressed_token_); 719 &pointerpressed_token_);
721 CheckHR(hr); 720 CheckHR(hr);
722 721
723 hr = window_->add_PointerReleased(mswr::Callback<PointerEventHandler>( 722 hr = window_->add_PointerReleased(mswr::Callback<PointerEventHandler>(
724 this, &ChromeAppView::OnPointerReleased).Get(), 723 this, &ChromeAppView::OnPointerReleased).Get(),
725 &pointerreleased_token_); 724 &pointerreleased_token_);
726 CheckHR(hr); 725 CheckHR(hr);
727 #endif 726
727 hr = window_->add_KeyDown(mswr::Callback<KeyEventHandler>(
728 this, &ChromeAppView::OnKeyDown).Get(),
729 &keydown_token_);
730 CheckHR(hr);
731
732 hr = window_->add_KeyUp(mswr::Callback<KeyEventHandler>(
733 this, &ChromeAppView::OnKeyUp).Get(),
734 &keyup_token_);
735 CheckHR(hr);
736
737 // By initializing the direct 3D swap chain with the corewindow
738 // we can now directly blit to it from the browser process.
739 direct3d_helper_.Initialize(window);
740 DVLOG(1) << "Initialized Direct3D.";
741 #else
742 // Register for size notifications.
743 hr = window_->add_SizeChanged(mswr::Callback<SizeChangedHandler>(
744 this, &ChromeAppView::OnSizeChanged).Get(),
scottmg 2012/10/18 00:53:19 don't we still need this if we get snapped, etc?
cpu_(ooo_6.6-7.5) 2012/10/18 20:15:26 Yes we will, but the current impl assumes we have
745 &sizechange_token_);
746 CheckHR(hr);
728 747
729 // Register for edge gesture notifications. 748 // Register for edge gesture notifications.
730 mswr::ComPtr<winui::Input::IEdgeGestureStatics> edge_gesture_statics; 749 mswr::ComPtr<winui::Input::IEdgeGestureStatics> edge_gesture_statics;
731 hr = winrt_utils::CreateActivationFactory( 750 hr = winrt_utils::CreateActivationFactory(
732 RuntimeClass_Windows_UI_Input_EdgeGesture, 751 RuntimeClass_Windows_UI_Input_EdgeGesture,
733 edge_gesture_statics.GetAddressOf()); 752 edge_gesture_statics.GetAddressOf());
734 CheckHR(hr, "Failed to activate IEdgeGestureStatics."); 753 CheckHR(hr, "Failed to activate IEdgeGestureStatics.");
735 754
736 mswr::ComPtr<winui::Input::IEdgeGesture> edge_gesture; 755 mswr::ComPtr<winui::Input::IEdgeGesture> edge_gesture;
737 hr = edge_gesture_statics->GetForCurrentView(&edge_gesture); 756 hr = edge_gesture_statics->GetForCurrentView(&edge_gesture);
(...skipping 27 matching lines...) Expand all
765 // chrome. Uncomment this once we figure out why they don't fire. 784 // chrome. Uncomment this once we figure out why they don't fire.
766 // RegisterInputPaneNotifications(); 785 // RegisterInputPaneNotifications();
767 786
768 hr = winrt_utils::CreateActivationFactory( 787 hr = winrt_utils::CreateActivationFactory(
769 RuntimeClass_Windows_UI_ViewManagement_ApplicationView, 788 RuntimeClass_Windows_UI_ViewManagement_ApplicationView,
770 app_view_.GetAddressOf()); 789 app_view_.GetAddressOf());
771 CheckHR(hr); 790 CheckHR(hr);
772 791
773 DVLOG(1) << "Created appview instance."; 792 DVLOG(1) << "Created appview instance.";
774 793
775 direct3d_helper_.Initialize(window);
776
777 DVLOG(1) << "Initialized Direct3D.";
778
779 hr = devices_handler_.Initialize(window); 794 hr = devices_handler_.Initialize(window);
780 // Don't check or return the failure here, we need to let the app 795 // Don't check or return the failure here, we need to let the app
781 // initialization succeed. Even if we won't be able to access devices 796 // initialization succeed. Even if we won't be able to access devices
782 // we still want to allow the app to start. 797 // we still want to allow the app to start.
783 LOG_IF(ERROR, FAILED(hr)) << "Failed to initialize devices handler."; 798 LOG_IF(ERROR, FAILED(hr)) << "Failed to initialize devices handler.";
799 #endif
800
784 return S_OK; 801 return S_OK;
785 } 802 }
786 803
787 IFACEMETHODIMP 804 IFACEMETHODIMP
788 ChromeAppView::Load(HSTRING entryPoint) { 805 ChromeAppView::Load(HSTRING entryPoint) {
789 DVLOG(1) << __FUNCTION__; 806 DVLOG(1) << __FUNCTION__;
790 return S_OK; 807 return S_OK;
791 } 808 }
792 809
793 void RunMessageLoop(winui::Core::ICoreDispatcher* dispatcher) { 810 void RunMessageLoop(winui::Core::ICoreDispatcher* dispatcher) {
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 DWORD chrome_ui_thread_id = 0; 1021 DWORD chrome_ui_thread_id = 0;
1005 globals.host_thread = 1022 globals.host_thread =
1006 ::CreateThread(NULL, 0, HostMainThreadProc, NULL, 0, 1023 ::CreateThread(NULL, 0, HostMainThreadProc, NULL, 0,
1007 &chrome_ui_thread_id); 1024 &chrome_ui_thread_id);
1008 1025
1009 if (!globals.host_thread) { 1026 if (!globals.host_thread) {
1010 NOTREACHED() << "thread creation failed."; 1027 NOTREACHED() << "thread creation failed.";
1011 return E_UNEXPECTED; 1028 return E_UNEXPECTED;
1012 } 1029 }
1013 } 1030 }
1014 #endif
1015 1031
1016 if (RegisterHotKey(globals.core_window, kFlipWindowsHotKeyId, 1032 if (RegisterHotKey(globals.core_window, kFlipWindowsHotKeyId,
1017 MOD_CONTROL, VK_F12)) { 1033 MOD_CONTROL, VK_F12)) {
1018 DVLOG(1) << "Registered flip window hotkey."; 1034 DVLOG(1) << "Registered flip window hotkey.";
1019 } else { 1035 } else {
1020 VPLOG(1) << "Failed to register flip window hotkey."; 1036 VPLOG(1) << "Failed to register flip window hotkey.";
1021 } 1037 }
1022 HRESULT hr = settings_handler_.Initialize(); 1038 HRESULT hr = settings_handler_.Initialize();
1023 CheckHR(hr,"Failed to initialize settings handler."); 1039 CheckHR(hr,"Failed to initialize settings handler.");
1024 return hr; 1040 return hr;
1041 #else
1042 return S_OK;
1043 #endif
1025 } 1044 }
1026 1045
1027 // We subclass the core window for moving the associated chrome window when the 1046 // We subclass the core window for moving the associated chrome window when the
1028 // core window is moved around, typically in the snap view operation. The 1047 // core window is moved around, typically in the snap view operation. The
1029 // size changes are handled in the documented size changed event. 1048 // size changes are handled in the documented size changed event.
1030 LRESULT CALLBACK ChromeAppView::CoreWindowProc( 1049 LRESULT CALLBACK ChromeAppView::CoreWindowProc(
1031 HWND window, UINT message, WPARAM wp, LPARAM lp) { 1050 HWND window, UINT message, WPARAM wp, LPARAM lp) {
1032 1051
1033 static const UINT kBrowserClosingMessage = 1052 static const UINT kBrowserClosingMessage =
1034 ::RegisterWindowMessage(L"DefaultBrowserClosing"); 1053 ::RegisterWindowMessage(L"DefaultBrowserClosing");
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 return hr; 1144 return hr;
1126 if (!pointer.is_mouse()) 1145 if (!pointer.is_mouse())
1127 return S_OK; 1146 return S_OK;
1128 1147
1129 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(pointer.x(), 1148 ui_channel_->Send(new MetroViewerHostMsg_MouseButton(pointer.x(),
1130 pointer.y(), 1149 pointer.y(),
1131 0)); 1150 0));
1132 return S_OK; 1151 return S_OK;
1133 } 1152 }
1134 1153
1154 HRESULT ChromeAppView::OnKeyDown(winui::Core::ICoreWindow* sender,
1155 winui::Core::IKeyEventArgs* args) {
1156 winsys::VirtualKey virtual_key;
1157 HRESULT hr = args->get_VirtualKey(&virtual_key);
1158 if (FAILED(hr))
1159 return hr;
1160 winui::Core::CorePhysicalKeyStatus status;
1161 hr = args->get_KeyStatus(&status);
1162 if (FAILED(hr))
1163 return hr;
1164
1165 ui_channel_->Send(new MetroViewerHostMsg_KeyDown(virtual_key,
1166 status.RepeatCount,
1167 status.ScanCode));
1168 return S_OK;
1169 }
1170
1171 HRESULT ChromeAppView::OnKeyUp(winui::Core::ICoreWindow* sender,
1172 winui::Core::IKeyEventArgs* args) {
1173 winsys::VirtualKey virtual_key;
1174 HRESULT hr = args->get_VirtualKey(&virtual_key);
1175 if (FAILED(hr))
1176 return hr;
1177 winui::Core::CorePhysicalKeyStatus status;
1178 hr = args->get_KeyStatus(&status);
1179 if (FAILED(hr))
1180 return hr;
1181
1182 ui_channel_->Send(new MetroViewerHostMsg_KeyUp(virtual_key,
1183 status.RepeatCount,
1184 status.ScanCode));
1185 return S_OK;
1186 }
1187
1135 HRESULT ChromeAppView::OnPositionChanged(int x, int y) { 1188 HRESULT ChromeAppView::OnPositionChanged(int x, int y) {
1136 DVLOG(1) << __FUNCTION__; 1189 DVLOG(1) << __FUNCTION__;
1137 1190
1138 ::SetWindowPos(globals.host_windows.front().first, NULL, x, y, 0, 0, 1191 ::SetWindowPos(globals.host_windows.front().first, NULL, x, y, 0, 0,
1139 SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSIZE); 1192 SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOSIZE);
1140 return S_OK; 1193 return S_OK;
1141 } 1194 }
1142 1195
1143 HRESULT ChromeAppView::OnEdgeGestureCompleted( 1196 HRESULT ChromeAppView::OnEdgeGestureCompleted(
1144 winui::Input::IEdgeGesture* gesture, 1197 winui::Input::IEdgeGesture* gesture,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 CheckHR(core_app.As(&app_exit)); 1381 CheckHR(core_app.As(&app_exit));
1329 globals.app_exit = app_exit.Detach(); 1382 globals.app_exit = app_exit.Detach();
1330 } 1383 }
1331 1384
1332 IFACEMETHODIMP 1385 IFACEMETHODIMP
1333 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) { 1386 ChromeAppViewFactory::CreateView(winapp::Core::IFrameworkView** view) {
1334 globals.view = mswr::Make<ChromeAppView>().Detach(); 1387 globals.view = mswr::Make<ChromeAppView>().Detach();
1335 *view = globals.view; 1388 *view = globals.view;
1336 return (*view) ? S_OK : E_OUTOFMEMORY; 1389 return (*view) ? S_OK : E_OUTOFMEMORY;
1337 } 1390 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698