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 14 matching lines...) Expand all Loading... |
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 kHopSpacing = 2; |
35 const int kIconPad = 5; | 35 const int kIconPad = 8; |
36 const int kIconPadVertical = 6; | 36 const int kAlternateIconPad = 5; |
| 37 const int kAlternateIconPadVertical = 6; |
37 const int kHopUpMS = 0; | 38 const int kHopUpMS = 0; |
38 const int kHopDownMS = 200; | 39 const int kHopDownMS = 200; |
39 const int kAttentionThrobDurationMS = 800; | 40 const int kAttentionThrobDurationMS = 800; |
40 | 41 |
41 bool ShouldHop(int state) { | 42 bool ShouldHop(int state) { |
42 return state & ash::internal::ShelfButton::STATE_HOVERED || | 43 return state & ash::internal::ShelfButton::STATE_HOVERED || |
43 state & ash::internal::ShelfButton::STATE_ACTIVE || | 44 state & ash::internal::ShelfButton::STATE_ACTIVE || |
44 state & ash::internal::ShelfButton::STATE_FOCUSED; | 45 state & ash::internal::ShelfButton::STATE_FOCUSED; |
45 } | 46 } |
46 | 47 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 SetShadowedImage(gfx::ImageSkiaOperations::CreateResizedImage(image, | 291 SetShadowedImage(gfx::ImageSkiaOperations::CreateResizedImage(image, |
291 skia::ImageOperations::RESIZE_BEST, gfx::Size(width, height))); | 292 skia::ImageOperations::RESIZE_BEST, gfx::Size(width, height))); |
292 } | 293 } |
293 | 294 |
294 const gfx::ImageSkia& ShelfButton::GetImage() const { | 295 const gfx::ImageSkia& ShelfButton::GetImage() const { |
295 return icon_view_->GetImage(); | 296 return icon_view_->GetImage(); |
296 } | 297 } |
297 | 298 |
298 void ShelfButton::AddState(State state) { | 299 void ShelfButton::AddState(State state) { |
299 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 } |
300 state_ |= state; | 308 state_ |= state; |
301 Layout(); | 309 Layout(); |
302 if (state & STATE_ATTENTION) | 310 if (state & STATE_ATTENTION) |
303 bar_->ShowAttention(true); | 311 bar_->ShowAttention(true); |
304 } | 312 } |
305 } | 313 } |
306 | 314 |
307 void ShelfButton::ClearState(State state) { | 315 void ShelfButton::ClearState(State state) { |
308 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 } |
309 state_ &= ~state; | 325 state_ &= ~state; |
310 Layout(); | 326 Layout(); |
311 if (state & STATE_ATTENTION) | 327 if (state & STATE_ATTENTION) |
312 bar_->ShowAttention(false); | 328 bar_->ShowAttention(false); |
313 } | 329 } |
314 } | 330 } |
315 | 331 |
316 gfx::Rect ShelfButton::GetIconBounds() const { | 332 gfx::Rect ShelfButton::GetIconBounds() const { |
317 return icon_view_->bounds(); | 333 return icon_view_->bounds(); |
318 } | 334 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 } | 393 } |
378 | 394 |
379 void ShelfButton::GetAccessibleState(ui::AXViewState* state) { | 395 void ShelfButton::GetAccessibleState(ui::AXViewState* state) { |
380 state->role = ui::AX_ROLE_BUTTON; | 396 state->role = ui::AX_ROLE_BUTTON; |
381 state->name = host_->GetAccessibleName(this); | 397 state->name = host_->GetAccessibleName(this); |
382 } | 398 } |
383 | 399 |
384 void ShelfButton::Layout() { | 400 void ShelfButton::Layout() { |
385 const gfx::Rect button_bounds(GetContentsBounds()); | 401 const gfx::Rect button_bounds(GetContentsBounds()); |
386 int icon_pad = kIconPad; | 402 int icon_pad = kIconPad; |
387 icon_pad = | 403 if (ash::switches::UseAlternateShelfLayout()) { |
388 shelf_layout_manager_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM ? | 404 icon_pad = |
389 kIconPadVertical : kIconPad; | 405 shelf_layout_manager_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM ? |
| 406 kAlternateIconPadVertical : kAlternateIconPad; |
| 407 } |
390 int x_offset = shelf_layout_manager_->PrimaryAxisValue(0, icon_pad); | 408 int x_offset = shelf_layout_manager_->PrimaryAxisValue(0, icon_pad); |
391 int y_offset = shelf_layout_manager_->PrimaryAxisValue(icon_pad, 0); | 409 int y_offset = shelf_layout_manager_->PrimaryAxisValue(icon_pad, 0); |
392 | 410 |
393 int icon_width = std::min(kIconSize, | 411 int icon_width = std::min(kIconSize, |
394 button_bounds.width() - x_offset); | 412 button_bounds.width() - x_offset); |
395 int icon_height = std::min(kIconSize, | 413 int icon_height = std::min(kIconSize, |
396 button_bounds.height() - y_offset); | 414 button_bounds.height() - y_offset); |
397 | 415 |
398 // 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 |
399 // the interior (towards the center of display) edge of the shelf. | 417 // the interior (towards the center of display) edge of the shelf. |
400 if (SHELF_ALIGNMENT_LEFT == shelf_layout_manager_->GetAlignment()) | 418 if (SHELF_ALIGNMENT_LEFT == shelf_layout_manager_->GetAlignment()) |
401 x_offset = button_bounds.width() - (kIconSize + icon_pad); | 419 x_offset = button_bounds.width() - (kIconSize + icon_pad); |
402 | 420 |
403 if (SHELF_ALIGNMENT_TOP == shelf_layout_manager_->GetAlignment()) | 421 if (SHELF_ALIGNMENT_TOP == shelf_layout_manager_->GetAlignment()) |
404 y_offset = button_bounds.height() - (kIconSize + icon_pad); | 422 y_offset = button_bounds.height() - (kIconSize + icon_pad); |
405 | 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 |
406 // Center icon with respect to the secondary axis, and ensure | 431 // Center icon with respect to the secondary axis, and ensure |
407 // that the icon doesn't occlude the bar highlight. | 432 // that the icon doesn't occlude the bar highlight. |
408 if (shelf_layout_manager_->IsHorizontalAlignment()) { | 433 if (shelf_layout_manager_->IsHorizontalAlignment()) { |
409 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; | 434 x_offset = std::max(0, button_bounds.width() - icon_width) / 2; |
410 if (y_offset + icon_height + kBarSize > button_bounds.height()) | 435 if (y_offset + icon_height + kBarSize > button_bounds.height()) |
411 icon_height = button_bounds.height() - (y_offset + kBarSize); | 436 icon_height = button_bounds.height() - (y_offset + kBarSize); |
412 } else { | 437 } else { |
413 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; | 438 y_offset = std::max(0, button_bounds.height() - icon_height) / 2; |
414 if (x_offset + icon_width + kBarSize > button_bounds.width()) | 439 if (x_offset + icon_width + kBarSize > button_bounds.width()) |
415 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... |
513 SchedulePaint(); | 538 SchedulePaint(); |
514 } | 539 } |
515 | 540 |
516 void ShelfButton::UpdateBar() { | 541 void ShelfButton::UpdateBar() { |
517 if (state_ & STATE_HIDDEN) { | 542 if (state_ & STATE_HIDDEN) { |
518 bar_->SetVisible(false); | 543 bar_->SetVisible(false); |
519 return; | 544 return; |
520 } | 545 } |
521 | 546 |
522 int bar_id = 0; | 547 int bar_id = 0; |
523 if (state_ & STATE_ACTIVE) | 548 if (ash::switches::UseAlternateShelfLayout()) { |
524 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_ACTIVE; | 549 if (state_ & STATE_ACTIVE) |
525 else if (state_ & STATE_RUNNING) | 550 bar_id = IDR_AURA_LAUNCHER_UNDERLINE_ACTIVE_ALTERNATE; |
526 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 } |
527 | 561 |
528 if (bar_id != 0) { | 562 if (bar_id != 0) { |
529 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 563 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
530 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia(); | 564 const gfx::ImageSkia* image = rb.GetImageNamed(bar_id).ToImageSkia(); |
531 if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 565 if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
532 bar_->SetImage(*image); | 566 bar_->SetImage(*image); |
533 } else { | 567 } else { |
534 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(*image, | 568 bar_->SetImage(gfx::ImageSkiaOperations::CreateRotatedImage(*image, |
535 shelf_layout_manager_->SelectValueForShelfAlignment( | 569 shelf_layout_manager_->SelectValueForShelfAlignment( |
536 SkBitmapOperations::ROTATION_90_CW, | 570 SkBitmapOperations::ROTATION_90_CW, |
(...skipping 14 matching lines...) Expand all Loading... |
551 views::ImageView::CENTER, | 585 views::ImageView::CENTER, |
552 views::ImageView::LEADING)); | 586 views::ImageView::LEADING)); |
553 bar_->SchedulePaint(); | 587 bar_->SchedulePaint(); |
554 } | 588 } |
555 | 589 |
556 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); | 590 bar_->SetVisible(bar_id != 0 && state_ != STATE_NORMAL); |
557 } | 591 } |
558 | 592 |
559 } // namespace internal | 593 } // namespace internal |
560 } // namespace ash | 594 } // namespace ash |
OLD | NEW |