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. 4 5 #include "ui/aura/test/test_focus_client.h" 6 7 #include "ui/aura/client/focus_change_observer.h" 8 #include "ui/aura/window.h" 9 10 namespace aura { 11 namespace test { 12 13 //////////////////////////////////////////////////////////////////////////////// 14 // TestFocusClient, public: 15 TestFocusClient()16TestFocusClient::TestFocusClient() 17 : focused_window_(NULL), 18 observer_manager_(this) { 19 } 20 ~TestFocusClient()21TestFocusClient::~TestFocusClient() { 22 } 23 24 //////////////////////////////////////////////////////////////////////////////// 25 // TestFocusClient, client::FocusClient implementation: 26 AddObserver(client::FocusChangeObserver * observer)27void TestFocusClient::AddObserver(client::FocusChangeObserver* observer) { 28 } 29 RemoveObserver(client::FocusChangeObserver * observer)30void TestFocusClient::RemoveObserver(client::FocusChangeObserver* observer) { 31 } 32 FocusWindow(Window * window)33void 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_); 42 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); 50 } 51 ResetFocusWithinActiveWindow(Window * window)52void TestFocusClient::ResetFocusWithinActiveWindow(Window* window) { 53 if (!window->Contains(focused_window_)) 54 FocusWindow(window); 55 } 56 GetFocusedWindow()57Window* TestFocusClient::GetFocusedWindow() { 58 return focused_window_; 59 } 60 61 //////////////////////////////////////////////////////////////////////////////// 62 // TestFocusClient, WindowObserver implementation: 63 OnWindowDestroying(Window * window)64void TestFocusClient::OnWindowDestroying(Window* window) { 65 DCHECK_EQ(window, focused_window_); 66 FocusWindow(NULL); 67 } 68 69 } // namespace test 70 } // namespace aura 71