base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / wm / core / focus_controller.h
blob43d3c608b2138493f070bce4150b24a073edca58
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_WM_CORE_FOCUS_CONTROLLER_H_
6 #define UI_WM_CORE_FOCUS_CONTROLLER_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/observer_list.h"
11 #include "base/scoped_observer.h"
12 #include "ui/aura/client/focus_client.h"
13 #include "ui/aura/window_observer.h"
14 #include "ui/events/event_handler.h"
15 #include "ui/wm/public/activation_client.h"
16 #include "ui/wm/wm_export.h"
18 namespace wm {
20 class FocusRules;
22 // FocusController handles focus and activation changes for an environment
23 // encompassing one or more RootWindows. Within an environment there can be
24 // only one focused and one active window at a time. When focus or activation
25 // changes notifications are sent using the
26 // aura::client::Focus/ActivationChangeObserver interfaces.
27 // Changes to focus and activation can be from three sources:
28 // . the Aura Client API (implemented here in aura::client::ActivationClient).
29 // (The FocusController must be set as the ActivationClient implementation
30 // for all RootWindows).
31 // . input events (implemented here in ui::EventHandler).
32 // (The FocusController must be registered as a pre-target handler for
33 // the applicable environment owner, either a RootWindow or another type).
34 // . Window disposition changes (implemented here in aura::WindowObserver).
35 // (The FocusController registers itself as an observer of the active and
36 // focused windows).
37 class WM_EXPORT FocusController : public aura::client::ActivationClient,
38 public aura::client::FocusClient,
39 public ui::EventHandler,
40 public aura::WindowObserver {
41 public:
42 // |rules| cannot be NULL.
43 explicit FocusController(FocusRules* rules);
44 ~FocusController() override;
46 private:
47 // Overridden from aura::client::ActivationClient:
48 void AddObserver(aura::client::ActivationChangeObserver* observer) override;
49 void RemoveObserver(
50 aura::client::ActivationChangeObserver* observer) override;
51 void ActivateWindow(aura::Window* window) override;
52 void DeactivateWindow(aura::Window* window) override;
53 aura::Window* GetActiveWindow() override;
54 aura::Window* GetActivatableWindow(aura::Window* window) override;
55 aura::Window* GetToplevelWindow(aura::Window* window) override;
56 bool CanActivateWindow(aura::Window* window) const override;
58 // Overridden from aura::client::FocusClient:
59 void AddObserver(aura::client::FocusChangeObserver* observer) override;
60 void RemoveObserver(aura::client::FocusChangeObserver* observer) override;
61 void FocusWindow(aura::Window* window) override;
62 void ResetFocusWithinActiveWindow(aura::Window* window) override;
63 aura::Window* GetFocusedWindow() override;
65 // Overridden from ui::EventHandler:
66 void OnKeyEvent(ui::KeyEvent* event) override;
67 void OnMouseEvent(ui::MouseEvent* event) override;
68 void OnScrollEvent(ui::ScrollEvent* event) override;
69 void OnTouchEvent(ui::TouchEvent* event) override;
70 void OnGestureEvent(ui::GestureEvent* event) override;
72 // Overridden from aura::WindowObserver:
73 void OnWindowVisibilityChanged(aura::Window* window, bool visible) override;
74 void OnWindowDestroying(aura::Window* window) override;
75 void OnWindowHierarchyChanging(const HierarchyChangeParams& params) override;
76 void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override;
78 // Internal implementation that sets the focused window, fires events etc.
79 // This function must be called with a valid focusable window.
80 void SetFocusedWindow(aura::Window* window);
82 // Internal implementation that sets the active window, fires events etc.
83 // This function must be called with a valid |activatable_window|.
84 // |requested window| refers to the window that was passed in to an external
85 // request (e.g. FocusWindow or ActivateWindow). It may be NULL, e.g. if
86 // SetActiveWindow was not called by an external request. |activatable_window|
87 // refers to the actual window to be activated, which may be different.
88 void SetActiveWindow(aura::Window* requested_window,
89 aura::Window* activatable_window);
91 // Called when a window's disposition changed such that it and its hierarchy
92 // are no longer focusable/activatable. |next| is a valid window that is used
93 // as a starting point for finding a window to focus next based on rules.
94 void WindowLostFocusFromDispositionChange(aura::Window* window,
95 aura::Window* next);
97 // Called when an attempt is made to focus or activate a window via an input
98 // event targeted at that window. Rules determine the best focusable window
99 // for the input window.
100 void WindowFocusedFromInputEvent(aura::Window* window);
102 aura::Window* active_window_;
103 aura::Window* focused_window_;
105 bool updating_focus_;
106 bool updating_activation_;
108 scoped_ptr<FocusRules> rules_;
110 ObserverList<aura::client::ActivationChangeObserver> activation_observers_;
111 ObserverList<aura::client::FocusChangeObserver> focus_observers_;
113 ScopedObserver<aura::Window, aura::WindowObserver> observer_manager_;
115 DISALLOW_COPY_AND_ASSIGN(FocusController);
118 } // namespace wm
120 #endif // UI_WM_CORE_FOCUS_CONTROLLER_H_