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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
// 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.
#include "ui/aura/remote_root_window_host_win.h"
#include <windows.h>
#include <algorithm>
#include "base/message_loop.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_sender.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/root_window.h"
#include "ui/base/cursor/cursor_loader_win.h"
#include "ui/base/events/event.h"
#include "ui/base/events/event_utils.h"
#include "ui/base/keycodes/keyboard_code_conversion_win.h"
#include "ui/base/view_prop.h"
#include "ui/metro_viewer/metro_viewer_messages.h"
namespace aura {
namespace {
const char* kRootWindowHostWinKey = "__AURA_REMOTE_ROOT_WINDOW_HOST_WIN__";
// The touch id to be used for touch events coming in from Windows Ash.
const int kRemoteWindowTouchId = 10;
} // namespace
void HandleOpenFile(
const string16& title,
const FilePath& default_path,
const string16& filter,
const OpenFileCompletion& callback) {
DCHECK(aura::RemoteRootWindowHostWin::Instance());
aura::RemoteRootWindowHostWin::Instance()->HandleOpenFile(title,
default_path,
filter,
callback);
}
void HandleOpenMultipleFiles(
const string16& title,
const FilePath& default_path,
const string16& filter,
const OpenMultipleFilesCompletion& callback) {
DCHECK(aura::RemoteRootWindowHostWin::Instance());
aura::RemoteRootWindowHostWin::Instance()->HandleOpenMultipleFiles(
title,
default_path,
filter,
callback);
}
void HandleSaveFile(
const string16& title,
const FilePath& default_path,
const string16& filter,
int filter_index,
const string16& default_extension,
const SaveFileCompletion& callback) {
DCHECK(aura::RemoteRootWindowHostWin::Instance());
aura::RemoteRootWindowHostWin::Instance()->HandleSaveFile(title,
default_path,
filter,
filter_index,
default_extension,
callback);
}
RemoteRootWindowHostWin* g_instance = NULL;
RemoteRootWindowHostWin* RemoteRootWindowHostWin::Instance() {
return g_instance;
}
RemoteRootWindowHostWin* RemoteRootWindowHostWin::Create(
const gfx::Rect& bounds) {
g_instance = new RemoteRootWindowHostWin(bounds);
return g_instance;
}
RemoteRootWindowHostWin::RemoteRootWindowHostWin(const gfx::Rect& bounds)
: delegate_(NULL), host_(NULL) {
prop_.reset(new ui::ViewProp(NULL, kRootWindowHostWinKey, this));
}
RemoteRootWindowHostWin::~RemoteRootWindowHostWin() {
}
void RemoteRootWindowHostWin::Connected(IPC::Sender* host) {
CHECK(host_ == NULL);
host_ = host;
}
void RemoteRootWindowHostWin::Disconnected() {
CHECK(host_ != NULL);
host_ = NULL;
}
bool RemoteRootWindowHostWin::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(RemoteRootWindowHostWin, message)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseMoved, OnMouseMoved)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MouseButton, OnMouseButton)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyDown, OnKeyDown)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_KeyUp, OnKeyUp)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_Character, OnChar)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_VisibilityChanged,
OnVisibilityChanged)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchDown,
OnTouchDown)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchUp,
OnTouchUp)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_TouchMoved,
OnTouchMoved)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileSaveAsDone,
OnFileSaveAsDone)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_FileOpenDone,
OnFileOpenDone)
IPC_MESSAGE_HANDLER(MetroViewerHostMsg_MultiFileOpenDone,
OnMultiFileOpenDone)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void RemoteRootWindowHostWin::HandleOpenFile(
const string16& title,
const FilePath& default_path,
const string16& filter,
const OpenFileCompletion& callback) {
if (!host_)
return;
// Can only one of these operations in flight.
DCHECK(file_open_completion_callback_.is_null());
file_open_completion_callback_ = callback;
host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title,
filter,
default_path.value(),
false));
}
void RemoteRootWindowHostWin::HandleOpenMultipleFiles(
const string16& title,
const FilePath& default_path,
const string16& filter,
const OpenMultipleFilesCompletion& callback) {
if (!host_)
return;
// Can only one of these operations in flight.
DCHECK(multi_file_open_completion_callback_.is_null());
multi_file_open_completion_callback_ = callback;
host_->Send(new MetroViewerHostMsg_DisplayFileOpen(title,
filter,
default_path.value(),
true));
}
void RemoteRootWindowHostWin::HandleSaveFile(
const string16& title,
const FilePath& default_path,
const string16& filter,
int filter_index,
const string16& default_extension,
const SaveFileCompletion& callback) {
if (!host_)
return;
MetroViewerHostMsg_SaveAsDialogParams params;
params.title = title;
params.default_extension = default_extension;
params.filter = filter;
params.filter_index = filter_index;
// Can only one of these operations in flight.
DCHECK(file_saveas_completion_callback_.is_null());
file_saveas_completion_callback_ = callback;
host_->Send(new MetroViewerHostMsg_DisplayFileSaveAs(params));
}
void RemoteRootWindowHostWin::SetDelegate(RootWindowHostDelegate* delegate) {
delegate_ = delegate;
}
RootWindow* RemoteRootWindowHostWin::GetRootWindow() {
return delegate_->AsRootWindow();
}
gfx::AcceleratedWidget RemoteRootWindowHostWin::GetAcceleratedWidget() {
// TODO(cpu): This is bad. Chrome's compositor needs a valid window
// initially and then later on we swap it. Since the compositor never
// uses this initial window we tell ourselves this hack is ok to get
// thing off the ground.
return ::GetDesktopWindow();
}
void RemoteRootWindowHostWin::Show() {
}
void RemoteRootWindowHostWin::Hide() {
NOTIMPLEMENTED();
}
void RemoteRootWindowHostWin::ToggleFullScreen() {
}
gfx::Rect RemoteRootWindowHostWin::GetBounds() const {
gfx::Rect r(gfx::Point(0, 0), aura::RootWindowHost::GetNativeScreenSize());
return r;
}
void RemoteRootWindowHostWin::SetBounds(const gfx::Rect& bounds) {
delegate_->OnHostResized(bounds.size());
}
gfx::Point RemoteRootWindowHostWin::GetLocationOnNativeScreen() const {
return gfx::Point(0, 0);
}
void RemoteRootWindowHostWin::SetCursor(gfx::NativeCursor native_cursor) {
if (!host_)
return;
host_->Send(
new MetroViewerHostMsg_SetCursor(uint64(native_cursor.platform())));
}
void RemoteRootWindowHostWin::SetCapture() {
}
void RemoteRootWindowHostWin::ReleaseCapture() {
}
bool RemoteRootWindowHostWin::QueryMouseLocation(gfx::Point* location_return) {
POINT pt;
GetCursorPos(&pt);
*location_return =
gfx::Point(static_cast<int>(pt.x), static_cast<int>(pt.y));
return true;
}
bool RemoteRootWindowHostWin::ConfineCursorToRootWindow() {
return true;
}
bool RemoteRootWindowHostWin::CopyAreaToSkCanvas(const gfx::Rect& source_bounds,
const gfx::Point& dest_offset,
SkCanvas* canvas) {
NOTIMPLEMENTED();
return false;
}
bool RemoteRootWindowHostWin::GrabSnapshot(
const gfx::Rect& snapshot_bounds,
std::vector<unsigned char>* png_representation) {
NOTIMPLEMENTED();
return false;
}
void RemoteRootWindowHostWin::UnConfineCursor() {
}
void RemoteRootWindowHostWin::OnCursorVisibilityChanged(bool show) {
NOTIMPLEMENTED();
}
void RemoteRootWindowHostWin::MoveCursorTo(const gfx::Point& location) {
}
void RemoteRootWindowHostWin::SetFocusWhenShown(bool focus_when_shown) {
NOTIMPLEMENTED();
}
void RemoteRootWindowHostWin::PostNativeEvent(
const base::NativeEvent& native_event) {
}
void RemoteRootWindowHostWin::OnDeviceScaleFactorChanged(
float device_scale_factor) {
NOTIMPLEMENTED();
}
void RemoteRootWindowHostWin::PrepareForShutdown() {
}
void RemoteRootWindowHostWin::OnMouseMoved(int32 x, int32 y, int32 flags) {
gfx::Point location(x, y);
ui::MouseEvent event(ui::ET_MOUSE_MOVED, location, location, flags);
delegate_->OnHostMouseEvent(&event);
}
void RemoteRootWindowHostWin::OnMouseButton(
int32 x, int32 y, int32 extra, ui::EventType type, ui::EventFlags flags) {
gfx::Point location(x, y);
ui::MouseEvent mouse_event(type, location, location, 0);
mouse_event.set_flags(flags);
if (type == ui::ET_MOUSEWHEEL) {
ui::MouseWheelEvent wheel_event(mouse_event, extra);
delegate_->OnHostMouseEvent(&wheel_event);
} else {
mouse_event.SetClickCount(1);
delegate_->OnHostMouseEvent(&mouse_event);
}
}
void RemoteRootWindowHostWin::OnKeyDown(uint32 vkey,
uint32 repeat_count,
uint32 scan_code,
uint32 flags) {
ui::KeyEvent event(ui::ET_KEY_PRESSED,
ui::KeyboardCodeForWindowsKeyCode(vkey),
flags,
false);
delegate_->OnHostKeyEvent(&event);
}
void RemoteRootWindowHostWin::OnKeyUp(uint32 vkey,
uint32 repeat_count,
uint32 scan_code,
uint32 flags) {
ui::KeyEvent event(ui::ET_KEY_RELEASED,
ui::KeyboardCodeForWindowsKeyCode(vkey),
flags,
false);
delegate_->OnHostKeyEvent(&event);
}
void RemoteRootWindowHostWin::OnChar(uint32 key_code,
uint32 repeat_count,
uint32 scan_code,
uint32 flags) {
ui::KeyEvent event(ui::ET_KEY_PRESSED,
ui::KeyboardCodeForWindowsKeyCode(key_code),
flags,
true);
delegate_->OnHostKeyEvent(&event);
}
void RemoteRootWindowHostWin::OnVisibilityChanged(bool visible) {
if (visible)
delegate_->OnHostActivated();
}
void RemoteRootWindowHostWin::OnTouchDown(int32 x, int32 y, uint64 timestamp) {
ui::TouchEvent event(ui::ET_TOUCH_PRESSED,
gfx::Point(x, y),
kRemoteWindowTouchId,
base::TimeDelta::FromMicroseconds(timestamp));
delegate_->OnHostTouchEvent(&event);
}
void RemoteRootWindowHostWin::OnTouchUp(int32 x, int32 y, uint64 timestamp) {
ui::TouchEvent event(ui::ET_TOUCH_RELEASED,
gfx::Point(x, y),
kRemoteWindowTouchId,
base::TimeDelta::FromMicroseconds(timestamp));
delegate_->OnHostTouchEvent(&event);
}
void RemoteRootWindowHostWin::OnTouchMoved(int32 x,
int32 y,
uint64 timestamp) {
ui::TouchEvent event(ui::ET_TOUCH_MOVED,
gfx::Point(x, y),
kRemoteWindowTouchId,
base::TimeDelta::FromMicroseconds(timestamp));
delegate_->OnHostTouchEvent(&event);
}
void RemoteRootWindowHostWin::OnFileSaveAsDone(bool success,
string16 filename,
int filter_index) {
if (success) {
file_saveas_completion_callback_.Run(
FilePath(filename), filter_index, NULL);
}
file_saveas_completion_callback_.Reset();
}
void RemoteRootWindowHostWin::OnFileOpenDone(bool success, string16 filename) {
if (success) {
file_open_completion_callback_.Run(
FilePath(filename), 0, NULL);
}
file_open_completion_callback_.Reset();
}
void RemoteRootWindowHostWin::OnMultiFileOpenDone(
bool success,
const std::vector<FilePath>& files) {
if (success) {
multi_file_open_completion_callback_.Run(files, NULL);
}
multi_file_open_completion_callback_.Reset();
}
} // namespace aura
|