Skip to content

Commit

Permalink
Rework FocusManager as FocusClient.
Browse files Browse the repository at this point in the history
This allows us to have multiple focus system implementations.

http://crbug.com/162100
R=sky@chromium.org
Review URL: https://codereview.chromium.org/11299219

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@169824 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
ben@chromium.org committed Nov 28, 2012
1 parent 9bf222b commit 8cfb672
Show file tree
Hide file tree
Showing 44 changed files with 303 additions and 224 deletions.
12 changes: 7 additions & 5 deletions ash/display/screen_position_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include "ash/wm/workspace_controller.h"
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/capture_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/window_tracker.h"
#include "ui/compositor/dip_util.h"
Expand Down Expand Up @@ -171,7 +171,8 @@ void ScreenPositionController::SetBounds(aura::Window* window,
}

if (dst_container && window->parent() != dst_container) {
aura::Window* focused = window->GetFocusManager()->GetFocusedWindow();
aura::Window* focused = aura::client::GetFocusClient(window)->
GetFocusedWindow();
aura::client::ActivationClient* activation_client =
aura::client::GetActivationClient(window->GetRootWindow());
aura::Window* active = activation_client->GetActiveWindow();
Expand All @@ -193,10 +194,11 @@ void ScreenPositionController::SetBounds(aura::Window* window,
MoveAllTransientChildrenToNewRoot(display, window);

// Restore focused/active window.
if (tracker.Contains(focused))
window->GetFocusManager()->SetFocusedWindow(focused, NULL);
else if (tracker.Contains(active))
if (tracker.Contains(focused)) {
aura::client::GetFocusClient(window)->FocusWindow(focused, NULL);
} else if (tracker.Contains(active)) {
activation_client->ActivateWindow(active);
}
}
}

Expand Down
27 changes: 14 additions & 13 deletions ash/extended_desktop_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "base/string_util.h"
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_windows.h"
Expand Down Expand Up @@ -119,8 +119,8 @@ TEST_F(ExtendedDesktopTest, Basic) {
EXPECT_TRUE(GetRootWindowController(*iter) != NULL);
}
// Make sure root windows share the same controllers.
EXPECT_EQ(root_windows[0]->GetFocusManager(),
root_windows[1]->GetFocusManager());
EXPECT_EQ(aura::client::GetFocusClient(root_windows[0]),
aura::client::GetFocusClient(root_windows[1]));
EXPECT_EQ(aura::client::GetActivationClient(root_windows[0]),
aura::client::GetActivationClient(root_windows[1]));
EXPECT_EQ(aura::client::GetCaptureClient(root_windows[0]),
Expand All @@ -138,7 +138,7 @@ TEST_F(ExtendedDesktopTest, Activation) {
EXPECT_EQ(root_windows[1], widget_on_2nd->GetNativeView()->GetRootWindow());

EXPECT_EQ(widget_on_2nd->GetNativeView(),
root_windows[0]->GetFocusManager()->GetFocusedWindow());
aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));

aura::test::EventGenerator generator_1st(root_windows[0]);
Expand All @@ -149,14 +149,14 @@ TEST_F(ExtendedDesktopTest, Activation) {
generator_1st.ClickLeftButton();

EXPECT_EQ(widget_on_1st->GetNativeView(),
root_windows[0]->GetFocusManager()->GetFocusedWindow());
aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
EXPECT_TRUE(wm::IsActiveWindow(widget_on_1st->GetNativeView()));

generator_2nd.MoveMouseToCenterOf(widget_on_2nd->GetNativeView());
generator_2nd.ClickLeftButton();

EXPECT_EQ(widget_on_2nd->GetNativeView(),
root_windows[0]->GetFocusManager()->GetFocusedWindow());
aura::client::GetFocusClient(root_windows[0])->GetFocusedWindow());
EXPECT_TRUE(wm::IsActiveWindow(widget_on_2nd->GetNativeView()));
}

Expand Down Expand Up @@ -670,27 +670,28 @@ TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
lock_widget->Show();
textfield->RequestFocus();

aura::FocusManager* focus_manager = root_windows[0]->GetFocusManager();
EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow());
aura::client::FocusClient* focus_client =
aura::client::GetFocusClient(root_windows[0]);
EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());

// The lock window should get events on both root windows.
aura::test::EventGenerator generator1(root_windows[0]);
generator1.PressKey(ui::VKEY_A, 0);
generator1.ReleaseKey(ui::VKEY_A, 0);
EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow());
EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
EXPECT_EQ("a", UTF16ToASCII(textfield->text()));

aura::test::EventGenerator generator2(root_windows[1]);
generator2.PressKey(ui::VKEY_B, 0);
generator2.ReleaseKey(ui::VKEY_B, 0);
EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow());
EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
EXPECT_EQ("ab", UTF16ToASCII(textfield->text()));

// Deleting 2nd display. The lock window still should get the events.
UpdateDisplay("100x100");
generator2.PressKey(ui::VKEY_C, 0);
generator2.ReleaseKey(ui::VKEY_C, 0);
EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow());
EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
EXPECT_EQ("abc", UTF16ToASCII(textfield->text()));

// Creating 2nd display again, and lock window still should get events
Expand All @@ -699,13 +700,13 @@ TEST_F(ExtendedDesktopTest, KeyEventsOnLockScreen) {
root_windows = Shell::GetAllRootWindows();
generator1.PressKey(ui::VKEY_D, 0);
generator1.ReleaseKey(ui::VKEY_D, 0);
EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow());
EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
EXPECT_EQ("abcd", UTF16ToASCII(textfield->text()));

aura::test::EventGenerator generator22(root_windows[1]);
generator22.PressKey(ui::VKEY_E, 0);
generator22.ReleaseKey(ui::VKEY_E, 0);
EXPECT_EQ(lock_widget->GetNativeView(), focus_manager->GetFocusedWindow());
EXPECT_EQ(lock_widget->GetNativeView(), focus_client->GetFocusedWindow());
EXPECT_EQ("abcde", UTF16ToASCII(textfield->text()));
}

Expand Down
8 changes: 4 additions & 4 deletions ash/root_window_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/client/tooltip_client.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
Expand Down Expand Up @@ -413,7 +413,7 @@ void RootWindowController::CloseChildWindows() {
}

void RootWindowController::MoveWindowsTo(aura::RootWindow* dst) {
aura::Window* focused = dst->GetFocusManager()->GetFocusedWindow();
aura::Window* focused = aura::client::GetFocusClient(dst)->GetFocusedWindow();
aura::WindowTracker tracker;
if (focused)
tracker.Add(focused);
Expand All @@ -431,13 +431,13 @@ void RootWindowController::MoveWindowsTo(aura::RootWindow* dst) {
// window may be deleted when losing focus (fullscreen flash for
// example). If the focused window is still alive after move, it'll
// be re-focused below.
dst->GetFocusManager()->SetFocusedWindow(NULL, NULL);
aura::client::GetFocusClient(dst)->FocusWindow(NULL, NULL);

ReparentAllWindows(root_window_.get(), dst);

// Restore focused or active window if it's still alive.
if (focused && tracker.Contains(focused) && dst->Contains(focused)) {
dst->GetFocusManager()->SetFocusedWindow(focused, NULL);
aura::client::GetFocusClient(dst)->FocusWindow(focused, NULL);
} else if (active && tracker.Contains(active) && dst->Contains(active)) {
activation_client->ActivateWindow(active);
}
Expand Down
5 changes: 2 additions & 3 deletions ash/root_window_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include "ash/test/ash_test_base.h"
#include "ash/wm/system_modal_container_layout_manager.h"
#include "ash/wm/window_util.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/env.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
Expand Down Expand Up @@ -150,8 +150,7 @@ TEST_F(RootWindowControllerTest, MoveWindows_Basic) {
aura::Window* d2 = aura::test::CreateTestWindowWithDelegate(
&delete_on_blur_delegate, 0, gfx::Rect(50, 50, 100, 100), NULL);
delete_on_blur_delegate.set_window(d2);
root_windows[0]->GetFocusManager()->SetFocusedWindow(
d2, NULL);
aura::client::GetFocusClient(root_windows[0])->FocusWindow(d2, NULL);
tracker.Add(d2);

UpdateDisplay("600x600");
Expand Down
10 changes: 5 additions & 5 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ Shell::~Shell() {
// effects (e.g. crashes) from changing focus during shutdown.
// See bug crbug.com/134502.
if (active_root_window_)
active_root_window_->GetFocusManager()->SetFocusedWindow(NULL, NULL);
aura::client::GetFocusClient(active_root_window_)->FocusWindow(NULL, NULL);

// Please keep in same order as in Init() because it's easy to miss one.
RemovePreTargetHandler(user_activity_detector_.get());
Expand Down Expand Up @@ -409,10 +409,10 @@ void Shell::Init() {
env_filter_.reset(new views::corewm::CompoundEventFilter);
AddPreTargetHandler(env_filter_.get());

focus_manager_.reset(new aura::FocusManager);
focus_client_.reset(new aura::FocusManager);
activation_controller_.reset(
new internal::ActivationController(
focus_manager_.get(),
focus_client_.get(),
new internal::AshActivationController));
AddPreTargetHandler(activation_controller_.get());

Expand Down Expand Up @@ -771,7 +771,7 @@ SystemTray* Shell::system_tray() {
}

void Shell::InitRootWindowForSecondaryDisplay(aura::RootWindow* root) {
root->set_focus_manager(focus_manager_.get());
aura::client::SetFocusClient(root, focus_client_.get());
internal::RootWindowController* controller =
new internal::RootWindowController(root);
controller->CreateContainers();
Expand Down Expand Up @@ -808,7 +808,7 @@ void Shell::InitRootWindowController(
DCHECK(capture_controller_.get());
DCHECK(window_cycle_controller_.get());

root_window->set_focus_manager(focus_manager_.get());
aura::client::SetFocusClient(root_window, focus_client_.get());
input_method_filter_->SetInputMethodPropertyInRootWindow(root_window);
aura::client::SetActivationClient(root_window, activation_controller_.get());
aura::client::SetVisibilityClient(root_window, visibility_controller_.get());
Expand Down
4 changes: 2 additions & 2 deletions ash/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class CommandLine;

namespace aura {
class EventFilter;
class FocusManager;
class RootWindow;
class Window;
namespace client {
class FocusClient;
class StackingClient;
class UserActionClient;
}
Expand Down Expand Up @@ -505,7 +505,7 @@ class ASH_EXPORT Shell : internal::SystemModalContainerEventFilterDelegate,
scoped_ptr<HighContrastController> high_contrast_controller_;
scoped_ptr<MagnificationController> magnification_controller_;
scoped_ptr<PartialMagnificationController> partial_magnification_controller_;
scoped_ptr<aura::FocusManager> focus_manager_;
scoped_ptr<aura::client::FocusClient> focus_client_;
scoped_ptr<aura::client::UserActionClient> user_action_client_;
scoped_ptr<internal::MouseCursorEventFilter> mouse_cursor_filter_;
scoped_ptr<internal::ScreenPositionController> screen_position_controller_;
Expand Down
17 changes: 9 additions & 8 deletions ash/wm/activation_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#include "ui/aura/client/activation_change_observer.h"
#include "ui/aura/client/activation_delegate.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/focus_client.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_delegate.h"
Expand Down Expand Up @@ -144,20 +144,20 @@ aura::Window* FindFocusableWindowFor(aura::Window* window) {
// ActivationController, public:

ActivationController::ActivationController(
aura::FocusManager* focus_manager,
aura::client::FocusClient* focus_client,
ActivationControllerDelegate* delegate)
: focus_manager_(focus_manager),
: focus_client_(focus_client),
updating_activation_(false),
active_window_(NULL),
ALLOW_THIS_IN_INITIALIZER_LIST(observer_manager_(this)),
delegate_(delegate) {
aura::Env::GetInstance()->AddObserver(this);
focus_manager_->AddObserver(this);
focus_client_->AddObserver(this);
}

ActivationController::~ActivationController() {
aura::Env::GetInstance()->RemoveObserver(this);
focus_manager_->RemoveObserver(this);
focus_client_->RemoveObserver(this);
}

// static
Expand Down Expand Up @@ -320,8 +320,9 @@ void ActivationController::ActivateWindowWithEvent(aura::Window* window,
active_window_ = window;

if (window &&
!window->Contains(window->GetFocusManager()->GetFocusedWindow())) {
window->GetFocusManager()->SetFocusedWindow(window, event);
!window->Contains(aura::client::GetFocusClient(window)->
GetFocusedWindow())) {
aura::client::GetFocusClient(window)->FocusWindow(window, event);
}

FOR_EACH_OBSERVER(aura::client::ActivationChangeObserver,
Expand Down Expand Up @@ -413,7 +414,7 @@ aura::Window* ActivationController::GetTopmostWindowToActivateInContainer(
void ActivationController::FocusWindowWithEvent(const ui::Event* event) {
aura::Window* window = static_cast<aura::Window*>(event->target());
if (GetActiveWindow() != window) {
window->GetFocusManager()->SetFocusedWindow(
aura::client::GetFocusClient(window)->FocusWindow(
FindFocusableWindowFor(window), event);
}
}
Expand Down
13 changes: 7 additions & 6 deletions ash/wm/activation_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
#include "base/observer_list.h"
#include "base/scoped_observer.h"
#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/aura/env_observer.h"
#include "ui/aura/focus_change_observer.h"
#include "ui/aura/window_observer.h"
#include "ui/base/events/event_handler.h"

namespace aura {
namespace client {
class ActivationChangeObserver;
class FocusClient;
}
}

Expand All @@ -32,16 +33,16 @@ class ASH_EXPORT ActivationController
: public aura::client::ActivationClient,
public aura::WindowObserver,
public aura::EnvObserver,
public aura::FocusChangeObserver,
public aura::client::FocusChangeObserver,
public ui::EventHandler {
public:
// The ActivationController takes ownership of |delegate|.
ActivationController(aura::FocusManager* focus_manager,
ActivationController(aura::client::FocusClient* focus_client,
ActivationControllerDelegate* delegate);
virtual ~ActivationController();

// Returns true if |window| exists within a container that supports
// activation. |event| is the revent responsible for initiating the change, or
// activation. |event| is the event responsible for initiating the change, or
// NULL if there is no event.
static aura::Window* GetActivatableWindow(aura::Window* window,
const ui::Event* event);
Expand All @@ -66,7 +67,7 @@ class ASH_EXPORT ActivationController
// Overridden from aura::EnvObserver:
virtual void OnWindowInitialized(aura::Window* window) OVERRIDE;

// Overridden from aura::FocusChangeObserver:
// Overridden from aura::client::FocusChangeObserver:
virtual void OnWindowFocused(aura::Window* window) OVERRIDE;

private:
Expand Down Expand Up @@ -99,7 +100,7 @@ class ASH_EXPORT ActivationController
// result in focus changes.
void FocusWindowWithEvent(const ui::Event* event);

aura::FocusManager* focus_manager_;
aura::client::FocusClient* focus_client_;

// True inside ActivateWindow(). Used to prevent recursion of focus
// change notifications causing activation.
Expand Down
1 change: 0 additions & 1 deletion ash/wm/activation_controller_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "ash/test/test_activation_delegate.h"
#include "ash/wm/window_util.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/root_window.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
Expand Down
6 changes: 3 additions & 3 deletions ash/wm/app_list_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/app_list_view.h"
#include "ui/app_list/pagination_model.h"
#include "ui/aura/focus_manager.h"
#include "ui/aura/client/focus_client.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/base/events/event.h"
Expand Down Expand Up @@ -160,7 +160,7 @@ void AppListController::SetView(app_list::AppListView* view) {
Shell::GetInstance()->AddPreTargetHandler(this);
Launcher::ForWindow(GetWindow())->AddIconObserver(this);
widget->GetNativeView()->GetRootWindow()->AddRootWindowObserver(this);
widget->GetNativeView()->GetFocusManager()->AddObserver(this);
aura::client::GetFocusClient(widget->GetNativeView())->AddObserver(this);
widget->SetOpacity(0);
ScheduleAnimation();

Expand All @@ -180,7 +180,7 @@ void AppListController::ResetView() {
Shell::GetInstance()->RemovePreTargetHandler(this);
Launcher::ForWindow(GetWindow())->RemoveIconObserver(this);
widget->GetNativeView()->GetRootWindow()->RemoveRootWindowObserver(this);
widget->GetNativeView()->GetFocusManager()->RemoveObserver(this);
aura::client::GetFocusClient(widget->GetNativeView())->RemoveObserver(this);
view_ = NULL;
}

Expand Down
Loading

0 comments on commit 8cfb672

Please sign in to comment.