| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "services/ui/ws/focus_controller.h" | 5 #include "services/ui/ws/focus_controller.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "services/ui/public/interfaces/window_manager.mojom.h" | 8 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 9 #include "services/ui/ws/focus_controller_delegate.h" | 9 #include "services/ui/ws/focus_controller_delegate.h" |
| 10 #include "services/ui/ws/focus_controller_observer.h" | 10 #include "services/ui/ws/focus_controller_observer.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 } else if (activation_reason_ != ActivationChangeReason::CYCLE) { | 141 } else if (activation_reason_ != ActivationChangeReason::CYCLE) { |
| 142 DCHECK(!cycle_windows_); | 142 DCHECK(!cycle_windows_); |
| 143 cycle_windows_ = base::MakeUnique<ServerWindowTracker>(); | 143 cycle_windows_ = base::MakeUnique<ServerWindowTracker>(); |
| 144 if (active_window_) | 144 if (active_window_) |
| 145 cycle_windows_->Add(active_window_); | 145 cycle_windows_->Add(active_window_); |
| 146 } | 146 } |
| 147 | 147 |
| 148 ServerWindow* old_active = active_window_; | 148 ServerWindow* old_active = active_window_; |
| 149 active_window_ = window; | 149 active_window_ = window; |
| 150 activation_reason_ = reason; | 150 activation_reason_ = reason; |
| 151 FOR_EACH_OBSERVER(FocusControllerObserver, observers_, | 151 for (auto& observer : observers_) |
| 152 OnActivationChanged(old_active, active_window_)); | 152 observer.OnActivationChanged(old_active, active_window_); |
| 153 if (active_window_ && activation_reason_ == ActivationChangeReason::CYCLE) | 153 if (active_window_ && activation_reason_ == ActivationChangeReason::CYCLE) |
| 154 cycle_windows_->Add(active_window_); | 154 cycle_windows_->Add(active_window_); |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool FocusController::CanBeFocused(ServerWindow* window) const { | 157 bool FocusController::CanBeFocused(ServerWindow* window) const { |
| 158 // All ancestors of |window| must be drawn, and be focusable. | 158 // All ancestors of |window| must be drawn, and be focusable. |
| 159 for (ServerWindow* w = window; w; w = w->parent()) { | 159 for (ServerWindow* w = window; w; w = w->parent()) { |
| 160 if (!w->IsDrawn()) | 160 if (!w->IsDrawn()) |
| 161 return false; | 161 return false; |
| 162 if (!w->can_focus()) | 162 if (!w->can_focus()) |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 ServerWindow* old_focused = GetFocusedWindow(); | 216 ServerWindow* old_focused = GetFocusedWindow(); |
| 217 | 217 |
| 218 DCHECK(!window || window->IsDrawn()); | 218 DCHECK(!window || window->IsDrawn()); |
| 219 | 219 |
| 220 // Activate the closest activatable ancestor window. | 220 // Activate the closest activatable ancestor window. |
| 221 // TODO(sad): The window to activate doesn't necessarily have to be a direct | 221 // TODO(sad): The window to activate doesn't necessarily have to be a direct |
| 222 // ancestor (e.g. could be a transient parent). | 222 // ancestor (e.g. could be a transient parent). |
| 223 SetActiveWindow(GetActivatableAncestorOf(window), | 223 SetActiveWindow(GetActivatableAncestorOf(window), |
| 224 ActivationChangeReason::FOCUS); | 224 ActivationChangeReason::FOCUS); |
| 225 | 225 |
| 226 FOR_EACH_OBSERVER(FocusControllerObserver, observers_, | 226 for (auto& observer : observers_) |
| 227 OnFocusChanged(change_source, old_focused, window)); | 227 observer.OnFocusChanged(change_source, old_focused, window); |
| 228 | 228 |
| 229 focused_window_ = window; | 229 focused_window_ = window; |
| 230 // We can currently use only a single ServerWindowDrawnTracker since focused | 230 // We can currently use only a single ServerWindowDrawnTracker since focused |
| 231 // window is expected to be a direct descendant of the active window. | 231 // window is expected to be a direct descendant of the active window. |
| 232 if (focused_window_ && active_window_) { | 232 if (focused_window_ && active_window_) { |
| 233 DCHECK(active_window_->Contains(focused_window_)); | 233 DCHECK(active_window_->Contains(focused_window_)); |
| 234 } | 234 } |
| 235 ServerWindow* track_window = focused_window_; | 235 ServerWindow* track_window = focused_window_; |
| 236 if (!track_window) | 236 if (!track_window) |
| 237 track_window = active_window_; | 237 track_window = active_window_; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 } | 304 } |
| 305 | 305 |
| 306 void FocusController::OnDrawnStateChanged(ServerWindow* ancestor, | 306 void FocusController::OnDrawnStateChanged(ServerWindow* ancestor, |
| 307 ServerWindow* window, | 307 ServerWindow* window, |
| 308 bool is_drawn) { | 308 bool is_drawn) { |
| 309 // DCHECK(false); TODO(sadrul): | 309 // DCHECK(false); TODO(sadrul): |
| 310 } | 310 } |
| 311 | 311 |
| 312 } // namespace ws | 312 } // namespace ws |
| 313 } // namespace ui | 313 } // namespace ui |
| OLD | NEW |