blob: 8e59c4f8b02f590e133594d0854abf28e0267159 [file] [log] [blame]
[email protected]e0d22e82012-01-04 00:46:571// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]81585f32011-07-29 19:32:062// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]99f07e02011-12-07 00:02:595#ifndef UI_AURA_ROOT_WINDOW_H_
6#define UI_AURA_ROOT_WINDOW_H_
[email protected]81585f32011-07-29 19:32:067#pragma once
8
[email protected]81585f32011-07-29 19:32:069#include "base/basictypes.h"
10#include "base/memory/ref_counted.h"
[email protected]f296be72011-10-11 15:40:0011#include "base/memory/weak_ptr.h"
[email protected]35e9b66a2011-10-06 18:19:2112#include "base/message_loop.h"
[email protected]f94f0f12011-09-14 21:14:0113#include "ui/aura/aura_export.h"
[email protected]70ccf702011-09-22 18:15:5814#include "ui/aura/cursor.h"
[email protected]114bfbd2011-10-18 21:20:2415#include "ui/aura/focus_manager.h"
16#include "ui/aura/window.h"
[email protected]7a05bdc2011-10-04 23:38:3917#include "ui/base/events.h"
[email protected]905e19a2011-09-07 02:17:5318#include "ui/gfx/compositor/compositor.h"
[email protected]e876c272011-11-02 16:42:4519#include "ui/gfx/compositor/layer_animation_observer.h"
[email protected]81585f32011-07-29 19:32:0620#include "ui/gfx/native_widget_types.h"
[email protected]896728e2011-10-14 00:41:2621#include "ui/gfx/point.h"
[email protected]81585f32011-07-29 19:32:0622
23namespace gfx {
24class Size;
25}
26
[email protected]593ddfa2011-10-20 21:51:4327namespace ui {
[email protected]fe7074c62011-10-28 15:22:5428class LayerAnimationSequence;
[email protected]593ddfa2011-10-20 21:51:4329class Transform;
30}
31
[email protected]81585f32011-07-29 19:32:0632namespace aura {
33
[email protected]99f07e02011-12-07 00:02:5934class RootWindowHost;
35class RootWindowObserver;
[email protected]5951806f2011-10-17 16:06:3536class KeyEvent;
[email protected]a83f0f22011-08-23 15:39:1537class MouseEvent;
[email protected]4def0e692011-10-19 14:11:0938class ScreenAura;
[email protected]aca200e2011-12-15 17:52:0239class StackingClient;
40class ScrollEvent;
[email protected]5951806f2011-10-17 16:06:3541class TouchEvent;
[email protected]538f9562012-01-17 17:46:0442class GestureEvent;
[email protected]912b6f32012-01-19 00:48:0143class GestureRecognizer;
[email protected]b1b155512011-08-18 22:47:5044
[email protected]99f07e02011-12-07 00:02:5945// RootWindow is responsible for hosting a set of windows.
46class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
47 public Window,
48 public internal::FocusManager,
49 public ui::LayerAnimationObserver {
[email protected]81585f32011-07-29 19:32:0650 public:
[email protected]99f07e02011-12-07 00:02:5951 static RootWindow* GetInstance();
[email protected]c06186d2011-11-23 06:58:5952 static void DeleteInstance();
[email protected]9ed496e2011-10-18 23:47:3953
[email protected]5978af5e2011-10-24 22:17:1854 static void set_use_fullscreen_host_window(bool use_fullscreen) {
55 use_fullscreen_host_window_ = use_fullscreen;
56 }
[email protected]b0639282011-12-22 21:12:2757 static bool use_fullscreen_host_window() {
58 return use_fullscreen_host_window_;
59 }
[email protected]5978af5e2011-10-24 22:17:1860
[email protected]9ed496e2011-10-18 23:47:3961 ui::Compositor* compositor() { return compositor_.get(); }
[email protected]896728e2011-10-14 00:41:2662 gfx::Point last_mouse_location() const { return last_mouse_location_; }
[email protected]912be0e2011-11-09 19:05:2463 gfx::NativeCursor last_cursor() const { return last_cursor_; }
[email protected]9ed496e2011-10-18 23:47:3964 Window* mouse_pressed_handler() { return mouse_pressed_handler_; }
65 Window* capture_window() { return capture_window_; }
[email protected]4def0e692011-10-19 14:11:0966 ScreenAura* screen() { return screen_; }
[email protected]87b0d82e2011-10-07 21:02:5967
[email protected]99f07e02011-12-07 00:02:5968 // Shows the root window host.
69 void ShowRootWindow();
[email protected]970aa362011-08-30 20:03:3470
[email protected]99f07e02011-12-07 00:02:5971 // Sets the size of the root window.
[email protected]114bfbd2011-10-18 21:20:2472 void SetHostSize(const gfx::Size& size);
73 gfx::Size GetHostSize() const;
[email protected]970aa362011-08-30 20:03:3474
[email protected]70ccf702011-09-22 18:15:5875 // Shows the specified cursor.
[email protected]0207c92d2011-10-04 14:45:0776 void SetCursor(gfx::NativeCursor cursor);
[email protected]70ccf702011-09-22 18:15:5877
[email protected]09a02fff2011-12-20 22:01:4378 // Sets current cursor visibility to |show|.
79 void ShowCursor(bool show);
80
[email protected]5922cb22012-01-17 21:53:1281 // Moves the cursor to the specified location relative to the root window.
82 void MoveCursorTo(const gfx::Point& location);
83
[email protected]99f07e02011-12-07 00:02:5984 // Shows the root window host and runs an event loop for it.
[email protected]8d8c7732011-08-25 22:35:1385 void Run();
86
[email protected]81585f32011-07-29 19:32:0687 // Draws the necessary set of windows.
88 void Draw();
89
[email protected]a83f0f22011-08-23 15:39:1590 // Handles a mouse event. Returns true if handled.
[email protected]593ddfa2011-10-20 21:51:4391 bool DispatchMouseEvent(MouseEvent* event);
[email protected]a83f0f22011-08-23 15:39:1592
[email protected]c94f8592011-09-02 20:12:1393 // Handles a key event. Returns true if handled.
[email protected]593ddfa2011-10-20 21:51:4394 bool DispatchKeyEvent(KeyEvent* event);
[email protected]c94f8592011-09-02 20:12:1395
[email protected]aca200e2011-12-15 17:52:0296 // Handles a scroll event. Returns true if handled.
97 bool DispatchScrollEvent(ScrollEvent* event);
98
[email protected]5951806f2011-10-17 16:06:3599 // Handles a touch event. Returns true if handled.
[email protected]593ddfa2011-10-20 21:51:43100 bool DispatchTouchEvent(TouchEvent* event);
[email protected]5951806f2011-10-17 16:06:35101
[email protected]538f9562012-01-17 17:46:04102 // 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]7a9f8912011-09-12 21:31:31107 // Called when the host changes size.
108 void OnHostResized(const gfx::Size& size);
109
[email protected]e6f03842011-11-29 21:26:20110 // Called when the native screen's resolution changes.
111 void OnNativeScreenResized(const gfx::Size& size);
112
[email protected]a54e65b2011-11-21 22:03:34113 // Invoked when |window| is initialized.
114 void WindowInitialized(Window* window);
115
[email protected]114bfbd2011-10-18 21:20:24116 // Invoked when |window| is being destroyed.
[email protected]b8b456ce2011-09-27 00:19:13117 void WindowDestroying(Window* window);
118
[email protected]99f07e02011-12-07 00:02:59119 // Returns the root window's dispatcher. The result should only be passed to
[email protected]4d6285312011-10-24 07:19:51120 // 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]35e9b66a2011-10-06 18:19:21123 MessageLoop::Dispatcher* GetDispatcher();
124
[email protected]e717ffd2011-10-13 17:15:19125 // Add/remove observer.
[email protected]9fc206d2011-12-13 00:05:33126 void AddRootWindowObserver(RootWindowObserver* observer);
127 void RemoveRootWindowObserver(RootWindowObserver* observer);
[email protected]e717ffd2011-10-13 17:15:19128
[email protected]bf74dd82011-11-11 21:36:41129 // Are any mouse buttons currently down?
130 bool IsMouseButtonDown() const;
131
[email protected]b5a18642011-11-18 22:45:36132 // Posts |native_event| to the platform's event queue.
133 void PostNativeEvent(const base::NativeEvent& native_event);
134
[email protected]99f07e02011-12-07 00:02:59135 // Converts |point| from the root window's coordinate system to native
136 // screen's.
[email protected]ace7ca02011-11-22 21:34:17137 void ConvertPointToNativeScreen(gfx::Point* point) const;
138
[email protected]4def0e692011-10-19 14:11:09139 // Capture -------------------------------------------------------------------
140
[email protected]114bfbd2011-10-18 21:20:24141 // 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]ea2a867a2011-10-26 17:41:33147 // Overridden from Window:
[email protected]57519062011-10-21 18:28:15148 virtual void SetTransform(const ui::Transform& transform) OVERRIDE;
149
[email protected]745816be2011-11-22 05:08:30150#if !defined(NDEBUG)
151 // Toggles the host's full screen state.
152 void ToggleFullScreen();
153#endif
154
[email protected]912b6f32012-01-19 00:48:01155 // Provided only for testing:
156 void SetGestureRecognizerForTesting(GestureRecognizer* gr) {
157 gesture_recognizer_ = gr;
158 }
159
[email protected]6e456882011-12-06 07:42:51160 // Overridden from ui::CompositorDelegate:
[email protected]e0d22e82012-01-04 00:46:57161 virtual void ScheduleDraw() OVERRIDE;
[email protected]6e456882011-12-06 07:42:51162
[email protected]81585f32011-07-29 19:32:06163 private:
[email protected]99f07e02011-12-07 00:02:59164 RootWindow();
165 virtual ~RootWindow();
[email protected]c06186d2011-11-23 06:58:59166
[email protected]114bfbd2011-10-18 21:20:24167 // 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]ea2a867a2011-10-26 17:41:33171 bool ProcessMouseEvent(Window* target, MouseEvent* event);
172 bool ProcessKeyEvent(Window* target, KeyEvent* event);
173 ui::TouchStatus ProcessTouchEvent(Window* target, TouchEvent* event);
[email protected]538f9562012-01-17 17:46:04174 ui::GestureStatus ProcessGestureEvent(Window* target, GestureEvent* event);
[email protected]ea2a867a2011-10-26 17:41:33175
[email protected]114bfbd2011-10-18 21:20:24176 // Overridden from Window:
177 virtual bool CanFocus() const OVERRIDE;
[email protected]1128681f2012-01-13 03:15:40178 virtual bool CanReceiveEvents() const OVERRIDE;
[email protected]114bfbd2011-10-18 21:20:24179 virtual internal::FocusManager* GetFocusManager() OVERRIDE;
[email protected]99f07e02011-12-07 00:02:59180 virtual RootWindow* GetRootWindow() OVERRIDE;
181 virtual void WindowDetachedFromRootWindow(Window* window) OVERRIDE;
[email protected]114bfbd2011-10-18 21:20:24182
[email protected]e876c272011-11-02 16:42:45183 // Overridden from ui::LayerAnimationObserver:
[email protected]fe7074c62011-10-28 15:22:54184 virtual void OnLayerAnimationEnded(
185 const ui::LayerAnimationSequence* animation) OVERRIDE;
[email protected]e876c272011-11-02 16:42:45186 virtual void OnLayerAnimationScheduled(
187 const ui::LayerAnimationSequence* animation) OVERRIDE;
188 virtual void OnLayerAnimationAborted(
189 const ui::LayerAnimationSequence* animation) OVERRIDE;
[email protected]326828b2011-10-21 02:01:10190
[email protected]114bfbd2011-10-18 21:20:24191 // 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]99f07e02011-12-07 00:02:59196 // Initializes the root window.
[email protected]9ed496e2011-10-18 23:47:39197 void Init();
[email protected]87b0d82e2011-10-07 21:02:59198
[email protected]4a14bca92011-10-21 00:09:22199 // 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]81585f32011-07-29 19:32:06203 scoped_refptr<ui::Compositor> compositor_;
204
[email protected]99f07e02011-12-07 00:02:59205 scoped_ptr<RootWindowHost> host_;
[email protected]8d8c7732011-08-25 22:35:13206
[email protected]99f07e02011-12-07 00:02:59207 static RootWindow* instance_;
[email protected]8d8c7732011-08-25 22:35:13208
[email protected]99f07e02011-12-07 00:02:59209 // 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]5978af5e2011-10-24 22:17:18211 // switches::kAuraHostWindowSize flag.
212 static bool use_fullscreen_host_window_;
213
214 // Used to schedule painting.
[email protected]99f07e02011-12-07 00:02:59215 base::WeakPtrFactory<RootWindow> schedule_paint_factory_;
[email protected]5978af5e2011-10-24 22:17:18216
[email protected]896728e2011-10-14 00:41:26217 // Last location seen in a mouse event.
218 gfx::Point last_mouse_location_;
219
[email protected]bf74dd82011-11-11 21:36:41220 // ui::EventFlags containing the current state of the mouse buttons.
221 int mouse_button_flags_;
222
[email protected]912be0e2011-11-09 19:05:24223 // Last cursor set. Used for testing.
224 gfx::NativeCursor last_cursor_;
225
[email protected]99f07e02011-12-07 00:02:59226 ObserverList<RootWindowObserver> observers_;
[email protected]e717ffd2011-10-13 17:15:19227
[email protected]4def0e692011-10-19 14:11:09228 ScreenAura* screen_;
229
[email protected]114bfbd2011-10-18 21:20:24230 // 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]912b6f32012-01-19 00:48:01238 Window* gesture_handler_;
239
240 // The gesture_recognizer_ for this.
241 GestureRecognizer* gesture_recognizer_;
[email protected]114bfbd2011-10-18 21:20:24242
[email protected]99f07e02011-12-07 00:02:59243 DISALLOW_COPY_AND_ASSIGN(RootWindow);
[email protected]81585f32011-07-29 19:32:06244};
245
246} // namespace aura
247
[email protected]99f07e02011-12-07 00:02:59248#endif // UI_AURA_ROOT_WINDOW_H_