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/memory/scoped_ptr.h" 14 #include "base/message_loop/message_loop.h" 15 #include "base/strings/string16.h" 16 #include "ui/events/event_constants.h" 17 #include "win8/metro_driver/direct3d_helper.h" 18 #include "win8/metro_driver/ime/ime_popup_observer.h" 19 #include "win8/metro_driver/ime/input_source_observer.h" 20 #include "win8/metro_driver/ime/text_service_delegate.h" 21 22 namespace base { 23 class FilePath; 24 } 25 26 namespace IPC { 27 class Listener; 28 class ChannelProxy; 29 } 30 31 namespace metro_driver { 32 class InputSource; 33 class TextService; 34 } 35 36 namespace metro_viewer { 37 struct CharacterBounds; 38 struct UnderlineInfo; 39 } 40 41 class OpenFilePickerSession; 42 class SaveFilePickerSession; 43 class FolderPickerSession; 44 class FilePickerSessionBase; 45 46 struct MetroViewerHostMsg_SaveAsDialogParams; 47 48 class ChromeAppViewAsh 49 : public mswr::RuntimeClass<winapp::Core::IFrameworkView>, 50 public metro_driver::ImePopupObserver, 51 public metro_driver::InputSourceObserver, 52 public metro_driver::TextServiceDelegate { 53 public: 54 ChromeAppViewAsh(); 55 ~ChromeAppViewAsh(); 56 57 // IViewProvider overrides. 58 IFACEMETHOD(Initialize)(winapp::Core::ICoreApplicationView* view); 59 IFACEMETHOD(SetWindow)(winui::Core::ICoreWindow* window); 60 IFACEMETHOD(Load)(HSTRING entryPoint); 61 IFACEMETHOD(Run)(); 62 IFACEMETHOD(Uninitialize)(); 63 64 // Helper function to unsnap the chrome metro app if it is snapped. 65 // Returns S_OK on success. 66 static HRESULT Unsnap(); 67 68 void OnActivateDesktop(const base::FilePath& file_path, bool ash_exit); 69 void OnOpenURLOnDesktop(const base::FilePath& shortcut, const string16& url); 70 void OnSetCursor(HCURSOR cursor); 71 void OnDisplayFileOpenDialog(const string16& title, 72 const string16& filter, 73 const base::FilePath& default_path, 74 bool allow_multiple_files); 75 void OnDisplayFileSaveAsDialog( 76 const MetroViewerHostMsg_SaveAsDialogParams& params); 77 void OnDisplayFolderPicker(const string16& title); 78 void OnSetCursorPos(int x, int y); 79 80 // This function is invoked when the open file operation completes. The 81 // result of the operation is passed in along with the OpenFilePickerSession 82 // instance which is deleted after we read the required information from 83 // the OpenFilePickerSession class. 84 void OnOpenFileCompleted(OpenFilePickerSession* open_file_picker, 85 bool success); 86 87 // This function is invoked when the save file operation completes. The 88 // result of the operation is passed in along with the SaveFilePickerSession 89 // instance which is deleted after we read the required information from 90 // the SaveFilePickerSession class. 91 void OnSaveFileCompleted(SaveFilePickerSession* save_file_picker, 92 bool success); 93 94 // This function is invoked when the folder picker operation completes. The 95 // result of the operation is passed in along with the FolderPickerSession 96 // instance which is deleted after we read the required information from 97 // the FolderPickerSession class. 98 void OnFolderPickerCompleted(FolderPickerSession* folder_picker, 99 bool success); 100 101 void OnImeCancelComposition(); 102 void OnImeUpdateTextInputClient( 103 const std::vector<int32>& input_scopes, 104 const std::vector<metro_viewer::CharacterBounds>& character_bounds); 105 106 HWND core_window_hwnd() const { return core_window_hwnd_; } 107 108 109 private: 110 // ImePopupObserver overrides. 111 virtual void OnImePopupChanged(ImePopupObserver::EventType event) OVERRIDE; 112 113 // InputSourceObserver overrides. 114 virtual void OnInputSourceChanged() OVERRIDE; 115 116 // TextServiceDelegate overrides. 117 virtual void OnCompositionChanged( 118 const string16& text, 119 int32 selection_start, 120 int32 selection_end, 121 const std::vector<metro_viewer::UnderlineInfo>& underlines) OVERRIDE; 122 virtual void OnTextCommitted(const string16& text) OVERRIDE; 123 124 HRESULT OnActivate(winapp::Core::ICoreApplicationView* view, 125 winapp::Activation::IActivatedEventArgs* args); 126 127 HRESULT OnPointerMoved(winui::Core::ICoreWindow* sender, 128 winui::Core::IPointerEventArgs* args); 129 130 HRESULT OnPointerPressed(winui::Core::ICoreWindow* sender, 131 winui::Core::IPointerEventArgs* args); 132 133 HRESULT OnPointerReleased(winui::Core::ICoreWindow* sender, 134 winui::Core::IPointerEventArgs* args); 135 136 HRESULT OnWheel(winui::Core::ICoreWindow* sender, 137 winui::Core::IPointerEventArgs* args); 138 139 HRESULT OnKeyDown(winui::Core::ICoreWindow* sender, 140 winui::Core::IKeyEventArgs* args); 141 142 HRESULT OnKeyUp(winui::Core::ICoreWindow* sender, 143 winui::Core::IKeyEventArgs* args); 144 145 // Invoked for system keys like Alt, etc. 146 HRESULT OnAcceleratorKeyDown(winui::Core::ICoreDispatcher* sender, 147 winui::Core::IAcceleratorKeyEventArgs* args); 148 149 HRESULT OnCharacterReceived(winui::Core::ICoreWindow* sender, 150 winui::Core::ICharacterReceivedEventArgs* args); 151 152 HRESULT OnWindowActivated(winui::Core::ICoreWindow* sender, 153 winui::Core::IWindowActivatedEventArgs* args); 154 155 // Helper to handle search requests received via the search charm in ASH. 156 HRESULT HandleSearchRequest(winapp::Activation::IActivatedEventArgs* args); 157 // Helper to handle http/https url requests in ASH. 158 HRESULT HandleProtocolRequest(winapp::Activation::IActivatedEventArgs* args); 159 160 HRESULT OnEdgeGestureCompleted(winui::Input::IEdgeGesture* gesture, 161 winui::Input::IEdgeGestureEventArgs* args); 162 163 // Tasks posted to the UI thread to initiate the search/url navigation 164 // requests. 165 void OnSearchRequest(const string16& search_string); 166 void OnNavigateToUrl(const string16& url); 167 168 HRESULT OnSizeChanged(winui::Core::ICoreWindow* sender, 169 winui::Core::IWindowSizeChangedEventArgs* args); 170 171 mswr::ComPtr<winui::Core::ICoreWindow> window_; 172 mswr::ComPtr<winapp::Core::ICoreApplicationView> view_; 173 EventRegistrationToken activated_token_; 174 EventRegistrationToken pointermoved_token_; 175 EventRegistrationToken pointerpressed_token_; 176 EventRegistrationToken pointerreleased_token_; 177 EventRegistrationToken wheel_token_; 178 EventRegistrationToken keydown_token_; 179 EventRegistrationToken keyup_token_; 180 EventRegistrationToken character_received_token_; 181 EventRegistrationToken accel_keydown_token_; 182 EventRegistrationToken accel_keyup_token_; 183 EventRegistrationToken window_activated_token_; 184 EventRegistrationToken sizechange_token_; 185 EventRegistrationToken edgeevent_token_; 186 187 // Keep state about which button is currently down, if any, as PointerMoved 188 // events do not contain that state, but Ash's MouseEvents need it. 189 ui::EventFlags mouse_down_flags_; 190 191 // Set the D3D swap chain and nothing else. 192 metro_driver::Direct3DHelper direct3d_helper_; 193 194 // The channel to Chrome, in particular to the MetroViewerProcessHost. 195 IPC::ChannelProxy* ui_channel_; 196 197 // The actual window behind the view surface. 198 HWND core_window_hwnd_; 199 200 // UI message loop to allow message passing into this thread. 201 base::MessageLoop ui_loop_; 202 203 // For IME support. 204 scoped_ptr<metro_driver::InputSource> input_source_; 205 scoped_ptr<metro_driver::TextService> text_service_; 206 }; 207 208 #endif // WIN8_METRO_DRIVER_CHROME_APP_VIEW_ASH_H_ 209