| OLD | NEW |
| 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/wm/core/focus_controller.h" | 5 #include "ui/wm/core/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/client/capture_client.h" | 9 #include "ui/aura/client/capture_client.h" |
| 10 #include "ui/aura/client/focus_change_observer.h" | 10 #include "ui/aura/client/focus_change_observer.h" |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 if (lost_focus) | 237 if (lost_focus) |
| 238 window_tracker.Add(lost_focus); | 238 window_tracker.Add(lost_focus); |
| 239 if (focused_window_ && observer_manager_.IsObserving(focused_window_) && | 239 if (focused_window_ && observer_manager_.IsObserving(focused_window_) && |
| 240 focused_window_ != active_window_) { | 240 focused_window_ != active_window_) { |
| 241 observer_manager_.Remove(focused_window_); | 241 observer_manager_.Remove(focused_window_); |
| 242 } | 242 } |
| 243 focused_window_ = window; | 243 focused_window_ = window; |
| 244 if (focused_window_ && !observer_manager_.IsObserving(focused_window_)) | 244 if (focused_window_ && !observer_manager_.IsObserving(focused_window_)) |
| 245 observer_manager_.Add(focused_window_); | 245 observer_manager_.Add(focused_window_); |
| 246 | 246 |
| 247 FOR_EACH_OBSERVER(aura::client::FocusChangeObserver, | 247 for (auto& observer : focus_observers_) { |
| 248 focus_observers_, | 248 observer.OnWindowFocused( |
| 249 OnWindowFocused(focused_window_, | 249 focused_window_, |
| 250 window_tracker.Contains(lost_focus) ? | 250 window_tracker.Contains(lost_focus) ? lost_focus : NULL); |
| 251 lost_focus : NULL)); | 251 } |
| 252 if (window_tracker.Contains(lost_focus)) { | 252 if (window_tracker.Contains(lost_focus)) { |
| 253 aura::client::FocusChangeObserver* observer = | 253 aura::client::FocusChangeObserver* observer = |
| 254 aura::client::GetFocusChangeObserver(lost_focus); | 254 aura::client::GetFocusChangeObserver(lost_focus); |
| 255 if (observer) | 255 if (observer) |
| 256 observer->OnWindowFocused(focused_window_, lost_focus); | 256 observer->OnWindowFocused(focused_window_, lost_focus); |
| 257 } | 257 } |
| 258 aura::client::FocusChangeObserver* observer = | 258 aura::client::FocusChangeObserver* observer = |
| 259 aura::client::GetFocusChangeObserver(focused_window_); | 259 aura::client::GetFocusChangeObserver(focused_window_); |
| 260 if (observer) { | 260 if (observer) { |
| 261 observer->OnWindowFocused( | 261 observer->OnWindowFocused( |
| 262 focused_window_, | 262 focused_window_, |
| 263 window_tracker.Contains(lost_focus) ? lost_focus : NULL); | 263 window_tracker.Contains(lost_focus) ? lost_focus : NULL); |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 | 266 |
| 267 void FocusController::SetActiveWindow( | 267 void FocusController::SetActiveWindow( |
| 268 aura::client::ActivationChangeObserver::ActivationReason reason, | 268 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 269 aura::Window* requested_window, | 269 aura::Window* requested_window, |
| 270 aura::Window* window) { | 270 aura::Window* window) { |
| 271 if (updating_activation_) | 271 if (updating_activation_) |
| 272 return; | 272 return; |
| 273 | 273 |
| 274 if (window == active_window_) { | 274 if (window == active_window_) { |
| 275 if (requested_window) { | 275 if (requested_window) { |
| 276 FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver, | 276 for (auto& observer : activation_observers_) |
| 277 activation_observers_, | 277 observer.OnAttemptToReactivateWindow(requested_window, active_window_); |
| 278 OnAttemptToReactivateWindow(requested_window, | |
| 279 active_window_)); | |
| 280 } | 278 } |
| 281 return; | 279 return; |
| 282 } | 280 } |
| 283 | 281 |
| 284 DCHECK(rules_->CanActivateWindow(window)); | 282 DCHECK(rules_->CanActivateWindow(window)); |
| 285 if (window) | 283 if (window) |
| 286 DCHECK_EQ(window, rules_->GetActivatableWindow(window)); | 284 DCHECK_EQ(window, rules_->GetActivatableWindow(window)); |
| 287 | 285 |
| 288 base::AutoReset<bool> updating_activation(&updating_activation_, true); | 286 base::AutoReset<bool> updating_activation(&updating_activation_, true); |
| 289 aura::Window* lost_activation = active_window_; | 287 aura::Window* lost_activation = active_window_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 307 observer = aura::client::GetActivationChangeObserver(lost_activation); | 305 observer = aura::client::GetActivationChangeObserver(lost_activation); |
| 308 if (observer) | 306 if (observer) |
| 309 observer->OnWindowActivated(reason, active_window_, lost_activation); | 307 observer->OnWindowActivated(reason, active_window_, lost_activation); |
| 310 } | 308 } |
| 311 observer = aura::client::GetActivationChangeObserver(active_window_); | 309 observer = aura::client::GetActivationChangeObserver(active_window_); |
| 312 if (observer) { | 310 if (observer) { |
| 313 observer->OnWindowActivated( | 311 observer->OnWindowActivated( |
| 314 reason, active_window_, | 312 reason, active_window_, |
| 315 window_tracker.Contains(lost_activation) ? lost_activation : NULL); | 313 window_tracker.Contains(lost_activation) ? lost_activation : NULL); |
| 316 } | 314 } |
| 317 FOR_EACH_OBSERVER( | 315 for (auto& observer : activation_observers_) { |
| 318 aura::client::ActivationChangeObserver, activation_observers_, | 316 observer.OnWindowActivated( |
| 319 OnWindowActivated( | 317 reason, active_window_, |
| 320 reason, active_window_, | 318 window_tracker.Contains(lost_activation) ? lost_activation : NULL); |
| 321 window_tracker.Contains(lost_activation) ? lost_activation : NULL)); | 319 } |
| 322 } | 320 } |
| 323 | 321 |
| 324 void FocusController::StackActiveWindow() { | 322 void FocusController::StackActiveWindow() { |
| 325 if (active_window_) { | 323 if (active_window_) { |
| 326 StackTransientParentsBelowModalWindow(active_window_); | 324 StackTransientParentsBelowModalWindow(active_window_); |
| 327 active_window_->parent()->StackChildAtTop(active_window_); | 325 active_window_->parent()->StackChildAtTop(active_window_); |
| 328 } | 326 } |
| 329 } | 327 } |
| 330 | 328 |
| 331 void FocusController::WindowLostFocusFromDispositionChange( | 329 void FocusController::WindowLostFocusFromDispositionChange( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 354 // FocusWindow() will focus the topmost window, which may not be the | 352 // FocusWindow() will focus the topmost window, which may not be the |
| 355 // currently focused one. | 353 // currently focused one. |
| 356 if (rules_->CanFocusWindow(GetToplevelWindow(window))) { | 354 if (rules_->CanFocusWindow(GetToplevelWindow(window))) { |
| 357 FocusAndActivateWindow( | 355 FocusAndActivateWindow( |
| 358 aura::client::ActivationChangeObserver::ActivationReason::INPUT_EVENT, | 356 aura::client::ActivationChangeObserver::ActivationReason::INPUT_EVENT, |
| 359 window); | 357 window); |
| 360 } | 358 } |
| 361 } | 359 } |
| 362 | 360 |
| 363 } // namespace wm | 361 } // namespace wm |
| OLD | NEW |