Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / components / view_manager / focus_controller.cc
blob014dec9b635fc10658791567d0d7740fb38055a5
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.
5 #include "components/view_manager/focus_controller.h"
7 #include "components/view_manager/focus_controller_delegate.h"
8 #include "components/view_manager/server_view.h"
9 #include "components/view_manager/server_view_drawn_tracker.h"
11 namespace view_manager {
13 FocusController::FocusController(FocusControllerDelegate* delegate)
14 : delegate_(delegate) {
17 FocusController::~FocusController() {
20 void FocusController::SetFocusedView(ServerView* view) {
21 if (GetFocusedView() == view)
22 return;
24 SetFocusedViewImpl(view, CHANGE_SOURCE_EXPLICIT);
27 ServerView* FocusController::GetFocusedView() {
28 return drawn_tracker_ ? drawn_tracker_->view() : nullptr;
31 void FocusController::SetFocusedViewImpl(ServerView* view,
32 ChangeSource change_source) {
33 ServerView* old = GetFocusedView();
35 DCHECK(!view || view->IsDrawn());
37 if (view)
38 drawn_tracker_.reset(new ServerViewDrawnTracker(view, this));
39 else
40 drawn_tracker_.reset();
42 if (change_source == CHANGE_SOURCE_DRAWN_STATE_CHANGED)
43 delegate_->OnFocusChanged(old, view);
46 void FocusController::OnDrawnStateChanged(ServerView* ancestor,
47 ServerView* view,
48 bool is_drawn) {
49 DCHECK(!is_drawn); // We only observe when drawn.
50 SetFocusedViewImpl(ancestor, CHANGE_SOURCE_DRAWN_STATE_CHANGED);
53 } // namespace view_manager