1 // Copyright 2013 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 "ui/aura/test/test_focus_client.h"
7 #include "ui/aura/client/focus_change_observer.h"
8 #include "ui/aura/window.h"
13 ////////////////////////////////////////////////////////////////////////////////
14 // TestFocusClient, public:
16 TestFocusClient::TestFocusClient()
17 : focused_window_(NULL
),
18 observer_manager_(this) {
21 TestFocusClient::~TestFocusClient() {
24 ////////////////////////////////////////////////////////////////////////////////
25 // TestFocusClient, client::FocusClient implementation:
27 void TestFocusClient::AddObserver(client::FocusChangeObserver
* observer
) {
30 void TestFocusClient::RemoveObserver(client::FocusChangeObserver
* observer
) {
33 void TestFocusClient::FocusWindow(Window
* window
) {
34 if (window
&& !window
->CanFocus())
37 observer_manager_
.Remove(focused_window_
);
38 aura::Window
* old_focused_window
= focused_window_
;
39 focused_window_
= window
;
41 observer_manager_
.Add(focused_window_
);
43 client::FocusChangeObserver
* observer
=
44 client::GetFocusChangeObserver(old_focused_window
);
46 observer
->OnWindowFocused(focused_window_
, old_focused_window
);
47 observer
= client::GetFocusChangeObserver(focused_window_
);
49 observer
->OnWindowFocused(focused_window_
, old_focused_window
);
52 void TestFocusClient::ResetFocusWithinActiveWindow(Window
* window
) {
53 if (!window
->Contains(focused_window_
))
57 Window
* TestFocusClient::GetFocusedWindow() {
58 return focused_window_
;
61 ////////////////////////////////////////////////////////////////////////////////
62 // TestFocusClient, WindowObserver implementation:
64 void TestFocusClient::OnWindowDestroying(Window
* window
) {
65 DCHECK_EQ(window
, focused_window_
);