summaryrefslogtreecommitdiffstats
path: root/ui/aura
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-12 22:10:51 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-12 22:10:51 +0000
commit9b10d2a051ec36c4e7f012d31b8214221db16eaa (patch)
treeb6242231f0674978d51071f02f511c81370a022c /ui/aura
parent178520e30cfa28c3e33dd24a1868a06332975de4 (diff)
downloadchromium_src-9b10d2a051ec36c4e7f012d31b8214221db16eaa.zip
chromium_src-9b10d2a051ec36c4e7f012d31b8214221db16eaa.tar.gz
chromium_src-9b10d2a051ec36c4e7f012d31b8214221db16eaa.tar.bz2
Move the concept of Activation to the Shell.
The Active Window is now stored in a property on the RootWindow. Classes wishing to observe changes to this can implement WindowObserver and attach to the RootWindow to be notified of changes in this property. We provide an ActivationClient interface in Aura for customers to use to set/get the active window, and deactivate a window. This is because setting the active window involves more than just changing the property, there is some additional book-keeping that must be done. The ActivationClient is stored in a property on the RootWindow. We also provide an ActivationDelegate interface in Aura that window owners can use to be notified of changes in activation state, and to specify whether or not a window can be activated. The ActivationDelegate should be stored on the relevant window in a property. I moved a lot of Activation-related functionality out of Aura, including all of the unit tests, now on ActivationController, and the associated WindowDelegate implementations which have now become a single TestActivationDelegate implementation. BUG=none TEST=unit tests Review URL: http://codereview.chromium.org/8894018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114095 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/aura')
-rw-r--r--ui/aura/aura.gyp6
-rw-r--r--ui/aura/client/activation_client.cc23
-rw-r--r--ui/aura/client/activation_client.h42
-rw-r--r--ui/aura/client/activation_delegate.cc24
-rw-r--r--ui/aura/client/activation_delegate.h43
-rw-r--r--ui/aura/client/aura_constants.cc15
-rw-r--r--ui/aura/client/aura_constants.h52
-rw-r--r--ui/aura/client/stacking_client.h8
-rw-r--r--ui/aura/demo/demo_main.cc3
-rw-r--r--ui/aura/root_window.cc96
-rw-r--r--ui/aura/root_window.h25
-rw-r--r--ui/aura/root_window_observer.h5
-rw-r--r--ui/aura/test/test_activation_client.cc59
-rw-r--r--ui/aura/test/test_activation_client.h44
-rw-r--r--ui/aura/test/test_stacking_client.cc15
-rw-r--r--ui/aura/test/test_stacking_client.h2
-rw-r--r--ui/aura/test/test_window_delegate.cc38
-rw-r--r--ui/aura/test/test_window_delegate.h30
-rw-r--r--ui/aura/window.cc21
-rw-r--r--ui/aura/window.h14
-rw-r--r--ui/aura/window_delegate.h12
-rw-r--r--ui/aura/window_unittest.cc146
22 files changed, 309 insertions, 414 deletions
diff --git a/ui/aura/aura.gyp b/ui/aura/aura.gyp
index f6e03a6..9ac8248 100644
--- a/ui/aura/aura.gyp
+++ b/ui/aura/aura.gyp
@@ -25,6 +25,10 @@
'sources': [
'aura_switches.cc',
'aura_switches.h',
+ 'client/activation_client.cc',
+ 'client/activation_client.h',
+ 'client/activation_delegate.cc',
+ 'client/activation_delegate.h',
'client/aura_constants.cc',
'client/aura_constants.h',
'client/drag_drop_client.h',
@@ -71,6 +75,8 @@
'test/aura_test_base.h',
'test/event_generator.cc',
'test/event_generator.h',
+ 'test/test_activation_client.cc',
+ 'test/test_activation_client.h',
'test/test_event_filter.cc',
'test/test_event_filter.h',
'test/test_stacking_client.cc',
diff --git a/ui/aura/client/activation_client.cc b/ui/aura/client/activation_client.cc
new file mode 100644
index 0000000..8106ca2
--- /dev/null
+++ b/ui/aura/client/activation_client.cc
@@ -0,0 +1,23 @@
+// 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/client/activation_client.h"
+
+#include "ui/aura/client/aura_constants.h"
+#include "ui/aura/root_window.h"
+
+namespace aura {
+
+// static
+void ActivationClient::SetActivationClient(ActivationClient* client) {
+ RootWindow::GetInstance()->SetProperty(kRootWindowActivationClient, client);
+}
+
+// static
+ActivationClient* ActivationClient::GetActivationClient() {
+ return reinterpret_cast<ActivationClient*>(
+ RootWindow::GetInstance()->GetProperty(kRootWindowActivationClient));
+}
+
+} // namespace aura
diff --git a/ui/aura/client/activation_client.h b/ui/aura/client/activation_client.h
new file mode 100644
index 0000000..547f9ab
--- /dev/null
+++ b/ui/aura/client/activation_client.h
@@ -0,0 +1,42 @@
+// 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.
+
+#ifndef UI_AURA_CLIENT_ACTIVATION_CLIENT_H_
+#define UI_AURA_CLIENT_ACTIVATION_CLIENT_H_
+#pragma once
+
+#include "ui/aura/aura_export.h"
+
+namespace aura {
+
+class Window;
+
+// An interface implemented by an object that manages window activation.
+class AURA_EXPORT ActivationClient {
+ public:
+ // Sets/Gets the activation client on the RootWindow.
+ static void SetActivationClient(ActivationClient* client);
+ static ActivationClient* GetActivationClient();
+
+ // Activates |window|. If |window| is NULL, nothing happens.
+ virtual void ActivateWindow(Window* window) = 0;
+
+ // Deactivates |window|. What (if anything) is activated next is up to the
+ // client. If |window| is NULL, nothing happens.
+ virtual void DeactivateWindow(Window* window) = 0;
+
+ // Retrieves the active window, or NULL if there is none.
+ virtual aura::Window* GetActiveWindow() = 0;
+
+ // Returns true if |window| can be focused. To be focusable, |window| must
+ // exist inside an activatable window.
+ virtual bool CanFocusWindow(Window* window) const = 0;
+
+ protected:
+ virtual ~ActivationClient() {}
+};
+
+} // namespace aura
+
+#endif // UI_AURA_CLIENT_ACTIVATION_CLIENT_H_
diff --git a/ui/aura/client/activation_delegate.cc b/ui/aura/client/activation_delegate.cc
new file mode 100644
index 0000000..18688f0
--- /dev/null
+++ b/ui/aura/client/activation_delegate.cc
@@ -0,0 +1,24 @@
+// 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/client/activation_delegate.h"
+
+#include "ui/aura/client/aura_constants.h"
+#include "ui/aura/window.h"
+
+namespace aura {
+
+// static
+void ActivationDelegate::SetActivationDelegate(Window* window,
+ ActivationDelegate* delegate) {
+ window->SetProperty(kActivationDelegateKey, delegate);
+}
+
+// static
+ActivationDelegate* ActivationDelegate::GetActivationDelegate(Window* window) {
+ return reinterpret_cast<ActivationDelegate*>(
+ window->GetProperty(kActivationDelegateKey));
+}
+
+} // namespace aura
diff --git a/ui/aura/client/activation_delegate.h b/ui/aura/client/activation_delegate.h
new file mode 100644
index 0000000..dd2933e
--- /dev/null
+++ b/ui/aura/client/activation_delegate.h
@@ -0,0 +1,43 @@
+// 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.
+
+#ifndef UI_AURA_CLIENT_ACTIVATION_DELEGATE_H_
+#define UI_AURA_CLIENT_ACTIVATION_DELEGATE_H_
+#pragma once
+
+#include "ui/aura/aura_export.h"
+
+namespace aura {
+
+class Event;
+class Window;
+
+// An interface implemented by an object that configures and responds to changes
+// to a window's activation state.
+class AURA_EXPORT ActivationDelegate {
+ public:
+ // Sets/Gets the ActivationDelegate on the Window. No ownership changes.
+ static void SetActivationDelegate(Window* window,
+ ActivationDelegate* delegate);
+ static ActivationDelegate* GetActivationDelegate(Window* window);
+
+ // Returns true if the window should be activated. |event| is either the mouse
+ // event supplied if the activation is the result of a mouse, or the touch
+ // event if the activation is the result of a touch, or NULL if activation is
+ // attempted for another reason.
+ virtual bool ShouldActivate(Event* event) = 0;
+
+ // Sent when the window is activated.
+ virtual void OnActivated() = 0;
+
+ // Sent when the window loses active status.
+ virtual void OnLostActive() = 0;
+
+ protected:
+ virtual ~ActivationDelegate() {}
+};
+
+} // namespace aura
+
+#endif // UI_AURA_CLIENT_ACTIVATION_DELEGATE_H_
diff --git a/ui/aura/client/aura_constants.cc b/ui/aura/client/aura_constants.cc
index 9536a1f..c1d0d6e 100644
--- a/ui/aura/client/aura_constants.cc
+++ b/ui/aura/client/aura_constants.cc
@@ -6,14 +6,19 @@
namespace aura {
+// Alphabetical sort.
+const char kActivationDelegateKey[] = "ActivationDelegate";
const char kAlwaysOnTopKey[] = "AlwaysOnTop";
-const char kRestoreBoundsKey[] = "RestoreBounds";
-const char kShowStateKey[] = "ShowState";
-const char kTooltipTextKey[] = "TooltipText";
+const char kDragDropDelegateKey[] = "DragDropDelegate";
const char kModalKey[] = "Modal";
-const char kShadowTypeKey[] = "ShadowType";
+const char kRestoreBoundsKey[] = "RestoreBounds";
const char kRootWindowDragDropClientKey[] = "RootWindowDragDropClient";
-const char kDragDropDelegateKey[] = "DragDropDelegate";
const char kRootWindowTooltipClientKey[] = "RootWindowTooltipClient";
+const char kRootWindowActiveWindow[] = "RootWindowActiveWindow";
+const char kRootWindowActivationClient[] = "RootWindowActivationClient";
+const char kShadowTypeKey[] = "ShadowType";
+const char kShowStateKey[] = "ShowState";
+const char kTooltipTextKey[] = "TooltipText";
+// Alphabetical sort.
} // namespace aura
diff --git a/ui/aura/client/aura_constants.h b/ui/aura/client/aura_constants.h
index c756396..f5f2920 100644
--- a/ui/aura/client/aura_constants.h
+++ b/ui/aura/client/aura_constants.h
@@ -9,41 +9,57 @@
#include "ui/aura/aura_export.h"
namespace aura {
-// Window property keys that are shared between aura_shell and chrome/views.
+
+// Alphabetical sort.
+
+// A property key to store the activation delegate for a window. The type of the
+// value is |aura::ActivationDelegate*|.
+AURA_EXPORT extern const char kActivationDelegateKey[];
// A property key to store always-on-top flag. The type of the value is boolean.
AURA_EXPORT extern const char kAlwaysOnTopKey[];
+// A property key to store the drag and drop delegate for a window. The type of
+// the value is |aura::WindowDragDropDelegate*|.
+AURA_EXPORT extern const char kDragDropDelegateKey[];
+
+// A property key to store the boolean property of window modality.
+AURA_EXPORT extern const char kModalKey[];
+
// A property key to store the restore bounds for a window. The type
// of the value is |gfx::Rect*|.
AURA_EXPORT extern const char kRestoreBoundsKey[];
-// A property key to store ui::WindowShowState for a window.
-// See ui/base/ui_base_types.h for its definition.
-AURA_EXPORT extern const char kShowStateKey[];
+// A property key to store the drag and drop client for the root window. The
+// type of the value is |aura::DragDropClient*|.
+AURA_EXPORT extern const char kRootWindowDragDropClientKey[];
-// A property key to store tooltip text for a window. The type of the value
-// is |string16*|.
-AURA_EXPORT extern const char kTooltipTextKey[];
+// A property key to store the tooltip client for the root window. The type of
+// the value is |aura::TooltipClient*|.
+AURA_EXPORT extern const char kRootWindowTooltipClientKey[];
-// A property key to store the boolean property of window modality.
-AURA_EXPORT extern const char kModalKey[];
+// A property key to store what the client defines as the active window on the
+// RootWindow. The type of the value is |aura::Window*|.
+AURA_EXPORT extern const char kRootWindowActiveWindow[];
+
+// A property key to store a client that handles window activation. The type of
+// the value is |aura::ActivationClient*|.
+AURA_EXPORT extern const char kRootWindowActivationClient[];
// A property key for a value from aura::ShadowType describing the drop shadow
// that should be displayed under the window. If unset, no shadow is displayed.
AURA_EXPORT extern const char kShadowTypeKey[];
-// A property key to store the drag and drop client for the root window. The
-// type of the value is |aura::DragDropClient*|.
-AURA_EXPORT extern const char kRootWindowDragDropClientKey[];
+// A property key to store ui::WindowShowState for a window.
+// See ui/base/ui_base_types.h for its definition.
+AURA_EXPORT extern const char kShowStateKey[];
-// A property key to store the drag and drop delegate for a window. The type of
-// the value is |aura::WindowDragDropDelegate*|.
-AURA_EXPORT extern const char kDragDropDelegateKey[];
+// A property key to store tooltip text for a window. The type of the value
+// is |string16*|.
+AURA_EXPORT extern const char kTooltipTextKey[];
+
+// Alphabetical sort.
-// A property key to store the tooltip client for the root window. The type of
-// the value is |aura::TooltipClient*|.
-AURA_EXPORT extern const char kRootWindowTooltipClientKey[];
} // namespace aura
#endif // UI_AURA_CLIENT_AURA_CONSTANTS_H_
diff --git a/ui/aura/client/stacking_client.h b/ui/aura/client/stacking_client.h
index 26d137b..6e89636 100644
--- a/ui/aura/client/stacking_client.h
+++ b/ui/aura/client/stacking_client.h
@@ -21,14 +21,6 @@ class AURA_EXPORT StackingClient {
// an opportunity to inspect the window and add it to a default parent window
// of its choosing.
virtual void AddChildToDefaultParent(Window* window) = 0;
-
- // Returns true if |window| can be activated or deactivated.
- // A window manager typically defines some notion of "top level window" that
- // supports activation/deactivation.
- virtual bool CanActivateWindow(Window* window) const = 0;
-
- // Returns the window that should be activated other than |ignore|.
- virtual Window* GetTopmostWindowToActivate(Window* ignore) const = 0;
};
} // namespace aura
diff --git a/ui/aura/demo/demo_main.cc b/ui/aura/demo/demo_main.cc
index 76b87bd..817ec7f 100644
--- a/ui/aura/demo/demo_main.cc
+++ b/ui/aura/demo/demo_main.cc
@@ -54,9 +54,6 @@ class DemoWindowDelegate : public aura::WindowDelegate {
return ui::TOUCH_STATUS_END;
}
virtual bool CanFocus() OVERRIDE { return true; }
- virtual bool ShouldActivate(aura::Event* event) OVERRIDE { return true; }
- virtual void OnActivated() OVERRIDE {}
- virtual void OnLostActive() OVERRIDE {}
virtual void OnCaptureLost() OVERRIDE {}
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
canvas->GetSkCanvas()->drawColor(color_, SkXfermode::kSrc_Mode);
diff --git a/ui/aura/root_window.cc b/ui/aura/root_window.cc
index c0eb9b8..7396ad6 100644
--- a/ui/aura/root_window.cc
+++ b/ui/aura/root_window.cc
@@ -14,6 +14,7 @@
#include "base/string_number_conversions.h"
#include "base/string_split.h"
#include "ui/aura/aura_switches.h"
+#include "ui/aura/client/activation_client.h"
#include "ui/aura/client/drag_drop_client.h"
#include "ui/aura/client/stacking_client.h"
#include "ui/aura/client/tooltip_client.h"
@@ -69,20 +70,6 @@ class DefaultStackingClient : public StackingClient {
virtual void AddChildToDefaultParent(Window* window) OVERRIDE {
root_window_->AddChild(window);
}
- virtual bool CanActivateWindow(Window* window) const OVERRIDE {
- return window->parent() == root_window_;
- }
- virtual Window* GetTopmostWindowToActivate(Window* ignore) const OVERRIDE {
- Window::Windows::const_reverse_iterator i;
- for (i = root_window_->children().rbegin();
- i != root_window_->children().rend();
- ++i) {
- if (*i == ignore)
- continue;
- return *i;
- }
- return NULL;
- }
RootWindow* root_window_;
@@ -247,55 +234,6 @@ void RootWindow::OnNativeScreenResized(const gfx::Size& size) {
SetHostSize(size);
}
-void RootWindow::SetActiveWindow(Window* window, Window* to_focus) {
- if (!window)
- return;
- // The stacking client may impose rules on what window configurations can be
- // activated or deactivated.
- if (!stacking_client_->CanActivateWindow(window))
- return;
- // The window may not be activate-able.
- if (!window->CanActivate())
- return;
- // Nothing may actually have changed.
- if (active_window_ == window)
- return;
-
- Window* old_active = active_window_;
- active_window_ = window;
- // Invoke OnLostActive after we've changed the active window. That way if the
- // delegate queries for active state it doesn't think the window is still
- // active.
- if (old_active && old_active->delegate())
- old_active->delegate()->OnLostActive();
- if (active_window_) {
- active_window_->parent()->StackChildAtTop(active_window_);
- if (active_window_->delegate())
- active_window_->delegate()->OnActivated();
- active_window_->GetFocusManager()->SetFocusedWindow(
- to_focus ? to_focus : active_window_);
- }
- FOR_EACH_OBSERVER(RootWindowObserver, observers_,
- OnActiveWindowChanged(active_window_));
-}
-
-void RootWindow::ActivateTopmostWindow() {
- SetActiveWindow(stacking_client_->GetTopmostWindowToActivate(NULL), NULL);
-}
-
-void RootWindow::Deactivate(Window* window) {
- // The stacking client may impose rules on what window configurations can be
- // activated or deactivated.
- if (!window || !stacking_client_->CanActivateWindow(window))
- return;
- if (active_window_ != window)
- return;
-
- Window* to_activate = stacking_client_->GetTopmostWindowToActivate(window);
- if (to_activate)
- SetActiveWindow(to_activate, NULL);
-}
-
void RootWindow::WindowInitialized(Window* window) {
FOR_EACH_OBSERVER(RootWindowObserver, observers_,
OnWindowInitialized(window));
@@ -317,25 +255,17 @@ void RootWindow::WindowDestroying(Window* window) {
capture_window_ = NULL;
if (touch_event_handler_ == window)
touch_event_handler_ = NULL;
-
- if (in_destructor_ || window != active_window_)
- return;
-
- // Reset active_window_ before invoking SetActiveWindow so that we don't
- // attempt to notify it while running its destructor.
- active_window_ = NULL;
- SetActiveWindow(stacking_client_->GetTopmostWindowToActivate(window), NULL);
}
MessageLoop::Dispatcher* RootWindow::GetDispatcher() {
return host_.get();
}
-void RootWindow::AddObserver(RootWindowObserver* observer) {
+void RootWindow::AddRootWindowObserver(RootWindowObserver* observer) {
observers_.AddObserver(observer);
}
-void RootWindow::RemoveObserver(RootWindowObserver* observer) {
+void RootWindow::RemoveRootWindowObserver(RootWindowObserver* observer) {
observers_.RemoveObserver(observer);
}
@@ -406,10 +336,8 @@ RootWindow::RootWindow()
ALLOW_THIS_IN_INITIALIZER_LIST(
stacking_client_(new DefaultStackingClient(this))),
ALLOW_THIS_IN_INITIALIZER_LIST(schedule_paint_factory_(this)),
- active_window_(NULL),
mouse_button_flags_(0),
last_cursor_(kCursorNull),
- in_destructor_(false),
screen_(new ScreenAura),
capture_window_(NULL),
mouse_pressed_handler_(NULL),
@@ -434,7 +362,6 @@ RootWindow::RootWindow()
}
RootWindow::~RootWindow() {
- in_destructor_ = true;
// Make sure to destroy the compositor before terminating so that state is
// cleared and we don't hit asserts.
compositor_ = NULL;
@@ -571,15 +498,28 @@ void RootWindow::OnLayerAnimationAborted(
}
void RootWindow::SetFocusedWindow(Window* focused_window) {
- if (focused_window == focused_window_ ||
- (focused_window && !focused_window->CanFocus())) {
+ 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 && ActivationClient::GetActivationClient() &&
+ !ActivationClient::GetActivationClient()->CanFocusWindow(
+ focused_window)) {
return;
}
+
if (focused_window_ && focused_window_->delegate())
focused_window_->delegate()->OnBlur();
focused_window_ = focused_window;
if (focused_window_ && focused_window_->delegate())
focused_window_->delegate()->OnFocus();
+ if (focused_window_) {
+ FOR_EACH_OBSERVER(RootWindowObserver, observers_,
+ OnWindowFocused(focused_window_));
+ }
}
Window* RootWindow::GetFocusedWindow() {
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index ddefbe7..52640dc 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -57,7 +57,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
gfx::Point last_mouse_location() const { return last_mouse_location_; }
gfx::NativeCursor last_cursor() const { return last_cursor_; }
StackingClient* stacking_client() { return stacking_client_.get(); }
- Window* active_window() { return active_window_; }
Window* mouse_pressed_handler() { return mouse_pressed_handler_; }
Window* capture_window() { return capture_window_; }
ScreenAura* screen() { return screen_; }
@@ -95,20 +94,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
// Called when the native screen's resolution changes.
void OnNativeScreenResized(const gfx::Size& size);
- // Sets the active window to |window| and the focused window to |to_focus|.
- // If |to_focus| is NULL, |window| is focused. Does nothing if |window| is
- // NULL.
- void SetActiveWindow(Window* window, Window* to_focus);
-
- // Activates the topmost window. Does nothing if the topmost window is already
- // active.
- void ActivateTopmostWindow();
-
- // Deactivates |window| and activates the topmost window. Does nothing if
- // |window| is not a topmost window, or there are no other suitable windows to
- // activate.
- void Deactivate(Window* window);
-
// Invoked when |window| is initialized.
void WindowInitialized(Window* window);
@@ -122,8 +107,8 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
MessageLoop::Dispatcher* GetDispatcher();
// Add/remove observer.
- void AddObserver(RootWindowObserver* observer);
- void RemoveObserver(RootWindowObserver* observer);
+ void AddRootWindowObserver(RootWindowObserver* observer);
+ void RemoveRootWindowObserver(RootWindowObserver* observer);
// Are any mouse buttons currently down?
bool IsMouseButtonDown() const;
@@ -208,8 +193,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
// Used to schedule painting.
base::WeakPtrFactory<RootWindow> schedule_paint_factory_;
- Window* active_window_;
-
// Last location seen in a mouse event.
gfx::Point last_mouse_location_;
@@ -219,10 +202,6 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
// Last cursor set. Used for testing.
gfx::NativeCursor last_cursor_;
- // Are we in the process of being destroyed? Used to avoid processing during
- // destruction.
- bool in_destructor_;
-
ObserverList<RootWindowObserver> observers_;
ScreenAura* screen_;
diff --git a/ui/aura/root_window_observer.h b/ui/aura/root_window_observer.h
index 41417f2..8cc48e6 100644
--- a/ui/aura/root_window_observer.h
+++ b/ui/aura/root_window_observer.h
@@ -24,9 +24,8 @@ class AURA_EXPORT RootWindowObserver {
// Invoked when a new window is initialized.
virtual void OnWindowInitialized(Window* window) {}
- // Invoked when the active window is changed. |active| may be NULL if there is
- // not active window.
- virtual void OnActiveWindowChanged(Window* active) {}
+ // Invoked when a window is focused.
+ virtual void OnWindowFocused(Window* window) {}
protected:
virtual ~RootWindowObserver() {}
diff --git a/ui/aura/test/test_activation_client.cc b/ui/aura/test/test_activation_client.cc
new file mode 100644
index 0000000..6f32ea7
--- /dev/null
+++ b/ui/aura/test/test_activation_client.cc
@@ -0,0 +1,59 @@
+// 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/test/test_activation_client.h"
+
+#include "ui/aura/window.h"
+
+namespace aura {
+namespace test {
+
+////////////////////////////////////////////////////////////////////////////////
+// TestActivationClient, public:
+
+TestActivationClient::TestActivationClient() : active_window_(NULL) {
+ ActivationClient::SetActivationClient(this);
+}
+
+TestActivationClient::~TestActivationClient() {
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// TestActivationClient, ActivationClient implementation:
+
+void TestActivationClient::ActivateWindow(Window* window) {
+ if (active_window_)
+ active_window_->RemoveObserver(this);
+ active_window_ = window;
+ active_window_->AddObserver(this);
+}
+
+void TestActivationClient::DeactivateWindow(Window* window) {
+ if (window == active_window_) {
+ if (active_window_)
+ active_window_->RemoveObserver(this);
+ active_window_ = NULL;
+ }
+}
+
+Window* TestActivationClient::GetActiveWindow() {
+ return active_window_;
+}
+
+bool TestActivationClient::CanFocusWindow(Window* window) const {
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// TestActivationClient, WindowObserver implementation:
+
+void TestActivationClient::OnWindowDestroyed(Window* window) {
+ if (window == active_window_) {
+ window->RemoveObserver(this);
+ active_window_ = NULL;
+ }
+}
+
+} // namespace test
+} // namespace aura
diff --git a/ui/aura/test/test_activation_client.h b/ui/aura/test/test_activation_client.h
new file mode 100644
index 0000000..22d56e5
--- /dev/null
+++ b/ui/aura/test/test_activation_client.h
@@ -0,0 +1,44 @@
+// 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.
+
+#ifndef UI_AURA_TEST_TEST_ACTIVATION_CLIENT_H_
+#define UI_AURA_TEST_TEST_ACTIVATION_CLIENT_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "base/logging.h"
+#include "ui/aura/client/activation_client.h"
+#include "ui/aura/window_observer.h"
+
+namespace aura {
+namespace test {
+
+class TestActivationClient : public ActivationClient, public WindowObserver {
+ public:
+ TestActivationClient();
+ virtual ~TestActivationClient();
+
+ // Overridden from ActivationClient:
+ virtual void ActivateWindow(Window* window) OVERRIDE;
+ virtual void DeactivateWindow(Window* window) OVERRIDE;
+ virtual Window* GetActiveWindow() OVERRIDE;
+ virtual bool CanFocusWindow(Window* window) const OVERRIDE;
+
+ // Overridden from WindowObserver:
+ virtual void OnWindowDestroyed(Window* window) OVERRIDE;
+
+ private:
+ // This class explicitly does NOT store the active window in a window property
+ // to make sure that storing the active window in a property is not treated as
+ // part of the aura API. Assumptions to that end will cause tests that use
+ // this client to fail.
+ Window* active_window_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestActivationClient);
+};
+
+} // namespace test
+} // namespace aura
+
+#endif // UI_AURA_TEST_TEST_ACTIVATION_CLIENT_H_ \ No newline at end of file
diff --git a/ui/aura/test/test_stacking_client.cc b/ui/aura/test/test_stacking_client.cc
index 4c3ce31..18048f3 100644
--- a/ui/aura/test/test_stacking_client.cc
+++ b/ui/aura/test/test_stacking_client.cc
@@ -26,20 +26,5 @@ void TestStackingClient::AddChildToDefaultParent(Window* window) {
default_container_->AddChild(window);
}
-bool TestStackingClient::CanActivateWindow(Window* window) const {
- return window->parent() == default_container_;
-}
-
-Window* TestStackingClient::GetTopmostWindowToActivate(Window* ignore) const {
- for (aura::Window::Windows::const_reverse_iterator i =
- default_container_->children().rbegin();
- i != default_container_->children().rend();
- ++i) {
- if (*i != ignore && (*i)->CanActivate())
- return *i;
- }
- return NULL;
-}
-
} // namespace test
} // namespace aura
diff --git a/ui/aura/test/test_stacking_client.h b/ui/aura/test/test_stacking_client.h
index 3ea0ba5..73d9382 100644
--- a/ui/aura/test/test_stacking_client.h
+++ b/ui/aura/test/test_stacking_client.h
@@ -29,8 +29,6 @@ class TestStackingClient : public StackingClient {
private:
// Overridden from StackingClient:
virtual void AddChildToDefaultParent(Window* window) OVERRIDE;
- virtual bool CanActivateWindow(Window* window) const OVERRIDE;
- virtual Window* GetTopmostWindowToActivate(Window* ignore) const OVERRIDE;
scoped_ptr<Window> default_container_;
diff --git a/ui/aura/test/test_window_delegate.cc b/ui/aura/test/test_window_delegate.cc
index 4a4f778..661e168 100644
--- a/ui/aura/test/test_window_delegate.cc
+++ b/ui/aura/test/test_window_delegate.cc
@@ -60,16 +60,6 @@ bool TestWindowDelegate::CanFocus() {
return true;
}
-bool TestWindowDelegate::ShouldActivate(Event* event) {
- return true;
-}
-
-void TestWindowDelegate::OnActivated() {
-}
-
-void TestWindowDelegate::OnLostActive() {
-}
-
void TestWindowDelegate::OnCaptureLost() {
}
@@ -107,33 +97,5 @@ void ColorTestWindowDelegate::OnPaint(gfx::Canvas* canvas) {
canvas->GetSkCanvas()->drawColor(color_, SkXfermode::kSrc_Mode);
}
-////////////////////////////////////////////////////////////////////////////////
-// ActivateWindowDelegate
-
-ActivateWindowDelegate::ActivateWindowDelegate()
- : activate_(true),
- activated_count_(0),
- lost_active_count_(0),
- should_activate_count_(0) {
-}
-
-ActivateWindowDelegate::ActivateWindowDelegate(bool activate)
- : activate_(activate),
- activated_count_(0),
- lost_active_count_(0),
- should_activate_count_(0) {
-}
-
-bool ActivateWindowDelegate::ShouldActivate(Event* event) {
- should_activate_count_++;
- return activate_;
-}
-void ActivateWindowDelegate::OnActivated() {
- activated_count_++;
-}
-void ActivateWindowDelegate::OnLostActive() {
- lost_active_count_++;
-}
-
} // namespace test
} // namespace aura
diff --git a/ui/aura/test/test_window_delegate.h b/ui/aura/test/test_window_delegate.h
index 08f1d6f..12b241b 100644
--- a/ui/aura/test/test_window_delegate.h
+++ b/ui/aura/test/test_window_delegate.h
@@ -31,9 +31,6 @@ class TestWindowDelegate : public WindowDelegate {
virtual bool OnMouseEvent(MouseEvent* event) OVERRIDE;
virtual ui::TouchStatus OnTouchEvent(TouchEvent* event) OVERRIDE;
virtual bool CanFocus() OVERRIDE;
- virtual bool ShouldActivate(Event* event) OVERRIDE;
- virtual void OnActivated() OVERRIDE;
- virtual void OnLostActive() OVERRIDE;
virtual void OnCaptureLost() OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
virtual void OnWindowDestroying() OVERRIDE;
@@ -65,33 +62,6 @@ class ColorTestWindowDelegate : public TestWindowDelegate {
DISALLOW_COPY_AND_ASSIGN(ColorTestWindowDelegate);
};
-class ActivateWindowDelegate : public TestWindowDelegate {
- public:
- ActivateWindowDelegate();
- explicit ActivateWindowDelegate(bool activate);
-
- void set_activate(bool v) { activate_ = v; }
- int activated_count() const { return activated_count_; }
- int lost_active_count() const { return lost_active_count_; }
- int should_activate_count() const { return should_activate_count_; }
- void Clear() {
- activated_count_ = lost_active_count_ = should_activate_count_ = 0;
- }
-
- // Overridden from TestWindowDelegate:
- virtual bool ShouldActivate(Event* event) OVERRIDE;
- virtual void OnActivated() OVERRIDE;
- virtual void OnLostActive() OVERRIDE;
-
- private:
- bool activate_;
- int activated_count_;
- int lost_active_count_;
- int should_activate_count_;
-
- DISALLOW_COPY_AND_ASSIGN(ActivateWindowDelegate);
-};
-
} // namespace test
} // namespace aura
diff --git a/ui/aura/window.cc b/ui/aura/window.cc
index 74721fa..8a10667 100644
--- a/ui/aura/window.cc
+++ b/ui/aura/window.cc
@@ -103,10 +103,6 @@ void Window::Show() {
void Window::Hide() {
SetVisible(false);
ReleaseCapture();
- if (RootWindow::GetInstance()->active_window() == this ||
- !RootWindow::GetInstance()->active_window()) {
- RootWindow::GetInstance()->ActivateTopmostWindow();
- }
}
bool Window::IsVisible() const {
@@ -121,19 +117,6 @@ gfx::Rect Window::GetScreenBounds() const {
return gfx::Rect(origin, bounds().size());
}
-void Window::Activate() {
- // If we support minimization need to ensure this restores the window first.
- aura::RootWindow::GetInstance()->SetActiveWindow(this, this);
-}
-
-void Window::Deactivate() {
- aura::RootWindow::GetInstance()->Deactivate(this);
-}
-
-bool Window::IsActive() const {
- return aura::RootWindow::GetInstance()->active_window() == this;
-}
-
void Window::SetTransform(const ui::Transform& transform) {
layer()->SetTransform(transform);
}
@@ -219,10 +202,6 @@ void Window::StackChildAbove(Window* child, Window* other) {
child->OnStackingChanged();
}
-bool Window::CanActivate() const {
- return IsVisible() && (!delegate_ || delegate_->ShouldActivate(NULL));
-}
-
void Window::AddChild(Window* child) {
DCHECK(std::find(children_.begin(), children_.end(), child) ==
children_.end());
diff --git a/ui/aura/window.h b/ui/aura/window.h
index 2c77d39..dcd115d 100644
--- a/ui/aura/window.h
+++ b/ui/aura/window.h
@@ -92,14 +92,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// Returns the window's bounds in screen coordinates.
gfx::Rect GetScreenBounds() const;
- // Activates this window. Only top level windows can be activated. Requests
- // to activate a non-top level window are ignored.
- void Activate();
-
- // Deactivates this window. Only top level windows can be
- // deactivated. Requests to deactivate a non-top level window are ignored.
- void Deactivate();
-
// Returns true if this window is active.
bool IsActive() const;
@@ -135,9 +127,6 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// |other|.
void StackChildAbove(Window* child, Window* other);
- // Returns true if this window can be activated.
- bool CanActivate() const;
-
// Tree operations.
// TODO(beng): Child windows are currently not owned by the hierarchy. We
// should change this.
@@ -248,7 +237,8 @@ class AURA_EXPORT Window : public ui::LayerDelegate {
// Sets the window property |value| for given |name|. Setting NULL or 0
// removes the property. It uses |ui::ViewProp| to store the property.
- // Please see the description of |prop_map_| for more details.
+ // Please see the description of |prop_map_| for more details. The caller is
+ // responsible for the lifetime of any object set as a property on the Window.
void SetProperty(const char* name, void* value);
void SetIntProperty(const char* name, int value);
diff --git a/ui/aura/window_delegate.h b/ui/aura/window_delegate.h
index f865511..25070c2 100644
--- a/ui/aura/window_delegate.h
+++ b/ui/aura/window_delegate.h
@@ -55,18 +55,6 @@ class AURA_EXPORT WindowDelegate {
// Returns true of the window can be focused.
virtual bool CanFocus() = 0;
- // Returns true if the window should be activated. |event| is either the mouse
- // event supplied if the activation is the result of a mouse, or the touch
- // event if the activation is the result of a touch, or NULL if activation is
- // attempted for another reason.
- virtual bool ShouldActivate(Event* event) = 0;
-
- // Sent when the window is activated.
- virtual void OnActivated() = 0;
-
- // Sent when the window loses active status.
- virtual void OnLostActive() = 0;
-
// Invoked when mouse capture is lost on the window.
virtual void OnCaptureLost() = 0;
diff --git a/ui/aura/window_unittest.cc b/ui/aura/window_unittest.cc
index d812446..ccd9fe8 100644
--- a/ui/aura/window_unittest.cc
+++ b/ui/aura/window_unittest.cc
@@ -544,70 +544,6 @@ TEST_F(WindowTest, MouseEnterExit) {
EXPECT_FALSE(d2.exited());
}
-namespace {
-
-class ActiveWindowDelegate : public TestWindowDelegate {
- public:
- ActiveWindowDelegate() : window_(NULL), was_active_(false), hit_count_(0) {
- }
-
- void set_window(Window* window) { window_ = window; }
-
- // Number of times OnLostActive has been invoked.
- int hit_count() const { return hit_count_; }
-
- // Was the window active from the first call to OnLostActive?
- bool was_active() const { return was_active_; }
-
- virtual void OnLostActive() OVERRIDE {
- if (hit_count_++ == 0)
- was_active_ = window_->IsActive();
- }
-
- private:
- Window* window_;
-
- // See description above getters for details on these.
- bool was_active_;
- int hit_count_;
-
- DISALLOW_COPY_AND_ASSIGN(ActiveWindowDelegate);
-};
-
-} // namespace
-
-// Verifies that when WindowDelegate::OnLostActive is invoked the window is not
-// active.
-TEST_F(WindowTest, NotActiveInLostActive) {
- RootWindow* root_window = RootWindow::GetInstance();
-
- ActiveWindowDelegate d1;
- scoped_ptr<Window> w1(
- CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(10, 10, 50, 50), NULL));
- d1.set_window(w1.get());
- scoped_ptr<Window> w2(
- CreateTestWindowWithDelegate(NULL, 1, gfx::Rect(10, 10, 50, 50), NULL));
-
- // Activate w1.
- root_window->SetActiveWindow(w1.get(), NULL);
- EXPECT_EQ(w1.get(), root_window->active_window());
-
- // Should not have gotten a OnLostActive yet.
- EXPECT_EQ(0, d1.hit_count());
-
- // SetActiveWindow(NULL) should not change the active window.
- root_window->SetActiveWindow(NULL, NULL);
- EXPECT_TRUE(root_window->active_window() == w1.get());
-
- // Now activate another window.
- root_window->SetActiveWindow(w2.get(), NULL);
-
- // Should have gotten OnLostActive and w1 should not have been active at that
- // time.
- EXPECT_EQ(1, d1.hit_count());
- EXPECT_FALSE(d1.was_active());
-}
-
// Creates a window with a delegate (w111) that can handle events at a lower
// z-index than a window without a delegate (w12). w12 is sized to fill the
// entire bounds of the container. This test verifies that
@@ -775,37 +711,6 @@ TEST_F(WindowTest, IgnoreEventsTest) {
EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160)));
}
-// Various assertions for activating/deactivating.
-TEST_F(WindowTest, Deactivate) {
- TestWindowDelegate d1;
- TestWindowDelegate d2;
- scoped_ptr<Window> w1(
- CreateTestWindowWithDelegate(&d1, 1, gfx::Rect(), NULL));
- scoped_ptr<Window> w2(
- CreateTestWindowWithDelegate(&d2, 2, gfx::Rect(), NULL));
- Window* parent = w1->parent();
- parent->Show();
- ASSERT_TRUE(parent);
- ASSERT_EQ(2u, parent->children().size());
- // Activate w2 and make sure it's active and frontmost.
- w2->Activate();
- EXPECT_TRUE(w2->IsActive());
- EXPECT_FALSE(w1->IsActive());
- EXPECT_EQ(w2.get(), parent->children()[1]);
-
- // Activate w1 and make sure it's active and frontmost.
- w1->Activate();
- EXPECT_TRUE(w1->IsActive());
- EXPECT_FALSE(w2->IsActive());
- EXPECT_EQ(w1.get(), parent->children()[1]);
-
- // Deactivate w1 and make sure w2 becomes active and frontmost.
- w1->Deactivate();
- EXPECT_FALSE(w1->IsActive());
- EXPECT_TRUE(w2->IsActive());
- EXPECT_EQ(w2.get(), parent->children()[1]);
-}
-
// Tests transformation on the root window.
TEST_F(WindowTest, Transform) {
RootWindow* root_window = RootWindow::GetInstance();
@@ -1121,56 +1026,5 @@ TEST_F(WindowObserverTest, PropertyChanged) {
EXPECT_EQ("name= old=0 new=0", PropertyChangeInfoAndClear());
}
-class RootWindowObserverTest : public WindowTest,
- public RootWindowObserver {
- public:
- RootWindowObserverTest() : active_(NULL) {
- }
-
- virtual ~RootWindowObserverTest() {}
-
- Window* active() const { return active_; }
-
- void Reset() {
- active_ = NULL;
- }
-
- private:
- virtual void SetUp() OVERRIDE {
- WindowTest::SetUp();
- RootWindow::GetInstance()->AddObserver(this);
- }
-
- virtual void TearDown() OVERRIDE {
- RootWindow::GetInstance()->RemoveObserver(this);
- WindowTest::TearDown();
- }
-
- virtual void OnActiveWindowChanged(Window* active) OVERRIDE {
- active_ = active;
- }
-
- Window* active_;
-
- DISALLOW_COPY_AND_ASSIGN(RootWindowObserverTest);
-};
-
-TEST_F(RootWindowObserverTest, WindowActivationObserve) {
- scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
- scoped_ptr<Window> w2(CreateTestWindowWithId(2, NULL));
- scoped_ptr<Window> w3(CreateTestWindowWithId(3, w1.get()));
-
- EXPECT_EQ(NULL, active());
-
- w2->Activate();
- EXPECT_EQ(w2.get(), active());
-
- w3->Activate();
- EXPECT_EQ(w2.get(), active());
-
- w1->Activate();
- EXPECT_EQ(w1.get(), active());
-}
-
} // namespace test
} // namespace aura