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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 CreateApplicationShortcutView::CreateApplicationShortcutView(Profile* profile) | 251 CreateApplicationShortcutView::CreateApplicationShortcutView(Profile* profile) |
252 : profile_(profile), | 252 : profile_(profile), |
253 app_info_(NULL), | 253 app_info_(NULL), |
254 create_shortcuts_label_(NULL), | 254 create_shortcuts_label_(NULL), |
255 desktop_check_box_(NULL), | 255 desktop_check_box_(NULL), |
256 menu_check_box_(NULL), | 256 menu_check_box_(NULL), |
257 quick_launch_check_box_(NULL) {} | 257 quick_launch_check_box_(NULL) {} |
258 | 258 |
259 CreateApplicationShortcutView::~CreateApplicationShortcutView() {} | 259 CreateApplicationShortcutView::~CreateApplicationShortcutView() {} |
260 | 260 |
261 void CreateApplicationShortcutView::InitControls() { | 261 void CreateApplicationShortcutView::InitControls( |
262 // Create controls | 262 enum DialogLayout dialog_layout) { |
sky
2014/06/03 17:14:12
no enum here either.
sashab
2014/06/11 05:53:13
Done.
| |
263 app_info_ = new AppInfoView(shortcut_info_.title, shortcut_info_.description, | 263 if (dialog_layout == URL_SHORTCUT_LAYOUT) { |
264 shortcut_info_.favicon); | 264 app_info_ = new AppInfoView(shortcut_info_.title, |
265 shortcut_info_.description, | |
266 shortcut_info_.favicon); | |
267 } | |
265 create_shortcuts_label_ = new views::Label( | 268 create_shortcuts_label_ = new views::Label( |
266 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_LABEL)); | 269 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_LABEL)); |
267 create_shortcuts_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 270 create_shortcuts_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
268 | 271 |
269 desktop_check_box_ = AddCheckbox( | 272 desktop_check_box_ = AddCheckbox( |
270 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_DESKTOP_CHKBOX), | 273 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_DESKTOP_CHKBOX), |
271 profile_->GetPrefs()->GetBoolean(prefs::kWebAppCreateOnDesktop)); | 274 profile_->GetPrefs()->GetBoolean(prefs::kWebAppCreateOnDesktop)); |
272 | 275 |
273 menu_check_box_ = NULL; | 276 menu_check_box_ = NULL; |
274 quick_launch_check_box_ = NULL; | 277 quick_launch_check_box_ = NULL; |
(...skipping 26 matching lines...) Expand all Loading... | |
301 views::ColumnSet* column_set = layout->AddColumnSet(kHeaderColumnSetId); | 304 views::ColumnSet* column_set = layout->AddColumnSet(kHeaderColumnSetId); |
302 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 305 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
303 100.0f, views::GridLayout::FIXED, 0, 0); | 306 100.0f, views::GridLayout::FIXED, 0, 0); |
304 | 307 |
305 static const int kTableColumnSetId = 1; | 308 static const int kTableColumnSetId = 1; |
306 column_set = layout->AddColumnSet(kTableColumnSetId); | 309 column_set = layout->AddColumnSet(kTableColumnSetId); |
307 column_set->AddPaddingColumn(0, views::kPanelHorizIndentation); | 310 column_set->AddPaddingColumn(0, views::kPanelHorizIndentation); |
308 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 311 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
309 100.0f, views::GridLayout::USE_PREF, 0, 0); | 312 100.0f, views::GridLayout::USE_PREF, 0, 0); |
310 | 313 |
311 layout->StartRow(0, kHeaderColumnSetId); | 314 if (app_info_) { |
312 layout->AddView(app_info_); | 315 layout->StartRow(0, kHeaderColumnSetId); |
316 layout->AddView(app_info_); | |
317 layout->AddPaddingRow(0, views::kPanelSubVerticalSpacing); | |
318 } | |
313 | 319 |
314 layout->AddPaddingRow(0, views::kPanelSubVerticalSpacing); | |
315 layout->StartRow(0, kHeaderColumnSetId); | 320 layout->StartRow(0, kHeaderColumnSetId); |
316 layout->AddView(create_shortcuts_label_); | 321 layout->AddView(create_shortcuts_label_); |
317 | 322 |
318 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing); | 323 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing); |
319 layout->StartRow(0, kTableColumnSetId); | 324 layout->StartRow(0, kTableColumnSetId); |
320 layout->AddView(desktop_check_box_); | 325 layout->AddView(desktop_check_box_); |
321 | 326 |
322 if (menu_check_box_ != NULL) { | 327 if (menu_check_box_ != NULL) { |
323 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 328 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
324 layout->StartRow(0, kTableColumnSetId); | 329 layout->StartRow(0, kTableColumnSetId); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 const WebApplicationInfo& app_info = | 438 const WebApplicationInfo& app_info = |
434 extensions::TabHelper::FromWebContents(web_contents_)->web_app_info(); | 439 extensions::TabHelper::FromWebContents(web_contents_)->web_app_info(); |
435 if (!app_info.icons.empty()) { | 440 if (!app_info.icons.empty()) { |
436 web_app::GetIconsInfo(app_info, &unprocessed_icons_); | 441 web_app::GetIconsInfo(app_info, &unprocessed_icons_); |
437 FetchIcon(); | 442 FetchIcon(); |
438 } | 443 } |
439 | 444 |
440 // Create URL app shortcuts in the top-level menu. | 445 // Create URL app shortcuts in the top-level menu. |
441 create_in_chrome_apps_subdir_ = false; | 446 create_in_chrome_apps_subdir_ = false; |
442 | 447 |
443 InitControls(); | 448 InitControls(URL_SHORTCUT_LAYOUT); |
444 } | 449 } |
445 | 450 |
446 CreateUrlApplicationShortcutView::~CreateUrlApplicationShortcutView() { | 451 CreateUrlApplicationShortcutView::~CreateUrlApplicationShortcutView() { |
447 } | 452 } |
448 | 453 |
449 bool CreateUrlApplicationShortcutView::Accept() { | 454 bool CreateUrlApplicationShortcutView::Accept() { |
450 if (!CreateApplicationShortcutView::Accept()) | 455 if (!CreateApplicationShortcutView::Accept()) |
451 return false; | 456 return false; |
452 | 457 |
453 // Get the smallest icon in the icon family (should have only 1). | 458 // Get the smallest icon in the icon family (should have only 1). |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
517 } | 522 } |
518 } | 523 } |
519 | 524 |
520 CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( | 525 CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( |
521 Profile* profile, | 526 Profile* profile, |
522 const extensions::Extension* app, | 527 const extensions::Extension* app, |
523 const base::Callback<void(bool)>& close_callback) | 528 const base::Callback<void(bool)>& close_callback) |
524 : CreateApplicationShortcutView(profile), | 529 : CreateApplicationShortcutView(profile), |
525 close_callback_(close_callback), | 530 close_callback_(close_callback), |
526 weak_ptr_factory_(this) { | 531 weak_ptr_factory_(this) { |
527 // Required by InitControls(). | |
528 shortcut_info_.title = base::UTF8ToUTF16(app->name()); | |
529 shortcut_info_.description = base::UTF8ToUTF16(app->description()); | |
530 | |
531 // Place Chrome app shortcuts in the "Chrome Apps" submenu. | 532 // Place Chrome app shortcuts in the "Chrome Apps" submenu. |
532 create_in_chrome_apps_subdir_ = true; | 533 create_in_chrome_apps_subdir_ = true; |
533 | 534 |
534 InitControls(); | 535 InitControls(APP_SHORTCUT_LAYOUT); |
535 | |
536 // Get shortcut information and icon now; they are needed for our UI. | |
537 web_app::UpdateShortcutInfoAndIconForApp( | |
538 app, profile, | |
539 base::Bind(&CreateChromeApplicationShortcutView::OnShortcutInfoLoaded, | |
540 weak_ptr_factory_.GetWeakPtr())); | |
541 } | 536 } |
542 | 537 |
543 CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {} | 538 CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {} |
544 | 539 |
545 bool CreateChromeApplicationShortcutView::Accept() { | 540 bool CreateChromeApplicationShortcutView::Accept() { |
546 if (!close_callback_.is_null()) | 541 if (!close_callback_.is_null()) |
547 close_callback_.Run(true); | 542 close_callback_.Run(true); |
548 return CreateApplicationShortcutView::Accept(); | 543 return CreateApplicationShortcutView::Accept(); |
549 } | 544 } |
550 | 545 |
551 bool CreateChromeApplicationShortcutView::Cancel() { | 546 bool CreateChromeApplicationShortcutView::Cancel() { |
552 if (!close_callback_.is_null()) | 547 if (!close_callback_.is_null()) |
553 close_callback_.Run(false); | 548 close_callback_.Run(false); |
554 return CreateApplicationShortcutView::Cancel(); | 549 return CreateApplicationShortcutView::Cancel(); |
555 } | 550 } |
556 | |
557 // Called when the app's ShortcutInfo (with icon) is loaded. | |
558 void CreateChromeApplicationShortcutView::OnShortcutInfoLoaded( | |
559 const web_app::ShortcutInfo& shortcut_info) { | |
560 shortcut_info_ = shortcut_info; | |
561 | |
562 CHECK(app_info_); | |
563 static_cast<AppInfoView*>(app_info_)->UpdateIcon(shortcut_info_.favicon); | |
564 } | |
OLD | NEW |