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"
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"
31 namespace metro_driver
{
36 namespace metro_viewer
{
37 struct CharacterBounds
;
41 class OpenFilePickerSession
;
42 class SaveFilePickerSession
;
43 class FolderPickerSession
;
44 class FilePickerSessionBase
;
46 struct MetroViewerHostMsg_SaveAsDialogParams
;
48 enum MetroTerminateMethod
{
49 TERMINATE_USING_KEY_SEQUENCE
= 1,
50 TERMINATE_USING_PROCESS_EXIT
= 2,
53 class ChromeAppViewAsh
54 : public mswr::RuntimeClass
<winapp::Core::IFrameworkView
>,
55 public metro_driver::ImePopupObserver
,
56 public metro_driver::InputSourceObserver
,
57 public metro_driver::TextServiceDelegate
{
62 // IViewProvider overrides.
63 IFACEMETHOD(Initialize
)(winapp::Core::ICoreApplicationView
* view
);
64 IFACEMETHOD(SetWindow
)(winui::Core::ICoreWindow
* window
);
65 IFACEMETHOD(Load
)(HSTRING entryPoint
);
67 IFACEMETHOD(Uninitialize
)();
69 // Helper function to unsnap the chrome metro app if it is snapped.
70 // Returns S_OK on success.
71 static HRESULT
Unsnap();
73 void OnActivateDesktop(const base::FilePath
& file_path
, bool ash_exit
);
74 void OnOpenURLOnDesktop(const base::FilePath
& shortcut
,
75 const base::string16
& url
);
76 void OnSetCursor(HCURSOR cursor
);
77 void OnDisplayFileOpenDialog(const base::string16
& title
,
78 const base::string16
& filter
,
79 const base::FilePath
& default_path
,
80 bool allow_multiple_files
);
81 void OnDisplayFileSaveAsDialog(
82 const MetroViewerHostMsg_SaveAsDialogParams
& params
);
83 void OnDisplayFolderPicker(const base::string16
& title
);
84 void OnSetCursorPos(int x
, int y
);
86 // This function is invoked when the open file operation completes. The
87 // result of the operation is passed in along with the OpenFilePickerSession
88 // instance which is deleted after we read the required information from
89 // the OpenFilePickerSession class.
90 void OnOpenFileCompleted(OpenFilePickerSession
* open_file_picker
,
93 // This function is invoked when the save file operation completes. The
94 // result of the operation is passed in along with the SaveFilePickerSession
95 // instance which is deleted after we read the required information from
96 // the SaveFilePickerSession class.
97 void OnSaveFileCompleted(SaveFilePickerSession
* save_file_picker
,
100 // This function is invoked when the folder picker operation completes. The
101 // result of the operation is passed in along with the FolderPickerSession
102 // instance which is deleted after we read the required information from
103 // the FolderPickerSession class.
104 void OnFolderPickerCompleted(FolderPickerSession
* folder_picker
,
107 void OnImeCancelComposition();
108 void OnImeUpdateTextInputClient(
109 const std::vector
<int32
>& input_scopes
,
110 const std::vector
<metro_viewer::CharacterBounds
>& character_bounds
);
112 void OnMetroExit(MetroTerminateMethod method
);
114 HWND
core_window_hwnd() const { return core_window_hwnd_
; }
118 class PointerInfoHandler
;
120 // ImePopupObserver overrides.
121 virtual void OnImePopupChanged(ImePopupObserver::EventType event
) OVERRIDE
;
123 // InputSourceObserver overrides.
124 virtual void OnInputSourceChanged() OVERRIDE
;
126 // TextServiceDelegate overrides.
127 virtual void OnCompositionChanged(
128 const base::string16
& text
,
129 int32 selection_start
,
131 const std::vector
<metro_viewer::UnderlineInfo
>& underlines
) OVERRIDE
;
132 virtual void OnTextCommitted(const base::string16
& text
) OVERRIDE
;
134 // Convenience for sending a MetroViewerHostMsg_MouseButton with the specified
136 void SendMouseButton(int x
,
139 ui::EventType event_type
,
141 ui::EventFlags changed_button
,
142 bool is_horizontal_wheel
);
144 // Win8 only generates a mouse press for the initial button that goes down and
145 // a release when the last button is released. Any intermediary presses (or
146 // releases) do not result in a new press/release event. Instead a move is
147 // generated with the winui::Input::PointerUpdateKind identifying what
148 // changed. This function generates the necessary intermediary events (as
150 void GenerateMouseEventFromMoveIfNecessary(const PointerInfoHandler
& pointer
);
152 HRESULT
OnActivate(winapp::Core::ICoreApplicationView
* view
,
153 winapp::Activation::IActivatedEventArgs
* args
);
155 HRESULT
OnPointerMoved(winui::Core::ICoreWindow
* sender
,
156 winui::Core::IPointerEventArgs
* args
);
158 HRESULT
OnPointerPressed(winui::Core::ICoreWindow
* sender
,
159 winui::Core::IPointerEventArgs
* args
);
161 HRESULT
OnPointerReleased(winui::Core::ICoreWindow
* sender
,
162 winui::Core::IPointerEventArgs
* args
);
164 HRESULT
OnWheel(winui::Core::ICoreWindow
* sender
,
165 winui::Core::IPointerEventArgs
* args
);
167 HRESULT
OnKeyDown(winui::Core::ICoreWindow
* sender
,
168 winui::Core::IKeyEventArgs
* args
);
170 HRESULT
OnKeyUp(winui::Core::ICoreWindow
* sender
,
171 winui::Core::IKeyEventArgs
* args
);
173 // Invoked for system keys like Alt, etc.
174 HRESULT
OnAcceleratorKeyDown(winui::Core::ICoreDispatcher
* sender
,
175 winui::Core::IAcceleratorKeyEventArgs
* args
);
177 HRESULT
OnCharacterReceived(winui::Core::ICoreWindow
* sender
,
178 winui::Core::ICharacterReceivedEventArgs
* args
);
180 HRESULT
OnWindowActivated(winui::Core::ICoreWindow
* sender
,
181 winui::Core::IWindowActivatedEventArgs
* args
);
183 // Helper to handle search requests received via the search charm in ASH.
184 HRESULT
HandleSearchRequest(winapp::Activation::IActivatedEventArgs
* args
);
185 // Helper to handle http/https url requests in ASH.
186 HRESULT
HandleProtocolRequest(winapp::Activation::IActivatedEventArgs
* args
);
188 HRESULT
OnEdgeGestureCompleted(winui::Input::IEdgeGesture
* gesture
,
189 winui::Input::IEdgeGestureEventArgs
* args
);
191 // Tasks posted to the UI thread to initiate the search/url navigation
193 void OnSearchRequest(const base::string16
& search_string
);
194 void OnNavigateToUrl(const base::string16
& url
);
196 HRESULT
OnSizeChanged(winui::Core::ICoreWindow
* sender
,
197 winui::Core::IWindowSizeChangedEventArgs
* args
);
199 mswr::ComPtr
<winui::Core::ICoreWindow
> window_
;
200 mswr::ComPtr
<winapp::Core::ICoreApplicationView
> view_
;
201 EventRegistrationToken activated_token_
;
202 EventRegistrationToken pointermoved_token_
;
203 EventRegistrationToken pointerpressed_token_
;
204 EventRegistrationToken pointerreleased_token_
;
205 EventRegistrationToken wheel_token_
;
206 EventRegistrationToken keydown_token_
;
207 EventRegistrationToken keyup_token_
;
208 EventRegistrationToken character_received_token_
;
209 EventRegistrationToken accel_keydown_token_
;
210 EventRegistrationToken accel_keyup_token_
;
211 EventRegistrationToken window_activated_token_
;
212 EventRegistrationToken sizechange_token_
;
213 EventRegistrationToken edgeevent_token_
;
215 // Keep state about which button is currently down, if any, as PointerMoved
216 // events do not contain that state, but Ash's MouseEvents need it. Value is
217 // as a bitmask of ui::EventFlags.
218 uint32 mouse_down_flags_
;
220 // Set the D3D swap chain and nothing else.
221 metro_driver::Direct3DHelper direct3d_helper_
;
223 // The channel to Chrome, in particular to the MetroViewerProcessHost.
224 IPC::ChannelProxy
* ui_channel_
;
226 // The actual window behind the view surface.
227 HWND core_window_hwnd_
;
229 // UI message loop to allow message passing into this thread.
230 base::MessageLoopForUI ui_loop_
;
233 scoped_ptr
<metro_driver::InputSource
> input_source_
;
234 scoped_ptr
<metro_driver::TextService
> text_service_
;
237 #endif // WIN8_METRO_DRIVER_CHROME_APP_VIEW_ASH_H_