[email protected] | e0d22e8 | 2012-01-04 00:46:57 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 5 | #ifndef UI_AURA_ROOT_WINDOW_H_ |
| 6 | #define UI_AURA_ROOT_WINDOW_H_ |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 7 | #pragma once |
| 8 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 9 | #include "base/basictypes.h" |
| 10 | #include "base/memory/ref_counted.h" |
[email protected] | f296be7 | 2011-10-11 15:40:00 | [diff] [blame] | 11 | #include "base/memory/weak_ptr.h" |
[email protected] | 35e9b66a | 2011-10-06 18:19:21 | [diff] [blame] | 12 | #include "base/message_loop.h" |
[email protected] | f94f0f1 | 2011-09-14 21:14:01 | [diff] [blame] | 13 | #include "ui/aura/aura_export.h" |
[email protected] | 70ccf70 | 2011-09-22 18:15:58 | [diff] [blame] | 14 | #include "ui/aura/cursor.h" |
[email protected] | 114bfbd | 2011-10-18 21:20:24 | [diff] [blame] | 15 | #include "ui/aura/focus_manager.h" |
| 16 | #include "ui/aura/window.h" |
[email protected] | 7a05bdc | 2011-10-04 23:38:39 | [diff] [blame] | 17 | #include "ui/base/events.h" |
[email protected] | 905e19a | 2011-09-07 02:17:53 | [diff] [blame] | 18 | #include "ui/gfx/compositor/compositor.h" |
[email protected] | e876c27 | 2011-11-02 16:42:45 | [diff] [blame] | 19 | #include "ui/gfx/compositor/layer_animation_observer.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 20 | #include "ui/gfx/native_widget_types.h" |
[email protected] | 896728e | 2011-10-14 00:41:26 | [diff] [blame] | 21 | #include "ui/gfx/point.h" |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 22 | |
| 23 | namespace gfx { |
| 24 | class Size; |
| 25 | } |
| 26 | |
[email protected] | 593ddfa | 2011-10-20 21:51:43 | [diff] [blame] | 27 | namespace ui { |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 28 | class LayerAnimationSequence; |
[email protected] | 593ddfa | 2011-10-20 21:51:43 | [diff] [blame] | 29 | class Transform; |
| 30 | } |
| 31 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 32 | namespace aura { |
| 33 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 34 | class RootWindowHost; |
| 35 | class RootWindowObserver; |
[email protected] | 5951806f | 2011-10-17 16:06:35 | [diff] [blame] | 36 | class KeyEvent; |
[email protected] | a83f0f2 | 2011-08-23 15:39:15 | [diff] [blame] | 37 | class MouseEvent; |
[email protected] | 4def0e69 | 2011-10-19 14:11:09 | [diff] [blame] | 38 | class ScreenAura; |
[email protected] | aca200e | 2011-12-15 17:52:02 | [diff] [blame] | 39 | class StackingClient; |
| 40 | class ScrollEvent; |
[email protected] | 5951806f | 2011-10-17 16:06:35 | [diff] [blame] | 41 | class TouchEvent; |
[email protected] | 538f956 | 2012-01-17 17:46:04 | [diff] [blame] | 42 | class GestureEvent; |
[email protected] | 912b6f3 | 2012-01-19 00:48:01 | [diff] [blame^] | 43 | class GestureRecognizer; |
[email protected] | b1b15551 | 2011-08-18 22:47:50 | [diff] [blame] | 44 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 45 | // RootWindow is responsible for hosting a set of windows. |
| 46 | class AURA_EXPORT RootWindow : public ui::CompositorDelegate, |
| 47 | public Window, |
| 48 | public internal::FocusManager, |
| 49 | public ui::LayerAnimationObserver { |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 50 | public: |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 51 | static RootWindow* GetInstance(); |
[email protected] | c06186d | 2011-11-23 06:58:59 | [diff] [blame] | 52 | static void DeleteInstance(); |
[email protected] | 9ed496e | 2011-10-18 23:47:39 | [diff] [blame] | 53 | |
[email protected] | 5978af5e | 2011-10-24 22:17:18 | [diff] [blame] | 54 | static void set_use_fullscreen_host_window(bool use_fullscreen) { |
| 55 | use_fullscreen_host_window_ = use_fullscreen; |
| 56 | } |
[email protected] | b063928 | 2011-12-22 21:12:27 | [diff] [blame] | 57 | static bool use_fullscreen_host_window() { |
| 58 | return use_fullscreen_host_window_; |
| 59 | } |
[email protected] | 5978af5e | 2011-10-24 22:17:18 | [diff] [blame] | 60 | |
[email protected] | 9ed496e | 2011-10-18 23:47:39 | [diff] [blame] | 61 | ui::Compositor* compositor() { return compositor_.get(); } |
[email protected] | 896728e | 2011-10-14 00:41:26 | [diff] [blame] | 62 | gfx::Point last_mouse_location() const { return last_mouse_location_; } |
[email protected] | 912be0e | 2011-11-09 19:05:24 | [diff] [blame] | 63 | gfx::NativeCursor last_cursor() const { return last_cursor_; } |
[email protected] | 9ed496e | 2011-10-18 23:47:39 | [diff] [blame] | 64 | Window* mouse_pressed_handler() { return mouse_pressed_handler_; } |
| 65 | Window* capture_window() { return capture_window_; } |
[email protected] | 4def0e69 | 2011-10-19 14:11:09 | [diff] [blame] | 66 | ScreenAura* screen() { return screen_; } |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 67 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 68 | // Shows the root window host. |
| 69 | void ShowRootWindow(); |
[email protected] | 970aa36 | 2011-08-30 20:03:34 | [diff] [blame] | 70 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 71 | // Sets the size of the root window. |
[email protected] | 114bfbd | 2011-10-18 21:20:24 | [diff] [blame] | 72 | void SetHostSize(const gfx::Size& size); |
| 73 | gfx::Size GetHostSize() const; |
[email protected] | 970aa36 | 2011-08-30 20:03:34 | [diff] [blame] | 74 | |
[email protected] | 70ccf70 | 2011-09-22 18:15:58 | [diff] [blame] | 75 | // Shows the specified cursor. |
[email protected] | 0207c92d | 2011-10-04 14:45:07 | [diff] [blame] | 76 | void SetCursor(gfx::NativeCursor cursor); |
[email protected] | 70ccf70 | 2011-09-22 18:15:58 | [diff] [blame] | 77 | |
[email protected] | 09a02fff | 2011-12-20 22:01:43 | [diff] [blame] | 78 | // Sets current cursor visibility to |show|. |
| 79 | void ShowCursor(bool show); |
| 80 | |
[email protected] | 5922cb2 | 2012-01-17 21:53:12 | [diff] [blame] | 81 | // Moves the cursor to the specified location relative to the root window. |
| 82 | void MoveCursorTo(const gfx::Point& location); |
| 83 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 84 | // Shows the root window host and runs an event loop for it. |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 85 | void Run(); |
| 86 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 87 | // Draws the necessary set of windows. |
| 88 | void Draw(); |
| 89 | |
[email protected] | a83f0f2 | 2011-08-23 15:39:15 | [diff] [blame] | 90 | // Handles a mouse event. Returns true if handled. |
[email protected] | 593ddfa | 2011-10-20 21:51:43 | [diff] [blame] | 91 | bool DispatchMouseEvent(MouseEvent* event); |
[email protected] | a83f0f2 | 2011-08-23 15:39:15 | [diff] [blame] | 92 | |
[email protected] | c94f859 | 2011-09-02 20:12:13 | [diff] [blame] | 93 | // Handles a key event. Returns true if handled. |
[email protected] | 593ddfa | 2011-10-20 21:51:43 | [diff] [blame] | 94 | bool DispatchKeyEvent(KeyEvent* event); |
[email protected] | c94f859 | 2011-09-02 20:12:13 | [diff] [blame] | 95 | |
[email protected] | aca200e | 2011-12-15 17:52:02 | [diff] [blame] | 96 | // Handles a scroll event. Returns true if handled. |
| 97 | bool DispatchScrollEvent(ScrollEvent* event); |
| 98 | |
[email protected] | 5951806f | 2011-10-17 16:06:35 | [diff] [blame] | 99 | // Handles a touch event. Returns true if handled. |
[email protected] | 593ddfa | 2011-10-20 21:51:43 | [diff] [blame] | 100 | bool DispatchTouchEvent(TouchEvent* event); |
[email protected] | 5951806f | 2011-10-17 16:06:35 | [diff] [blame] | 101 | |
[email protected] | 538f956 | 2012-01-17 17:46:04 | [diff] [blame] | 102 | // Handles a gesture event. Returns true if handled. Unlike the other |
| 103 | // event-dispatching function (e.g. for touch/mouse/keyboard events), gesture |
| 104 | // events are dispatched from GestureRecognizer instead of RootWindowHost. |
| 105 | bool DispatchGestureEvent(GestureEvent* event); |
| 106 | |
[email protected] | 7a9f891 | 2011-09-12 21:31:31 | [diff] [blame] | 107 | // Called when the host changes size. |
| 108 | void OnHostResized(const gfx::Size& size); |
| 109 | |
[email protected] | e6f0384 | 2011-11-29 21:26:20 | [diff] [blame] | 110 | // Called when the native screen's resolution changes. |
| 111 | void OnNativeScreenResized(const gfx::Size& size); |
| 112 | |
[email protected] | a54e65b | 2011-11-21 22:03:34 | [diff] [blame] | 113 | // Invoked when |window| is initialized. |
| 114 | void WindowInitialized(Window* window); |
| 115 | |
[email protected] | 114bfbd | 2011-10-18 21:20:24 | [diff] [blame] | 116 | // Invoked when |window| is being destroyed. |
[email protected] | b8b456ce | 2011-09-27 00:19:13 | [diff] [blame] | 117 | void WindowDestroying(Window* window); |
| 118 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 119 | // Returns the root window's dispatcher. The result should only be passed to |
[email protected] | 4d628531 | 2011-10-24 07:19:51 | [diff] [blame] | 120 | // MessageLoopForUI::RunWithDispatcher() or |
| 121 | // MessageLoopForUI::RunAllPendingWithDispatcher(), or used to dispatch |
| 122 | // an event by |Dispatch(const NativeEvent&)| on it. It must never be stored. |
[email protected] | 35e9b66a | 2011-10-06 18:19:21 | [diff] [blame] | 123 | MessageLoop::Dispatcher* GetDispatcher(); |
| 124 | |
[email protected] | e717ffd | 2011-10-13 17:15:19 | [diff] [blame] | 125 | // Add/remove observer. |
[email protected] | 9fc206d | 2011-12-13 00:05:33 | [diff] [blame] | 126 | void AddRootWindowObserver(RootWindowObserver* observer); |
| 127 | void RemoveRootWindowObserver(RootWindowObserver* observer); |
[email protected] | e717ffd | 2011-10-13 17:15:19 | [diff] [blame] | 128 | |
[email protected] | bf74dd8 | 2011-11-11 21:36:41 | [diff] [blame] | 129 | // Are any mouse buttons currently down? |
| 130 | bool IsMouseButtonDown() const; |
| 131 | |
[email protected] | b5a1864 | 2011-11-18 22:45:36 | [diff] [blame] | 132 | // Posts |native_event| to the platform's event queue. |
| 133 | void PostNativeEvent(const base::NativeEvent& native_event); |
| 134 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 135 | // Converts |point| from the root window's coordinate system to native |
| 136 | // screen's. |
[email protected] | ace7ca0 | 2011-11-22 21:34:17 | [diff] [blame] | 137 | void ConvertPointToNativeScreen(gfx::Point* point) const; |
| 138 | |
[email protected] | 4def0e69 | 2011-10-19 14:11:09 | [diff] [blame] | 139 | // Capture ------------------------------------------------------------------- |
| 140 | |
[email protected] | 114bfbd | 2011-10-18 21:20:24 | [diff] [blame] | 141 | // Sets capture to the specified window. |
| 142 | void SetCapture(Window* window); |
| 143 | |
| 144 | // If |window| has mouse capture, the current capture window is set to NULL. |
| 145 | void ReleaseCapture(Window* window); |
| 146 | |
[email protected] | ea2a867a | 2011-10-26 17:41:33 | [diff] [blame] | 147 | // Overridden from Window: |
[email protected] | 5751906 | 2011-10-21 18:28:15 | [diff] [blame] | 148 | virtual void SetTransform(const ui::Transform& transform) OVERRIDE; |
| 149 | |
[email protected] | 745816be | 2011-11-22 05:08:30 | [diff] [blame] | 150 | #if !defined(NDEBUG) |
| 151 | // Toggles the host's full screen state. |
| 152 | void ToggleFullScreen(); |
| 153 | #endif |
| 154 | |
[email protected] | 912b6f3 | 2012-01-19 00:48:01 | [diff] [blame^] | 155 | // Provided only for testing: |
| 156 | void SetGestureRecognizerForTesting(GestureRecognizer* gr) { |
| 157 | gesture_recognizer_ = gr; |
| 158 | } |
| 159 | |
[email protected] | 6e45688 | 2011-12-06 07:42:51 | [diff] [blame] | 160 | // Overridden from ui::CompositorDelegate: |
[email protected] | e0d22e8 | 2012-01-04 00:46:57 | [diff] [blame] | 161 | virtual void ScheduleDraw() OVERRIDE; |
[email protected] | 6e45688 | 2011-12-06 07:42:51 | [diff] [blame] | 162 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 163 | private: |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 164 | RootWindow(); |
| 165 | virtual ~RootWindow(); |
[email protected] | c06186d | 2011-11-23 06:58:59 | [diff] [blame] | 166 | |
[email protected] | 114bfbd | 2011-10-18 21:20:24 | [diff] [blame] | 167 | // Called whenever the mouse moves, tracks the current |mouse_moved_handler_|, |
| 168 | // sending exited and entered events as its value changes. |
| 169 | void HandleMouseMoved(const MouseEvent& event, Window* target); |
| 170 | |
[email protected] | ea2a867a | 2011-10-26 17:41:33 | [diff] [blame] | 171 | bool ProcessMouseEvent(Window* target, MouseEvent* event); |
| 172 | bool ProcessKeyEvent(Window* target, KeyEvent* event); |
| 173 | ui::TouchStatus ProcessTouchEvent(Window* target, TouchEvent* event); |
[email protected] | 538f956 | 2012-01-17 17:46:04 | [diff] [blame] | 174 | ui::GestureStatus ProcessGestureEvent(Window* target, GestureEvent* event); |
[email protected] | ea2a867a | 2011-10-26 17:41:33 | [diff] [blame] | 175 | |
[email protected] | 114bfbd | 2011-10-18 21:20:24 | [diff] [blame] | 176 | // Overridden from Window: |
| 177 | virtual bool CanFocus() const OVERRIDE; |
[email protected] | 1128681f | 2012-01-13 03:15:40 | [diff] [blame] | 178 | virtual bool CanReceiveEvents() const OVERRIDE; |
[email protected] | 114bfbd | 2011-10-18 21:20:24 | [diff] [blame] | 179 | virtual internal::FocusManager* GetFocusManager() OVERRIDE; |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 180 | virtual RootWindow* GetRootWindow() OVERRIDE; |
| 181 | virtual void WindowDetachedFromRootWindow(Window* window) OVERRIDE; |
[email protected] | 114bfbd | 2011-10-18 21:20:24 | [diff] [blame] | 182 | |
[email protected] | e876c27 | 2011-11-02 16:42:45 | [diff] [blame] | 183 | // Overridden from ui::LayerAnimationObserver: |
[email protected] | fe7074c6 | 2011-10-28 15:22:54 | [diff] [blame] | 184 | virtual void OnLayerAnimationEnded( |
| 185 | const ui::LayerAnimationSequence* animation) OVERRIDE; |
[email protected] | e876c27 | 2011-11-02 16:42:45 | [diff] [blame] | 186 | virtual void OnLayerAnimationScheduled( |
| 187 | const ui::LayerAnimationSequence* animation) OVERRIDE; |
| 188 | virtual void OnLayerAnimationAborted( |
| 189 | const ui::LayerAnimationSequence* animation) OVERRIDE; |
[email protected] | 326828b | 2011-10-21 02:01:10 | [diff] [blame] | 190 | |
[email protected] | 114bfbd | 2011-10-18 21:20:24 | [diff] [blame] | 191 | // Overridden from FocusManager: |
| 192 | virtual void SetFocusedWindow(Window* window) OVERRIDE; |
| 193 | virtual Window* GetFocusedWindow() OVERRIDE; |
| 194 | virtual bool IsFocusedWindow(const Window* window) const OVERRIDE; |
| 195 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 196 | // Initializes the root window. |
[email protected] | 9ed496e | 2011-10-18 23:47:39 | [diff] [blame] | 197 | void Init(); |
[email protected] | 87b0d82e | 2011-10-07 21:02:59 | [diff] [blame] | 198 | |
[email protected] | 4a14bca9 | 2011-10-21 00:09:22 | [diff] [blame] | 199 | // Parses the switch describing the initial size for the host window and |
| 200 | // returns bounds for the window. |
| 201 | gfx::Rect GetInitialHostWindowBounds() const; |
| 202 | |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 203 | scoped_refptr<ui::Compositor> compositor_; |
| 204 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 205 | scoped_ptr<RootWindowHost> host_; |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 206 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 207 | static RootWindow* instance_; |
[email protected] | 8d8c773 | 2011-08-25 22:35:13 | [diff] [blame] | 208 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 209 | // If set before the RootWindow is created, the host window will cover the |
| 210 | // entire screen. Note that this can still be overridden via the |
[email protected] | 5978af5e | 2011-10-24 22:17:18 | [diff] [blame] | 211 | // switches::kAuraHostWindowSize flag. |
| 212 | static bool use_fullscreen_host_window_; |
| 213 | |
| 214 | // Used to schedule painting. |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 215 | base::WeakPtrFactory<RootWindow> schedule_paint_factory_; |
[email protected] | 5978af5e | 2011-10-24 22:17:18 | [diff] [blame] | 216 | |
[email protected] | 896728e | 2011-10-14 00:41:26 | [diff] [blame] | 217 | // Last location seen in a mouse event. |
| 218 | gfx::Point last_mouse_location_; |
| 219 | |
[email protected] | bf74dd8 | 2011-11-11 21:36:41 | [diff] [blame] | 220 | // ui::EventFlags containing the current state of the mouse buttons. |
| 221 | int mouse_button_flags_; |
| 222 | |
[email protected] | 912be0e | 2011-11-09 19:05:24 | [diff] [blame] | 223 | // Last cursor set. Used for testing. |
| 224 | gfx::NativeCursor last_cursor_; |
| 225 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 226 | ObserverList<RootWindowObserver> observers_; |
[email protected] | e717ffd | 2011-10-13 17:15:19 | [diff] [blame] | 227 | |
[email protected] | 4def0e69 | 2011-10-19 14:11:09 | [diff] [blame] | 228 | ScreenAura* screen_; |
| 229 | |
[email protected] | 114bfbd | 2011-10-18 21:20:24 | [diff] [blame] | 230 | // The capture window. When not-null, this window receives all the mouse and |
| 231 | // touch events. |
| 232 | Window* capture_window_; |
| 233 | |
| 234 | Window* mouse_pressed_handler_; |
| 235 | Window* mouse_moved_handler_; |
| 236 | Window* focused_window_; |
| 237 | Window* touch_event_handler_; |
[email protected] | 912b6f3 | 2012-01-19 00:48:01 | [diff] [blame^] | 238 | Window* gesture_handler_; |
| 239 | |
| 240 | // The gesture_recognizer_ for this. |
| 241 | GestureRecognizer* gesture_recognizer_; |
[email protected] | 114bfbd | 2011-10-18 21:20:24 | [diff] [blame] | 242 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 243 | DISALLOW_COPY_AND_ASSIGN(RootWindow); |
[email protected] | 81585f3 | 2011-07-29 19:32:06 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | } // namespace aura |
| 247 | |
[email protected] | 99f07e0 | 2011-12-07 00:02:59 | [diff] [blame] | 248 | #endif // UI_AURA_ROOT_WINDOW_H_ |