Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / aura / remote_window_tree_host_win.h
blob4cde32c9cf7ad5f5c0015923e34ef48300394b93
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_WINDOW_TREE_HOST_WIN_H_
6 #define UI_AURA_REMOTE_WINDOW_TREE_HOST_WIN_H_
8 #include <vector>
10 #include "base/compiler_specific.h"
11 #include "base/strings/string16.h"
12 #include "ui/aura/window_tree_host.h"
13 #include "ui/base/ime/remote_input_method_delegate_win.h"
14 #include "ui/events/event.h"
15 #include "ui/events/event_constants.h"
16 #include "ui/events/event_source.h"
17 #include "ui/gfx/native_widget_types.h"
18 #include "ui/metro_viewer/ime_types.h"
20 struct MetroViewerHostMsg_MouseButtonParams;
22 namespace base {
23 class FilePath;
26 namespace ui {
27 class RemoteInputMethodPrivateWin;
28 class ViewProp;
31 namespace IPC {
32 class Message;
33 class Sender;
36 namespace aura {
38 // WindowTreeHost implementaton that receives events from a different
39 // process. In the case of Windows this is the Windows 8 (aka Metro)
40 // frontend process, which forwards input events to this class.
41 class AURA_EXPORT RemoteWindowTreeHostWin
42 : public WindowTreeHost,
43 public ui::EventSource,
44 public ui::internal::RemoteInputMethodDelegateWin {
45 public:
46 // Returns the current RemoteWindowTreeHostWin. This does *not* create a
47 // RemoteWindowTreeHostWin.
48 static RemoteWindowTreeHostWin* Instance();
50 // Returns true if there is a RemoteWindowTreeHostWin and it has a valid
51 // HWND. A return value of false typically indicates we're not in metro mode.
52 static bool IsValid();
54 // Sets the handle to the remote window. The |remote_window| is the actual
55 // window owned by the viewer process. Call this before Connected() for some
56 // customers like input method initialization which needs the handle.
57 void SetRemoteWindowHandle(HWND remote_window);
58 HWND remote_window() { return remote_window_; }
60 // The |host| can be used when we need to send a message to it.
61 void Connected(IPC::Sender* host);
62 // Called when the remote process has closed its IPC connection.
63 void Disconnected();
65 // Called when we have a message from the remote process.
66 bool OnMessageReceived(const IPC::Message& message);
68 void HandleOpenURLOnDesktop(const base::FilePath& shortcut,
69 const base::string16& url);
71 void HandleWindowSizeChanged(uint32 width, uint32 height);
73 // Returns the active ASH root window.
74 Window* GetAshWindow();
76 // Returns true if the remote window is the foreground window according to the
77 // OS.
78 bool IsForegroundWindow();
80 protected:
81 RemoteWindowTreeHostWin();
82 ~RemoteWindowTreeHostWin() override;
84 private:
85 // IPC message handing methods:
86 void OnMouseMoved(int32 x, int32 y, int32 flags);
87 void OnMouseButton(const MetroViewerHostMsg_MouseButtonParams& params);
88 void OnKeyDown(uint32 vkey,
89 uint32 repeat_count,
90 uint32 scan_code,
91 uint32 flags);
92 void OnKeyUp(uint32 vkey,
93 uint32 repeat_count,
94 uint32 scan_code,
95 uint32 flags);
96 void OnChar(uint32 key_code,
97 uint32 repeat_count,
98 uint32 scan_code,
99 uint32 flags);
100 void OnWindowActivated(bool repaint);
101 void OnEdgeGesture();
102 void OnTouchDown(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
103 void OnTouchUp(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
104 void OnTouchMoved(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
105 void OnSetCursorPosAck();
107 // For Input Method support:
108 ui::RemoteInputMethodPrivateWin* GetRemoteInputMethodPrivate();
109 void OnImeCandidatePopupChanged(bool visible);
110 void OnImeCompositionChanged(
111 const base::string16& text,
112 int32 selection_start,
113 int32 selection_end,
114 const std::vector<metro_viewer::UnderlineInfo>& underlines);
115 void OnImeTextCommitted(const base::string16& text);
116 void OnImeInputSourceChanged(uint16 language_id, bool is_ime);
118 // WindowTreeHost overrides:
119 ui::EventSource* GetEventSource() override;
120 gfx::AcceleratedWidget GetAcceleratedWidget() override;
121 void Show() override;
122 void Hide() override;
123 gfx::Rect GetBounds() const override;
124 void SetBounds(const gfx::Rect& bounds) override;
125 gfx::Point GetLocationOnNativeScreen() const override;
126 void SetCapture() override;
127 void ReleaseCapture() override;
128 void SetCursorNative(gfx::NativeCursor cursor) override;
129 void MoveCursorToNative(const gfx::Point& location) override;
130 void OnCursorVisibilityChangedNative(bool show) override;
132 // ui::EventSource:
133 ui::EventProcessor* GetEventProcessor() override;
135 // ui::internal::RemoteInputMethodDelegateWin overrides:
136 void CancelComposition() override;
137 void OnTextInputClientUpdated(
138 const std::vector<int32>& input_scopes,
139 const std::vector<gfx::Rect>& composition_character_bounds) override;
141 // Helper function to dispatch a keyboard message to the desired target.
142 // The default target is the WindowEventDispatcher. For nested message loop
143 // invocations we post a synthetic keyboard message directly into the message
144 // loop. The dispatcher for the nested loop would then decide how this
145 // message is routed.
146 void DispatchKeyboardMessage(ui::EventType type,
147 uint32 vkey,
148 uint32 repeat_count,
149 uint32 scan_code,
150 uint32 flags,
151 bool is_character);
153 // Sets the event flags. |flags| is a bitmask of EventFlags. If there is a
154 // change the system virtual key state is updated as well. This way if chrome
155 // queries for key state it matches that of event being dispatched.
156 void SetEventFlags(uint32 flags);
158 uint32 mouse_event_flags() const {
159 return event_flags_ & (ui::EF_LEFT_MOUSE_BUTTON |
160 ui::EF_MIDDLE_MOUSE_BUTTON |
161 ui::EF_RIGHT_MOUSE_BUTTON);
164 uint32 key_event_flags() const {
165 return event_flags_ & (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN |
166 ui::EF_ALT_DOWN | ui::EF_CAPS_LOCK_DOWN);
169 HWND remote_window_;
170 IPC::Sender* host_;
171 scoped_ptr<ui::ViewProp> prop_;
173 // Incremented if we need to ignore mouse messages until the SetCursorPos
174 // operation is acked by the viewer.
175 int ignore_mouse_moves_until_set_cursor_ack_;
177 // Tracking last click event for synthetically generated mouse events.
178 scoped_ptr<ui::MouseEvent> last_mouse_click_event_;
180 // State of the keyboard/mouse at the time of the last input event. See
181 // description of SetEventFlags().
182 uint32 event_flags_;
184 // Current size of this root window.
185 gfx::Size window_size_;
187 DISALLOW_COPY_AND_ASSIGN(RemoteWindowTreeHostWin);
190 } // namespace aura
192 #endif // UI_AURA_REMOTE_WINDOW_TREE_HOST_WIN_H_