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/create_application_shortcut_view.h" | 5 #include "chrome/browser/ui/views/create_application_shortcut_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 | 91 |
92 void AppInfoView::Init(const string16& title_text, | 92 void AppInfoView::Init(const string16& title_text, |
93 const string16& description_text, | 93 const string16& description_text, |
94 const SkBitmap& icon) { | 94 const SkBitmap& icon) { |
95 icon_ = new views::ImageView(); | 95 icon_ = new views::ImageView(); |
96 icon_->SetImage(gfx::ImageSkia(icon)); | 96 icon_->SetImage(gfx::ImageSkia(icon)); |
97 icon_->SetImageSize(gfx::Size(kAppIconSize, kAppIconSize)); | 97 icon_->SetImageSize(gfx::Size(kAppIconSize, kAppIconSize)); |
98 | 98 |
99 title_ = new views::Label(title_text); | 99 title_ = new views::Label(title_text); |
100 title_->SetMultiLine(true); | 100 title_->SetMultiLine(true); |
101 title_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 101 title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
102 title_->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( | 102 title_->SetFont(ui::ResourceBundle::GetSharedInstance().GetFont( |
103 ui::ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD)); | 103 ui::ResourceBundle::BaseFont).DeriveFont(0, gfx::Font::BOLD)); |
104 | 104 |
105 if (!description_text.empty()) { | 105 if (!description_text.empty()) { |
106 PrepareDescriptionLabel(description_text); | 106 PrepareDescriptionLabel(description_text); |
107 } | 107 } |
108 | 108 |
109 SetupLayout(); | 109 SetupLayout(); |
110 } | 110 } |
111 | 111 |
112 void AppInfoView::PrepareDescriptionLabel(const string16& description) { | 112 void AppInfoView::PrepareDescriptionLabel(const string16& description) { |
113 DCHECK(!description.empty()); | 113 DCHECK(!description.empty()); |
114 | 114 |
115 const size_t kMaxLength = 200; | 115 const size_t kMaxLength = 200; |
116 const string16 kEllipsis(ASCIIToUTF16(" ... ")); | 116 const string16 kEllipsis(ASCIIToUTF16(" ... ")); |
117 | 117 |
118 string16 text = description; | 118 string16 text = description; |
119 if (text.length() > kMaxLength) { | 119 if (text.length() > kMaxLength) { |
120 text = text.substr(0, kMaxLength); | 120 text = text.substr(0, kMaxLength); |
121 text += kEllipsis; | 121 text += kEllipsis; |
122 } | 122 } |
123 | 123 |
124 if (description_) { | 124 if (description_) { |
125 description_->SetText(text); | 125 description_->SetText(text); |
126 } else { | 126 } else { |
127 description_ = new views::Label(text); | 127 description_ = new views::Label(text); |
128 description_->SetMultiLine(true); | 128 description_->SetMultiLine(true); |
129 description_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 129 description_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
130 } | 130 } |
131 } | 131 } |
132 | 132 |
133 void AppInfoView::SetupLayout() { | 133 void AppInfoView::SetupLayout() { |
134 views::GridLayout* layout = views::GridLayout::CreatePanel(this); | 134 views::GridLayout* layout = views::GridLayout::CreatePanel(this); |
135 SetLayoutManager(layout); | 135 SetLayoutManager(layout); |
136 | 136 |
137 static const int kColumnSetId = 0; | 137 static const int kColumnSetId = 0; |
138 views::ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); | 138 views::ColumnSet* column_set = layout->AddColumnSet(kColumnSetId); |
139 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, | 139 column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 248 |
249 CreateApplicationShortcutView::~CreateApplicationShortcutView() {} | 249 CreateApplicationShortcutView::~CreateApplicationShortcutView() {} |
250 | 250 |
251 void CreateApplicationShortcutView::InitControls() { | 251 void CreateApplicationShortcutView::InitControls() { |
252 // Create controls | 252 // Create controls |
253 app_info_ = new AppInfoView(shortcut_info_.title, shortcut_info_.description, | 253 app_info_ = new AppInfoView(shortcut_info_.title, shortcut_info_.description, |
254 shortcut_info_.favicon.IsEmpty() ? SkBitmap() : | 254 shortcut_info_.favicon.IsEmpty() ? SkBitmap() : |
255 *shortcut_info_.favicon.ToSkBitmap()); | 255 *shortcut_info_.favicon.ToSkBitmap()); |
256 create_shortcuts_label_ = new views::Label( | 256 create_shortcuts_label_ = new views::Label( |
257 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_LABEL)); | 257 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_LABEL)); |
258 create_shortcuts_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 258 create_shortcuts_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
259 | 259 |
260 desktop_check_box_ = AddCheckbox( | 260 desktop_check_box_ = AddCheckbox( |
261 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_DESKTOP_CHKBOX), | 261 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_DESKTOP_CHKBOX), |
262 profile_->GetPrefs()->GetBoolean(prefs::kWebAppCreateOnDesktop)); | 262 profile_->GetPrefs()->GetBoolean(prefs::kWebAppCreateOnDesktop)); |
263 | 263 |
264 menu_check_box_ = NULL; | 264 menu_check_box_ = NULL; |
265 quick_launch_check_box_ = NULL; | 265 quick_launch_check_box_ = NULL; |
266 | 266 |
267 #if defined(OS_WIN) | 267 #if defined(OS_WIN) |
268 // Do not allow creating shortcuts on the Start Screen for Windows 8. | 268 // Do not allow creating shortcuts on the Start Screen for Windows 8. |
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 if (image.IsEmpty()) { | 541 if (image.IsEmpty()) { |
542 shortcut_info_.favicon = ui::ResourceBundle::GetSharedInstance(). | 542 shortcut_info_.favicon = ui::ResourceBundle::GetSharedInstance(). |
543 GetImageNamed(IDR_APP_DEFAULT_ICON); | 543 GetImageNamed(IDR_APP_DEFAULT_ICON); |
544 } else { | 544 } else { |
545 shortcut_info_.favicon = image; | 545 shortcut_info_.favicon = image; |
546 } | 546 } |
547 | 547 |
548 CHECK(app_info_); | 548 CHECK(app_info_); |
549 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); | 549 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); |
550 } | 550 } |
OLD | NEW |