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