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/mus/focus_controller.h"
7 #include "components/mus/focus_controller_delegate.h"
8 #include "components/mus/server_view.h"
9 #include "components/mus/server_view_drawn_tracker.h"
13 FocusController::FocusController(FocusControllerDelegate
* delegate
)
14 : delegate_(delegate
) {}
16 FocusController::~FocusController() {}
18 void FocusController::SetFocusedView(ServerView
* view
) {
19 if (GetFocusedView() == view
)
22 SetFocusedViewImpl(view
, CHANGE_SOURCE_EXPLICIT
);
25 ServerView
* FocusController::GetFocusedView() {
26 return drawn_tracker_
? drawn_tracker_
->view() : nullptr;
29 void FocusController::SetFocusedViewImpl(ServerView
* view
,
30 ChangeSource change_source
) {
31 ServerView
* old
= GetFocusedView();
33 DCHECK(!view
|| view
->IsDrawn());
36 drawn_tracker_
.reset(new ServerViewDrawnTracker(view
, this));
38 drawn_tracker_
.reset();
40 if (change_source
== CHANGE_SOURCE_DRAWN_STATE_CHANGED
)
41 delegate_
->OnFocusChanged(old
, view
);
44 void FocusController::OnDrawnStateChanged(ServerView
* ancestor
,
47 DCHECK(!is_drawn
); // We only observe when drawn.
48 SetFocusedViewImpl(ancestor
, CHANGE_SOURCE_DRAWN_STATE_CHANGED
);