Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / aura / test / test_focus_client.cc
blobc7f9f8c642143cfab8c9757e8e80b09bb20a119c
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"
10 namespace aura {
11 namespace test {
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())
35 return;
36 if (focused_window_)
37 observer_manager_.Remove(focused_window_);
38 aura::Window* old_focused_window = focused_window_;
39 focused_window_ = window;
40 if (focused_window_)
41 observer_manager_.Add(focused_window_);
43 client::FocusChangeObserver* observer =
44 client::GetFocusChangeObserver(old_focused_window);
45 if (observer)
46 observer->OnWindowFocused(focused_window_, old_focused_window);
47 observer = client::GetFocusChangeObserver(focused_window_);
48 if (observer)
49 observer->OnWindowFocused(focused_window_, old_focused_window);
52 void TestFocusClient::ResetFocusWithinActiveWindow(Window* window) {
53 if (!window->Contains(focused_window_))
54 FocusWindow(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_);
66 FocusWindow(NULL);
69 } // namespace test
70 } // namespace aura