| 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 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::ShelfButton::STATE_HOVERED || | |
| 44 state & ash::ShelfButton::STATE_ACTIVE || | |
| 45 state & ash::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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 SetShadowedImage(gfx::ImageSkiaOperations::CreateResizedImage(image, | 280 SetShadowedImage(gfx::ImageSkiaOperations::CreateResizedImage(image, |
| 291 skia::ImageOperations::RESIZE_BEST, gfx::Size(width, height))); | 281 skia::ImageOperations::RESIZE_BEST, gfx::Size(width, height))); |
| 292 } | 282 } |
| 293 | 283 |
| 294 const gfx::ImageSkia& ShelfButton::GetImage() const { | 284 const gfx::ImageSkia& ShelfButton::GetImage() const { |
| 295 return icon_view_->GetImage(); | 285 return icon_view_->GetImage(); |
| 296 } | 286 } |
| 297 | 287 |
| 298 void ShelfButton::AddState(State state) { | 288 void ShelfButton::AddState(State state) { |
| 299 if (!(state_ & state)) { | 289 if (!(state_ & state)) { |
| 300 if (!ash::switches::UseAlternateShelfLayout() && | |
| 301 (ShouldHop(state) || !ShouldHop(state_))) { | |
| 302 ui::ScopedLayerAnimationSettings scoped_setter( | |
| 303 icon_view_->layer()->GetAnimator()); | |
| 304 scoped_setter.SetTransitionDuration( | |
| 305 base::TimeDelta::FromMilliseconds(kHopUpMS)); | |
| 306 } | |
| 307 state_ |= state; | 290 state_ |= state; |
| 308 Layout(); | 291 Layout(); |
| 309 if (state & STATE_ATTENTION) | 292 if (state & STATE_ATTENTION) |
| 310 bar_->ShowAttention(true); | 293 bar_->ShowAttention(true); |
| 311 } | 294 } |
| 312 } | 295 } |
| 313 | 296 |
| 314 void ShelfButton::ClearState(State state) { | 297 void ShelfButton::ClearState(State state) { |
| 315 if (state_ & state) { | 298 if (state_ & state) { |
| 316 if (!ash::switches::UseAlternateShelfLayout() && | |
| 317 (!ShouldHop(state) || ShouldHop(state_))) { | |
| 318 ui::ScopedLayerAnimationSettings scoped_setter( | |
| 319 icon_view_->layer()->GetAnimator()); | |
| 320 scoped_setter.SetTweenType(gfx::Tween::LINEAR); | |
| 321 scoped_setter.SetTransitionDuration( | |
| 322 base::TimeDelta::FromMilliseconds(kHopDownMS)); | |
| 323 } | |
| 324 state_ &= ~state; | 299 state_ &= ~state; |
| 325 Layout(); | 300 Layout(); |
| 326 if (state & STATE_ATTENTION) | 301 if (state & STATE_ATTENTION) |
| 327 bar_->ShowAttention(false); | 302 bar_->ShowAttention(false); |
| 328 } | 303 } |
| 329 } | 304 } |
| 330 | 305 |
| 331 gfx::Rect ShelfButton::GetIconBounds() const { | 306 gfx::Rect ShelfButton::GetIconBounds() const { |
| 332 return icon_view_->bounds(); | 307 return icon_view_->bounds(); |
| 333 } | 308 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 host_->MouseExitedButton(this); | 366 host_->MouseExitedButton(this); |
| 392 } | 367 } |
| 393 | 368 |
| 394 void ShelfButton::GetAccessibleState(ui::AXViewState* state) { | 369 void ShelfButton::GetAccessibleState(ui::AXViewState* state) { |
| 395 state->role = ui::AX_ROLE_BUTTON; | 370 state->role = ui::AX_ROLE_BUTTON; |
| 396 state->name = host_->GetAccessibleName(this); | 371 state->name = host_->GetAccessibleName(this); |
| 397 } | 372 } |
| 398 | 373 |
| 399 void ShelfButton::Layout() { | 374 void ShelfButton::Layout() { |
| 400 const gfx::Rect button_bounds(GetContentsBounds()); | 375 const gfx::Rect button_bounds(GetContentsBounds()); |
| 401 int icon_pad = kIconPad; | 376 int icon_pad = |
| 402 if (ash::switches::UseAlternateShelfLayout()) { | 377 shelf_layout_manager_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM ? |
| 403 icon_pad = | 378 kIconPadVertical : kIconPad; |
| 404 shelf_layout_manager_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM ? | |
| 405 kAlternateIconPadVertical : kAlternateIconPad; | |
| 406 } | |
| 407 int x_offset = shelf_layout_manager_->PrimaryAxisValue(0, icon_pad); | 379 int x_offset = shelf_layout_manager_->PrimaryAxisValue(0, icon_pad); |
| 408 int y_offset = shelf_layout_manager_->PrimaryAxisValue(icon_pad, 0); | 380 int y_offset = shelf_layout_manager_->PrimaryAxisValue(icon_pad, 0); |
| 409 | 381 |
| 410 int icon_width = std::min(kIconSize, | 382 int icon_width = std::min(kIconSize, |
| 411 button_bounds.width() - x_offset); | 383 button_bounds.width() - x_offset); |
| 412 int icon_height = std::min(kIconSize, | 384 int icon_height = std::min(kIconSize, |
| 413 button_bounds.height() - y_offset); | 385 button_bounds.height() - y_offset); |
| 414 | 386 |
| 415 // If on the left or top 'invert' the inset so the constant gap is on | 387 // If on the left or top 'invert' the inset so the constant gap is on |
| 416 // the interior (towards the center of display) edge of the shelf. | 388 // the interior (towards the center of display) edge of the shelf. |
| 417 if (SHELF_ALIGNMENT_LEFT == shelf_layout_manager_->GetAlignment()) | 389 if (SHELF_ALIGNMENT_LEFT == shelf_layout_manager_->GetAlignment()) |
| 418 x_offset = button_bounds.width() - (kIconSize + icon_pad); | 390 x_offset = button_bounds.width() - (kIconSize + icon_pad); |
| 419 | 391 |
| 420 if (SHELF_ALIGNMENT_TOP == shelf_layout_manager_->GetAlignment()) | 392 if (SHELF_ALIGNMENT_TOP == shelf_layout_manager_->GetAlignment()) |
| 421 y_offset = button_bounds.height() - (kIconSize + icon_pad); | 393 y_offset = button_bounds.height() - (kIconSize + icon_pad); |
| 422 | 394 |
| 423 if (ShouldHop(state_) && !ash::switches::UseAlternateShelfLayout()) { | |
| 424 x_offset += shelf_layout_manager_->SelectValueForShelfAlignment( | |
| 425 0, kHopSpacing, -kHopSpacing, 0); | |
| 426 y_offset += shelf_layout_manager_->SelectValueForShelfAlignment( | |
| 427 -kHopSpacing, 0, 0, kHopSpacing); | |
| 428 } | |
| 429 | |
| 430 // Center icon with respect to the secondary axis, and ensure | 395 // Center icon with respect to the secondary axis, and ensure |
| 431 // that the icon doesn't occlude the bar highlight. | 396 // that the icon doesn't occlude the bar highlight. |
| 432 if (shelf_layout_manager_->IsHorizontalAlignment()) { | 397 if (shelf_layout_manager_->IsHorizontalAlignment()) { |
| 433 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; | 398 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; |
| 434 if (y_offset + icon_height + kBarSize > button_bounds.height()) | 399 if (y_offset + icon_height + kBarSize > button_bounds.height()) |
| 435 icon_height = button_bounds.height() - (y_offset + kBarSize); | 400 icon_height = button_bounds.height() - (y_offset + kBarSize); |
| 436 } else { | 401 } else { |
| 437 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; | 402 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; |
| 438 if (x_offset + icon_width + kBarSize > button_bounds.width()) | 403 if (x_offset + icon_width + kBarSize > button_bounds.width()) |
| 439 icon_width = button_bounds.width() - (x_offset + kBarSize); | 404 icon_width = button_bounds.width() - (x_offset + kBarSize); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 SchedulePaint(); | 502 SchedulePaint(); |
| 538 } | 503 } |
| 539 | 504 |
| 540 void ShelfButton::UpdateBar() { | 505 void ShelfButton::UpdateBar() { |
| 541 if (state_ & STATE_HIDDEN) { | 506 if (state_ & STATE_HIDDEN) { |
| 542 bar_->SetVisible(false); | 507 bar_->SetVisible(false); |
| 543 return; | 508 return; |
| 544 } | 509 } |
| 545 | 510 |
| 546 int bar_id = 0; | 511 int bar_id = 0; |
| 547 if (ash::switches::UseAlternateShelfLayout()) { | 512 if (state_ & STATE_ACTIVE) |
| 548 if (state_ & STATE_ACTIVE) | 513 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE; |
| 549 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE_ALTERNATE; | 514 else if (state_ & STATE_RUNNING) |
| 550 else if (state_ & STATE_RUNNING) | 515 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING; |
| 551 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING_ALTERNATE; | |
| 552 } else { | |
| 553 if (state_ & (STATE_ACTIVE | STATE_ATTENTION)) | |
| 554 bar_id = IDR_ASH_SHELF_UNDERLINE_ACTIVE; | |
| 555 else if (state_ & (STATE_HOVERED | STATE_FOCUSED)) | |
| 556 bar_id = IDR_ASH_SHELF_UNDERLINE_HOVER; | |
| 557 else | |
| 558 bar_id = IDR_ASH_SHELF_UNDERLINE_RUNNING; | |
| 559 } | |
| 560 | 516 |
| 561 if (bar_id != 0) { | 517 if (bar_id != 0) { |
| 562 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 518 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 563 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia(); | 519 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia(); |
| 564 if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 520 if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
| 565 bar_->SetImage(*image); | 521 bar_->SetImage(*image); |
| 566 } else { | 522 } else { |
| 567 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(*image, | 523 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(*image, |
| 568 shelf_layout_manager_->SelectValueForShelfAlignment( | 524 shelf_layout_manager_->SelectValueForShelfAlignment( |
| 569 SkBitmapOperations::ROTATION_90_CW, | 525 SkBitmapOperations::ROTATION_90_CW, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 583 views::ImageView::CENTER, | 539 views::ImageView::CENTER, |
| 584 views::ImageView::CENTER, | 540 views::ImageView::CENTER, |
| 585 views::ImageView::LEADING)); | 541 views::ImageView::LEADING)); |
| 586 bar_->SchedulePaint(); | 542 bar_->SchedulePaint(); |
| 587 } | 543 } |
| 588 | 544 |
| 589 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); | 545 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); |
| 590 } | 546 } |
| 591 | 547 |
| 592 } // namespace ash | 548 } // namespace ash |
| OLD | NEW |