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 on_success
90 // callback passed in is invoked when activation is completed.
91 // The |ash_exit| parameter indicates whether the Ash process would be shutdown
92 // after activating the desktop.
93 AURA_EXPORT
void HandleActivateDesktop(
94 const base::FilePath
& shortcut
,
97 // WindowTreeHost implementaton that receives events from a different
98 // process. In the case of Windows this is the Windows 8 (aka Metro)
99 // frontend process, which forwards input events to this class.
100 class AURA_EXPORT RemoteWindowTreeHostWin
101 : public WindowTreeHost
,
102 public ui::internal::RemoteInputMethodDelegateWin
{
104 // Returns the only RemoteWindowTreeHostWin, if this is the first time
105 // this function is called, it will call Create() wiht empty bounds.
106 static RemoteWindowTreeHostWin
* Instance();
107 static RemoteWindowTreeHostWin
* Create(const gfx::Rect
& bounds
);
109 // Called when the remote process has established its IPC connection.
110 // The |host| can be used when we need to send a message to it and
111 // |remote_window| is the actual window owned by the viewer process.
112 void Connected(IPC::Sender
* host
, HWND remote_window
);
113 // Called when the remote process has closed its IPC connection.
116 // Called when we have a message from the remote process.
117 bool OnMessageReceived(const IPC::Message
& message
);
119 void HandleOpenURLOnDesktop(const base::FilePath
& shortcut
,
120 const base::string16
& url
);
122 // The |ash_exit| parameter indicates whether the Ash process would be
123 // shutdown after activating the desktop.
124 void HandleActivateDesktop(
125 const base::FilePath
& shortcut
,
128 void HandleOpenFile(const base::string16
& title
,
129 const base::FilePath
& default_path
,
130 const base::string16
& filter
,
131 const OpenFileCompletion
& on_success
,
132 const FileSelectionCanceled
& on_failure
);
134 void HandleOpenMultipleFiles(const base::string16
& title
,
135 const base::FilePath
& default_path
,
136 const base::string16
& filter
,
137 const OpenMultipleFilesCompletion
& on_success
,
138 const FileSelectionCanceled
& on_failure
);
140 void HandleSaveFile(const base::string16
& title
,
141 const base::FilePath
& default_path
,
142 const base::string16
& filter
,
144 const base::string16
& default_extension
,
145 const SaveFileCompletion
& on_success
,
146 const FileSelectionCanceled
& on_failure
);
148 void HandleSelectFolder(const base::string16
& title
,
149 const SelectFolderCompletion
& on_success
,
150 const FileSelectionCanceled
& on_failure
);
152 void HandleWindowSizeChanged(uint32 width
, uint32 height
);
154 // Returns the active ASH root window.
155 Window
* GetAshWindow();
157 // Returns true if the remote window is the foreground window according to the
159 bool IsForegroundWindow();
162 explicit RemoteWindowTreeHostWin(const gfx::Rect
& bounds
);
163 virtual ~RemoteWindowTreeHostWin();
165 // IPC message handing methods:
166 void OnMouseMoved(int32 x
, int32 y
, int32 flags
);
167 void OnMouseButton(const MetroViewerHostMsg_MouseButtonParams
& params
);
168 void OnKeyDown(uint32 vkey
,
172 void OnKeyUp(uint32 vkey
,
176 void OnChar(uint32 key_code
,
180 void OnWindowActivated();
181 void OnTouchDown(int32 x
, int32 y
, uint64 timestamp
, uint32 pointer_id
);
182 void OnTouchUp(int32 x
, int32 y
, uint64 timestamp
, uint32 pointer_id
);
183 void OnTouchMoved(int32 x
, int32 y
, uint64 timestamp
, uint32 pointer_id
);
184 void OnFileSaveAsDone(bool success
,
185 const base::FilePath
& filename
,
187 void OnFileOpenDone(bool success
, const base::FilePath
& filename
);
188 void OnMultiFileOpenDone(bool success
,
189 const std::vector
<base::FilePath
>& files
);
190 void OnSelectFolderDone(bool success
, const base::FilePath
& folder
);
191 void OnSetCursorPosAck();
193 // For Input Method support:
194 ui::RemoteInputMethodPrivateWin
* GetRemoteInputMethodPrivate();
195 void OnImeCandidatePopupChanged(bool visible
);
196 void OnImeCompositionChanged(
197 const base::string16
& text
,
198 int32 selection_start
,
200 const std::vector
<metro_viewer::UnderlineInfo
>& underlines
);
201 void OnImeTextCommitted(const base::string16
& text
);
202 void OnImeInputSourceChanged(uint16 language_id
, bool is_ime
);
204 // WindowTreeHost overrides:
205 virtual RootWindow
* GetRootWindow() OVERRIDE
;
206 virtual gfx::AcceleratedWidget
GetAcceleratedWidget() OVERRIDE
;
207 virtual void Show() OVERRIDE
;
208 virtual void Hide() OVERRIDE
;
209 virtual void ToggleFullScreen() OVERRIDE
;
210 virtual gfx::Rect
GetBounds() const OVERRIDE
;
211 virtual void SetBounds(const gfx::Rect
& bounds
) OVERRIDE
;
212 virtual gfx::Insets
GetInsets() const OVERRIDE
;
213 virtual void SetInsets(const gfx::Insets
& insets
) OVERRIDE
;
214 virtual gfx::Point
GetLocationOnNativeScreen() const OVERRIDE
;
215 virtual void SetCapture() OVERRIDE
;
216 virtual void ReleaseCapture() OVERRIDE
;
217 virtual void SetCursor(gfx::NativeCursor cursor
) OVERRIDE
;
218 virtual bool QueryMouseLocation(gfx::Point
* location_return
) OVERRIDE
;
219 virtual bool ConfineCursorToRootWindow() OVERRIDE
;
220 virtual void UnConfineCursor() OVERRIDE
;
221 virtual void OnCursorVisibilityChanged(bool show
) OVERRIDE
;
222 virtual void MoveCursorTo(const gfx::Point
& location
) OVERRIDE
;
223 virtual void PostNativeEvent(const base::NativeEvent
& native_event
) OVERRIDE
;
224 virtual void OnDeviceScaleFactorChanged(float device_scale_factor
) OVERRIDE
;
225 virtual void PrepareForShutdown() OVERRIDE
;
227 // ui::internal::RemoteInputMethodDelegateWin overrides:
228 virtual void CancelComposition() OVERRIDE
;
229 virtual void OnTextInputClientUpdated(
230 const std::vector
<int32
>& input_scopes
,
231 const std::vector
<gfx::Rect
>& composition_character_bounds
) OVERRIDE
;
233 // Helper function to dispatch a keyboard message to the desired target.
234 // The default target is the WindowTreeHostDelegate. For nested message loop
235 // invocations we post a synthetic keyboard message directly into the message
236 // loop. The dispatcher for the nested loop would then decide how this
237 // message is routed.
238 void DispatchKeyboardMessage(ui::EventType type
,
245 // Sets the event flags. |flags| is a bitmask of EventFlags. If there is a
246 // change the system virtual key state is updated as well. This way if chrome
247 // queries for key state it matches that of event being dispatched.
248 void SetEventFlags(uint32 flags
);
250 uint32
mouse_event_flags() const {
251 return event_flags_
& (ui::EF_LEFT_MOUSE_BUTTON
|
252 ui::EF_MIDDLE_MOUSE_BUTTON
|
253 ui::EF_RIGHT_MOUSE_BUTTON
);
256 uint32
key_event_flags() const {
257 return event_flags_
& (ui::EF_SHIFT_DOWN
| ui::EF_CONTROL_DOWN
|
258 ui::EF_ALT_DOWN
| ui::EF_CAPS_LOCK_DOWN
);
263 scoped_ptr
<ui::ViewProp
> prop_
;
265 // Saved callbacks which inform the caller about the result of the open file/
266 // save file/select operations.
267 OpenFileCompletion file_open_completion_callback_
;
268 OpenMultipleFilesCompletion multi_file_open_completion_callback_
;
269 SaveFileCompletion file_saveas_completion_callback_
;
270 SelectFolderCompletion select_folder_completion_callback_
;
271 FileSelectionCanceled failure_callback_
;
273 // Set to true if we need to ignore mouse messages until the SetCursorPos
274 // operation is acked by the viewer.
275 bool ignore_mouse_moves_until_set_cursor_ack_
;
277 // Tracking last click event for synthetically generated mouse events.
278 scoped_ptr
<ui::MouseEvent
> last_mouse_click_event_
;
280 // State of the keyboard/mouse at the time of the last input event. See
281 // description of SetEventFlags().
284 // Current size of this root window.
285 gfx::Size window_size_
;
287 DISALLOW_COPY_AND_ASSIGN(RemoteWindowTreeHostWin
);
292 #endif // UI_AURA_REMOTE_ROOT_WINDOW_HOST_WIN_H_