diff options
Diffstat (limited to 'ui/aura_shell/launcher')
-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 |
4 files changed, 128 insertions, 27 deletions
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 ? |