| 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 "build/build_config.h" | 11 #include "build/build_config.h" |
| 11 #include "chrome/app/vector_icons/vector_icons.h" | 12 #include "chrome/app/vector_icons/vector_icons.h" |
| 12 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/color_palette.h" | 16 #include "ui/gfx/color_palette.h" |
| 16 #include "ui/gfx/paint_vector_icon.h" | 17 #include "ui/gfx/paint_vector_icon.h" |
| 17 #include "ui/native_theme/common_theme.h" | 18 #include "ui/native_theme/common_theme.h" |
| 18 #include "ui/native_theme/native_theme.h" | 19 #include "ui/native_theme/native_theme.h" |
| 19 #include "ui/views/background.h" | 20 #include "ui/views/background.h" |
| 20 #include "ui/views/controls/button/md_text_button.h" | 21 #include "ui/views/controls/button/md_text_button.h" |
| 21 #include "ui/views/controls/image_view.h" | 22 #include "ui/views/controls/image_view.h" |
| 22 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
| 23 #include "ui/views/controls/link.h" | 24 #include "ui/views/controls/link.h" |
| 24 #include "ui/views/layout/grid_layout.h" | 25 #include "ui/views/layout/grid_layout.h" |
| 25 #include "ui/views/layout/layout_constants.h" | 26 #include "ui/views/layout/layout_constants.h" |
| 26 #include "ui/views/widget/widget.h" | 27 #include "ui/views/widget/widget.h" |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 | 30 |
| 30 constexpr int kMaxContentWidth = 600; | 31 constexpr int kMaxContentWidth = 600; |
| 31 constexpr int kMinColumnWidth = 120; | 32 constexpr int kMinColumnWidth = 120; |
| 32 constexpr int kTitleBottomSpacing = 13; | 33 constexpr int kTitleBottomSpacing = 13; |
| 34 constexpr int kBulletBottomSpacing = 1; |
| 35 constexpr int kBulletWidth = 20; |
| 36 constexpr int kBulletPadding = 13; |
| 37 |
| 38 views::Label* CreateFormattedLabel(const base::string16& message) { |
| 39 views::Label* label = new views::Label(message); |
| 40 |
| 41 label->SetMultiLine(true); |
| 42 label->SetEnabled(false); |
| 43 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 44 label->SetLineHeight(views::kPanelSubVerticalSpacing); |
| 45 |
| 46 return label; |
| 47 } |
| 33 | 48 |
| 34 } // namespace | 49 } // namespace |
| 35 | 50 |
| 36 SadTabView::SadTabView(content::WebContents* web_contents, | 51 SadTabView::SadTabView(content::WebContents* web_contents, |
| 37 chrome::SadTabKind kind) | 52 chrome::SadTabKind kind) |
| 38 : SadTab(web_contents, kind) { | 53 : SadTab(web_contents, kind) { |
| 39 set_background(views::Background::CreateThemedSolidBackground( | 54 set_background(views::Background::CreateThemedSolidBackground( |
| 40 this, ui::NativeTheme::kColorId_DialogBackground)); | 55 this, ui::NativeTheme::kColorId_DialogBackground)); |
| 41 | 56 |
| 42 views::GridLayout* layout = new views::GridLayout(this); | 57 views::GridLayout* layout = new views::GridLayout(this); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 61 | 76 |
| 62 title_ = new views::Label(l10n_util::GetStringUTF16(GetTitle())); | 77 title_ = new views::Label(l10n_util::GetStringUTF16(GetTitle())); |
| 63 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 78 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 64 title_->SetFontList(rb.GetFontList(ui::ResourceBundle::LargeFont)); | 79 title_->SetFontList(rb.GetFontList(ui::ResourceBundle::LargeFont)); |
| 65 title_->SetMultiLine(true); | 80 title_->SetMultiLine(true); |
| 66 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 81 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 67 layout->StartRowWithPadding(0, column_set_id, 0, | 82 layout->StartRowWithPadding(0, column_set_id, 0, |
| 68 views::kPanelVerticalSpacing); | 83 views::kPanelVerticalSpacing); |
| 69 layout->AddView(title_, 2, 1); | 84 layout->AddView(title_, 2, 1); |
| 70 | 85 |
| 71 message_ = new views::Label(l10n_util::GetStringUTF16(GetMessage())); | 86 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); | 87 layout->StartRowWithPadding(0, column_set_id, 0, kTitleBottomSpacing); |
| 79 layout->AddView(message_, 2, 1, views::GridLayout::LEADING, | 88 layout->AddView(message_, 2, 1, views::GridLayout::LEADING, |
| 80 views::GridLayout::LEADING); | 89 views::GridLayout::LEADING); |
| 90 size_t bullet_id = 0; |
| 91 int bullet_string_id = GetSubMessage(bullet_id); |
| 92 if (bullet_string_id) { |
| 93 const int bullet_columnset_id = 1; |
| 94 views::ColumnSet* column_set = layout->AddColumnSet(bullet_columnset_id); |
| 95 column_set->AddPaddingColumn(1, views::kPanelSubVerticalSpacing); |
| 96 column_set->AddColumn(views::GridLayout::TRAILING, |
| 97 views::GridLayout::LEADING, 0, |
| 98 views::GridLayout::FIXED, kBulletWidth, 0); |
| 99 column_set->AddPaddingColumn(0, kBulletPadding); |
| 100 column_set->AddColumn(views::GridLayout::LEADING, |
| 101 views::GridLayout::LEADING, 0, |
| 102 views::GridLayout::USE_PREF, |
| 103 0, // No fixed width. |
| 104 0); |
| 105 column_set->AddPaddingColumn(1, views::kPanelSubVerticalSpacing); |
| 106 |
| 107 while (bullet_string_id) { |
| 108 const base::string16 bullet_character(base::WideToUTF16(L"\u2022")); |
| 109 views::Label* bullet_label = CreateFormattedLabel(bullet_character); |
| 110 views::Label* label = |
| 111 CreateFormattedLabel(l10n_util::GetStringUTF16(bullet_string_id)); |
| 112 |
| 113 layout->StartRowWithPadding(0, bullet_columnset_id, 0, |
| 114 kBulletBottomSpacing); |
| 115 layout->AddView(bullet_label); |
| 116 layout->AddView(label); |
| 117 |
| 118 bullet_labels_.push_back(label); |
| 119 bullet_string_id = GetSubMessage(++bullet_id); |
| 120 } |
| 121 } |
| 81 | 122 |
| 82 action_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( | 123 action_button_ = views::MdTextButton::CreateSecondaryUiBlueButton( |
| 83 this, l10n_util::GetStringUTF16(GetButtonTitle())); | 124 this, l10n_util::GetStringUTF16(GetButtonTitle())); |
| 84 help_link_ = new views::Link(l10n_util::GetStringUTF16(GetHelpLinkTitle())); | 125 help_link_ = new views::Link(l10n_util::GetStringUTF16(GetHelpLinkTitle())); |
| 85 help_link_->set_listener(this); | 126 help_link_->set_listener(this); |
| 86 layout->StartRowWithPadding(0, column_set_id, 0, | 127 layout->StartRowWithPadding(0, column_set_id, 0, |
| 87 views::kPanelVerticalSpacing); | 128 views::kPanelVerticalSpacing); |
| 88 layout->AddView(help_link_, 1, 1, views::GridLayout::LEADING, | 129 layout->AddView(help_link_, 1, 1, views::GridLayout::LEADING, |
| 89 views::GridLayout::CENTER); | 130 views::GridLayout::CENTER); |
| 90 layout->AddView(action_button_, 1, 1, views::GridLayout::TRAILING, | 131 layout->AddView(action_button_, 1, 1, views::GridLayout::TRAILING, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 void SadTabView::ButtonPressed(views::Button* sender, | 165 void SadTabView::ButtonPressed(views::Button* sender, |
| 125 const ui::Event& event) { | 166 const ui::Event& event) { |
| 126 DCHECK_EQ(action_button_, sender); | 167 DCHECK_EQ(action_button_, sender); |
| 127 PerformAction(Action::BUTTON); | 168 PerformAction(Action::BUTTON); |
| 128 } | 169 } |
| 129 | 170 |
| 130 void SadTabView::Layout() { | 171 void SadTabView::Layout() { |
| 131 // Specify the maximum message width explicitly. | 172 // Specify the maximum message width explicitly. |
| 132 const int max_width = | 173 const int max_width = |
| 133 std::min(width() - views::kPanelSubVerticalSpacing * 2, kMaxContentWidth); | 174 std::min(width() - views::kPanelSubVerticalSpacing * 2, kMaxContentWidth); |
| 175 |
| 134 message_->SizeToFit(max_width); | 176 message_->SizeToFit(max_width); |
| 135 title_->SizeToFit(max_width); | 177 title_->SizeToFit(max_width); |
| 136 | 178 |
| 179 // Bullet labels need to take into acocunt the size of the bullet. |
| 180 for (views::Label* label : bullet_labels_) |
| 181 label->SizeToFit(max_width - kBulletWidth - kBulletPadding); |
| 182 |
| 137 View::Layout(); | 183 View::Layout(); |
| 138 } | 184 } |
| 139 | 185 |
| 140 void SadTabView::OnPaint(gfx::Canvas* canvas) { | 186 void SadTabView::OnPaint(gfx::Canvas* canvas) { |
| 141 if (!painted_) { | 187 if (!painted_) { |
| 142 RecordFirstPaint(); | 188 RecordFirstPaint(); |
| 143 painted_ = true; | 189 painted_ = true; |
| 144 } | 190 } |
| 145 View::OnPaint(canvas); | 191 View::OnPaint(canvas); |
| 146 } | 192 } |
| 147 | 193 |
| 148 namespace chrome { | 194 namespace chrome { |
| 149 | 195 |
| 150 SadTab* SadTab::Create(content::WebContents* web_contents, | 196 SadTab* SadTab::Create(content::WebContents* web_contents, |
| 151 SadTabKind kind) { | 197 SadTabKind kind) { |
| 152 return new SadTabView(web_contents, kind); | 198 return new SadTabView(web_contents, kind); |
| 153 } | 199 } |
| 154 | 200 |
| 155 } // namespace chrome | 201 } // namespace chrome |
| OLD | NEW |