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

Side by Side Diff: ash/common/system/tray/special_popup_row.cc

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 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
« no previous file with comments | « ash/common/system/tray/special_popup_row.h ('k') | ash/common/system/tray/system_menu_button.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/common/system/tray/special_popup_row.h"
6
7 #include "ash/common/ash_constants.h"
8 #include "ash/common/material_design/material_design_controller.h"
9 #include "ash/common/system/tray/hover_highlight_view.h"
10 #include "ash/common/system/tray/throbber_view.h"
11 #include "ash/common/system/tray/tray_constants.h"
12 #include "ash/common/system/tray/tray_popup_header_button.h"
13 #include "ash/resources/grit/ash_resources.h"
14 #include "ash/strings/grit/ash_strings.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/geometry/insets.h"
18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/views/background.h"
20 #include "ui/views/border.h"
21 #include "ui/views/controls/button/custom_button.h"
22 #include "ui/views/controls/button/image_button.h"
23 #include "ui/views/controls/label.h"
24 #include "ui/views/controls/separator.h"
25 #include "ui/views/layout/box_layout.h"
26 #include "ui/views/painter.h"
27
28 namespace ash {
29 namespace {
30
31 const int kIconPaddingLeft = 5;
32 const int kSeparatorInset = 10;
33 const int kSpecialPopupRowHeight = 55;
34 const int kBorderHeight = 1;
35 const SkColor kBorderColor = SkColorSetRGB(0xaa, 0xaa, 0xaa);
36
37 views::View* CreateViewContainer() {
38 views::View* view = new views::View;
39 view->SetLayoutManager(
40 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
41 view->SetBorder(views::CreateEmptyBorder(4, 0, 4, 5));
42 return view;
43 }
44
45 } // namespace
46
47 SpecialPopupRow::SpecialPopupRow()
48 : content_(nullptr), views_after_content_container_(nullptr) {
49 DCHECK(!MaterialDesignController::IsSystemTrayMenuMaterial());
50 set_background(
51 views::Background::CreateSolidBackground(kHeaderBackgroundColor));
52 SetBorder(
53 views::CreateSolidSidedBorder(kBorderHeight, 0, 0, 0, kBorderColor));
54 }
55
56 SpecialPopupRow::~SpecialPopupRow() {}
57
58 void SpecialPopupRow::SetTextLabel(int string_id, ViewClickListener* listener) {
59 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
60 HoverHighlightView* container = new HoverHighlightView(listener);
61 container->SetLayoutManager(new views::BoxLayout(
62 views::BoxLayout::kHorizontal, 0, 3, kIconPaddingLeft));
63
64 container->set_highlight_color(SkColorSetARGB(0, 0, 0, 0));
65 container->set_default_color(SkColorSetARGB(0, 0, 0, 0));
66 container->set_text_highlight_color(kHeaderTextColorHover);
67 container->set_text_default_color(kHeaderTextColorNormal);
68
69 container->AddIconAndLabel(
70 *rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToImageSkia(),
71 rb.GetLocalizedString(string_id), true /* highlight */);
72
73 container->SetBorder(
74 views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0));
75
76 container->SetAccessibleName(
77 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_PREVIOUS_MENU));
78 SetContent(container);
79 }
80
81 void SpecialPopupRow::SetContent(views::View* view) {
82 CHECK(!content_);
83 views::BoxLayout* box_layout =
84 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
85 SetLayoutManager(box_layout);
86 content_ = view;
87 AddChildViewAt(content_, 0);
88 }
89
90 void SpecialPopupRow::AddViewToTitleRow(views::View* view) {
91 AddViewAfterContent(view);
92 }
93
94 void SpecialPopupRow::AddViewToRowNonMd(views::View* view, bool add_separator) {
95 AddViewAfterContent(view, add_separator);
96 }
97
98 gfx::Size SpecialPopupRow::GetPreferredSize() const {
99 gfx::Size size = views::View::GetPreferredSize();
100 size.set_height(kSpecialPopupRowHeight);
101 return size;
102 }
103
104 int SpecialPopupRow::GetHeightForWidth(int width) const {
105 return kSpecialPopupRowHeight;
106 }
107
108 void SpecialPopupRow::Layout() {
109 views::View::Layout();
110
111 const gfx::Rect content_bounds = GetContentsBounds();
112 if (content_bounds.IsEmpty())
113 return;
114
115 if (!views_after_content_container_) {
116 content_->SetBoundsRect(GetContentsBounds());
117 return;
118 }
119
120 gfx::Rect bounds(views_after_content_container_->GetPreferredSize());
121 bounds.set_height(content_bounds.height());
122
123 gfx::Rect container_bounds = content_bounds;
124 container_bounds.ClampToCenteredSize(bounds.size());
125 container_bounds.set_x(content_bounds.width() - container_bounds.width());
126 views_after_content_container_->SetBoundsRect(container_bounds);
127
128 bounds = content_->bounds();
129 bounds.set_width(views_after_content_container_->x());
130 content_->SetBoundsRect(bounds);
131 }
132
133 void SpecialPopupRow::AddViewAfterContent(views::View* view) {
134 AddViewAfterContent(view, false);
135 }
136
137 void SpecialPopupRow::AddViewAfterContent(views::View* view,
138 bool add_separator) {
139 if (!views_after_content_container_) {
140 views_after_content_container_ = CreateViewContainer();
141 AddChildView(views_after_content_container_);
142 }
143
144 if (add_separator) {
145 views::Separator* separator = new views::Separator();
146 separator->SetColor(ash::kBorderDarkColor);
147 separator->SetBorder(
148 views::CreateEmptyBorder(kSeparatorInset, 0, kSeparatorInset, 0));
149 views_after_content_container_->AddChildView(separator);
150 }
151
152 views_after_content_container_->AddChildView(view);
153 }
154
155 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/tray/special_popup_row.h ('k') | ash/common/system/tray/system_menu_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698