diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-18 20:25:21 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-18 20:25:21 +0000 |
commit | d9ddff90179610845884d13e8cd7422cabae018f (patch) | |
tree | 20b7c26476d1091c19d67f632990039a720d2dd8 | |
parent | 35b035ffdb95d3df0ea5c643b1808ea037f8e872 (diff) | |
download | chromium_src-d9ddff90179610845884d13e8cd7422cabae018f.zip chromium_src-d9ddff90179610845884d13e8cd7422cabae018f.tar.gz chromium_src-d9ddff90179610845884d13e8cd7422cabae018f.tar.bz2 |
Revert 229437 "Remove old FocusManager code from Aura."
> Remove old FocusManager code from Aura.
>
> Needed to add a simple TestFocusClient that can be used by tests, which were still using the old FocusManager. This allows us to remove some obsolete methods from FocusClient/RootWindow/etc.
>
> R=sky@chromium.org
> BUG=
>
> Review URL: https://codereview.chromium.org/26116008
TBR=ben@chromium.org
Review URL: https://codereview.chromium.org/29693004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229464 0039d316-1c4b-4281-b951-d872f2087c98
31 files changed, 271 insertions, 135 deletions
diff --git a/ash/shell.cc b/ash/shell.cc index 6e25c52..7af0a3c 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -83,6 +83,7 @@ #include "ui/aura/client/aura_constants.h" #include "ui/aura/client/user_action_client.h" #include "ui/aura/env.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/layout_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" diff --git a/ash/wm/dock/docked_window_layout_manager.cc b/ash/wm/dock/docked_window_layout_manager.cc index e30a94b..e0a08e3 100644 --- a/ash/wm/dock/docked_window_layout_manager.cc +++ b/ash/wm/dock/docked_window_layout_manager.cc @@ -22,7 +22,7 @@ #include "base/command_line.h" #include "third_party/skia/include/core/SkColor.h" #include "ui/aura/client/activation_client.h" -#include "ui/aura/client/focus_client.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" #include "ui/aura/window_delegate.h" diff --git a/ash/wm/panels/panel_layout_manager.cc b/ash/wm/panels/panel_layout_manager.cc index cf75c29..2100925 100644 --- a/ash/wm/panels/panel_layout_manager.cc +++ b/ash/wm/panels/panel_layout_manager.cc @@ -24,7 +24,7 @@ #include "third_party/skia/include/core/SkPaint.h" #include "third_party/skia/include/core/SkPath.h" #include "ui/aura/client/activation_client.h" -#include "ui/aura/client/focus_client.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" #include "ui/compositor/scoped_layer_animation_settings.h" diff --git a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc index b87a6af..1248754 100644 --- a/chrome/browser/ui/views/omnibox/omnibox_view_views.cc +++ b/chrome/browser/ui/views/omnibox/omnibox_view_views.cc @@ -55,7 +55,7 @@ #endif #if defined(USE_AURA) -#include "ui/aura/client/focus_client.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" #include "ui/compositor/layer.h" #endif diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp index d793ac3..249f05e 100644 --- a/ui/aura/aura.gyp +++ b/ui/aura/aura.gyp @@ -79,6 +79,8 @@ 'env.cc', 'env.h', 'env_observer.h', + 'focus_manager.cc', + 'focus_manager.h', 'input_state_lookup.cc', 'input_state_lookup.h', 'input_state_lookup_win.cc', @@ -157,8 +159,6 @@ 'test/test_cursor_client.h', 'test/test_event_handler.cc', 'test/test_event_handler.h', - 'test/test_focus_client.cc', - 'test/test_focus_client.h', 'test/test_screen.cc', 'test/test_screen.h', 'test/test_stacking_client.cc', diff --git a/ui/aura/bench/bench_main.cc b/ui/aura/bench/bench_main.cc index 67ba3a6..a93bc1f 100644 --- a/ui/aura/bench/bench_main.cc +++ b/ui/aura/bench/bench_main.cc @@ -15,8 +15,8 @@ #include "third_party/skia/include/core/SkXfermode.h" #include "ui/aura/client/default_capture_client.h" #include "ui/aura/env.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" -#include "ui/aura/test/test_focus_client.h" #include "ui/aura/test/test_screen.h" #include "ui/aura/window.h" #include "ui/base/hit_test.h" @@ -318,8 +318,7 @@ int main(int argc, char** argv) { root_window.get(), new aura::client::DefaultCaptureClient(root_window.get())); - scoped_ptr<aura::client::FocusClient> focus_client( - new aura::test::TestFocusClient); + scoped_ptr<aura::client::FocusClient> focus_client(new aura::FocusManager); aura::client::SetFocusClient(root_window.get(), focus_client.get()); // add layers diff --git a/ui/aura/client/focus_client.h b/ui/aura/client/focus_client.h index ad55d5e..ff5f7f6 100644 --- a/ui/aura/client/focus_client.h +++ b/ui/aura/client/focus_client.h @@ -23,6 +23,7 @@ class AURA_EXPORT FocusClient { public: virtual ~FocusClient() {} + // TODO(beng): these methods will be OBSOLETE by FocusChangeEvent. virtual void AddObserver(FocusChangeObserver* observer) = 0; virtual void RemoveObserver(FocusChangeObserver* observer) = 0; @@ -35,6 +36,14 @@ class AURA_EXPORT FocusClient { // Retrieves the focused window, or NULL if there is none. virtual Window* GetFocusedWindow() = 0; + + // TODO(beng): temporary compat until FocusController is on. + // Called when |window|'s disposition in |root_window| changes such that + // focus must be shifted away from it. |destroyed| is true if the disposition + // change is that |window| is being destroyed. + virtual void OnWindowHiddenInRootWindow(aura::Window* window, + aura::RootWindow* root_window, + bool destroyed) = 0; }; // Sets/Gets the focus client on the RootWindow. diff --git a/ui/aura/demo/demo_main.cc b/ui/aura/demo/demo_main.cc index abdd514..e56ab71 100644 --- a/ui/aura/demo/demo_main.cc +++ b/ui/aura/demo/demo_main.cc @@ -11,8 +11,8 @@ #include "ui/aura/client/default_capture_client.h" #include "ui/aura/client/stacking_client.h" #include "ui/aura/env.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" -#include "ui/aura/test/test_focus_client.h" #include "ui/aura/test/test_screen.h" #include "ui/aura/window.h" #include "ui/aura/window_delegate.h" @@ -122,8 +122,8 @@ int DemoMain() { test_screen->CreateRootWindowForPrimaryDisplay()); scoped_ptr<DemoStackingClient> stacking_client(new DemoStackingClient( root_window.get())); - aura::test::TestFocusClient focus_client; - aura::client::SetFocusClient(root_window.get(), &focus_client); + aura::FocusManager focus_manager; + aura::client::SetFocusClient(root_window.get(), &focus_manager); // Create a hierarchy of test windows. DemoWindowDelegate window_delegate1(SK_ColorBLUE); diff --git a/ui/aura/focus_manager.cc b/ui/aura/focus_manager.cc new file mode 100644 index 0000000..921406b --- /dev/null +++ b/ui/aura/focus_manager.cc @@ -0,0 +1,105 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/aura/focus_manager.h" + +#include "ui/aura/client/activation_client.h" +#include "ui/aura/client/focus_change_observer.h" +#include "ui/aura/root_window.h" +#include "ui/aura/window_delegate.h" + +namespace aura { + +//////////////////////////////////////////////////////////////////////////////// +// FocusManager, public: + +FocusManager::FocusManager() : focused_window_(NULL) { +} + +FocusManager::~FocusManager() { +} + +//////////////////////////////////////////////////////////////////////////////// +// FocusManager, client::FocusClient implementation: + +void FocusManager::AddObserver(client::FocusChangeObserver* observer) { + observers_.AddObserver(observer); +} + +void FocusManager::RemoveObserver(client::FocusChangeObserver* observer) { + observers_.RemoveObserver(observer); +} + +void FocusManager::FocusWindow(Window* focused_window) { + if (focused_window == focused_window_) + return; + if (focused_window && !focused_window->CanFocus()) + return; + // The NULL-check of |focused_window| is essential here before asking the + // activation client, since it is valid to clear the focus by calling + // SetFocusedWindow() to NULL. + + if (focused_window) { + RootWindow* root = focused_window->GetRootWindow(); + DCHECK(root); + if (client::GetActivationClient(root) && + !client::GetActivationClient(root)->OnWillFocusWindow( + focused_window, NULL)) { + return; + } + } + + Window* old_focused_window = focused_window_; + focused_window_ = focused_window; + + FOR_EACH_OBSERVER(client::FocusChangeObserver, observers_, + OnWindowFocused(focused_window, old_focused_window)); + client::FocusChangeObserver* observer = + client::GetFocusChangeObserver(old_focused_window); + if (observer) + observer->OnWindowFocused(focused_window_, old_focused_window); + observer = client::GetFocusChangeObserver(focused_window_); + if (observer) + observer->OnWindowFocused(focused_window_, old_focused_window); +} + +void FocusManager::ResetFocusWithinActiveWindow(Window* window) { + FocusWindow(window); +} + +Window* FocusManager::GetFocusedWindow() { + return focused_window_; +} + +void FocusManager::OnWindowHiddenInRootWindow( + aura::Window* window, + aura::RootWindow* root_window, + bool destroyed) { + Window* focused_window = + client::GetFocusClient(root_window)->GetFocusedWindow(); + if (window->Contains(focused_window)) { + Window* focus_to = window->transient_parent(); + if (focus_to) { + // Has to be removed from the transient parent before focusing, + // otherwise |window| will be focused again. + if (destroyed) + focus_to->RemoveTransientChild(window); + } else { + // If the invisible view has no visible transient window, focus to the + // topmost visible parent window. + focus_to = window->parent(); + } + if (focus_to && + (!focus_to->IsVisible() || + !focus_to->CanFocus() || + (client::GetActivationClient(root_window) && + !client::GetActivationClient(root_window)->OnWillFocusWindow( + focus_to, NULL)))) { + focus_to = NULL; + } + client::GetFocusClient(root_window)->FocusWindow(focus_to); + } +} + +} // namespace aura diff --git a/ui/aura/focus_manager.h b/ui/aura/focus_manager.h new file mode 100644 index 0000000..b3a1331 --- /dev/null +++ b/ui/aura/focus_manager.h @@ -0,0 +1,49 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_AURA_FOCUS_MANAGER_H_ +#define UI_AURA_FOCUS_MANAGER_H_ + +#include "base/basictypes.h" +#include "base/observer_list.h" +#include "ui/aura/aura_export.h" +#include "ui/aura/client/focus_client.h" + +namespace ui { +class Event; +} + +namespace aura { + +class Window; + +// An interface implemented by the Desktop to expose the focused window and +// allow for it to be changed. +class AURA_EXPORT FocusManager : public client::FocusClient { + public: + FocusManager(); + virtual ~FocusManager(); + + private: + // Overridden from client::FocusClient: + virtual void AddObserver(client::FocusChangeObserver* observer) OVERRIDE; + virtual void RemoveObserver(client::FocusChangeObserver* observer) OVERRIDE; + virtual void FocusWindow(Window* window) OVERRIDE; + virtual void ResetFocusWithinActiveWindow(Window* window) OVERRIDE; + virtual Window* GetFocusedWindow() OVERRIDE; + virtual void OnWindowHiddenInRootWindow(aura::Window* window, + aura::RootWindow* root_window, + bool destroyed) OVERRIDE; + + protected: + aura::Window* focused_window_; + + ObserverList<client::FocusChangeObserver> observers_; + + DISALLOW_COPY_AND_ASSIGN(FocusManager); +}; + +} // namespace aura + +#endif // UI_AURA_FOCUS_MANAGER_H_ diff --git a/ui/aura/remote_root_window_host_win.cc b/ui/aura/remote_root_window_host_win.cc index e3578c8..8e54836 100644 --- a/ui/aura/remote_root_window_host_win.cc +++ b/ui/aura/remote_root_window_host_win.cc @@ -11,6 +11,7 @@ #include "base/message_loop/message_loop.h" #include "ipc/ipc_message.h" #include "ipc/ipc_sender.h" +#include "ui/aura/client/capture_client.h" #include "ui/aura/client/cursor_client.h" #include "ui/aura/root_window.h" #include "ui/base/cursor/cursor_loader_win.h" diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc index bfd6b35..19c60bf 100644 --- a/ui/aura/root_window.cc +++ b/ui/aura/root_window.cc @@ -11,6 +11,7 @@ #include "base/debug/trace_event.h" #include "base/logging.h" #include "base/message_loop/message_loop.h" +#include "ui/aura/client/activation_client.h" #include "ui/aura/client/capture_client.h" #include "ui/aura/client/cursor_client.h" #include "ui/aura/client/event_client.h" @@ -705,6 +706,12 @@ void RootWindow::OnWindowRemovedFromRootWindow(Window* detached, } void RootWindow::OnWindowHidden(Window* invisible, WindowHiddenReason reason) { + // TODO(beng): This should be removed once FocusController is turned on. + if (client::GetFocusClient(this)) { + client::GetFocusClient(this)->OnWindowHiddenInRootWindow( + invisible, this, reason == WINDOW_DESTROYED); + } + // Do not clear the capture, and the |event_dispatch_target_| if the // window is moving across root windows, because the target itself // is actually still visible and clearing them stops further event diff --git a/ui/aura/root_window_host_win.cc b/ui/aura/root_window_host_win.cc index 020a766..e5658f7 100644 --- a/ui/aura/root_window_host_win.cc +++ b/ui/aura/root_window_host_win.cc @@ -9,6 +9,7 @@ #include <algorithm> #include "base/message_loop/message_loop.h" +#include "ui/aura/client/capture_client.h" #include "ui/aura/client/cursor_client.h" #include "ui/aura/root_window.h" #include "ui/base/cursor/cursor_loader_win.h" diff --git a/ui/aura/root_window_host_x11.cc b/ui/aura/root_window_host_x11.cc index 65dde3b..112e23e 100644 --- a/ui/aura/root_window_host_x11.cc +++ b/ui/aura/root_window_host_x11.cc @@ -27,6 +27,7 @@ #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" #include "base/sys_info.h" +#include "ui/aura/client/capture_client.h" #include "ui/aura/client/cursor_client.h" #include "ui/aura/client/screen_position_client.h" #include "ui/aura/client/user_action_client.h" diff --git a/ui/aura/root_window_unittest.cc b/ui/aura/root_window_unittest.cc index 8a4947f..2820515 100644 --- a/ui/aura/root_window_unittest.cc +++ b/ui/aura/root_window_unittest.cc @@ -8,8 +8,8 @@ #include "testing/gtest/include/gtest/gtest.h" #include "ui/aura/client/event_client.h" -#include "ui/aura/client/focus_client.h" #include "ui/aura/env.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/test/aura_test_base.h" #include "ui/aura/test/event_generator.h" #include "ui/aura/test/test_cursor_client.h" diff --git a/ui/aura/test/aura_test_helper.cc b/ui/aura/test/aura_test_helper.cc index 2e6e389..1b6ec92 100644 --- a/ui/aura/test/aura_test_helper.cc +++ b/ui/aura/test/aura_test_helper.cc @@ -11,10 +11,10 @@ #include "ui/aura/client/default_capture_client.h" #include "ui/aura/client/focus_client.h" #include "ui/aura/env.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/input_state_lookup.h" #include "ui/aura/root_window.h" #include "ui/aura/test/env_test_helper.h" -#include "ui/aura/test/test_focus_client.h" #include "ui/aura/test/test_screen.h" #include "ui/aura/test/test_stacking_client.h" #include "ui/base/ime/dummy_input_method.h" @@ -77,7 +77,7 @@ void AuraTestHelper::SetUp() { gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); root_window_.reset(test_screen_->CreateRootWindowForPrimaryDisplay()); - focus_client_.reset(new TestFocusClient); + focus_client_.reset(new FocusManager); client::SetFocusClient(root_window_.get(), focus_client_.get()); stacking_client_.reset(new TestStackingClient(root_window_.get())); activation_client_.reset( diff --git a/ui/aura/test/test_cursor_client.h b/ui/aura/test/test_cursor_client.h index 696f34d..c10552a 100644 --- a/ui/aura/test/test_cursor_client.h +++ b/ui/aura/test/test_cursor_client.h @@ -5,7 +5,6 @@ #ifndef UI_AURA_TEST_TEST_CURSOR_CLIENT_H_ #define UI_AURA_TEST_TEST_CURSOR_CLIENT_H_ -#include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/observer_list.h" #include "ui/aura/client/cursor_client.h" diff --git a/ui/aura/test/test_focus_client.cc b/ui/aura/test/test_focus_client.cc deleted file mode 100644 index c7f9f8c..0000000 --- a/ui/aura/test/test_focus_client.cc +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "ui/aura/test/test_focus_client.h" - -#include "ui/aura/client/focus_change_observer.h" -#include "ui/aura/window.h" - -namespace aura { -namespace test { - -//////////////////////////////////////////////////////////////////////////////// -// TestFocusClient, public: - -TestFocusClient::TestFocusClient() - : focused_window_(NULL), - observer_manager_(this) { -} - -TestFocusClient::~TestFocusClient() { -} - -//////////////////////////////////////////////////////////////////////////////// -// TestFocusClient, client::FocusClient implementation: - -void TestFocusClient::AddObserver(client::FocusChangeObserver* observer) { -} - -void TestFocusClient::RemoveObserver(client::FocusChangeObserver* observer) { -} - -void TestFocusClient::FocusWindow(Window* window) { - if (window && !window->CanFocus()) - return; - if (focused_window_) - observer_manager_.Remove(focused_window_); - aura::Window* old_focused_window = focused_window_; - focused_window_ = window; - if (focused_window_) - observer_manager_.Add(focused_window_); - - client::FocusChangeObserver* observer = - client::GetFocusChangeObserver(old_focused_window); - if (observer) - observer->OnWindowFocused(focused_window_, old_focused_window); - observer = client::GetFocusChangeObserver(focused_window_); - if (observer) - observer->OnWindowFocused(focused_window_, old_focused_window); -} - -void TestFocusClient::ResetFocusWithinActiveWindow(Window* window) { - if (!window->Contains(focused_window_)) - FocusWindow(window); -} - -Window* TestFocusClient::GetFocusedWindow() { - return focused_window_; -} - -//////////////////////////////////////////////////////////////////////////////// -// TestFocusClient, WindowObserver implementation: - -void TestFocusClient::OnWindowDestroying(Window* window) { - DCHECK_EQ(window, focused_window_); - FocusWindow(NULL); -} - -} // namespace test -} // namespace aura diff --git a/ui/aura/test/test_focus_client.h b/ui/aura/test/test_focus_client.h deleted file mode 100644 index b58671f..0000000 --- a/ui/aura/test/test_focus_client.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef UI_AURA_TEST_TEST_FOCUS_CLIENT_H_ -#define UI_AURA_TEST_TEST_FOCUS_CLIENT_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/scoped_observer.h" -#include "ui/aura/client/focus_client.h" -#include "ui/aura/window_observer.h" - -namespace aura { -namespace test { - -class TestFocusClient : public client::FocusClient, - public WindowObserver { - public: - TestFocusClient(); - virtual ~TestFocusClient(); - - private: - // Overridden from client::FocusClient: - virtual void AddObserver(client::FocusChangeObserver* observer) OVERRIDE; - virtual void RemoveObserver(client::FocusChangeObserver* observer) OVERRIDE; - virtual void FocusWindow(Window* window) OVERRIDE; - virtual void ResetFocusWithinActiveWindow(Window* window) OVERRIDE; - virtual Window* GetFocusedWindow() OVERRIDE; - - // Overridden from WindowObserver: - virtual void OnWindowDestroying(Window* window) OVERRIDE; - - Window* focused_window_; - ScopedObserver<Window, WindowObserver> observer_manager_; - - DISALLOW_COPY_AND_ASSIGN(TestFocusClient); -}; - -} // namespace test -} // namespace aura - -#endif // UI_AURA_TEST_TEST_FOCUS_CLIENT_H_
\ No newline at end of file diff --git a/ui/aura/window.cc b/ui/aura/window.cc index e7f0c2a..c0c5744 100644 --- a/ui/aura/window.cc +++ b/ui/aura/window.cc @@ -15,11 +15,11 @@ #include "base/strings/stringprintf.h" #include "ui/aura/client/capture_client.h" #include "ui/aura/client/event_client.h" -#include "ui/aura/client/focus_client.h" #include "ui/aura/client/screen_position_client.h" #include "ui/aura/client/stacking_client.h" #include "ui/aura/client/visibility_client.h" #include "ui/aura/env.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/layout_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/window_delegate.h" diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc index 620130a..2c44d3c 100644 --- a/ui/aura/window_unittest.cc +++ b/ui/aura/window_unittest.cc @@ -202,6 +202,30 @@ class CaptureWindowDelegateImpl : public TestWindowDelegate { DISALLOW_COPY_AND_ASSIGN(CaptureWindowDelegateImpl); }; +// aura::WindowDelegate that tracks the window that was reported as having the +// focus before us. +class FocusDelegate : public TestWindowDelegate, + public aura::client::FocusChangeObserver { + public: + FocusDelegate() : previous_focused_window_(NULL) { + } + + aura::Window* previous_focused_window() const { + return previous_focused_window_; + } + + // Overridden from client::FocusChangeObserver: + virtual void OnWindowFocused(Window* gained_focus, + Window* lost_focus) OVERRIDE { + previous_focused_window_ = lost_focus; + } + + private: + aura::Window* previous_focused_window_; + + DISALLOW_COPY_AND_ASSIGN(FocusDelegate); +}; + // Keeps track of the location of the gesture. class GestureTrackPositionDelegate : public TestWindowDelegate { public: @@ -1758,6 +1782,44 @@ TEST_F(WindowTest, TransientChildrenGroupBelow) { EXPECT_EQ("2 22 21 213 211 212 1 11", ChildWindowIDsAsString(parent.get())); } +// Tests that when a focused window is closed, its parent inherits the focus. +TEST_F(WindowTest, FocusedWindowTest) { + scoped_ptr<Window> parent(CreateTestWindowWithId(0, root_window())); + scoped_ptr<Window> child(CreateTestWindowWithId(1, parent.get())); + + parent->Show(); + + child->Focus(); + EXPECT_TRUE(child->HasFocus()); + EXPECT_FALSE(parent->HasFocus()); + + child.reset(); + EXPECT_TRUE(parent->HasFocus()); +} + +// Tests that the previously-focused window is passed to OnWindowFocused. +// TODO(beng): Remove once the FocusController lands. +TEST_F(WindowTest, OldFocusedWindowTest) { + const gfx::Rect kBounds(0, 0, 100, 100); + + FocusDelegate delegate1; + scoped_ptr<Window> window1( + CreateTestWindowWithDelegate(&delegate1, 0, kBounds, root_window())); + client::SetFocusChangeObserver(window1.get(), &delegate1); + window1->Focus(); + ASSERT_TRUE(window1->HasFocus()); + EXPECT_TRUE(delegate1.previous_focused_window() == NULL); + + FocusDelegate delegate2; + scoped_ptr<Window> window2( + CreateTestWindowWithDelegate(&delegate2, 1, kBounds, root_window())); + client::SetFocusChangeObserver(window2.get(), &delegate2); + window2->Focus(); + ASSERT_TRUE(window2->HasFocus()); + EXPECT_FALSE(window1->HasFocus()); + EXPECT_EQ(window1.get(), delegate2.previous_focused_window()); +} + namespace { DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); diff --git a/ui/shell/minimal_shell.cc b/ui/shell/minimal_shell.cc index 556c16e..9c3ca11 100644 --- a/ui/shell/minimal_shell.cc +++ b/ui/shell/minimal_shell.cc @@ -7,8 +7,8 @@ #include "ui/aura/client/default_activation_client.h" #include "ui/aura/client/default_capture_client.h" #include "ui/aura/env.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" -#include "ui/aura/test/test_focus_client.h" #include "ui/views/corewm/compound_event_filter.h" #include "ui/views/corewm/input_method_event_filter.h" @@ -22,7 +22,7 @@ MinimalShell::MinimalShell(const gfx::Size& default_window_size) { root_window_->Init(); aura::client::SetStackingClient(root_window_.get(), this); - focus_client_.reset(new aura::test::TestFocusClient); + focus_client_.reset(new aura::FocusManager); aura::client::SetFocusClient(root_window_.get(), focus_client_.get()); root_window_event_filter_ = new views::corewm::CompoundEventFilter; diff --git a/ui/views/controls/native/native_view_host_aura.cc b/ui/views/controls/native/native_view_host_aura.cc index a71e230..444f580 100644 --- a/ui/views/controls/native/native_view_host_aura.cc +++ b/ui/views/controls/native/native_view_host_aura.cc @@ -5,7 +5,7 @@ #include "ui/views/controls/native/native_view_host_aura.h" #include "base/logging.h" -#include "ui/aura/client/focus_client.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/window.h" #include "ui/views/controls/native/native_view_host.h" #include "ui/views/view_constants_aura.h" diff --git a/ui/views/corewm/compound_event_filter.cc b/ui/views/corewm/compound_event_filter.cc index 0d021bd..89fa198 100644 --- a/ui/views/corewm/compound_event_filter.cc +++ b/ui/views/corewm/compound_event_filter.cc @@ -10,6 +10,7 @@ #include "ui/aura/client/cursor_client.h" #include "ui/aura/client/drag_drop_client.h" #include "ui/aura/env.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/window_delegate.h" #include "ui/aura/window_tracker.h" diff --git a/ui/views/corewm/focus_controller.cc b/ui/views/corewm/focus_controller.cc index 8c05ac2..a5fe9c3 100644 --- a/ui/views/corewm/focus_controller.cc +++ b/ui/views/corewm/focus_controller.cc @@ -179,6 +179,15 @@ aura::Window* FocusController::GetFocusedWindow() { return focused_window_; } +void FocusController::OnWindowHiddenInRootWindow( + aura::Window* window, + aura::RootWindow* root_window, + bool destroyed) { + //NOTREACHED(); + // This method is only for compat with aura::FocusManager. It should not be + // needed in the new FocusController. +} + //////////////////////////////////////////////////////////////////////////////// // FocusController, ui::EventHandler implementation: void FocusController::OnKeyEvent(ui::KeyEvent* event) { diff --git a/ui/views/corewm/focus_controller.h b/ui/views/corewm/focus_controller.h index d3d34e6..0026436 100644 --- a/ui/views/corewm/focus_controller.h +++ b/ui/views/corewm/focus_controller.h @@ -64,6 +64,9 @@ class VIEWS_EXPORT FocusController : public aura::client::ActivationClient, virtual void FocusWindow(aura::Window* window) OVERRIDE; virtual void ResetFocusWithinActiveWindow(aura::Window* window) OVERRIDE; virtual aura::Window* GetFocusedWindow() OVERRIDE; + virtual void OnWindowHiddenInRootWindow(aura::Window* window, + aura::RootWindow* root_window, + bool destroyed) OVERRIDE; // Overridden from ui::EventHandler: virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; diff --git a/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc b/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc index 347cbb2..8cffb57 100644 --- a/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc +++ b/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc @@ -8,8 +8,8 @@ #include "ui/aura/client/activation_client.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/client/cursor_client.h" -#include "ui/aura/client/focus_client.h" #include "ui/aura/client/stacking_client.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/root_window_host.h" #include "ui/aura/window.h" diff --git a/ui/views/widget/desktop_aura/desktop_root_window_host_win.cc b/ui/views/widget/desktop_aura/desktop_root_window_host_win.cc index ea5c1ae..9d1a330 100644 --- a/ui/views/widget/desktop_aura/desktop_root_window_host_win.cc +++ b/ui/views/widget/desktop_aura/desktop_root_window_host_win.cc @@ -9,7 +9,7 @@ #include "third_party/skia/include/core/SkRegion.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/client/cursor_client.h" -#include "ui/aura/client/focus_client.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/window_property.h" #include "ui/base/cursor/cursor_loader_win.h" diff --git a/ui/views/widget/desktop_aura/desktop_root_window_host_x11.cc b/ui/views/widget/desktop_aura/desktop_root_window_host_x11.cc index 391beb4..9890b0a 100644 --- a/ui/views/widget/desktop_aura/desktop_root_window_host_x11.cc +++ b/ui/views/widget/desktop_aura/desktop_root_window_host_x11.cc @@ -17,6 +17,7 @@ #include "third_party/skia/include/core/SkPath.h" #include "ui/aura/client/screen_position_client.h" #include "ui/aura/client/user_action_client.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/window_property.h" #include "ui/base/dragdrop/os_exchange_data_provider_aurax11.h" diff --git a/ui/views/widget/desktop_aura/x11_desktop_handler.cc b/ui/views/widget/desktop_aura/x11_desktop_handler.cc index 179bc75..0c96565 100644 --- a/ui/views/widget/desktop_aura/x11_desktop_handler.cc +++ b/ui/views/widget/desktop_aura/x11_desktop_handler.cc @@ -6,6 +6,7 @@ #include "base/message_loop/message_loop.h" #include "ui/aura/env.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" #include "ui/base/x/x11_util.h" diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index e0778c0..b3320d1 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -11,12 +11,12 @@ #include "ui/aura/client/aura_constants.h" #include "ui/aura/client/cursor_client.h" #include "ui/aura/client/drag_drop_client.h" -#include "ui/aura/client/focus_client.h" #include "ui/aura/client/screen_position_client.h" #include "ui/aura/client/stacking_client.h" #include "ui/aura/client/window_move_client.h" #include "ui/aura/client/window_types.h" #include "ui/aura/env.h" +#include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" #include "ui/aura/window_observer.h" |