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