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/string16.h"
13 #include "ui/aura/root_window_host.h"
14 #include "ui/base/events/event_constants.h"
15 #include "ui/gfx/native_widget_types.h"
32 typedef base::Callback
<void(const base::FilePath
&, int, void*)>
35 typedef base::Callback
<void(const std::vector
<base::FilePath
>&, void*)>
36 OpenMultipleFilesCompletion
;
38 typedef base::Callback
<void(const base::FilePath
&, int, void*)>
41 // Handles the open file operation for Metro Chrome Ash. The callback passed in
42 // is invoked when we receive the opened file name from the metro viewer.
43 AURA_EXPORT
void HandleOpenFile(
44 const string16
& title
,
45 const base::FilePath
& default_path
,
46 const string16
& filter
,
47 const OpenFileCompletion
& callback
);
49 // Handles the open multiple file operation for Metro Chrome Ash. The callback
50 // passed in is invoked when we receive the opened file names from the metro
52 AURA_EXPORT
void HandleOpenMultipleFiles(
53 const string16
& title
,
54 const base::FilePath
& default_path
,
55 const string16
& filter
,
56 const OpenMultipleFilesCompletion
& callback
);
58 // Handles the save file operation for Metro Chrome Ash. The callback passed in
59 // is invoked when we receive the saved file name from the metro viewer.
60 AURA_EXPORT
void HandleSaveFile(
61 const string16
& title
,
62 const base::FilePath
& default_path
,
63 const string16
& filter
,
65 const string16
& default_extension
,
66 const SaveFileCompletion
& callback
);
69 // RootWindowHost implementaton that receives events from a different
70 // process. In the case of Windows this is the Windows 8 (aka Metro)
71 // frontend process, which forwards input events to this class.
72 class AURA_EXPORT RemoteRootWindowHostWin
: public RootWindowHost
{
74 static RemoteRootWindowHostWin
* Instance();
75 static RemoteRootWindowHostWin
* Create(const gfx::Rect
& bounds
);
77 // Called when the remote process has established its IPC connection.
78 // The |host| can be used when we need to send a message to it.
79 void Connected(IPC::Sender
* host
);
80 // Called when the remote process has closed its IPC connection.
83 // Called when we have a message from the remote process.
84 bool OnMessageReceived(const IPC::Message
& message
);
87 const string16
& title
,
88 const base::FilePath
& default_path
,
89 const string16
& filter
,
90 const OpenFileCompletion
& callback
);
92 void HandleOpenMultipleFiles(
93 const string16
& title
,
94 const base::FilePath
& default_path
,
95 const string16
& filter
,
96 const OpenMultipleFilesCompletion
& callback
);
99 const string16
& title
,
100 const base::FilePath
& default_path
,
101 const string16
& filter
,
103 const string16
& default_extension
,
104 const SaveFileCompletion
& callback
);
107 explicit RemoteRootWindowHostWin(const gfx::Rect
& bounds
);
108 virtual ~RemoteRootWindowHostWin();
110 // IPC message handing methods:
111 void OnMouseMoved(int32 x
, int32 y
, int32 flags
);
112 void OnMouseButton(int32 x
,
116 ui::EventFlags flags
);
117 void OnKeyDown(uint32 vkey
,
121 void OnKeyUp(uint32 vkey
,
125 void OnChar(uint32 key_code
,
129 void OnVisibilityChanged(bool visible
);
130 void OnTouchDown(int32 x
, int32 y
, uint64 timestamp
, uint32 pointer_id
);
131 void OnTouchUp(int32 x
, int32 y
, uint64 timestamp
, uint32 pointer_id
);
132 void OnTouchMoved(int32 x
, int32 y
, uint64 timestamp
, uint32 pointer_id
);
133 void OnFileSaveAsDone(bool success
,
136 void OnFileOpenDone(bool success
, string16 filename
);
137 void OnMultiFileOpenDone(bool success
,
138 const std::vector
<base::FilePath
>& files
);
140 // RootWindowHost overrides:
141 virtual void SetDelegate(RootWindowHostDelegate
* delegate
) OVERRIDE
;
142 virtual RootWindow
* GetRootWindow() OVERRIDE
;
143 virtual gfx::AcceleratedWidget
GetAcceleratedWidget() OVERRIDE
;
144 virtual void Show() OVERRIDE
;
145 virtual void Hide() OVERRIDE
;
146 virtual void ToggleFullScreen() OVERRIDE
;
147 virtual gfx::Rect
GetBounds() const OVERRIDE
;
148 virtual void SetBounds(const gfx::Rect
& bounds
) OVERRIDE
;
149 virtual gfx::Insets
GetInsets() const OVERRIDE
;
150 virtual void SetInsets(const gfx::Insets
& insets
) OVERRIDE
;
151 virtual gfx::Point
GetLocationOnNativeScreen() const OVERRIDE
;
152 virtual void SetCapture() OVERRIDE
;
153 virtual void ReleaseCapture() OVERRIDE
;
154 virtual void SetCursor(gfx::NativeCursor cursor
) OVERRIDE
;
155 virtual bool QueryMouseLocation(gfx::Point
* location_return
) OVERRIDE
;
156 virtual bool ConfineCursorToRootWindow() OVERRIDE
;
157 virtual void UnConfineCursor() OVERRIDE
;
158 virtual void OnCursorVisibilityChanged(bool show
) OVERRIDE
;
159 virtual void MoveCursorTo(const gfx::Point
& location
) OVERRIDE
;
160 virtual void SetFocusWhenShown(bool focus_when_shown
) OVERRIDE
;
161 virtual bool CopyAreaToSkCanvas(const gfx::Rect
& source_bounds
,
162 const gfx::Point
& dest_offset
,
163 SkCanvas
* canvas
) OVERRIDE
;
164 virtual bool GrabSnapshot(
165 const gfx::Rect
& snapshot_bounds
,
166 std::vector
<unsigned char>* png_representation
) OVERRIDE
;
167 virtual void PostNativeEvent(const base::NativeEvent
& native_event
) OVERRIDE
;
168 virtual void OnDeviceScaleFactorChanged(float device_scale_factor
) OVERRIDE
;
169 virtual void PrepareForShutdown() OVERRIDE
;
171 // Helper function to dispatch a keyboard message to the desired target.
172 // The default target is the RootWindowHostDelegate. For nested message loop
173 // invocations we post a synthetic keyboard message directly into the message
174 // loop. The dispatcher for the nested loop would then decide how this
175 // message is routed.
176 void DispatchKeyboardMessage(ui::EventType type
,
183 RootWindowHostDelegate
* delegate_
;
185 scoped_ptr
<ui::ViewProp
> prop_
;
187 // Saved callbacks which inform the caller about the result of the open file/
188 // save file operations.
189 OpenFileCompletion file_open_completion_callback_
;
190 OpenMultipleFilesCompletion multi_file_open_completion_callback_
;
191 SaveFileCompletion file_saveas_completion_callback_
;
193 DISALLOW_COPY_AND_ASSIGN(RemoteRootWindowHostWin
);
198 #endif // UI_AURA_REMOTE_ROOT_WINDOW_HOST_WIN_H_