OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/services/view_manager/focus_controller.h" |
| 6 |
| 7 #include "mojo/services/view_manager/focus_controller_delegate.h" |
| 8 #include "mojo/services/view_manager/server_view.h" |
| 9 #include "mojo/services/view_manager/server_view_drawn_tracker.h" |
| 10 |
| 11 namespace view_manager { |
| 12 |
| 13 FocusController::FocusController(FocusControllerDelegate* delegate, |
| 14 ServerView* root) |
| 15 : delegate_(delegate), root_(root) { |
| 16 } |
| 17 |
| 18 FocusController::~FocusController() { |
| 19 } |
| 20 |
| 21 void FocusController::SetFocusedView(ServerView* view) { |
| 22 if (GetFocusedView() == view) |
| 23 return; |
| 24 |
| 25 SetFocusedViewImpl(view, CHANGE_SOURCE_EXPLICIT); |
| 26 } |
| 27 |
| 28 ServerView* FocusController::GetFocusedView() { |
| 29 return drawn_tracker_ ? drawn_tracker_->view() : nullptr; |
| 30 } |
| 31 |
| 32 void FocusController::SetFocusedViewImpl(ServerView* view, |
| 33 ChangeSource change_source) { |
| 34 ServerView* old = GetFocusedView(); |
| 35 |
| 36 DCHECK(!view || view->IsDrawn(root_)); |
| 37 |
| 38 if (view) |
| 39 drawn_tracker_.reset(new ServerViewDrawnTracker(root_, view, this)); |
| 40 else |
| 41 drawn_tracker_.reset(); |
| 42 |
| 43 if (change_source == CHANGE_SOURCE_DRAWN_STATE_CHANGED) |
| 44 delegate_->OnFocusChanged(old, view); |
| 45 } |
| 46 |
| 47 void FocusController::OnDrawnStateChanged(ServerView* ancestor, |
| 48 ServerView* view, |
| 49 bool is_drawn) { |
| 50 DCHECK(!is_drawn); // We only observe when drawn. |
| 51 SetFocusedViewImpl(ancestor, CHANGE_SOURCE_DRAWN_STATE_CHANGED); |
| 52 } |
| 53 |
| 54 } // namespace view_manager |
OLD | NEW |