Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / ui / aura / remote_root_window_host_win.h
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.
4
5 #ifndef UI_AURA_REMOTE_ROOT_WINDOW_HOST_WIN_H_
6 #define UI_AURA_REMOTE_ROOT_WINDOW_HOST_WIN_H_
7
8 #include <vector>
9
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"
19
20 struct MetroViewerHostMsg_MouseButtonParams;
21
22 namespace base {
23 class FilePath;
24 }
25
26 namespace ui {
27 class RemoteInputMethodPrivateWin;
28 class ViewProp;
29 }
30
31 namespace IPC {
32 class Message;
33 class Sender;
34 }
35
36 namespace aura {
37
38 typedef base::Callback<void(const base::FilePath&, int, void*)>
39     OpenFileCompletion;
40
41 typedef base::Callback<void(const std::vector<base::FilePath>&, void*)>
42     OpenMultipleFilesCompletion;
43
44 typedef base::Callback<void(const base::FilePath&, int, void*)>
45     SaveFileCompletion;
46
47 typedef base::Callback<void(const base::FilePath&, int, void*)>
48     SelectFolderCompletion;
49
50 typedef base::Callback<void(void*)> FileSelectionCanceled;
51
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);
60
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);
70
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,
77                                 int filter_index,
78                                 const base::string16& default_extension,
79                                 const SaveFileCompletion& on_success,
80                                 const FileSelectionCanceled& on_failure);
81
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);
88
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,
94     bool ash_exit);
95
96 // Handles the metro exit command.  Notifies the metro viewer to shutdown
97 // gracefully.
98 AURA_EXPORT void HandleMetroExit();
99
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 {
106  public:
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);
111
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);
116
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.
120   void Disconnected();
121
122   // Called when we have a message from the remote process.
123   bool OnMessageReceived(const IPC::Message& message);
124
125   void HandleOpenURLOnDesktop(const base::FilePath& shortcut,
126                               const base::string16& url);
127
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);
131
132   // Notify the metro viewer that it should shut itself down.
133   void HandleMetroExit();
134
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);
140
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);
146
147   void HandleSaveFile(const base::string16& title,
148                       const base::FilePath& default_path,
149                       const base::string16& filter,
150                       int filter_index,
151                       const base::string16& default_extension,
152                       const SaveFileCompletion& on_success,
153                       const FileSelectionCanceled& on_failure);
154
155   void HandleSelectFolder(const base::string16& title,
156                           const SelectFolderCompletion& on_success,
157                           const FileSelectionCanceled& on_failure);
158
159   void HandleWindowSizeChanged(uint32 width, uint32 height);
160
161   // Returns the active ASH root window.
162   Window* GetAshWindow();
163
164   // Returns true if the remote window is the foreground window according to the
165   // OS.
166   bool IsForegroundWindow();
167
168  private:
169   explicit RemoteWindowTreeHostWin(const gfx::Rect& bounds);
170   virtual ~RemoteWindowTreeHostWin();
171
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,
176                  uint32 repeat_count,
177                  uint32 scan_code,
178                  uint32 flags);
179   void OnKeyUp(uint32 vkey,
180                uint32 repeat_count,
181                uint32 scan_code,
182                uint32 flags);
183   void OnChar(uint32 key_code,
184               uint32 repeat_count,
185               uint32 scan_code,
186               uint32 flags);
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,
193                         int filter_index);
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();
199
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,
206       int32 selection_end,
207       const std::vector<metro_viewer::UnderlineInfo>& underlines);
208   void OnImeTextCommitted(const base::string16& text);
209   void OnImeInputSourceChanged(uint16 language_id, bool is_ime);
210
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;
233
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;
239
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,
246                                uint32 vkey,
247                                uint32 repeat_count,
248                                uint32 scan_code,
249                                uint32 flags,
250                                bool is_character);
251
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);
256
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);
261   }
262
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);
266   }
267
268   HWND remote_window_;
269   IPC::Sender* host_;
270   scoped_ptr<ui::ViewProp> prop_;
271
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_;
279
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_;
283
284   // Tracking last click event for synthetically generated mouse events.
285   scoped_ptr<ui::MouseEvent> last_mouse_click_event_;
286
287   // State of the keyboard/mouse at the time of the last input event. See
288   // description of SetEventFlags().
289   uint32 event_flags_;
290
291   // Current size of this root window.
292   gfx::Size window_size_;
293
294   DISALLOW_COPY_AND_ASSIGN(RemoteWindowTreeHostWin);
295 };
296
297 }  // namespace aura
298
299 #endif  // UI_AURA_REMOTE_ROOT_WINDOW_HOST_WIN_H_