Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(556)

Side by Side Diff: ash/system/tray/tray_views.cc

Issue 12263021: Refactor SpecialPopupRow out of tray_views.h/cc into its own files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix nits. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/system/tray/tray_views.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 17 matching lines...) Expand all
28 #include "ui/views/controls/label.h" 28 #include "ui/views/controls/label.h"
29 #include "ui/views/layout/box_layout.h" 29 #include "ui/views/layout/box_layout.h"
30 #include "ui/views/layout/fill_layout.h" 30 #include "ui/views/layout/fill_layout.h"
31 #include "ui/views/layout/grid_layout.h" 31 #include "ui/views/layout/grid_layout.h"
32 #include "ui/views/painter.h" 32 #include "ui/views/painter.h"
33 33
34 namespace ash { 34 namespace ash {
35 namespace internal { 35 namespace internal {
36 36
37 namespace { 37 namespace {
38 const int kIconPaddingLeft = 5;
39 const int kPopupDetailLabelExtraLeftMargin = 8; 38 const int kPopupDetailLabelExtraLeftMargin = 8;
40 const int kCheckLabelPadding = 4; 39 const int kCheckLabelPadding = 4;
41 const int kSpecialPopupRowHeight = 55;
42 const int kTrayPopupLabelButtonPaddingHorizontal = 16; 40 const int kTrayPopupLabelButtonPaddingHorizontal = 16;
43 const int kTrayPopupLabelButtonPaddingVertical = 8; 41 const int kTrayPopupLabelButtonPaddingVertical = 8;
44 42
45 // Time in ms per throbber frame. 43 // Time in ms per throbber frame.
46 const int kThrobberFrameMs = 50; 44 const int kThrobberFrameMs = 50;
47 45
48 // Duration for showing/hiding animation in milliseconds. 46 // Duration for showing/hiding animation in milliseconds.
49 const int kThrobberAnimationDurationMs = 200; 47 const int kThrobberAnimationDurationMs = 200;
50 48
51 const int kBarImagesActive[] = { 49 const int kBarImagesActive[] = {
(...skipping 24 matching lines...) Expand all
76 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, 74 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
77 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, 75 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
78 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, 76 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
79 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_HOVER_BACKGROUND, 77 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_HOVER_BACKGROUND,
80 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, 78 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
81 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, 79 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
82 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, 80 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
83 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER, 81 IDR_AURA_TRAY_POPUP_LABEL_BUTTON_BORDER,
84 }; 82 };
85 83
86 views::View* CreatePopupHeaderButtonsContainer() {
87 views::View* view = new views::View;
88 view->SetLayoutManager(new
89 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, -1));
90 view->set_border(views::Border::CreateEmptyBorder(0, 0, 0, 5));
91 return view;
92 }
93
94 const int kBorderHeight = 3;
95 const SkColor kBorderGradientDark = SkColorSetRGB(0xae, 0xae, 0xae);
96 const SkColor kBorderGradientLight = SkColorSetRGB(0xe8, 0xe8, 0xe8);
97
98 class SpecialPopupRowBorder : public views::Border {
99 public:
100 SpecialPopupRowBorder()
101 : painter_(views::Painter::CreateVerticalGradient(kBorderGradientDark,
102 kBorderGradientLight)) {
103 }
104
105 virtual ~SpecialPopupRowBorder() {}
106
107 private:
108 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE {
109 views::Painter::PaintPainterAt(canvas, painter_.get(),
110 gfx::Rect(gfx::Size(view.width(), kBorderHeight)));
111 }
112
113 virtual gfx::Insets GetInsets() const OVERRIDE {
114 return gfx::Insets(kBorderHeight, 0, 0, 0);
115 }
116
117 scoped_ptr<views::Painter> painter_;
118
119 DISALLOW_COPY_AND_ASSIGN(SpecialPopupRowBorder);
120 };
121
122 } 84 }
123 85
124 //////////////////////////////////////////////////////////////////////////////// 86 ////////////////////////////////////////////////////////////////////////////////
125 // FixedSizedImageView 87 // FixedSizedImageView
126 88
127 FixedSizedImageView::FixedSizedImageView(int width, int height) 89 FixedSizedImageView::FixedSizedImageView(int width, int height)
128 : width_(width), 90 : width_(width),
129 height_(height) { 91 height_(height) {
130 SetHorizontalAlignment(views::ImageView::CENTER); 92 SetHorizontalAlignment(views::ImageView::CENTER);
131 SetVerticalAlignment(views::ImageView::CENTER); 93 SetVerticalAlignment(views::ImageView::CENTER);
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 // Stop any previous animation. 655 // Stop any previous animation.
694 layer()->GetAnimator()->StopAnimating(); 656 layer()->GetAnimator()->StopAnimating();
695 657
696 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); 658 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
697 animation.SetTransitionDuration( 659 animation.SetTransitionDuration(
698 base::TimeDelta::FromMilliseconds(kThrobberAnimationDurationMs)); 660 base::TimeDelta::FromMilliseconds(kThrobberAnimationDurationMs));
699 661
700 layer()->SetOpacity(start_throbber ? 1.0 : 0.0); 662 layer()->SetOpacity(start_throbber ? 1.0 : 0.0);
701 } 663 }
702 664
703 ////////////////////////////////////////////////////////////////////////////////
704 // SpecialPopupRow
705
706 SpecialPopupRow::SpecialPopupRow()
707 : content_(NULL),
708 button_container_(NULL) {
709 views::Background* background = views::Background::CreateBackgroundPainter(
710 true, views::Painter::CreateVerticalGradient(kHeaderBackgroundColorLight,
711 kHeaderBackgroundColorDark));
712 background->SetNativeControlColor(kHeaderBackgroundColorDark);
713 set_background(background);
714 set_border(new SpecialPopupRowBorder);
715 SetLayoutManager(
716 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
717 }
718
719 SpecialPopupRow::~SpecialPopupRow() {
720 }
721
722 void SpecialPopupRow::SetTextLabel(int string_id, ViewClickListener* listener) {
723 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
724 HoverHighlightView* container = new HoverHighlightView(listener);
725 container->SetLayoutManager(new
726 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft));
727
728 container->set_highlight_color(SkColorSetARGB(0, 0, 0, 0));
729 container->set_default_color(SkColorSetARGB(0, 0, 0, 0));
730 container->set_text_highlight_color(kHeaderTextColorHover);
731 container->set_text_default_color(kHeaderTextColorNormal);
732
733 container->AddIconAndLabel(
734 *rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToImageSkia(),
735 rb.GetLocalizedString(string_id),
736 gfx::Font::BOLD);
737
738 container->set_border(views::Border::CreateEmptyBorder(0,
739 kTrayPopupPaddingHorizontal, 0, 0));
740
741 container->SetAccessibleName(
742 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_PREVIOUS_MENU));
743 SetContent(container);
744 }
745
746 void SpecialPopupRow::SetContent(views::View* view) {
747 CHECK(!content_);
748 content_ = view;
749 AddChildViewAt(content_, 0);
750 }
751
752 void SpecialPopupRow::AddButton(TrayPopupHeaderButton* button) {
753 if (!button_container_) {
754 button_container_ = CreatePopupHeaderButtonsContainer();
755 AddChildView(button_container_);
756 }
757
758 button_container_->AddChildView(button);
759 }
760
761 void SpecialPopupRow::AddThrobber(ThrobberView* throbber) {
762 if (!button_container_) {
763 button_container_ = CreatePopupHeaderButtonsContainer();
764 AddChildView(button_container_);
765 }
766
767 button_container_->AddChildView(throbber);
768 }
769
770 gfx::Size SpecialPopupRow::GetPreferredSize() {
771 gfx::Size size = views::View::GetPreferredSize();
772 size.set_height(kSpecialPopupRowHeight);
773 return size;
774 }
775
776 void SpecialPopupRow::Layout() {
777 views::View::Layout();
778 gfx::Rect content_bounds = GetContentsBounds();
779 if (content_bounds.IsEmpty())
780 return;
781 if (!button_container_) {
782 content_->SetBoundsRect(GetContentsBounds());
783 return;
784 }
785
786 gfx::Rect bounds(button_container_->GetPreferredSize());
787 bounds.set_height(content_bounds.height());
788 gfx::Rect container_bounds = content_bounds;
789 container_bounds.ClampToCenteredSize(bounds.size());
790 container_bounds.set_x(content_bounds.width() - container_bounds.width());
791 button_container_->SetBoundsRect(container_bounds);
792
793 bounds = content_->bounds();
794 bounds.set_width(button_container_->x());
795 content_->SetBoundsRect(bounds);
796 }
797
798 void SetupLabelForTray(views::Label* label) { 665 void SetupLabelForTray(views::Label* label) {
799 // Making label_font static to avoid the time penalty of DeriveFont for 666 // Making label_font static to avoid the time penalty of DeriveFont for
800 // all but the first call. 667 // all but the first call.
801 static const gfx::Font label_font(gfx::Font().DeriveFont(1, gfx::Font::BOLD)); 668 static const gfx::Font label_font(gfx::Font().DeriveFont(1, gfx::Font::BOLD));
802 label->SetFont(label_font); 669 label->SetFont(label_font);
803 label->SetAutoColorReadabilityEnabled(false); 670 label->SetAutoColorReadabilityEnabled(false);
804 label->SetEnabledColor(SK_ColorWHITE); 671 label->SetEnabledColor(SK_ColorWHITE);
805 label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); 672 label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255));
806 label->SetShadowColors(SkColorSetARGB(64, 0, 0, 0), 673 label->SetShadowColors(SkColorSetARGB(64, 0, 0, 0),
807 SkColorSetARGB(64, 0, 0, 0)); 674 SkColorSetARGB(64, 0, 0, 0));
(...skipping 30 matching lines...) Expand all
838 tray_view->set_border(views::Border::CreateEmptyBorder( 705 tray_view->set_border(views::Border::CreateEmptyBorder(
839 kTrayLabelItemVerticalPaddingVeriticalAlignment, 706 kTrayLabelItemVerticalPaddingVeriticalAlignment,
840 horizontal_padding, 707 horizontal_padding,
841 kTrayLabelItemVerticalPaddingVeriticalAlignment, 708 kTrayLabelItemVerticalPaddingVeriticalAlignment,
842 horizontal_padding)); 709 horizontal_padding));
843 } 710 }
844 } 711 }
845 712
846 } // namespace internal 713 } // namespace internal
847 } // namespace ash 714 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/tray_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698