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

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

Issue 8914023: Relands fixes for 106432, 107287 and 107401. These got reverted (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Da fix 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.cc ('k') | ui/aura_shell/launcher/tabbed_launcher_button.h » ('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_view.h" 5 #include "ui/aura_shell/launcher/launcher_view.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "grit/ui_resources.h" 8 #include "grit/ui_resources.h"
9 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
10 #include "ui/aura_shell/launcher/app_launcher_button.h" 10 #include "ui/aura_shell/launcher/app_launcher_button.h"
11 #include "ui/aura_shell/launcher/launcher_model.h" 11 #include "ui/aura_shell/launcher/launcher_model.h"
12 #include "ui/aura_shell/launcher/tabbed_launcher_button.h" 12 #include "ui/aura_shell/launcher/tabbed_launcher_button.h"
13 #include "ui/aura_shell/launcher/view_model.h" 13 #include "ui/aura_shell/launcher/view_model.h"
14 #include "ui/aura_shell/launcher/view_model_utils.h" 14 #include "ui/aura_shell/launcher/view_model_utils.h"
15 #include "ui/aura_shell/shelf_layout_manager.h"
15 #include "ui/aura_shell/shell.h" 16 #include "ui/aura_shell/shell.h"
16 #include "ui/aura_shell/shell_delegate.h" 17 #include "ui/aura_shell/shell_delegate.h"
17 #include "ui/base/animation/animation.h" 18 #include "ui/base/animation/animation.h"
18 #include "ui/base/animation/throb_animation.h" 19 #include "ui/base/animation/throb_animation.h"
19 #include "ui/base/models/simple_menu_model.h" 20 #include "ui/base/models/simple_menu_model.h"
20 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/gfx/canvas.h"
21 #include "ui/gfx/compositor/layer.h" 23 #include "ui/gfx/compositor/layer.h"
22 #include "ui/gfx/image/image.h" 24 #include "ui/gfx/image/image.h"
23 #include "ui/views/animation/bounds_animator.h" 25 #include "ui/views/animation/bounds_animator.h"
24 #include "ui/views/controls/button/image_button.h" 26 #include "ui/views/controls/button/image_button.h"
25 #include "ui/views/controls/menu/menu_model_adapter.h" 27 #include "ui/views/controls/menu/menu_model_adapter.h"
26 #include "ui/views/controls/menu/menu_runner.h" 28 #include "ui/views/controls/menu/menu_runner.h"
29 #include "ui/views/painter.h"
27 #include "ui/views/widget/widget.h" 30 #include "ui/views/widget/widget.h"
28 31
29 using ui::Animation; 32 using ui::Animation;
30 using views::View; 33 using views::View;
31 34
32 namespace aura_shell { 35 namespace aura_shell {
33 namespace internal { 36 namespace internal {
34 37
35 // Padding between each view. 38 // Padding between each view.
36 static const int kHorizontalPadding = 12; 39 static const int kHorizontalPadding = 12;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 activated_command_id_ = command_id; 78 activated_command_id_ = command_id;
76 } 79 }
77 80
78 private: 81 private:
79 // ID of the command passed to ExecuteCommand. 82 // ID of the command passed to ExecuteCommand.
80 int activated_command_id_; 83 int activated_command_id_;
81 84
82 DISALLOW_COPY_AND_ASSIGN(MenuDelegateImpl); 85 DISALLOW_COPY_AND_ASSIGN(MenuDelegateImpl);
83 }; 86 };
84 87
85 // ImageButton subclass that animates transition changes using the opacity of
86 // the layer.
87 class FadeButton : public views::ImageButton {
88 public:
89 explicit FadeButton(views::ButtonListener* listener)
90 : ImageButton(listener) {
91 SetPaintToLayer(true);
92 layer()->SetFillsBoundsOpaquely(false);
93 layer()->SetOpacity(kDimmedButtonOpacity);
94 }
95
96 protected:
97 // ImageButton overrides:
98 virtual SkBitmap GetImageToPaint() OVERRIDE {
99 // ImageButton::GetImageToPaint returns an alpha blended image based on
100 // hover_animation_. FadeButton uses hover_animation to change the opacity
101 // of the layer, so this can be overriden to return the normal image always.
102 return images_[BS_NORMAL];
103 }
104 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE {
105 layer()->SetOpacity(kDimmedButtonOpacity + (1.0f - kDimmedButtonOpacity) *
106 animation->GetCurrentValue());
107 layer()->ScheduleDraw();
108 }
109 virtual void StateChanged() OVERRIDE {
110 if (!hover_animation_->is_animating()) {
111 float opacity = state_ == BS_NORMAL ? kDimmedButtonOpacity : 1.0f;
112 if (layer()->opacity() != opacity) {
113 layer()->SetOpacity(opacity);
114 layer()->ScheduleDraw();
115 }
116 }
117 }
118 virtual void SchedulePaint() OVERRIDE {
119 // All changes we care about trigger a draw on the layer, so this can be
120 // overriden to do nothing.
121 }
122
123 private:
124 DISALLOW_COPY_AND_ASSIGN(FadeButton);
125 };
126
127 // AnimationDelegate that deletes a view when done. This is used when a launcher 88 // AnimationDelegate that deletes a view when done. This is used when a launcher
128 // item is removed, which triggers a remove animation. When the animation is 89 // item is removed, which triggers a remove animation. When the animation is
129 // done we delete the view. 90 // done we delete the view.
130 class DeleteViewAnimationDelegate : 91 class DeleteViewAnimationDelegate :
131 public views::BoundsAnimator::OwnedAnimationDelegate { 92 public views::BoundsAnimator::OwnedAnimationDelegate {
132 public: 93 public:
133 explicit DeleteViewAnimationDelegate(views::View* view) : view_(view) {} 94 explicit DeleteViewAnimationDelegate(views::View* view) : view_(view) {}
134 virtual ~DeleteViewAnimationDelegate() {} 95 virtual ~DeleteViewAnimationDelegate() {}
135 96
136 private: 97 private:
(...skipping 23 matching lines...) Expand all
160 view_->layer()->SetOpacity(1.0f); 121 view_->layer()->SetOpacity(1.0f);
161 view_->layer()->ScheduleDraw(); 122 view_->layer()->ScheduleDraw();
162 } 123 }
163 124
164 private: 125 private:
165 views::View* view_; 126 views::View* view_;
166 127
167 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate); 128 DISALLOW_COPY_AND_ASSIGN(FadeInAnimationDelegate);
168 }; 129 };
169 130
131 // Used to draw the background of the shelf.
132 class ShelfPainter : public views::Painter {
133 public:
134 ShelfPainter() {
135 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
136 image_ = *rb.GetImageNamed(IDR_AURA_LAUNCHER_BACKGROUND).ToSkBitmap();
137 }
138
139 virtual void Paint(int w, int h, gfx::Canvas* canvas) OVERRIDE {
140 canvas->TileImageInt(image_, 0, 0, w, h);
141 }
142
143 private:
144 SkBitmap image_;
145
146 DISALLOW_COPY_AND_ASSIGN(ShelfPainter);
147 };
148
149
170 } // namespace 150 } // namespace
171 151
172 // AnimationDelegate used when inserting a new item. This steadily decreased the 152 // AnimationDelegate used when inserting a new item. This steadily decreased the
173 // opacity of the layer as the animation progress. 153 // opacity of the layer as the animation progress.
174 class LauncherView::FadeOutAnimationDelegate : 154 class LauncherView::FadeOutAnimationDelegate :
175 public views::BoundsAnimator::OwnedAnimationDelegate { 155 public views::BoundsAnimator::OwnedAnimationDelegate {
176 public: 156 public:
177 FadeOutAnimationDelegate(LauncherView* host, views::View* view) 157 FadeOutAnimationDelegate(LauncherView* host, views::View* view)
178 : launcher_view_(host), 158 : launcher_view_(host),
179 view_(view) {} 159 view_(view) {}
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 start_drag_index_(-1) { 217 start_drag_index_(-1) {
238 DCHECK(model_); 218 DCHECK(model_);
239 bounds_animator_.reset(new views::BoundsAnimator(this)); 219 bounds_animator_.reset(new views::BoundsAnimator(this));
240 } 220 }
241 221
242 LauncherView::~LauncherView() { 222 LauncherView::~LauncherView() {
243 model_->RemoveObserver(this); 223 model_->RemoveObserver(this);
244 } 224 }
245 225
246 void LauncherView::Init() { 226 void LauncherView::Init() {
227 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
247 model_->AddObserver(this); 228 model_->AddObserver(this);
248 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 229
249 new_browser_button_ = new FadeButton(this); 230 set_background(
231 views::Background::CreateBackgroundPainter(true, new ShelfPainter()));
232
233 new_browser_button_ = new views::ImageButton(this);
234 ShellDelegate* delegate = Shell::GetInstance()->delegate();
235 int new_browser_button_image_id = delegate ?
236 delegate->GetResourceIDForNewBrowserWindow() :
237 IDR_AURA_LAUNCHER_ICON_CHROME;
250 new_browser_button_->SetImage( 238 new_browser_button_->SetImage(
251 views::CustomButton::BS_NORMAL, 239 views::CustomButton::BS_NORMAL,
252 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_CHROME).ToSkBitmap()); 240 rb.GetImageNamed(new_browser_button_image_id).ToSkBitmap());
253 ConfigureChildView(new_browser_button_); 241 ConfigureChildView(new_browser_button_);
254 AddChildView(new_browser_button_); 242 AddChildView(new_browser_button_);
255 243
256 const LauncherItems& items(model_->items()); 244 const LauncherItems& items(model_->items());
257 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { 245 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) {
258 views::View* child = CreateViewForItem(*i); 246 views::View* child = CreateViewForItem(*i);
259 child->SetPaintToLayer(true); 247 child->SetPaintToLayer(true);
260 view_model_->Add(child, static_cast<int>(i - items.begin())); 248 view_model_->Add(child, static_cast<int>(i - items.begin()));
261 AddChildView(child); 249 AddChildView(child);
262 } 250 }
263 251
264 show_apps_button_ = new FadeButton(this); 252 show_apps_button_ = new views::ImageButton(this);
265 show_apps_button_->SetImage( 253 show_apps_button_->SetImage(
266 views::CustomButton::BS_NORMAL, 254 views::CustomButton::BS_NORMAL,
267 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToSkBitmap()); 255 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST).ToSkBitmap());
256 show_apps_button_->SetImage(
257 views::CustomButton::BS_HOT,
258 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_HOT).ToSkBitmap());
259 show_apps_button_->SetImage(
260 views::CustomButton::BS_PUSHED,
261 rb.GetImageNamed(IDR_AURA_LAUNCHER_ICON_APPLIST_PUSHED).ToSkBitmap());
268 ConfigureChildView(show_apps_button_); 262 ConfigureChildView(show_apps_button_);
269 AddChildView(show_apps_button_); 263 AddChildView(show_apps_button_);
270 264
271 overflow_button_ = new FadeButton(this); 265 overflow_button_ = new views::ImageButton(this);
272 // TODO: need image for this.
273 overflow_button_->SetImage( 266 overflow_button_->SetImage(
274 views::CustomButton::BS_NORMAL, 267 views::CustomButton::BS_NORMAL,
275 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToSkBitmap()); 268 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToSkBitmap());
269 overflow_button_->SetImage(
270 views::CustomButton::BS_HOT,
271 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_HOT).ToSkBitmap());
272 overflow_button_->SetImage(
273 views::CustomButton::BS_PUSHED,
274 rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW_PUSHED).ToSkBitmap());
276 ConfigureChildView(overflow_button_); 275 ConfigureChildView(overflow_button_);
277 AddChildView(overflow_button_); 276 AddChildView(overflow_button_);
278 277
279 // We'll layout when our bounds change. 278 // We'll layout when our bounds change.
280 } 279 }
281 280
282 void LauncherView::LayoutToIdealBounds() { 281 void LauncherView::LayoutToIdealBounds() {
283 IdealBounds ideal_bounds; 282 IdealBounds ideal_bounds;
284 CalculateIdealBounds(&ideal_bounds); 283 CalculateIdealBounds(&ideal_bounds);
285 new_browser_button_->SetBoundsRect(ideal_bounds.new_browser_bounds); 284 new_browser_button_->SetBoundsRect(ideal_bounds.new_browser_bounds);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 overflow_button_->SetVisible(show_overflow); 328 overflow_button_->SetVisible(show_overflow);
330 if (show_overflow) { 329 if (show_overflow) {
331 DCHECK_NE(0, view_model_->view_size()); 330 DCHECK_NE(0, view_model_->view_size());
332 x = view_model_->ideal_bounds(last_visible_index).right() + 331 x = view_model_->ideal_bounds(last_visible_index).right() +
333 kHorizontalPadding; 332 kHorizontalPadding;
334 bounds->overflow_bounds.set_x(x); 333 bounds->overflow_bounds.set_x(x);
335 bounds->overflow_bounds.set_y( 334 bounds->overflow_bounds.set_y(
336 (kPreferredHeight - bounds->overflow_bounds.height()) / 2); 335 (kPreferredHeight - bounds->overflow_bounds.height()) / 2);
337 x = bounds->overflow_bounds.right() + kHorizontalPadding; 336 x = bounds->overflow_bounds.right() + kHorizontalPadding;
338 } 337 }
339 // TODO(sky): -8 is a hack, remove when we get better images. 338 // TODO(sky): -6 is a hack, remove when we get better images.
340 bounds->show_apps_bounds.set_x(x - 8); 339 bounds->show_apps_bounds.set_x(x - 6);
341 bounds->show_apps_bounds.set_y( 340 bounds->show_apps_bounds.set_y(
342 (kPreferredHeight - bounds->show_apps_bounds.height()) / 2); 341 (kPreferredHeight - bounds->show_apps_bounds.height()) / 2);
343 } 342 }
344 343
345 int LauncherView::DetermineLastVisibleIndex(int max_x) { 344 int LauncherView::DetermineLastVisibleIndex(int max_x) {
346 int index = view_model_->view_size() - 1; 345 int index = view_model_->view_size() - 1;
347 while (index >= 0 && view_model_->ideal_bounds(index).right() > max_x) 346 while (index >= 0 && view_model_->ideal_bounds(index).right() > max_x)
348 index--; 347 index--;
349 return index; 348 return index;
350 } 349 }
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
604 } else { 603 } else {
605 int view_index = view_model_->GetIndexOfView(sender); 604 int view_index = view_model_->GetIndexOfView(sender);
606 // May be -1 while in the process of animating closed. 605 // May be -1 while in the process of animating closed.
607 if (view_index != -1) 606 if (view_index != -1)
608 delegate->LauncherItemClicked(model_->items()[view_index]); 607 delegate->LauncherItemClicked(model_->items()[view_index]);
609 } 608 }
610 } 609 }
611 610
612 } // namespace internal 611 } // namespace internal
613 } // namespace aura_shell 612 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/launcher/launcher.cc ('k') | ui/aura_shell/launcher/tabbed_launcher_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698