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

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

Issue 2926533002: Remove references to ui/views/layout/layout_constants.h (Closed)
Patch Set: Created 3 years, 6 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
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 "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "chrome/app/vector_icons/vector_icons.h" 12 #include "chrome/app/vector_icons/vector_icons.h"
13 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
13 #include "chrome/browser/ui/views/harmony/chrome_typography.h" 14 #include "chrome/browser/ui/views/harmony/chrome_typography.h"
14 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/color_palette.h" 18 #include "ui/gfx/color_palette.h"
18 #include "ui/gfx/paint_vector_icon.h" 19 #include "ui/gfx/paint_vector_icon.h"
19 #include "ui/native_theme/common_theme.h" 20 #include "ui/native_theme/common_theme.h"
20 #include "ui/native_theme/native_theme.h" 21 #include "ui/native_theme/native_theme.h"
21 #include "ui/views/background.h" 22 #include "ui/views/background.h"
22 #include "ui/views/controls/button/md_text_button.h" 23 #include "ui/views/controls/button/md_text_button.h"
23 #include "ui/views/controls/image_view.h" 24 #include "ui/views/controls/image_view.h"
24 #include "ui/views/controls/label.h" 25 #include "ui/views/controls/label.h"
25 #include "ui/views/controls/link.h" 26 #include "ui/views/controls/link.h"
26 #include "ui/views/layout/grid_layout.h" 27 #include "ui/views/layout/grid_layout.h"
27 #include "ui/views/layout/layout_constants.h"
28 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
29 29
30 namespace { 30 namespace {
31 31
32 constexpr int kMaxContentWidth = 600; 32 constexpr int kMaxContentWidth = 600;
33 constexpr int kMinColumnWidth = 120; 33 constexpr int kMinColumnWidth = 120;
34 constexpr int kTitleBottomSpacing = 13; 34 constexpr int kTitleBottomSpacing = 13;
35 constexpr int kBulletBottomSpacing = 1; 35 constexpr int kBulletBottomSpacing = 1;
36 constexpr int kBulletWidth = 20; 36 constexpr int kBulletWidth = 20;
37 constexpr int kBulletPadding = 13; 37 constexpr int kBulletPadding = 13;
38 38
39 views::Label* CreateFormattedLabel(const base::string16& message) { 39 views::Label* CreateFormattedLabel(const base::string16& message) {
40 views::Label* label = 40 views::Label* label =
41 new views::Label(message, views::style::CONTEXT_LABEL, STYLE_SECONDARY); 41 new views::Label(message, views::style::CONTEXT_LABEL, STYLE_SECONDARY);
42 42
43 label->SetMultiLine(true); 43 label->SetMultiLine(true);
44 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 44 label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
45 label->SetLineHeight(views::kPanelSubVerticalSpacing); 45 label->SetLineHeight(ChromeLayoutProvider::Get()->GetDistanceMetric(
46 46 DISTANCE_UNRELATED_CONTROL_VERTICAL));
47 return label; 47 return label;
48 } 48 }
49 49
50 } // namespace 50 } // namespace
51 51
52 SadTabView::SadTabView(content::WebContents* web_contents, 52 SadTabView::SadTabView(content::WebContents* web_contents,
53 chrome::SadTabKind kind) 53 chrome::SadTabKind kind)
54 : SadTab(web_contents, kind) { 54 : SadTab(web_contents, kind) {
55 SetBackground(views::CreateThemedSolidBackground( 55 SetBackground(views::CreateThemedSolidBackground(
56 this, ui::NativeTheme::kColorId_DialogBackground)); 56 this, ui::NativeTheme::kColorId_DialogBackground));
57 57
58 views::GridLayout* layout = new views::GridLayout(this); 58 views::GridLayout* layout = new views::GridLayout(this);
59 SetLayoutManager(layout); 59 SetLayoutManager(layout);
60 60
61 const int column_set_id = 0; 61 const int column_set_id = 0;
62 views::ColumnSet* columns = layout->AddColumnSet(column_set_id); 62 views::ColumnSet* columns = layout->AddColumnSet(column_set_id);
63 columns->AddPaddingColumn(1, views::kPanelSubVerticalSpacing); 63
64 // TODO(ananta)
65 // This view should probably be styled as web UI.
66 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
67 const int unrelated_vertical_spacing = provider->GetDistanceMetric(
68 DISTANCE_UNRELATED_CONTROL_VERTICAL);
69 columns->AddPaddingColumn(1, unrelated_vertical_spacing);
64 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0, 70 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0,
65 views::GridLayout::USE_PREF, 0, kMinColumnWidth); 71 views::GridLayout::USE_PREF, 0, kMinColumnWidth);
66 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, 0, 72 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, 0,
67 views::GridLayout::USE_PREF, 0, kMinColumnWidth); 73 views::GridLayout::USE_PREF, 0, kMinColumnWidth);
68 columns->AddPaddingColumn(1, views::kPanelSubVerticalSpacing); 74 columns->AddPaddingColumn(1, unrelated_vertical_spacing);
Peter Kasting 2017/06/06 03:34:33 This uses a vertical constant for a horizontal val
ananta 2017/06/06 03:44:18 Replaced with DISTANCE_UNRELATED_CONTROL_HORIZONTA
69 75
70 views::ImageView* image = new views::ImageView(); 76 views::ImageView* image = new views::ImageView();
71 77
72 image->SetImage( 78 image->SetImage(
73 gfx::CreateVectorIcon(kCrashedTabIcon, 48, gfx::kChromeIconGrey)); 79 gfx::CreateVectorIcon(kCrashedTabIcon, 48, gfx::kChromeIconGrey));
74 layout->AddPaddingRow(1, views::kPanelVerticalSpacing); 80
81 const int vertical_spacing_large = provider->GetDistanceMetric(
82 DISTANCE_UNRELATED_CONTROL_VERTICAL_LARGE);
83 layout->AddPaddingRow(1, provider->GetDistanceMetric(vertical_spacing_large));
75 layout->StartRow(0, column_set_id); 84 layout->StartRow(0, column_set_id);
76 layout->AddView(image, 2, 1); 85 layout->AddView(image, 2, 1);
77 86
78 title_ = new views::Label(l10n_util::GetStringUTF16(GetTitle())); 87 title_ = new views::Label(l10n_util::GetStringUTF16(GetTitle()));
79 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 88 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
80 title_->SetFontList(rb.GetFontList(ui::ResourceBundle::LargeFont)); 89 title_->SetFontList(rb.GetFontList(ui::ResourceBundle::LargeFont));
81 title_->SetMultiLine(true); 90 title_->SetMultiLine(true);
82 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 91 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
83 layout->StartRowWithPadding(0, column_set_id, 0, 92 layout->StartRowWithPadding(0, column_set_id, 0, unrelated_vertical_spacing);
Peter Kasting 2017/06/06 03:34:33 You used the LARGE variant of this above, should p
ananta 2017/06/06 03:44:18 Thanks done.
84 views::kPanelVerticalSpacing);
85 layout->AddView(title_, 2, 1); 93 layout->AddView(title_, 2, 1);
86 94
87 message_ = CreateFormattedLabel(l10n_util::GetStringUTF16(GetMessage())); 95 message_ = CreateFormattedLabel(l10n_util::GetStringUTF16(GetMessage()));
88 layout->StartRowWithPadding(0, column_set_id, 0, kTitleBottomSpacing); 96 layout->StartRowWithPadding(0, column_set_id, 0, kTitleBottomSpacing);
89 layout->AddView(message_, 2, 1, views::GridLayout::LEADING, 97 layout->AddView(message_, 2, 1, views::GridLayout::LEADING,
90 views::GridLayout::LEADING); 98 views::GridLayout::LEADING);
91 size_t bullet_id = 0; 99 size_t bullet_id = 0;
92 int bullet_string_id = GetSubMessage(bullet_id); 100 int bullet_string_id = GetSubMessage(bullet_id);
93 if (bullet_string_id) { 101 if (bullet_string_id) {
94 const int bullet_columnset_id = 1; 102 const int bullet_columnset_id = 1;
95 views::ColumnSet* column_set = layout->AddColumnSet(bullet_columnset_id); 103 views::ColumnSet* column_set = layout->AddColumnSet(bullet_columnset_id);
96 column_set->AddPaddingColumn(1, views::kPanelSubVerticalSpacing); 104 column_set->AddPaddingColumn(1, unrelated_vertical_spacing);
97 column_set->AddColumn(views::GridLayout::TRAILING, 105 column_set->AddColumn(views::GridLayout::TRAILING,
98 views::GridLayout::LEADING, 0, 106 views::GridLayout::LEADING, 0,
99 views::GridLayout::FIXED, kBulletWidth, 0); 107 views::GridLayout::FIXED, kBulletWidth, 0);
100 column_set->AddPaddingColumn(0, kBulletPadding); 108 column_set->AddPaddingColumn(0, kBulletPadding);
101 column_set->AddColumn(views::GridLayout::LEADING, 109 column_set->AddColumn(views::GridLayout::LEADING,
102 views::GridLayout::LEADING, 0, 110 views::GridLayout::LEADING, 0,
103 views::GridLayout::USE_PREF, 111 views::GridLayout::USE_PREF,
104 0, // No fixed width. 112 0, // No fixed width.
105 0); 113 0);
106 column_set->AddPaddingColumn(1, views::kPanelSubVerticalSpacing); 114 column_set->AddPaddingColumn(1, unrelated_vertical_spacing);
107 115
108 while (bullet_string_id) { 116 while (bullet_string_id) {
109 const base::string16 bullet_character(base::WideToUTF16(L"\u2022")); 117 const base::string16 bullet_character(base::WideToUTF16(L"\u2022"));
110 views::Label* bullet_label = CreateFormattedLabel(bullet_character); 118 views::Label* bullet_label = CreateFormattedLabel(bullet_character);
111 views::Label* label = 119 views::Label* label =
112 CreateFormattedLabel(l10n_util::GetStringUTF16(bullet_string_id)); 120 CreateFormattedLabel(l10n_util::GetStringUTF16(bullet_string_id));
113 121
114 layout->StartRowWithPadding(0, bullet_columnset_id, 0, 122 layout->StartRowWithPadding(0, bullet_columnset_id, 0,
115 kBulletBottomSpacing); 123 kBulletBottomSpacing);
116 layout->AddView(bullet_label); 124 layout->AddView(bullet_label);
117 layout->AddView(label); 125 layout->AddView(label);
118 126
119 bullet_labels_.push_back(label); 127 bullet_labels_.push_back(label);
120 bullet_string_id = GetSubMessage(++bullet_id); 128 bullet_string_id = GetSubMessage(++bullet_id);
121 } 129 }
122 } 130 }
123 131
124 action_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( 132 action_button_ = views::MdTextButton::CreateSecondaryUiBlueButton(
125 this, l10n_util::GetStringUTF16(GetButtonTitle())); 133 this, l10n_util::GetStringUTF16(GetButtonTitle()));
126 help_link_ = new views::Link(l10n_util::GetStringUTF16(GetHelpLinkTitle())); 134 help_link_ = new views::Link(l10n_util::GetStringUTF16(GetHelpLinkTitle()));
127 help_link_->set_listener(this); 135 help_link_->set_listener(this);
128 layout->StartRowWithPadding(0, column_set_id, 0, 136 layout->StartRowWithPadding(0, column_set_id, 0, vertical_spacing_large);
129 views::kPanelVerticalSpacing);
130 layout->AddView(help_link_, 1, 1, views::GridLayout::LEADING, 137 layout->AddView(help_link_, 1, 1, views::GridLayout::LEADING,
131 views::GridLayout::CENTER); 138 views::GridLayout::CENTER);
132 layout->AddView(action_button_, 1, 1, views::GridLayout::TRAILING, 139 layout->AddView(action_button_, 1, 1, views::GridLayout::TRAILING,
133 views::GridLayout::LEADING); 140 views::GridLayout::LEADING);
134 141
135 layout->AddPaddingRow(2, views::kPanelSubVerticalSpacing); 142 layout->AddPaddingRow(2, unrelated_vertical_spacing);
136 143
137 views::Widget::InitParams sad_tab_params( 144 views::Widget::InitParams sad_tab_params(
138 views::Widget::InitParams::TYPE_CONTROL); 145 views::Widget::InitParams::TYPE_CONTROL);
139 146
140 // It is not possible to create a native_widget_win that has no parent in 147 // It is not possible to create a native_widget_win that has no parent in
141 // and later re-parent it. 148 // and later re-parent it.
142 // TODO(avi): This is a cheat. Can this be made cleaner? 149 // TODO(avi): This is a cheat. Can this be made cleaner?
143 sad_tab_params.parent = web_contents->GetNativeView(); 150 sad_tab_params.parent = web_contents->GetNativeView();
144 151
145 set_owned_by_client(); 152 set_owned_by_client();
(...skipping 19 matching lines...) Expand all
165 172
166 void SadTabView::ButtonPressed(views::Button* sender, 173 void SadTabView::ButtonPressed(views::Button* sender,
167 const ui::Event& event) { 174 const ui::Event& event) {
168 DCHECK_EQ(action_button_, sender); 175 DCHECK_EQ(action_button_, sender);
169 PerformAction(Action::BUTTON); 176 PerformAction(Action::BUTTON);
170 } 177 }
171 178
172 void SadTabView::Layout() { 179 void SadTabView::Layout() {
173 // Specify the maximum message width explicitly. 180 // Specify the maximum message width explicitly.
174 const int max_width = 181 const int max_width =
175 std::min(width() - views::kPanelSubVerticalSpacing * 2, kMaxContentWidth); 182 std::min(width() - ChromeLayoutProvider::Get()->GetDistanceMetric(
183 DISTANCE_UNRELATED_CONTROL_VERTICAL), kMaxContentWidth);
Peter Kasting 2017/06/06 03:34:33 This uses a vertical constant for a horizontal val
ananta 2017/06/06 03:44:17 Done. Replaced with DISTANCE_UNRELATED_CONTROL_HOR
176 184
177 message_->SizeToFit(max_width); 185 message_->SizeToFit(max_width);
178 title_->SizeToFit(max_width); 186 title_->SizeToFit(max_width);
179 187
180 // Bullet labels need to take into acocunt the size of the bullet. 188 // Bullet labels need to take into acocunt the size of the bullet.
Peter Kasting 2017/06/06 03:34:33 Nit: While here: can you fix the "account" typo?
ananta 2017/06/06 03:44:18 Done.
181 for (views::Label* label : bullet_labels_) 189 for (views::Label* label : bullet_labels_)
182 label->SizeToFit(max_width - kBulletWidth - kBulletPadding); 190 label->SizeToFit(max_width - kBulletWidth - kBulletPadding);
183 191
184 View::Layout(); 192 View::Layout();
185 } 193 }
186 194
187 void SadTabView::OnPaint(gfx::Canvas* canvas) { 195 void SadTabView::OnPaint(gfx::Canvas* canvas) {
188 if (!painted_) { 196 if (!painted_) {
189 RecordFirstPaint(); 197 RecordFirstPaint();
190 painted_ = true; 198 painted_ = true;
191 } 199 }
192 View::OnPaint(canvas); 200 View::OnPaint(canvas);
193 } 201 }
194 202
195 namespace chrome { 203 namespace chrome {
196 204
197 SadTab* SadTab::Create(content::WebContents* web_contents, 205 SadTab* SadTab::Create(content::WebContents* web_contents,
198 SadTabKind kind) { 206 SadTabKind kind) {
199 return new SadTabView(web_contents, kind); 207 return new SadTabView(web_contents, kind);
200 } 208 }
201 209
202 } // namespace chrome 210 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698