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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "chrome/grit/generated_resources.h" | 32 #include "chrome/grit/generated_resources.h" |
| 33 #include "components/constrained_window/constrained_window_views.h" | 33 #include "components/constrained_window/constrained_window_views.h" |
| 34 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/page_navigator.h" | 35 #include "content/public/browser/page_navigator.h" |
| 36 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 37 #include "extensions/common/extension.h" | 37 #include "extensions/common/extension.h" |
| 38 #include "extensions/common/extension_urls.h" | 38 #include "extensions/common/extension_urls.h" |
| 39 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 40 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "ui/gfx/color_palette.h" | 41 #include "ui/gfx/color_palette.h" |
| 42 #include "ui/gfx/paint_vector_icon.h" | 42 #include "ui/gfx/paint_vector_icon.h" |
|
Devlin
2017/04/26 15:54:23
nit: no longer needed
Elly Fong-Jones
2017/04/26 16:41:55
Done.
| |
| 43 #include "ui/gfx/text_utils.h" | 43 #include "ui/gfx/text_utils.h" |
| 44 #include "ui/native_theme/common_theme.h" | 44 #include "ui/native_theme/common_theme.h" |
| 45 #include "ui/views/border.h" | 45 #include "ui/views/border.h" |
| 46 #include "ui/views/controls/button/image_button.h" | 46 #include "ui/views/controls/button/image_button.h" |
|
Devlin
2017/04/26 15:54:23
nit: no longer needed
Elly Fong-Jones
2017/04/26 16:41:55
Done.
| |
| 47 #include "ui/views/controls/image_view.h" | 47 #include "ui/views/controls/image_view.h" |
| 48 #include "ui/views/controls/label.h" | 48 #include "ui/views/controls/label.h" |
| 49 #include "ui/views/controls/link.h" | 49 #include "ui/views/controls/link.h" |
| 50 #include "ui/views/controls/scroll_view.h" | 50 #include "ui/views/controls/scroll_view.h" |
| 51 #include "ui/views/controls/separator.h" | 51 #include "ui/views/controls/separator.h" |
| 52 #include "ui/views/layout/box_layout.h" | 52 #include "ui/views/layout/box_layout.h" |
| 53 #include "ui/views/layout/grid_layout.h" | 53 #include "ui/views/layout/grid_layout.h" |
| 54 #include "ui/views/widget/widget.h" | 54 #include "ui/views/widget/widget.h" |
| 55 #include "ui/views/window/dialog_client_view.h" | 55 #include "ui/views/window/dialog_client_view.h" |
| 56 | 56 |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 detail_label->SetMultiLine(true); | 660 detail_label->SetMultiLine(true); |
| 661 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 661 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 662 layout_->AddView(detail_label); | 662 layout_->AddView(detail_label); |
| 663 } | 663 } |
| 664 | 664 |
| 665 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const { | 665 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const { |
| 666 gfx::Size size = views::View::GetPreferredSize(); | 666 gfx::Size size = views::View::GetPreferredSize(); |
| 667 return gfx::Size(size.width(), size.height() * state_); | 667 return gfx::Size(size.width(), size.height() * state_); |
| 668 } | 668 } |
| 669 | 669 |
| 670 // This is necessary for a subtle reason: views::BoxLayout only honors the | |
| 671 // preferred size of subviews when using horizontal layout; in vertical layout, | |
| 672 // it computes the width it should be, then calls |GetHeightForWidth()| on each | |
| 673 // of the subviews to size them vertically. Without this override, the logic in | |
| 674 // |GetPreferredSize()| to animate show/hide ends up ignored when this View is | |
| 675 // inside a BoxLayout. | |
| 676 int ExpandableContainerView::DetailsView::GetHeightForWidth(int width) const { | |
| 677 return views::View::GetHeightForWidth(width) * state_; | |
| 678 } | |
| 679 | |
| 670 void ExpandableContainerView::DetailsView::AnimateToState(double state) { | 680 void ExpandableContainerView::DetailsView::AnimateToState(double state) { |
| 671 state_ = state; | 681 state_ = state; |
| 672 PreferredSizeChanged(); | 682 PreferredSizeChanged(); |
| 673 SchedulePaint(); | 683 SchedulePaint(); |
| 674 } | 684 } |
| 675 | 685 |
| 676 // ExpandableContainerView ----------------------------------------------------- | 686 // ExpandableContainerView ----------------------------------------------------- |
| 677 | 687 |
| 678 ExpandableContainerView::ExpandableContainerView( | 688 ExpandableContainerView::ExpandableContainerView( |
| 679 const PermissionDetails& details, | 689 const PermissionDetails& details, |
| 680 int horizontal_space, | 690 int horizontal_space, |
| 681 bool parent_bulleted) | 691 bool parent_bulleted) |
| 682 : details_view_(NULL), | 692 : details_view_(NULL), |
| 683 slide_animation_(this), | 693 slide_animation_(this), |
| 684 more_details_(NULL), | 694 more_details_(NULL), |
| 685 arrow_toggle_(NULL), | |
| 686 expanded_(false) { | 695 expanded_(false) { |
| 687 views::GridLayout* layout = new views::GridLayout(this); | 696 views::BoxLayout* layout = |
| 697 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | |
| 698 layout->set_cross_axis_alignment( | |
| 699 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | |
| 688 SetLayoutManager(layout); | 700 SetLayoutManager(layout); |
| 689 int column_set_id = 0; | |
| 690 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); | |
| 691 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, | |
| 692 0, views::GridLayout::USE_PREF, 0, 0); | |
| 693 | 701 |
| 694 if (details.empty()) | 702 if (details.empty()) |
| 695 return; | 703 return; |
| 696 | 704 |
| 697 details_view_ = new DetailsView(horizontal_space, parent_bulleted); | 705 details_view_ = new DetailsView(horizontal_space, parent_bulleted); |
| 698 | |
| 699 layout->StartRow(0, column_set_id); | |
| 700 layout->AddView(details_view_); | |
| 701 | |
| 702 for (size_t i = 0; i < details.size(); ++i) | 706 for (size_t i = 0; i < details.size(); ++i) |
| 703 details_view_->AddDetail(details[i]); | 707 details_view_->AddDetail(details[i]); |
| 708 AddChildView(details_view_); | |
| 704 | 709 |
| 705 // Make sure the link width column is as wide as needed for both Show and | 710 more_details_ = |
| 706 // Hide details, so that the arrow doesn't shift horizontally when we toggle. | 711 new views::Link(l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); |
| 707 views::Link* link = new views::Link( | |
| 708 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS)); | |
| 709 int link_col_width = link->GetPreferredSize().width(); | |
| 710 link->SetText(l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); | |
| 711 link_col_width = std::max(link_col_width, link->GetPreferredSize().width()); | |
| 712 | |
| 713 column_set = layout->AddColumnSet(++column_set_id); | |
| 714 // Padding to the left of the More Details column. | |
| 715 column_set->AddPaddingColumn(0, | |
| 716 GetLeftPaddingForBulletedItems(parent_bulleted)); | |
| 717 // The More Details column. | |
| 718 column_set->AddColumn(views::GridLayout::LEADING, | |
| 719 views::GridLayout::LEADING, | |
| 720 0, | |
| 721 views::GridLayout::FIXED, | |
| 722 link_col_width, | |
| 723 link_col_width); | |
| 724 // The Up/Down arrow column. | |
| 725 column_set->AddColumn(views::GridLayout::LEADING, | |
| 726 views::GridLayout::TRAILING, | |
| 727 0, | |
| 728 views::GridLayout::USE_PREF, | |
| 729 0, | |
| 730 0); | |
| 731 | |
| 732 // Add the More Details link. | |
| 733 layout->StartRow(0, column_set_id); | |
| 734 more_details_ = link; | |
| 735 more_details_->set_listener(this); | 712 more_details_->set_listener(this); |
| 736 more_details_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 713 more_details_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 737 layout->AddView(more_details_); | 714 AddChildView(more_details_); |
| 738 | |
| 739 // Add the arrow after the More Details link. | |
| 740 arrow_toggle_ = new views::ImageButton(this); | |
| 741 UpdateArrowToggle(false); | |
| 742 layout->AddView(arrow_toggle_); | |
| 743 } | 715 } |
| 744 | 716 |
| 745 ExpandableContainerView::~ExpandableContainerView() { | 717 ExpandableContainerView::~ExpandableContainerView() { |
| 746 } | 718 } |
| 747 | 719 |
| 748 void ExpandableContainerView::ButtonPressed( | 720 void ExpandableContainerView::ButtonPressed( |
| 749 views::Button* sender, const ui::Event& event) { | 721 views::Button* sender, const ui::Event& event) { |
| 750 ToggleDetailLevel(); | 722 ToggleDetailLevel(); |
| 751 } | 723 } |
| 752 | 724 |
| 753 void ExpandableContainerView::LinkClicked( | 725 void ExpandableContainerView::LinkClicked( |
| 754 views::Link* source, int event_flags) { | 726 views::Link* source, int event_flags) { |
| 755 ToggleDetailLevel(); | 727 ToggleDetailLevel(); |
| 756 } | 728 } |
| 757 | 729 |
| 758 void ExpandableContainerView::AnimationProgressed( | 730 void ExpandableContainerView::AnimationProgressed( |
| 759 const gfx::Animation* animation) { | 731 const gfx::Animation* animation) { |
| 760 DCHECK_EQ(&slide_animation_, animation); | 732 DCHECK_EQ(&slide_animation_, animation); |
| 761 if (details_view_) | 733 if (details_view_) |
| 762 details_view_->AnimateToState(animation->GetCurrentValue()); | 734 details_view_->AnimateToState(animation->GetCurrentValue()); |
| 763 } | 735 } |
| 764 | 736 |
| 765 void ExpandableContainerView::AnimationEnded(const gfx::Animation* animation) { | 737 void ExpandableContainerView::AnimationEnded(const gfx::Animation* animation) { |
| 766 if (arrow_toggle_) | |
| 767 UpdateArrowToggle(animation->GetCurrentValue() != 0.0); | |
| 768 if (more_details_) { | 738 if (more_details_) { |
| 769 more_details_->SetText(expanded_ ? | 739 more_details_->SetText(expanded_ ? |
| 770 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS) : | 740 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS) : |
| 771 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); | 741 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); |
| 772 } | 742 } |
| 773 } | 743 } |
| 774 | 744 |
| 775 void ExpandableContainerView::ChildPreferredSizeChanged(views::View* child) { | 745 void ExpandableContainerView::ChildPreferredSizeChanged(views::View* child) { |
| 776 PreferredSizeChanged(); | 746 PreferredSizeChanged(); |
| 777 } | 747 } |
| 778 | 748 |
| 779 void ExpandableContainerView::ToggleDetailLevel() { | 749 void ExpandableContainerView::ToggleDetailLevel() { |
| 780 expanded_ = !expanded_; | 750 expanded_ = !expanded_; |
| 781 | 751 |
| 782 if (slide_animation_.IsShowing()) | 752 if (slide_animation_.IsShowing()) |
| 783 slide_animation_.Hide(); | 753 slide_animation_.Hide(); |
| 784 else | 754 else |
| 785 slide_animation_.Show(); | 755 slide_animation_.Show(); |
| 786 } | 756 } |
| 787 | 757 |
| 788 void ExpandableContainerView::UpdateArrowToggle(bool expanded) { | |
| 789 gfx::ImageSkia icon = gfx::CreateVectorIcon( | |
| 790 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey); | |
| 791 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon); | |
| 792 } | |
| 793 | |
| 794 // static | 758 // static |
| 795 ExtensionInstallPrompt::ShowDialogCallback | 759 ExtensionInstallPrompt::ShowDialogCallback |
| 796 ExtensionInstallPrompt::GetViewsShowDialogCallback() { | 760 ExtensionInstallPrompt::GetViewsShowDialogCallback() { |
| 797 return base::Bind(&ShowExtensionInstallDialogImpl); | 761 return base::Bind(&ShowExtensionInstallDialogImpl); |
| 798 } | 762 } |
| OLD | NEW |