blob: 40963f4de36c1445adf174a11e9807769acaaf65 [file] [log] [blame]
[email protected]81585f32011-07-29 19:32:061// Copyright (c) 2011 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.
4
[email protected]f94f0f12011-09-14 21:14:015#ifndef UI_AURA_DESKTOP_H_
6#define UI_AURA_DESKTOP_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]905e19a2011-09-07 02:17:5313#include "base/task.h"
[email protected]f94f0f12011-09-14 21:14:0114#include "ui/aura/aura_export.h"
[email protected]70ccf702011-09-22 18:15:5815#include "ui/aura/cursor.h"
[email protected]114bfbd2011-10-18 21:20:2416#include "ui/aura/focus_manager.h"
17#include "ui/aura/window.h"
[email protected]7a05bdc2011-10-04 23:38:3918#include "ui/base/events.h"
[email protected]905e19a2011-09-07 02:17:5319#include "ui/gfx/compositor/compositor.h"
[email protected]e876c272011-11-02 16:42:4520#include "ui/gfx/compositor/layer_animation_observer.h"
[email protected]81585f32011-07-29 19:32:0621#include "ui/gfx/native_widget_types.h"
[email protected]896728e2011-10-14 00:41:2622#include "ui/gfx/point.h"
[email protected]81585f32011-07-29 19:32:0623
24namespace gfx {
25class Size;
26}
27
[email protected]593ddfa2011-10-20 21:51:4328namespace ui {
[email protected]fe7074c62011-10-28 15:22:5429class LayerAnimationSequence;
[email protected]593ddfa2011-10-20 21:51:4330class Transform;
31}
32
[email protected]81585f32011-07-29 19:32:0633namespace aura {
34
[email protected]8d8c7732011-08-25 22:35:1335class DesktopHost;
[email protected]e717ffd2011-10-13 17:15:1936class DesktopObserver;
[email protected]5951806f2011-10-17 16:06:3537class KeyEvent;
[email protected]a83f0f22011-08-23 15:39:1538class MouseEvent;
[email protected]4def0e692011-10-19 14:11:0939class ScreenAura;
[email protected]982348162011-11-09 22:48:5740class StackingClient;
[email protected]5951806f2011-10-17 16:06:3541class TouchEvent;
[email protected]b1b155512011-08-18 22:47:5042
[email protected]81585f32011-07-29 19:32:0643// Desktop is responsible for hosting a set of windows.
[email protected]114bfbd2011-10-18 21:20:2444class AURA_EXPORT Desktop : public ui::CompositorDelegate,
45 public Window,
[email protected]e876c272011-11-02 16:42:4546 public internal::FocusManager,
47 public ui::LayerAnimationObserver {
[email protected]81585f32011-07-29 19:32:0648 public:
[email protected]8d8c7732011-08-25 22:35:1349 Desktop();
[email protected]c4170c982011-10-12 17:03:1350 virtual ~Desktop();
[email protected]81585f32011-07-29 19:32:0651
[email protected]9ed496e2011-10-18 23:47:3952 static Desktop* GetInstance();
53 static void DeleteInstanceForTesting();
54
[email protected]5978af5e2011-10-24 22:17:1855 static void set_use_fullscreen_host_window(bool use_fullscreen) {
56 use_fullscreen_host_window_ = use_fullscreen;
57 }
58
[email protected]9ed496e2011-10-18 23:47:3959 ui::Compositor* compositor() { return compositor_.get(); }
[email protected]896728e2011-10-14 00:41:2660 gfx::Point last_mouse_location() const { return last_mouse_location_; }
[email protected]912be0e2011-11-09 19:05:2461 gfx::NativeCursor last_cursor() const { return last_cursor_; }
[email protected]982348162011-11-09 22:48:5762 StackingClient* stacking_client() { return stacking_client_.get(); }
[email protected]9ed496e2011-10-18 23:47:3963 Window* active_window() { return active_window_; }
64 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]982348162011-11-09 22:48:5768 void SetStackingClient(StackingClient* stacking_client);
[email protected]a91f5192011-09-20 05:42:3769
[email protected]970aa362011-08-30 20:03:3470 // Shows the desktop host.
[email protected]114bfbd2011-10-18 21:20:2471 void ShowDesktop();
[email protected]970aa362011-08-30 20:03:3472
73 // Sets the size of the desktop.
[email protected]114bfbd2011-10-18 21:20:2474 void SetHostSize(const gfx::Size& size);
75 gfx::Size GetHostSize() const;
[email protected]970aa362011-08-30 20:03:3476
[email protected]70ccf702011-09-22 18:15:5877 // Shows the specified cursor.
[email protected]0207c92d2011-10-04 14:45:0778 void SetCursor(gfx::NativeCursor cursor);
[email protected]70ccf702011-09-22 18:15:5879
[email protected]8d8c7732011-08-25 22:35:1380 // Shows the desktop host and runs an event loop for it.
81 void Run();
82
[email protected]81585f32011-07-29 19:32:0683 // Draws the necessary set of windows.
84 void Draw();
85
[email protected]a83f0f22011-08-23 15:39:1586 // Handles a mouse event. Returns true if handled.
[email protected]593ddfa2011-10-20 21:51:4387 bool DispatchMouseEvent(MouseEvent* event);
[email protected]a83f0f22011-08-23 15:39:1588
[email protected]c94f8592011-09-02 20:12:1389 // Handles a key event. Returns true if handled.
[email protected]593ddfa2011-10-20 21:51:4390 bool DispatchKeyEvent(KeyEvent* event);
[email protected]c94f8592011-09-02 20:12:1391
[email protected]5951806f2011-10-17 16:06:3592 // Handles a touch event. Returns true if handled.
[email protected]593ddfa2011-10-20 21:51:4393 bool DispatchTouchEvent(TouchEvent* event);
[email protected]5951806f2011-10-17 16:06:3594
[email protected]7a9f8912011-09-12 21:31:3195 // Called when the host changes size.
96 void OnHostResized(const gfx::Size& size);
97
[email protected]b8b456ce2011-09-27 00:19:1398 // Sets the active window to |window| and the focused window to |to_focus|.
[email protected]f4b96e202011-11-15 18:07:5099 // If |to_focus| is NULL, |window| is focused. Does nothing if |window| is
100 // NULL.
[email protected]b8b456ce2011-09-27 00:19:13101 void SetActiveWindow(Window* window, Window* to_focus);
[email protected]b8b456ce2011-09-27 00:19:13102
103 // Activates the topmost window. Does nothing if the topmost window is already
104 // active.
105 void ActivateTopmostWindow();
106
[email protected]ea567c82011-10-07 19:44:08107 // Deactivates |window| and activates the topmost window. Does nothing if
108 // |window| is not a topmost window, or there are no other suitable windows to
109 // activate.
110 void Deactivate(Window* window);
111
[email protected]a54e65b2011-11-21 22:03:34112 // Invoked when |window| is initialized.
113 void WindowInitialized(Window* window);
114
[email protected]114bfbd2011-10-18 21:20:24115 // Invoked when |window| is being destroyed.
[email protected]b8b456ce2011-09-27 00:19:13116 void WindowDestroying(Window* window);
117
[email protected]35e9b66a2011-10-06 18:19:21118 // Returns the desktop's dispatcher. The result should only be passed to
[email protected]4d6285312011-10-24 07:19:51119 // MessageLoopForUI::RunWithDispatcher() or
120 // MessageLoopForUI::RunAllPendingWithDispatcher(), or used to dispatch
121 // an event by |Dispatch(const NativeEvent&)| on it. It must never be stored.
[email protected]35e9b66a2011-10-06 18:19:21122 MessageLoop::Dispatcher* GetDispatcher();
123
[email protected]e717ffd2011-10-13 17:15:19124 // Add/remove observer.
125 void AddObserver(DesktopObserver* observer);
126 void RemoveObserver(DesktopObserver* observer);
127
[email protected]bf74dd82011-11-11 21:36:41128 // Are any mouse buttons currently down?
129 bool IsMouseButtonDown() const;
130
[email protected]b5a18642011-11-18 22:45:36131 // Posts |native_event| to the platform's event queue.
132 void PostNativeEvent(const base::NativeEvent& native_event);
133
[email protected]ace7ca02011-11-22 21:34:17134 // Converts |point| from the desktop's coordinate system to native screen's.
135 void ConvertPointToNativeScreen(gfx::Point* point) const;
136
[email protected]4def0e692011-10-19 14:11:09137 // Capture -------------------------------------------------------------------
138
[email protected]114bfbd2011-10-18 21:20:24139 // Sets capture to the specified window.
140 void SetCapture(Window* window);
141
142 // If |window| has mouse capture, the current capture window is set to NULL.
143 void ReleaseCapture(Window* window);
144
[email protected]ea2a867a2011-10-26 17:41:33145 // Overridden from Window:
[email protected]57519062011-10-21 18:28:15146 virtual void SetTransform(const ui::Transform& transform) OVERRIDE;
147
[email protected]745816be2011-11-22 05:08:30148#if !defined(NDEBUG)
149 // Toggles the host's full screen state.
150 void ToggleFullScreen();
151#endif
152
[email protected]81585f32011-07-29 19:32:06153 private:
[email protected]114bfbd2011-10-18 21:20:24154 // Called whenever the mouse moves, tracks the current |mouse_moved_handler_|,
155 // sending exited and entered events as its value changes.
156 void HandleMouseMoved(const MouseEvent& event, Window* target);
157
[email protected]ea2a867a2011-10-26 17:41:33158 bool ProcessMouseEvent(Window* target, MouseEvent* event);
159 bool ProcessKeyEvent(Window* target, KeyEvent* event);
160 ui::TouchStatus ProcessTouchEvent(Window* target, TouchEvent* event);
161
[email protected]905e19a2011-09-07 02:17:53162 // Overridden from ui::CompositorDelegate
[email protected]870119a2011-09-30 18:13:22163 virtual void ScheduleDraw();
[email protected]905e19a2011-09-07 02:17:53164
[email protected]114bfbd2011-10-18 21:20:24165 // Overridden from Window:
166 virtual bool CanFocus() const OVERRIDE;
167 virtual internal::FocusManager* GetFocusManager() OVERRIDE;
168 virtual Desktop* GetDesktop() OVERRIDE;
[email protected]ca163e02011-11-10 17:06:27169 virtual void WindowDetachedFromDesktop(Window* window) OVERRIDE;
[email protected]114bfbd2011-10-18 21:20:24170
[email protected]e876c272011-11-02 16:42:45171 // Overridden from ui::LayerAnimationObserver:
[email protected]fe7074c62011-10-28 15:22:54172 virtual void OnLayerAnimationEnded(
173 const ui::LayerAnimationSequence* animation) OVERRIDE;
[email protected]e876c272011-11-02 16:42:45174 virtual void OnLayerAnimationScheduled(
175 const ui::LayerAnimationSequence* animation) OVERRIDE;
176 virtual void OnLayerAnimationAborted(
177 const ui::LayerAnimationSequence* animation) OVERRIDE;
[email protected]326828b2011-10-21 02:01:10178
[email protected]114bfbd2011-10-18 21:20:24179 // Overridden from FocusManager:
180 virtual void SetFocusedWindow(Window* window) OVERRIDE;
181 virtual Window* GetFocusedWindow() OVERRIDE;
182 virtual bool IsFocusedWindow(const Window* window) const OVERRIDE;
183
[email protected]9ed496e2011-10-18 23:47:39184 // Initializes the desktop.
185 void Init();
[email protected]87b0d82e2011-10-07 21:02:59186
[email protected]4a14bca92011-10-21 00:09:22187 // Parses the switch describing the initial size for the host window and
188 // returns bounds for the window.
189 gfx::Rect GetInitialHostWindowBounds() const;
190
[email protected]81585f32011-07-29 19:32:06191 scoped_refptr<ui::Compositor> compositor_;
192
[email protected]658600e2011-09-07 21:16:21193 scoped_ptr<DesktopHost> host_;
[email protected]8d8c7732011-08-25 22:35:13194
[email protected]982348162011-11-09 22:48:57195 scoped_ptr<StackingClient> stacking_client_;
[email protected]9ed496e2011-10-18 23:47:39196
[email protected]8d8c7732011-08-25 22:35:13197 static Desktop* instance_;
198
[email protected]5978af5e2011-10-24 22:17:18199 // If set before the Desktop is created, the host window will cover the entire
200 // screen. Note that this can still be overridden via the
201 // switches::kAuraHostWindowSize flag.
202 static bool use_fullscreen_host_window_;
203
204 // Used to schedule painting.
205 base::WeakPtrFactory<Desktop> schedule_paint_factory_;
206
[email protected]b8b456ce2011-09-27 00:19:13207 Window* active_window_;
208
[email protected]896728e2011-10-14 00:41:26209 // Last location seen in a mouse event.
210 gfx::Point last_mouse_location_;
211
[email protected]bf74dd82011-11-11 21:36:41212 // ui::EventFlags containing the current state of the mouse buttons.
213 int mouse_button_flags_;
214
[email protected]912be0e2011-11-09 19:05:24215 // Last cursor set. Used for testing.
216 gfx::NativeCursor last_cursor_;
217
[email protected]b8b456ce2011-09-27 00:19:13218 // Are we in the process of being destroyed? Used to avoid processing during
219 // destruction.
220 bool in_destructor_;
221
[email protected]e717ffd2011-10-13 17:15:19222 ObserverList<DesktopObserver> observers_;
223
[email protected]4def0e692011-10-19 14:11:09224 ScreenAura* screen_;
225
[email protected]114bfbd2011-10-18 21:20:24226 // The capture window. When not-null, this window receives all the mouse and
227 // touch events.
228 Window* capture_window_;
229
230 Window* mouse_pressed_handler_;
231 Window* mouse_moved_handler_;
232 Window* focused_window_;
233 Window* touch_event_handler_;
234
[email protected]81585f32011-07-29 19:32:06235 DISALLOW_COPY_AND_ASSIGN(Desktop);
236};
237
238} // namespace aura
239
[email protected]f94f0f12011-09-14 21:14:01240#endif // UI_AURA_DESKTOP_H_