| 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 "components/mus/ws/focus_controller.h" | 5 #include "components/mus/ws/focus_controller.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "components/mus/public/interfaces/window_manager.mojom.h" | 8 #include "components/mus/public/interfaces/window_manager.mojom.h" |
| 9 #include "components/mus/ws/focus_controller_delegate.h" | 9 #include "components/mus/ws/focus_controller_delegate.h" |
| 10 #include "components/mus/ws/focus_controller_observer.h" | 10 #include "components/mus/ws/focus_controller_observer.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 focused_window_(nullptr), | 64 focused_window_(nullptr), |
| 65 active_window_(nullptr), | 65 active_window_(nullptr), |
| 66 activation_reason_(ActivationChangeReason::UNKNONW) { | 66 activation_reason_(ActivationChangeReason::UNKNONW) { |
| 67 DCHECK(delegate_); | 67 DCHECK(delegate_); |
| 68 DCHECK(root_); | 68 DCHECK(root_); |
| 69 } | 69 } |
| 70 | 70 |
| 71 FocusController::~FocusController() { | 71 FocusController::~FocusController() { |
| 72 } | 72 } |
| 73 | 73 |
| 74 void FocusController::SetFocusedWindow(ServerWindow* window) { | 74 bool FocusController::SetFocusedWindow(ServerWindow* window) { |
| 75 if (GetFocusedWindow() == window) | 75 if (GetFocusedWindow() == window) |
| 76 return; | 76 return true; |
| 77 | 77 |
| 78 SetFocusedWindowImpl(FocusControllerChangeSource::EXPLICIT, window); | 78 return SetFocusedWindowImpl(FocusControllerChangeSource::EXPLICIT, window); |
| 79 } | 79 } |
| 80 | 80 |
| 81 ServerWindow* FocusController::GetFocusedWindow() { | 81 ServerWindow* FocusController::GetFocusedWindow() { |
| 82 return focused_window_; | 82 return focused_window_; |
| 83 } | 83 } |
| 84 | 84 |
| 85 void FocusController::ActivateNextWindow() { | 85 void FocusController::ActivateNextWindow() { |
| 86 WindowTreeIterator iter(root_); | 86 WindowTreeIterator iter(root_); |
| 87 ServerWindow* activate = active_window_; | 87 ServerWindow* activate = active_window_; |
| 88 while (true) { | 88 while (true) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 200 |
| 201 ServerWindow* FocusController::GetActivatableAncestorOf( | 201 ServerWindow* FocusController::GetActivatableAncestorOf( |
| 202 ServerWindow* window) const { | 202 ServerWindow* window) const { |
| 203 for (ServerWindow* w = window; w; w = w->parent()) { | 203 for (ServerWindow* w = window; w; w = w->parent()) { |
| 204 if (CanBeActivated(w)) | 204 if (CanBeActivated(w)) |
| 205 return w; | 205 return w; |
| 206 } | 206 } |
| 207 return nullptr; | 207 return nullptr; |
| 208 } | 208 } |
| 209 | 209 |
| 210 void FocusController::SetFocusedWindowImpl( | 210 bool FocusController::SetFocusedWindowImpl( |
| 211 FocusControllerChangeSource change_source, | 211 FocusControllerChangeSource change_source, |
| 212 ServerWindow* window) { | 212 ServerWindow* window) { |
| 213 if (window && !CanBeFocused(window)) | 213 if (window && !CanBeFocused(window)) |
| 214 return; | 214 return false; |
| 215 |
| 215 ServerWindow* old_focused = GetFocusedWindow(); | 216 ServerWindow* old_focused = GetFocusedWindow(); |
| 216 | 217 |
| 217 DCHECK(!window || window->IsDrawn()); | 218 DCHECK(!window || window->IsDrawn()); |
| 218 | 219 |
| 219 // Activate the closest activatable ancestor window. | 220 // Activate the closest activatable ancestor window. |
| 220 // 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 |
| 221 // ancestor (e.g. could be a transient parent). | 222 // ancestor (e.g. could be a transient parent). |
| 222 SetActiveWindow(GetActivatableAncestorOf(window), | 223 SetActiveWindow(GetActivatableAncestorOf(window), |
| 223 ActivationChangeReason::FOCUS); | 224 ActivationChangeReason::FOCUS); |
| 224 | 225 |
| 225 FOR_EACH_OBSERVER(FocusControllerObserver, observers_, | 226 FOR_EACH_OBSERVER(FocusControllerObserver, observers_, |
| 226 OnFocusChanged(change_source, old_focused, window)); | 227 OnFocusChanged(change_source, old_focused, window)); |
| 227 | 228 |
| 228 focused_window_ = window; | 229 focused_window_ = window; |
| 229 // We can currently use only a single ServerWindowDrawnTracker since focused | 230 // We can currently use only a single ServerWindowDrawnTracker since focused |
| 230 // 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. |
| 231 if (focused_window_ && active_window_) { | 232 if (focused_window_ && active_window_) { |
| 232 DCHECK(active_window_->Contains(focused_window_)); | 233 DCHECK(active_window_->Contains(focused_window_)); |
| 233 } | 234 } |
| 234 ServerWindow* track_window = focused_window_; | 235 ServerWindow* track_window = focused_window_; |
| 235 if (!track_window) | 236 if (!track_window) |
| 236 track_window = active_window_; | 237 track_window = active_window_; |
| 237 if (track_window) | 238 if (track_window) |
| 238 drawn_tracker_.reset(new ServerWindowDrawnTracker(track_window, this)); | 239 drawn_tracker_.reset(new ServerWindowDrawnTracker(track_window, this)); |
| 239 else | 240 else |
| 240 drawn_tracker_.reset(); | 241 drawn_tracker_.reset(); |
| 242 return true; |
| 241 } | 243 } |
| 242 | 244 |
| 243 void FocusController::OnDrawnStateWillChange(ServerWindow* ancestor, | 245 void FocusController::OnDrawnStateWillChange(ServerWindow* ancestor, |
| 244 ServerWindow* window, | 246 ServerWindow* window, |
| 245 bool is_drawn) { | 247 bool is_drawn) { |
| 246 DCHECK(!is_drawn); | 248 DCHECK(!is_drawn); |
| 247 DCHECK_NE(ancestor, window); | 249 DCHECK_NE(ancestor, window); |
| 248 DCHECK(root_->Contains(window)); | 250 DCHECK(root_->Contains(window)); |
| 249 drawn_tracker_.reset(); | 251 drawn_tracker_.reset(); |
| 250 | 252 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 } | 302 } |
| 301 | 303 |
| 302 void FocusController::OnDrawnStateChanged(ServerWindow* ancestor, | 304 void FocusController::OnDrawnStateChanged(ServerWindow* ancestor, |
| 303 ServerWindow* window, | 305 ServerWindow* window, |
| 304 bool is_drawn) { | 306 bool is_drawn) { |
| 305 // DCHECK(false); TODO(sadrul): | 307 // DCHECK(false); TODO(sadrul): |
| 306 } | 308 } |
| 307 | 309 |
| 308 } // namespace ws | 310 } // namespace ws |
| 309 } // namespace mus | 311 } // namespace mus |
| OLD | NEW |