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 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 detail_label->SetMultiLine(true); | 658 detail_label->SetMultiLine(true); |
| 659 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 659 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 660 layout_->AddView(detail_label); | 660 layout_->AddView(detail_label); |
| 661 } | 661 } |
| 662 | 662 |
| 663 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const { | 663 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const { |
| 664 gfx::Size size = views::View::GetPreferredSize(); | 664 gfx::Size size = views::View::GetPreferredSize(); |
| 665 return gfx::Size(size.width(), size.height() * state_); | 665 return gfx::Size(size.width(), size.height() * state_); |
| 666 } | 666 } |
| 667 | 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 | |
| 668 void ExpandableContainerView::DetailsView::AnimateToState(double state) { | 678 void ExpandableContainerView::DetailsView::AnimateToState(double state) { |
| 669 state_ = state; | 679 state_ = state; |
| 670 PreferredSizeChanged(); | 680 PreferredSizeChanged(); |
| 671 SchedulePaint(); | 681 SchedulePaint(); |
| 672 } | 682 } |
| 673 | 683 |
| 674 // ExpandableContainerView ----------------------------------------------------- | 684 // ExpandableContainerView ----------------------------------------------------- |
| 675 | 685 |
| 676 ExpandableContainerView::ExpandableContainerView( | 686 ExpandableContainerView::ExpandableContainerView( |
| 677 const PermissionDetails& details, | 687 const PermissionDetails& details, |
| 678 int horizontal_space, | 688 int horizontal_space, |
| 679 bool parent_bulleted) | 689 bool parent_bulleted) |
| 680 : details_view_(NULL), | 690 : details_view_(NULL), |
| 681 slide_animation_(this), | 691 slide_animation_(this), |
| 682 more_details_(NULL), | 692 more_details_(NULL), |
| 683 arrow_toggle_(NULL), | |
| 684 expanded_(false) { | 693 expanded_(false) { |
| 685 views::GridLayout* layout = new views::GridLayout(this); | 694 views::BoxLayout* layout = |
| 695 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | |
| 696 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | |
|
Devlin
2017/04/25 22:11:50
This is the default, isn't it?
Elly Fong-Jones
2017/04/26 15:24:33
So it is, well spotted.
| |
| 697 layout->set_cross_axis_alignment( | |
| 698 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | |
| 686 SetLayoutManager(layout); | 699 SetLayoutManager(layout); |
| 687 int column_set_id = 0; | |
| 688 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); | |
| 689 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, | |
| 690 0, views::GridLayout::USE_PREF, 0, 0); | |
| 691 | 700 |
| 692 if (details.empty()) | 701 if (details.empty()) |
| 693 return; | 702 return; |
| 694 | 703 |
| 695 details_view_ = new DetailsView(horizontal_space, parent_bulleted); | 704 details_view_ = new DetailsView(horizontal_space, parent_bulleted); |
| 696 | |
| 697 layout->StartRow(0, column_set_id); | |
| 698 layout->AddView(details_view_); | |
| 699 | |
| 700 for (size_t i = 0; i < details.size(); ++i) | 705 for (size_t i = 0; i < details.size(); ++i) |
| 701 details_view_->AddDetail(details[i]); | 706 details_view_->AddDetail(details[i]); |
| 707 AddChildView(details_view_); | |
| 702 | 708 |
| 703 // Make sure the link width column is as wide as needed for both Show and | 709 more_details_ = |
| 704 // Hide details, so that the arrow doesn't shift horizontally when we toggle. | 710 new views::Link(l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); |
| 705 views::Link* link = new views::Link( | |
| 706 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS)); | |
| 707 int link_col_width = link->GetPreferredSize().width(); | |
| 708 link->SetText(l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); | |
| 709 link_col_width = std::max(link_col_width, link->GetPreferredSize().width()); | |
| 710 | |
| 711 column_set = layout->AddColumnSet(++column_set_id); | |
| 712 // Padding to the left of the More Details column. | |
| 713 column_set->AddPaddingColumn(0, | |
| 714 GetLeftPaddingForBulletedItems(parent_bulleted)); | |
| 715 // The More Details column. | |
| 716 column_set->AddColumn(views::GridLayout::LEADING, | |
| 717 views::GridLayout::LEADING, | |
| 718 0, | |
| 719 views::GridLayout::FIXED, | |
| 720 link_col_width, | |
| 721 link_col_width); | |
| 722 // The Up/Down arrow column. | |
| 723 column_set->AddColumn(views::GridLayout::LEADING, | |
| 724 views::GridLayout::TRAILING, | |
| 725 0, | |
| 726 views::GridLayout::USE_PREF, | |
| 727 0, | |
| 728 0); | |
| 729 | |
| 730 // Add the More Details link. | |
| 731 layout->StartRow(0, column_set_id); | |
| 732 more_details_ = link; | |
| 733 more_details_->set_listener(this); | 711 more_details_->set_listener(this); |
| 734 more_details_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 712 more_details_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 735 layout->AddView(more_details_); | 713 AddChildView(more_details_); |
| 736 | |
| 737 // Add the arrow after the More Details link. | |
| 738 arrow_toggle_ = new views::ImageButton(this); | |
| 739 UpdateArrowToggle(false); | |
| 740 layout->AddView(arrow_toggle_); | |
| 741 } | 714 } |
| 742 | 715 |
| 743 ExpandableContainerView::~ExpandableContainerView() { | 716 ExpandableContainerView::~ExpandableContainerView() { |
| 744 } | 717 } |
| 745 | 718 |
| 746 void ExpandableContainerView::ButtonPressed( | 719 void ExpandableContainerView::ButtonPressed( |
| 747 views::Button* sender, const ui::Event& event) { | 720 views::Button* sender, const ui::Event& event) { |
| 748 ToggleDetailLevel(); | 721 ToggleDetailLevel(); |
| 749 } | 722 } |
| 750 | 723 |
| 751 void ExpandableContainerView::LinkClicked( | 724 void ExpandableContainerView::LinkClicked( |
| 752 views::Link* source, int event_flags) { | 725 views::Link* source, int event_flags) { |
| 753 ToggleDetailLevel(); | 726 ToggleDetailLevel(); |
| 754 } | 727 } |
| 755 | 728 |
| 756 void ExpandableContainerView::AnimationProgressed( | 729 void ExpandableContainerView::AnimationProgressed( |
| 757 const gfx::Animation* animation) { | 730 const gfx::Animation* animation) { |
| 758 DCHECK_EQ(&slide_animation_, animation); | 731 DCHECK_EQ(&slide_animation_, animation); |
| 759 if (details_view_) | 732 if (details_view_) |
| 760 details_view_->AnimateToState(animation->GetCurrentValue()); | 733 details_view_->AnimateToState(animation->GetCurrentValue()); |
| 761 } | 734 } |
| 762 | 735 |
| 763 void ExpandableContainerView::AnimationEnded(const gfx::Animation* animation) { | 736 void ExpandableContainerView::AnimationEnded(const gfx::Animation* animation) { |
| 764 if (arrow_toggle_) | |
| 765 UpdateArrowToggle(animation->GetCurrentValue() != 0.0); | |
| 766 if (more_details_) { | 737 if (more_details_) { |
| 767 more_details_->SetText(expanded_ ? | 738 more_details_->SetText(expanded_ ? |
| 768 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS) : | 739 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS) : |
| 769 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); | 740 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); |
| 770 } | 741 } |
| 771 } | 742 } |
| 772 | 743 |
| 773 void ExpandableContainerView::ChildPreferredSizeChanged(views::View* child) { | 744 void ExpandableContainerView::ChildPreferredSizeChanged(views::View* child) { |
| 774 PreferredSizeChanged(); | 745 PreferredSizeChanged(); |
| 775 } | 746 } |
| 776 | 747 |
| 777 void ExpandableContainerView::ToggleDetailLevel() { | 748 void ExpandableContainerView::ToggleDetailLevel() { |
| 778 expanded_ = !expanded_; | 749 expanded_ = !expanded_; |
| 779 | 750 |
| 780 if (slide_animation_.IsShowing()) | 751 if (slide_animation_.IsShowing()) |
| 781 slide_animation_.Hide(); | 752 slide_animation_.Hide(); |
| 782 else | 753 else |
| 783 slide_animation_.Show(); | 754 slide_animation_.Show(); |
| 784 } | 755 } |
| 785 | 756 |
| 786 void ExpandableContainerView::UpdateArrowToggle(bool expanded) { | |
| 787 gfx::ImageSkia icon = gfx::CreateVectorIcon( | |
| 788 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey); | |
| 789 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon); | |
| 790 } | |
| 791 | |
| 792 // static | 757 // static |
| 793 ExtensionInstallPrompt::ShowDialogCallback | 758 ExtensionInstallPrompt::ShowDialogCallback |
| 794 ExtensionInstallPrompt::GetViewsShowDialogCallback() { | 759 ExtensionInstallPrompt::GetViewsShowDialogCallback() { |
| 795 return base::Bind(&ShowExtensionInstallDialogImpl); | 760 return base::Bind(&ShowExtensionInstallDialogImpl); |
| 796 } | 761 } |
| OLD | NEW |