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

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

Issue 176883022: Shelf Cleanup (- binary files) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 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 | Annotate | Revision Log
« no previous file with comments | « ash/shelf/overflow_button.cc ('k') | ash/shelf/shelf_constants.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"
(...skipping 13 matching lines...) Expand all
24 #include "ui/gfx/image/image_skia_operations.h" 24 #include "ui/gfx/image/image_skia_operations.h"
25 #include "ui/gfx/skbitmap_operations.h" 25 #include "ui/gfx/skbitmap_operations.h"
26 #include "ui/views/controls/image_view.h" 26 #include "ui/views/controls/image_view.h"
27 27
28 namespace { 28 namespace {
29 29
30 // Size of the bar. This is along the opposite axis of the shelf. For example, 30 // Size of the bar. This is along the opposite axis of the shelf. For example,
31 // if the shelf is aligned horizontally then this is the height of the bar. 31 // if the shelf is aligned horizontally then this is the height of the bar.
32 const int kBarSize = 3; 32 const int kBarSize = 3;
33 const int kIconSize = 32; 33 const int kIconSize = 32;
34 const int kHopSpacing = 2; 34 const int kIconPad = 5;
35 const int kIconPad = 8; 35 const int kIconPadVertical = 6;
36 const int kAlternateIconPad = 5;
37 const int kAlternateIconPadVertical = 6;
38 const int kHopUpMS = 0;
39 const int kHopDownMS = 200;
40 const int kAttentionThrobDurationMS = 800; 36 const int kAttentionThrobDurationMS = 800;
41 37
42 bool ShouldHop(int state) {
43 return state & ash::internal::ShelfButton::STATE_HOVERED ||
44 state & ash::internal::ShelfButton::STATE_ACTIVE ||
45 state & ash::internal::ShelfButton::STATE_FOCUSED;
46 }
47
48 // Simple AnimationDelegate that owns a single ThrobAnimation instance to 38 // Simple AnimationDelegate that owns a single ThrobAnimation instance to
49 // keep all Draw Attention animations in sync. 39 // keep all Draw Attention animations in sync.
50 class ShelfButtonAnimation : public gfx::AnimationDelegate { 40 class ShelfButtonAnimation : public gfx::AnimationDelegate {
51 public: 41 public:
52 class Observer { 42 class Observer {
53 public: 43 public:
54 virtual void AnimationProgressed() = 0; 44 virtual void AnimationProgressed() = 0;
55 45
56 protected: 46 protected:
57 virtual ~Observer() {} 47 virtual ~Observer() {}
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 SetShadowedImage(gfx::ImageSkiaOperations::CreateResizedImage(image, 281 SetShadowedImage(gfx::ImageSkiaOperations::CreateResizedImage(image,
292 skia::ImageOperations::RESIZE_BEST, gfx::Size(width, height))); 282 skia::ImageOperations::RESIZE_BEST, gfx::Size(width, height)));
293 } 283 }
294 284
295 const gfx::ImageSkia& ShelfButton::GetImage() const { 285 const gfx::ImageSkia& ShelfButton::GetImage() const {
296 return icon_view_->GetImage(); 286 return icon_view_->GetImage();
297 } 287 }
298 288
299 void ShelfButton::AddState(State state) { 289 void ShelfButton::AddState(State state) {
300 if (!(state_ & state)) { 290 if (!(state_ & state)) {
301 if (!ash::switches::UseAlternateShelfLayout() &&
302 (ShouldHop(state) || !ShouldHop(state_))) {
303 ui::ScopedLayerAnimationSettings scoped_setter(
304 icon_view_->layer()->GetAnimator());
305 scoped_setter.SetTransitionDuration(
306 base::TimeDelta::FromMilliseconds(kHopUpMS));
307 }
308 state_ |= state; 291 state_ |= state;
309 Layout(); 292 Layout();
310 if (state & STATE_ATTENTION) 293 if (state & STATE_ATTENTION)
311 bar_->ShowAttention(true); 294 bar_->ShowAttention(true);
312 } 295 }
313 } 296 }
314 297
315 void ShelfButton::ClearState(State state) { 298 void ShelfButton::ClearState(State state) {
316 if (state_ & state) { 299 if (state_ & state) {
317 if (!ash::switches::UseAlternateShelfLayout() &&
318 (!ShouldHop(state) || ShouldHop(state_))) {
319 ui::ScopedLayerAnimationSettings scoped_setter(
320 icon_view_->layer()->GetAnimator());
321 scoped_setter.SetTweenType(gfx::Tween::LINEAR);
322 scoped_setter.SetTransitionDuration(
323 base::TimeDelta::FromMilliseconds(kHopDownMS));
324 }
325 state_ &= ~state; 300 state_ &= ~state;
326 Layout(); 301 Layout();
327 if (state & STATE_ATTENTION) 302 if (state & STATE_ATTENTION)
328 bar_->ShowAttention(false); 303 bar_->ShowAttention(false);
329 } 304 }
330 } 305 }
331 306
332 gfx::Rect ShelfButton::GetIconBounds() const { 307 gfx::Rect ShelfButton::GetIconBounds() const {
333 return icon_view_->bounds(); 308 return icon_view_->bounds();
334 } 309 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 368 }
394 369
395 void ShelfButton::GetAccessibleState(ui::AXViewState* state) { 370 void ShelfButton::GetAccessibleState(ui::AXViewState* state) {
396 state->role = ui::AX_ROLE_BUTTON; 371 state->role = ui::AX_ROLE_BUTTON;
397 state->name = host_->GetAccessibleName(this); 372 state->name = host_->GetAccessibleName(this);
398 } 373 }
399 374
400 void ShelfButton::Layout() { 375 void ShelfButton::Layout() {
401 const gfx::Rect button_bounds(GetContentsBounds()); 376 const gfx::Rect button_bounds(GetContentsBounds());
402 int icon_pad = kIconPad; 377 int icon_pad = kIconPad;
403 if (ash::switches::UseAlternateShelfLayout()) { 378 icon_pad =
404 icon_pad = 379 shelf_layout_manager_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM ?
405 shelf_layout_manager_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM ? 380 kIconPadVertical : kIconPad;
406 kAlternateIconPadVertical : kAlternateIconPad;
407 }
408 int x_offset = shelf_layout_manager_->PrimaryAxisValue(0, icon_pad); 381 int x_offset = shelf_layout_manager_->PrimaryAxisValue(0, icon_pad);
409 int y_offset = shelf_layout_manager_->PrimaryAxisValue(icon_pad, 0); 382 int y_offset = shelf_layout_manager_->PrimaryAxisValue(icon_pad, 0);
410 383
411 int icon_width = std::min(kIconSize, 384 int icon_width = std::min(kIconSize,
412 button_bounds.width() - x_offset); 385 button_bounds.width() - x_offset);
413 int icon_height = std::min(kIconSize, 386 int icon_height = std::min(kIconSize,
414 button_bounds.height() - y_offset); 387 button_bounds.height() - y_offset);
415 388
416 // If on the left or top 'invert' the inset so the constant gap is on 389 // If on the left or top 'invert' the inset so the constant gap is on
417 // the interior (towards the center of display) edge of the shelf. 390 // the interior (towards the center of display) edge of the shelf.
418 if (SHELF_ALIGNMENT_LEFT == shelf_layout_manager_->GetAlignment()) 391 if (SHELF_ALIGNMENT_LEFT == shelf_layout_manager_->GetAlignment())
419 x_offset = button_bounds.width() - (kIconSize + icon_pad); 392 x_offset = button_bounds.width() - (kIconSize + icon_pad);
420 393
421 if (SHELF_ALIGNMENT_TOP == shelf_layout_manager_->GetAlignment()) 394 if (SHELF_ALIGNMENT_TOP == shelf_layout_manager_->GetAlignment())
422 y_offset = button_bounds.height() - (kIconSize + icon_pad); 395 y_offset = button_bounds.height() - (kIconSize + icon_pad);
423 396
424 if (ShouldHop(state_) && !ash::switches::UseAlternateShelfLayout()) {
425 x_offset += shelf_layout_manager_->SelectValueForShelfAlignment(
426 0, kHopSpacing, -kHopSpacing, 0);
427 y_offset += shelf_layout_manager_->SelectValueForShelfAlignment(
428 -kHopSpacing, 0, 0, kHopSpacing);
429 }
430
431 // Center icon with respect to the secondary axis, and ensure 397 // Center icon with respect to the secondary axis, and ensure
432 // that the icon doesn't occlude the bar highlight. 398 // that the icon doesn't occlude the bar highlight.
433 if (shelf_layout_manager_->IsHorizontalAlignment()) { 399 if (shelf_layout_manager_->IsHorizontalAlignment()) {
434 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; 400 x_offset = std::max(0, button_bounds.width() - icon_width) / 2;
435 if (y_offset + icon_height + kBarSize > button_bounds.height()) 401 if (y_offset + icon_height + kBarSize > button_bounds.height())
436 icon_height = button_bounds.height() - (y_offset + kBarSize); 402 icon_height = button_bounds.height() - (y_offset + kBarSize);
437 } else { 403 } else {
438 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; 404 y_offset = std::max(0, button_bounds.height() - icon_height) / 2;
439 if (x_offset + icon_width + kBarSize > button_bounds.width()) 405 if (x_offset + icon_width + kBarSize > button_bounds.width())
440 icon_width = button_bounds.width() - (x_offset + kBarSize); 406 icon_width = button_bounds.width() - (x_offset + kBarSize);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
538 SchedulePaint(); 504 SchedulePaint();
539 } 505 }
540 506
541 void ShelfButton::UpdateBar() { 507 void ShelfButton::UpdateBar() {
542 if (state_ & STATE_HIDDEN) { 508 if (state_ & STATE_HIDDEN) {
543 bar_->SetVisible(false); 509 bar_->SetVisible(false);
544 return; 510 return;
545 } 511 }
546 512
547 int bar_id = 0; 513 int bar_id = 0;
548 if (ash::switches::UseAlternateShelfLayout()) { 514 if (state_ & STATE_ACTIVE)
549 if (state_ & STATE_ACTIVE) 515 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_ACTIVE;
550 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_ACTIVE_ALTERNATE; 516 else if (state_ & STATE_RUNNING)
551 else if (state_ & STATE_RUNNING) 517 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_RUNNING;
552 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_RUNNING_ALTERNATE;
553 } else {
554 if (state_ & (STATE_ACTIVE | STATE_ATTENTION))
555 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_ACTIVE;
556 else if (state_ & (STATE_HOVERED | STATE_FOCUSED))
557 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_HOVER;
558 else
559 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_RUNNING;
560 }
561 518
562 if (bar_id != 0) { 519 if (bar_id != 0) {
563 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 520 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
564 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia(); 521 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia();
565 if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { 522 if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) {
566 bar_->SetImage(*image); 523 bar_->SetImage(*image);
567 } else { 524 } else {
568 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(*image, 525 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(*image,
569 shelf_layout_manager_->SelectValueForShelfAlignment( 526 shelf_layout_manager_->SelectValueForShelfAlignment(
570 SkBitmapOperations::ROTATION_90_CW, 527 SkBitmapOperations::ROTATION_90_CW,
(...skipping 14 matching lines...) Expand all
585 views::ImageView::CENTER, 542 views::ImageView::CENTER,
586 views::ImageView::LEADING)); 543 views::ImageView::LEADING));
587 bar_->SchedulePaint(); 544 bar_->SchedulePaint();
588 } 545 }
589 546
590 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); 547 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL);
591 } 548 }
592 549
593 } // namespace internal 550 } // namespace internal
594 } // namespace ash 551 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/overflow_button.cc ('k') | ash/shelf/shelf_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698