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. 4 5 #ifndef WIN8_METRO_DRIVER_CHROME_APP_VIEW_ASH_H_ 6 #define WIN8_METRO_DRIVER_CHROME_APP_VIEW_ASH_H_ 7 8 #include <windows.applicationmodel.core.h> 9 #include <windows.ui.core.h> 10 #include <windows.ui.input.h> 11 #include <windows.ui.viewmanagement.h> 12 13 #include "base/files/file_path.h" 14 #include "base/memory/scoped_ptr.h" 15 #include "base/message_loop/message_loop.h" 16 #include "base/strings/string16.h" 17 #include "ui/base/events/event_constants.h" 18 #include "win8/metro_driver/direct3d_helper.h" 19 20 namespace IPC { 21 class Listener; 22 class ChannelProxy; 23 } 24 25 class OpenFilePickerSession; 26 class SaveFilePickerSession; 27 class FolderPickerSession; 28 class FilePickerSessionBase; 29 30 struct MetroViewerHostMsg_SaveAsDialogParams; 31 32 class ChromeAppViewAsh 33 : public mswr::RuntimeClass<winapp::Core::IFrameworkView> { 34 public: 35 ChromeAppViewAsh(); 36 ~ChromeAppViewAsh(); 37 38 // IViewProvider overrides. 39 IFACEMETHOD(Initialize)(winapp::Core::ICoreApplicationView* view); 40 IFACEMETHOD(SetWindow)(winui::Core::ICoreWindow* window); 41 IFACEMETHOD(Load)(HSTRING entryPoint); 42 IFACEMETHOD(Run)(); 43 IFACEMETHOD(Uninitialize)(); 44 45 // Helper function to unsnap the chrome metro app if it is snapped. 46 // Returns S_OK on success. 47 static HRESULT Unsnap(); 48 49 void OnSetCursor(HCURSOR cursor); 50 void OnDisplayFileOpenDialog(const string16& title, 51 const string16& filter, 52 const base::FilePath& default_path, 53 bool allow_multiple_files); 54 void OnDisplayFileSaveAsDialog( 55 const MetroViewerHostMsg_SaveAsDialogParams& params); 56 void OnDisplayFolderPicker(const string16& title); 57 void OnSetCursorPos(int x, int y); 58 59 // This function is invoked when the open file operation completes. The 60 // result of the operation is passed in along with the OpenFilePickerSession 61 // instance which is deleted after we read the required information from 62 // the OpenFilePickerSession class. 63 void OnOpenFileCompleted(OpenFilePickerSession* open_file_picker, 64 bool success); 65 66 // This function is invoked when the save file operation completes. The 67 // result of the operation is passed in along with the SaveFilePickerSession 68 // instance which is deleted after we read the required information from 69 // the SaveFilePickerSession class. 70 void OnSaveFileCompleted(SaveFilePickerSession* save_file_picker, 71 bool success); 72 73 // This function is invoked when the folder picker operation completes. The 74 // result of the operation is passed in along with the FolderPickerSession 75 // instance which is deleted after we read the required information from 76 // the FolderPickerSession class. 77 void OnFolderPickerCompleted(FolderPickerSession* folder_picker, 78 bool success); 79 80 private: 81 HRESULT OnActivate(winapp::Core::ICoreApplicationView* view, 82 winapp::Activation::IActivatedEventArgs* args); 83 84 HRESULT OnPointerMoved(winui::Core::ICoreWindow* sender, 85 winui::Core::IPointerEventArgs* args); 86 87 HRESULT OnPointerPressed(winui::Core::ICoreWindow* sender, 88 winui::Core::IPointerEventArgs* args); 89 90 HRESULT OnPointerReleased(winui::Core::ICoreWindow* sender, 91 winui::Core::IPointerEventArgs* args); 92 93 HRESULT OnWheel(winui::Core::ICoreWindow* sender, 94 winui::Core::IPointerEventArgs* args); 95 96 HRESULT OnKeyDown(winui::Core::ICoreWindow* sender, 97 winui::Core::IKeyEventArgs* args); 98 99 HRESULT OnKeyUp(winui::Core::ICoreWindow* sender, 100 winui::Core::IKeyEventArgs* args); 101 102 // Invoked for system keys like Alt, etc. 103 HRESULT OnAcceleratorKeyDown(winui::Core::ICoreDispatcher* sender, 104 winui::Core::IAcceleratorKeyEventArgs* args); 105 106 HRESULT OnCharacterReceived(winui::Core::ICoreWindow* sender, 107 winui::Core::ICharacterReceivedEventArgs* args); 108 109 HRESULT OnVisibilityChanged(winui::Core::ICoreWindow* sender, 110 winui::Core::IVisibilityChangedEventArgs* args); 111 112 HRESULT OnWindowActivated(winui::Core::ICoreWindow* sender, 113 winui::Core::IWindowActivatedEventArgs* args); 114 115 // Helper to handle search requests received via the search charm in ASH. 116 HRESULT HandleSearchRequest(winapp::Activation::IActivatedEventArgs* args); 117 // Helper to handle http/https url requests in ASH. 118 HRESULT HandleProtocolRequest(winapp::Activation::IActivatedEventArgs* args); 119 120 // Tasks posted to the UI thread to initiate the search/url navigation 121 // requests. 122 void OnSearchRequest(const string16& search_string); 123 void OnNavigateToUrl(const string16& url); 124 125 HRESULT OnSizeChanged(winui::Core::ICoreWindow* sender, 126 winui::Core::IWindowSizeChangedEventArgs* args); 127 128 mswr::ComPtr<winui::Core::ICoreWindow> window_; 129 mswr::ComPtr<winapp::Core::ICoreApplicationView> view_; 130 EventRegistrationToken activated_token_; 131 EventRegistrationToken pointermoved_token_; 132 EventRegistrationToken pointerpressed_token_; 133 EventRegistrationToken pointerreleased_token_; 134 EventRegistrationToken wheel_token_; 135 EventRegistrationToken keydown_token_; 136 EventRegistrationToken keyup_token_; 137 EventRegistrationToken character_received_token_; 138 EventRegistrationToken visibility_changed_token_; 139 EventRegistrationToken accel_keydown_token_; 140 EventRegistrationToken accel_keyup_token_; 141 EventRegistrationToken window_activated_token_; 142 EventRegistrationToken sizechange_token_; 143 144 // Keep state about which button is currently down, if any, as PointerMoved 145 // events do not contain that state, but Ash's MouseEvents need it. 146 ui::EventFlags mouse_down_flags_; 147 148 // Set the D3D swap chain and nothing else. 149 metro_driver::Direct3DHelper direct3d_helper_; 150 151 // The channel to Chrome, in particular to the MetroViewerProcessHost. 152 IPC::ChannelProxy* ui_channel_; 153 154 // The actual window behind the view surface. 155 HWND core_window_hwnd_; 156 157 // UI message loop to allow message passing into this thread. 158 base::MessageLoop ui_loop_; 159 }; 160 161 #endif // WIN8_METRO_DRIVER_CHROME_APP_VIEW_ASH_H_ 162