diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-23 01:04:56 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-23 01:04:56 +0000 |
commit | 7585967a09c178beb19d154411e16d0bf460b98c (patch) | |
tree | cc081a045d88728d3ec1afccdf603278f9a9fd6a /ui | |
parent | 7d578660a7d482216efbac91434fd30bb122a154 (diff) | |
download | chromium_src-7585967a09c178beb19d154411e16d0bf460b98c.zip chromium_src-7585967a09c178beb19d154411e16d0bf460b98c.tar.gz chromium_src-7585967a09c178beb19d154411e16d0bf460b98c.tar.bz2 |
Move some more files into ash... this time seed the window manager dir.
http://crbug.com/108457
TEST=none
TBR=sky
Review URL: http://codereview.chromium.org/9026017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115655 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
35 files changed, 36 insertions, 2705 deletions
diff --git a/ui/aura_shell/DEPS b/ui/aura_shell/DEPS index 9dd8332..6ac4b32 100644 --- a/ui/aura_shell/DEPS +++ b/ui/aura_shell/DEPS @@ -1,4 +1,5 @@ include_rules = [ + "+ash", "+grit/ui_resources.h", "+grit/ui_resources_standard.h", "+grit/ui_resources_large.h", diff --git a/ui/aura_shell/activation_controller.cc b/ui/aura_shell/activation_controller.cc deleted file mode 100644 index 0365fe6..0000000 --- a/ui/aura_shell/activation_controller.cc +++ /dev/null @@ -1,187 +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_shell/activation_controller.h" - -#include "base/auto_reset.h" -#include "ui/aura/client/activation_delegate.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/aura/window_delegate.h" -#include "ui/aura_shell/shell.h" -#include "ui/aura_shell/shell_window_ids.h" -#include "ui/aura_shell/window_util.h" - -namespace aura_shell { -namespace internal { -namespace { - -aura::Window* GetContainer(int id) { - return Shell::GetInstance()->GetContainer(id); -} - -// Returns true if children of |window| can be activated. -// These are the only containers in which windows can receive focus. -bool SupportsChildActivation(aura::Window* window) { - return window->id() == kShellWindowId_DefaultContainer || - window->id() == kShellWindowId_AlwaysOnTopContainer || - window->id() == kShellWindowId_ModalContainer || - window->id() == kShellWindowId_LockScreenContainer || - window->id() == kShellWindowId_LockModalContainer; -} - -// Returns true if |window| can be activated or deactivated. -// A window manager typically defines some notion of "top level window" that -// supports activation/deactivation. -bool CanActivateWindow(aura::Window* window) { - return window && - window->IsVisible() && - (!aura::client::GetActivationDelegate(window) || - aura::client::GetActivationDelegate(window)->ShouldActivate(NULL)) && - SupportsChildActivation(window->parent()); -} - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// -// ActivationController, public: - -ActivationController::ActivationController() - : updating_activation_(false), - default_container_for_test_(NULL) { - aura::client::SetActivationClient(this); - aura::RootWindow::GetInstance()->AddRootWindowObserver(this); -} - -ActivationController::~ActivationController() { - aura::RootWindow::GetInstance()->RemoveRootWindowObserver(this); -} - -// static -aura::Window* ActivationController::GetActivatableWindow(aura::Window* window) { - aura::Window* parent = window->parent(); - aura::Window* child = window; - while (parent) { - if (SupportsChildActivation(parent)) - return child; - // If |child| isn't activatable, but has transient parent, trace - // that path instead. - if (child->transient_parent()) - return GetActivatableWindow(child->transient_parent()); - parent = parent->parent(); - child = child->parent(); - } - return NULL; -} - -//////////////////////////////////////////////////////////////////////////////// -// ActivationController, aura::client::ActivationClient implementation: - -void ActivationController::ActivateWindow(aura::Window* window) { - // Prevent recursion when called from focus. - if (updating_activation_) - return; - - AutoReset<bool> in_activate_window(&updating_activation_, true); - if (!window) - return; - // Nothing may actually have changed. - aura::Window* old_active = GetActiveWindow(); - if (old_active == window) - return; - // The stacking client may impose rules on what window configurations can be - // activated or deactivated. - if (!CanActivateWindow(window)) - return; - - if (!window->Contains(window->GetFocusManager()->GetFocusedWindow())) - window->GetFocusManager()->SetFocusedWindow(window); - aura::RootWindow::GetInstance()->SetProperty( - aura::client::kRootWindowActiveWindow, - 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 && aura::client::GetActivationDelegate(old_active)) - aura::client::GetActivationDelegate(old_active)->OnLostActive(); - if (window) { - window->parent()->StackChildAtTop(window); - if (aura::client::GetActivationDelegate(window)) - aura::client::GetActivationDelegate(window)->OnActivated(); - } -} - -void ActivationController::DeactivateWindow(aura::Window* window) { - if (window) - ActivateNextWindow(window); -} - -aura::Window* ActivationController::GetActiveWindow() { - return reinterpret_cast<aura::Window*>( - aura::RootWindow::GetInstance()->GetProperty( - aura::client::kRootWindowActiveWindow)); -} - -bool ActivationController::CanFocusWindow(aura::Window* window) const { - return CanActivateWindow(GetActivatableWindow(window)); -} - -//////////////////////////////////////////////////////////////////////////////// -// ActivationController, aura::WindowObserver implementation: - -void ActivationController::OnWindowVisibilityChanged(aura::Window* window, - bool visible) { - if (!visible) - ActivateNextWindow(window); -} - -void ActivationController::OnWindowDestroyed(aura::Window* window) { - if (IsActiveWindow(window)) { - // Clear the property before activating something else, since - // ActivateWindow() will attempt to notify the window stored in this value - // otherwise. - aura::RootWindow::GetInstance()->SetProperty( - aura::client::kRootWindowActiveWindow, - NULL); - ActivateWindow(GetTopmostWindowToActivate(window)); - } - window->RemoveObserver(this); -} - -//////////////////////////////////////////////////////////////////////////////// -// ActivationController, aura::RootWindowObserver implementation: - -void ActivationController::OnWindowInitialized(aura::Window* window) { - window->AddObserver(this); -} - -void ActivationController::OnWindowFocused(aura::Window* window) { - ActivateWindow(GetActivatableWindow(window)); -} - -//////////////////////////////////////////////////////////////////////////////// -// ActivationController, private: - -void ActivationController::ActivateNextWindow(aura::Window* window) { - if (IsActiveWindow(window)) - ActivateWindow(GetTopmostWindowToActivate(window)); -} - -aura::Window* ActivationController::GetTopmostWindowToActivate( - aura::Window* ignore) const { - const aura::Window* container = - default_container_for_test_ ? default_container_for_test_ : - GetContainer(kShellWindowId_DefaultContainer); - for (aura::Window::Windows::const_reverse_iterator i = - container->children().rbegin(); - i != container->children().rend(); - ++i) { - if (*i != ignore && CanActivateWindow(*i)) - return *i; - } - return NULL; -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/activation_controller.h b/ui/aura_shell/activation_controller.h deleted file mode 100644 index a849d9b..0000000 --- a/ui/aura_shell/activation_controller.h +++ /dev/null @@ -1,77 +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. - -#ifndef UI_AURA_SHELL_ACTIVATION_CONTROLLER_H_ -#define UI_AURA_SHELL_ACTIVATION_CONTROLLER_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "ui/aura/client/activation_client.h" -#include "ui/aura/root_window_observer.h" -#include "ui/aura/window_observer.h" -#include "ui/aura_shell/aura_shell_export.h" - -namespace aura_shell { -namespace internal { - -// Exported for unit tests. -class AURA_SHELL_EXPORT ActivationController - : public aura::client::ActivationClient, - public aura::WindowObserver, - public aura::RootWindowObserver { - public: - ActivationController(); - virtual ~ActivationController(); - - // Returns true if |window| exists within a container that supports - // activation. - static aura::Window* GetActivatableWindow(aura::Window* window); - - // Overridden from aura::client::ActivationClient: - virtual void ActivateWindow(aura::Window* window) OVERRIDE; - virtual void DeactivateWindow(aura::Window* window) OVERRIDE; - virtual aura::Window* GetActiveWindow() OVERRIDE; - virtual bool CanFocusWindow(aura::Window* window) const OVERRIDE; - - // Overridden from aura::WindowObserver: - virtual void OnWindowVisibilityChanged(aura::Window* window, - bool visible) OVERRIDE; - virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; - - // Overridden from aura::RootWindowObserver: - virtual void OnWindowInitialized(aura::Window* window) OVERRIDE; - virtual void OnWindowFocused(aura::Window* window) OVERRIDE; - -#if defined(UNIT_TEST) - void set_default_container_for_test(aura::Window* window) { - default_container_for_test_ = window; - } -#endif - - private: - // Shifts activation to the next window, ignoring |window|. - void ActivateNextWindow(aura::Window* window); - - // Returns the next window that should be activated, ignoring |ignore|. - aura::Window* GetTopmostWindowToActivate(aura::Window* ignore) const; - - // True inside ActivateWindow(). Used to prevent recursion of focus - // change notifications causing activation. - bool updating_activation_; - - // For tests that are not running with a Shell instance, - // ActivationController's attempts to locate the next active window in - // GetTopmostWindowToActivate() will crash, so we provide this way for such - // tests to specify a default container. - aura::Window* default_container_for_test_; - - DISALLOW_COPY_AND_ASSIGN(ActivationController); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_ACTIVATION_CONTROLLER_H_ diff --git a/ui/aura_shell/activation_controller_unittest.cc b/ui/aura_shell/activation_controller_unittest.cc deleted file mode 100644 index c308d17..0000000 --- a/ui/aura_shell/activation_controller_unittest.cc +++ /dev/null @@ -1,280 +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_shell/activation_controller.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_windows.h" -#include "ui/aura/test/test_window_delegate.h" -#include "ui/aura_shell/test/aura_shell_test_base.h" -#include "ui/aura_shell/test/test_activation_delegate.h" -#include "ui/aura_shell/window_util.h" - -#if defined(OS_WIN) -// Windows headers define macros for these function names which screw with us. -#if defined(CreateWindow) -#undef CreateWindow -#endif -#endif - -namespace aura_shell { -namespace test { - -typedef test::AuraShellTestBase ActivationControllerTest; - -// Utilities for a set of tests that test -// ActivationController::GetTopmostWindowToActivate(). -class GetTopmostWindowToActivateTest : public ActivationControllerTest { - public: - GetTopmostWindowToActivateTest() : ad_1_(false), ad_3_(false) {} - virtual ~GetTopmostWindowToActivateTest() {} - - // Overridden from ActivationControllerTest: - virtual void SetUp() OVERRIDE { - ActivationControllerTest::SetUp(); - CreateWindows(); - } - virtual void TearDown() OVERRIDE { - DestroyWindows(); - ActivationControllerTest::TearDown(); - } - - protected: - aura::Window* w1() { return w1_.get(); } - aura::Window* w2() { return w2_.get(); } - aura::Window* w3() { return w3_.get(); } - aura::Window* w4() { return w4_.get(); } - - void DestroyWindow2() { - w2_.reset(); - } - - private: - void CreateWindows() { - // Create four windows, the first and third are not activatable, the second - // and fourth are. - w1_.reset(CreateWindow(1, &ad_1_)); - w2_.reset(CreateWindow(2, &ad_2_)); - w3_.reset(CreateWindow(3, &ad_3_)); - w4_.reset(CreateWindow(4, &ad_4_)); - } - - aura::Window* CreateWindow(int id, TestActivationDelegate* delegate) { - aura::Window* window = aura::test::CreateTestWindowWithDelegate( - &delegate_, id, gfx::Rect(), NULL); - delegate->SetWindow(window); - return window; - } - - void DestroyWindows() { - w1_.reset(); - w2_.reset(); - w3_.reset(); - w4_.reset(); - } - - aura::test::TestWindowDelegate delegate_; - TestActivationDelegate ad_1_; - TestActivationDelegate ad_2_; - TestActivationDelegate ad_3_; - TestActivationDelegate ad_4_; - scoped_ptr<aura::Window> w1_; // Non-activatable. - scoped_ptr<aura::Window> w2_; // Activatable. - scoped_ptr<aura::Window> w3_; // Non-activatable. - scoped_ptr<aura::Window> w4_; // Activatable. - - DISALLOW_COPY_AND_ASSIGN(GetTopmostWindowToActivateTest); -}; - -// Hiding the active window should activate the next valid activatable window. -TEST_F(GetTopmostWindowToActivateTest, HideActivatesNext) { - ActivateWindow(w2()); - EXPECT_TRUE(IsActiveWindow(w2())); - - w2()->Hide(); - EXPECT_TRUE(IsActiveWindow(w4())); -} - -// Destroying the active window should activate the next valid activatable -// window. -TEST_F(GetTopmostWindowToActivateTest, DestroyActivatesNext) { - ActivateWindow(w2()); - EXPECT_TRUE(IsActiveWindow(w2())); - - DestroyWindow2(); - EXPECT_EQ(NULL, w2()); - EXPECT_TRUE(IsActiveWindow(w4())); -} - -// Deactivating the active window should activate the next valid activatable -// window. -TEST_F(GetTopmostWindowToActivateTest, DeactivateActivatesNext) { - ActivateWindow(w2()); - EXPECT_TRUE(IsActiveWindow(w2())); - - DeactivateWindow(w2()); - EXPECT_TRUE(IsActiveWindow(w4())); -} - -// Test if the clicking on a menu picks the transient parent as activatable -// window. -TEST_F(ActivationControllerTest, ClickOnMenu) { - aura::test::TestWindowDelegate wd; - TestActivationDelegate ad1; - TestActivationDelegate ad2(false); - - scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( - &wd, 1, gfx::Rect(100, 100), NULL)); - ad1.SetWindow(w1.get()); - EXPECT_TRUE(IsActiveWindow(NULL)); - - // Clicking on an activatable window activtes the window. - aura::test::EventGenerator generator(w1.get()); - generator.ClickLeftButton(); - EXPECT_TRUE(IsActiveWindow(w1.get())); - - // Creates a menu that covers the transient parent. - scoped_ptr<aura::Window> menu(aura::test::CreateTestWindowWithDelegateAndType( - &wd, aura::client::WINDOW_TYPE_MENU, 2, gfx::Rect(100, 100), NULL)); - ad2.SetWindow(menu.get()); - w1->AddTransientChild(menu.get()); - - // Clicking on a menu whose transient parent is active window shouldn't - // change the active window. - generator.ClickLeftButton(); - EXPECT_TRUE(IsActiveWindow(w1.get())); -} - -// Various assertions for activating/deactivating. -TEST_F(ActivationControllerTest, Deactivate) { - aura::test::TestWindowDelegate d1; - aura::test::TestWindowDelegate d2; - scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( - &d1, 1, gfx::Rect(), NULL)); - scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( - &d2, 2, gfx::Rect(), NULL)); - aura::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. - ActivateWindow(w2.get()); - EXPECT_TRUE(IsActiveWindow(w2.get())); - EXPECT_FALSE(IsActiveWindow(w1.get())); - EXPECT_EQ(w2.get(), parent->children()[1]); - - // Activate w1 and make sure it's active and frontmost. - ActivateWindow(w1.get()); - EXPECT_TRUE(IsActiveWindow(w1.get())); - EXPECT_FALSE(IsActiveWindow(w2.get())); - EXPECT_EQ(w1.get(), parent->children()[1]); - - // Deactivate w1 and make sure w2 becomes active and frontmost. - DeactivateWindow(w1.get()); - EXPECT_FALSE(IsActiveWindow(w1.get())); - EXPECT_TRUE(IsActiveWindow(w2.get())); - EXPECT_EQ(w2.get(), parent->children()[1]); -} - -// Verifies that when WindowDelegate::OnLostActive is invoked the window is not -// active. -TEST_F(ActivationControllerTest, NotActiveInLostActive) { - TestActivationDelegate ad1; - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( - &wd, 1, gfx::Rect(10, 10, 50, 50), NULL)); - ad1.SetWindow(w1.get()); - scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( - NULL, 1, gfx::Rect(10, 10, 50, 50), NULL)); - - // Activate w1. - ActivateWindow(w1.get()); - EXPECT_TRUE(IsActiveWindow(w1.get())); - - // Should not have gotten a OnLostActive yet. - EXPECT_EQ(0, ad1.lost_active_count()); - - // ActivateWindow(NULL) should not change the active window. - ActivateWindow(NULL); - EXPECT_TRUE(IsActiveWindow(w1.get())); - - // Now activate another window. - ActivateWindow(w2.get()); - - // Should have gotten OnLostActive and w1 should not have been active at that - // time. - EXPECT_EQ(1, ad1.lost_active_count()); - EXPECT_FALSE(ad1.window_was_active()); -} - -// Verifies that focusing another window or its children causes it to become -// active. -TEST_F(ActivationControllerTest, FocusTriggersActivation) { - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( - &wd, -1, gfx::Rect(50, 50), NULL)); - scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( - &wd, -2, gfx::Rect(50, 50), NULL)); - scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( - &wd, -21, gfx::Rect(50, 50), w2.get())); - - ActivateWindow(w1.get()); - EXPECT_TRUE(IsActiveWindow(w1.get())); - EXPECT_TRUE(w1->HasFocus()); - - w2->Focus(); - EXPECT_TRUE(IsActiveWindow(w2.get())); - EXPECT_TRUE(w2->HasFocus()); - - ActivateWindow(w1.get()); - EXPECT_TRUE(IsActiveWindow(w1.get())); - EXPECT_TRUE(w1->HasFocus()); - - w21->Focus(); - EXPECT_TRUE(IsActiveWindow(w2.get())); - EXPECT_TRUE(w21->HasFocus()); -} - -// Verifies that we prevent all attempts to focus a child of a non-activatable -// window from claiming focus to that window. -TEST_F(ActivationControllerTest, PreventFocusToNonActivatableWindow) { - aura::test::TestWindowDelegate wd; - scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate( - &wd, -1, gfx::Rect(50, 50), NULL)); - // The RootWindow itself is a non-activatable parent. - scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate( - &wd, -2, gfx::Rect(50, 50), aura::RootWindow::GetInstance())); - scoped_ptr<aura::Window> w21(aura::test::CreateTestWindowWithDelegate( - &wd, -21, gfx::Rect(50, 50), w2.get())); - - ActivateWindow(w1.get()); - EXPECT_TRUE(IsActiveWindow(w1.get())); - EXPECT_TRUE(w1->HasFocus()); - - // Try activating |w2|. It's not a child of an activatable container, so it - // should neither be activated nor get focus. - ActivateWindow(w2.get()); - EXPECT_FALSE(IsActiveWindow(w2.get())); - EXPECT_FALSE(w2->HasFocus()); - EXPECT_TRUE(IsActiveWindow(w1.get())); - EXPECT_TRUE(w1->HasFocus()); - - // Try focusing |w2|. Same rules apply. - w2->Focus(); - EXPECT_FALSE(IsActiveWindow(w2.get())); - EXPECT_FALSE(w2->HasFocus()); - EXPECT_TRUE(IsActiveWindow(w1.get())); - EXPECT_TRUE(w1->HasFocus()); - - // Try focusing |w21|. Same rules apply. - EXPECT_FALSE(IsActiveWindow(w2.get())); - EXPECT_FALSE(w21->HasFocus()); - EXPECT_TRUE(IsActiveWindow(w1.get())); - EXPECT_TRUE(w1->HasFocus()); -} - -} // namespace test -} // namespace aura_shell diff --git a/ui/aura_shell/always_on_top_controller.cc b/ui/aura_shell/always_on_top_controller.cc deleted file mode 100644 index def6210..0000000 --- a/ui/aura_shell/always_on_top_controller.cc +++ /dev/null @@ -1,79 +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_shell/always_on_top_controller.h" - -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/window.h" - -namespace aura_shell { -namespace internal { - -AlwaysOnTopController::AlwaysOnTopController() - : default_container_(NULL), - always_on_top_container_(NULL) { -} - -AlwaysOnTopController::~AlwaysOnTopController() { - if (default_container_) - default_container_->RemoveObserver(this); - if (always_on_top_container_) - always_on_top_container_->RemoveObserver(this); -} - -void AlwaysOnTopController::SetContainers(aura::Window* default_container, - aura::Window* always_on_top_container) { - // Both containers should have no children. - DCHECK(default_container->children().empty()); - DCHECK(always_on_top_container->children().empty()); - - // We are not handling any containers yet. - DCHECK(default_container_ == NULL && always_on_top_container_ == NULL); - - default_container_ = default_container; - default_container_->AddObserver(this); - - always_on_top_container_ = always_on_top_container; - always_on_top_container_->AddObserver(this); -} - -aura::Window* AlwaysOnTopController::GetContainer(aura::Window* window) const { - DCHECK(default_container_ && always_on_top_container_); - return !window->GetProperty(aura::client::kAlwaysOnTopKey) ? - default_container_ : always_on_top_container_; -} - -void AlwaysOnTopController::OnWindowAdded(aura::Window* child) { - // Observe direct child of the containers. - if (child->parent() == default_container_ || - child->parent() == always_on_top_container_) { - child->AddObserver(this); - } -} - -void AlwaysOnTopController::OnWillRemoveWindow(aura::Window* child) { - child->RemoveObserver(this); -} - -void AlwaysOnTopController::OnWindowPropertyChanged(aura::Window* window, - const char* name, - void* old) { - if (name == aura::client::kAlwaysOnTopKey) { - DCHECK(window->type() == aura::client::WINDOW_TYPE_NORMAL || - window->type() == aura::client::WINDOW_TYPE_POPUP); - aura::Window* container = GetContainer(window); - if (window->parent() != container) - container->AddChild(window); - } -} - -void AlwaysOnTopController::OnWindowDestroyed(aura::Window* window) { - if (window == default_container_) - default_container_ = NULL; - if (window == always_on_top_container_) - always_on_top_container_ = NULL; -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/always_on_top_controller.h b/ui/aura_shell/always_on_top_controller.h deleted file mode 100644 index 19d1606..0000000 --- a/ui/aura_shell/always_on_top_controller.h +++ /dev/null @@ -1,54 +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. - -#ifndef UI_AURA_SHELL_ALWAYS_ON_TOP_CONTROLLER_H_ -#define UI_AURA_SHELL_ALWAYS_ON_TOP_CONTROLLER_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/aura/window_observer.h" - -namespace aura { -class Window; -} - -namespace aura_shell { -namespace internal { - -// AlwaysOnTopController puts window into proper containers based on its -// 'AlwaysOnTop' property. That is, putting a window to |default_container_| -// if its "AlwaysOnTop" property is false. Otherwise, put it in -// |always_on_top_container_|. -class AlwaysOnTopController : public aura::WindowObserver { - public: - AlwaysOnTopController(); - virtual ~AlwaysOnTopController(); - - // Sets the two top level window containers. - void SetContainers(aura::Window* default_container, - aura::Window* always_on_top_container); - - // Gets container for given |window| based on its "AlwaysOnTop" property. - aura::Window* GetContainer(aura::Window* window) const; - - private: - // Overridden from aura::WindowObserver: - virtual void OnWindowAdded(aura::Window* child) OVERRIDE; - virtual void OnWillRemoveWindow(aura::Window* child) OVERRIDE; - virtual void OnWindowPropertyChanged(aura::Window* window, - const char* name, - void* old) OVERRIDE; - virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; - - aura::Window* default_container_; - aura::Window* always_on_top_container_; - - DISALLOW_COPY_AND_ASSIGN(AlwaysOnTopController); -}; - -} // namepsace aura_shell -} // namepsace internal - -#endif // UI_AURA_SHELL_ALWAYS_ON_TOP_CONTROLLER_H_ diff --git a/ui/aura_shell/aura_shell.gyp b/ui/aura_shell/aura_shell.gyp index 4897d61..a19034d 100644 --- a/ui/aura_shell/aura_shell.gyp +++ b/ui/aura_shell/aura_shell.gyp @@ -33,10 +33,6 @@ ], 'sources': [ # All .cc, .h under views, except unittests - 'activation_controller.cc', - 'activation_controller.h', - 'always_on_top_controller.cc', - 'always_on_top_controller.h', 'app_list.cc', 'app_list.h', 'aura_shell_switches.cc', @@ -59,8 +55,6 @@ 'drag_drop_controller.h', 'drag_image_view.cc', 'drag_image_view.h', - 'image_grid.cc', - 'image_grid.h', 'launcher/app_launcher_button.cc', 'launcher/app_launcher_button.h', 'launcher/launcher.cc', @@ -77,19 +71,8 @@ 'launcher/view_model.h', 'launcher/view_model_utils.cc', 'launcher/view_model_utils.h', - 'modal_container_layout_manager.cc', - 'modal_container_layout_manager.h', - 'modality_event_filter.cc', - 'modality_event_filter.h', - 'modality_event_filter_delegate.h', 'property_util.cc', 'property_util.h', - 'shadow.cc', - 'shadow.h', - 'shadow_controller.cc', - 'shadow_controller.h', - 'shadow_types.cc', - 'shadow_types.h', 'shelf_layout_manager.cc', 'shelf_layout_manager.h', 'shell.cc', @@ -101,10 +84,6 @@ 'shell_delegate.h', 'shell_factory.h', 'shell_window_ids.h', - 'show_state_controller.h', - 'show_state_controller.cc', - 'stacking_controller.cc', - 'stacking_controller.h', 'status_area_layout_manager.cc', 'status_area_layout_manager.h', 'status_area_view.cc', @@ -130,6 +109,27 @@ 'workspace/workspace_manager.cc', 'workspace/workspace_manager.h', 'workspace/workspace_observer.h', + '../../ash/wm/activation_controller.cc', + '../../ash/wm/activation_controller.h', + '../../ash/wm/always_on_top_controller.cc', + '../../ash/wm/always_on_top_controller.h', + '../../ash/wm/image_grid.cc', + '../../ash/wm/image_grid.h', + '../../ash/wm/modal_container_layout_manager.cc', + '../../ash/wm/modal_container_layout_manager.h', + '../../ash/wm/modality_event_filter.cc', + '../../ash/wm/modality_event_filter.h', + '../../ash/wm/modality_event_filter_delegate.h', + '../../ash/wm/shadow.cc', + '../../ash/wm/shadow.h', + '../../ash/wm/shadow_controller.cc', + '../../ash/wm/shadow_controller.h', + '../../ash/wm/shadow_types.cc', + '../../ash/wm/shadow_types.h', + '../../ash/wm/show_state_controller.h', + '../../ash/wm/show_state_controller.cc', + '../../ash/wm/stacking_controller.cc', + '../../ash/wm/stacking_controller.h', ], }, { @@ -155,18 +155,14 @@ 'aura_shell', ], 'sources': [ - 'activation_controller_unittest.cc', 'default_container_layout_manager_unittest.cc', 'root_window_event_filter_unittest.cc', 'drag_drop_controller_unittest.cc', - 'image_grid_unittest.cc', 'launcher/launcher_model_unittest.cc', 'launcher/launcher_unittest.cc', 'launcher/view_model_unittest.cc', 'launcher/view_model_utils_unittest.cc', - 'modal_container_layout_manager_unittest.cc', 'run_all_unittests.cc', - 'shadow_controller_unittest.cc', 'shelf_layout_manager_unittest.cc', 'shell_accelerator_controller_unittest.cc', 'shell_unittest.cc', @@ -183,6 +179,10 @@ 'toplevel_window_event_filter_unittest.cc', 'workspace_controller_unittest.cc', 'workspace/workspace_manager_unittest.cc', + '../../ash/wm/activation_controller_unittest.cc', + '../../ash/wm/image_grid_unittest.cc', + '../../ash/wm/modal_container_layout_manager_unittest.cc', + '../../ash/wm/shadow_controller_unittest.cc', '<(SHARED_INTERMEDIATE_DIR)/ui/gfx/gfx_resources.rc', '<(SHARED_INTERMEDIATE_DIR)/ui/ui_resources/ui_resources.rc', diff --git a/ui/aura_shell/default_container_layout_manager.cc b/ui/aura_shell/default_container_layout_manager.cc index d646fec..d2a911d 100644 --- a/ui/aura_shell/default_container_layout_manager.cc +++ b/ui/aura_shell/default_container_layout_manager.cc @@ -4,6 +4,7 @@ #include "ui/aura_shell/default_container_layout_manager.h" +#include "ash/wm/show_state_controller.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/event.h" #include "ui/aura/root_window.h" @@ -11,7 +12,6 @@ #include "ui/aura/window.h" #include "ui/aura/window_observer.h" #include "ui/aura_shell/property_util.h" -#include "ui/aura_shell/show_state_controller.h" #include "ui/aura_shell/window_util.h" #include "ui/aura_shell/workspace/workspace.h" #include "ui/aura_shell/workspace/workspace_manager.h" diff --git a/ui/aura_shell/image_grid.cc b/ui/aura_shell/image_grid.cc deleted file mode 100644 index 99f8d90..0000000 --- a/ui/aura_shell/image_grid.cc +++ /dev/null @@ -1,246 +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_shell/image_grid.h" - -#include <algorithm> - -#include "ui/gfx/canvas.h" -#include "ui/gfx/image/image.h" -#include "ui/gfx/transform.h" -#include "third_party/skia/include/core/SkColor.h" -#include "third_party/skia/include/core/SkXfermode.h" - -using std::max; -using std::min; - -namespace aura_shell { -namespace internal { - -gfx::Rect ImageGrid::TestAPI::GetTransformedLayerBounds( - const ui::Layer& layer) { - gfx::Rect bounds = layer.bounds(); - layer.transform().TransformRect(&bounds); - return bounds; -} - -ImageGrid::ImageGrid() - : top_image_height_(0), - bottom_image_height_(0), - left_image_width_(0), - right_image_width_(0), - top_row_height_(0), - bottom_row_height_(0), - left_column_width_(0), - right_column_width_(0) { -} - -ImageGrid::~ImageGrid() { -} - -void ImageGrid::Init(const gfx::Image* top_left_image, - const gfx::Image* top_image, - const gfx::Image* top_right_image, - const gfx::Image* left_image, - const gfx::Image* center_image, - const gfx::Image* right_image, - const gfx::Image* bottom_left_image, - const gfx::Image* bottom_image, - const gfx::Image* bottom_right_image) { - layer_.reset(new ui::Layer(ui::Layer::LAYER_HAS_NO_TEXTURE)); - - InitImage(top_left_image, &top_left_layer_, &top_left_painter_); - InitImage(top_image, &top_layer_, &top_painter_); - InitImage(top_right_image, &top_right_layer_, &top_right_painter_); - InitImage(left_image, &left_layer_, &left_painter_); - InitImage(center_image, ¢er_layer_, ¢er_painter_); - InitImage(right_image, &right_layer_, &right_painter_); - InitImage(bottom_left_image, &bottom_left_layer_, &bottom_left_painter_); - InitImage(bottom_image, &bottom_layer_, &bottom_painter_); - InitImage(bottom_right_image, &bottom_right_layer_, &bottom_right_painter_); - - top_image_height_ = GetImageSize(top_image).height(); - bottom_image_height_ = GetImageSize(bottom_image).height(); - left_image_width_ = GetImageSize(left_image).width(); - right_image_width_ = GetImageSize(right_image).width(); - - top_row_height_ = max(GetImageSize(top_left_image).height(), - max(GetImageSize(top_image).height(), - GetImageSize(top_right_image).height())); - bottom_row_height_ = max(GetImageSize(bottom_left_image).height(), - max(GetImageSize(bottom_image).height(), - GetImageSize(bottom_right_image).height())); - left_column_width_ = max(GetImageSize(top_left_image).width(), - max(GetImageSize(left_image).width(), - GetImageSize(bottom_left_image).width())); - right_column_width_ = max(GetImageSize(top_right_image).width(), - max(GetImageSize(right_image).width(), - GetImageSize(bottom_right_image).width())); -} - -void ImageGrid::SetSize(const gfx::Size& size) { - if (size_ == size) - return; - - size_ = size; - - gfx::Rect updated_bounds = layer_->bounds(); - updated_bounds.set_size(size); - layer_->SetBounds(updated_bounds); - - float center_width = size.width() - left_column_width_ - right_column_width_; - float center_height = size.height() - top_row_height_ - bottom_row_height_; - - if (top_layer_.get()) { - if (center_width > 0) { - ui::Transform transform; - transform.SetScaleX(center_width / top_layer_->bounds().width()); - transform.ConcatTranslate(left_column_width_, 0); - top_layer_->SetTransform(transform); - } - top_layer_->SetVisible(center_width > 0); - } - if (bottom_layer_.get()) { - if (center_width > 0) { - ui::Transform transform; - transform.SetScaleX(center_width / bottom_layer_->bounds().width()); - transform.ConcatTranslate( - left_column_width_, size.height() - bottom_layer_->bounds().height()); - bottom_layer_->SetTransform(transform); - } - bottom_layer_->SetVisible(center_width > 0); - } - if (left_layer_.get()) { - if (center_height > 0) { - ui::Transform transform; - transform.SetScaleY(center_height / left_layer_->bounds().height()); - transform.ConcatTranslate(0, top_row_height_); - left_layer_->SetTransform(transform); - } - left_layer_->SetVisible(center_height > 0); - } - if (right_layer_.get()) { - if (center_height > 0) { - ui::Transform transform; - transform.SetScaleY(center_height / right_layer_->bounds().height()); - transform.ConcatTranslate( - size.width() - right_layer_->bounds().width(), top_row_height_); - right_layer_->SetTransform(transform); - } - right_layer_->SetVisible(center_height > 0); - } - - // Calculate the available amount of space for corner images on all sides of - // the grid. If the images don't fit, we need to clip them. - const int left = min(left_column_width_, size_.width() / 2); - const int right = min(right_column_width_, size_.width() - left); - const int top = min(top_row_height_, size_.height() / 2); - const int bottom = min(bottom_row_height_, size_.height() - top); - - if (top_left_layer_.get()) { - // No transformation needed; it should be at (0, 0) and unscaled. - top_left_painter_->SetClipRect( - LayerExceedsSize(top_left_layer_.get(), gfx::Size(left, top)) ? - gfx::Rect(gfx::Rect(0, 0, left, top)) : - gfx::Rect(), - top_left_layer_.get()); - } - if (top_right_layer_.get()) { - ui::Transform transform; - transform.SetTranslateX(size.width() - top_right_layer_->bounds().width()); - top_right_layer_->SetTransform(transform); - top_right_painter_->SetClipRect( - LayerExceedsSize(top_right_layer_.get(), gfx::Size(right, top)) ? - gfx::Rect(top_right_layer_->bounds().width() - right, 0, - right, top) : - gfx::Rect(), - top_right_layer_.get()); - } - if (bottom_left_layer_.get()) { - ui::Transform transform; - transform.SetTranslateY( - size.height() - bottom_left_layer_->bounds().height()); - bottom_left_layer_->SetTransform(transform); - bottom_left_painter_->SetClipRect( - LayerExceedsSize(bottom_left_layer_.get(), gfx::Size(left, bottom)) ? - gfx::Rect(0, bottom_left_layer_->bounds().height() - bottom, - left, bottom) : - gfx::Rect(), - bottom_left_layer_.get()); - } - if (bottom_right_layer_.get()) { - ui::Transform transform; - transform.SetTranslate( - size.width() - bottom_right_layer_->bounds().width(), - size.height() - bottom_right_layer_->bounds().height()); - bottom_right_layer_->SetTransform(transform); - bottom_right_painter_->SetClipRect( - LayerExceedsSize(bottom_right_layer_.get(), gfx::Size(right, bottom)) ? - gfx::Rect(bottom_right_layer_->bounds().width() - right, - bottom_right_layer_->bounds().height() - bottom, - right, bottom) : - gfx::Rect(), - bottom_right_layer_.get()); - } - - if (center_layer_.get()) { - if (center_width > 0 && center_height > 0) { - ui::Transform transform; - transform.SetScale(center_width / center_layer_->bounds().width(), - center_height / center_layer_->bounds().height()); - transform.ConcatTranslate(left_column_width_, top_row_height_); - center_layer_->SetTransform(transform); - } - center_layer_->SetVisible(center_width > 0 && center_height > 0); - } -} - -void ImageGrid::ImagePainter::SetClipRect(const gfx::Rect& clip_rect, - ui::Layer* layer) { - if (clip_rect != clip_rect_) { - clip_rect_ = clip_rect; - layer->ScheduleDraw(); - } -} - -void ImageGrid::ImagePainter::OnPaintLayer(gfx::Canvas* canvas) { - if (!clip_rect_.IsEmpty()) - canvas->ClipRect(clip_rect_); - canvas->DrawBitmapInt(*(image_->ToSkBitmap()), 0, 0); -} - -// static -gfx::Size ImageGrid::GetImageSize(const gfx::Image* image) { - return image ? - gfx::Size(image->ToSkBitmap()->width(), image->ToSkBitmap()->height()) : - gfx::Size(); -} - -// static -bool ImageGrid::LayerExceedsSize(const ui::Layer* layer, - const gfx::Size& size) { - return layer->bounds().width() > size.width() || - layer->bounds().height() > size.height(); -} - -void ImageGrid::InitImage(const gfx::Image* image, - scoped_ptr<ui::Layer>* layer_ptr, - scoped_ptr<ImagePainter>* painter_ptr) { - if (!image) - return; - - layer_ptr->reset(new ui::Layer(ui::Layer::LAYER_HAS_TEXTURE)); - - const gfx::Size size = GetImageSize(image); - layer_ptr->get()->SetBounds(gfx::Rect(0, 0, size.width(), size.height())); - - painter_ptr->reset(new ImagePainter(image)); - layer_ptr->get()->set_delegate(painter_ptr->get()); - layer_ptr->get()->SetFillsBoundsOpaquely(false); - layer_ptr->get()->SetVisible(true); - layer_->Add(layer_ptr->get()); -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/image_grid.h b/ui/aura_shell/image_grid.h deleted file mode 100644 index 892ab7f0..0000000 --- a/ui/aura_shell/image_grid.h +++ /dev/null @@ -1,212 +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. - -#ifndef UI_AURA_SHELL_IMAGE_GRID_H_ -#define UI_AURA_SHELL_IMAGE_GRID_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/gtest_prod_util.h" -#include "base/memory/scoped_ptr.h" -#include "ui/aura_shell/aura_shell_export.h" -#include "ui/gfx/compositor/layer.h" -#include "ui/gfx/compositor/layer_delegate.h" -#include "ui/gfx/rect.h" -#include "ui/gfx/size.h" - -namespace gfx { -class Image; -} // namespace gfx - -namespace aura_shell { -namespace internal { - -// An ImageGrid is a 3x3 array of ui::Layers, each containing an image. -// -// As the grid is resized, its images fill the requested space: -// - corner images are not scaled -// - top and bottom images are scaled horizontally -// - left and right images are scaled vertically -// - the center image is scaled in both directions -// -// If one of the non-center images is smaller than the largest images in its -// row or column, it will be aligned with the outside of the grid. For -// example, given 4x4 top-left and top-right images and a 1x2 top images: -// -// +--------+---------------------+--------+ -// | | top | | -// | top- +---------------------+ top- + -// | left | | right | -// +----+---+ +---+----+ -// | | | | -// ... -// -// This may seem odd at first, but it lets ImageGrid be used to draw shadows -// with curved corners that extend inwards beyond a window's borders. In the -// below example, the top-left corner image is overlaid on top of the window's -// top-left corner: -// -// +---------+----------------------- -// | ..xxx|XXXXXXXXXXXXXXXXXX -// | .xXXXXX|XXXXXXXXXXXXXXXXXX_____ -// | .xXX | ^ window's top edge -// | .xXX | -// +---------+ -// | xXX| -// | xXX|< window's left edge -// | xXX| -// ... -// -class AURA_SHELL_EXPORT ImageGrid { - public: - // Helper class for use by tests. - class TestAPI { - public: - TestAPI(ImageGrid* grid) : grid_(grid) {} - ui::Layer* top_left_layer() const { return grid_->top_left_layer_.get(); } - ui::Layer* top_layer() const { return grid_->top_layer_.get(); } - ui::Layer* top_right_layer() const { return grid_->top_right_layer_.get(); } - ui::Layer* left_layer() const { return grid_->left_layer_.get(); } - ui::Layer* center_layer() const { return grid_->center_layer_.get(); } - ui::Layer* right_layer() const { return grid_->right_layer_.get(); } - ui::Layer* bottom_left_layer() const { - return grid_->bottom_left_layer_.get(); - } - ui::Layer* bottom_layer() const { return grid_->bottom_layer_.get(); } - ui::Layer* bottom_right_layer() const { - return grid_->bottom_right_layer_.get(); - } - - gfx::Rect top_left_clip_rect() const { - return grid_->top_left_painter_->clip_rect_; - } - gfx::Rect top_right_clip_rect() const { - return grid_->top_right_painter_->clip_rect_; - } - gfx::Rect bottom_left_clip_rect() const { - return grid_->bottom_left_painter_->clip_rect_; - } - gfx::Rect bottom_right_clip_rect() const { - return grid_->bottom_right_painter_->clip_rect_; - } - - // Returns |layer|'s bounds after applying the layer's current transform. - gfx::Rect GetTransformedLayerBounds(const ui::Layer& layer); - - private: - ImageGrid* grid_; // not owned - - DISALLOW_COPY_AND_ASSIGN(TestAPI); - }; - - ImageGrid(); - ~ImageGrid(); - - ui::Layer* layer() { return layer_.get(); } - int top_image_height() const { return top_image_height_; } - int bottom_image_height() const { return bottom_image_height_; } - int left_image_width() const { return left_image_width_; } - int right_image_width() const { return right_image_width_; } - - // Initializes the grid to display the passed-in images (any of which can be - // NULL). Ownership of the images remains with the caller. - void Init(const gfx::Image* top_left_image, - const gfx::Image* top_image, - const gfx::Image* top_right_image, - const gfx::Image* left_image, - const gfx::Image* center_image, - const gfx::Image* right_image, - const gfx::Image* bottom_left_image, - const gfx::Image* bottom_image, - const gfx::Image* bottom_right_image); - - void SetSize(const gfx::Size& size); - - private: - // Delegate responsible for painting a specific image on a layer. - class ImagePainter : public ui::LayerDelegate { - public: - ImagePainter(const gfx::Image* image) : image_(image) {} - virtual ~ImagePainter() {} - - // Clips |layer| to |clip_rect|. Triggers a repaint if the clipping - // rectangle has changed. An empty rectangle disables clipping. - void SetClipRect(const gfx::Rect& clip_rect, ui::Layer* layer); - - // ui::LayerDelegate implementation: - virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE; - - private: - friend class TestAPI; - - const gfx::Image* image_; // not owned - - gfx::Rect clip_rect_; - - DISALLOW_COPY_AND_ASSIGN(ImagePainter); - }; - - // Returns the dimensions of |image| if non-NULL or gfx::Size(0, 0) otherwise. - static gfx::Size GetImageSize(const gfx::Image* image); - - // Returns true if |layer|'s bounds don't fit within |size|. - static bool LayerExceedsSize(const ui::Layer* layer, const gfx::Size& size); - - // Initializes |layer_ptr| and |painter_ptr| to display |image|. - // Also adds the passed-in layer to |layer_|. - void InitImage(const gfx::Image* image, - scoped_ptr<ui::Layer>* layer_ptr, - scoped_ptr<ImagePainter>* painter_ptr); - - // Layer that contains all of the image layers. - scoped_ptr<ui::Layer> layer_; - - // The grid's dimensions. - gfx::Size size_; - - // Heights and widths of the images displayed by |top_layer_|, - // |bottom_layer_|, |left_layer_|, and |right_layer_|. - int top_image_height_; - int bottom_image_height_; - int left_image_width_; - int right_image_width_; - - // Heights of the tallest images in the top and bottom rows and the widest - // images in the left and right columns. - int top_row_height_; - int bottom_row_height_; - int left_column_width_; - int right_column_width_; - - // Layers used to display the various images. Children of |layer_|. - // Positions for which no images were supplied are NULL. - scoped_ptr<ui::Layer> top_left_layer_; - scoped_ptr<ui::Layer> top_layer_; - scoped_ptr<ui::Layer> top_right_layer_; - scoped_ptr<ui::Layer> left_layer_; - scoped_ptr<ui::Layer> center_layer_; - scoped_ptr<ui::Layer> right_layer_; - scoped_ptr<ui::Layer> bottom_left_layer_; - scoped_ptr<ui::Layer> bottom_layer_; - scoped_ptr<ui::Layer> bottom_right_layer_; - - // Delegates responsible for painting the above layers. - // Positions for which no images were supplied are NULL. - scoped_ptr<ImagePainter> top_left_painter_; - scoped_ptr<ImagePainter> top_painter_; - scoped_ptr<ImagePainter> top_right_painter_; - scoped_ptr<ImagePainter> left_painter_; - scoped_ptr<ImagePainter> center_painter_; - scoped_ptr<ImagePainter> right_painter_; - scoped_ptr<ImagePainter> bottom_left_painter_; - scoped_ptr<ImagePainter> bottom_painter_; - scoped_ptr<ImagePainter> bottom_right_painter_; - - DISALLOW_COPY_AND_ASSIGN(ImageGrid); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_IMAGE_GRID_H_ diff --git a/ui/aura_shell/image_grid_unittest.cc b/ui/aura_shell/image_grid_unittest.cc deleted file mode 100644 index 185a0fa..0000000 --- a/ui/aura_shell/image_grid_unittest.cc +++ /dev/null @@ -1,272 +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 "testing/gtest/include/gtest/gtest.h" -#include "third_party/skia/include/core/SkBitmap.h" -#include "ui/aura_shell/image_grid.h" -#include "ui/aura_shell/test/aura_shell_test_base.h" -#include "ui/gfx/image/image.h" - -using aura_shell::internal::ImageGrid; - -namespace aura_shell { -namespace test { - -namespace { - -// Creates a gfx::Image with the requested dimensions. -gfx::Image* CreateImage(const gfx::Size& size) { - SkBitmap* bitmap = new SkBitmap(); - bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.width(), size.height()); - return new gfx::Image(bitmap); -} - -} // namespace - -typedef aura_shell::test::AuraShellTestBase ImageGridTest; - -// Test that an ImageGrid's layers are transformed correctly when SetSize() is -// called. -TEST_F(ImageGridTest, Basic) { - // Size of the images around the grid's border. - const int kBorder = 2; - - scoped_ptr<gfx::Image> image_1x1(CreateImage(gfx::Size(1, 1))); - scoped_ptr<gfx::Image> image_1xB(CreateImage(gfx::Size(1, kBorder))); - scoped_ptr<gfx::Image> image_Bx1(CreateImage(gfx::Size(kBorder, 1))); - scoped_ptr<gfx::Image> image_BxB(CreateImage(gfx::Size(kBorder, kBorder))); - - ImageGrid grid; - grid.Init(image_BxB.get(), image_1xB.get(), image_BxB.get(), - image_Bx1.get(), image_1x1.get(), image_Bx1.get(), - image_BxB.get(), image_1xB.get(), image_BxB.get()); - - ImageGrid::TestAPI test_api(&grid); - ASSERT_TRUE(test_api.top_left_layer() != NULL); - ASSERT_TRUE(test_api.top_layer() != NULL); - ASSERT_TRUE(test_api.top_right_layer() != NULL); - ASSERT_TRUE(test_api.left_layer() != NULL); - ASSERT_TRUE(test_api.center_layer() != NULL); - ASSERT_TRUE(test_api.right_layer() != NULL); - ASSERT_TRUE(test_api.bottom_left_layer() != NULL); - ASSERT_TRUE(test_api.bottom_layer() != NULL); - ASSERT_TRUE(test_api.bottom_right_layer() != NULL); - - const gfx::Size size(20, 30); - grid.SetSize(size); - - // The top-left layer should be flush with the top-left corner and unscaled. - EXPECT_EQ(gfx::Rect(0, 0, kBorder, kBorder).ToString(), - test_api.GetTransformedLayerBounds( - *test_api.top_left_layer()).ToString()); - - // The top layer should be flush with the top edge and stretched horizontally - // between the two top corners. - EXPECT_EQ(gfx::Rect( - kBorder, 0, size.width() - 2 * kBorder, kBorder).ToString(), - test_api.GetTransformedLayerBounds( - *test_api.top_layer()).ToString()); - - // The top-right layer should be flush with the top-right corner and unscaled. - EXPECT_EQ(gfx::Rect(size.width() - kBorder, 0, kBorder, kBorder).ToString(), - test_api.GetTransformedLayerBounds( - *test_api.top_right_layer()).ToString()); - - // The left layer should be flush with the left edge and stretched vertically - // between the two left corners. - EXPECT_EQ(gfx::Rect( - 0, kBorder, kBorder, size.height() - 2 * kBorder).ToString(), - test_api.GetTransformedLayerBounds( - *test_api.left_layer()).ToString()); - - // The center layer should fill the space in the middle of the grid. - EXPECT_EQ(gfx::Rect( - kBorder, kBorder, size.width() - 2 * kBorder, - size.height() - 2 * kBorder).ToString(), - test_api.GetTransformedLayerBounds( - *test_api.center_layer()).ToString()); - - // The right layer should be flush with the right edge and stretched - // vertically between the two right corners. - EXPECT_EQ(gfx::Rect( - size.width() - kBorder, kBorder, - kBorder, size.height() - 2 * kBorder).ToString(), - test_api.GetTransformedLayerBounds( - *test_api.right_layer()).ToString()); - - // The bottom-left layer should be flush with the bottom-left corner and - // unscaled. - EXPECT_EQ(gfx::Rect(0, size.height() - kBorder, kBorder, kBorder).ToString(), - test_api.GetTransformedLayerBounds( - *test_api.bottom_left_layer()).ToString()); - - // The bottom layer should be flush with the bottom edge and stretched - // horizontally between the two bottom corners. - EXPECT_EQ(gfx::Rect( - kBorder, size.height() - kBorder, - size.width() - 2 * kBorder, kBorder).ToString(), - test_api.GetTransformedLayerBounds( - *test_api.bottom_layer()).ToString()); - - // The bottom-right layer should be flush with the bottom-right corner and - // unscaled. - EXPECT_EQ(gfx::Rect( - size.width() - kBorder, size.height() - kBorder, - kBorder, kBorder).ToString(), - test_api.GetTransformedLayerBounds( - *test_api.bottom_right_layer()).ToString()); -} - -// Check that we don't crash if only a single image is supplied. -TEST_F(ImageGridTest, SingleImage) { - const int kBorder = 1; - scoped_ptr<gfx::Image> image(CreateImage(gfx::Size(kBorder, kBorder))); - - ImageGrid grid; - grid.Init(NULL, image.get(), NULL, - NULL, NULL, NULL, - NULL, NULL, NULL); - - ImageGrid::TestAPI test_api(&grid); - EXPECT_TRUE(test_api.top_left_layer() == NULL); - ASSERT_TRUE(test_api.top_layer() != NULL); - EXPECT_TRUE(test_api.top_right_layer() == NULL); - EXPECT_TRUE(test_api.left_layer() == NULL); - EXPECT_TRUE(test_api.center_layer() == NULL); - EXPECT_TRUE(test_api.right_layer() == NULL); - EXPECT_TRUE(test_api.bottom_left_layer() == NULL); - EXPECT_TRUE(test_api.bottom_layer() == NULL); - EXPECT_TRUE(test_api.bottom_right_layer() == NULL); - - const gfx::Size kSize(10, 10); - grid.SetSize(kSize); - - // The top layer should be scaled horizontally across the entire width, but it - // shouldn't be scaled vertically. - EXPECT_EQ(gfx::Rect(0, 0, kSize.width(), kBorder).ToString(), - test_api.GetTransformedLayerBounds( - *test_api.top_layer()).ToString()); -} - -// Test that side (top, left, right, bottom) layers that are narrower than their -// adjacent corner layers stay pinned to the outside edges instead of getting -// moved inwards or scaled. This exercises the scenario used for shadows. -TEST_F(ImageGridTest, SmallerSides) { - const int kCorner = 2; - const int kEdge = 1; - - scoped_ptr<gfx::Image> top_left_image( - CreateImage(gfx::Size(kCorner, kCorner))); - scoped_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge))); - scoped_ptr<gfx::Image> top_right_image( - CreateImage(gfx::Size(kCorner, kCorner))); - scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); - scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); - - ImageGrid grid; - grid.Init(top_left_image.get(), top_image.get(), top_right_image.get(), - left_image.get(), NULL, right_image.get(), - NULL, NULL, NULL); - ImageGrid::TestAPI test_api(&grid); - - const gfx::Size kSize(20, 30); - grid.SetSize(kSize); - - // The top layer should be flush with the top edge and stretched horizontally - // between the two top corners. - EXPECT_EQ(gfx::Rect( - kCorner, 0, kSize.width() - 2 * kCorner, kEdge).ToString(), - test_api.GetTransformedLayerBounds( - *test_api.top_layer()).ToString()); - - // The left layer should be flush with the left edge and stretched vertically - // between the top left corner and the bottom. - EXPECT_EQ(gfx::Rect( - 0, kCorner, kEdge, kSize.height() - kCorner).ToString(), - test_api.GetTransformedLayerBounds( - *test_api.left_layer()).ToString()); - - // The right layer should be flush with the right edge and stretched - // vertically between the top right corner and the bottom. - EXPECT_EQ(gfx::Rect( - kSize.width() - kEdge, kCorner, - kEdge, kSize.height() - kCorner).ToString(), - test_api.GetTransformedLayerBounds( - *test_api.right_layer()).ToString()); -} - -// Test that we hide or clip layers as needed when the grid is assigned a small -// size. -TEST_F(ImageGridTest, TooSmall) { - const int kCorner = 5; - const int kCenter = 3; - const int kEdge = 3; - - scoped_ptr<gfx::Image> top_left_image( - CreateImage(gfx::Size(kCorner, kCorner))); - scoped_ptr<gfx::Image> top_image(CreateImage(gfx::Size(kEdge, kEdge))); - scoped_ptr<gfx::Image> top_right_image( - CreateImage(gfx::Size(kCorner, kCorner))); - scoped_ptr<gfx::Image> left_image(CreateImage(gfx::Size(kEdge, kEdge))); - scoped_ptr<gfx::Image> center_image(CreateImage(gfx::Size(kCenter, kCenter))); - scoped_ptr<gfx::Image> right_image(CreateImage(gfx::Size(kEdge, kEdge))); - scoped_ptr<gfx::Image> bottom_left_image( - CreateImage(gfx::Size(kCorner, kCorner))); - scoped_ptr<gfx::Image> bottom_image(CreateImage(gfx::Size(kEdge, kEdge))); - scoped_ptr<gfx::Image> bottom_right_image( - CreateImage(gfx::Size(kCorner, kCorner))); - - ImageGrid grid; - grid.Init( - top_left_image.get(), top_image.get(), top_right_image.get(), - left_image.get(), center_image.get(), right_image.get(), - bottom_left_image.get(), bottom_image.get(), bottom_right_image.get()); - ImageGrid::TestAPI test_api(&grid); - - // Set a size that's smaller than the combined (unscaled) corner images. - const gfx::Size kSmallSize(kCorner + kCorner - 3, kCorner + kCorner - 5); - grid.SetSize(kSmallSize); - - // The scalable images around the sides and in the center should be hidden. - EXPECT_FALSE(test_api.top_layer()->visible()); - EXPECT_FALSE(test_api.bottom_layer()->visible()); - EXPECT_FALSE(test_api.left_layer()->visible()); - EXPECT_FALSE(test_api.right_layer()->visible()); - EXPECT_FALSE(test_api.center_layer()->visible()); - - // The corner images' clip rects should sum to the expected size. - EXPECT_EQ(kSmallSize.width(), - test_api.top_left_clip_rect().width() + - test_api.top_right_clip_rect().width()); - EXPECT_EQ(kSmallSize.width(), - test_api.bottom_left_clip_rect().width() + - test_api.bottom_right_clip_rect().width()); - EXPECT_EQ(kSmallSize.height(), - test_api.top_left_clip_rect().height() + - test_api.bottom_left_clip_rect().height()); - EXPECT_EQ(kSmallSize.height(), - test_api.top_right_clip_rect().height() + - test_api.bottom_right_clip_rect().height()); - - // Resize the grid to be large enough to show all images. - const gfx::Size kLargeSize(kCorner + kCorner + kCenter, - kCorner + kCorner + kCenter); - grid.SetSize(kLargeSize); - - // The scalable images should be visible now. - EXPECT_TRUE(test_api.top_layer()->visible()); - EXPECT_TRUE(test_api.bottom_layer()->visible()); - EXPECT_TRUE(test_api.left_layer()->visible()); - EXPECT_TRUE(test_api.right_layer()->visible()); - EXPECT_TRUE(test_api.center_layer()->visible()); - - // We shouldn't be clipping the corner images anymore. - EXPECT_TRUE(test_api.top_left_clip_rect().IsEmpty()); - EXPECT_TRUE(test_api.top_right_clip_rect().IsEmpty()); - EXPECT_TRUE(test_api.bottom_left_clip_rect().IsEmpty()); - EXPECT_TRUE(test_api.bottom_right_clip_rect().IsEmpty()); -} - -} // namespace test -} // namespace aura_shell diff --git a/ui/aura_shell/modal_container_layout_manager.cc b/ui/aura_shell/modal_container_layout_manager.cc deleted file mode 100644 index 6be8ebc..0000000 --- a/ui/aura_shell/modal_container_layout_manager.cc +++ /dev/null @@ -1,190 +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_shell/modal_container_layout_manager.h" - -#include "base/bind.h" -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/event.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/modality_event_filter.h" -#include "ui/aura_shell/shell.h" -#include "ui/aura_shell/window_util.h" -#include "ui/gfx/canvas.h" -#include "ui/gfx/compositor/layer.h" -#include "ui/gfx/compositor/layer_animator.h" -#include "ui/views/view.h" -#include "ui/views/widget/widget.h" - -namespace aura_shell { -namespace internal { - -namespace { - -class ScreenView : public views::View { - public: - ScreenView() {} - virtual ~ScreenView() {} - - // Overridden from views::View: - virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { - canvas->FillRect(SK_ColorBLACK, GetLocalBounds()); - } - - private: - DISALLOW_COPY_AND_ASSIGN(ScreenView); -}; - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// -// ModalContainerLayoutManager, public: - -ModalContainerLayoutManager::ModalContainerLayoutManager( - aura::Window* container) - : container_(container), - modal_screen_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST( - modality_filter_(new ModalityEventFilter(container, this))) { -} - -ModalContainerLayoutManager::~ModalContainerLayoutManager() { -} - -//////////////////////////////////////////////////////////////////////////////// -// ModalContainerLayoutManager, aura::LayoutManager implementation: - -void ModalContainerLayoutManager::OnWindowResized() { - if (modal_screen_) { - modal_screen_->SetBounds(gfx::Rect(0, 0, container_->bounds().width(), - container_->bounds().height())); - } -} - -void ModalContainerLayoutManager::OnWindowAddedToLayout( - aura::Window* child) { - child->AddObserver(this); - if (child->GetIntProperty(aura::client::kModalKey)) - AddModalWindow(child); -} - -void ModalContainerLayoutManager::OnWillRemoveWindowFromLayout( - aura::Window* child) { - child->RemoveObserver(this); - if (child->GetIntProperty(aura::client::kModalKey)) - RemoveModalWindow(child); -} - -void ModalContainerLayoutManager::OnChildWindowVisibilityChanged( - aura::Window* child, - bool visible) { -} - -void ModalContainerLayoutManager::SetChildBounds( - aura::Window* child, - const gfx::Rect& requested_bounds) { - SetChildBoundsDirect(child, requested_bounds); -} - -//////////////////////////////////////////////////////////////////////////////// -// ModalContainerLayoutManager, aura::WindowObserver implementation: - -void ModalContainerLayoutManager::OnWindowPropertyChanged(aura::Window* window, - const char* key, - void* old) { - if (key != aura::client::kModalKey) - return; - - if (window->GetIntProperty(aura::client::kModalKey)) { - AddModalWindow(window); - } else if (static_cast<int>(reinterpret_cast<intptr_t>(old))) { - RemoveModalWindow(window); - } -} - -//////////////////////////////////////////////////////////////////////////////// -// ModalContainerLayoutManager, ui::LayerAnimationObserver implementation: - -void ModalContainerLayoutManager::OnLayerAnimationEnded( - const ui::LayerAnimationSequence* sequence) { - if (modal_screen_ && !modal_screen_->GetNativeView()->layer()->ShouldDraw()) - DestroyModalScreen(); -} - -void ModalContainerLayoutManager::OnLayerAnimationAborted( - const ui::LayerAnimationSequence* sequence) { -} - -void ModalContainerLayoutManager::OnLayerAnimationScheduled( - const ui::LayerAnimationSequence* sequence) { -} - -//////////////////////////////////////////////////////////////////////////////// -// ModalContainerLayoutManager, ModalityEventFilter::Delegate implementation: - -bool ModalContainerLayoutManager::CanWindowReceiveEvents( - aura::Window* window) { - return GetActivatableWindow(window) == modal_window(); -} - -//////////////////////////////////////////////////////////////////////////////// -// ModalContainerLayoutManager, private: - -void ModalContainerLayoutManager::AddModalWindow(aura::Window* window) { - modal_windows_.push_back(window); - CreateModalScreen(); -} - -void ModalContainerLayoutManager::RemoveModalWindow(aura::Window* window) { - aura::Window::Windows::iterator it = - std::find(modal_windows_.begin(), modal_windows_.end(), window); - if (it != modal_windows_.end()) - modal_windows_.erase(it); - - if (modal_windows_.empty()) - HideModalScreen(); - else - aura_shell::ActivateWindow(modal_window()); -} - -void ModalContainerLayoutManager::CreateModalScreen() { - if (modal_screen_) - return; - modal_screen_ = new views::Widget; - views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); - params.parent = container_; - params.bounds = gfx::Rect(0, 0, container_->bounds().width(), - container_->bounds().height()); - modal_screen_->Init(params); - modal_screen_->GetNativeView()->SetName( - "ModalContainerLayoutManager.ModalScreen"); - modal_screen_->SetContentsView(new ScreenView); - modal_screen_->GetNativeView()->layer()->SetOpacity(0.0f); - modal_screen_->GetNativeView()->layer()->GetAnimator()->AddObserver(this); - - Shell::GetInstance()->AddRootWindowEventFilter(modality_filter_.get()); - - ui::LayerAnimator::ScopedSettings settings( - modal_screen_->GetNativeView()->layer()->GetAnimator()); - modal_screen_->Show(); - modal_screen_->GetNativeView()->layer()->SetOpacity(0.5f); - container_->StackChildAtTop(modal_screen_->GetNativeView()); -} - -void ModalContainerLayoutManager::DestroyModalScreen() { - modal_screen_->GetNativeView()->layer()->GetAnimator()->RemoveObserver(this); - modal_screen_->Close(); - modal_screen_ = NULL; -} - -void ModalContainerLayoutManager::HideModalScreen() { - Shell::GetInstance()->RemoveRootWindowEventFilter(modality_filter_.get()); - ui::LayerAnimator::ScopedSettings settings( - modal_screen_->GetNativeView()->layer()->GetAnimator()); - modal_screen_->GetNativeView()->layer()->SetOpacity(0.0f); -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/modal_container_layout_manager.h b/ui/aura_shell/modal_container_layout_manager.h deleted file mode 100644 index a01505c..0000000 --- a/ui/aura_shell/modal_container_layout_manager.h +++ /dev/null @@ -1,102 +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. - -#ifndef UI_AURA_SHELL_MODAL_CONTAINER_LAYOUT_MANAGER_H_ -#define UI_AURA_SHELL_MODAL_CONTAINER_LAYOUT_MANAGER_H_ -#pragma once - -#include <vector> - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "ui/aura/layout_manager.h" -#include "ui/aura/window_observer.h" -#include "ui/aura_shell/aura_shell_export.h" -#include "ui/aura_shell/modality_event_filter_delegate.h" -#include "ui/gfx/compositor/layer_animation_observer.h" - -namespace aura { -class Window; -class EventFilter; -} -namespace gfx { -class Rect; -} -namespace views { -class Widget; -} - -namespace aura_shell { -namespace internal { - -// LayoutManager for the modal window container. -class AURA_SHELL_EXPORT ModalContainerLayoutManager - : public aura::LayoutManager, - public aura::WindowObserver, - public ui::LayerAnimationObserver, - public ModalityEventFilterDelegate { - public: - explicit ModalContainerLayoutManager(aura::Window* container); - virtual ~ModalContainerLayoutManager(); - - // Overridden from aura::LayoutManager: - virtual void OnWindowResized() OVERRIDE; - virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; - virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE; - virtual void OnChildWindowVisibilityChanged(aura::Window* child, - bool visibile) OVERRIDE; - virtual void SetChildBounds(aura::Window* child, - const gfx::Rect& requested_bounds) OVERRIDE; - - // Overridden from aura::WindowObserver: - virtual void OnWindowPropertyChanged(aura::Window* window, - const char* key, - void* old) OVERRIDE; - - // Overridden from ui::LayerAnimationObserver: - virtual void OnLayerAnimationEnded( - const ui::LayerAnimationSequence* sequence) OVERRIDE; - virtual void OnLayerAnimationAborted( - const ui::LayerAnimationSequence* sequence) OVERRIDE; - virtual void OnLayerAnimationScheduled( - const ui::LayerAnimationSequence* sequence) OVERRIDE; - - // Overridden from ModalityEventFilterDelegate: - virtual bool CanWindowReceiveEvents(aura::Window* window) OVERRIDE; - - private: - void AddModalWindow(aura::Window* window); - void RemoveModalWindow(aura::Window* window); - - void CreateModalScreen(); - void DestroyModalScreen(); - void HideModalScreen(); - - aura::Window* modal_window() { - return !modal_windows_.empty() ? modal_windows_.back() : NULL; - } - - // The container that owns the layout manager. - aura::Window* container_; - - // A "screen" widget that dims the windows behind the modal window(s) being - // shown in |container_|. - views::Widget* modal_screen_; - - // A stack of modal windows. Only the topmost can receive events. - std::vector<aura::Window*> modal_windows_; - - // An event filter that enforces the modality of the topmost window in - // |modal_windows_|. The event filter is attached when a modal window is - // added, and removed when the last is closed. - scoped_ptr<aura::EventFilter> modality_filter_; - - DISALLOW_COPY_AND_ASSIGN(ModalContainerLayoutManager); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_MODAL_CONTAINER_LAYOUT_MANAGER_H_ diff --git a/ui/aura_shell/modal_container_layout_manager_unittest.cc b/ui/aura_shell/modal_container_layout_manager_unittest.cc deleted file mode 100644 index 228b853..0000000 --- a/ui/aura_shell/modal_container_layout_manager_unittest.cc +++ /dev/null @@ -1,174 +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_shell/modal_container_layout_manager.h" - -#include "base/compiler_specific.h" -#include "ui/aura/root_window.h" -#include "ui/aura/test/event_generator.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/shell.h" -#include "ui/aura_shell/shell_window_ids.h" -#include "ui/aura_shell/test/aura_shell_test_base.h" -#include "ui/aura_shell/window_util.h" -#include "ui/views/widget/widget.h" -#include "ui/views/widget/widget_delegate.h" - -namespace aura_shell { -namespace test { - -namespace { - -aura::Window* GetModalContainer() { - return Shell::GetInstance()->GetContainer( - aura_shell::internal::kShellWindowId_ModalContainer); -} - -aura::Window* GetDefaultContainer() { - return Shell::GetInstance()->GetContainer( - aura_shell::internal::kShellWindowId_DefaultContainer); -} - -class TestWindow : public views::WidgetDelegateView { - public: - explicit TestWindow(bool modal) : modal_(modal) {} - virtual ~TestWindow() {} - - static aura::Window* OpenTestWindow(aura::Window* parent, bool modal) { - DCHECK(!modal || (modal && parent)); - views::Widget* widget = - views::Widget::CreateWindowWithParent(new TestWindow(modal), parent); - widget->Show(); - return widget->GetNativeView(); - } - - // Overridden from views::View: - virtual gfx::Size GetPreferredSize() OVERRIDE { - return gfx::Size(50, 50); - } - - // Overridden from views::WidgetDelegate: - virtual views::View* GetContentsView() OVERRIDE { - return this; - } - virtual bool IsModal() const OVERRIDE { - return modal_; - } - - private: - bool modal_; - - DISALLOW_COPY_AND_ASSIGN(TestWindow); -}; - -class TransientWindowObserver : public aura::WindowObserver { - public: - TransientWindowObserver() : destroyed_(false) {} - virtual ~TransientWindowObserver() {} - - bool destroyed() const { return destroyed_; } - - // Overridden from aura::WindowObserver: - virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE { - destroyed_ = true; - } - - private: - bool destroyed_; - - DISALLOW_COPY_AND_ASSIGN(TransientWindowObserver); -}; - -} // namespace - -typedef AuraShellTestBase ModalContainerLayoutManagerTest; - -TEST_F(ModalContainerLayoutManagerTest, NonModalTransient) { - scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); - aura::Window* transient = TestWindow::OpenTestWindow(parent.get(), false); - TransientWindowObserver destruction_observer; - transient->AddObserver(&destruction_observer); - - EXPECT_EQ(parent.get(), transient->transient_parent()); - EXPECT_EQ(GetDefaultContainer(), transient->parent()); - - // The transient should be destroyed with its parent. - parent.reset(); - EXPECT_TRUE(destruction_observer.destroyed()); -} - -TEST_F(ModalContainerLayoutManagerTest, ModalTransient) { - scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); - // parent should be active. - EXPECT_TRUE(IsActiveWindow(parent.get())); - - aura::Window* t1 = TestWindow::OpenTestWindow(parent.get(), true); - TransientWindowObserver do1; - t1->AddObserver(&do1); - - EXPECT_EQ(parent.get(), t1->transient_parent()); - EXPECT_EQ(GetModalContainer(), t1->parent()); - - // t1 should now be active. - EXPECT_TRUE(IsActiveWindow(t1)); - - // Attempting to click the parent should result in no activation change. - aura::test::EventGenerator e1(parent.get()); - e1.ClickLeftButton(); - EXPECT_TRUE(IsActiveWindow(t1)); - - // Now open another modal transient parented to the original modal transient. - aura::Window* t2 = TestWindow::OpenTestWindow(t1, true); - TransientWindowObserver do2; - t2->AddObserver(&do2); - - EXPECT_TRUE(IsActiveWindow(t2)); - - EXPECT_EQ(t1, t2->transient_parent()); - EXPECT_EQ(GetModalContainer(), t2->parent()); - - // t2 should still be active, even after clicking on t1. - aura::test::EventGenerator e2(t1); - e2.ClickLeftButton(); - EXPECT_TRUE(IsActiveWindow(t2)); - - // Both transients should be destroyed with parent. - parent.reset(); - EXPECT_TRUE(do1.destroyed()); - EXPECT_TRUE(do2.destroyed()); -} - -// Tests that we can activate an unrelated window after a modal window is closed -// for a window. -TEST_F(ModalContainerLayoutManagerTest, CanActivateAfterEndModalSession) { - scoped_ptr<aura::Window> unrelated(TestWindow::OpenTestWindow(NULL, false)); - unrelated->SetBounds(gfx::Rect(100, 100, 50, 50)); - scoped_ptr<aura::Window> parent(TestWindow::OpenTestWindow(NULL, false)); - // parent should be active. - EXPECT_TRUE(IsActiveWindow(parent.get())); - - scoped_ptr<aura::Window> transient( - TestWindow::OpenTestWindow(parent.get(), true)); - // t1 should now be active. - EXPECT_TRUE(IsActiveWindow(transient.get())); - - // Attempting to click the parent should result in no activation change. - aura::test::EventGenerator e1(parent.get()); - e1.ClickLeftButton(); - EXPECT_TRUE(IsActiveWindow(transient.get())); - - // Now close the transient. - transient.reset(); - - // parent should now be active again. - EXPECT_TRUE(IsActiveWindow(parent.get())); - - // Attempting to click unrelated should activate it. - aura::test::EventGenerator e2(unrelated.get()); - e2.ClickLeftButton(); - EXPECT_TRUE(IsActiveWindow(unrelated.get())); -} - -} // namespace test -} // namespace aura_shell diff --git a/ui/aura_shell/modality_event_filter.cc b/ui/aura_shell/modality_event_filter.cc deleted file mode 100644 index 0df6a53..0000000 --- a/ui/aura_shell/modality_event_filter.cc +++ /dev/null @@ -1,40 +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_shell/modality_event_filter.h" - -#include "ui/aura/event.h" -#include "ui/aura_shell/modality_event_filter_delegate.h" - -namespace aura_shell { -namespace internal { - -ModalityEventFilter::ModalityEventFilter(aura::Window* container, - ModalityEventFilterDelegate* delegate) - : EventFilter(container), - delegate_(delegate) { -} - -ModalityEventFilter::~ModalityEventFilter() { -} - -bool ModalityEventFilter::PreHandleKeyEvent(aura::Window* target, - aura::KeyEvent* event) { - return !delegate_->CanWindowReceiveEvents(target); -} - -bool ModalityEventFilter::PreHandleMouseEvent(aura::Window* target, - aura::MouseEvent* event) { - return !delegate_->CanWindowReceiveEvents(target); -} - -ui::TouchStatus ModalityEventFilter::PreHandleTouchEvent( - aura::Window* target, - aura::TouchEvent* event) { - // TODO(sadrul): ! - return ui::TOUCH_STATUS_UNKNOWN; -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/modality_event_filter.h b/ui/aura_shell/modality_event_filter.h deleted file mode 100644 index 91f2fc2..0000000 --- a/ui/aura_shell/modality_event_filter.h +++ /dev/null @@ -1,42 +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. - -#ifndef UI_AURA_SHELL_MODALITY_EVENT_FILTER_H_ -#define UI_AURA_SHELL_MODALITY_EVENT_FILTER_H_ -#pragma once - -#include "base/compiler_specific.h" -#include "ui/aura/event_filter.h" -#include "ui/aura_shell/aura_shell_export.h" - -namespace aura_shell { -namespace internal { - -class ModalityEventFilterDelegate; - -class AURA_SHELL_EXPORT ModalityEventFilter : public aura::EventFilter { - public: - ModalityEventFilter(aura::Window* container, - ModalityEventFilterDelegate* delegate); - virtual ~ModalityEventFilter(); - - // Overridden from aura::EventFilter: - virtual bool PreHandleKeyEvent(aura::Window* target, - aura::KeyEvent* event) OVERRIDE; - virtual bool PreHandleMouseEvent(aura::Window* target, - aura::MouseEvent* event) OVERRIDE; - virtual ui::TouchStatus PreHandleTouchEvent( - aura::Window* target, - aura::TouchEvent* event) OVERRIDE; - - private: - ModalityEventFilterDelegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(ModalityEventFilter); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_MODALITY_EVENT_FILTER_H_ diff --git a/ui/aura_shell/modality_event_filter_delegate.h b/ui/aura_shell/modality_event_filter_delegate.h deleted file mode 100644 index 7afed81..0000000 --- a/ui/aura_shell/modality_event_filter_delegate.h +++ /dev/null @@ -1,27 +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. - -#ifndef UI_AURA_SHELL_MODALITY_EVENT_FILTER_DELEGATE_H_ -#define UI_AURA_SHELL_MODALITY_EVENT_FILTER_DELEGATE_H_ -#pragma once - -#include "ui/aura_shell/aura_shell_export.h" - -namespace aura { -class Window; -} - -namespace aura_shell { -namespace internal { - -class AURA_SHELL_EXPORT ModalityEventFilterDelegate { - public: - // Returns true if |window| can receive the specified event. - virtual bool CanWindowReceiveEvents(aura::Window* window) = 0; -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_MODALITY_EVENT_FILTER_DELEGATE_H_ diff --git a/ui/aura_shell/root_window_event_filter.cc b/ui/aura_shell/root_window_event_filter.cc index 4279f30..6b4fa8e 100644 --- a/ui/aura_shell/root_window_event_filter.cc +++ b/ui/aura_shell/root_window_event_filter.cc @@ -4,11 +4,11 @@ #include "ui/aura_shell/root_window_event_filter.h" +#include "ash/wm/activation_controller.h" #include "ui/aura/event.h" #include "ui/aura/focus_manager.h" #include "ui/aura/root_window.h" #include "ui/aura/window_delegate.h" -#include "ui/aura_shell/activation_controller.h" #include "ui/aura_shell/shell.h" #include "ui/aura_shell/window_util.h" #include "ui/base/hit_test.h" diff --git a/ui/aura_shell/root_window_event_filter_unittest.cc b/ui/aura_shell/root_window_event_filter_unittest.cc index 533867a..9b2a380 100644 --- a/ui/aura_shell/root_window_event_filter_unittest.cc +++ b/ui/aura_shell/root_window_event_filter_unittest.cc @@ -4,6 +4,7 @@ #include "ui/aura_shell/root_window_event_filter.h" +#include "ash/wm/activation_controller.h" #include "ui/aura/client/activation_delegate.h" #include "ui/aura/cursor.h" #include "ui/aura/event.h" @@ -13,7 +14,6 @@ #include "ui/aura/test/test_windows.h" #include "ui/aura/test/test_event_filter.h" #include "ui/aura/test/test_window_delegate.h" -#include "ui/aura_shell/activation_controller.h" #include "ui/aura_shell/shell_window_ids.h" #include "ui/aura_shell/test/test_activation_delegate.h" #include "ui/aura_shell/window_util.h" diff --git a/ui/aura_shell/shadow.cc b/ui/aura_shell/shadow.cc deleted file mode 100644 index 2963dd5..0000000 --- a/ui/aura_shell/shadow.cc +++ /dev/null @@ -1,54 +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_shell/shadow.h" - -#include "grit/ui_resources.h" -#include "ui/aura_shell/image_grid.h" -#include "ui/base/resource/resource_bundle.h" - -namespace aura_shell { -namespace internal { - -Shadow::Shadow() { -} - -Shadow::~Shadow() { -} - -ui::Layer* Shadow::layer() const { return image_grid_->layer(); } - -void Shadow::Init() { - image_grid_.reset(new ImageGrid); - - ResourceBundle& res = ResourceBundle::GetSharedInstance(); - image_grid_->Init(&res.GetImageNamed(IDR_AURA_SHADOW_RECT_TOP_LEFT), - &res.GetImageNamed(IDR_AURA_SHADOW_RECT_TOP), - &res.GetImageNamed(IDR_AURA_SHADOW_RECT_TOP_RIGHT), - &res.GetImageNamed(IDR_AURA_SHADOW_RECT_LEFT), - NULL, - &res.GetImageNamed(IDR_AURA_SHADOW_RECT_RIGHT), - &res.GetImageNamed(IDR_AURA_SHADOW_RECT_BOTTOM_LEFT), - &res.GetImageNamed(IDR_AURA_SHADOW_RECT_BOTTOM), - &res.GetImageNamed(IDR_AURA_SHADOW_RECT_BOTTOM_RIGHT)); -} - -void Shadow::SetContentBounds(const gfx::Rect& content_bounds) { - content_bounds_ = content_bounds; - image_grid_->SetSize( - gfx::Size(content_bounds.width() + - image_grid_->left_image_width() + - image_grid_->right_image_width(), - content_bounds.height() + - image_grid_->top_image_height() + - image_grid_->bottom_image_height())); - image_grid_->layer()->SetBounds( - gfx::Rect(content_bounds.x() - image_grid_->left_image_width(), - content_bounds.y() - image_grid_->top_image_height(), - image_grid_->layer()->bounds().width(), - image_grid_->layer()->bounds().height())); -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/shadow.h b/ui/aura_shell/shadow.h deleted file mode 100644 index ba73285..0000000 --- a/ui/aura_shell/shadow.h +++ /dev/null @@ -1,54 +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. - -#ifndef UI_AURA_SHELL_SHADOW_H_ -#define UI_AURA_SHELL_SHADOW_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/memory/scoped_ptr.h" -#include "ui/aura_shell/aura_shell_export.h" -#include "ui/gfx/rect.h" - -namespace ui { -class Layer; -} // namespace ui - -namespace aura_shell { -namespace internal { - -class ImageGrid; - -// Simple class that draws a drop shadow around content at given bounds. -class AURA_SHELL_EXPORT Shadow { - public: - Shadow(); - ~Shadow(); - - // Returns |image_grid_|'s ui::Layer. This is exposed so it can be added to - // the same layer as the content and stacked below it. SetContentBounds() - // should be used to adjust the shadow's size and position (rather than - // applying transformations to this layer). - ui::Layer* layer() const; - - const gfx::Rect& content_bounds() const { return content_bounds_; } - - void Init(); - - // Moves and resizes |image_grid_| to frame |content_bounds|. - void SetContentBounds(const gfx::Rect& content_bounds); - - private: - scoped_ptr<ImageGrid> image_grid_; - - // Bounds of the content that the shadow encloses. - gfx::Rect content_bounds_; - - DISALLOW_COPY_AND_ASSIGN(Shadow); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_SHADOW_H_ diff --git a/ui/aura_shell/shadow_controller.cc b/ui/aura_shell/shadow_controller.cc deleted file mode 100644 index e813435..0000000 --- a/ui/aura_shell/shadow_controller.cc +++ /dev/null @@ -1,117 +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_shell/shadow_controller.h" - -#include <utility> - -#include "base/command_line.h" -#include "base/logging.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/aura_shell_switches.h" -#include "ui/aura_shell/shadow.h" -#include "ui/aura_shell/shadow_types.h" -#include "ui/aura_shell/window_properties.h" - -using std::make_pair; - -namespace aura_shell { -namespace internal { - -namespace { - -ShadowType GetShadowTypeFromWindowType(aura::Window* window) { - switch (window->type()) { - case aura::client::WINDOW_TYPE_NORMAL: - return CommandLine::ForCurrentProcess()->HasSwitch( - switches::kAuraTranslucentFrames) ? - SHADOW_TYPE_NONE : SHADOW_TYPE_RECTANGULAR; - case aura::client::WINDOW_TYPE_MENU: - case aura::client::WINDOW_TYPE_TOOLTIP: - return SHADOW_TYPE_RECTANGULAR; - default: - break; - } - return SHADOW_TYPE_NONE; -} - -} // namespace - -ShadowController::ShadowController() { - aura::RootWindow::GetInstance()->AddRootWindowObserver(this); -} - -ShadowController::~ShadowController() { - for (WindowShadowMap::const_iterator it = window_shadows_.begin(); - it != window_shadows_.end(); ++it) { - it->first->RemoveObserver(this); - } - aura::RootWindow::GetInstance()->RemoveRootWindowObserver(this); -} - -void ShadowController::OnWindowInitialized(aura::Window* window) { - window->AddObserver(this); - SetShadowType(window, GetShadowTypeFromWindowType(window)); - HandlePossibleShadowVisibilityChange(window); -} - -void ShadowController::OnWindowPropertyChanged(aura::Window* window, - const char* name, - void* old) { - if (name == kShadowTypeKey) - HandlePossibleShadowVisibilityChange(window); -} - -void ShadowController::OnWindowBoundsChanged(aura::Window* window, - const gfx::Rect& bounds) { - Shadow* shadow = GetShadowForWindow(window); - if (shadow) - shadow->SetContentBounds(gfx::Rect(bounds.size())); -} - -void ShadowController::OnWindowDestroyed(aura::Window* window) { - window_shadows_.erase(window); -} - -bool ShadowController::ShouldShowShadowForWindow(aura::Window* window) const { - const ShadowType type = GetShadowType(window); - switch (type) { - case SHADOW_TYPE_NONE: - return false; - case SHADOW_TYPE_RECTANGULAR: - return true; - default: - NOTREACHED() << "Unknown shadow type " << type; - return false; - } -} - -Shadow* ShadowController::GetShadowForWindow(aura::Window* window) { - WindowShadowMap::const_iterator it = window_shadows_.find(window); - return it != window_shadows_.end() ? it->second.get() : NULL; -} - -void ShadowController::HandlePossibleShadowVisibilityChange( - aura::Window* window) { - const bool should_show = ShouldShowShadowForWindow(window); - Shadow* shadow = GetShadowForWindow(window); - if (shadow) - shadow->layer()->SetVisible(should_show); - else if (should_show && !shadow) - CreateShadowForWindow(window); -} - -void ShadowController::CreateShadowForWindow(aura::Window* window) { - linked_ptr<Shadow> shadow(new Shadow()); - window_shadows_.insert(make_pair(window, shadow)); - - shadow->Init(); - shadow->SetContentBounds(gfx::Rect(window->bounds().size())); - shadow->layer()->SetVisible(ShouldShowShadowForWindow(window)); - window->layer()->Add(shadow->layer()); -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/shadow_controller.h b/ui/aura_shell/shadow_controller.h deleted file mode 100644 index 7b6e96e67..0000000 --- a/ui/aura_shell/shadow_controller.h +++ /dev/null @@ -1,89 +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. - -#ifndef UI_AURA_SHELL_SHADOW_CONTROLLER_H_ -#define UI_AURA_SHELL_SHADOW_CONTROLLER_H_ -#pragma once - -#include <map> - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/linked_ptr.h" -#include "ui/aura/root_window_observer.h" -#include "ui/aura/window_observer.h" -#include "ui/aura_shell/aura_shell_export.h" - -namespace aura { -class Window; -} -namespace gfx { -class Rect; -} - -namespace aura_shell { -namespace internal { - -class Shadow; - -// ShadowController observes changes to windows and creates and updates drop -// shadows as needed. -class AURA_SHELL_EXPORT ShadowController : public aura::RootWindowObserver, - public aura::WindowObserver { -public: - class TestApi { - public: - explicit TestApi(ShadowController* controller) : controller_(controller) {} - ~TestApi() {} - - Shadow* GetShadowForWindow(aura::Window* window) { - return controller_->GetShadowForWindow(window); - } - - private: - ShadowController* controller_; // not owned - - DISALLOW_COPY_AND_ASSIGN(TestApi); - }; - - explicit ShadowController(); - virtual ~ShadowController(); - - // aura::RootWindowObserver override: - virtual void OnWindowInitialized(aura::Window* window) OVERRIDE; - - // aura::WindowObserver overrides: - virtual void OnWindowPropertyChanged( - aura::Window* window, const char* name, void* old) OVERRIDE; - virtual void OnWindowBoundsChanged( - aura::Window* window, const gfx::Rect& bounds) OVERRIDE; - virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE; - - private: - typedef std::map<aura::Window*, linked_ptr<Shadow> > WindowShadowMap; - - // Checks if |window| is visible and contains a property requesting a shadow. - bool ShouldShowShadowForWindow(aura::Window* window) const; - - // Returns |window|'s shadow from |window_shadows_|, or NULL if no shadow - // exists. - Shadow* GetShadowForWindow(aura::Window* window); - - // Shows or hides |window|'s shadow as needed (creating the shadow if - // necessary). - void HandlePossibleShadowVisibilityChange(aura::Window* window); - - // Creates a new shadow for |window| and stores it in |window_shadows_|. The - // shadow's bounds are initialized and it is added to the window's layer. - void CreateShadowForWindow(aura::Window* window); - - WindowShadowMap window_shadows_; - - DISALLOW_COPY_AND_ASSIGN(ShadowController); -}; - -} // namepsace aura_shell -} // namepsace internal - -#endif // UI_AURA_SHELL_SHADOW_CONTROLLER_H_ diff --git a/ui/aura_shell/shadow_controller_unittest.cc b/ui/aura_shell/shadow_controller_unittest.cc deleted file mode 100644 index b5bbbb8..0000000 --- a/ui/aura_shell/shadow_controller_unittest.cc +++ /dev/null @@ -1,91 +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_shell/shadow_controller.h" - -#include <algorithm> -#include <vector> - -#include "base/memory/scoped_ptr.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/shadow.h" -#include "ui/aura_shell/shadow_types.h" -#include "ui/aura_shell/shell.h" -#include "ui/aura_shell/test/aura_shell_test_base.h" -#include "ui/aura_shell/window_properties.h" -#include "ui/gfx/compositor/layer.h" - -namespace aura_shell { -namespace test { - -typedef aura_shell::test::AuraShellTestBase ShadowControllerTest; - -// Tests that various methods in Window update the Shadow object as expected. -TEST_F(ShadowControllerTest, Shadow) { - scoped_ptr<aura::Window> window(new aura::Window(NULL)); - window->SetType(aura::client::WINDOW_TYPE_NORMAL); - window->Init(ui::Layer::LAYER_HAS_TEXTURE); - window->SetParent(NULL); - - // We should create the shadow before the window is visible (the shadow's - // layer won't get drawn yet since it's a child of the window's layer). - internal::ShadowController::TestApi api( - aura_shell::Shell::GetInstance()->shadow_controller()); - const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); - ASSERT_TRUE(shadow != NULL); - EXPECT_TRUE(shadow->layer()->visible()); - - // The shadow should remain visible after window visibility changes. - window->Show(); - EXPECT_TRUE(shadow->layer()->visible()); - window->Hide(); - EXPECT_TRUE(shadow->layer()->visible()); - - // If the shadow is disabled, it should be hidden. - internal::SetShadowType(window.get(), internal::SHADOW_TYPE_NONE); - window->Show(); - EXPECT_FALSE(shadow->layer()->visible()); - internal::SetShadowType(window.get(), internal::SHADOW_TYPE_RECTANGULAR); - EXPECT_TRUE(shadow->layer()->visible()); - - // The shadow's layer should be a child of the window's layer. - EXPECT_EQ(window->layer(), shadow->layer()->parent()); - - window->parent()->RemoveChild(window.get()); - aura::Window* window_ptr = window.get(); - window.reset(); - EXPECT_TRUE(api.GetShadowForWindow(window_ptr) == NULL); -} - -// Tests that the window's shadow's bounds are updated correctly. -TEST_F(ShadowControllerTest, ShadowBounds) { - scoped_ptr<aura::Window> window(new aura::Window(NULL)); - window->SetType(aura::client::WINDOW_TYPE_NORMAL); - window->Init(ui::Layer::LAYER_HAS_TEXTURE); - window->SetParent(NULL); - window->Show(); - - const gfx::Rect kOldBounds(20, 30, 400, 300); - window->SetBounds(kOldBounds); - - // When the shadow is first created, it should use the window's size (but - // remain at the origin, since it's a child of the window's layer). - internal::SetShadowType(window.get(), internal::SHADOW_TYPE_RECTANGULAR); - internal::ShadowController::TestApi api( - aura_shell::Shell::GetInstance()->shadow_controller()); - const internal::Shadow* shadow = api.GetShadowForWindow(window.get()); - ASSERT_TRUE(shadow != NULL); - EXPECT_EQ(gfx::Rect(kOldBounds.size()).ToString(), - shadow->content_bounds().ToString()); - - // When we change the window's bounds, the shadow's should be updated too. - gfx::Rect kNewBounds(50, 60, 500, 400); - window->SetBounds(kNewBounds); - EXPECT_EQ(gfx::Rect(kNewBounds.size()).ToString(), - shadow->content_bounds().ToString()); -} - -} // namespace test -} // namespace aura_shell diff --git a/ui/aura_shell/shadow_types.cc b/ui/aura_shell/shadow_types.cc deleted file mode 100644 index 6eeacbd..0000000 --- a/ui/aura_shell/shadow_types.cc +++ /dev/null @@ -1,22 +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_shell/shadow_types.h" - -#include "ui/aura/window.h" -#include "ui/aura_shell/window_properties.h" - -namespace aura_shell { -namespace internal { - -void SetShadowType(aura::Window* window, ShadowType shadow_type) { - window->SetIntProperty(kShadowTypeKey, shadow_type); -} - -ShadowType GetShadowType(aura::Window* window) { - return static_cast<ShadowType>(window->GetIntProperty(kShadowTypeKey)); -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/shadow_types.h b/ui/aura_shell/shadow_types.h deleted file mode 100644 index b67c7b4..0000000 --- a/ui/aura_shell/shadow_types.h +++ /dev/null @@ -1,33 +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. - -#ifndef UI_AURA_SHELL_SHADOW_TYPES_H_ -#define UI_AURA_SHELL_SHADOW_TYPES_H_ -#pragma once - -#include "ui/aura_shell/aura_shell_export.h" - -namespace aura { -class Window; -} - -namespace aura_shell { -namespace internal { - -// Different types of drop shadows that can be drawn under a window by the -// shell. Used as a value for the kShadowTypeKey property. -enum ShadowType { - // Starts at 0 due to the cast in GetShadowType(). - SHADOW_TYPE_NONE = 0, - SHADOW_TYPE_RECTANGULAR, -}; - -AURA_SHELL_EXPORT void SetShadowType(aura::Window* window, - ShadowType shadow_type); -AURA_SHELL_EXPORT ShadowType GetShadowType(aura::Window* window); - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_SHADOW_TYPES_H_ diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc index 87c772e..bfa233e 100644 --- a/ui/aura_shell/shell.cc +++ b/ui/aura_shell/shell.cc @@ -6,12 +6,15 @@ #include <algorithm> +#include "ash/wm/activation_controller.h" +#include "ash/wm/modal_container_layout_manager.h" +#include "ash/wm/shadow_controller.h" +#include "ash/wm/stacking_controller.h" #include "base/bind.h" #include "base/command_line.h" #include "ui/aura/root_window.h" #include "ui/aura/layout_manager.h" #include "ui/aura/window.h" -#include "ui/aura_shell/activation_controller.h" #include "ui/aura_shell/app_list.h" #include "ui/aura_shell/aura_shell_switches.h" #include "ui/aura_shell/compact_layout_manager.h" @@ -22,15 +25,12 @@ #include "ui/aura_shell/root_window_layout_manager.h" #include "ui/aura_shell/drag_drop_controller.h" #include "ui/aura_shell/launcher/launcher.h" -#include "ui/aura_shell/modal_container_layout_manager.h" -#include "ui/aura_shell/shadow_controller.h" #include "ui/aura_shell/shelf_layout_manager.h" #include "ui/aura_shell/shell_accelerator_controller.h" #include "ui/aura_shell/shell_accelerator_filter.h" #include "ui/aura_shell/shell_delegate.h" #include "ui/aura_shell/shell_factory.h" #include "ui/aura_shell/shell_window_ids.h" -#include "ui/aura_shell/stacking_controller.h" #include "ui/aura_shell/status_area_layout_manager.h" #include "ui/aura_shell/tooltip_controller.h" #include "ui/aura_shell/toplevel_layout_manager.h" diff --git a/ui/aura_shell/show_state_controller.cc b/ui/aura_shell/show_state_controller.cc deleted file mode 100644 index ffd3b4a..0000000 --- a/ui/aura_shell/show_state_controller.cc +++ /dev/null @@ -1,47 +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_shell/show_state_controller.h" - -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/property_util.h" -#include "ui/aura_shell/workspace/workspace.h" -#include "ui/aura_shell/workspace/workspace_manager.h" -#include "ui/base/ui_base_types.h" - -namespace aura_shell { -namespace internal { - -ShowStateController::ShowStateController( - WorkspaceManager* workspace_manager) - : workspace_manager_(workspace_manager) { -} - -ShowStateController::~ShowStateController() { -} - -void ShowStateController::OnWindowPropertyChanged(aura::Window* window, - const char* name, - void* old) { - if (name != aura::client::kShowStateKey) - return; - if (window->GetIntProperty(name) == ui::SHOW_STATE_NORMAL) { - // Restore the size of window first, then let Workspace layout the window. - const gfx::Rect* restore = GetRestoreBounds(window); - window->SetProperty(aura::client::kRestoreBoundsKey, NULL); - if (restore) - window->SetBounds(*restore); - delete restore; - } else if (old == reinterpret_cast<void*>(ui::SHOW_STATE_NORMAL)) { - // Store the restore bounds only if previous state is normal. - DCHECK(window->GetProperty(aura::client::kRestoreBoundsKey) == NULL); - SetRestoreBounds(window, window->GetTargetBounds()); - } - - workspace_manager_->FindBy(window)->Layout(window); -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/show_state_controller.h b/ui/aura_shell/show_state_controller.h deleted file mode 100644 index 880ba5b..0000000 --- a/ui/aura_shell/show_state_controller.h +++ /dev/null @@ -1,44 +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. - -#ifndef UI_AURA_SHELL_SHOW_STATE_CONTROLLER_H_ -#define UI_AURA_SHELL_SHOW_STATE_CONTROLLER_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "ui/aura/window_observer.h" - -namespace aura { -class Window; -} - -namespace aura_shell { -namespace internal { - -class WorkspaceManager; - -// ShowStateController controls the window's bounds when -// the window's show state property has changed. -class ShowStateController : public aura::WindowObserver { -public: - explicit ShowStateController(WorkspaceManager* layout_manager); - virtual ~ShowStateController(); - - // aura::WindowObserver overrides: - virtual void OnWindowPropertyChanged(aura::Window* window, - const char* name, - void* old) OVERRIDE; - - private: - // |workspace_maanger_| is owned by |WorkspaceController|. - WorkspaceManager* workspace_manager_; - - DISALLOW_COPY_AND_ASSIGN(ShowStateController); -}; - -} // namepsace aura_shell -} // namepsace internal - -#endif // UI_AURA_SHELL_SHOW_STATE_CONTROLLER_H_ diff --git a/ui/aura_shell/stacking_controller.cc b/ui/aura_shell/stacking_controller.cc deleted file mode 100644 index 594b676..0000000 --- a/ui/aura_shell/stacking_controller.cc +++ /dev/null @@ -1,94 +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_shell/stacking_controller.h" - -#include "ui/aura/client/aura_constants.h" -#include "ui/aura/root_window.h" -#include "ui/aura/window.h" -#include "ui/aura_shell/always_on_top_controller.h" -#include "ui/aura_shell/shell.h" -#include "ui/aura_shell/shell_window_ids.h" - -namespace aura_shell { -namespace internal { -namespace { - -aura::Window* GetContainer(int id) { - return Shell::GetInstance()->GetContainer(id); -} - -bool IsWindowModal(aura::Window* window) { - return window->transient_parent() && - window->GetIntProperty(aura::client::kModalKey); -} - -} // namespace - -//////////////////////////////////////////////////////////////////////////////// -// StackingController, public: - -StackingController::StackingController() { - aura::client::SetStackingClient(this); - always_on_top_controller_.reset(new internal::AlwaysOnTopController); - always_on_top_controller_->SetContainers( - GetContainer(internal::kShellWindowId_DefaultContainer), - GetContainer(internal::kShellWindowId_AlwaysOnTopContainer)); -} - -StackingController::~StackingController() { -} - -//////////////////////////////////////////////////////////////////////////////// -// StackingController, aura::StackingClient implementation: - -aura::Window* StackingController::GetDefaultParent(aura::Window* window) { - switch (window->type()) { - case aura::client::WINDOW_TYPE_NORMAL: - case aura::client::WINDOW_TYPE_POPUP: - if (IsWindowModal(window)) - return GetModalContainer(window); - return always_on_top_controller_->GetContainer(window); - case aura::client::WINDOW_TYPE_MENU: - case aura::client::WINDOW_TYPE_TOOLTIP: - return GetContainer(internal::kShellWindowId_MenusAndTooltipsContainer); - default: - NOTREACHED() << "Window " << window->id() - << " has unhandled type " << window->type(); - break; - } - return NULL; -} - -//////////////////////////////////////////////////////////////////////////////// -// StackingController, private: - -aura::Window* StackingController::GetModalContainer( - aura::Window* window) const { - if (!IsWindowModal(window)) - return NULL; - - // If screen lock is not active, all modal windows are placed into the - // normal modal container. - aura::Window* lock_container = - GetContainer(internal::kShellWindowId_LockScreenContainer); - if (!lock_container->children().size()) - return GetContainer(internal::kShellWindowId_ModalContainer); - - // Otherwise those that originate from LockScreen container and above are - // placed in the screen lock modal container. - int lock_container_id = lock_container->id(); - int window_container_id = window->transient_parent()->parent()->id(); - - aura::Window* container = NULL; - if (window_container_id < lock_container_id) - container = GetContainer(internal::kShellWindowId_ModalContainer); - else - container = GetContainer(internal::kShellWindowId_LockModalContainer); - - return container; -} - -} // namespace internal -} // namespace aura_shell diff --git a/ui/aura_shell/stacking_controller.h b/ui/aura_shell/stacking_controller.h deleted file mode 100644 index 96d278d..0000000 --- a/ui/aura_shell/stacking_controller.h +++ /dev/null @@ -1,43 +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. - -#ifndef UI_AURA_SHELL_STACKING_CONTROLLER_H_ -#define UI_AURA_SHELL_STACKING_CONTROLLER_H_ -#pragma once - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "ui/aura/client/stacking_client.h" - -namespace aura_shell { -namespace internal { - -class AlwaysOnTopController; - -class StackingController : public aura::client::StackingClient { - public: - StackingController(); - virtual ~StackingController(); - - // Overridden from aura::client::StackingClient: - virtual aura::Window* GetDefaultParent(aura::Window* window) OVERRIDE; - - private: - // Returns corresponding modal container for a modal window. - // If screen lock is not active, all modal windows are placed into the - // normal modal container. - // Otherwise those that originate from LockScreen container and above are - // placed in the screen lock modal container. - aura::Window* GetModalContainer(aura::Window* window) const; - - scoped_ptr<internal::AlwaysOnTopController> always_on_top_controller_; - - DISALLOW_COPY_AND_ASSIGN(StackingController); -}; - -} // namespace internal -} // namespace aura_shell - -#endif // UI_AURA_SHELL_STACKING_CONTROLLER_H_ diff --git a/ui/aura_shell/stacking_controller_unittest.cc b/ui/aura_shell/stacking_controller_unittest.cc deleted file mode 100644 index e69de29..0000000 --- a/ui/aura_shell/stacking_controller_unittest.cc +++ /dev/null diff --git a/ui/aura_shell/window_util.cc b/ui/aura_shell/window_util.cc index e3ecf9f..a6e5e0d 100644 --- a/ui/aura_shell/window_util.cc +++ b/ui/aura_shell/window_util.cc @@ -4,11 +4,11 @@ #include "ui/aura_shell/window_util.h" +#include "ash/wm/activation_controller.h" #include "ui/aura/client/activation_client.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" -#include "ui/aura_shell/activation_controller.h" #include "ui/aura_shell/property_util.h" #include "ui/base/ui_base_types.h" #include "ui/gfx/screen.h" diff --git a/ui/aura_shell/workspace/workspace_manager_unittest.cc b/ui/aura_shell/workspace/workspace_manager_unittest.cc index 843e059..3c3e5e3 100644 --- a/ui/aura_shell/workspace/workspace_manager_unittest.cc +++ b/ui/aura_shell/workspace/workspace_manager_unittest.cc @@ -4,12 +4,12 @@ #include "ui/aura_shell/workspace/workspace_manager.h" +#include "ash/wm/activation_controller.h" #include "ui/aura/client/aura_constants.h" #include "ui/aura/root_window.h" #include "ui/aura/screen_aura.h" #include "ui/aura/test/aura_test_base.h" #include "ui/aura/window.h" -#include "ui/aura_shell/activation_controller.h" #include "ui/aura_shell/shell_window_ids.h" #include "ui/aura_shell/workspace/workspace.h" #include "ui/aura_shell/workspace/workspace_observer.h" diff --git a/ui/aura_shell/workspace_controller_unittest.cc b/ui/aura_shell/workspace_controller_unittest.cc index 3966049..5a3ad04 100644 --- a/ui/aura_shell/workspace_controller_unittest.cc +++ b/ui/aura_shell/workspace_controller_unittest.cc @@ -4,10 +4,10 @@ #include "ui/aura_shell/workspace_controller.h" +#include "ash/wm/activation_controller.h" #include "ui/aura/test/aura_test_base.h" #include "ui/aura/root_window.h" #include "ui/aura/window.h" -#include "ui/aura_shell/activation_controller.h" #include "ui/aura_shell/shell_window_ids.h" #include "ui/aura_shell/window_util.h" #include "ui/aura_shell/workspace/workspace.h" |