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_
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
;
27 class RemoteInputMethodPrivateWin
;
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
{
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.
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
78 bool IsForegroundWindow();
81 RemoteWindowTreeHostWin();
82 virtual ~RemoteWindowTreeHostWin();
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
,
92 void OnKeyUp(uint32 vkey
,
96 void OnChar(uint32 key_code
,
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
,
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 virtual ui::EventSource
* GetEventSource() override
;
120 virtual gfx::AcceleratedWidget
GetAcceleratedWidget() override
;
121 virtual void Show() override
;
122 virtual void Hide() override
;
123 virtual gfx::Rect
GetBounds() const override
;
124 virtual void SetBounds(const gfx::Rect
& bounds
) override
;
125 virtual gfx::Point
GetLocationOnNativeScreen() const override
;
126 virtual void SetCapture() override
;
127 virtual void ReleaseCapture() override
;
128 virtual void SetCursorNative(gfx::NativeCursor cursor
) override
;
129 virtual void MoveCursorToNative(const gfx::Point
& location
) override
;
130 virtual void OnCursorVisibilityChangedNative(bool show
) override
;
133 virtual ui::EventProcessor
* GetEventProcessor() override
;
135 // ui::internal::RemoteInputMethodDelegateWin overrides:
136 virtual void CancelComposition() override
;
137 virtual 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
,
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
);
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().
184 // Current size of this root window.
185 gfx::Size window_size_
;
187 DISALLOW_COPY_AND_ASSIGN(RemoteWindowTreeHostWin
);
192 #endif // UI_AURA_REMOTE_WINDOW_TREE_HOST_WIN_H_