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

Side by Side Diff: ash/shelf/shelf_button.cc

Issue 1816753002: Enable mash shelf tooltips. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address destructor comment. Created 4 years, 9 months 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
« no previous file with comments | « ash/shelf/shelf_button.h ('k') | ash/shelf/shelf_button_host.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/shelf/shelf_button.h" 5 #include "ash/shelf/shelf_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/ash_constants.h" 9 #include "ash/ash_constants.h"
10 #include "ash/ash_switches.h" 10 #include "ash/ash_switches.h"
11 #include "ash/shelf/shelf.h" 11 #include "ash/shelf/shelf.h"
12 #include "ash/shelf/shelf_button_host.h" 12 #include "ash/shelf/shelf_view.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "grit/ash_resources.h" 14 #include "grit/ash_resources.h"
15 #include "skia/ext/image_operations.h" 15 #include "skia/ext/image_operations.h"
16 #include "ui/accessibility/ax_view_state.h" 16 #include "ui/accessibility/ax_view_state.h"
17 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/compositor/layer.h" 18 #include "ui/compositor/layer.h"
19 #include "ui/compositor/scoped_layer_animation_settings.h" 19 #include "ui/compositor/scoped_layer_animation_settings.h"
20 #include "ui/events/event_constants.h" 20 #include "ui/events/event_constants.h"
21 #include "ui/gfx/animation/animation_delegate.h" 21 #include "ui/gfx/animation/animation_delegate.h"
22 #include "ui/gfx/animation/throb_animation.h" 22 #include "ui/gfx/animation/throb_animation.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } // namespace 108 } // namespace
109 109
110 namespace ash { 110 namespace ash {
111 111
112 //////////////////////////////////////////////////////////////////////////////// 112 ////////////////////////////////////////////////////////////////////////////////
113 // ShelfButton::BarView 113 // ShelfButton::BarView
114 114
115 class ShelfButton::BarView : public views::ImageView, 115 class ShelfButton::BarView : public views::ImageView,
116 public ShelfButtonAnimation::Observer { 116 public ShelfButtonAnimation::Observer {
117 public: 117 public:
118 BarView(ShelfButton* host) 118 BarView(Shelf* shelf)
119 : host_(host), 119 : shelf_(shelf),
120 show_attention_(false), 120 show_attention_(false),
121 animation_end_time_(base::TimeTicks()), 121 animation_end_time_(base::TimeTicks()),
122 animating_(false) { 122 animating_(false) {
123 // Make sure the events reach the parent view for handling. 123 // Make sure the events reach the parent view for handling.
124 set_interactive(false); 124 set_interactive(false);
125 } 125 }
126 126
127 ~BarView() override { 127 ~BarView() override {
128 if (show_attention_) 128 if (show_attention_)
129 ShelfButtonAnimation::GetInstance()->RemoveObserver(this); 129 ShelfButtonAnimation::GetInstance()->RemoveObserver(this);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 void UpdateBounds() { 173 void UpdateBounds() {
174 gfx::Rect bounds = base_bounds_; 174 gfx::Rect bounds = base_bounds_;
175 if (show_attention_) { 175 if (show_attention_) {
176 // Scale from .35 to 1.0 of the total width (which is wider than the 176 // Scale from .35 to 1.0 of the total width (which is wider than the
177 // visible width of the image), so the animation "rests" briefly at full 177 // visible width of the image), so the animation "rests" briefly at full
178 // visible width. Cap bounds length at kIconSize to prevent visual 178 // visible width. Cap bounds length at kIconSize to prevent visual
179 // flutter while centering bar within further expanding bounds. 179 // flutter while centering bar within further expanding bounds.
180 double animation = animating_ ? 180 double animation = animating_ ?
181 ShelfButtonAnimation::GetInstance()->GetAnimation() : 1.0; 181 ShelfButtonAnimation::GetInstance()->GetAnimation() : 1.0;
182 double scale = .35 + .65 * animation; 182 double scale = .35 + .65 * animation;
183 if (host_->shelf()->alignment() == SHELF_ALIGNMENT_BOTTOM) { 183 if (shelf_->alignment() == SHELF_ALIGNMENT_BOTTOM) {
184 int width = base_bounds_.width() * scale; 184 int width = base_bounds_.width() * scale;
185 bounds.set_width(std::min(width, kIconSize)); 185 bounds.set_width(std::min(width, kIconSize));
186 int x_offset = (base_bounds_.width() - bounds.width()) / 2; 186 int x_offset = (base_bounds_.width() - bounds.width()) / 2;
187 bounds.set_x(base_bounds_.x() + x_offset); 187 bounds.set_x(base_bounds_.x() + x_offset);
188 UpdateAnimating(bounds.width() == kIconSize); 188 UpdateAnimating(bounds.width() == kIconSize);
189 } else { 189 } else {
190 int height = base_bounds_.height() * scale; 190 int height = base_bounds_.height() * scale;
191 bounds.set_height(std::min(height, kIconSize)); 191 bounds.set_height(std::min(height, kIconSize));
192 int y_offset = (base_bounds_.height() - bounds.height()) / 2; 192 int y_offset = (base_bounds_.height() - bounds.height()) / 2;
193 bounds.set_y(base_bounds_.y() + y_offset); 193 bounds.set_y(base_bounds_.y() + y_offset);
194 UpdateAnimating(bounds.height() == kIconSize); 194 UpdateAnimating(bounds.height() == kIconSize);
195 } 195 }
196 } 196 }
197 SetBoundsRect(bounds); 197 SetBoundsRect(bounds);
198 } 198 }
199 199
200 void UpdateAnimating(bool max_length) { 200 void UpdateAnimating(bool max_length) {
201 if (!max_length) 201 if (!max_length)
202 return; 202 return;
203 if (base::TimeTicks::Now() > animation_end_time_) { 203 if (base::TimeTicks::Now() > animation_end_time_) {
204 animating_ = false; 204 animating_ = false;
205 ShelfButtonAnimation::GetInstance()->RemoveObserver(this); 205 ShelfButtonAnimation::GetInstance()->RemoveObserver(this);
206 } 206 }
207 } 207 }
208 208
209 ShelfButton* host_; 209 Shelf* shelf_;
210 bool show_attention_; 210 bool show_attention_;
211 base::TimeTicks animation_end_time_; // For attention throbbing underline. 211 base::TimeTicks animation_end_time_; // For attention throbbing underline.
212 bool animating_; // Is time-limited attention animation running? 212 bool animating_; // Is time-limited attention animation running?
213 gfx::Rect base_bounds_; 213 gfx::Rect base_bounds_;
214 214
215 DISALLOW_COPY_AND_ASSIGN(BarView); 215 DISALLOW_COPY_AND_ASSIGN(BarView);
216 }; 216 };
217 217
218 //////////////////////////////////////////////////////////////////////////////// 218 ////////////////////////////////////////////////////////////////////////////////
219 // ShelfButton::IconView
220
221 ShelfButton::IconView::IconView() : icon_size_(kIconSize) {
222 // Do not make this interactive, so that events are sent to ShelfView for
223 // handling.
224 set_interactive(false);
225 }
226
227 ShelfButton::IconView::~IconView() {
228 }
229
230 ////////////////////////////////////////////////////////////////////////////////
231 // ShelfButton 219 // ShelfButton
232 220
233 // static 221 // static
234 const char ShelfButton::kViewClassName[] = "ash/ShelfButton"; 222 const char ShelfButton::kViewClassName[] = "ash/ShelfButton";
235 223
236 ShelfButton* ShelfButton::Create(views::ButtonListener* listener, 224 ShelfButton::ShelfButton(ShelfView* shelf_view)
237 ShelfButtonHost* host, 225 : CustomButton(shelf_view),
238 Shelf* shelf) { 226 shelf_view_(shelf_view),
239 ShelfButton* button = new ShelfButton(listener, host, shelf); 227 icon_view_(new views::ImageView()),
240 button->Init(); 228 bar_(new BarView(shelf_view->shelf())),
241 return button;
242 }
243
244 ShelfButton::ShelfButton(views::ButtonListener* listener,
245 ShelfButtonHost* host,
246 Shelf* shelf)
247 : CustomButton(listener),
248 host_(host),
249 icon_view_(NULL),
250 bar_(new BarView(this)),
251 state_(STATE_NORMAL), 229 state_(STATE_NORMAL),
252 shelf_(shelf), 230 destroyed_flag_(nullptr) {
253 destroyed_flag_(NULL) {
254 SetAccessibilityFocusable(true); 231 SetAccessibilityFocusable(true);
255 232
256 const gfx::ShadowValue kShadows[] = { 233 const gfx::ShadowValue kShadows[] = {
257 gfx::ShadowValue(gfx::Vector2d(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)), 234 gfx::ShadowValue(gfx::Vector2d(0, 2), 0, SkColorSetARGB(0x1A, 0, 0, 0)),
258 gfx::ShadowValue(gfx::Vector2d(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)), 235 gfx::ShadowValue(gfx::Vector2d(0, 3), 1, SkColorSetARGB(0x1A, 0, 0, 0)),
259 gfx::ShadowValue(gfx::Vector2d(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)), 236 gfx::ShadowValue(gfx::Vector2d(0, 0), 1, SkColorSetARGB(0x54, 0, 0, 0)),
260 }; 237 };
261 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows)); 238 icon_shadows_.assign(kShadows, kShadows + arraysize(kShadows));
262 239
240 // TODO: refactor the layers so each button doesn't require 2.
241 icon_view_->SetPaintToLayer(true);
242 icon_view_->layer()->SetFillsBoundsOpaquely(false);
243 icon_view_->SetHorizontalAlignment(views::ImageView::CENTER);
244 icon_view_->SetVerticalAlignment(views::ImageView::LEADING);
245 // Do not make this interactive, so that events are sent to ShelfView.
246 icon_view_->set_interactive(false);
247
263 AddChildView(bar_); 248 AddChildView(bar_);
249 AddChildView(icon_view_);
264 } 250 }
265 251
266 ShelfButton::~ShelfButton() { 252 ShelfButton::~ShelfButton() {
267 if (destroyed_flag_) 253 if (destroyed_flag_)
268 *destroyed_flag_ = true; 254 *destroyed_flag_ = true;
269 } 255 }
270 256
271 void ShelfButton::SetShadowedImage(const gfx::ImageSkia& image) { 257 void ShelfButton::SetShadowedImage(const gfx::ImageSkia& image) {
272 icon_view_->SetImage(gfx::ImageSkiaOperations::CreateImageWithDropShadow( 258 icon_view_->SetImage(gfx::ImageSkiaOperations::CreateImageWithDropShadow(
273 image, icon_shadows_)); 259 image, icon_shadows_));
274 } 260 }
275 261
276 void ShelfButton::SetImage(const gfx::ImageSkia& image) { 262 void ShelfButton::SetImage(const gfx::ImageSkia& image) {
277 if (image.isNull()) { 263 if (image.isNull()) {
278 // TODO: need an empty image. 264 // TODO: need an empty image.
279 icon_view_->SetImage(image); 265 icon_view_->SetImage(image);
280 return; 266 return;
281 } 267 }
282 268
283 if (icon_view_->icon_size() == 0) {
284 SetShadowedImage(image);
285 return;
286 }
287
288 // Resize the image maintaining our aspect ratio. 269 // Resize the image maintaining our aspect ratio.
289 int pref = icon_view_->icon_size();
290 float aspect_ratio = 270 float aspect_ratio =
291 static_cast<float>(image.width()) / static_cast<float>(image.height()); 271 static_cast<float>(image.width()) / static_cast<float>(image.height());
292 int height = pref; 272 int height = kIconSize;
293 int width = static_cast<int>(aspect_ratio * height); 273 int width = static_cast<int>(aspect_ratio * height);
294 if (width > pref) { 274 if (width > kIconSize) {
295 width = pref; 275 width = kIconSize;
296 height = static_cast<int>(width / aspect_ratio); 276 height = static_cast<int>(width / aspect_ratio);
297 } 277 }
298 278
299 if (width == image.width() && height == image.height()) { 279 if (width == image.width() && height == image.height()) {
300 SetShadowedImage(image); 280 SetShadowedImage(image);
301 return; 281 return;
302 } 282 }
303 283
304 SetShadowedImage(gfx::ImageSkiaOperations::CreateResizedImage(image, 284 SetShadowedImage(gfx::ImageSkiaOperations::CreateResizedImage(image,
305 skia::ImageOperations::RESIZE_BEST, gfx::Size(width, height))); 285 skia::ImageOperations::RESIZE_BEST, gfx::Size(width, height)));
(...skipping 29 matching lines...) Expand all
335 ui::MenuSourceType source_type) { 315 ui::MenuSourceType source_type) {
336 if (!context_menu_controller()) 316 if (!context_menu_controller())
337 return; 317 return;
338 318
339 bool destroyed = false; 319 bool destroyed = false;
340 destroyed_flag_ = &destroyed; 320 destroyed_flag_ = &destroyed;
341 321
342 CustomButton::ShowContextMenu(p, source_type); 322 CustomButton::ShowContextMenu(p, source_type);
343 323
344 if (!destroyed) { 324 if (!destroyed) {
345 destroyed_flag_ = NULL; 325 destroyed_flag_ = nullptr;
346 // The menu will not propagate mouse events while its shown. To address, 326 // The menu will not propagate mouse events while its shown. To address,
347 // the hover state gets cleared once the menu was shown (and this was not 327 // the hover state gets cleared once the menu was shown (and this was not
348 // destroyed). 328 // destroyed).
349 ClearState(STATE_HOVERED); 329 ClearState(STATE_HOVERED);
350 } 330 }
351 } 331 }
352 332
353 const char* ShelfButton::GetClassName() const { 333 const char* ShelfButton::GetClassName() const {
354 return kViewClassName; 334 return kViewClassName;
355 } 335 }
356 336
357 bool ShelfButton::OnMousePressed(const ui::MouseEvent& event) { 337 bool ShelfButton::OnMousePressed(const ui::MouseEvent& event) {
358 CustomButton::OnMousePressed(event); 338 CustomButton::OnMousePressed(event);
359 host_->PointerPressedOnButton(this, ShelfButtonHost::MOUSE, event); 339 shelf_view_->PointerPressedOnButton(this, ShelfView::MOUSE, event);
360 return true; 340 return true;
361 } 341 }
362 342
363 void ShelfButton::OnMouseReleased(const ui::MouseEvent& event) { 343 void ShelfButton::OnMouseReleased(const ui::MouseEvent& event) {
364 CustomButton::OnMouseReleased(event); 344 CustomButton::OnMouseReleased(event);
365 host_->PointerReleasedOnButton(this, ShelfButtonHost::MOUSE, false); 345 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, false);
366 } 346 }
367 347
368 void ShelfButton::OnMouseCaptureLost() { 348 void ShelfButton::OnMouseCaptureLost() {
369 ClearState(STATE_HOVERED); 349 ClearState(STATE_HOVERED);
370 host_->PointerReleasedOnButton(this, ShelfButtonHost::MOUSE, true); 350 shelf_view_->PointerReleasedOnButton(this, ShelfView::MOUSE, true);
371 CustomButton::OnMouseCaptureLost(); 351 CustomButton::OnMouseCaptureLost();
372 } 352 }
373 353
374 bool ShelfButton::OnMouseDragged(const ui::MouseEvent& event) { 354 bool ShelfButton::OnMouseDragged(const ui::MouseEvent& event) {
375 CustomButton::OnMouseDragged(event); 355 CustomButton::OnMouseDragged(event);
376 host_->PointerDraggedOnButton(this, ShelfButtonHost::MOUSE, event); 356 shelf_view_->PointerDraggedOnButton(this, ShelfView::MOUSE, event);
377 return true; 357 return true;
378 } 358 }
379 359
380 void ShelfButton::OnMouseMoved(const ui::MouseEvent& event) {
381 CustomButton::OnMouseMoved(event);
382 host_->MouseMovedOverButton(this);
383 }
384
385 void ShelfButton::OnMouseEntered(const ui::MouseEvent& event) {
386 AddState(STATE_HOVERED);
387 CustomButton::OnMouseEntered(event);
388 host_->MouseEnteredButton(this);
389 }
390
391 void ShelfButton::OnMouseExited(const ui::MouseEvent& event) {
392 ClearState(STATE_HOVERED);
393 CustomButton::OnMouseExited(event);
394 host_->MouseExitedButton(this);
395 }
396
397 void ShelfButton::GetAccessibleState(ui::AXViewState* state) { 360 void ShelfButton::GetAccessibleState(ui::AXViewState* state) {
398 state->role = ui::AX_ROLE_BUTTON; 361 state->role = ui::AX_ROLE_BUTTON;
399 state->name = host_->GetAccessibleName(this); 362 state->name = shelf_view_->GetTitleForView(this);
400 } 363 }
401 364
402 void ShelfButton::Layout() { 365 void ShelfButton::Layout() {
403 const gfx::Rect button_bounds(GetContentsBounds()); 366 const gfx::Rect button_bounds(GetContentsBounds());
404 int icon_pad = shelf_->IsHorizontalAlignment() ? kIconPad : kIconPadVertical; 367 Shelf* shelf = shelf_view_->shelf();
405 int x_offset = shelf_->PrimaryAxisValue(0, icon_pad); 368 int icon_pad = shelf->PrimaryAxisValue(kIconPad, kIconPadVertical);
406 int y_offset = shelf_->PrimaryAxisValue(icon_pad, 0); 369 int x_offset = shelf->PrimaryAxisValue(0, icon_pad);
370 int y_offset = shelf->PrimaryAxisValue(icon_pad, 0);
407 371
408 int icon_width = std::min(kIconSize, 372 int icon_width = std::min(kIconSize, button_bounds.width() - x_offset);
409 button_bounds.width() - x_offset); 373 int icon_height = std::min(kIconSize, button_bounds.height() - y_offset);
410 int icon_height = std::min(kIconSize,
411 button_bounds.height() - y_offset);
412 374
413 // If on the left or top 'invert' the inset so the constant gap is on 375 // If on the left or top 'invert' the inset so the constant gap is on
414 // the interior (towards the center of display) edge of the shelf. 376 // the interior (towards the center of display) edge of the shelf.
415 if (SHELF_ALIGNMENT_LEFT == shelf_->alignment()) 377 if (SHELF_ALIGNMENT_LEFT == shelf->alignment())
416 x_offset = button_bounds.width() - (kIconSize + icon_pad); 378 x_offset = button_bounds.width() - (kIconSize + icon_pad);
417 379
418 if (SHELF_ALIGNMENT_TOP == shelf_->alignment()) 380 if (SHELF_ALIGNMENT_TOP == shelf->alignment())
419 y_offset = button_bounds.height() - (kIconSize + icon_pad); 381 y_offset = button_bounds.height() - (kIconSize + icon_pad);
420 382
421 // Center icon with respect to the secondary axis, and ensure 383 // Center icon with respect to the secondary axis, and ensure
422 // that the icon doesn't occlude the bar highlight. 384 // that the icon doesn't occlude the bar highlight.
423 if (shelf_->IsHorizontalAlignment()) { 385 if (shelf->IsHorizontalAlignment()) {
424 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; 386 x_offset = std::max(0, button_bounds.width() - icon_width) / 2;
425 if (y_offset + icon_height + kBarSize > button_bounds.height()) 387 if (y_offset + icon_height + kBarSize > button_bounds.height())
426 icon_height = button_bounds.height() - (y_offset + kBarSize); 388 icon_height = button_bounds.height() - (y_offset + kBarSize);
427 } else { 389 } else {
428 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; 390 y_offset = std::max(0, button_bounds.height() - icon_height) / 2;
429 if (x_offset + icon_width + kBarSize > button_bounds.width()) 391 if (x_offset + icon_width + kBarSize > button_bounds.width())
430 icon_width = button_bounds.width() - (x_offset + kBarSize); 392 icon_width = button_bounds.width() - (x_offset + kBarSize);
431 } 393 }
432 394
433 // Expand bounds to include shadows. 395 // Expand bounds to include shadows.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 439
478 void ShelfButton::OnGestureEvent(ui::GestureEvent* event) { 440 void ShelfButton::OnGestureEvent(ui::GestureEvent* event) {
479 switch (event->type()) { 441 switch (event->type()) {
480 case ui::ET_GESTURE_TAP_DOWN: 442 case ui::ET_GESTURE_TAP_DOWN:
481 AddState(STATE_HOVERED); 443 AddState(STATE_HOVERED);
482 return CustomButton::OnGestureEvent(event); 444 return CustomButton::OnGestureEvent(event);
483 case ui::ET_GESTURE_END: 445 case ui::ET_GESTURE_END:
484 ClearState(STATE_HOVERED); 446 ClearState(STATE_HOVERED);
485 return CustomButton::OnGestureEvent(event); 447 return CustomButton::OnGestureEvent(event);
486 case ui::ET_GESTURE_SCROLL_BEGIN: 448 case ui::ET_GESTURE_SCROLL_BEGIN:
487 host_->PointerPressedOnButton(this, ShelfButtonHost::TOUCH, *event); 449 shelf_view_->PointerPressedOnButton(this, ShelfView::TOUCH, *event);
488 event->SetHandled(); 450 event->SetHandled();
489 return; 451 return;
490 case ui::ET_GESTURE_SCROLL_UPDATE: 452 case ui::ET_GESTURE_SCROLL_UPDATE:
491 host_->PointerDraggedOnButton(this, ShelfButtonHost::TOUCH, *event); 453 shelf_view_->PointerDraggedOnButton(this, ShelfView::TOUCH, *event);
492 event->SetHandled(); 454 event->SetHandled();
493 return; 455 return;
494 case ui::ET_GESTURE_SCROLL_END: 456 case ui::ET_GESTURE_SCROLL_END:
495 case ui::ET_SCROLL_FLING_START: 457 case ui::ET_SCROLL_FLING_START:
496 host_->PointerReleasedOnButton(this, ShelfButtonHost::TOUCH, false); 458 shelf_view_->PointerReleasedOnButton(this, ShelfView::TOUCH, false);
497 event->SetHandled(); 459 event->SetHandled();
498 return; 460 return;
499 default: 461 default:
500 return CustomButton::OnGestureEvent(event); 462 return CustomButton::OnGestureEvent(event);
501 } 463 }
502 } 464 }
503 465
504 void ShelfButton::Init() {
505 icon_view_ = CreateIconView();
506
507 // TODO: refactor the layers so each button doesn't require 2.
508 icon_view_->SetPaintToLayer(true);
509 icon_view_->layer()->SetFillsBoundsOpaquely(false);
510 icon_view_->SetHorizontalAlignment(views::ImageView::CENTER);
511 icon_view_->SetVerticalAlignment(views::ImageView::LEADING);
512
513 AddChildView(icon_view_);
514 }
515
516 ShelfButton::IconView* ShelfButton::CreateIconView() {
517 return new IconView;
518 }
519
520 void ShelfButton::UpdateState() { 466 void ShelfButton::UpdateState() {
521 UpdateBar(); 467 UpdateBar();
522 468 Shelf* shelf = shelf_view_->shelf();
523 icon_view_->SetHorizontalAlignment(shelf_->PrimaryAxisValue( 469 icon_view_->SetHorizontalAlignment(shelf->PrimaryAxisValue(
524 views::ImageView::CENTER, views::ImageView::LEADING)); 470 views::ImageView::CENTER, views::ImageView::LEADING));
525 icon_view_->SetVerticalAlignment(shelf_->PrimaryAxisValue( 471 icon_view_->SetVerticalAlignment(shelf->PrimaryAxisValue(
526 views::ImageView::LEADING, views::ImageView::CENTER)); 472 views::ImageView::LEADING, views::ImageView::CENTER));
527 SchedulePaint(); 473 SchedulePaint();
528 } 474 }
529 475
530 void ShelfButton::UpdateBar() { 476 void ShelfButton::UpdateBar() {
531 if (state_ & STATE_HIDDEN) { 477 if (state_ & STATE_HIDDEN) {
532 bar_->SetVisible(false); 478 bar_->SetVisible(false);
533 return; 479 return;
534 } 480 }
535 481
536 int bar_id = 0; 482 int bar_id = 0;
537 if (state_ & (STATE_ACTIVE)) 483 if (state_ & (STATE_ACTIVE))
538 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE; 484 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE;
539 else if (state_ & STATE_ATTENTION) 485 else if (state_ & STATE_ATTENTION)
540 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION; 486 bar_id = IDR_ASH_SHELF_UNDERLINE_ATTENTION;
541 else if (state_ & STATE_RUNNING) 487 else if (state_ & STATE_RUNNING)
542 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING; 488 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING;
543 489
544 if (bar_id != 0) { 490 if (bar_id != 0) {
545 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 491 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
546 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia(); 492 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia();
547 if (shelf_->alignment() == SHELF_ALIGNMENT_BOTTOM) { 493
494 Shelf* shelf = shelf_view_->shelf();
495 if (shelf->alignment() == SHELF_ALIGNMENT_BOTTOM) {
548 bar_->SetImage(*image); 496 bar_->SetImage(*image);
549 } else { 497 } else {
550 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage( 498 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(
551 *image, shelf_->SelectValueForShelfAlignment( 499 *image, shelf->SelectValueForShelfAlignment(
552 SkBitmapOperations::ROTATION_90_CW, 500 SkBitmapOperations::ROTATION_90_CW,
553 SkBitmapOperations::ROTATION_90_CW, 501 SkBitmapOperations::ROTATION_90_CW,
554 SkBitmapOperations::ROTATION_270_CW, 502 SkBitmapOperations::ROTATION_270_CW,
555 SkBitmapOperations::ROTATION_180_CW))); 503 SkBitmapOperations::ROTATION_180_CW)));
556 } 504 }
557 bar_->SetHorizontalAlignment(shelf_->SelectValueForShelfAlignment( 505 bar_->SetHorizontalAlignment(shelf->SelectValueForShelfAlignment(
558 views::ImageView::CENTER, views::ImageView::LEADING, 506 views::ImageView::CENTER, views::ImageView::LEADING,
559 views::ImageView::TRAILING, views::ImageView::CENTER)); 507 views::ImageView::TRAILING, views::ImageView::CENTER));
560 bar_->SetVerticalAlignment(shelf_->SelectValueForShelfAlignment( 508 bar_->SetVerticalAlignment(shelf->SelectValueForShelfAlignment(
561 views::ImageView::TRAILING, views::ImageView::CENTER, 509 views::ImageView::TRAILING, views::ImageView::CENTER,
562 views::ImageView::CENTER, views::ImageView::LEADING)); 510 views::ImageView::CENTER, views::ImageView::LEADING));
563 bar_->SchedulePaint(); 511 bar_->SchedulePaint();
564 } 512 }
565 513
566 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); 514 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL);
567 } 515 }
568 516
569 } // namespace ash 517 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_button.h ('k') | ash/shelf/shelf_button_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698