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/extensions/extension_install_dialog_view.h" | 5 #include "chrome/browser/ui/views/extensions/extension_install_dialog_view.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 22 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 23 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
| 25 #include "chrome/installer/util/browser_distribution.h" | 25 #include "chrome/installer/util/browser_distribution.h" |
| 26 #include "components/constrained_window/constrained_window_views.h" | 26 #include "components/constrained_window/constrained_window_views.h" |
| 27 #include "content/public/browser/page_navigator.h" | 27 #include "content/public/browser/page_navigator.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
| 30 #include "extensions/common/extension_urls.h" | 30 #include "extensions/common/extension_urls.h" |
| 31 #include "grit/theme_resources.h" | |
| 32 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| 33 #include "ui/gfx/paint_vector_icon.h" | |
| 34 #include "ui/gfx/text_utils.h" | 34 #include "ui/gfx/text_utils.h" |
| 35 #include "ui/gfx/vector_icons_public2.h" | |
| 36 #include "ui/native_theme/common_theme.h" | |
| 35 #include "ui/views/border.h" | 37 #include "ui/views/border.h" |
| 36 #include "ui/views/controls/button/image_button.h" | 38 #include "ui/views/controls/button/image_button.h" |
| 37 #include "ui/views/controls/image_view.h" | 39 #include "ui/views/controls/image_view.h" |
| 38 #include "ui/views/controls/label.h" | 40 #include "ui/views/controls/label.h" |
| 39 #include "ui/views/controls/link.h" | 41 #include "ui/views/controls/link.h" |
| 40 #include "ui/views/controls/scroll_view.h" | 42 #include "ui/views/controls/scroll_view.h" |
| 41 #include "ui/views/controls/separator.h" | 43 #include "ui/views/controls/separator.h" |
| 42 #include "ui/views/layout/box_layout.h" | 44 #include "ui/views/layout/box_layout.h" |
| 43 #include "ui/views/layout/grid_layout.h" | 45 #include "ui/views/layout/grid_layout.h" |
| 44 #include "ui/views/layout/layout_constants.h" | 46 #include "ui/views/layout/layout_constants.h" |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 layout->AddView(title); | 526 layout->AddView(title); |
| 525 | 527 |
| 526 // Scale down to icon size, but allow smaller icons (don't scale up). | 528 // Scale down to icon size, but allow smaller icons (don't scale up). |
| 527 const gfx::ImageSkia* image = prompt_->icon().ToImageSkia(); | 529 const gfx::ImageSkia* image = prompt_->icon().ToImageSkia(); |
| 528 gfx::Size size(image->width(), image->height()); | 530 gfx::Size size(image->width(), image->height()); |
| 529 if (size.width() > kIconSize || size.height() > kIconSize) | 531 if (size.width() > kIconSize || size.height() > kIconSize) |
| 530 size = gfx::Size(kIconSize, kIconSize); | 532 size = gfx::Size(kIconSize, kIconSize); |
| 531 views::ImageView* icon = new views::ImageView(); | 533 views::ImageView* icon = new views::ImageView(); |
| 532 icon->SetImageSize(size); | 534 icon->SetImageSize(size); |
| 533 icon->SetImage(*image); | 535 icon->SetImage(*image); |
| 534 icon->SetHorizontalAlignment(views::ImageView::CENTER); | |
|
Evan Stade
2015/08/10 17:13:40
unrelated, but these are already the defaults
| |
| 535 icon->SetVerticalAlignment(views::ImageView::CENTER); | |
| 536 | 536 |
| 537 int icon_row_span = 1; // Always span the title. | 537 int icon_row_span = 1; // Always span the title. |
| 538 if (prompt_->has_webstore_data()) { | 538 if (prompt_->has_webstore_data()) { |
| 539 // Also span the rating, user_count and store_link rows. | 539 // Also span the rating, user_count and store_link rows. |
| 540 icon_row_span += 3; | 540 icon_row_span += 3; |
| 541 // Note: Do not span the permissions here, there's a separator in between! | 541 // Note: Do not span the permissions here, there's a separator in between! |
| 542 } else { | 542 } else { |
| 543 // Also span the scrollable container with permissions, retained files etc. | 543 // Also span the scrollable container with permissions, retained files etc. |
| 544 icon_row_span += 1; | 544 icon_row_span += 1; |
| 545 } | 545 } |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 717 return; | 717 return; |
| 718 | 718 |
| 719 details_view_ = new DetailsView(horizontal_space, parent_bulleted); | 719 details_view_ = new DetailsView(horizontal_space, parent_bulleted); |
| 720 | 720 |
| 721 layout->StartRow(0, column_set_id); | 721 layout->StartRow(0, column_set_id); |
| 722 layout->AddView(details_view_); | 722 layout->AddView(details_view_); |
| 723 | 723 |
| 724 for (size_t i = 0; i < details.size(); ++i) | 724 for (size_t i = 0; i < details.size(); ++i) |
| 725 details_view_->AddDetail(details[i]); | 725 details_view_->AddDetail(details[i]); |
| 726 | 726 |
| 727 views::Link* link = new views::Link( | |
| 728 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); | |
| 729 | |
| 730 // Make sure the link width column is as wide as needed for both Show and | 727 // Make sure the link width column is as wide as needed for both Show and |
| 731 // Hide details, so that the arrow doesn't shift horizontally when we | 728 // Hide details, so that the arrow doesn't shift horizontally when we |
| 732 // toggle. | 729 // toggle. |
| 733 int link_col_width = | 730 views::Link* link = new views::Link( |
| 734 views::kRelatedControlHorizontalSpacing + | 731 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS)); |
| 735 std::max(gfx::GetStringWidth( | 732 int link_col_width = link->GetPreferredSize().width(); |
|
Evan Stade
2015/08/10 17:13:40
this was buggy; it neglects insets but papers over
| |
| 736 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS), | 733 link->SetText(l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); |
| 737 link->font_list()), | 734 link_col_width = std::max(link_col_width, link->GetPreferredSize().width()); |
| 738 gfx::GetStringWidth( | |
| 739 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS), | |
| 740 link->font_list())); | |
| 741 | 735 |
| 742 column_set = layout->AddColumnSet(++column_set_id); | 736 column_set = layout->AddColumnSet(++column_set_id); |
| 743 // Padding to the left of the More Details column. If the parent is using | 737 // Padding to the left of the More Details column. If the parent is using |
| 744 // bullets for its items, then a padding of one unit will make the child | 738 // bullets for its items, then a padding of one unit will make the child |
| 745 // item (which has no bullet) look like a sibling of its parent. Therefore | 739 // item (which has no bullet) look like a sibling of its parent. Therefore |
| 746 // increase the indentation by one more unit to show that it is in fact a | 740 // increase the indentation by one more unit to show that it is in fact a |
| 747 // child item (with no missing bullet) and not a sibling. | 741 // child item (with no missing bullet) and not a sibling. |
| 748 column_set->AddPaddingColumn( | 742 column_set->AddPaddingColumn( |
| 749 0, views::kRelatedControlHorizontalSpacing * (parent_bulleted ? 2 : 1)); | 743 0, views::kRelatedControlHorizontalSpacing * (parent_bulleted ? 2 : 1)); |
| 750 // The More Details column. | 744 // The More Details column. |
| 751 column_set->AddColumn(views::GridLayout::LEADING, | 745 column_set->AddColumn(views::GridLayout::LEADING, |
| 752 views::GridLayout::LEADING, | 746 views::GridLayout::LEADING, |
| 753 0, | 747 0, |
| 754 views::GridLayout::FIXED, | 748 views::GridLayout::FIXED, |
| 755 link_col_width, | 749 link_col_width, |
| 756 link_col_width); | 750 link_col_width); |
| 757 // The Up/Down arrow column. | 751 // The Up/Down arrow column. |
| 758 column_set->AddColumn(views::GridLayout::LEADING, | 752 column_set->AddColumn(views::GridLayout::LEADING, |
| 759 views::GridLayout::LEADING, | 753 views::GridLayout::TRAILING, |
| 760 0, | 754 0, |
| 761 views::GridLayout::USE_PREF, | 755 views::GridLayout::USE_PREF, |
| 762 0, | 756 0, |
| 763 0); | 757 0); |
| 764 | 758 |
| 765 // Add the More Details link. | 759 // Add the More Details link. |
| 766 layout->StartRow(0, column_set_id); | 760 layout->StartRow(0, column_set_id); |
| 767 more_details_ = link; | 761 more_details_ = link; |
| 768 more_details_->set_listener(this); | 762 more_details_->set_listener(this); |
| 769 more_details_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 763 more_details_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 770 layout->AddView(more_details_); | 764 layout->AddView(more_details_); |
| 771 | 765 |
| 772 // Add the arrow after the More Details link. | 766 // Add the arrow after the More Details link. |
| 773 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 774 arrow_toggle_ = new views::ImageButton(this); | 767 arrow_toggle_ = new views::ImageButton(this); |
| 775 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, | 768 UpdateArrowToggle(false); |
| 776 rb.GetImageSkiaNamed(IDR_DOWN_ARROW)); | |
| 777 layout->AddView(arrow_toggle_); | 769 layout->AddView(arrow_toggle_); |
| 778 } | 770 } |
| 779 | 771 |
| 780 ExpandableContainerView::~ExpandableContainerView() { | 772 ExpandableContainerView::~ExpandableContainerView() { |
| 781 } | 773 } |
| 782 | 774 |
| 783 void ExpandableContainerView::ButtonPressed( | 775 void ExpandableContainerView::ButtonPressed( |
| 784 views::Button* sender, const ui::Event& event) { | 776 views::Button* sender, const ui::Event& event) { |
| 785 ToggleDetailLevel(); | 777 ToggleDetailLevel(); |
| 786 } | 778 } |
| 787 | 779 |
| 788 void ExpandableContainerView::LinkClicked( | 780 void ExpandableContainerView::LinkClicked( |
| 789 views::Link* source, int event_flags) { | 781 views::Link* source, int event_flags) { |
| 790 ToggleDetailLevel(); | 782 ToggleDetailLevel(); |
| 791 } | 783 } |
| 792 | 784 |
| 793 void ExpandableContainerView::AnimationProgressed( | 785 void ExpandableContainerView::AnimationProgressed( |
| 794 const gfx::Animation* animation) { | 786 const gfx::Animation* animation) { |
| 795 DCHECK_EQ(&slide_animation_, animation); | 787 DCHECK_EQ(&slide_animation_, animation); |
| 796 if (details_view_) | 788 if (details_view_) |
| 797 details_view_->AnimateToState(animation->GetCurrentValue()); | 789 details_view_->AnimateToState(animation->GetCurrentValue()); |
| 798 } | 790 } |
| 799 | 791 |
| 800 void ExpandableContainerView::AnimationEnded(const gfx::Animation* animation) { | 792 void ExpandableContainerView::AnimationEnded(const gfx::Animation* animation) { |
| 801 if (arrow_toggle_) { | 793 if (arrow_toggle_) |
| 802 if (animation->GetCurrentValue() != 0.0) { | 794 UpdateArrowToggle(animation->GetCurrentValue() != 0.0); |
| 803 arrow_toggle_->SetImage( | |
| 804 views::Button::STATE_NORMAL, | |
| 805 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 806 IDR_UP_ARROW)); | |
| 807 } else { | |
| 808 arrow_toggle_->SetImage( | |
| 809 views::Button::STATE_NORMAL, | |
| 810 ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 811 IDR_DOWN_ARROW)); | |
| 812 } | |
| 813 } | |
| 814 if (more_details_) { | 795 if (more_details_) { |
| 815 more_details_->SetText(expanded_ ? | 796 more_details_->SetText(expanded_ ? |
| 816 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS) : | 797 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS) : |
| 817 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); | 798 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); |
| 818 } | 799 } |
| 819 } | 800 } |
| 820 | 801 |
| 821 void ExpandableContainerView::ChildPreferredSizeChanged(views::View* child) { | 802 void ExpandableContainerView::ChildPreferredSizeChanged(views::View* child) { |
| 822 PreferredSizeChanged(); | 803 PreferredSizeChanged(); |
| 823 } | 804 } |
| 824 | 805 |
| 825 void ExpandableContainerView::ToggleDetailLevel() { | 806 void ExpandableContainerView::ToggleDetailLevel() { |
| 826 expanded_ = !expanded_; | 807 expanded_ = !expanded_; |
| 827 | 808 |
| 828 if (slide_animation_.IsShowing()) | 809 if (slide_animation_.IsShowing()) |
| 829 slide_animation_.Hide(); | 810 slide_animation_.Hide(); |
| 830 else | 811 else |
| 831 slide_animation_.Show(); | 812 slide_animation_.Show(); |
| 832 } | 813 } |
| 833 | 814 |
| 815 void ExpandableContainerView::UpdateArrowToggle(bool expanded) { | |
| 816 SkColor icon_color; | |
| 817 ui::CommonThemeGetSystemColor(ui::NativeTheme::kColorId_ChromeIconGrey, | |
| 818 &icon_color); | |
| 819 gfx::ImageSkia icon = gfx::CreateVectorIcon(expanded ? | |
| 820 gfx::VectorIconId::FIND_PREV : | |
| 821 gfx::VectorIconId::FIND_NEXT, | |
| 822 16, | |
| 823 icon_color); | |
| 824 arrow_toggle_->SetImage( | |
| 825 views::Button::STATE_NORMAL, | |
| 826 &icon); | |
| 827 } | |
| 828 | |
| 834 // static | 829 // static |
| 835 ExtensionInstallPrompt::ShowDialogCallback | 830 ExtensionInstallPrompt::ShowDialogCallback |
| 836 ExtensionInstallPrompt::GetDefaultShowDialogCallback() { | 831 ExtensionInstallPrompt::GetDefaultShowDialogCallback() { |
| 837 return base::Bind(&ShowExtensionInstallDialogImpl); | 832 return base::Bind(&ShowExtensionInstallDialogImpl); |
| 838 } | 833 } |
| OLD | NEW |