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/window_tree_host.h"
14 #include "ui/base/ime/remote_input_method_delegate_win.h"
15 #include "ui/events/event.h"
16 #include "ui/events/event_constants.h"
17 #include "ui/gfx/native_widget_types.h"
18 #include "ui/metro_viewer/ime_types.h"
20 struct MetroViewerHostMsg_MouseButtonParams;
27 class RemoteInputMethodPrivateWin;
38 typedef base::Callback<void(const base::FilePath&, int, void*)>
41 typedef base::Callback<void(const std::vector<base::FilePath>&, void*)>
42 OpenMultipleFilesCompletion;
44 typedef base::Callback<void(const base::FilePath&, int, void*)>
47 typedef base::Callback<void(const base::FilePath&, int, void*)>
48 SelectFolderCompletion;
50 typedef base::Callback<void(void*)> FileSelectionCanceled;
52 // Handles the open file operation for Metro Chrome Ash. The on_success
53 // callback passed in is invoked when we receive the opened file name from
54 // the metro viewer. The on failure callback is invoked on failure.
55 AURA_EXPORT void HandleOpenFile(const base::string16& title,
56 const base::FilePath& default_path,
57 const base::string16& filter,
58 const OpenFileCompletion& on_success,
59 const FileSelectionCanceled& on_failure);
61 // Handles the open multiple file operation for Metro Chrome Ash. The
62 // on_success callback passed in is invoked when we receive the opened file
63 // names from the metro viewer. The on failure callback is invoked on failure.
64 AURA_EXPORT void HandleOpenMultipleFiles(
65 const base::string16& title,
66 const base::FilePath& default_path,
67 const base::string16& filter,
68 const OpenMultipleFilesCompletion& on_success,
69 const FileSelectionCanceled& on_failure);
71 // Handles the save file operation for Metro Chrome Ash. The on_success
72 // callback passed in is invoked when we receive the saved file name from
73 // the metro viewer. The on failure callback is invoked on failure.
74 AURA_EXPORT void HandleSaveFile(const base::string16& title,
75 const base::FilePath& default_path,
76 const base::string16& filter,
78 const base::string16& default_extension,
79 const SaveFileCompletion& on_success,
80 const FileSelectionCanceled& on_failure);
82 // Handles the select folder for Metro Chrome Ash. The on_success
83 // callback passed in is invoked when we receive the folder name from the
84 // metro viewer. The on failure callback is invoked on failure.
85 AURA_EXPORT void HandleSelectFolder(const base::string16& title,
86 const SelectFolderCompletion& on_success,
87 const FileSelectionCanceled& on_failure);
89 // Handles the activate desktop command for Metro Chrome Ash. The |ash_exit|
90 // parameter indicates whether the Ash process would be shutdown after
91 // activating the desktop.
92 AURA_EXPORT void HandleActivateDesktop(
93 const base::FilePath& shortcut,
96 // Handles the metro exit command. Notifies the metro viewer to shutdown
98 AURA_EXPORT void HandleMetroExit();
100 // WindowTreeHost implementaton that receives events from a different
101 // process. In the case of Windows this is the Windows 8 (aka Metro)
102 // frontend process, which forwards input events to this class.
103 class AURA_EXPORT RemoteWindowTreeHostWin
104 : public WindowTreeHost,
105 public ui::internal::RemoteInputMethodDelegateWin {
107 // Returns the only RemoteWindowTreeHostWin, if this is the first time
108 // this function is called, it will call Create() wiht empty bounds.
109 static RemoteWindowTreeHostWin* Instance();
110 static RemoteWindowTreeHostWin* Create(const gfx::Rect& bounds);
112 // Sets the handle to the remote window. The |remote_window| is the actual
113 // window owned by the viewer process. Call this before Connected() for some
114 // customers like input method initialization which needs the handle.
115 void SetRemoteWindowHandle(HWND remote_window);
117 // The |host| can be used when we need to send a message to it.
118 void Connected(IPC::Sender* host);
119 // Called when the remote process has closed its IPC connection.
122 // Called when we have a message from the remote process.
123 bool OnMessageReceived(const IPC::Message& message);
125 void HandleOpenURLOnDesktop(const base::FilePath& shortcut,
126 const base::string16& url);
128 // The |ash_exit| parameter indicates whether the Ash process would be
129 // shutdown after activating the desktop.
130 void HandleActivateDesktop(const base::FilePath& shortcut, bool ash_exit);
132 // Notify the metro viewer that it should shut itself down.
133 void HandleMetroExit();
135 void HandleOpenFile(const base::string16& title,
136 const base::FilePath& default_path,
137 const base::string16& filter,
138 const OpenFileCompletion& on_success,
139 const FileSelectionCanceled& on_failure);
141 void HandleOpenMultipleFiles(const base::string16& title,
142 const base::FilePath& default_path,
143 const base::string16& filter,
144 const OpenMultipleFilesCompletion& on_success,
145 const FileSelectionCanceled& on_failure);
147 void HandleSaveFile(const base::string16& title,
148 const base::FilePath& default_path,
149 const base::string16& filter,
151 const base::string16& default_extension,
152 const SaveFileCompletion& on_success,
153 const FileSelectionCanceled& on_failure);
155 void HandleSelectFolder(const base::string16& title,
156 const SelectFolderCompletion& on_success,
157 const FileSelectionCanceled& on_failure);
159 void HandleWindowSizeChanged(uint32 width, uint32 height);
161 // Returns the active ASH root window.
162 Window* GetAshWindow();
164 // Returns true if the remote window is the foreground window according to the
166 bool IsForegroundWindow();
169 explicit RemoteWindowTreeHostWin(const gfx::Rect& bounds);
170 virtual ~RemoteWindowTreeHostWin();
172 // IPC message handing methods:
173 void OnMouseMoved(int32 x, int32 y, int32 flags);
174 void OnMouseButton(const MetroViewerHostMsg_MouseButtonParams& params);
175 void OnKeyDown(uint32 vkey,
179 void OnKeyUp(uint32 vkey,
183 void OnChar(uint32 key_code,
187 void OnWindowActivated();
188 void OnTouchDown(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
189 void OnTouchUp(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
190 void OnTouchMoved(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
191 void OnFileSaveAsDone(bool success,
192 const base::FilePath& filename,
194 void OnFileOpenDone(bool success, const base::FilePath& filename);
195 void OnMultiFileOpenDone(bool success,
196 const std::vector<base::FilePath>& files);
197 void OnSelectFolderDone(bool success, const base::FilePath& folder);
198 void OnSetCursorPosAck();
200 // For Input Method support:
201 ui::RemoteInputMethodPrivateWin* GetRemoteInputMethodPrivate();
202 void OnImeCandidatePopupChanged(bool visible);
203 void OnImeCompositionChanged(
204 const base::string16& text,
205 int32 selection_start,
207 const std::vector<metro_viewer::UnderlineInfo>& underlines);
208 void OnImeTextCommitted(const base::string16& text);
209 void OnImeInputSourceChanged(uint16 language_id, bool is_ime);
211 // WindowTreeHost overrides:
212 virtual RootWindow* GetRootWindow() OVERRIDE;
213 virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
214 virtual void Show() OVERRIDE;
215 virtual void Hide() OVERRIDE;
216 virtual void ToggleFullScreen() OVERRIDE;
217 virtual gfx::Rect GetBounds() const OVERRIDE;
218 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
219 virtual gfx::Insets GetInsets() const OVERRIDE;
220 virtual void SetInsets(const gfx::Insets& insets) OVERRIDE;
221 virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
222 virtual void SetCapture() OVERRIDE;
223 virtual void ReleaseCapture() OVERRIDE;
224 virtual void SetCursor(gfx::NativeCursor cursor) OVERRIDE;
225 virtual bool QueryMouseLocation(gfx::Point* location_return) OVERRIDE;
226 virtual bool ConfineCursorToRootWindow() OVERRIDE;
227 virtual void UnConfineCursor() OVERRIDE;
228 virtual void OnCursorVisibilityChanged(bool show) OVERRIDE;
229 virtual void MoveCursorTo(const gfx::Point& location) OVERRIDE;
230 virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE;
231 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
232 virtual void PrepareForShutdown() OVERRIDE;
234 // ui::internal::RemoteInputMethodDelegateWin overrides:
235 virtual void CancelComposition() OVERRIDE;
236 virtual void OnTextInputClientUpdated(
237 const std::vector<int32>& input_scopes,
238 const std::vector<gfx::Rect>& composition_character_bounds) OVERRIDE;
240 // Helper function to dispatch a keyboard message to the desired target.
241 // The default target is the WindowTreeHostDelegate. For nested message loop
242 // invocations we post a synthetic keyboard message directly into the message
243 // loop. The dispatcher for the nested loop would then decide how this
244 // message is routed.
245 void DispatchKeyboardMessage(ui::EventType type,
252 // Sets the event flags. |flags| is a bitmask of EventFlags. If there is a
253 // change the system virtual key state is updated as well. This way if chrome
254 // queries for key state it matches that of event being dispatched.
255 void SetEventFlags(uint32 flags);
257 uint32 mouse_event_flags() const {
258 return event_flags_ & (ui::EF_LEFT_MOUSE_BUTTON |
259 ui::EF_MIDDLE_MOUSE_BUTTON |
260 ui::EF_RIGHT_MOUSE_BUTTON);
263 uint32 key_event_flags() const {
264 return event_flags_ & (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN |
265 ui::EF_ALT_DOWN | ui::EF_CAPS_LOCK_DOWN);
270 scoped_ptr<ui::ViewProp> prop_;
272 // Saved callbacks which inform the caller about the result of the open file/
273 // save file/select operations.
274 OpenFileCompletion file_open_completion_callback_;
275 OpenMultipleFilesCompletion multi_file_open_completion_callback_;
276 SaveFileCompletion file_saveas_completion_callback_;
277 SelectFolderCompletion select_folder_completion_callback_;
278 FileSelectionCanceled failure_callback_;
280 // Set to true if we need to ignore mouse messages until the SetCursorPos
281 // operation is acked by the viewer.
282 bool ignore_mouse_moves_until_set_cursor_ack_;
284 // Tracking last click event for synthetically generated mouse events.
285 scoped_ptr<ui::MouseEvent> last_mouse_click_event_;
287 // State of the keyboard/mouse at the time of the last input event. See
288 // description of SetEventFlags().
291 // Current size of this root window.
292 gfx::Size window_size_;
294 DISALLOW_COPY_AND_ASSIGN(RemoteWindowTreeHostWin);
299 #endif // UI_AURA_REMOTE_ROOT_WINDOW_HOST_WIN_H_