1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_AURA_REMOTE_WINDOW_TREE_HOST_WIN_H_
#define UI_AURA_REMOTE_WINDOW_TREE_HOST_WIN_H_
#include <vector>
#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/strings/string16.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ime/remote_input_method_delegate_win.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/events/event_source.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/metro_viewer/ime_types.h"
struct MetroViewerHostMsg_MouseButtonParams;
namespace base {
class FilePath;
}
namespace ui {
class RemoteInputMethodPrivateWin;
class ViewProp;
}
namespace IPC {
class Message;
class Sender;
}
namespace aura {
typedef base::Callback<void(const base::FilePath&, int, void*)>
OpenFileCompletion;
typedef base::Callback<void(const std::vector<base::FilePath>&, void*)>
OpenMultipleFilesCompletion;
typedef base::Callback<void(const base::FilePath&, int, void*)>
SaveFileCompletion;
typedef base::Callback<void(const base::FilePath&, int, void*)>
SelectFolderCompletion;
typedef base::Callback<void(void*)> FileSelectionCanceled;
// Handles the open file operation for Metro Chrome Ash. The on_success
// callback passed in is invoked when we receive the opened file name from
// the metro viewer. The on failure callback is invoked on failure.
AURA_EXPORT void HandleOpenFile(const base::string16& title,
const base::FilePath& default_path,
const base::string16& filter,
const OpenFileCompletion& on_success,
const FileSelectionCanceled& on_failure);
// Handles the open multiple file operation for Metro Chrome Ash. The
// on_success callback passed in is invoked when we receive the opened file
// names from the metro viewer. The on failure callback is invoked on failure.
AURA_EXPORT void HandleOpenMultipleFiles(
const base::string16& title,
const base::FilePath& default_path,
const base::string16& filter,
const OpenMultipleFilesCompletion& on_success,
const FileSelectionCanceled& on_failure);
// Handles the save file operation for Metro Chrome Ash. The on_success
// callback passed in is invoked when we receive the saved file name from
// the metro viewer. The on failure callback is invoked on failure.
AURA_EXPORT void HandleSaveFile(const base::string16& title,
const base::FilePath& default_path,
const base::string16& filter,
int filter_index,
const base::string16& default_extension,
const SaveFileCompletion& on_success,
const FileSelectionCanceled& on_failure);
// Handles the select folder for Metro Chrome Ash. The on_success
// callback passed in is invoked when we receive the folder name from the
// metro viewer. The on failure callback is invoked on failure.
AURA_EXPORT void HandleSelectFolder(const base::string16& title,
const SelectFolderCompletion& on_success,
const FileSelectionCanceled& on_failure);
// Handles the activate desktop command for Metro Chrome Ash. The |ash_exit|
// parameter indicates whether the Ash process would be shutdown after
// activating the desktop.
AURA_EXPORT void HandleActivateDesktop(
const base::FilePath& shortcut,
bool ash_exit);
// Handles the metro exit command. Notifies the metro viewer to shutdown
// gracefully.
AURA_EXPORT void HandleMetroExit();
// WindowTreeHost implementaton that receives events from a different
// process. In the case of Windows this is the Windows 8 (aka Metro)
// frontend process, which forwards input events to this class.
class AURA_EXPORT RemoteWindowTreeHostWin
: public WindowTreeHost,
public ui::EventSource,
public ui::internal::RemoteInputMethodDelegateWin {
public:
// Returns the only RemoteWindowTreeHostWin, if this is the first time
// this function is called and the instance have never set by SetInstance,
// it will call Create() wiht empty bounds.
static RemoteWindowTreeHostWin* Instance();
// Manually sets the instance to be used as a return value of |Instance()|
// method above. This should not be called if the instance has already
// been set or created, and doing so will result in CHECK failure.
static void SetInstance(RemoteWindowTreeHostWin* instance);
// Returns true if there is a RemoteWindowTreeHostWin and it has a valid
// HWND. A return value of false typically indicates we're not in metro mode.
static bool IsValid();
// Sets the handle to the remote window. The |remote_window| is the actual
// window owned by the viewer process. Call this before Connected() for some
// customers like input method initialization which needs the handle.
void SetRemoteWindowHandle(HWND remote_window);
// The |host| can be used when we need to send a message to it.
void Connected(IPC::Sender* host);
// Called when the remote process has closed its IPC connection.
void Disconnected();
// Called when we have a message from the remote process.
bool OnMessageReceived(const IPC::Message& message);
void HandleOpenURLOnDesktop(const base::FilePath& shortcut,
const base::string16& url);
// The |ash_exit| parameter indicates whether the Ash process would be
// shutdown after activating the desktop.
void HandleActivateDesktop(const base::FilePath& shortcut, bool ash_exit);
// Notify the metro viewer that it should shut itself down.
void HandleMetroExit();
void HandleOpenFile(const base::string16& title,
const base::FilePath& default_path,
const base::string16& filter,
const OpenFileCompletion& on_success,
const FileSelectionCanceled& on_failure);
void HandleOpenMultipleFiles(const base::string16& title,
const base::FilePath& default_path,
const base::string16& filter,
const OpenMultipleFilesCompletion& on_success,
const FileSelectionCanceled& on_failure);
void HandleSaveFile(const base::string16& title,
const base::FilePath& default_path,
const base::string16& filter,
int filter_index,
const base::string16& default_extension,
const SaveFileCompletion& on_success,
const FileSelectionCanceled& on_failure);
void HandleSelectFolder(const base::string16& title,
const SelectFolderCompletion& on_success,
const FileSelectionCanceled& on_failure);
void HandleWindowSizeChanged(uint32 width, uint32 height);
// Returns the active ASH root window.
Window* GetAshWindow();
// Returns true if the remote window is the foreground window according to the
// OS.
bool IsForegroundWindow();
protected:
explicit RemoteWindowTreeHostWin(const gfx::Rect& bounds);
virtual ~RemoteWindowTreeHostWin();
private:
// IPC message handing methods:
void OnMouseMoved(int32 x, int32 y, int32 flags);
void OnMouseButton(const MetroViewerHostMsg_MouseButtonParams& params);
void OnKeyDown(uint32 vkey,
uint32 repeat_count,
uint32 scan_code,
uint32 flags);
void OnKeyUp(uint32 vkey,
uint32 repeat_count,
uint32 scan_code,
uint32 flags);
void OnChar(uint32 key_code,
uint32 repeat_count,
uint32 scan_code,
uint32 flags);
void OnWindowActivated();
void OnEdgeGesture();
void OnTouchDown(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
void OnTouchUp(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
void OnTouchMoved(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
void OnFileSaveAsDone(bool success,
const base::FilePath& filename,
int filter_index);
void OnFileOpenDone(bool success, const base::FilePath& filename);
void OnMultiFileOpenDone(bool success,
const std::vector<base::FilePath>& files);
void OnSelectFolderDone(bool success, const base::FilePath& folder);
void OnSetCursorPosAck();
// For Input Method support:
ui::RemoteInputMethodPrivateWin* GetRemoteInputMethodPrivate();
void OnImeCandidatePopupChanged(bool visible);
void OnImeCompositionChanged(
const base::string16& text,
int32 selection_start,
int32 selection_end,
const std::vector<metro_viewer::UnderlineInfo>& underlines);
void OnImeTextCommitted(const base::string16& text);
void OnImeInputSourceChanged(uint16 language_id, bool is_ime);
// WindowTreeHost overrides:
virtual ui::EventSource* GetEventSource() OVERRIDE;
virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
virtual void Show() OVERRIDE;
virtual void Hide() OVERRIDE;
virtual gfx::Rect GetBounds() const OVERRIDE;
virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
virtual gfx::Point GetLocationOnNativeScreen() const OVERRIDE;
virtual void SetCapture() OVERRIDE;
virtual void ReleaseCapture() OVERRIDE;
virtual void PostNativeEvent(const base::NativeEvent& native_event) OVERRIDE;
virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE;
virtual void SetCursorNative(gfx::NativeCursor cursor) OVERRIDE;
virtual void MoveCursorToNative(const gfx::Point& location) OVERRIDE;
virtual void OnCursorVisibilityChangedNative(bool show) OVERRIDE;
// ui::EventSource:
virtual ui::EventProcessor* GetEventProcessor() OVERRIDE;
// ui::internal::RemoteInputMethodDelegateWin overrides:
virtual void CancelComposition() OVERRIDE;
virtual void OnTextInputClientUpdated(
const std::vector<int32>& input_scopes,
const std::vector<gfx::Rect>& composition_character_bounds) OVERRIDE;
// Helper function to dispatch a keyboard message to the desired target.
// The default target is the WindowEventDispatcher. For nested message loop
// invocations we post a synthetic keyboard message directly into the message
// loop. The dispatcher for the nested loop would then decide how this
// message is routed.
void DispatchKeyboardMessage(ui::EventType type,
uint32 vkey,
uint32 repeat_count,
uint32 scan_code,
uint32 flags,
bool is_character);
// Sets the event flags. |flags| is a bitmask of EventFlags. If there is a
// change the system virtual key state is updated as well. This way if chrome
// queries for key state it matches that of event being dispatched.
void SetEventFlags(uint32 flags);
uint32 mouse_event_flags() const {
return event_flags_ & (ui::EF_LEFT_MOUSE_BUTTON |
ui::EF_MIDDLE_MOUSE_BUTTON |
ui::EF_RIGHT_MOUSE_BUTTON);
}
uint32 key_event_flags() const {
return event_flags_ & (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN |
ui::EF_ALT_DOWN | ui::EF_CAPS_LOCK_DOWN);
}
HWND remote_window_;
IPC::Sender* host_;
scoped_ptr<ui::ViewProp> prop_;
// Saved callbacks which inform the caller about the result of the open file/
// save file/select operations.
OpenFileCompletion file_open_completion_callback_;
OpenMultipleFilesCompletion multi_file_open_completion_callback_;
SaveFileCompletion file_saveas_completion_callback_;
SelectFolderCompletion select_folder_completion_callback_;
FileSelectionCanceled failure_callback_;
// Set to true if we need to ignore mouse messages until the SetCursorPos
// operation is acked by the viewer.
bool ignore_mouse_moves_until_set_cursor_ack_;
// Tracking last click event for synthetically generated mouse events.
scoped_ptr<ui::MouseEvent> last_mouse_click_event_;
// State of the keyboard/mouse at the time of the last input event. See
// description of SetEventFlags().
uint32 event_flags_;
// Current size of this root window.
gfx::Size window_size_;
DISALLOW_COPY_AND_ASSIGN(RemoteWindowTreeHostWin);
};
} // namespace aura
#endif // UI_AURA_REMOTE_WINDOW_TREE_HOST_WIN_H_
|