diff options
Diffstat (limited to 'ui')
-rw-r--r-- | ui/aura_shell/aura_shell.gyp | 1 | ||||
-rw-r--r-- | ui/aura_shell/launcher/launcher.cc | 91 | ||||
-rw-r--r-- | ui/aura_shell/launcher/launcher.h | 9 | ||||
-rw-r--r-- | ui/aura_shell/launcher/launcher_unittest.cc | 31 | ||||
-rw-r--r-- | ui/aura_shell/launcher/launcher_view.cc | 24 | ||||
-rw-r--r-- | ui/aura_shell/shelf_layout_manager.cc | 4 | ||||
-rw-r--r-- | ui/aura_shell/shelf_layout_manager.h | 10 | ||||
-rw-r--r-- | ui/aura_shell/shelf_layout_manager_unittest.cc | 26 |
8 files changed, 165 insertions, 31 deletions
diff --git a/ui/aura_shell/aura_shell.gyp b/ui/aura_shell/aura_shell.gyp index e404546..88268c4 100644 --- a/ui/aura_shell/aura_shell.gyp +++ b/ui/aura_shell/aura_shell.gyp @@ -153,6 +153,7 @@ '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', diff --git a/ui/aura_shell/launcher/launcher.cc b/ui/aura_shell/launcher/launcher.cc index 7dddc94..0883724e 100644 --- a/ui/aura_shell/launcher/launcher.cc +++ b/ui/aura_shell/launcher/launcher.cc @@ -4,20 +4,95 @@ #include "ui/aura_shell/launcher/launcher.h" +#include "grit/ui_resources.h" #include "ui/aura/window.h" #include "ui/aura_shell/launcher/launcher_model.h" #include "ui/aura_shell/launcher/launcher_view.h" #include "ui/aura_shell/shell.h" #include "ui/aura_shell/shell_delegate.h" #include "ui/aura_shell/shell_window_ids.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/compositor/layer.h" +#include "ui/gfx/image/image.h" +#include "ui/views/painter.h" #include "ui/views/widget/widget.h" namespace aura_shell { +namespace { + +// Used to draw the background of the shelf. +class ShelfPainter : public views::Painter { + public: + ShelfPainter() { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + image_ = *rb.GetImageNamed(IDR_AURA_LAUNCHER_BACKGROUND).ToSkBitmap(); + } + + virtual void Paint(int w, int h, gfx::Canvas* canvas) OVERRIDE { + canvas->TileImageInt(image_, 0, 0, w, h); + } + + private: + SkBitmap image_; + + DISALLOW_COPY_AND_ASSIGN(ShelfPainter); +}; + +} // namespace + +// The contents view of the Widget. This view contains LauncherView and +// sizes it to the width of the widget minus the size of the status area. +class Launcher::DelegateView : public views::WidgetDelegateView { + public: + explicit DelegateView(); + virtual ~DelegateView(); + + void SetStatusWidth(int width); + int status_width() const { return status_width_; } + + // views::View overrides + virtual gfx::Size GetPreferredSize() OVERRIDE; + virtual void Layout() OVERRIDE; + + private: + int status_width_; + + DISALLOW_COPY_AND_ASSIGN(DelegateView); +}; + +Launcher::DelegateView::DelegateView() + : status_width_(0) { + set_background( + views::Background::CreateBackgroundPainter(true, new ShelfPainter())); +} + +Launcher::DelegateView::~DelegateView() { +} + +void Launcher::DelegateView::SetStatusWidth(int width) { + if (status_width_ == width) + return; + + status_width_ = width; + Layout(); +} + +gfx::Size Launcher::DelegateView::GetPreferredSize() { + return child_count() > 0 ? child_at(0)->GetPreferredSize() : gfx::Size(); +} + +void Launcher::DelegateView::Layout() { + if (child_count() == 0) + return; + child_at(0)->SetBounds(0, 0, std::max(0, width() - status_width_), height()); +} + Launcher::Launcher(aura::Window* window_container) : widget_(NULL), - window_container_(window_container) { + window_container_(window_container), + delegate_view_(NULL) { window_container->AddObserver(this); model_.reset(new LauncherModel); @@ -31,11 +106,13 @@ Launcher::Launcher(aura::Window* window_container) internal::LauncherView* launcher_view = new internal::LauncherView(model_.get()); launcher_view->Init(); - params.delegate = launcher_view; + delegate_view_ = new DelegateView; + delegate_view_->AddChildView(launcher_view); + params.delegate = delegate_view_; widget_->Init(params); gfx::Size pref = static_cast<views::View*>(launcher_view)->GetPreferredSize(); widget_->SetBounds(gfx::Rect(0, 0, pref.width(), pref.height())); - widget_->SetContentsView(launcher_view); + widget_->SetContentsView(delegate_view_); widget_->Show(); widget_->GetNativeView()->SetName("LauncherView"); } @@ -49,6 +126,14 @@ Launcher::~Launcher() { } } +void Launcher::SetStatusWidth(int width) { + delegate_view_->SetStatusWidth(width); +} + +int Launcher::GetStatusWidth() { + return delegate_view_->status_width(); +} + void Launcher::MaybeAdd(aura::Window* window) { if (known_windows_[window] == true) return; // We already tried to add this window. diff --git a/ui/aura_shell/launcher/launcher.h b/ui/aura_shell/launcher/launcher.h index ef1a2ac..b7f4ac4 100644 --- a/ui/aura_shell/launcher/launcher.h +++ b/ui/aura_shell/launcher/launcher.h @@ -30,10 +30,16 @@ class AURA_SHELL_EXPORT Launcher : public aura::WindowObserver { explicit Launcher(aura::Window* window_container); ~Launcher(); + // Sets the width of the status area. + void SetStatusWidth(int width); + int GetStatusWidth(); + LauncherModel* model() { return model_.get(); } views::Widget* widget() { return widget_; } private: + class DelegateView; + typedef std::map<aura::Window*, bool> WindowMap; // If necessary asks the delegate if an entry should be created in the @@ -57,6 +63,9 @@ class AURA_SHELL_EXPORT Launcher : public aura::WindowObserver { // the delegate if the window should added to the launcher. WindowMap known_windows_; + // Contents view of the widget. Houses the LauncherView. + DelegateView* delegate_view_; + DISALLOW_COPY_AND_ASSIGN(Launcher); }; diff --git a/ui/aura_shell/launcher/launcher_unittest.cc b/ui/aura_shell/launcher/launcher_unittest.cc new file mode 100644 index 0000000..eccef4d --- /dev/null +++ b/ui/aura_shell/launcher/launcher_unittest.cc @@ -0,0 +1,31 @@ +// 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/launcher/launcher.h" + +#include "ui/aura_shell/shell.h" +#include "ui/aura_shell/test/aura_shell_test_base.h" +#include "ui/views/view.h" +#include "ui/views/widget/widget.h" + +typedef aura_shell::test::AuraShellTestBase LauncherTest; + +namespace aura_shell { + +// Makes sure invoking SetStatusWidth on the launcher changes the size of the +// LauncherView. +TEST_F(LauncherTest, SetStatusWidth) { + Launcher* launcher = Shell::GetInstance()->launcher(); + ASSERT_TRUE(launcher); + views::View* launcher_view = launcher->widget()->GetContentsView(); + ASSERT_EQ(1, launcher_view->child_count()); + launcher_view = launcher_view->child_at(0); + + int total_width = launcher->widget()->GetWindowScreenBounds().width(); + ASSERT_GT(total_width, 0); + launcher->SetStatusWidth(total_width / 2); + EXPECT_EQ(total_width - total_width / 2, launcher_view->width()); +} + +} // namespace aura_shell diff --git a/ui/aura_shell/launcher/launcher_view.cc b/ui/aura_shell/launcher/launcher_view.cc index 4d7c0f2..9434a5a 100644 --- a/ui/aura_shell/launcher/launcher_view.cc +++ b/ui/aura_shell/launcher/launcher_view.cc @@ -19,14 +19,12 @@ #include "ui/base/animation/throb_animation.h" #include "ui/base/models/simple_menu_model.h" #include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas.h" #include "ui/gfx/compositor/layer.h" #include "ui/gfx/image/image.h" #include "ui/views/animation/bounds_animator.h" #include "ui/views/controls/button/image_button.h" #include "ui/views/controls/menu/menu_model_adapter.h" #include "ui/views/controls/menu/menu_runner.h" -#include "ui/views/painter.h" #include "ui/views/widget/widget.h" using ui::Animation; @@ -128,25 +126,6 @@ class FadeInAnimationDelegate : DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); }; -// Used to draw the background of the shelf. -class ShelfPainter : public views::Painter { - public: - ShelfPainter() { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - image_ = *rb.GetImageNamed(IDR_AURA_LAUNCHER_BACKGROUND).ToSkBitmap(); - } - - virtual void Paint(int w, int h, gfx::Canvas* canvas) OVERRIDE { - canvas->TileImageInt(image_, 0, 0, w, h); - } - - private: - SkBitmap image_; - - DISALLOW_COPY_AND_ASSIGN(ShelfPainter); -}; - - } // namespace // AnimationDelegate used when inserting a new item. This steadily decreased the @@ -227,9 +206,6 @@ void LauncherView::Init() { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); model_->AddObserver(this); - set_background( - views::Background::CreateBackgroundPainter(true, new ShelfPainter())); - new_browser_button_ = new views::ImageButton(this); ShellDelegate* delegate = Shell::GetInstance()->delegate(); int new_browser_button_image_id = delegate ? diff --git a/ui/aura_shell/shelf_layout_manager.cc b/ui/aura_shell/shelf_layout_manager.cc index d9f58e2..e9ec851 100644 --- a/ui/aura_shell/shelf_layout_manager.cc +++ b/ui/aura_shell/shelf_layout_manager.cc @@ -7,6 +7,8 @@ #include "base/auto_reset.h" #include "ui/aura/root_window.h" #include "ui/aura/screen_aura.h" +#include "ui/aura_shell/launcher/launcher.h" +#include "ui/aura_shell/shell.h" #include "ui/gfx/compositor/layer.h" #include "ui/gfx/compositor/layer_animator.h" #include "ui/views/widget/widget.h" @@ -54,6 +56,8 @@ void ShelfLayoutManager::LayoutShelf() { GetLayer(status_)->SetOpacity(target_opacity); launcher_->SetBounds(target_bounds.launcher_bounds); status_->SetBounds(target_bounds.status_bounds); + Shell::GetInstance()->launcher()->SetStatusWidth( + target_bounds.status_bounds.width()); aura::RootWindow::GetInstance()->screen()->set_work_area_insets( target_bounds.work_area_insets); } diff --git a/ui/aura_shell/shelf_layout_manager.h b/ui/aura_shell/shelf_layout_manager.h index 21a9b6d..f2be188 100644 --- a/ui/aura_shell/shelf_layout_manager.h +++ b/ui/aura_shell/shelf_layout_manager.h @@ -21,10 +21,12 @@ class Widget; namespace aura_shell { namespace internal { -// ShelfLayoutManager is a layout manager responsible for the launcher. -// Also supports showing and hiding the launcher/status area -// as well as positioning them. -// Exported for unit tests. +// ShelfLayoutManager is the layout manager responsible for the launcher and +// status widgets. The launcher is given the total available width and told the +// width of the status area. This allows the launcher to draw the background and +// layout to the status area. +// To respond to bounds changes in the status area StatusAreaLayoutManager works +// closely with ShelfLayoutManager. class AURA_SHELL_EXPORT ShelfLayoutManager : public aura::LayoutManager, public ui::LayerAnimationObserver { public: diff --git a/ui/aura_shell/shelf_layout_manager_unittest.cc b/ui/aura_shell/shelf_layout_manager_unittest.cc index 4596b1e..920660d 100644 --- a/ui/aura_shell/shelf_layout_manager_unittest.cc +++ b/ui/aura_shell/shelf_layout_manager_unittest.cc @@ -7,6 +7,7 @@ #include "ui/aura/root_window.h" #include "ui/aura/screen_aura.h" #include "ui/aura/window.h" +#include "ui/aura_shell/launcher/launcher.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" @@ -104,5 +105,30 @@ TEST_F(ShelfLayoutManagerTest, LayoutShelfWhileAnimating) { gfx::Screen::GetPrimaryMonitorBounds().bottom()); } +// Makes sure the launcher is initially sized correctly. +TEST_F(ShelfLayoutManagerTest, LauncherInitiallySized) { + Launcher* launcher = Shell::GetInstance()->launcher(); + ASSERT_TRUE(launcher); + ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); + ASSERT_TRUE(shelf_layout_manager); + ASSERT_TRUE(shelf_layout_manager->status()); + int status_width = + shelf_layout_manager->status()->GetWindowScreenBounds().width(); + // Test only makes sense if the status is > 0, which is better be. + EXPECT_GT(status_width, 0); + EXPECT_EQ(status_width, launcher->GetStatusWidth()); +} + +// Makes sure the launcher is sized when the status area changes size. +TEST_F(ShelfLayoutManagerTest, LauncherUpdatedWhenStatusAreaChangesSize) { + Launcher* launcher = Shell::GetInstance()->launcher(); + ASSERT_TRUE(launcher); + ShelfLayoutManager* shelf_layout_manager = GetShelfLayoutManager(); + ASSERT_TRUE(shelf_layout_manager); + ASSERT_TRUE(shelf_layout_manager->status()); + shelf_layout_manager->status()->SetBounds(gfx::Rect(0, 0, 200, 200)); + EXPECT_EQ(200, launcher->GetStatusWidth()); +} + } // namespace internal } // namespace aura_shell |