Index: ui/aura_shell/launcher/launcher.cc |
diff --git a/ui/aura_shell/launcher/launcher.cc b/ui/aura_shell/launcher/launcher.cc |
index 7dddc9402230fa0769092e9790ad03f8bef0ea07..0883724ec3883bd6970b2909029ba1fda2d54391 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. |