Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/ui/views/extensions/extension_install_dialog_view.cc

Issue 23890009: Polish for Extension Install Dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address nits Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <vector> 5 #include <vector>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/i18n/rtl.h" 10 #include "base/i18n/rtl.h"
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 156
157 // The container view for the scroll view. 157 // The container view for the scroll view.
158 CustomScrollableView* scrollable_; 158 CustomScrollableView* scrollable_;
159 159
160 // The preferred size of the dialog. 160 // The preferred size of the dialog.
161 gfx::Size dialog_size_; 161 gfx::Size dialog_size_;
162 162
163 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogView); 163 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogView);
164 }; 164 };
165 165
166 // A simple view that prepends a view with a bullet with the help of a grid
167 // layout.
168 class BulletedView : public views::View {
169 public:
170 explicit BulletedView(views::View* view);
171 private:
172 DISALLOW_COPY_AND_ASSIGN(BulletedView);
173 };
174
175 BulletedView::BulletedView(views::View* view) {
176 views::GridLayout* layout = new views::GridLayout(this);
177 SetLayoutManager(layout);
178 views::ColumnSet* column_set = layout->AddColumnSet(0);
179 column_set->AddColumn(views::GridLayout::LEADING,
180 views::GridLayout::LEADING,
181 0,
182 views::GridLayout::USE_PREF,
183 0, // no fixed width
184 0);
185 column_set->AddColumn(views::GridLayout::LEADING,
186 views::GridLayout::LEADING,
187 0,
188 views::GridLayout::USE_PREF,
189 0, // no fixed width
190 0);
191 layout->StartRow(0, 0);
192 layout->AddView(new views::Label(PrepareForDisplay(string16(), true)));
193 layout->AddView(view);
194 }
195
166 // A view to display text with an expandable details section. 196 // A view to display text with an expandable details section.
167 class ExpandableContainerView : public views::View, 197 class ExpandableContainerView : public views::View,
168 public views::ButtonListener, 198 public views::ButtonListener,
169 public views::LinkListener, 199 public views::LinkListener,
170 public ui::AnimationDelegate { 200 public ui::AnimationDelegate {
171 public: 201 public:
172 ExpandableContainerView(ExtensionInstallDialogView* owner, 202 ExpandableContainerView(ExtensionInstallDialogView* owner,
173 const string16& description, 203 const string16& description,
174 const PermissionDetails& details, 204 const PermissionDetails& details,
175 int horizontal_space, 205 int horizontal_space,
176 bool show_bullets); 206 bool parent_bulleted);
177 virtual ~ExpandableContainerView(); 207 virtual ~ExpandableContainerView();
178 208
179 // views::View: 209 // views::View:
180 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE; 210 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
181 211
182 // views::ButtonListener: 212 // views::ButtonListener:
183 virtual void ButtonPressed(views::Button* sender, 213 virtual void ButtonPressed(views::Button* sender,
184 const ui::Event& event) OVERRIDE; 214 const ui::Event& event) OVERRIDE;
185 215
186 // views::LinkListener: 216 // views::LinkListener:
187 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; 217 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
188 218
189 // ui::AnimationDelegate: 219 // ui::AnimationDelegate:
190 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; 220 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
191 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; 221 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
192 222
193 private: 223 private:
194 // A view which displays all the details of an IssueAdviceInfoEntry. 224 // A view which displays all the details of an IssueAdviceInfoEntry.
195 class DetailsView : public views::View { 225 class DetailsView : public views::View {
196 public: 226 public:
197 explicit DetailsView(int horizontal_space, bool show_bullets); 227 explicit DetailsView(int horizontal_space, bool parent_bulleted);
198 virtual ~DetailsView() {} 228 virtual ~DetailsView() {}
199 229
200 // views::View: 230 // views::View:
201 virtual gfx::Size GetPreferredSize() OVERRIDE; 231 virtual gfx::Size GetPreferredSize() OVERRIDE;
202 232
203 void AddDetail(const string16& detail); 233 void AddDetail(const string16& detail);
204 234
205 // Animates this to be a height proportional to |state|. 235 // Animates this to be a height proportional to |state|.
206 void AnimateToState(double state); 236 void AnimateToState(double state);
207 237
208 private: 238 private:
209 views::GridLayout* layout_; 239 views::GridLayout* layout_;
210 double state_; 240 double state_;
211 241
212 // Whether to show bullets in front of each item in the details. 242 // Whether the parent item is showing bullets. This will determine how much
213 bool show_bullets_; 243 // extra indentation is needed.
244 bool parent_bulleted_;
214 245
215 DISALLOW_COPY_AND_ASSIGN(DetailsView); 246 DISALLOW_COPY_AND_ASSIGN(DetailsView);
216 }; 247 };
217 248
218 // Expand/Collapse the detail section for this ExpandableContainerView. 249 // Expand/Collapse the detail section for this ExpandableContainerView.
219 void ToggleDetailLevel(); 250 void ToggleDetailLevel();
220 251
221 // The dialog that owns |this|. It's also an ancestor in the View hierarchy. 252 // The dialog that owns |this|. It's also an ancestor in the View hierarchy.
222 ExtensionInstallDialogView* owner_; 253 ExtensionInstallDialogView* owner_;
223 254
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 permissions_header = new views::Label(prompt.GetPermissionsHeading()); 505 permissions_header = new views::Label(prompt.GetPermissionsHeading());
475 } 506 }
476 permissions_header->SetMultiLine(true); 507 permissions_header->SetMultiLine(true);
477 permissions_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); 508 permissions_header->SetHorizontalAlignment(gfx::ALIGN_LEFT);
478 permissions_header->SizeToFit(left_column_width); 509 permissions_header->SizeToFit(left_column_width);
479 layout->AddView(permissions_header); 510 layout->AddView(permissions_header);
480 511
481 for (size_t i = 0; i < prompt.GetPermissionCount(); ++i) { 512 for (size_t i = 0; i < prompt.GetPermissionCount(); ++i) {
482 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 513 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
483 layout->StartRow(0, column_set_id); 514 layout->StartRow(0, column_set_id);
484 views::Label* permission_label = new views::Label(PrepareForDisplay( 515 views::Label* permission_label =
485 prompt.GetPermission(i), true)); 516 new views::Label(prompt.GetPermission(i));
486 permission_label->SetMultiLine(true); 517 permission_label->SetMultiLine(true);
487 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 518 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
488 permission_label->SizeToFit(left_column_width); 519 permission_label->SizeToFit(left_column_width);
489 layout->AddView(permission_label); 520 layout->AddView(new BulletedView(permission_label));
490 521
491 // If we have more details to provide, show them in collapsed form. 522 // If we have more details to provide, show them in collapsed form.
492 if (!prompt.GetPermissionsDetails(i).empty()) { 523 if (!prompt.GetPermissionsDetails(i).empty()) {
493 layout->StartRow(0, column_set_id); 524 layout->StartRow(0, column_set_id);
494 PermissionDetails details; 525 PermissionDetails details;
495 details.push_back( 526 details.push_back(
496 PrepareForDisplay(prompt.GetPermissionsDetails(i), false)); 527 PrepareForDisplay(prompt.GetPermissionsDetails(i), false));
497 ExpandableContainerView* details_container = 528 ExpandableContainerView* details_container =
498 new ExpandableContainerView( 529 new ExpandableContainerView(
499 this, string16(), details, left_column_width, false); 530 this, string16(), details, left_column_width, true);
500 layout->AddView(details_container); 531 layout->AddView(details_container);
501 } 532 }
502 } 533 }
503 } else { 534 } else {
504 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 535 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
505 layout->StartRow(0, column_set_id); 536 layout->StartRow(0, column_set_id);
506 views::Label* permission_label = new views::Label( 537 views::Label* permission_label = new views::Label(
507 l10n_util::GetStringUTF16(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS)); 538 l10n_util::GetStringUTF16(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS));
508 permission_label->SetMultiLine(true); 539 permission_label->SetMultiLine(true);
509 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 540 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 layout->StartRowWithPadding( 572 layout->StartRowWithPadding(
542 0, column_set_id, 573 0, column_set_id,
543 0, views::kRelatedControlVerticalSpacing); 574 0, views::kRelatedControlVerticalSpacing);
544 575
545 PermissionDetails details; 576 PermissionDetails details;
546 const IssueAdviceInfoEntry& entry = prompt.GetOAuthIssue(i); 577 const IssueAdviceInfoEntry& entry = prompt.GetOAuthIssue(i);
547 for (size_t x = 0; x < entry.details.size(); ++x) 578 for (size_t x = 0; x < entry.details.size(); ++x)
548 details.push_back(entry.details[x]); 579 details.push_back(entry.details[x]);
549 ExpandableContainerView* issue_advice_view = 580 ExpandableContainerView* issue_advice_view =
550 new ExpandableContainerView( 581 new ExpandableContainerView(
551 this, entry.description, details, space_for_oauth, false); 582 this, entry.description, details, space_for_oauth, true);
552 layout->AddView(issue_advice_view); 583 layout->AddView(issue_advice_view);
553 } 584 }
554 } 585 }
555 if (prompt.GetRetainedFileCount()) { 586 if (prompt.GetRetainedFileCount()) {
556 // Slide in under the permissions or OAuth, if there are any. If there are 587 // Slide in under the permissions or OAuth, if there are any. If there are
557 // either, the retained files prompt stretches all the way to the right of 588 // either, the retained files prompt stretches all the way to the right of
558 // the dialog. If there are no permissions or OAuth, the retained files 589 // the dialog. If there are no permissions or OAuth, the retained files
559 // prompt just takes up the left column. 590 // prompt just takes up the left column.
560 int space_for_files = left_column_width; 591 int space_for_files = left_column_width;
561 if (prompt.GetPermissionCount() || prompt.GetOAuthIssueCount()) { 592 if (prompt.GetPermissionCount() || prompt.GetOAuthIssueCount()) {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 701
671 // static 702 // static
672 ExtensionInstallPrompt::ShowDialogCallback 703 ExtensionInstallPrompt::ShowDialogCallback
673 ExtensionInstallPrompt::GetDefaultShowDialogCallback() { 704 ExtensionInstallPrompt::GetDefaultShowDialogCallback() {
674 return base::Bind(&ShowExtensionInstallDialogImpl); 705 return base::Bind(&ShowExtensionInstallDialogImpl);
675 } 706 }
676 707
677 // ExpandableContainerView::DetailsView ---------------------------------------- 708 // ExpandableContainerView::DetailsView ----------------------------------------
678 709
679 ExpandableContainerView::DetailsView::DetailsView(int horizontal_space, 710 ExpandableContainerView::DetailsView::DetailsView(int horizontal_space,
680 bool show_bullets) 711 bool parent_bulleted)
681 : layout_(new views::GridLayout(this)), 712 : layout_(new views::GridLayout(this)),
682 state_(0), 713 state_(0),
683 show_bullets_(show_bullets) { 714 parent_bulleted_(parent_bulleted) {
684 SetLayoutManager(layout_); 715 SetLayoutManager(layout_);
685 views::ColumnSet* column_set = layout_->AddColumnSet(0); 716 views::ColumnSet* column_set = layout_->AddColumnSet(0);
686 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); 717 // If the parent is using bullets for its items, then a padding of one unit
718 // will make the child item (which has no bullet) look like a sibling of its
719 // parent. Therefore increase the indentation by one more unit to show that it
720 // is in fact a child item (with no missing bullet) and not a sibling.
721 column_set->AddPaddingColumn(
722 0, views::kRelatedControlHorizontalSpacing * (parent_bulleted ? 2 : 1));
687 column_set->AddColumn(views::GridLayout::LEADING, 723 column_set->AddColumn(views::GridLayout::LEADING,
688 views::GridLayout::LEADING, 724 views::GridLayout::LEADING,
689 0, 725 0,
690 views::GridLayout::FIXED, 726 views::GridLayout::FIXED,
691 horizontal_space, 727 horizontal_space,
692 0); 728 0);
693 } 729 }
694 730
695 void ExpandableContainerView::DetailsView::AddDetail(const string16& detail) { 731 void ExpandableContainerView::DetailsView::AddDetail(const string16& detail) {
696 layout_->StartRowWithPadding(0, 0, 732 layout_->StartRowWithPadding(0, 0,
697 0, views::kRelatedControlSmallVerticalSpacing); 733 0, views::kRelatedControlSmallVerticalSpacing);
698 views::Label* detail_label = 734 views::Label* detail_label =
699 new views::Label(PrepareForDisplay(detail, show_bullets_)); 735 new views::Label(PrepareForDisplay(detail, false));
700 detail_label->SetMultiLine(true); 736 detail_label->SetMultiLine(true);
701 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 737 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
702 layout_->AddView(detail_label); 738 layout_->AddView(detail_label);
703 } 739 }
704 740
705 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() { 741 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() {
706 gfx::Size size = views::View::GetPreferredSize(); 742 gfx::Size size = views::View::GetPreferredSize();
707 return gfx::Size(size.width(), size.height() * state_); 743 return gfx::Size(size.width(), size.height() * state_);
708 } 744 }
709 745
710 void ExpandableContainerView::DetailsView::AnimateToState(double state) { 746 void ExpandableContainerView::DetailsView::AnimateToState(double state) {
711 state_ = state; 747 state_ = state;
712 PreferredSizeChanged(); 748 PreferredSizeChanged();
713 SchedulePaint(); 749 SchedulePaint();
714 } 750 }
715 751
716 // ExpandableContainerView ----------------------------------------------------- 752 // ExpandableContainerView -----------------------------------------------------
717 753
718 ExpandableContainerView::ExpandableContainerView( 754 ExpandableContainerView::ExpandableContainerView(
719 ExtensionInstallDialogView* owner, 755 ExtensionInstallDialogView* owner,
720 const string16& description, 756 const string16& description,
721 const PermissionDetails& details, 757 const PermissionDetails& details,
722 int horizontal_space, 758 int horizontal_space,
723 bool show_bullets) 759 bool parent_bulleted)
724 : owner_(owner), 760 : owner_(owner),
725 details_view_(NULL), 761 details_view_(NULL),
726 arrow_view_(NULL), 762 arrow_view_(NULL),
727 slide_animation_(this), 763 slide_animation_(this),
728 expanded_(false) { 764 expanded_(false) {
729 views::GridLayout* layout = new views::GridLayout(this); 765 views::GridLayout* layout = new views::GridLayout(this);
730 SetLayoutManager(layout); 766 SetLayoutManager(layout);
731 int column_set_id = 0; 767 int column_set_id = 0;
732 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); 768 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
733 column_set->AddColumn(views::GridLayout::LEADING, 769 column_set->AddColumn(views::GridLayout::LEADING,
734 views::GridLayout::LEADING, 770 views::GridLayout::LEADING,
735 0, 771 0,
736 views::GridLayout::USE_PREF, 772 views::GridLayout::USE_PREF,
737 0, 773 0,
738 0); 774 0);
739 if (!description.empty()) { 775 if (!description.empty()) {
740 layout->StartRow(0, column_set_id); 776 layout->StartRow(0, column_set_id);
741 777
742 views::Label* description_label = 778 views::Label* description_label = new views::Label(description);
743 new views::Label(PrepareForDisplay(description, true));
744 description_label->SetMultiLine(true); 779 description_label->SetMultiLine(true);
745 description_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 780 description_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
746 description_label->SizeToFit(horizontal_space); 781 description_label->SizeToFit(horizontal_space);
747 layout->AddView(description_label); 782 layout->AddView(new BulletedView(description_label));
748 } 783 }
749 784
750 if (details.empty()) 785 if (details.empty())
751 return; 786 return;
752 787
753 details_view_ = new DetailsView(horizontal_space, show_bullets); 788 details_view_ = new DetailsView(horizontal_space, parent_bulleted);
754 789
755 layout->StartRow(0, column_set_id); 790 layout->StartRow(0, column_set_id);
756 layout->AddView(details_view_); 791 layout->AddView(details_view_);
757 792
758 for (size_t i = 0; i < details.size(); ++i) 793 for (size_t i = 0; i < details.size(); ++i)
759 details_view_->AddDetail(details[i]); 794 details_view_->AddDetail(details[i]);
760 795
761 // Prepare the columns for the More Details row. 796 views::Link* link = new views::Link(
797 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS));
798
799 // Make sure the link width column is as wide as needed for both Show and
800 // Hide details, so that the arrow doesn't shift horizontally when we toggle.
801 int link_col_width =
802 views::kRelatedControlHorizontalSpacing +
803 std::max(link->font_list().GetStringWidth(
804 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS)),
805 link->font_list().GetStringWidth(
806 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)));
807
762 column_set = layout->AddColumnSet(++column_set_id); 808 column_set = layout->AddColumnSet(++column_set_id);
763 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); 809 // Padding to the left of the More Details column. If the parent is using
810 // bullets for its items, then a padding of one unit will make the child item
811 // (which has no bullet) look like a sibling of its parent. Therefore increase
812 // the indentation by one more unit to show that it is in fact a child item
813 // (with no missing bullet) and not a sibling.
814 column_set->AddPaddingColumn(
815 0, views::kRelatedControlHorizontalSpacing * (parent_bulleted ? 2 : 1));
816 // The More Details column.
764 column_set->AddColumn(views::GridLayout::LEADING, 817 column_set->AddColumn(views::GridLayout::LEADING,
765 views::GridLayout::LEADING, 818 views::GridLayout::LEADING,
766 0, 819 0,
767 views::GridLayout::USE_PREF, 820 views::GridLayout::FIXED,
768 0, 821 link_col_width,
769 0); 822 link_col_width);
770 column_set->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); 823 // The Up/Down arrow column.
771 column_set->AddColumn(views::GridLayout::LEADING, 824 column_set->AddColumn(views::GridLayout::LEADING,
772 views::GridLayout::LEADING, 825 views::GridLayout::LEADING,
773 0, 826 0,
774 views::GridLayout::USE_PREF, 827 views::GridLayout::USE_PREF,
775 0, 828 0,
776 0); 829 0);
777 column_set->AddColumn(views::GridLayout::LEADING,
778 views::GridLayout::LEADING,
779 0,
780 views::GridLayout::USE_PREF,
781 0,
782 0);
783 830
784 // Add the More Details link. 831 // Add the More Details link.
785 layout->StartRow(0, column_set_id); 832 layout->StartRow(0, column_set_id);
786 more_details_ = new views::Link( 833 more_details_ = link;
787 l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS));
788 more_details_->set_listener(this); 834 more_details_->set_listener(this);
789 more_details_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 835 more_details_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
790 layout->AddView(more_details_); 836 layout->AddView(more_details_);
791 837
792 // Add the arrow after the More Details link. 838 // Add the arrow after the More Details link.
793 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 839 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
794 arrow_toggle_ = new views::ImageButton(this); 840 arrow_toggle_ = new views::ImageButton(this);
795 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, 841 arrow_toggle_->SetImage(views::Button::STATE_NORMAL,
796 rb.GetImageSkiaNamed(IDR_DOWN_ARROW)); 842 rb.GetImageSkiaNamed(IDR_DOWN_ARROW));
797 layout->AddView(arrow_toggle_); 843 layout->AddView(arrow_toggle_);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 } 886 }
841 887
842 void ExpandableContainerView::ToggleDetailLevel() { 888 void ExpandableContainerView::ToggleDetailLevel() {
843 expanded_ = !expanded_; 889 expanded_ = !expanded_;
844 890
845 if (slide_animation_.IsShowing()) 891 if (slide_animation_.IsShowing())
846 slide_animation_.Hide(); 892 slide_animation_.Hide();
847 else 893 else
848 slide_animation_.Show(); 894 slide_animation_.Show();
849 } 895 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698