summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-04 20:18:55 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-04 20:18:55 +0000
commit526f69b0d351859d4320544e478046edba412cdc (patch)
tree1870bf39e6b0b266f07ddfa7831bd0becaebb065
parent1f2d9ed1db3f8f50cc4773515c55c8a9b9a9166e (diff)
downloadchromium_src-526f69b0d351859d4320544e478046edba412cdc.zip
chromium_src-526f69b0d351859d4320544e478046edba412cdc.tar.gz
chromium_src-526f69b0d351859d4320544e478046edba412cdc.tar.bz2
Gets rid of the FocusManager as a concrete object, changes it to an interface that RootWindow implements.RootWindow is already the center of our event tracking/targeting anyway.BUG=noneTEST=existing
Review URL: http://codereview.chromium.org/8142003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@103973 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/aura/aura.gyp1
-rw-r--r--ui/aura/focus_manager.cc32
-rw-r--r--ui/aura/focus_manager.h28
-rw-r--r--ui/aura/root_window.cc33
-rw-r--r--ui/aura/root_window.h14
-rw-r--r--ui/aura/window.cc1
-rw-r--r--ui/aura/window_unittest.cc10
7 files changed, 49 insertions, 70 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index ef34a40..5a42a40 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -34,7 +34,6 @@
'event.h',
'event_filter.cc',
'event_filter.h',
- 'focus_manager.cc',
'focus_manager.h',
'hit_test.h',
'layout_manager.h',
diff --git a/ui/aura/focus_manager.cc b/ui/aura/focus_manager.cc
deleted file mode 100644
index 9652f1c..0000000
--- a/ui/aura/focus_manager.cc
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) 2011 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/window.h"
-#include "ui/aura/window_delegate.h"
-
-namespace aura {
-namespace internal {
-
-FocusManager::FocusManager(Window* owner)
- : owner_(owner),
- focused_window_(NULL) {
-}
-
-FocusManager::~FocusManager() {
-}
-
-void FocusManager::SetFocusedWindow(Window* focused_window) {
- if (focused_window == focused_window_)
- return;
- if (focused_window_)
- focused_window_->delegate()->OnBlur();
- focused_window_ = focused_window;
- if (focused_window_)
- focused_window_->delegate()->OnFocus();
-}
-
-} // namespace internal
-} // namespace aura
diff --git a/ui/aura/focus_manager.h b/ui/aura/focus_manager.h
index f6249b6..0cd8e6f 100644
--- a/ui/aura/focus_manager.h
+++ b/ui/aura/focus_manager.h
@@ -13,22 +13,22 @@ class Window;
namespace internal {
-// The FocusManager, when attached to a Window, tracks changes to keyboard input
-// focus within that Window's hierarchy.
+// An interface implemented by the RootWindow to expose the focused window and
+// allow for it to be changed.
class FocusManager {
public:
- explicit FocusManager(Window* owner);
- ~FocusManager();
-
- void SetFocusedWindow(Window* window);
-
- Window* focused_window() { return focused_window_; }
-
- private:
- Window* owner_;
- Window* focused_window_;
-
- DISALLOW_COPY_AND_ASSIGN(FocusManager);
+ // Sets the currently focused window. Before the currently focused window is
+ // changed, the previous focused window's delegate is sent a blur
+ // notification, and after it is changed the new focused window is sent a
+ // focused notification. Nothing happens if |window| and GetFocusedWindow()
+ // match.
+ virtual void SetFocusedWindow(Window* window) = 0;
+
+ // Returns the currently focused window or NULL if there is none.
+ virtual Window* GetFocusedWindow() = 0;
+
+ protected:
+ virtual ~FocusManager() {}
};
} // namespace internal
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index 13eb9ca..b200a85 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -8,7 +8,6 @@
#include "base/utf_string_conversions.h"
#include "ui/aura/desktop.h"
#include "ui/aura/event.h"
-#include "ui/aura/focus_manager.h"
#include "ui/aura/window_delegate.h"
#include "ui/base/events.h"
@@ -19,7 +18,7 @@ RootWindow::RootWindow()
: Window(NULL),
mouse_pressed_handler_(NULL),
mouse_moved_handler_(NULL),
- ALLOW_THIS_IN_INITIALIZER_LIST(focus_manager_(new FocusManager(this))),
+ focused_window_(NULL),
capture_window_(NULL) {
set_name("RootWindow");
}
@@ -54,10 +53,9 @@ bool RootWindow::HandleMouseEvent(const MouseEvent& event) {
}
bool RootWindow::HandleKeyEvent(const KeyEvent& event) {
- Window* focused_window = GetFocusManager()->focused_window();
- if (focused_window) {
+ if (focused_window_) {
KeyEvent translated_event(event);
- return focused_window->OnKeyEvent(&translated_event);
+ return focused_window_->OnKeyEvent(&translated_event);
}
return false;
}
@@ -87,10 +85,9 @@ void RootWindow::ReleaseCapture(Window* window) {
}
void RootWindow::WindowDestroying(Window* window) {
- // Update the FocusManager if the window was focused.
- internal::FocusManager* focus_manager = GetFocusManager();
- if (focus_manager && focus_manager->focused_window() == window)
- focus_manager->SetFocusedWindow(NULL);
+ // Update the focused window state if the window was focused.
+ if (focused_window_ == window)
+ SetFocusedWindow(NULL);
Desktop::GetInstance()->WindowDestroying(window);
@@ -105,11 +102,25 @@ void RootWindow::WindowDestroying(Window* window) {
capture_window_ = NULL;
}
+void RootWindow::SetFocusedWindow(Window* focused_window) {
+ if (focused_window == focused_window_)
+ return;
+ if (focused_window_)
+ focused_window_->delegate()->OnBlur();
+ focused_window_ = focused_window;
+ if (focused_window_)
+ focused_window_->delegate()->OnFocus();
+}
+
+Window* RootWindow::GetFocusedWindow() {
+ return focused_window_;
+}
+
FocusManager* RootWindow::GetFocusManager() {
- return focus_manager_.get();
+ return this;
}
-internal::RootWindow* RootWindow::GetRoot() {
+RootWindow* RootWindow::GetRoot() {
return this;
}
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index 82c0534..8c92c5d 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -6,6 +6,7 @@
#define UI_AURA_ROOT_WINDOW_H_
#pragma once
+#include "ui/aura/focus_manager.h"
#include "ui/aura/window.h"
namespace aura {
@@ -14,11 +15,10 @@ class MouseEvent;
namespace internal {
-class FocusManager;
-
// A Window subclass that handles event targeting for certain types of
// MouseEvent.
-class RootWindow : public Window {
+class RootWindow : public Window,
+ public FocusManager {
public:
RootWindow();
virtual ~RootWindow();
@@ -45,11 +45,13 @@ class RootWindow : public Window {
// Current handler for mouse events.
Window* mouse_pressed_handler() { return mouse_pressed_handler_; }
- // Overridden from Window:
- virtual FocusManager* GetFocusManager() OVERRIDE;
+ // Overridden from FocusManager:
+ virtual void SetFocusedWindow(Window* window) OVERRIDE;
+ virtual Window* GetFocusedWindow() OVERRIDE;
protected:
// Overridden from Window:
+ virtual internal::FocusManager* GetFocusManager() OVERRIDE;
virtual internal::RootWindow* GetRoot() OVERRIDE;
private:
@@ -59,7 +61,7 @@ class RootWindow : public Window {
Window* mouse_pressed_handler_;
Window* mouse_moved_handler_;
- scoped_ptr<FocusManager> focus_manager_;
+ Window* focused_window_;
Window* capture_window_;
DISALLOW_COPY_AND_ASSIGN(RootWindow);
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index 86663ca..effca03 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -10,7 +10,6 @@
#include "ui/aura/desktop.h"
#include "ui/aura/event.h"
#include "ui/aura/event_filter.h"
-#include "ui/aura/focus_manager.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window_delegate.h"
#include "ui/base/animation/multi_animation.h"
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index 52dd7dc..fa6813f 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -308,7 +308,7 @@ TEST_F(WindowTest, Focus) {
desktop->OnMouseEvent(
MouseEvent(ui::ET_MOUSE_PRESSED, click_point, ui::EF_LEFT_BUTTON_DOWN));
internal::FocusManager* focus_manager = w121->GetFocusManager();
- EXPECT_EQ(w121.get(), focus_manager->focused_window());
+ EXPECT_EQ(w121.get(), focus_manager->GetFocusedWindow());
// The key press should be sent to the focused sub-window.
desktop->OnKeyEvent(KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_E, 0));
@@ -524,7 +524,7 @@ TEST_F(WindowTest, ActivateOnMouse) {
// Activate window1.
desktop->SetActiveWindow(w1.get(), NULL);
EXPECT_EQ(w1.get(), desktop->active_window());
- EXPECT_EQ(w1.get(), focus_manager->focused_window());
+ EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow());
EXPECT_EQ(1, d1.activated_count());
EXPECT_EQ(0, d1.lost_active_count());
d1.Clear();
@@ -537,7 +537,7 @@ TEST_F(WindowTest, ActivateOnMouse) {
// Window2 should have become active.
EXPECT_EQ(w2.get(), desktop->active_window());
- EXPECT_EQ(w2.get(), focus_manager->focused_window());
+ EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow());
EXPECT_EQ(0, d1.activated_count());
EXPECT_EQ(1, d1.lost_active_count());
EXPECT_EQ(1, d2.activated_count());
@@ -554,7 +554,7 @@ TEST_F(WindowTest, ActivateOnMouse) {
// Window2 should still be active and focused.
EXPECT_EQ(w2.get(), desktop->active_window());
- EXPECT_EQ(w2.get(), focus_manager->focused_window());
+ EXPECT_EQ(w2.get(), focus_manager->GetFocusedWindow());
EXPECT_EQ(0, d1.activated_count());
EXPECT_EQ(0, d1.lost_active_count());
EXPECT_EQ(0, d2.activated_count());
@@ -568,7 +568,7 @@ TEST_F(WindowTest, ActivateOnMouse) {
EXPECT_EQ(0, d2.activated_count());
EXPECT_EQ(0, d2.lost_active_count());
EXPECT_EQ(w1.get(), desktop->active_window());
- EXPECT_EQ(w1.get(), focus_manager->focused_window());
+ EXPECT_EQ(w1.get(), focus_manager->GetFocusedWindow());
EXPECT_EQ(1, d1.activated_count());
EXPECT_EQ(0, d1.lost_active_count());
}