Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: ui/aura_shell/launcher/launcher.cc

Issue 8953004: Now that the launcher is sized to the width of the root window we need (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweaks Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura_shell/launcher/launcher.h ('k') | ui/aura_shell/launcher/launcher_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura_shell/launcher/launcher.h" 5 #include "ui/aura_shell/launcher/launcher.h"
6 6
7 #include "grit/ui_resources.h"
7 #include "ui/aura/window.h" 8 #include "ui/aura/window.h"
8 #include "ui/aura_shell/launcher/launcher_model.h" 9 #include "ui/aura_shell/launcher/launcher_model.h"
9 #include "ui/aura_shell/launcher/launcher_view.h" 10 #include "ui/aura_shell/launcher/launcher_view.h"
10 #include "ui/aura_shell/shell.h" 11 #include "ui/aura_shell/shell.h"
11 #include "ui/aura_shell/shell_delegate.h" 12 #include "ui/aura_shell/shell_delegate.h"
12 #include "ui/aura_shell/shell_window_ids.h" 13 #include "ui/aura_shell/shell_window_ids.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/compositor/layer.h" 16 #include "ui/gfx/compositor/layer.h"
17 #include "ui/gfx/image/image.h"
18 #include "ui/views/painter.h"
14 #include "ui/views/widget/widget.h" 19 #include "ui/views/widget/widget.h"
15 20
16 namespace aura_shell { 21 namespace aura_shell {
17 22
23 namespace {
24
25 // Used to draw the background of the shelf.
26 class ShelfPainter : public views::Painter {
27 public:
28 ShelfPainter() {
29 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
30 image_ = *rb.GetImageNamed(IDR_AURA_LAUNCHER_BACKGROUND).ToSkBitmap();
31 }
32
33 virtual void Paint(int w, int h, gfx::Canvas* canvas) OVERRIDE {
34 canvas->TileImageInt(image_, 0, 0, w, h);
35 }
36
37 private:
38 SkBitmap image_;
39
40 DISALLOW_COPY_AND_ASSIGN(ShelfPainter);
41 };
42
43 } // namespace
44
45 // The contents view of the Widget. This view contains LauncherView and
46 // sizes it to the width of the widget minus the size of the status area.
47 class Launcher::DelegateView : public views::WidgetDelegateView {
48 public:
49 explicit DelegateView();
50 virtual ~DelegateView();
51
52 void SetStatusWidth(int width);
53 int status_width() const { return status_width_; }
54
55 // views::View overrides
56 virtual gfx::Size GetPreferredSize() OVERRIDE;
57 virtual void Layout() OVERRIDE;
58
59 private:
60 int status_width_;
61
62 DISALLOW_COPY_AND_ASSIGN(DelegateView);
63 };
64
65 Launcher::DelegateView::DelegateView()
66 : status_width_(0) {
67 set_background(
68 views::Background::CreateBackgroundPainter(true, new ShelfPainter()));
69 }
70
71 Launcher::DelegateView::~DelegateView() {
72 }
73
74 void Launcher::DelegateView::SetStatusWidth(int width) {
75 if (status_width_ == width)
76 return;
77
78 status_width_ = width;
79 Layout();
80 }
81
82 gfx::Size Launcher::DelegateView::GetPreferredSize() {
83 return child_count() > 0 ? child_at(0)->GetPreferredSize() : gfx::Size();
84 }
85
86 void Launcher::DelegateView::Layout() {
87 if (child_count() == 0)
88 return;
89 child_at(0)->SetBounds(0, 0, std::max(0, width() - status_width_), height());
90 }
91
18 Launcher::Launcher(aura::Window* window_container) 92 Launcher::Launcher(aura::Window* window_container)
19 : widget_(NULL), 93 : widget_(NULL),
20 window_container_(window_container) { 94 window_container_(window_container),
95 delegate_view_(NULL) {
21 window_container->AddObserver(this); 96 window_container->AddObserver(this);
22 97
23 model_.reset(new LauncherModel); 98 model_.reset(new LauncherModel);
24 99
25 widget_ = new views::Widget; 100 widget_ = new views::Widget;
26 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); 101 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
27 params.create_texture_for_layer = true; 102 params.create_texture_for_layer = true;
28 params.transparent = true; 103 params.transparent = true;
29 params.parent = Shell::GetInstance()->GetContainer( 104 params.parent = Shell::GetInstance()->GetContainer(
30 aura_shell::internal::kShellWindowId_LauncherContainer); 105 aura_shell::internal::kShellWindowId_LauncherContainer);
31 internal::LauncherView* launcher_view = 106 internal::LauncherView* launcher_view =
32 new internal::LauncherView(model_.get()); 107 new internal::LauncherView(model_.get());
33 launcher_view->Init(); 108 launcher_view->Init();
34 params.delegate = launcher_view; 109 delegate_view_ = new DelegateView;
110 delegate_view_->AddChildView(launcher_view);
111 params.delegate = delegate_view_;
35 widget_->Init(params); 112 widget_->Init(params);
36 gfx::Size pref = static_cast<views::View*>(launcher_view)->GetPreferredSize(); 113 gfx::Size pref = static_cast<views::View*>(launcher_view)->GetPreferredSize();
37 widget_->SetBounds(gfx::Rect(0, 0, pref.width(), pref.height())); 114 widget_->SetBounds(gfx::Rect(0, 0, pref.width(), pref.height()));
38 widget_->SetContentsView(launcher_view); 115 widget_->SetContentsView(delegate_view_);
39 widget_->Show(); 116 widget_->Show();
40 widget_->GetNativeView()->SetName("LauncherView"); 117 widget_->GetNativeView()->SetName("LauncherView");
41 } 118 }
42 119
43 Launcher::~Launcher() { 120 Launcher::~Launcher() {
44 widget_->CloseNow(); 121 widget_->CloseNow();
45 window_container_->RemoveObserver(this); 122 window_container_->RemoveObserver(this);
46 for (WindowMap::iterator i = known_windows_.begin(); 123 for (WindowMap::iterator i = known_windows_.begin();
47 i != known_windows_.end(); ++i) { 124 i != known_windows_.end(); ++i) {
48 i->first->RemoveObserver(this); 125 i->first->RemoveObserver(this);
49 } 126 }
50 } 127 }
51 128
129 void Launcher::SetStatusWidth(int width) {
130 delegate_view_->SetStatusWidth(width);
131 }
132
133 int Launcher::GetStatusWidth() {
134 return delegate_view_->status_width();
135 }
136
52 void Launcher::MaybeAdd(aura::Window* window) { 137 void Launcher::MaybeAdd(aura::Window* window) {
53 if (known_windows_[window] == true) 138 if (known_windows_[window] == true)
54 return; // We already tried to add this window. 139 return; // We already tried to add this window.
55 140
56 known_windows_[window] = true; 141 known_windows_[window] = true;
57 ShellDelegate* delegate = Shell::GetInstance()->delegate(); 142 ShellDelegate* delegate = Shell::GetInstance()->delegate();
58 if (!delegate) 143 if (!delegate)
59 return; 144 return;
60 LauncherItem item; 145 LauncherItem item;
61 item.window = window; 146 item.window = window;
(...skipping 27 matching lines...) Expand all
89 model_->RemoveItemAt(i - model_->items().begin()); 174 model_->RemoveItemAt(i - model_->items().begin());
90 } 175 }
91 176
92 void Launcher::OnWindowVisibilityChanged(aura::Window* window, 177 void Launcher::OnWindowVisibilityChanged(aura::Window* window,
93 bool visibile) { 178 bool visibile) {
94 if (visibile && !known_windows_[window]) 179 if (visibile && !known_windows_[window])
95 MaybeAdd(window); 180 MaybeAdd(window);
96 } 181 }
97 182
98 } // namespace aura_shell 183 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/launcher/launcher.h ('k') | ui/aura_shell/launcher/launcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698