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(DialogLayout dialog_layout) { |
262 // Create controls | 262 if (dialog_layout == DIALOG_LAYOUT_URL_SHORTCUT) { |
263 app_info_ = new AppInfoView(shortcut_info_.title, shortcut_info_.description, | 263 app_info_ = new AppInfoView(shortcut_info_.title, |
264 shortcut_info_.favicon); | 264 shortcut_info_.description, |
| 265 shortcut_info_.favicon); |
| 266 } |
265 create_shortcuts_label_ = new views::Label( | 267 create_shortcuts_label_ = new views::Label( |
266 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_LABEL)); | 268 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_LABEL)); |
267 create_shortcuts_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 269 create_shortcuts_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
268 | 270 |
269 desktop_check_box_ = AddCheckbox( | 271 desktop_check_box_ = AddCheckbox( |
270 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_DESKTOP_CHKBOX), | 272 l10n_util::GetStringUTF16(IDS_CREATE_SHORTCUTS_DESKTOP_CHKBOX), |
271 profile_->GetPrefs()->GetBoolean(prefs::kWebAppCreateOnDesktop)); | 273 profile_->GetPrefs()->GetBoolean(prefs::kWebAppCreateOnDesktop)); |
272 | 274 |
273 menu_check_box_ = NULL; | 275 menu_check_box_ = NULL; |
274 quick_launch_check_box_ = NULL; | 276 quick_launch_check_box_ = NULL; |
(...skipping 26 matching lines...) Expand all Loading... |
301 views::ColumnSet* column_set = layout->AddColumnSet(kHeaderColumnSetId); | 303 views::ColumnSet* column_set = layout->AddColumnSet(kHeaderColumnSetId); |
302 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 304 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, |
303 100.0f, views::GridLayout::FIXED, 0, 0); | 305 100.0f, views::GridLayout::FIXED, 0, 0); |
304 | 306 |
305 static const int kTableColumnSetId = 1; | 307 static const int kTableColumnSetId = 1; |
306 column_set = layout->AddColumnSet(kTableColumnSetId); | 308 column_set = layout->AddColumnSet(kTableColumnSetId); |
307 column_set->AddPaddingColumn(0, views::kPanelHorizIndentation); | 309 column_set->AddPaddingColumn(0, views::kPanelHorizIndentation); |
308 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | 310 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
309 100.0f, views::GridLayout::USE_PREF, 0, 0); | 311 100.0f, views::GridLayout::USE_PREF, 0, 0); |
310 | 312 |
311 layout->StartRow(0, kHeaderColumnSetId); | 313 if (app_info_) { |
312 layout->AddView(app_info_); | 314 layout->StartRow(0, kHeaderColumnSetId); |
| 315 layout->AddView(app_info_); |
| 316 layout->AddPaddingRow(0, views::kPanelSubVerticalSpacing); |
| 317 } |
313 | 318 |
314 layout->AddPaddingRow(0, views::kPanelSubVerticalSpacing); | |
315 layout->StartRow(0, kHeaderColumnSetId); | 319 layout->StartRow(0, kHeaderColumnSetId); |
316 layout->AddView(create_shortcuts_label_); | 320 layout->AddView(create_shortcuts_label_); |
317 | 321 |
318 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing); | 322 layout->AddPaddingRow(0, views::kLabelToControlVerticalSpacing); |
319 layout->StartRow(0, kTableColumnSetId); | 323 layout->StartRow(0, kTableColumnSetId); |
320 layout->AddView(desktop_check_box_); | 324 layout->AddView(desktop_check_box_); |
321 | 325 |
322 if (menu_check_box_ != NULL) { | 326 if (menu_check_box_ != NULL) { |
323 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 327 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
324 layout->StartRow(0, kTableColumnSetId); | 328 layout->StartRow(0, kTableColumnSetId); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 const WebApplicationInfo& app_info = | 437 const WebApplicationInfo& app_info = |
434 extensions::TabHelper::FromWebContents(web_contents_)->web_app_info(); | 438 extensions::TabHelper::FromWebContents(web_contents_)->web_app_info(); |
435 if (!app_info.icons.empty()) { | 439 if (!app_info.icons.empty()) { |
436 web_app::GetIconsInfo(app_info, &unprocessed_icons_); | 440 web_app::GetIconsInfo(app_info, &unprocessed_icons_); |
437 FetchIcon(); | 441 FetchIcon(); |
438 } | 442 } |
439 | 443 |
440 // Create URL app shortcuts in the top-level menu. | 444 // Create URL app shortcuts in the top-level menu. |
441 create_in_chrome_apps_subdir_ = false; | 445 create_in_chrome_apps_subdir_ = false; |
442 | 446 |
443 InitControls(); | 447 InitControls(DIALOG_LAYOUT_URL_SHORTCUT); |
444 } | 448 } |
445 | 449 |
446 CreateUrlApplicationShortcutView::~CreateUrlApplicationShortcutView() { | 450 CreateUrlApplicationShortcutView::~CreateUrlApplicationShortcutView() { |
447 } | 451 } |
448 | 452 |
449 bool CreateUrlApplicationShortcutView::Accept() { | 453 bool CreateUrlApplicationShortcutView::Accept() { |
450 if (!CreateApplicationShortcutView::Accept()) | 454 if (!CreateApplicationShortcutView::Accept()) |
451 return false; | 455 return false; |
452 | 456 |
453 // Get the smallest icon in the icon family (should have only 1). | 457 // 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 } | 521 } |
518 } | 522 } |
519 | 523 |
520 CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( | 524 CreateChromeApplicationShortcutView::CreateChromeApplicationShortcutView( |
521 Profile* profile, | 525 Profile* profile, |
522 const extensions::Extension* app, | 526 const extensions::Extension* app, |
523 const base::Callback<void(bool)>& close_callback) | 527 const base::Callback<void(bool)>& close_callback) |
524 : CreateApplicationShortcutView(profile), | 528 : CreateApplicationShortcutView(profile), |
525 close_callback_(close_callback), | 529 close_callback_(close_callback), |
526 weak_ptr_factory_(this) { | 530 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. | 531 // Place Chrome app shortcuts in the "Chrome Apps" submenu. |
532 create_in_chrome_apps_subdir_ = true; | 532 create_in_chrome_apps_subdir_ = true; |
533 | 533 |
534 InitControls(); | 534 InitControls(DIALOG_LAYOUT_APP_SHORTCUT); |
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 } | 535 } |
542 | 536 |
543 CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {} | 537 CreateChromeApplicationShortcutView::~CreateChromeApplicationShortcutView() {} |
544 | 538 |
545 bool CreateChromeApplicationShortcutView::Accept() { | 539 bool CreateChromeApplicationShortcutView::Accept() { |
546 if (!close_callback_.is_null()) | 540 if (!close_callback_.is_null()) |
547 close_callback_.Run(true); | 541 close_callback_.Run(true); |
548 return CreateApplicationShortcutView::Accept(); | 542 return CreateApplicationShortcutView::Accept(); |
549 } | 543 } |
550 | 544 |
551 bool CreateChromeApplicationShortcutView::Cancel() { | 545 bool CreateChromeApplicationShortcutView::Cancel() { |
552 if (!close_callback_.is_null()) | 546 if (!close_callback_.is_null()) |
553 close_callback_.Run(false); | 547 close_callback_.Run(false); |
554 return CreateApplicationShortcutView::Cancel(); | 548 return CreateApplicationShortcutView::Cancel(); |
555 } | 549 } |
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 |