blob: aebcb1dd723f95fcc39e9d6f6d3bcd2c968bd243 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_COREWM_FOCUS_CONTROLLER_H_
#define UI_VIEWS_COREWM_FOCUS_CONTROLLER_H_
#include "base/compiler_specific.h"
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/env_observer.h"
#include "ui/aura/window_observer.h"
#include "ui/base/events/event_dispatcher.h"
#include "ui/views/views_export.h"
namespace views {
namespace corewm {
class FocusRules;
// FocusController handles focus and activation changes for an environment
// encompassing one or more RootWindows. Within an environment there can be
// only one focused and one active window at a time. When focus or activation
// changes a FocusChangeEvent is dispatched.
// Changes to focus and activation can be from three sources:
// . the Aura Client API (implemented here in aura::client::ActivationClient).
// (The FocusController must be set as the ActivationClient implementation
// for all RootWindows).
// . input events (implemented here in ui::EventHandler).
// (The FocusController must be registered as a pre-target handler for
// the applicable environment owner, either a RootWindow or another type).
// . Window disposition changes (implemented here in aura::WindowObserver).
// (The FocusController registers itself as an observer of the active and
// focused windows).
class VIEWS_EXPORT FocusController : public aura::client::ActivationClient,
public aura::client::FocusClient,
public ui::EventHandler,
public aura::WindowObserver,
public aura::EnvObserver,
public ui::EventDispatcher {
public:
// |rules| cannot be NULL.
explicit FocusController(FocusRules* rules);
virtual ~FocusController();
private:
// Overridden from aura::client::ActivationClient:
virtual void AddObserver(
aura::client::ActivationChangeObserver* observer) OVERRIDE;
virtual void RemoveObserver(
aura::client::ActivationChangeObserver* observer) OVERRIDE;
virtual void ActivateWindow(aura::Window* window) OVERRIDE;
virtual void DeactivateWindow(aura::Window* window) OVERRIDE;
virtual aura::Window* GetActiveWindow() OVERRIDE;
virtual aura::Window* GetActivatableWindow(aura::Window* window) OVERRIDE;
virtual bool OnWillFocusWindow(aura::Window* window,
const ui::Event* event) OVERRIDE;
virtual bool CanActivateWindow(aura::Window* window) const OVERRIDE;
// Overridden from aura::client::FocusClient:
virtual void AddObserver(
aura::client::FocusChangeObserver* observer) OVERRIDE;
virtual void RemoveObserver(
aura::client::FocusChangeObserver* observer) OVERRIDE;
virtual void FocusWindow(aura::Window* window,
const ui::Event* event) OVERRIDE;
virtual aura::Window* GetFocusedWindow() OVERRIDE;
// Overridden from ui::EventHandler:
virtual ui::EventResult OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
virtual ui::EventResult OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
virtual ui::EventResult OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
virtual ui::EventResult OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
virtual ui::EventResult OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
// Overridden from aura::WindowObserver:
virtual void OnWindowVisibilityChanging(aura::Window* window,
bool visible) OVERRIDE;
virtual void OnWindowDestroying(aura::Window* window) OVERRIDE;
virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE;
virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE;
// Overridden from aura::EnvObserver:
virtual void OnWindowInitialized(aura::Window* window) OVERRIDE;
// Overridden from ui::EventDispatcher:
virtual bool CanDispatchToTarget(ui::EventTarget* target) OVERRIDE;
// Internal implementations that set the focused/active windows, fire events
// etc. These functions must be called with valid focusable/activatable
// windows.
void SetFocusedWindow(aura::Window* window);
void SetActiveWindow(aura::Window* window);
// Called when a window's disposition changed such that it and its hierarchy
// are no longer focusable/activatable. The system must determine what window
// to focus next based on rules.
void WindowLostFocusFromDispositionChange(aura::Window* window);
// Called when an attempt is made to focus or activate a window via an input
// event targeted at that window. Rules determine the best focusable window
// for the input window.
void WindowFocusedFromInputEvent(aura::Window* window);
aura::Window* active_window_;
aura::Window* focused_window_;
ui::EventTarget* event_dispatch_target_;
scoped_ptr<FocusRules> rules_;
DISALLOW_COPY_AND_ASSIGN(FocusController);
};
} // namespace corewm
} // namespace views
#endif // UI_VIEWS_COREWM_FOCUS_CONTROLLER_H_
|