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

Side by Side Diff: chrome/browser/ui/views/sad_tab_view.cc

Issue 2794763002: New Sad Tab strings. (Closed)
Patch Set: final tweak from the denizens of UI review Created 3 years, 7 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 | « chrome/browser/ui/views/sad_tab_view.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 "chrome/browser/ui/views/sad_tab_view.h" 5 #include "chrome/browser/ui/views/sad_tab_view.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 12 matching lines...) Expand all
23 #include "ui/views/controls/link.h" 23 #include "ui/views/controls/link.h"
24 #include "ui/views/layout/grid_layout.h" 24 #include "ui/views/layout/grid_layout.h"
25 #include "ui/views/layout/layout_constants.h" 25 #include "ui/views/layout/layout_constants.h"
26 #include "ui/views/widget/widget.h" 26 #include "ui/views/widget/widget.h"
27 27
28 namespace { 28 namespace {
29 29
30 constexpr int kMaxContentWidth = 600; 30 constexpr int kMaxContentWidth = 600;
31 constexpr int kMinColumnWidth = 120; 31 constexpr int kMinColumnWidth = 120;
32 constexpr int kTitleBottomSpacing = 13; 32 constexpr int kTitleBottomSpacing = 13;
33 constexpr int kBulletBottomSpacing = 1;
34 constexpr int kBulletWidth = 20;
35 constexpr int kBulletPadding = 13;
36
37 // A simple view that prepends a view with a bullet with the help of a grid
38 // layout.
39 class BulletedView : public views::View {
40 public:
41 explicit BulletedView(views::View* view);
42
43 private:
44 DISALLOW_COPY_AND_ASSIGN(BulletedView);
45 };
46
47 BulletedView::BulletedView(views::View* view) {
48 views::GridLayout* layout = new views::GridLayout(this);
49 SetLayoutManager(layout);
50 views::ColumnSet* column_set = layout->AddColumnSet(0);
sky 2017/05/18 16:10:06 Creating another view will certainly work, but Gri
Will Harris 2017/05/18 17:13:29 Adding a new column set here means that I need to
51 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
52 0, views::GridLayout::FIXED, kBulletWidth, 0);
53 column_set->AddPaddingColumn(0, kBulletPadding);
54 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING,
55 0, views::GridLayout::USE_PREF,
56 0, // No fixed width.
57 0);
58 layout->StartRow(0, 0);
59 views::Label* bullet_label = new views::Label(L"\u2022");
60 bullet_label->SetEnabled(false);
61 bullet_label->SetLineHeight(views::kPanelSubVerticalSpacing);
62 bullet_label->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
63
64 layout->AddView(bullet_label);
65 layout->AddView(view);
66 }
67
68 views::Label* CreateFormattedLabel(int message_id) {
69 views::Label* label = new views::Label(l10n_util::GetStringUTF16(message_id));
70
71 label->SetMultiLine(true);
72 label->SetEnabled(false);
73 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
74 label->SetLineHeight(views::kPanelSubVerticalSpacing);
75
76 return label;
77 }
33 78
34 } // namespace 79 } // namespace
35 80
36 SadTabView::SadTabView(content::WebContents* web_contents, 81 SadTabView::SadTabView(content::WebContents* web_contents,
37 chrome::SadTabKind kind) 82 chrome::SadTabKind kind)
38 : SadTab(web_contents, kind) { 83 : SadTab(web_contents, kind) {
39 set_background(views::Background::CreateThemedSolidBackground( 84 set_background(views::Background::CreateThemedSolidBackground(
40 this, ui::NativeTheme::kColorId_DialogBackground)); 85 this, ui::NativeTheme::kColorId_DialogBackground));
41 86
42 views::GridLayout* layout = new views::GridLayout(this); 87 views::GridLayout* layout = new views::GridLayout(this);
(...skipping 18 matching lines...) Expand all
61 106
62 title_ = new views::Label(l10n_util::GetStringUTF16(GetTitle())); 107 title_ = new views::Label(l10n_util::GetStringUTF16(GetTitle()));
63 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 108 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
64 title_->SetFontList(rb.GetFontList(ui::ResourceBundle::LargeFont)); 109 title_->SetFontList(rb.GetFontList(ui::ResourceBundle::LargeFont));
65 title_->SetMultiLine(true); 110 title_->SetMultiLine(true);
66 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 111 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
67 layout->StartRowWithPadding(0, column_set_id, 0, 112 layout->StartRowWithPadding(0, column_set_id, 0,
68 views::kPanelVerticalSpacing); 113 views::kPanelVerticalSpacing);
69 layout->AddView(title_, 2, 1); 114 layout->AddView(title_, 2, 1);
70 115
71 message_ = new views::Label(l10n_util::GetStringUTF16(GetMessage())); 116 views::Label* message = CreateFormattedLabel(GetMessage());
117 layout->StartRowWithPadding(0, column_set_id, 0, kTitleBottomSpacing);
118 layout->AddView(message, 2, 1, views::GridLayout::LEADING,
119 views::GridLayout::LEADING);
120 labels_.push_back(message);
121 size_t bullet_id = 0;
122 int bullet_string_id = GetSubMessage(bullet_id);
72 123
73 message_->SetMultiLine(true); 124 while (bullet_string_id) {
74 message_->SetEnabled(false); 125 message = CreateFormattedLabel(bullet_string_id);
75 message_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 126 layout->StartRowWithPadding(0, column_set_id, 0, kBulletBottomSpacing);
76 message_->SetLineHeight(views::kPanelSubVerticalSpacing); 127 layout->AddView(new BulletedView(message), 2, 1, views::GridLayout::LEADING,
77 128 views::GridLayout::LEADING);
78 layout->StartRowWithPadding(0, column_set_id, 0, kTitleBottomSpacing); 129 labels_.push_back(message);
79 layout->AddView(message_, 2, 1, views::GridLayout::LEADING, 130 bullet_string_id = GetSubMessage(++bullet_id);
80 views::GridLayout::LEADING); 131 }
81 132
82 action_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( 133 action_button_ = views::MdTextButton::CreateSecondaryUiBlueButton(
83 this, l10n_util::GetStringUTF16(GetButtonTitle())); 134 this, l10n_util::GetStringUTF16(GetButtonTitle()));
84 help_link_ = new views::Link(l10n_util::GetStringUTF16(GetHelpLinkTitle())); 135 help_link_ = new views::Link(l10n_util::GetStringUTF16(GetHelpLinkTitle()));
85 help_link_->set_listener(this); 136 help_link_->set_listener(this);
86 layout->StartRowWithPadding(0, column_set_id, 0, 137 layout->StartRowWithPadding(0, column_set_id, 0,
87 views::kPanelVerticalSpacing); 138 views::kPanelVerticalSpacing);
88 layout->AddView(help_link_, 1, 1, views::GridLayout::LEADING, 139 layout->AddView(help_link_, 1, 1, views::GridLayout::LEADING,
89 views::GridLayout::CENTER); 140 views::GridLayout::CENTER);
90 layout->AddView(action_button_, 1, 1, views::GridLayout::TRAILING, 141 layout->AddView(action_button_, 1, 1, views::GridLayout::TRAILING,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 void SadTabView::ButtonPressed(views::Button* sender, 175 void SadTabView::ButtonPressed(views::Button* sender,
125 const ui::Event& event) { 176 const ui::Event& event) {
126 DCHECK_EQ(action_button_, sender); 177 DCHECK_EQ(action_button_, sender);
127 PerformAction(Action::BUTTON); 178 PerformAction(Action::BUTTON);
128 } 179 }
129 180
130 void SadTabView::Layout() { 181 void SadTabView::Layout() {
131 // Specify the maximum message width explicitly. 182 // Specify the maximum message width explicitly.
132 const int max_width = 183 const int max_width =
133 std::min(width() - views::kPanelSubVerticalSpacing * 2, kMaxContentWidth); 184 std::min(width() - views::kPanelSubVerticalSpacing * 2, kMaxContentWidth);
134 message_->SizeToFit(max_width); 185 for (views::Label* label : labels_) {
186 label->SizeToFit(max_width);
187 }
135 title_->SizeToFit(max_width); 188 title_->SizeToFit(max_width);
136 189
137 View::Layout(); 190 View::Layout();
138 } 191 }
139 192
140 void SadTabView::OnPaint(gfx::Canvas* canvas) { 193 void SadTabView::OnPaint(gfx::Canvas* canvas) {
141 if (!painted_) { 194 if (!painted_) {
142 RecordFirstPaint(); 195 RecordFirstPaint();
143 painted_ = true; 196 painted_ = true;
144 } 197 }
145 View::OnPaint(canvas); 198 View::OnPaint(canvas);
146 } 199 }
147 200
148 namespace chrome { 201 namespace chrome {
149 202
150 SadTab* SadTab::Create(content::WebContents* web_contents, 203 SadTab* SadTab::Create(content::WebContents* web_contents,
151 SadTabKind kind) { 204 SadTabKind kind) {
152 return new SadTabView(web_contents, kind); 205 return new SadTabView(web_contents, kind);
153 } 206 }
154 207
155 } // namespace chrome 208 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/sad_tab_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698