OLD | NEW |
| (Empty) |
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 <stdint.h> | |
9 #include <windows.applicationmodel.core.h> | |
10 #include <windows.ui.core.h> | |
11 #include <windows.ui.input.h> | |
12 #include <windows.ui.viewmanagement.h> | |
13 | |
14 #include "base/memory/scoped_ptr.h" | |
15 #include "base/message_loop/message_loop.h" | |
16 #include "base/strings/string16.h" | |
17 #include "base/threading/thread.h" | |
18 #include "ipc/ipc_listener.h" | |
19 #include "ui/events/event_constants.h" | |
20 #include "win8/metro_driver/direct3d_helper.h" | |
21 #include "win8/metro_driver/ime/ime_popup_observer.h" | |
22 #include "win8/metro_driver/ime/input_source_observer.h" | |
23 #include "win8/metro_driver/ime/text_service_delegate.h" | |
24 | |
25 namespace base { | |
26 class FilePath; | |
27 } | |
28 | |
29 namespace IPC { | |
30 class Listener; | |
31 class ChannelProxy; | |
32 } | |
33 | |
34 namespace metro_driver { | |
35 class InputSource; | |
36 class TextService; | |
37 } | |
38 | |
39 namespace metro_viewer { | |
40 struct CharacterBounds; | |
41 struct UnderlineInfo; | |
42 } | |
43 | |
44 class OpenFilePickerSession; | |
45 class SaveFilePickerSession; | |
46 class FolderPickerSession; | |
47 class FilePickerSessionBase; | |
48 | |
49 struct MetroViewerHostMsg_SaveAsDialogParams; | |
50 | |
51 enum MetroTerminateMethod { | |
52 TERMINATE_USING_KEY_SEQUENCE = 1, | |
53 TERMINATE_USING_PROCESS_EXIT = 2, | |
54 }; | |
55 | |
56 class ChromeAppViewAsh | |
57 : public mswr::RuntimeClass<winapp::Core::IFrameworkView>, | |
58 public metro_driver::ImePopupObserver, | |
59 public metro_driver::InputSourceObserver, | |
60 public metro_driver::TextServiceDelegate { | |
61 public: | |
62 ChromeAppViewAsh(); | |
63 ~ChromeAppViewAsh() override; | |
64 | |
65 // IViewProvider overrides. | |
66 IFACEMETHOD(Initialize)(winapp::Core::ICoreApplicationView* view) override; | |
67 IFACEMETHOD(SetWindow)(winui::Core::ICoreWindow* window) override; | |
68 IFACEMETHOD(Load)(HSTRING entryPoint) override; | |
69 IFACEMETHOD(Run)() override; | |
70 IFACEMETHOD(Uninitialize)() override; | |
71 | |
72 // Helper function to unsnap the chrome metro app if it is snapped. | |
73 // Returns S_OK on success. | |
74 static HRESULT Unsnap(); | |
75 | |
76 void OnActivateDesktop(const base::FilePath& file_path, bool ash_exit); | |
77 void OnOpenURLOnDesktop(const base::FilePath& shortcut, | |
78 const base::string16& url); | |
79 void OnSetCursor(HCURSOR cursor); | |
80 void OnDisplayFileOpenDialog(const base::string16& title, | |
81 const base::string16& filter, | |
82 const base::FilePath& default_path, | |
83 bool allow_multiple_files); | |
84 void OnDisplayFileSaveAsDialog( | |
85 const MetroViewerHostMsg_SaveAsDialogParams& params); | |
86 void OnDisplayFolderPicker(const base::string16& title); | |
87 void OnSetCursorPos(int x, int y); | |
88 | |
89 // This function is invoked when the open file operation completes. The | |
90 // result of the operation is passed in along with the OpenFilePickerSession | |
91 // instance which is deleted after we read the required information from | |
92 // the OpenFilePickerSession class. | |
93 void OnOpenFileCompleted(OpenFilePickerSession* open_file_picker, | |
94 bool success); | |
95 | |
96 // This function is invoked when the save file operation completes. The | |
97 // result of the operation is passed in along with the SaveFilePickerSession | |
98 // instance which is deleted after we read the required information from | |
99 // the SaveFilePickerSession class. | |
100 void OnSaveFileCompleted(SaveFilePickerSession* save_file_picker, | |
101 bool success); | |
102 | |
103 // This function is invoked when the folder picker operation completes. The | |
104 // result of the operation is passed in along with the FolderPickerSession | |
105 // instance which is deleted after we read the required information from | |
106 // the FolderPickerSession class. | |
107 void OnFolderPickerCompleted(FolderPickerSession* folder_picker, | |
108 bool success); | |
109 | |
110 void OnImeCancelComposition(); | |
111 void OnImeUpdateTextInputClient( | |
112 const std::vector<int32_t>& input_scopes, | |
113 const std::vector<metro_viewer::CharacterBounds>& character_bounds); | |
114 | |
115 void OnMetroExit(MetroTerminateMethod method); | |
116 | |
117 HWND core_window_hwnd() const { return core_window_hwnd_; } | |
118 | |
119 | |
120 private: | |
121 class PointerInfoHandler; | |
122 | |
123 // ImePopupObserver overrides. | |
124 void OnImePopupChanged(ImePopupObserver::EventType event) override; | |
125 | |
126 // InputSourceObserver overrides. | |
127 void OnInputSourceChanged() override; | |
128 | |
129 // TextServiceDelegate overrides. | |
130 void OnCompositionChanged( | |
131 const base::string16& text, | |
132 int32_t selection_start, | |
133 int32_t selection_end, | |
134 const std::vector<metro_viewer::UnderlineInfo>& underlines) override; | |
135 void OnTextCommitted(const base::string16& text) override; | |
136 | |
137 // Convenience for sending a MetroViewerHostMsg_MouseButton with the specified | |
138 // parameters. | |
139 void SendMouseButton(int x, | |
140 int y, | |
141 int extra, | |
142 ui::EventType event_type, | |
143 uint32_t flags, | |
144 ui::EventFlags changed_button, | |
145 bool is_horizontal_wheel); | |
146 | |
147 // Win8 only generates a mouse press for the initial button that goes down and | |
148 // a release when the last button is released. Any intermediary presses (or | |
149 // releases) do not result in a new press/release event. Instead a move is | |
150 // generated with the winui::Input::PointerUpdateKind identifying what | |
151 // changed. This function generates the necessary intermediary events (as | |
152 // necessary). | |
153 void GenerateMouseEventFromMoveIfNecessary(const PointerInfoHandler& pointer); | |
154 | |
155 HRESULT OnActivate(winapp::Core::ICoreApplicationView* view, | |
156 winapp::Activation::IActivatedEventArgs* args); | |
157 | |
158 HRESULT OnPointerMoved(winui::Core::ICoreWindow* sender, | |
159 winui::Core::IPointerEventArgs* args); | |
160 | |
161 HRESULT OnPointerPressed(winui::Core::ICoreWindow* sender, | |
162 winui::Core::IPointerEventArgs* args); | |
163 | |
164 HRESULT OnPointerReleased(winui::Core::ICoreWindow* sender, | |
165 winui::Core::IPointerEventArgs* args); | |
166 | |
167 HRESULT OnWheel(winui::Core::ICoreWindow* sender, | |
168 winui::Core::IPointerEventArgs* args); | |
169 | |
170 HRESULT OnKeyDown(winui::Core::ICoreWindow* sender, | |
171 winui::Core::IKeyEventArgs* args); | |
172 | |
173 HRESULT OnKeyUp(winui::Core::ICoreWindow* sender, | |
174 winui::Core::IKeyEventArgs* args); | |
175 | |
176 // Invoked for system keys like Alt, etc. | |
177 HRESULT OnAcceleratorKeyDown(winui::Core::ICoreDispatcher* sender, | |
178 winui::Core::IAcceleratorKeyEventArgs* args); | |
179 | |
180 HRESULT OnCharacterReceived(winui::Core::ICoreWindow* sender, | |
181 winui::Core::ICharacterReceivedEventArgs* args); | |
182 | |
183 HRESULT OnWindowActivated(winui::Core::ICoreWindow* sender, | |
184 winui::Core::IWindowActivatedEventArgs* args); | |
185 | |
186 // Helper to handle search requests received via the search charm in ASH. | |
187 HRESULT HandleSearchRequest(winapp::Activation::IActivatedEventArgs* args); | |
188 // Helper to handle http/https url requests in ASH. | |
189 HRESULT HandleProtocolRequest(winapp::Activation::IActivatedEventArgs* args); | |
190 | |
191 HRESULT OnEdgeGestureCompleted(winui::Input::IEdgeGesture* gesture, | |
192 winui::Input::IEdgeGestureEventArgs* args); | |
193 | |
194 // Tasks posted to the UI thread to initiate the search/url navigation | |
195 // requests. | |
196 void OnSearchRequest(const base::string16& search_string); | |
197 void OnNavigateToUrl(const base::string16& url); | |
198 | |
199 HRESULT OnSizeChanged(winui::Core::ICoreWindow* sender, | |
200 winui::Core::IWindowSizeChangedEventArgs* args); | |
201 | |
202 // This function checks if the Chrome browser channel is initialized. If yes | |
203 // then it goes ahead and starts up the viewer in Chrome OS mode. If not it | |
204 // posts a delayed task and checks again. It does this for a duration of 10 | |
205 // seconds and then bails. | |
206 void StartChromeOSMode(); | |
207 | |
208 mswr::ComPtr<winui::Core::ICoreWindow> window_; | |
209 mswr::ComPtr<winapp::Core::ICoreApplicationView> view_; | |
210 EventRegistrationToken activated_token_; | |
211 EventRegistrationToken pointermoved_token_; | |
212 EventRegistrationToken pointerpressed_token_; | |
213 EventRegistrationToken pointerreleased_token_; | |
214 EventRegistrationToken wheel_token_; | |
215 EventRegistrationToken keydown_token_; | |
216 EventRegistrationToken keyup_token_; | |
217 EventRegistrationToken character_received_token_; | |
218 EventRegistrationToken accel_keydown_token_; | |
219 EventRegistrationToken accel_keyup_token_; | |
220 EventRegistrationToken window_activated_token_; | |
221 EventRegistrationToken sizechange_token_; | |
222 EventRegistrationToken edgeevent_token_; | |
223 | |
224 // Keep state about which button is currently down, if any, as PointerMoved | |
225 // events do not contain that state, but Ash's MouseEvents need it. Value is | |
226 // as a bitmask of ui::EventFlags. | |
227 uint32_t mouse_down_flags_; | |
228 | |
229 // Set the D3D swap chain and nothing else. | |
230 metro_driver::Direct3DHelper direct3d_helper_; | |
231 | |
232 // The IPC channel IO thread. | |
233 scoped_ptr<base::Thread> io_thread_; | |
234 | |
235 // The channel to Chrome, in particular to the MetroViewerProcessHost. | |
236 scoped_ptr<IPC::ChannelProxy> ui_channel_; | |
237 | |
238 // The actual window behind the view surface. | |
239 HWND core_window_hwnd_; | |
240 | |
241 // UI message loop to allow message passing into this thread. | |
242 base::MessageLoopForUI ui_loop_; | |
243 | |
244 // For IME support. | |
245 scoped_ptr<metro_driver::InputSource> input_source_; | |
246 scoped_ptr<metro_driver::TextService> text_service_; | |
247 | |
248 // The metro device scale factor as reported by the winrt interfaces. | |
249 float metro_dpi_scale_; | |
250 // The win32 dpi scale which is queried via GetDeviceCaps. Please refer to | |
251 // ui/gfx/win/dpi.cc for more information. | |
252 float win32_dpi_scale_; | |
253 | |
254 // The cursor set by the chroem browser process. | |
255 HCURSOR last_cursor_; | |
256 | |
257 // Pointer to the channel listener for the channel between the viewer and | |
258 // the browser. | |
259 IPC::Listener* channel_listener_; | |
260 }; | |
261 | |
262 #endif // WIN8_METRO_DRIVER_CHROME_APP_VIEW_ASH_H_ | |
OLD | NEW |