OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/system/tray/tray_views.h" | 5 #include "ash/system/tray/tray_views.h" |
6 | 6 |
7 #include "ash/ash_constants.h" | 7 #include "ash/ash_constants.h" |
8 #include "ash/system/tray/tray_constants.h" | 8 #include "ash/system/tray/tray_constants.h" |
9 #include "ash/system/tray/tray_item_view.h" | 9 #include "ash/system/tray/tray_item_view.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "grit/ash_resources.h" | 11 #include "grit/ash_resources.h" |
12 #include "grit/ash_strings.h" | 12 #include "grit/ash_strings.h" |
13 #include "grit/ui_resources.h" | 13 #include "grit/ui_resources.h" |
14 #include "ui/base/accessibility/accessible_view_state.h" | 14 #include "ui/base/accessibility/accessible_view_state.h" |
15 #include "ui/base/events/event.h" | 15 #include "ui/base/events/event.h" |
16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/compositor/layer.h" |
| 18 #include "ui/compositor/scoped_layer_animation_settings.h" |
17 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
18 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
19 #include "ui/gfx/image/image_skia.h" | 21 #include "ui/gfx/image/image_skia.h" |
20 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
21 #include "ui/gfx/text_constants.h" | 23 #include "ui/gfx/text_constants.h" |
22 #include "ui/gfx/vector2d.h" | 24 #include "ui/gfx/vector2d.h" |
23 #include "ui/native_theme/native_theme.h" | 25 #include "ui/native_theme/native_theme.h" |
24 #include "ui/views/border.h" | 26 #include "ui/views/border.h" |
25 #include "ui/views/controls/button/image_button.h" | 27 #include "ui/views/controls/button/image_button.h" |
26 #include "ui/views/controls/label.h" | 28 #include "ui/views/controls/label.h" |
| 29 #include "ui/views/controls/throbber.h" |
27 #include "ui/views/layout/box_layout.h" | 30 #include "ui/views/layout/box_layout.h" |
28 #include "ui/views/layout/fill_layout.h" | 31 #include "ui/views/layout/fill_layout.h" |
29 #include "ui/views/layout/grid_layout.h" | 32 #include "ui/views/layout/grid_layout.h" |
30 #include "ui/views/painter.h" | 33 #include "ui/views/painter.h" |
31 | 34 |
32 namespace ash { | 35 namespace ash { |
33 namespace internal { | 36 namespace internal { |
34 | 37 |
35 namespace { | 38 namespace { |
36 const int kIconPaddingLeft = 5; | 39 const int kIconPaddingLeft = 5; |
37 const int kPopupDetailLabelExtraLeftMargin = 8; | 40 const int kPopupDetailLabelExtraLeftMargin = 8; |
38 const int kCheckLabelPadding = 4; | 41 const int kCheckLabelPadding = 4; |
39 const int kSpecialPopupRowHeight = 55; | 42 const int kSpecialPopupRowHeight = 55; |
40 const int kTrayPopupLabelButtonPaddingHorizontal = 16; | 43 const int kTrayPopupLabelButtonPaddingHorizontal = 16; |
41 const int kTrayPopupLabelButtonPaddingVertical = 8; | 44 const int kTrayPopupLabelButtonPaddingVertical = 8; |
42 | 45 |
| 46 // Time in ms per throbber frame. |
| 47 const int kThrobberFrameMs = 50; |
| 48 |
| 49 // Duration for showing/hiding animation in milliseconds. |
| 50 const int kThrobberAnimationDurationMs = 200; |
| 51 |
43 const int kBarImagesActive[] = { | 52 const int kBarImagesActive[] = { |
44 IDR_SLIDER_ACTIVE_LEFT, | 53 IDR_SLIDER_ACTIVE_LEFT, |
45 IDR_SLIDER_ACTIVE_CENTER, | 54 IDR_SLIDER_ACTIVE_CENTER, |
46 IDR_SLIDER_ACTIVE_RIGHT, | 55 IDR_SLIDER_ACTIVE_RIGHT, |
47 }; | 56 }; |
48 | 57 |
49 const int kBarImagesDisabled[] = { | 58 const int kBarImagesDisabled[] = { |
50 IDR_SLIDER_DISABLED_LEFT, | 59 IDR_SLIDER_DISABLED_LEFT, |
51 IDR_SLIDER_DISABLED_CENTER, | 60 IDR_SLIDER_DISABLED_CENTER, |
52 IDR_SLIDER_DISABLED_RIGHT, | 61 IDR_SLIDER_DISABLED_RIGHT, |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 bar_image_y + image_height_ - 3, | 613 bar_image_y + image_height_ - 3, |
605 rect.width(), | 614 rect.width(), |
606 title_size.height()); | 615 title_size.height()); |
607 } | 616 } |
608 } | 617 } |
609 | 618 |
610 void TrayBarButtonWithTitle::UpdateButton(bool control_on) { | 619 void TrayBarButtonWithTitle::UpdateButton(bool control_on) { |
611 image_->Update(control_on); | 620 image_->Update(control_on); |
612 } | 621 } |
613 | 622 |
| 623 ThrobberView::ThrobberView() { |
| 624 throbber_ = new views::SmoothedThrobber(kThrobberFrameMs); |
| 625 throbber_->set_stop_delay_ms(kThrobberAnimationDurationMs); |
| 626 throbber_->set_interactive(false); |
| 627 AddChildView(throbber_); |
| 628 |
| 629 SetPaintToLayer(true); |
| 630 layer()->SetFillsBoundsOpaquely(false); |
| 631 layer()->SetOpacity(0.0); |
| 632 } |
| 633 |
| 634 ThrobberView::~ThrobberView() { |
| 635 } |
| 636 |
| 637 gfx::Size ThrobberView::GetPreferredSize() { |
| 638 return gfx::Size(ash::kTrayPopupItemHeight, ash::kTrayPopupItemHeight); |
| 639 } |
| 640 |
| 641 void ThrobberView::Layout() { |
| 642 View* child = child_at(0); |
| 643 gfx::Size ps = child->GetPreferredSize(); |
| 644 child->SetBounds((width() - ps.width()) / 2, |
| 645 (height() - ps.height()) / 2, |
| 646 ps.width(), ps.height()); |
| 647 SizeToPreferredSize(); |
| 648 } |
| 649 |
| 650 bool ThrobberView::GetTooltipText(const gfx::Point& p, |
| 651 string16* tooltip) const { |
| 652 if (tooltip_text_.empty()) |
| 653 return false; |
| 654 |
| 655 *tooltip = tooltip_text_; |
| 656 return true; |
| 657 } |
| 658 |
| 659 void ThrobberView::Start() { |
| 660 ScheduleAnimation(true); |
| 661 throbber_->Start(); |
| 662 } |
| 663 |
| 664 void ThrobberView::Stop() { |
| 665 ScheduleAnimation(false); |
| 666 throbber_->Stop(); |
| 667 } |
| 668 |
| 669 void ThrobberView::SetTooltipText(const string16& tooltip_text) { |
| 670 tooltip_text_ = tooltip_text; |
| 671 } |
| 672 |
| 673 void ThrobberView::ScheduleAnimation(bool start_throbber) { |
| 674 // Stop any previous animation. |
| 675 layer()->GetAnimator()->StopAnimating(); |
| 676 |
| 677 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); |
| 678 animation.SetTransitionDuration( |
| 679 base::TimeDelta::FromMilliseconds(kThrobberAnimationDurationMs)); |
| 680 |
| 681 layer()->SetOpacity(start_throbber ? 1.0 : 0.0); |
| 682 } |
| 683 |
614 //////////////////////////////////////////////////////////////////////////////// | 684 //////////////////////////////////////////////////////////////////////////////// |
615 // SpecialPopupRow | 685 // SpecialPopupRow |
616 | 686 |
617 SpecialPopupRow::SpecialPopupRow() | 687 SpecialPopupRow::SpecialPopupRow() |
618 : content_(NULL), | 688 : content_(NULL), |
619 button_container_(NULL) { | 689 button_container_(NULL) { |
620 views::Background* background = views::Background::CreateBackgroundPainter( | 690 views::Background* background = views::Background::CreateBackgroundPainter( |
621 true, views::Painter::CreateVerticalGradient(kHeaderBackgroundColorLight, | 691 true, views::Painter::CreateVerticalGradient(kHeaderBackgroundColorLight, |
622 kHeaderBackgroundColorDark)); | 692 kHeaderBackgroundColorDark)); |
623 background->SetNativeControlColor(kHeaderBackgroundColorDark); | 693 background->SetNativeControlColor(kHeaderBackgroundColorDark); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 | 732 |
663 void SpecialPopupRow::AddButton(TrayPopupHeaderButton* button) { | 733 void SpecialPopupRow::AddButton(TrayPopupHeaderButton* button) { |
664 if (!button_container_) { | 734 if (!button_container_) { |
665 button_container_ = CreatePopupHeaderButtonsContainer(); | 735 button_container_ = CreatePopupHeaderButtonsContainer(); |
666 AddChildView(button_container_); | 736 AddChildView(button_container_); |
667 } | 737 } |
668 | 738 |
669 button_container_->AddChildView(button); | 739 button_container_->AddChildView(button); |
670 } | 740 } |
671 | 741 |
| 742 void SpecialPopupRow::AddThrobber(ThrobberView* throbber) { |
| 743 if (!button_container_) { |
| 744 button_container_ = CreatePopupHeaderButtonsContainer(); |
| 745 AddChildView(button_container_); |
| 746 } |
| 747 |
| 748 button_container_->AddChildView(throbber); |
| 749 } |
| 750 |
672 gfx::Size SpecialPopupRow::GetPreferredSize() { | 751 gfx::Size SpecialPopupRow::GetPreferredSize() { |
673 gfx::Size size = views::View::GetPreferredSize(); | 752 gfx::Size size = views::View::GetPreferredSize(); |
674 size.set_height(kSpecialPopupRowHeight); | 753 size.set_height(kSpecialPopupRowHeight); |
675 return size; | 754 return size; |
676 } | 755 } |
677 | 756 |
678 void SpecialPopupRow::Layout() { | 757 void SpecialPopupRow::Layout() { |
679 views::View::Layout(); | 758 views::View::Layout(); |
680 gfx::Rect content_bounds = GetContentsBounds(); | 759 gfx::Rect content_bounds = GetContentsBounds(); |
681 if (content_bounds.IsEmpty()) | 760 if (content_bounds.IsEmpty()) |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 tray_view->set_border(views::Border::CreateEmptyBorder( | 819 tray_view->set_border(views::Border::CreateEmptyBorder( |
741 kTrayLabelItemVerticalPaddingVeriticalAlignment, | 820 kTrayLabelItemVerticalPaddingVeriticalAlignment, |
742 horizontal_padding, | 821 horizontal_padding, |
743 kTrayLabelItemVerticalPaddingVeriticalAlignment, | 822 kTrayLabelItemVerticalPaddingVeriticalAlignment, |
744 horizontal_padding)); | 823 horizontal_padding)); |
745 } | 824 } |
746 } | 825 } |
747 | 826 |
748 } // namespace internal | 827 } // namespace internal |
749 } // namespace ash | 828 } // namespace ash |
OLD | NEW |