OLD | NEW |
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 Loading... |
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 kIconPad = 5; | 34 const int kHopSpacing = 2; |
35 const int kIconPadVertical = 6; | 35 const int kIconPad = 8; |
| 36 const int kAlternateIconPad = 5; |
| 37 const int kAlternateIconPadVertical = 6; |
| 38 const int kHopUpMS = 0; |
| 39 const int kHopDownMS = 200; |
36 const int kAttentionThrobDurationMS = 800; | 40 const int kAttentionThrobDurationMS = 800; |
37 | 41 |
| 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 |
38 // Simple AnimationDelegate that owns a single ThrobAnimation instance to | 48 // Simple AnimationDelegate that owns a single ThrobAnimation instance to |
39 // keep all Draw Attention animations in sync. | 49 // keep all Draw Attention animations in sync. |
40 class ShelfButtonAnimation : public gfx::AnimationDelegate { | 50 class ShelfButtonAnimation : public gfx::AnimationDelegate { |
41 public: | 51 public: |
42 class Observer { | 52 class Observer { |
43 public: | 53 public: |
44 virtual void AnimationProgressed() = 0; | 54 virtual void AnimationProgressed() = 0; |
45 | 55 |
46 protected: | 56 protected: |
47 virtual ~Observer() {} | 57 virtual ~Observer() {} |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 SetShadowedImage(gfx::ImageSkiaOperations::CreateResizedImage(image, | 291 SetShadowedImage(gfx::ImageSkiaOperations::CreateResizedImage(image, |
282 skia::ImageOperations::RESIZE_BEST, gfx::Size(width, height))); | 292 skia::ImageOperations::RESIZE_BEST, gfx::Size(width, height))); |
283 } | 293 } |
284 | 294 |
285 const gfx::ImageSkia& ShelfButton::GetImage() const { | 295 const gfx::ImageSkia& ShelfButton::GetImage() const { |
286 return icon_view_->GetImage(); | 296 return icon_view_->GetImage(); |
287 } | 297 } |
288 | 298 |
289 void ShelfButton::AddState(State state) { | 299 void ShelfButton::AddState(State state) { |
290 if (!(state_ & state)) { | 300 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 } |
291 state_ |= state; | 308 state_ |= state; |
292 Layout(); | 309 Layout(); |
293 if (state & STATE_ATTENTION) | 310 if (state & STATE_ATTENTION) |
294 bar_->ShowAttention(true); | 311 bar_->ShowAttention(true); |
295 } | 312 } |
296 } | 313 } |
297 | 314 |
298 void ShelfButton::ClearState(State state) { | 315 void ShelfButton::ClearState(State state) { |
299 if (state_ & state) { | 316 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 } |
300 state_ &= ~state; | 325 state_ &= ~state; |
301 Layout(); | 326 Layout(); |
302 if (state & STATE_ATTENTION) | 327 if (state & STATE_ATTENTION) |
303 bar_->ShowAttention(false); | 328 bar_->ShowAttention(false); |
304 } | 329 } |
305 } | 330 } |
306 | 331 |
307 gfx::Rect ShelfButton::GetIconBounds() const { | 332 gfx::Rect ShelfButton::GetIconBounds() const { |
308 return icon_view_->bounds(); | 333 return icon_view_->bounds(); |
309 } | 334 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 } | 393 } |
369 | 394 |
370 void ShelfButton::GetAccessibleState(ui::AXViewState* state) { | 395 void ShelfButton::GetAccessibleState(ui::AXViewState* state) { |
371 state->role = ui::AX_ROLE_BUTTON; | 396 state->role = ui::AX_ROLE_BUTTON; |
372 state->name = host_->GetAccessibleName(this); | 397 state->name = host_->GetAccessibleName(this); |
373 } | 398 } |
374 | 399 |
375 void ShelfButton::Layout() { | 400 void ShelfButton::Layout() { |
376 const gfx::Rect button_bounds(GetContentsBounds()); | 401 const gfx::Rect button_bounds(GetContentsBounds()); |
377 int icon_pad = kIconPad; | 402 int icon_pad = kIconPad; |
378 icon_pad = | 403 if (ash::switches::UseAlternateShelfLayout()) { |
379 shelf_layout_manager_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM ? | 404 icon_pad = |
380 kIconPadVertical : kIconPad; | 405 shelf_layout_manager_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM ? |
| 406 kAlternateIconPadVertical : kAlternateIconPad; |
| 407 } |
381 int x_offset = shelf_layout_manager_->PrimaryAxisValue(0, icon_pad); | 408 int x_offset = shelf_layout_manager_->PrimaryAxisValue(0, icon_pad); |
382 int y_offset = shelf_layout_manager_->PrimaryAxisValue(icon_pad, 0); | 409 int y_offset = shelf_layout_manager_->PrimaryAxisValue(icon_pad, 0); |
383 | 410 |
384 int icon_width = std::min(kIconSize, | 411 int icon_width = std::min(kIconSize, |
385 button_bounds.width() - x_offset); | 412 button_bounds.width() - x_offset); |
386 int icon_height = std::min(kIconSize, | 413 int icon_height = std::min(kIconSize, |
387 button_bounds.height() - y_offset); | 414 button_bounds.height() - y_offset); |
388 | 415 |
389 // If on the left or top 'invert' the inset so the constant gap is on | 416 // If on the left or top 'invert' the inset so the constant gap is on |
390 // the interior (towards the center of display) edge of the shelf. | 417 // the interior (towards the center of display) edge of the shelf. |
391 if (SHELF_ALIGNMENT_LEFT == shelf_layout_manager_->GetAlignment()) | 418 if (SHELF_ALIGNMENT_LEFT == shelf_layout_manager_->GetAlignment()) |
392 x_offset = button_bounds.width() - (kIconSize + icon_pad); | 419 x_offset = button_bounds.width() - (kIconSize + icon_pad); |
393 | 420 |
394 if (SHELF_ALIGNMENT_TOP == shelf_layout_manager_->GetAlignment()) | 421 if (SHELF_ALIGNMENT_TOP == shelf_layout_manager_->GetAlignment()) |
395 y_offset = button_bounds.height() - (kIconSize + icon_pad); | 422 y_offset = button_bounds.height() - (kIconSize + icon_pad); |
396 | 423 |
| 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 |
397 // Center icon with respect to the secondary axis, and ensure | 431 // Center icon with respect to the secondary axis, and ensure |
398 // that the icon doesn't occlude the bar highlight. | 432 // that the icon doesn't occlude the bar highlight. |
399 if (shelf_layout_manager_->IsHorizontalAlignment()) { | 433 if (shelf_layout_manager_->IsHorizontalAlignment()) { |
400 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; | 434 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; |
401 if (y_offset + icon_height + kBarSize > button_bounds.height()) | 435 if (y_offset + icon_height + kBarSize > button_bounds.height()) |
402 icon_height = button_bounds.height() - (y_offset + kBarSize); | 436 icon_height = button_bounds.height() - (y_offset + kBarSize); |
403 } else { | 437 } else { |
404 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; | 438 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; |
405 if (x_offset + icon_width + kBarSize > button_bounds.width()) | 439 if (x_offset + icon_width + kBarSize > button_bounds.width()) |
406 icon_width = button_bounds.width() - (x_offset + kBarSize); | 440 icon_width = button_bounds.width() - (x_offset + kBarSize); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 SchedulePaint(); | 538 SchedulePaint(); |
505 } | 539 } |
506 | 540 |
507 void ShelfButton::UpdateBar() { | 541 void ShelfButton::UpdateBar() { |
508 if (state_ & STATE_HIDDEN) { | 542 if (state_ & STATE_HIDDEN) { |
509 bar_->SetVisible(false); | 543 bar_->SetVisible(false); |
510 return; | 544 return; |
511 } | 545 } |
512 | 546 |
513 int bar_id = 0; | 547 int bar_id = 0; |
514 if (state_ & STATE_ACTIVE) | 548 if (ash::switches::UseAlternateShelfLayout()) { |
515 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_ACTIVE; | 549 if (state_ & STATE_ACTIVE) |
516 else if (state_ & STATE_RUNNING) | 550 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_ACTIVE_ALTERNATE; |
517 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_RUNNING; | 551 else if (state_ & STATE_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 } |
518 | 561 |
519 if (bar_id != 0) { | 562 if (bar_id != 0) { |
520 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 563 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
521 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia(); | 564 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia(); |
522 if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 565 if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
523 bar_->SetImage(*image); | 566 bar_->SetImage(*image); |
524 } else { | 567 } else { |
525 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(*image, | 568 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(*image, |
526 shelf_layout_manager_->SelectValueForShelfAlignment( | 569 shelf_layout_manager_->SelectValueForShelfAlignment( |
527 SkBitmapOperations::ROTATION_90_CW, | 570 SkBitmapOperations::ROTATION_90_CW, |
(...skipping 14 matching lines...) Expand all Loading... |
542 views::ImageView::CENTER, | 585 views::ImageView::CENTER, |
543 views::ImageView::LEADING)); | 586 views::ImageView::LEADING)); |
544 bar_->SchedulePaint(); | 587 bar_->SchedulePaint(); |
545 } | 588 } |
546 | 589 |
547 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); | 590 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); |
548 } | 591 } |
549 | 592 |
550 } // namespace internal | 593 } // namespace internal |
551 } // namespace ash | 594 } // namespace ash |
OLD | NEW |