Chromium Code Reviews| OLD | NEW |
|---|---|
| 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); | |
|
Peter Kasting
2017/06/06 03:47:01
This is also a horizontal amount.
ananta
2017/06/06 13:18:17
Yes. I should have noticed it earlier.
| |
| 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, provider->GetDistanceMetric( |
| 75 DISTANCE_UNRELATED_CONTROL_HORIZONTAL)); | |
| 69 | 76 |
| 70 views::ImageView* image = new views::ImageView(); | 77 views::ImageView* image = new views::ImageView(); |
| 71 | 78 |
| 72 image->SetImage( | 79 image->SetImage( |
| 73 gfx::CreateVectorIcon(kCrashedTabIcon, 48, gfx::kChromeIconGrey)); | 80 gfx::CreateVectorIcon(kCrashedTabIcon, 48, gfx::kChromeIconGrey)); |
| 74 layout->AddPaddingRow(1, views::kPanelVerticalSpacing); | 81 |
| 82 const int vertical_spacing_large = provider->GetDistanceMetric( | |
| 83 DISTANCE_UNRELATED_CONTROL_VERTICAL_LARGE); | |
| 84 layout->AddPaddingRow(1, provider->GetDistanceMetric(vertical_spacing_large)); | |
| 75 layout->StartRow(0, column_set_id); | 85 layout->StartRow(0, column_set_id); |
| 76 layout->AddView(image, 2, 1); | 86 layout->AddView(image, 2, 1); |
| 77 | 87 |
| 78 title_ = new views::Label(l10n_util::GetStringUTF16(GetTitle())); | 88 title_ = new views::Label(l10n_util::GetStringUTF16(GetTitle())); |
| 79 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 89 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 80 title_->SetFontList(rb.GetFontList(ui::ResourceBundle::LargeFont)); | 90 title_->SetFontList(rb.GetFontList(ui::ResourceBundle::LargeFont)); |
| 81 title_->SetMultiLine(true); | 91 title_->SetMultiLine(true); |
| 82 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 92 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 83 layout->StartRowWithPadding(0, column_set_id, 0, | 93 layout->StartRowWithPadding(0, column_set_id, 0, vertical_spacing_large); |
| 84 views::kPanelVerticalSpacing); | |
| 85 layout->AddView(title_, 2, 1); | 94 layout->AddView(title_, 2, 1); |
| 86 | 95 |
| 87 message_ = CreateFormattedLabel(l10n_util::GetStringUTF16(GetMessage())); | 96 message_ = CreateFormattedLabel(l10n_util::GetStringUTF16(GetMessage())); |
| 88 layout->StartRowWithPadding(0, column_set_id, 0, kTitleBottomSpacing); | 97 layout->StartRowWithPadding(0, column_set_id, 0, kTitleBottomSpacing); |
| 89 layout->AddView(message_, 2, 1, views::GridLayout::LEADING, | 98 layout->AddView(message_, 2, 1, views::GridLayout::LEADING, |
| 90 views::GridLayout::LEADING); | 99 views::GridLayout::LEADING); |
| 91 size_t bullet_id = 0; | 100 size_t bullet_id = 0; |
| 92 int bullet_string_id = GetSubMessage(bullet_id); | 101 int bullet_string_id = GetSubMessage(bullet_id); |
| 93 if (bullet_string_id) { | 102 if (bullet_string_id) { |
| 94 const int bullet_columnset_id = 1; | 103 const int bullet_columnset_id = 1; |
| 95 views::ColumnSet* column_set = layout->AddColumnSet(bullet_columnset_id); | 104 views::ColumnSet* column_set = layout->AddColumnSet(bullet_columnset_id); |
| 96 column_set->AddPaddingColumn(1, views::kPanelSubVerticalSpacing); | 105 column_set->AddPaddingColumn(1, unrelated_vertical_spacing); |
| 97 column_set->AddColumn(views::GridLayout::TRAILING, | 106 column_set->AddColumn(views::GridLayout::TRAILING, |
| 98 views::GridLayout::LEADING, 0, | 107 views::GridLayout::LEADING, 0, |
| 99 views::GridLayout::FIXED, kBulletWidth, 0); | 108 views::GridLayout::FIXED, kBulletWidth, 0); |
| 100 column_set->AddPaddingColumn(0, kBulletPadding); | 109 column_set->AddPaddingColumn(0, kBulletPadding); |
| 101 column_set->AddColumn(views::GridLayout::LEADING, | 110 column_set->AddColumn(views::GridLayout::LEADING, |
| 102 views::GridLayout::LEADING, 0, | 111 views::GridLayout::LEADING, 0, |
| 103 views::GridLayout::USE_PREF, | 112 views::GridLayout::USE_PREF, |
| 104 0, // No fixed width. | 113 0, // No fixed width. |
| 105 0); | 114 0); |
| 106 column_set->AddPaddingColumn(1, views::kPanelSubVerticalSpacing); | 115 column_set->AddPaddingColumn(1, unrelated_vertical_spacing); |
| 107 | 116 |
| 108 while (bullet_string_id) { | 117 while (bullet_string_id) { |
| 109 const base::string16 bullet_character(base::WideToUTF16(L"\u2022")); | 118 const base::string16 bullet_character(base::WideToUTF16(L"\u2022")); |
| 110 views::Label* bullet_label = CreateFormattedLabel(bullet_character); | 119 views::Label* bullet_label = CreateFormattedLabel(bullet_character); |
| 111 views::Label* label = | 120 views::Label* label = |
| 112 CreateFormattedLabel(l10n_util::GetStringUTF16(bullet_string_id)); | 121 CreateFormattedLabel(l10n_util::GetStringUTF16(bullet_string_id)); |
| 113 | 122 |
| 114 layout->StartRowWithPadding(0, bullet_columnset_id, 0, | 123 layout->StartRowWithPadding(0, bullet_columnset_id, 0, |
| 115 kBulletBottomSpacing); | 124 kBulletBottomSpacing); |
| 116 layout->AddView(bullet_label); | 125 layout->AddView(bullet_label); |
| 117 layout->AddView(label); | 126 layout->AddView(label); |
| 118 | 127 |
| 119 bullet_labels_.push_back(label); | 128 bullet_labels_.push_back(label); |
| 120 bullet_string_id = GetSubMessage(++bullet_id); | 129 bullet_string_id = GetSubMessage(++bullet_id); |
| 121 } | 130 } |
| 122 } | 131 } |
| 123 | 132 |
| 124 action_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( | 133 action_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( |
| 125 this, l10n_util::GetStringUTF16(GetButtonTitle())); | 134 this, l10n_util::GetStringUTF16(GetButtonTitle())); |
| 126 help_link_ = new views::Link(l10n_util::GetStringUTF16(GetHelpLinkTitle())); | 135 help_link_ = new views::Link(l10n_util::GetStringUTF16(GetHelpLinkTitle())); |
| 127 help_link_->set_listener(this); | 136 help_link_->set_listener(this); |
| 128 layout->StartRowWithPadding(0, column_set_id, 0, | 137 layout->StartRowWithPadding(0, column_set_id, 0, vertical_spacing_large); |
| 129 views::kPanelVerticalSpacing); | |
| 130 layout->AddView(help_link_, 1, 1, views::GridLayout::LEADING, | 138 layout->AddView(help_link_, 1, 1, views::GridLayout::LEADING, |
| 131 views::GridLayout::CENTER); | 139 views::GridLayout::CENTER); |
| 132 layout->AddView(action_button_, 1, 1, views::GridLayout::TRAILING, | 140 layout->AddView(action_button_, 1, 1, views::GridLayout::TRAILING, |
| 133 views::GridLayout::LEADING); | 141 views::GridLayout::LEADING); |
| 134 | 142 |
| 135 layout->AddPaddingRow(2, views::kPanelSubVerticalSpacing); | 143 layout->AddPaddingRow(2, unrelated_vertical_spacing); |
| 136 | 144 |
| 137 views::Widget::InitParams sad_tab_params( | 145 views::Widget::InitParams sad_tab_params( |
| 138 views::Widget::InitParams::TYPE_CONTROL); | 146 views::Widget::InitParams::TYPE_CONTROL); |
| 139 | 147 |
| 140 // It is not possible to create a native_widget_win that has no parent in | 148 // It is not possible to create a native_widget_win that has no parent in |
| 141 // and later re-parent it. | 149 // and later re-parent it. |
| 142 // TODO(avi): This is a cheat. Can this be made cleaner? | 150 // TODO(avi): This is a cheat. Can this be made cleaner? |
| 143 sad_tab_params.parent = web_contents->GetNativeView(); | 151 sad_tab_params.parent = web_contents->GetNativeView(); |
| 144 | 152 |
| 145 set_owned_by_client(); | 153 set_owned_by_client(); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 165 | 173 |
| 166 void SadTabView::ButtonPressed(views::Button* sender, | 174 void SadTabView::ButtonPressed(views::Button* sender, |
| 167 const ui::Event& event) { | 175 const ui::Event& event) { |
| 168 DCHECK_EQ(action_button_, sender); | 176 DCHECK_EQ(action_button_, sender); |
| 169 PerformAction(Action::BUTTON); | 177 PerformAction(Action::BUTTON); |
| 170 } | 178 } |
| 171 | 179 |
| 172 void SadTabView::Layout() { | 180 void SadTabView::Layout() { |
| 173 // Specify the maximum message width explicitly. | 181 // Specify the maximum message width explicitly. |
| 174 const int max_width = | 182 const int max_width = |
| 175 std::min(width() - views::kPanelSubVerticalSpacing * 2, kMaxContentWidth); | 183 std::min(width() - ChromeLayoutProvider::Get()->GetDistanceMetric( |
| 184 DISTANCE_UNRELATED_CONTROL_HORIZONTAL), kMaxContentWidth); | |
|
Peter Kasting
2017/06/06 03:47:01
The amount here has to equal the sum of the widths
ananta
2017/06/06 13:18:17
Sorry for missing this one as well. I missed the *
| |
| 176 | 185 |
| 177 message_->SizeToFit(max_width); | 186 message_->SizeToFit(max_width); |
| 178 title_->SizeToFit(max_width); | 187 title_->SizeToFit(max_width); |
| 179 | 188 |
| 180 // Bullet labels need to take into acocunt the size of the bullet. | 189 // Bullet labels need to take into account the size of the bullet. |
| 181 for (views::Label* label : bullet_labels_) | 190 for (views::Label* label : bullet_labels_) |
| 182 label->SizeToFit(max_width - kBulletWidth - kBulletPadding); | 191 label->SizeToFit(max_width - kBulletWidth - kBulletPadding); |
| 183 | 192 |
| 184 View::Layout(); | 193 View::Layout(); |
| 185 } | 194 } |
| 186 | 195 |
| 187 void SadTabView::OnPaint(gfx::Canvas* canvas) { | 196 void SadTabView::OnPaint(gfx::Canvas* canvas) { |
| 188 if (!painted_) { | 197 if (!painted_) { |
| 189 RecordFirstPaint(); | 198 RecordFirstPaint(); |
| 190 painted_ = true; | 199 painted_ = true; |
| 191 } | 200 } |
| 192 View::OnPaint(canvas); | 201 View::OnPaint(canvas); |
| 193 } | 202 } |
| 194 | 203 |
| 195 namespace chrome { | 204 namespace chrome { |
| 196 | 205 |
| 197 SadTab* SadTab::Create(content::WebContents* web_contents, | 206 SadTab* SadTab::Create(content::WebContents* web_contents, |
| 198 SadTabKind kind) { | 207 SadTabKind kind) { |
| 199 return new SadTabView(web_contents, kind); | 208 return new SadTabView(web_contents, kind); |
| 200 } | 209 } |
| 201 | 210 |
| 202 } // namespace chrome | 211 } // namespace chrome |
| OLD | NEW |