| 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" | |
| 43 #include "ui/gfx/text_utils.h" | 42 #include "ui/gfx/text_utils.h" |
| 44 #include "ui/native_theme/common_theme.h" | 43 #include "ui/native_theme/common_theme.h" |
| 45 #include "ui/views/border.h" | 44 #include "ui/views/border.h" |
| 46 #include "ui/views/controls/button/image_button.h" | |
| 47 #include "ui/views/controls/image_view.h" | 45 #include "ui/views/controls/image_view.h" |
| 48 #include "ui/views/controls/label.h" | 46 #include "ui/views/controls/label.h" |
| 49 #include "ui/views/controls/link.h" | 47 #include "ui/views/controls/link.h" |
| 50 #include "ui/views/controls/scroll_view.h" | 48 #include "ui/views/controls/scroll_view.h" |
| 51 #include "ui/views/controls/separator.h" | 49 #include "ui/views/controls/separator.h" |
| 52 #include "ui/views/layout/box_layout.h" | 50 #include "ui/views/layout/box_layout.h" |
| 53 #include "ui/views/layout/grid_layout.h" | 51 #include "ui/views/layout/grid_layout.h" |
| 54 #include "ui/views/widget/widget.h" | 52 #include "ui/views/widget/widget.h" |
| 55 #include "ui/views/window/dialog_client_view.h" | 53 #include "ui/views/window/dialog_client_view.h" |
| 56 | 54 |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 detail_label->SetMultiLine(true); | 658 detail_label->SetMultiLine(true); |
| 661 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 659 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 662 layout_->AddView(detail_label); | 660 layout_->AddView(detail_label); |
| 663 } | 661 } |
| 664 | 662 |
| 665 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const { | 663 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const { |
| 666 gfx::Size size = views::View::GetPreferredSize(); | 664 gfx::Size size = views::View::GetPreferredSize(); |
| 667 return gfx::Size(size.width(), size.height() * state_); | 665 return gfx::Size(size.width(), size.height() * state_); |
| 668 } | 666 } |
| 669 | 667 |
| 668 // This is necessary for a subtle reason: views::BoxLayout only honors the |
| 669 // preferred size of subviews when using horizontal layout; in vertical layout, |
| 670 // it computes the width it should be, then calls |GetHeightForWidth()| on each |
| 671 // of the subviews to size them vertically. Without this override, the logic in |
| 672 // |GetPreferredSize()| to animate show/hide ends up ignored when this View is |
| 673 // inside a BoxLayout. |
| 674 int ExpandableContainerView::DetailsView::GetHeightForWidth(int width) const { |
| 675 return views::View::GetHeightForWidth(width) * state_; |
| 676 } |
| 677 |
| 670 void ExpandableContainerView::DetailsView::AnimateToState(double state) { | 678 void ExpandableContainerView::DetailsView::AnimateToState(double state) { |
| 671 state_ = state; | 679 state_ = state; |
| 672 PreferredSizeChanged(); | 680 PreferredSizeChanged(); |
| 673 SchedulePaint(); | 681 SchedulePaint(); |
| 674 } | 682 } |
| 675 | 683 |
| 676 // ExpandableContainerView ----------------------------------------------------- | 684 // ExpandableContainerView ----------------------------------------------------- |
| 677 | 685 |
| 678 ExpandableContainerView::ExpandableContainerView( | 686 ExpandableContainerView::ExpandableContainerView( |
| 679 const PermissionDetails& details, | 687 const PermissionDetails& details, |
| 680 int horizontal_space, | 688 int horizontal_space, |
| 681 bool parent_bulleted) | 689 bool parent_bulleted) |
| 682 : details_view_(NULL), | 690 : details_view_(NULL), |
| 683 slide_animation_(this), | 691 slide_animation_(this), |
| 684 more_details_(NULL), | 692 more_details_(NULL), |
| 685 arrow_toggle_(NULL), | |
| 686 expanded_(false) { | 693 expanded_(false) { |
| 687 views::GridLayout* layout = new views::GridLayout(this); | 694 views::BoxLayout* layout = |
| 695 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); |
| 696 layout->set_cross_axis_alignment( |
| 697 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); |
| 688 SetLayoutManager(layout); | 698 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 | 699 |
| 694 if (details.empty()) | 700 if (details.empty()) |
| 695 return; | 701 return; |
| 696 | 702 |
| 697 details_view_ = new DetailsView(horizontal_space, parent_bulleted); | 703 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) | 704 for (size_t i = 0; i < details.size(); ++i) |
| 703 details_view_->AddDetail(details[i]); | 705 details_view_->AddDetail(details[i]); |
| 706 AddChildView(details_view_); |
| 704 | 707 |
| 705 // Make sure the link width column is as wide as needed for both Show and | 708 more_details_ = |
| 706 // Hide details, so that the arrow doesn't shift horizontally when we toggle. | 709 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); | 710 more_details_->set_listener(this); |
| 736 more_details_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 711 more_details_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 737 layout->AddView(more_details_); | 712 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 } | 713 } |
| 744 | 714 |
| 745 ExpandableContainerView::~ExpandableContainerView() { | 715 ExpandableContainerView::~ExpandableContainerView() { |
| 746 } | 716 } |
| 747 | 717 |
| 748 void ExpandableContainerView::ButtonPressed( | 718 void ExpandableContainerView::ButtonPressed( |
| 749 views::Button* sender, const ui::Event& event) { | 719 views::Button* sender, const ui::Event& event) { |
| 750 ToggleDetailLevel(); | 720 ToggleDetailLevel(); |
| 751 } | 721 } |
| 752 | 722 |
| 753 void ExpandableContainerView::LinkClicked( | 723 void ExpandableContainerView::LinkClicked( |
| 754 views::Link* source, int event_flags) { | 724 views::Link* source, int event_flags) { |
| 755 ToggleDetailLevel(); | 725 ToggleDetailLevel(); |
| 756 } | 726 } |
| 757 | 727 |
| 758 void ExpandableContainerView::AnimationProgressed( | 728 void ExpandableContainerView::AnimationProgressed( |
| 759 const gfx::Animation* animation) { | 729 const gfx::Animation* animation) { |
| 760 DCHECK_EQ(&slide_animation_, animation); | 730 DCHECK_EQ(&slide_animation_, animation); |
| 761 if (details_view_) | 731 if (details_view_) |
| 762 details_view_->AnimateToState(animation->GetCurrentValue()); | 732 details_view_->AnimateToState(animation->GetCurrentValue()); |
| 763 } | 733 } |
| 764 | 734 |
| 765 void ExpandableContainerView::AnimationEnded(const gfx::Animation* animation) { | 735 void ExpandableContainerView::AnimationEnded(const gfx::Animation* animation) { |
| 766 if (arrow_toggle_) | |
| 767 UpdateArrowToggle(animation->GetCurrentValue() != 0.0); | |
| 768 if (more_details_) { | 736 if (more_details_) { |
| 769 more_details_->SetText(expanded_ ? | 737 more_details_->SetText(expanded_ ? |
| 770 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS) : | 738 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS) : |
| 771 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); | 739 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); |
| 772 } | 740 } |
| 773 } | 741 } |
| 774 | 742 |
| 775 void ExpandableContainerView::ChildPreferredSizeChanged(views::View* child) { | 743 void ExpandableContainerView::ChildPreferredSizeChanged(views::View* child) { |
| 776 PreferredSizeChanged(); | 744 PreferredSizeChanged(); |
| 777 } | 745 } |
| 778 | 746 |
| 779 void ExpandableContainerView::ToggleDetailLevel() { | 747 void ExpandableContainerView::ToggleDetailLevel() { |
| 780 expanded_ = !expanded_; | 748 expanded_ = !expanded_; |
| 781 | 749 |
| 782 if (slide_animation_.IsShowing()) | 750 if (slide_animation_.IsShowing()) |
| 783 slide_animation_.Hide(); | 751 slide_animation_.Hide(); |
| 784 else | 752 else |
| 785 slide_animation_.Show(); | 753 slide_animation_.Show(); |
| 786 } | 754 } |
| 787 | 755 |
| 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 | 756 // static |
| 795 ExtensionInstallPrompt::ShowDialogCallback | 757 ExtensionInstallPrompt::ShowDialogCallback |
| 796 ExtensionInstallPrompt::GetViewsShowDialogCallback() { | 758 ExtensionInstallPrompt::GetViewsShowDialogCallback() { |
| 797 return base::Bind(&ShowExtensionInstallDialogImpl); | 759 return base::Bind(&ShowExtensionInstallDialogImpl); |
| 798 } | 760 } |
| OLD | NEW |