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

Side by Side Diff: ash/system/tray/special_popup_row.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/special_popup_row.h ('k') | ash/system/tray/tray_details_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/system/tray/special_popup_row.h"
6
7 #include "ash/system/tray/tray_constants.h"
8 #include "ash/system/tray/tray_views.h"
9 #include "grit/ash_resources.h"
10 #include "grit/ash_strings.h"
11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/rect.h"
14 #include "ui/views/border.h"
15 #include "ui/views/layout/box_layout.h"
16 #include "ui/views/painter.h"
17
18 namespace ash {
19 namespace internal {
20
21 namespace {
22
23 const int kIconPaddingLeft = 5;
24 const int kSpecialPopupRowHeight = 55;
25 const int kBorderHeight = 3;
26 const SkColor kBorderGradientDark = SkColorSetRGB(0xae, 0xae, 0xae);
27 const SkColor kBorderGradientLight = SkColorSetRGB(0xe8, 0xe8, 0xe8);
28
29 views::View* CreatePopupHeaderButtonsContainer() {
30 views::View* view = new views::View;
31 view->SetLayoutManager(new
32 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, -1));
33 view->set_border(views::Border::CreateEmptyBorder(0, 0, 0, 5));
34 return view;
35 }
36
37 class SpecialPopupRowBorder : public views::Border {
38 public:
39 SpecialPopupRowBorder()
40 : painter_(views::Painter::CreateVerticalGradient(kBorderGradientDark,
41 kBorderGradientLight)) {
42 }
43
44 virtual ~SpecialPopupRowBorder() {}
45
46 private:
47 virtual void Paint(const views::View& view, gfx::Canvas* canvas) OVERRIDE {
48 views::Painter::PaintPainterAt(canvas, painter_.get(),
49 gfx::Rect(gfx::Size(view.width(), kBorderHeight)));
50 }
51
52 virtual gfx::Insets GetInsets() const OVERRIDE {
53 return gfx::Insets(kBorderHeight, 0, 0, 0);
54 }
55
56 scoped_ptr<views::Painter> painter_;
57
58 DISALLOW_COPY_AND_ASSIGN(SpecialPopupRowBorder);
59 };
60
61 } // namespace
62
63 SpecialPopupRow::SpecialPopupRow()
64 : content_(NULL),
65 button_container_(NULL) {
66 views::Background* background = views::Background::CreateBackgroundPainter(
67 true, views::Painter::CreateVerticalGradient(kHeaderBackgroundColorLight,
68 kHeaderBackgroundColorDark));
69 background->SetNativeControlColor(kHeaderBackgroundColorDark);
70 set_background(background);
71 set_border(new SpecialPopupRowBorder);
72 SetLayoutManager(
73 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
74 }
75
76 SpecialPopupRow::~SpecialPopupRow() {
77 }
78
79 void SpecialPopupRow::SetTextLabel(int string_id, ViewClickListener* listener) {
80 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
81 HoverHighlightView* container = new HoverHighlightView(listener);
82 container->SetLayoutManager(new
83 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft));
84
85 container->set_highlight_color(SkColorSetARGB(0, 0, 0, 0));
86 container->set_default_color(SkColorSetARGB(0, 0, 0, 0));
87 container->set_text_highlight_color(kHeaderTextColorHover);
88 container->set_text_default_color(kHeaderTextColorNormal);
89
90 container->AddIconAndLabel(
91 *rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToImageSkia(),
92 rb.GetLocalizedString(string_id),
93 gfx::Font::BOLD);
94
95 container->set_border(views::Border::CreateEmptyBorder(0,
96 kTrayPopupPaddingHorizontal, 0, 0));
97
98 container->SetAccessibleName(
99 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_PREVIOUS_MENU));
100 SetContent(container);
101 }
102
103 void SpecialPopupRow::SetContent(views::View* view) {
104 CHECK(!content_);
105 content_ = view;
106 AddChildViewAt(content_, 0);
107 }
108
109 void SpecialPopupRow::AddButton(TrayPopupHeaderButton* button) {
110 if (!button_container_) {
111 button_container_ = CreatePopupHeaderButtonsContainer();
112 AddChildView(button_container_);
113 }
114 button_container_->AddChildView(button);
115 }
116
117 void SpecialPopupRow::AddThrobber(ThrobberView* throbber) {
118 if (!button_container_) {
119 button_container_ = CreatePopupHeaderButtonsContainer();
120 AddChildView(button_container_);
121 }
122 button_container_->AddChildView(throbber);
123 }
124
125 gfx::Size SpecialPopupRow::GetPreferredSize() {
126 gfx::Size size = views::View::GetPreferredSize();
127 size.set_height(kSpecialPopupRowHeight);
128 return size;
129 }
130
131 void SpecialPopupRow::Layout() {
132 views::View::Layout();
133 gfx::Rect content_bounds = GetContentsBounds();
134 if (content_bounds.IsEmpty())
135 return;
136 if (!button_container_) {
137 content_->SetBoundsRect(GetContentsBounds());
138 return;
139 }
140
141 gfx::Rect bounds(button_container_->GetPreferredSize());
142 bounds.set_height(content_bounds.height());
143 gfx::Rect container_bounds = content_bounds;
144 container_bounds.ClampToCenteredSize(bounds.size());
145 container_bounds.set_x(content_bounds.width() - container_bounds.width());
146 button_container_->SetBoundsRect(container_bounds);
147
148 bounds = content_->bounds();
149 bounds.set_width(button_container_->x());
150 content_->SetBoundsRect(bounds);
151 }
152
153 } // namespace internal
154 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/special_popup_row.h ('k') | ash/system/tray/tray_details_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698