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 UI_AURA_REMOTE_ROOT_WINDOW_HOST_WIN_H_
6 #define UI_AURA_REMOTE_ROOT_WINDOW_HOST_WIN_H_
10 #include "base/callback.h"
11 #include "base/compiler_specific.h"
12 #include "base/strings/string16.h"
13 #include "ui/aura/root_window_host.h"
14 #include "ui/events/event.h"
15 #include "ui/events/event_constants.h"
16 #include "ui/gfx/native_widget_types.h"
33 typedef base::Callback<void(const base::FilePath&, int, void*)>
36 typedef base::Callback<void(const std::vector<base::FilePath>&, void*)>
37 OpenMultipleFilesCompletion;
39 typedef base::Callback<void(const base::FilePath&, int, void*)>
42 typedef base::Callback<void(const base::FilePath&, int, void*)>
43 SelectFolderCompletion;
45 typedef base::Callback<void(void*)> FileSelectionCanceled;
47 typedef base::Callback<void()> ActivateDesktopCompleted;
49 // Handles the open file operation for Metro Chrome Ash. The on_success
50 // callback passed in is invoked when we receive the opened file name from
51 // the metro viewer. The on failure callback is invoked on failure.
52 AURA_EXPORT void HandleOpenFile(const base::string16& title,
53 const base::FilePath& default_path,
54 const base::string16& filter,
55 const OpenFileCompletion& on_success,
56 const FileSelectionCanceled& on_failure);
58 // Handles the open multiple file operation for Metro Chrome Ash. The
59 // on_success callback passed in is invoked when we receive the opened file
60 // names from the metro viewer. The on failure callback is invoked on failure.
61 AURA_EXPORT void HandleOpenMultipleFiles(
62 const base::string16& title,
63 const base::FilePath& default_path,
64 const base::string16& filter,
65 const OpenMultipleFilesCompletion& on_success,
66 const FileSelectionCanceled& on_failure);
68 // Handles the save file operation for Metro Chrome Ash. The on_success
69 // callback passed in is invoked when we receive the saved file name from
70 // the metro viewer. The on failure callback is invoked on failure.
71 AURA_EXPORT void HandleSaveFile(const base::string16& title,
72 const base::FilePath& default_path,
73 const base::string16& filter,
75 const base::string16& default_extension,
76 const SaveFileCompletion& on_success,
77 const FileSelectionCanceled& on_failure);
79 // Handles the select folder for Metro Chrome Ash. The on_success
80 // callback passed in is invoked when we receive the folder name from the
81 // metro viewer. The on failure callback is invoked on failure.
82 AURA_EXPORT void HandleSelectFolder(const base::string16& title,
83 const SelectFolderCompletion& on_success,
84 const FileSelectionCanceled& on_failure);
86 // Handles the activate desktop command for Metro Chrome Ash. The on_success
87 // callback passed in is invoked when activation is completed.
88 AURA_EXPORT void HandleActivateDesktop(
89 const base::FilePath& shortcut,
90 const ActivateDesktopCompleted& on_success);
92 // RootWindowHost implementaton that receives events from a different
93 // process. In the case of Windows this is the Windows 8 (aka Metro)
94 // frontend process, which forwards input events to this class.
95 class AURA_EXPORT RemoteRootWindowHostWin : public RootWindowHost {
97 // Returns the only RemoteRootWindowHostWin, if this is the first time
98 // this function is called, it will call Create() wiht empty bounds.
99 static RemoteRootWindowHostWin* Instance();
100 static RemoteRootWindowHostWin* Create(const gfx::Rect& bounds);
102 // Called when the remote process has established its IPC connection.
103 // The |host| can be used when we need to send a message to it and
104 // |remote_window| is the actual window owned by the viewer process.
105 void Connected(IPC::Sender* host, HWND remote_window);
106 // Called when the remote process has closed its IPC connection.
109 // Called when we have a message from the remote process.
110 bool OnMessageReceived(const IPC::Message& message);
112 void HandleOpenURLOnDesktop(const base::FilePath& shortcut,
113 const base::string16& url);
115 void HandleActivateDesktop(const base::FilePath& shortcut,
116 const ActivateDesktopCompleted& on_success);
118 void HandleOpenFile(const base::string16& title,
119 const base::FilePath& default_path,
120 const base::string16& filter,
121 const OpenFileCompletion& on_success,
122 const FileSelectionCanceled& on_failure);
124 void HandleOpenMultipleFiles(const base::string16& title,
125 const base::FilePath& default_path,
126 const base::string16& filter,
127 const OpenMultipleFilesCompletion& on_success,
128 const FileSelectionCanceled& on_failure);
130 void HandleSaveFile(const base::string16& title,
131 const base::FilePath& default_path,
132 const base::string16& filter,
134 const base::string16& default_extension,
135 const SaveFileCompletion& on_success,
136 const FileSelectionCanceled& on_failure);
138 void HandleSelectFolder(const base::string16& title,
139 const SelectFolderCompletion& on_success,
140 const FileSelectionCanceled& on_failure);
142 // Returns the active ASH root window.
143 Window* GetAshWindow();
146 explicit RemoteRootWindowHostWin(const gfx::Rect& bounds);
147 virtual ~RemoteRootWindowHostWin();
149 // IPC message handing methods:
150 void OnMouseMoved(int32 x, int32 y, int32 flags);
151 void OnMouseButton(int32 x,
155 ui::EventFlags flags);
156 void OnKeyDown(uint32 vkey,
160 void OnKeyUp(uint32 vkey,
164 void OnChar(uint32 key_code,
168 void OnWindowActivated();
169 void OnTouchDown(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
170 void OnTouchUp(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
171 void OnTouchMoved(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
172 void OnFileSaveAsDone(bool success,
173 const base::FilePath& filename,
175 void OnFileOpenDone(bool success, const base::FilePath& filename);
176 void OnMultiFileOpenDone(bool success,
177 const std::vector<base::FilePath>& files);
178 void OnSelectFolderDone(bool success, const base::FilePath& folder);
179 void OnSetCursorPosAck();
180 void OnWindowSizeChanged(uint32 width, uint32 height);
181 void OnDesktopActivated();
183 // RootWindowHost overrides:
184 virtual void SetDelegate(RootWindowHostDelegate* delegate) OVERRIDE;
185 virtual RootWindow* GetRootWindow() OVERRIDE;
186 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
187 virtual void Show() OVERRIDE;
188 virtual void Hide() OVERRIDE;
189 virtual void ToggleFullScreen() OVERRIDE;
190 virtual gfx::Rect GetBounds() const OVERRIDE;
191 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
192 virtual gfx::Insets GetInsets() const OVERRIDE;
193 virtual void SetInsets(const gfx::Insets& insets) OVERRIDE;
194 virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
195 virtual void SetCapture() OVERRIDE;
196 virtual void ReleaseCapture() OVERRIDE;
197 virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
198 virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
199 virtual bool ConfineCursorToRootWindow() OVERRIDE;
200 virtual void UnConfineCursor() OVERRIDE;
201 virtual void OnCursorVisibilityChanged(bool show) OVERRIDE;
202 virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE;
203 virtual void SetFocusWhenShown(bool focus_when_shown) OVERRIDE;
204 virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE;
205 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
206 virtual void PrepareForShutdown() OVERRIDE;
208 // Helper function to dispatch a keyboard message to the desired target.
209 // The default target is the RootWindowHostDelegate. For nested message loop
210 // invocations we post a synthetic keyboard message directly into the message
211 // loop. The dispatcher for the nested loop would then decide how this
212 // message is routed.
213 void DispatchKeyboardMessage(ui::EventType type,
220 // Sets the event flags. |flags| is a bitmask of EventFlags. If there is a
221 // change the system virtual key state is updated as well. This way if chrome
222 // queries for key state it matches that of event being dispatched.
223 void SetEventFlags(uint32 flags);
225 uint32 mouse_event_flags() const {
226 return event_flags_ & (ui::EF_LEFT_MOUSE_BUTTON |
227 ui::EF_MIDDLE_MOUSE_BUTTON |
228 ui::EF_RIGHT_MOUSE_BUTTON);
231 uint32 key_event_flags() const {
232 return event_flags_ & (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN |
233 ui::EF_ALT_DOWN | ui::EF_CAPS_LOCK_DOWN);
237 RootWindowHostDelegate* delegate_;
239 scoped_ptr<ui::ViewProp> prop_;
241 // Saved callbacks which inform the caller about the result of the open file/
242 // save file/select operations.
243 OpenFileCompletion file_open_completion_callback_;
244 OpenMultipleFilesCompletion multi_file_open_completion_callback_;
245 SaveFileCompletion file_saveas_completion_callback_;
246 SelectFolderCompletion select_folder_completion_callback_;
247 FileSelectionCanceled failure_callback_;
249 // Saved callback which informs caller about successful completion of desktop
251 ActivateDesktopCompleted activate_completed_callback_;
253 // Set to true if we need to ignore mouse messages until the SetCursorPos
254 // operation is acked by the viewer.
255 bool ignore_mouse_moves_until_set_cursor_ack_;
257 // Tracking last click event for synthetically generated mouse events.
258 scoped_ptr<ui::MouseEvent> last_mouse_click_event_;
260 // State of the keyboard/mouse at the time of the last input event. See
261 // description of SetEventFlags().
264 DISALLOW_COPY_AND_ASSIGN(RemoteRootWindowHostWin);
269 #endif // UI_AURA_REMOTE_ROOT_WINDOW_HOST_WIN_H_