Fix OOP <webview> resize and autosize.
[chromium-blink-merge.git] / ui / aura / remote_window_tree_host_win.h
blob340d75fa4c37820563117bd2f9ea6c09c04f82fb
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::internal::RemoteInputMethodDelegateWin {
44 public:
45 // Returns the current RemoteWindowTreeHostWin. This does *not* create a
46 // RemoteWindowTreeHostWin.
47 static RemoteWindowTreeHostWin* Instance();
49 // Returns true if there is a RemoteWindowTreeHostWin and it has a valid
50 // HWND. A return value of false typically indicates we're not in metro mode.
51 static bool IsValid();
53 // Sets the handle to the remote window. The |remote_window| is the actual
54 // window owned by the viewer process. Call this before Connected() for some
55 // customers like input method initialization which needs the handle.
56 void SetRemoteWindowHandle(HWND remote_window);
57 HWND remote_window() { return remote_window_; }
59 // The |host| can be used when we need to send a message to it.
60 void Connected(IPC::Sender* host);
61 // Called when the remote process has closed its IPC connection.
62 void Disconnected();
64 // Called when we have a message from the remote process.
65 bool OnMessageReceived(const IPC::Message& message);
67 void HandleOpenURLOnDesktop(const base::FilePath& shortcut,
68 const base::string16& url);
70 void HandleWindowSizeChanged(uint32 width, uint32 height);
72 // Returns the active ASH root window.
73 Window* GetAshWindow();
75 // Returns true if the remote window is the foreground window according to the
76 // OS.
77 bool IsForegroundWindow();
79 protected:
80 RemoteWindowTreeHostWin();
81 ~RemoteWindowTreeHostWin() override;
83 private:
84 // IPC message handing methods:
85 void OnMouseMoved(int32 x, int32 y, int32 flags);
86 void OnMouseButton(const MetroViewerHostMsg_MouseButtonParams& params);
87 void OnKeyDown(uint32 vkey,
88 uint32 repeat_count,
89 uint32 scan_code,
90 uint32 flags);
91 void OnKeyUp(uint32 vkey,
92 uint32 repeat_count,
93 uint32 scan_code,
94 uint32 flags);
95 void OnChar(uint32 key_code,
96 uint32 repeat_count,
97 uint32 scan_code,
98 uint32 flags);
99 void OnWindowActivated(bool repaint);
100 void OnEdgeGesture();
101 void OnTouchDown(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
102 void OnTouchUp(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
103 void OnTouchMoved(int32 x, int32 y, uint64 timestamp, uint32 pointer_id);
104 void OnSetCursorPosAck();
106 // For Input Method support:
107 ui::RemoteInputMethodPrivateWin* GetRemoteInputMethodPrivate();
108 void OnImeCandidatePopupChanged(bool visible);
109 void OnImeCompositionChanged(
110 const base::string16& text,
111 int32 selection_start,
112 int32 selection_end,
113 const std::vector<metro_viewer::UnderlineInfo>& underlines);
114 void OnImeTextCommitted(const base::string16& text);
115 void OnImeInputSourceChanged(uint16 language_id, bool is_ime);
117 // WindowTreeHost overrides:
118 ui::EventSource* GetEventSource() override;
119 gfx::AcceleratedWidget GetAcceleratedWidget() override;
120 void ShowImpl() override;
121 void HideImpl() override;
122 gfx::Rect GetBounds() const override;
123 void SetBounds(const gfx::Rect& bounds) override;
124 gfx::Point GetLocationOnNativeScreen() const override;
125 void SetCapture() override;
126 void ReleaseCapture() override;
127 void SetCursorNative(gfx::NativeCursor cursor) override;
128 void MoveCursorToNative(const gfx::Point& location) override;
129 void OnCursorVisibilityChangedNative(bool show) override;
131 // ui::internal::RemoteInputMethodDelegateWin overrides:
132 void CancelComposition() override;
133 void OnTextInputClientUpdated(
134 const std::vector<int32>& input_scopes,
135 const std::vector<gfx::Rect>& composition_character_bounds) override;
137 // Helper function to dispatch a keyboard message to the desired target.
138 // The default target is the WindowEventDispatcher. For nested message loop
139 // invocations we post a synthetic keyboard message directly into the message
140 // loop. The dispatcher for the nested loop would then decide how this
141 // message is routed.
142 void DispatchKeyboardMessage(ui::EventType type,
143 uint32 vkey,
144 uint32 repeat_count,
145 uint32 scan_code,
146 uint32 flags,
147 bool is_character);
149 // Sets the event flags. |flags| is a bitmask of EventFlags. If there is a
150 // change the system virtual key state is updated as well. This way if chrome
151 // queries for key state it matches that of event being dispatched.
152 void SetEventFlags(uint32 flags);
154 uint32 mouse_event_flags() const {
155 return event_flags_ & (ui::EF_LEFT_MOUSE_BUTTON |
156 ui::EF_MIDDLE_MOUSE_BUTTON |
157 ui::EF_RIGHT_MOUSE_BUTTON);
160 uint32 key_event_flags() const {
161 return event_flags_ & (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN |
162 ui::EF_ALT_DOWN | ui::EF_CAPS_LOCK_DOWN);
165 HWND remote_window_;
166 IPC::Sender* host_;
167 scoped_ptr<ui::ViewProp> prop_;
169 // Incremented if we need to ignore mouse messages until the SetCursorPos
170 // operation is acked by the viewer.
171 int ignore_mouse_moves_until_set_cursor_ack_;
173 // Tracking last click event for synthetically generated mouse events.
174 scoped_ptr<ui::MouseEvent> last_mouse_click_event_;
176 // State of the keyboard/mouse at the time of the last input event. See
177 // description of SetEventFlags().
178 uint32 event_flags_;
180 // Current size of this root window.
181 gfx::Size window_size_;
183 DISALLOW_COPY_AND_ASSIGN(RemoteWindowTreeHostWin);
186 } // namespace aura
188 #endif // UI_AURA_REMOTE_WINDOW_TREE_HOST_WIN_H_