Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1204)

Side by Side Diff: ui/views/corewm/focus_controller.cc

Issue 11421194: Hook up the FocusController behind a flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/corewm/focus_controller.h ('k') | ui/views/corewm/focus_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/corewm/focus_controller.h" 5 #include "ui/views/corewm/focus_controller.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "ui/aura/client/aura_constants.h" 8 #include "ui/aura/client/aura_constants.h"
9 #include "ui/aura/env.h" 9 #include "ui/aura/env.h"
10 #include "ui/views/corewm/focus_change_event.h" 10 #include "ui/views/corewm/focus_change_event.h"
(...skipping 27 matching lines...) Expand all
38 ui::EventTarget** event_dispatch_target) { 38 ui::EventTarget** event_dispatch_target) {
39 int result = ui::ER_UNHANDLED; 39 int result = ui::ER_UNHANDLED;
40 { 40 {
41 base::AutoReset<ui::EventTarget*> reset(event_dispatch_target, *state); 41 base::AutoReset<ui::EventTarget*> reset(event_dispatch_target, *state);
42 FocusChangeEvent changing_event(changing_event_type); 42 FocusChangeEvent changing_event(changing_event_type);
43 result = dispatcher->ProcessEvent(*state, &changing_event); 43 result = dispatcher->ProcessEvent(*state, &changing_event);
44 } 44 }
45 DCHECK(!(result & ui::ER_CONSUMED)) 45 DCHECK(!(result & ui::ER_CONSUMED))
46 << "Focus and Activation events cannot be consumed"; 46 << "Focus and Activation events cannot be consumed";
47 47
48 aura::Window* lost_active = *state;
48 *state = new_state; 49 *state = new_state;
49 50
50 if (restack && new_state) { 51 if (restack && new_state) {
51 StackTransientParentsBelowModalWindow(new_state); 52 StackTransientParentsBelowModalWindow(new_state);
52 new_state->parent()->StackChildAtTop(new_state); 53 new_state->parent()->StackChildAtTop(new_state);
53 } 54 }
54 55
55 { 56 {
56 base::AutoReset<ui::EventTarget*> reset(event_dispatch_target, *state); 57 base::AutoReset<ui::EventTarget*> reset(event_dispatch_target, *state);
57 FocusChangeEvent changed_event(changed_event_type); 58 FocusChangeEvent changed_event(changed_event_type);
59 FocusChangeEvent::DispatcherApi(&changed_event).set_last_focus(lost_active);
58 dispatcher->ProcessEvent(*state, &changed_event); 60 dispatcher->ProcessEvent(*state, &changed_event);
59 } 61 }
60 } 62 }
61 63
62 } // namespace 64 } // namespace
63 65
64 //////////////////////////////////////////////////////////////////////////////// 66 ////////////////////////////////////////////////////////////////////////////////
65 // FocusController, public: 67 // FocusController, public:
66 68
67 FocusController::FocusController(FocusRules* rules) 69 FocusController::FocusController(FocusRules* rules)
68 : active_window_(NULL), 70 : active_window_(NULL),
69 focused_window_(NULL), 71 focused_window_(NULL),
70 event_dispatch_target_(NULL), 72 event_dispatch_target_(NULL),
71 rules_(rules) { 73 rules_(rules) {
72 DCHECK(rules); 74 DCHECK(rules);
73 FocusChangeEvent::RegisterEventTypes(); 75 FocusChangeEvent::RegisterEventTypes();
74 aura::Env::GetInstance()->AddObserver(this); 76 aura::Env::GetInstance()->AddObserver(this);
75 } 77 }
76 78
77 FocusController::~FocusController() { 79 FocusController::~FocusController() {
78 aura::Env::GetInstance()->RemoveObserver(this); 80 aura::Env::GetInstance()->RemoveObserver(this);
79 } 81 }
80 82
81 void FocusController::FocusWindow(aura::Window* window) {
82 // Focusing a window also activates its containing activatable window. Note
83 // that the rules could redirect activation activation and/or focus.
84 aura::Window* focusable = rules_->GetFocusableWindow(window);
85 SetActiveWindow(rules_->GetActivatableWindow(focusable));
86 DCHECK(GetActiveWindow()->Contains(focusable));
87 SetFocusedWindow(focusable);
88 }
89
90 //////////////////////////////////////////////////////////////////////////////// 83 ////////////////////////////////////////////////////////////////////////////////
91 // FocusController, aura::client::ActivationClient implementation: 84 // FocusController, aura::client::ActivationClient implementation:
92 85
93 void FocusController::AddObserver( 86 void FocusController::AddObserver(
94 aura::client::ActivationChangeObserver* observer) { 87 aura::client::ActivationChangeObserver* observer) {
95 NOTREACHED(); 88 //NOTREACHED();
96 } 89 }
97 90
98 void FocusController::RemoveObserver( 91 void FocusController::RemoveObserver(
99 aura::client::ActivationChangeObserver* observer) { 92 aura::client::ActivationChangeObserver* observer) {
100 NOTREACHED(); 93 //NOTREACHED();
101 } 94 }
102 95
103 void FocusController::ActivateWindow(aura::Window* window) { 96 void FocusController::ActivateWindow(aura::Window* window) {
104 FocusWindow(window); 97 FocusWindow(window, NULL);
105 } 98 }
106 99
107 void FocusController::DeactivateWindow(aura::Window* window) { 100 void FocusController::DeactivateWindow(aura::Window* window) {
108 FocusWindow(rules_->GetNextActivatableWindow(window)); 101 FocusWindow(rules_->GetNextActivatableWindow(window), NULL);
109 } 102 }
110 103
111 aura::Window* FocusController::GetActiveWindow() { 104 aura::Window* FocusController::GetActiveWindow() {
112 return active_window_; 105 return active_window_;
113 } 106 }
114 107
115 aura::Window* FocusController::GetActivatableWindow(aura::Window* window) { 108 aura::Window* FocusController::GetActivatableWindow(aura::Window* window) {
116 return rules_->GetActivatableWindow(window); 109 return rules_->GetActivatableWindow(window);
117 } 110 }
118 111
119 bool FocusController::OnWillFocusWindow(aura::Window* window, 112 bool FocusController::OnWillFocusWindow(aura::Window* window,
120 const ui::Event* event) { 113 const ui::Event* event) {
121 NOTREACHED(); 114 NOTREACHED();
122 return false; 115 return false;
123 } 116 }
124 117
125 bool FocusController::CanActivateWindow(aura::Window* window) const { 118 bool FocusController::CanActivateWindow(aura::Window* window) const {
126 return rules_->CanActivateWindow(window); 119 return rules_->CanActivateWindow(window);
127 } 120 }
128 121
129 //////////////////////////////////////////////////////////////////////////////// 122 ////////////////////////////////////////////////////////////////////////////////
123 // FocusController, aura::client::FocusClient implementation:
124
125 void FocusController::AddObserver(
126 aura::client::FocusChangeObserver* observer) {
127 //NOTREACHED();
128 }
129
130 void FocusController::RemoveObserver(
131 aura::client::FocusChangeObserver* observer) {
132 //NOTREACHED();
133 }
134
135 void FocusController::FocusWindow(aura::Window* window,
136 const ui::Event* event) {
137 // Focusing a window also activates its containing activatable window. Note
138 // that the rules could redirect activation activation and/or focus.
139 aura::Window* focusable = rules_->GetFocusableWindow(window);
140 SetActiveWindow(rules_->GetActivatableWindow(focusable));
141 DCHECK(GetActiveWindow()->Contains(focusable));
142 SetFocusedWindow(focusable);
143 }
144
145 aura::Window* FocusController::GetFocusedWindow() {
146 return focused_window_;
147 }
148
149 ////////////////////////////////////////////////////////////////////////////////
130 // FocusController, ui::EventHandler implementation: 150 // FocusController, ui::EventHandler implementation:
131 ui::EventResult FocusController::OnKeyEvent(ui::KeyEvent* event) { 151 ui::EventResult FocusController::OnKeyEvent(ui::KeyEvent* event) {
132 return ui::ER_UNHANDLED; 152 return ui::ER_UNHANDLED;
133 } 153 }
134 154
135 ui::EventResult FocusController::OnMouseEvent(ui::MouseEvent* event) { 155 ui::EventResult FocusController::OnMouseEvent(ui::MouseEvent* event) {
136 if (event->type() == ui::ET_MOUSE_PRESSED) 156 if (event->type() == ui::ET_MOUSE_PRESSED)
137 WindowFocusedFromInputEvent(static_cast<aura::Window*>(event->target())); 157 WindowFocusedFromInputEvent(static_cast<aura::Window*>(event->target()));
138 return ui::ER_UNHANDLED; 158 return ui::ER_UNHANDLED;
139 } 159 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 aura::Window* next_activatable = rules_->GetNextActivatableWindow(window); 255 aura::Window* next_activatable = rules_->GetNextActivatableWindow(window);
236 SetActiveWindow(next_activatable); 256 SetActiveWindow(next_activatable);
237 SetFocusedWindow(next_activatable); 257 SetFocusedWindow(next_activatable);
238 } else if (window->Contains(focused_window_)) { 258 } else if (window->Contains(focused_window_)) {
239 // Active window isn't changing, but focused window might be. 259 // Active window isn't changing, but focused window might be.
240 SetFocusedWindow(rules_->GetNextFocusableWindow(window)); 260 SetFocusedWindow(rules_->GetNextFocusableWindow(window));
241 } 261 }
242 } 262 }
243 263
244 void FocusController::WindowFocusedFromInputEvent(aura::Window* window) { 264 void FocusController::WindowFocusedFromInputEvent(aura::Window* window) {
245 FocusWindow(window); 265 FocusWindow(window, NULL);
246 } 266 }
247 267
248 } // namespace corewm 268 } // namespace corewm
249 } // namespace views 269 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/corewm/focus_controller.h ('k') | ui/views/corewm/focus_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698