From 7eaa3c1037aeaf6ae34b916960d7ece124d5761c Mon Sep 17 00:00:00 2001 From: "groby@chromium.org" Date: Sat, 21 Apr 2012 00:57:02 +0000 Subject: Revert 133309 - Draw panels above their launcher icons. (Caused test failures on Win and CrOS:PanelLayoutManagerTest.AddOnePanel) Note that this patch doesn't handle dragging panels to rearrange them (if we want that at all) and panels with no launcher icon because they are in overflow. BUG=124115 TEST=aura_shell_unittests --gtest_filter=*Panel* --aura-panels Review URL: https://chromiumcodereview.appspot.com/10091017 TBR=dcheng@chromium.org Review URL: https://chromiumcodereview.appspot.com/10134018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133312 0039d316-1c4b-4281-b951-d872f2087c98 --- ash/wm/panel_layout_manager.cc | 69 +++++++++++++++------------------ ash/wm/panel_layout_manager.h | 13 +------ ash/wm/panel_layout_manager_unittest.cc | 68 +++++++++++--------------------- 3 files changed, 54 insertions(+), 96 deletions(-) (limited to 'ash/wm') diff --git a/ash/wm/panel_layout_manager.cc b/ash/wm/panel_layout_manager.cc index f741154..3c8a522 100644 --- a/ash/wm/panel_layout_manager.cc +++ b/ash/wm/panel_layout_manager.cc @@ -36,32 +36,25 @@ namespace internal { PanelLayoutManager::PanelLayoutManager(aura::Window* panel_container) : panel_container_(panel_container), in_layout_(false), - dragged_panel_(NULL), - launcher_(NULL) { + dragged_panel_(NULL) { DCHECK(panel_container); } PanelLayoutManager::~PanelLayoutManager() { - if (launcher_) - launcher_->RemoveIconObserver(this); } void PanelLayoutManager::StartDragging(aura::Window* panel) { - DCHECK(!dragged_panel_); + DCHECK(dragged_panel_ == NULL); DCHECK(panel->parent() == panel_container_); dragged_panel_ = panel; } void PanelLayoutManager::FinishDragging() { - DCHECK(dragged_panel_); + DCHECK(dragged_panel_ != NULL); dragged_panel_ = NULL; Relayout(); } -void PanelLayoutManager::SetLauncher(ash::Launcher* launcher) { - launcher->AddIconObserver(this); -} - void PanelLayoutManager::ToggleMinimize(aura::Window* panel) { DCHECK(panel->parent() == panel_container_); if (panel->GetProperty(aura::client::kShowStateKey) == @@ -71,7 +64,7 @@ void PanelLayoutManager::ToggleMinimize(aura::Window* panel) { gfx::Rect new_bounds(old_bounds); const gfx::Rect* restore_bounds = GetRestoreBounds(panel); - if (restore_bounds) { + if (restore_bounds != NULL) { new_bounds.set_height(restore_bounds->height()); new_bounds.set_y(old_bounds.bottom() - restore_bounds->height()); SetChildBounds(panel, new_bounds); @@ -156,46 +149,46 @@ void PanelLayoutManager::SetChildBounds(aura::Window* child, } //////////////////////////////////////////////////////////////////////////////// -// PanelLayoutManager, aura::LauncherIconObserver implementation: - -void PanelLayoutManager::OnLauncherIconPositionsChanged() { - Relayout(); -} - -//////////////////////////////////////////////////////////////////////////////// // PanelLayoutManager private implementation: +// This is a rough outline of a simple panel layout manager. void PanelLayoutManager::Relayout() { if (in_layout_) return; AutoReset auto_reset_in_layout(&in_layout_, true); + // Panels are currently laid out just above the launcher (if it exists), + // otherwise at the bottom of the root window. + int right, bottom; ash::Shell* shell = ash::Shell::GetInstance(); + if (shell->launcher() && shell->launcher()->widget()->IsVisible()) { + const gfx::Rect& bounds = + shell->launcher()->widget()->GetWindowScreenBounds(); + right = bounds.width() - 1 - kPanelMarginEdge; + bottom = bounds.y() - 1; + } else { + const gfx::Rect& bounds = panel_container_->GetRootWindow()->bounds(); + right = bounds.width() - 1 - kPanelMarginEdge; + bottom = bounds.bottom() - 1; + } + // Layout the panel windows right to left. for (PanelList::iterator iter = panel_windows_.begin(); iter != panel_windows_.end(); ++iter) { aura::Window* panel_win = *iter; - if (!panel_win->IsVisible() || panel_win == dragged_panel_) - continue; - - gfx::Rect icon_bounds = - shell->launcher()->GetScreenBoundsOfItemIconForWindow(panel_win); - - // An empty rect indicates that there is no icon for the panel in the - // launcher. Just use the current bounds, as there's no icon to draw the - // panel above. - if (icon_bounds.IsEmpty()) + if (!panel_win->IsVisible()) continue; - - gfx::Point icon_origin = icon_bounds.origin(); - aura::Window::ConvertPointToWindow(panel_container_->GetRootWindow(), - panel_container_, &icon_origin); - - gfx::Rect bounds = panel_win->bounds(); - bounds.set_x( - icon_origin.x() + icon_bounds.width() / 2 - bounds.width() / 2); - bounds.set_y(icon_origin.y() - bounds.height()); - SetChildBoundsDirect(panel_win, bounds); + int x = right - panel_win->bounds().width(); + int y = bottom - panel_win->bounds().height(); + + // Do not relayout dragged panel, but pretend it is in place + if (panel_win != dragged_panel_) { + gfx::Rect bounds(x, y, + panel_win->bounds().width(), + panel_win->bounds().height()); + SetChildBoundsDirect(panel_win, bounds); + } + right = x - kPanelMarginMiddle; } } diff --git a/ash/wm/panel_layout_manager.h b/ash/wm/panel_layout_manager.h index 8ec53d5..07ffd0e 100644 --- a/ash/wm/panel_layout_manager.h +++ b/ash/wm/panel_layout_manager.h @@ -9,7 +9,6 @@ #include #include "ash/ash_export.h" -#include "ash/launcher/launcher_icon_observer.h" #include "base/basictypes.h" #include "base/compiler_specific.h" #include "ui/aura/layout_manager.h" @@ -23,8 +22,6 @@ class Rect; } namespace ash { -class Launcher; - namespace internal { // PanelLayoutManager is responsible for organizing panels within the @@ -36,8 +33,7 @@ namespace internal { // its layout manager to this instance, e.g.: // panel_container->SetLayoutManager(new PanelLayoutManager(panel_container)); -class ASH_EXPORT PanelLayoutManager : public aura::LayoutManager, - public ash::LauncherIconObserver { +class ASH_EXPORT PanelLayoutManager : public aura::LayoutManager { public: explicit PanelLayoutManager(aura::Window* panel_container); virtual ~PanelLayoutManager(); @@ -47,8 +43,6 @@ class ASH_EXPORT PanelLayoutManager : public aura::LayoutManager, void ToggleMinimize(aura::Window* panel); - void SetLauncher(ash::Launcher* launcher); - // Overridden from aura::LayoutManager: virtual void OnWindowResized() OVERRIDE; virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE; @@ -59,9 +53,6 @@ class ASH_EXPORT PanelLayoutManager : public aura::LayoutManager, virtual void SetChildBounds(aura::Window* child, const gfx::Rect& requested_bounds) OVERRIDE; - // Overriden from ash::LauncherIconObserver - virtual void OnLauncherIconPositionsChanged() OVERRIDE; - private: typedef std::list PanelList; @@ -77,8 +68,6 @@ class ASH_EXPORT PanelLayoutManager : public aura::LayoutManager, aura::Window* dragged_panel_; - Launcher* launcher_; - DISALLOW_COPY_AND_ASSIGN(PanelLayoutManager); }; diff --git a/ash/wm/panel_layout_manager_unittest.cc b/ash/wm/panel_layout_manager_unittest.cc index 17c6035..4ee864c 100644 --- a/ash/wm/panel_layout_manager_unittest.cc +++ b/ash/wm/panel_layout_manager_unittest.cc @@ -5,11 +5,9 @@ #include "ash/wm/panel_layout_manager.h" #include "ash/ash_switches.h" -#include "ash/launcher/launcher.h" #include "ash/shell.h" #include "ash/shell_window_ids.h" #include "ash/test/ash_test_base.h" -#include "ash/test/test_launcher_delegate.h" #include "base/basictypes.h" #include "base/command_line.h" #include "base/compiler_specific.h" @@ -23,15 +21,9 @@ namespace { views::Widget* CreatePanelWindow(const gfx::Rect& rect) { views::Widget::InitParams params(views::Widget::InitParams::TYPE_PANEL); - params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.bounds = rect; - params.child = true; views::Widget* widget = new views::Widget(); widget->Init(params); - ash::test::TestLauncherDelegate* launcher_delegate = - ash::test::TestLauncherDelegate::instance(); - CHECK(launcher_delegate); - launcher_delegate->AddLauncherItem(widget->GetNativeWindow()); widget->Show(); return widget; } @@ -50,49 +42,29 @@ class PanelLayoutManagerTest : public ash::test::AshTestBase { DISALLOW_COPY_AND_ASSIGN(PanelLayoutManagerTest); }; -void IsPanelAboveLauncherIcon(views::Widget* panel) { - Launcher* launcher = Shell::GetInstance()->launcher(); - aura::Window* window = panel->GetNativeWindow(); - gfx::Rect icon_bounds = launcher->GetScreenBoundsOfItemIconForWindow(window); - ASSERT_FALSE(icon_bounds.IsEmpty()); - - gfx::Rect window_bounds = panel->GetWindowScreenBounds(); - - // 1-pixel tolerance--since we center panels over their icons, panels with odd - // pixel widths won't be perfectly lined up with even pixel width launcher - // icons. - EXPECT_NEAR( - window_bounds.CenterPoint().x(), icon_bounds.CenterPoint().x(), 1); - EXPECT_EQ(window_bounds.bottom(), icon_bounds.y()); -} - } // namespace // Tests that a created panel window is successfully added to the panel // layout manager. TEST_F(PanelLayoutManagerTest, AddOnePanel) { - gfx::Rect bounds(0, 0, 201, 201); - scoped_ptr window(CreatePanelWindow(bounds)); - EXPECT_EQ(GetPanelContainer(), window->GetNativeWindow()->parent()); - EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(window.get())); + gfx::Rect bounds(1, 1, 200, 200); + views::Widget* w1 = CreatePanelWindow(bounds); + EXPECT_EQ(GetPanelContainer(), w1->GetNativeWindow()->parent()); } // Tests that panels are ordered right-to-left. -TEST_F(PanelLayoutManagerTest, PanelAboveLauncherIcons) { +TEST_F(PanelLayoutManagerTest, PanelOrderRightToLeft) { if (!CommandLine::ForCurrentProcess()->HasSwitch( switches::kAuraPanelManager)) return; - - gfx::Rect bounds(0, 0, 201, 201); - scoped_ptr w1(CreatePanelWindow(bounds)); - EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); - scoped_ptr w2(CreatePanelWindow(bounds)); - EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); - EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); - scoped_ptr w3(CreatePanelWindow(bounds)); - EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); - EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w2.get())); - EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); + gfx::Rect bounds(1, 1, 200, 200); + views::Widget* w1 = CreatePanelWindow(bounds); + views::Widget* w2 = CreatePanelWindow(bounds); + EXPECT_LT(w2->GetWindowScreenBounds().x(), w1->GetWindowScreenBounds().x()); + + views::Widget* w3 = CreatePanelWindow(bounds); + EXPECT_LT(w3->GetWindowScreenBounds().x(), w2->GetWindowScreenBounds().x()); + EXPECT_LT(w2->GetWindowScreenBounds().x(), w1->GetWindowScreenBounds().x()); } // Tests removing a panel. @@ -101,15 +73,19 @@ TEST_F(PanelLayoutManagerTest, RemovePanel) { switches::kAuraPanelManager)) return; - gfx::Rect bounds(0, 0, 201, 201); - scoped_ptr w1(CreatePanelWindow(bounds)); - scoped_ptr w2(CreatePanelWindow(bounds)); - scoped_ptr w3(CreatePanelWindow(bounds)); + gfx::Rect bounds(1, 1, 200, 200); + views::Widget* w1 = CreatePanelWindow(bounds); + views::Widget* w2 = CreatePanelWindow(bounds); + views::Widget* w3 = CreatePanelWindow(bounds); + + gfx::Rect w3bounds = w3->GetWindowScreenBounds(); GetPanelContainer()->RemoveChild(w2->GetNativeWindow()); - EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w1.get())); - EXPECT_NO_FATAL_FAILURE(IsPanelAboveLauncherIcon(w3.get())); + // Verify that w3 has moved. + EXPECT_NE(w3->GetWindowScreenBounds(), w3bounds); + // Verify that w3 is still left of w1. + EXPECT_LT(w3->GetWindowScreenBounds().x(), w1->GetWindowScreenBounds().x()); } } // namespace ash -- cgit v1.1