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

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

Issue 2794763002: New Sad Tab strings. (Closed)
Patch Set: remove nested view 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 views::Label* CreateFormattedLabel(const base::string16& message) {
38 views::Label* label = new views::Label(message);
39
40 label->SetMultiLine(true);
41 label->SetEnabled(false);
sky 2017/05/18 20:53:36 I don't think you need this.
Will Harris 2017/05/18 21:02:07 this is needed to make the text grey rather than b
42 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
43 label->SetLineHeight(views::kPanelSubVerticalSpacing);
44
45 return label;
46 }
33 47
34 } // namespace 48 } // namespace
35 49
36 SadTabView::SadTabView(content::WebContents* web_contents, 50 SadTabView::SadTabView(content::WebContents* web_contents,
37 chrome::SadTabKind kind) 51 chrome::SadTabKind kind)
38 : SadTab(web_contents, kind) { 52 : SadTab(web_contents, kind) {
39 set_background(views::Background::CreateThemedSolidBackground( 53 set_background(views::Background::CreateThemedSolidBackground(
40 this, ui::NativeTheme::kColorId_DialogBackground)); 54 this, ui::NativeTheme::kColorId_DialogBackground));
41 55
42 views::GridLayout* layout = new views::GridLayout(this); 56 views::GridLayout* layout = new views::GridLayout(this);
(...skipping 18 matching lines...) Expand all
61 75
62 title_ = new views::Label(l10n_util::GetStringUTF16(GetTitle())); 76 title_ = new views::Label(l10n_util::GetStringUTF16(GetTitle()));
63 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 77 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
64 title_->SetFontList(rb.GetFontList(ui::ResourceBundle::LargeFont)); 78 title_->SetFontList(rb.GetFontList(ui::ResourceBundle::LargeFont));
65 title_->SetMultiLine(true); 79 title_->SetMultiLine(true);
66 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 80 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
67 layout->StartRowWithPadding(0, column_set_id, 0, 81 layout->StartRowWithPadding(0, column_set_id, 0,
68 views::kPanelVerticalSpacing); 82 views::kPanelVerticalSpacing);
69 layout->AddView(title_, 2, 1); 83 layout->AddView(title_, 2, 1);
70 84
71 message_ = new views::Label(l10n_util::GetStringUTF16(GetMessage())); 85 message_ = CreateFormattedLabel(l10n_util::GetStringUTF16(GetMessage()));
72
73 message_->SetMultiLine(true);
74 message_->SetEnabled(false);
75 message_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
76 message_->SetLineHeight(views::kPanelSubVerticalSpacing);
77
78 layout->StartRowWithPadding(0, column_set_id, 0, kTitleBottomSpacing); 86 layout->StartRowWithPadding(0, column_set_id, 0, kTitleBottomSpacing);
79 layout->AddView(message_, 2, 1, views::GridLayout::LEADING, 87 layout->AddView(message_, 2, 1, views::GridLayout::LEADING,
80 views::GridLayout::LEADING); 88 views::GridLayout::LEADING);
89 size_t bullet_id = 0;
90 int bullet_string_id = GetSubMessage(bullet_id);
91 if (bullet_string_id) {
92 const int bullet_columnset_id = 1;
93 views::ColumnSet* column_set = layout->AddColumnSet(bullet_columnset_id);
94 column_set->AddPaddingColumn(1, views::kPanelSubVerticalSpacing);
95 column_set->AddColumn(views::GridLayout::TRAILING,
96 views::GridLayout::LEADING, 0,
97 views::GridLayout::FIXED, kBulletWidth, 0);
98 column_set->AddPaddingColumn(0, kBulletPadding);
99 column_set->AddColumn(views::GridLayout::LEADING,
100 views::GridLayout::LEADING, 0,
101 views::GridLayout::USE_PREF,
102 0, // No fixed width.
103 0);
104 column_set->AddPaddingColumn(1, views::kPanelSubVerticalSpacing);
105
106 while (bullet_string_id) {
107 views::Label* bullet_label = CreateFormattedLabel(L"\u2022");
108 views::Label* label =
109 CreateFormattedLabel(l10n_util::GetStringUTF16(bullet_string_id));
110
111 layout->StartRowWithPadding(0, bullet_columnset_id, 0,
112 kBulletBottomSpacing);
113 layout->AddView(bullet_label);
114 layout->AddView(label);
115
116 bullet_labels_.push_back(label);
117 bullet_string_id = GetSubMessage(++bullet_id);
118 }
119 }
81 120
82 action_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( 121 action_button_ = views::MdTextButton::CreateSecondaryUiBlueButton(
83 this, l10n_util::GetStringUTF16(GetButtonTitle())); 122 this, l10n_util::GetStringUTF16(GetButtonTitle()));
84 help_link_ = new views::Link(l10n_util::GetStringUTF16(GetHelpLinkTitle())); 123 help_link_ = new views::Link(l10n_util::GetStringUTF16(GetHelpLinkTitle()));
85 help_link_->set_listener(this); 124 help_link_->set_listener(this);
86 layout->StartRowWithPadding(0, column_set_id, 0, 125 layout->StartRowWithPadding(0, column_set_id, 0,
87 views::kPanelVerticalSpacing); 126 views::kPanelVerticalSpacing);
88 layout->AddView(help_link_, 1, 1, views::GridLayout::LEADING, 127 layout->AddView(help_link_, 1, 1, views::GridLayout::LEADING,
89 views::GridLayout::CENTER); 128 views::GridLayout::CENTER);
90 layout->AddView(action_button_, 1, 1, views::GridLayout::TRAILING, 129 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, 163 void SadTabView::ButtonPressed(views::Button* sender,
125 const ui::Event& event) { 164 const ui::Event& event) {
126 DCHECK_EQ(action_button_, sender); 165 DCHECK_EQ(action_button_, sender);
127 PerformAction(Action::BUTTON); 166 PerformAction(Action::BUTTON);
128 } 167 }
129 168
130 void SadTabView::Layout() { 169 void SadTabView::Layout() {
131 // Specify the maximum message width explicitly. 170 // Specify the maximum message width explicitly.
132 const int max_width = 171 const int max_width =
133 std::min(width() - views::kPanelSubVerticalSpacing * 2, kMaxContentWidth); 172 std::min(width() - views::kPanelSubVerticalSpacing * 2, kMaxContentWidth);
173
134 message_->SizeToFit(max_width); 174 message_->SizeToFit(max_width);
135 title_->SizeToFit(max_width); 175 title_->SizeToFit(max_width);
136 176
177 // Bullet labels need to take into acocunt the size of the bullet.
178 for (views::Label* label : bullet_labels_) {
sky 2017/05/18 20:53:36 no {}
Will Harris 2017/05/18 21:02:07 Done.
179 label->SizeToFit(max_width - kBulletWidth - kBulletPadding);
180 }
181
137 View::Layout(); 182 View::Layout();
138 } 183 }
139 184
140 void SadTabView::OnPaint(gfx::Canvas* canvas) { 185 void SadTabView::OnPaint(gfx::Canvas* canvas) {
141 if (!painted_) { 186 if (!painted_) {
142 RecordFirstPaint(); 187 RecordFirstPaint();
143 painted_ = true; 188 painted_ = true;
144 } 189 }
145 View::OnPaint(canvas); 190 View::OnPaint(canvas);
146 } 191 }
147 192
148 namespace chrome { 193 namespace chrome {
149 194
150 SadTab* SadTab::Create(content::WebContents* web_contents, 195 SadTab* SadTab::Create(content::WebContents* web_contents,
151 SadTabKind kind) { 196 SadTabKind kind) {
152 return new SadTabView(web_contents, kind); 197 return new SadTabView(web_contents, kind);
153 } 198 }
154 199
155 } // namespace chrome 200 } // 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