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

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

Issue 2758323002: Broke out layout metric information from ViewsDelegate to LayoutProvider (Closed)
Patch Set: Fix warning which causes one of the bots to fail Created 3 years, 8 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
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 "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>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/i18n/rtl.h" 16 #include "base/i18n/rtl.h"
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/metrics/histogram_macros.h" 18 #include "base/metrics/histogram_macros.h"
19 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "chrome/app/vector_icons/vector_icons.h" 21 #include "chrome/app/vector_icons/vector_icons.h"
22 #include "chrome/browser/browser_process.h" 22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h" 23 #include "chrome/browser/extensions/api/experience_sampling_private/experience_s ampling.h"
24 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" 24 #include "chrome/browser/extensions/extension_install_prompt_show_params.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/ui/browser.h" 26 #include "chrome/browser/ui/browser.h"
27 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 27 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
28 #include "chrome/browser/ui/views/harmony/chrome_layout_delegate.h"
28 #include "chrome/browser/ui/views/harmony/chrome_typography.h" 29 #include "chrome/browser/ui/views/harmony/chrome_typography.h"
29 #include "chrome/browser/ui/views/harmony/layout_delegate.h"
30 #include "chrome/common/extensions/extension_constants.h" 30 #include "chrome/common/extensions/extension_constants.h"
31 #include "chrome/grit/generated_resources.h" 31 #include "chrome/grit/generated_resources.h"
32 #include "components/constrained_window/constrained_window_views.h" 32 #include "components/constrained_window/constrained_window_views.h"
33 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/page_navigator.h" 34 #include "content/public/browser/page_navigator.h"
35 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
36 #include "extensions/common/extension.h" 36 #include "extensions/common/extension.h"
37 #include "extensions/common/extension_urls.h" 37 #include "extensions/common/extension_urls.h"
38 #include "ui/base/l10n/l10n_util.h" 38 #include "ui/base/l10n/l10n_util.h"
39 #include "ui/base/resource/resource_bundle.h" 39 #include "ui/base/resource/resource_bundle.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Width of the left column for external install prompts. The text is long in 79 // Width of the left column for external install prompts. The text is long in
80 // this case, so make it wider than normal. 80 // this case, so make it wider than normal.
81 constexpr int kExternalInstallLeftColumnWidth = 350; 81 constexpr int kExternalInstallLeftColumnWidth = 350;
82 82
83 // Get the appropriate indentation for an item if its parent is using bullet 83 // Get the appropriate indentation for an item if its parent is using bullet
84 // points. If the parent is using bullets for its items, then a padding of one 84 // points. If the parent is using bullets for its items, then a padding of one
85 // unit will make the child item (which has no bullet) look like a sibling of 85 // unit will make the child item (which has no bullet) look like a sibling of
86 // its parent. Therefore increase the indentation by one more unit to show that 86 // its parent. Therefore increase the indentation by one more unit to show that
87 // it is in fact a child item (with no missing bullet) and not a sibling. 87 // it is in fact a child item (with no missing bullet) and not a sibling.
88 int GetLeftPaddingForBulletedItems(bool parent_bulleted) { 88 int GetLeftPaddingForBulletedItems(bool parent_bulleted) {
89 return LayoutDelegate::Get()->GetMetric( 89 return ChromeLayoutDelegate::Get()->GetDistanceMetric(
90 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING) * 90 ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL) *
91 (parent_bulleted ? 2 : 1); 91 (parent_bulleted ? 2 : 1);
92 } 92 }
93 93
94 // Time delay before the install button is enabled after initial display. 94 // Time delay before the install button is enabled after initial display.
95 int g_install_delay_in_ms = 500; 95 int g_install_delay_in_ms = 500;
96 96
97 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) { 97 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) {
98 views::View* parent = static_cast<views::View*>(data); 98 views::View* parent = static_cast<views::View*>(data);
99 views::ImageView* image_view = new views::ImageView(); 99 views::ImageView* image_view = new views::ImageView();
100 image_view->SetImage(*skia_image); 100 image_view->SetImage(*skia_image);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 241
242 if (prompt_->has_webstore_data()) { 242 if (prompt_->has_webstore_data()) {
243 layout->StartRow(0, column_set_id); 243 layout->StartRow(0, column_set_id);
244 views::View* rating = new views::View(); 244 views::View* rating = new views::View();
245 rating->SetLayoutManager(new views::BoxLayout( 245 rating->SetLayoutManager(new views::BoxLayout(
246 views::BoxLayout::kHorizontal, 0, 0, 0)); 246 views::BoxLayout::kHorizontal, 0, 0, 0));
247 layout->AddView(rating); 247 layout->AddView(rating);
248 prompt_->AppendRatingStars(AddResourceIcon, rating); 248 prompt_->AppendRatingStars(AddResourceIcon, rating);
249 249
250 int rating_text_context, user_count_text_context; 250 int rating_text_context, user_count_text_context;
251 if (LayoutDelegate::Get()->IsHarmonyMode()) { 251 if (ChromeLayoutDelegate::Get()->IsHarmonyMode()) {
252 rating_text_context = CONTEXT_BODY_TEXT_LARGE; 252 rating_text_context = CONTEXT_BODY_TEXT_LARGE;
253 user_count_text_context = CONTEXT_BODY_TEXT_SMALL; 253 user_count_text_context = CONTEXT_BODY_TEXT_SMALL;
254 } else { 254 } else {
255 rating_text_context = user_count_text_context = CONTEXT_DEPRECATED_SMALL; 255 rating_text_context = user_count_text_context = CONTEXT_DEPRECATED_SMALL;
256 } 256 }
257 views::Label* rating_count = 257 views::Label* rating_count =
258 new views::Label(prompt_->GetRatingCount(), rating_text_context, 258 new views::Label(prompt_->GetRatingCount(), rating_text_context,
259 views::style::STYLE_PRIMARY); 259 views::style::STYLE_PRIMARY);
260 // Add some space between the stars and the rating count. 260 // Add some space between the stars and the rating count.
261 rating_count->SetBorder(views::CreateEmptyBorder(0, 2, 0, 0)); 261 rating_count->SetBorder(views::CreateEmptyBorder(0, 2, 0, 0));
262 rating->AddChildView(rating_count); 262 rating->AddChildView(rating_count);
263 263
264 layout->StartRow(0, column_set_id); 264 layout->StartRow(0, column_set_id);
265 views::Label* user_count = new views::Label( 265 views::Label* user_count = new views::Label(
266 prompt_->GetUserCount(), user_count_text_context, STYLE_SECONDARY); 266 prompt_->GetUserCount(), user_count_text_context, STYLE_SECONDARY);
267 user_count->SetAutoColorReadabilityEnabled(false); 267 user_count->SetAutoColorReadabilityEnabled(false);
268 user_count->SetEnabledColor(SK_ColorGRAY); 268 user_count->SetEnabledColor(SK_ColorGRAY);
269 layout->AddView(user_count); 269 layout->AddView(user_count);
270 } 270 }
271 271
272 LayoutDelegate* layout_delegate = LayoutDelegate::Get(); 272 ChromeLayoutDelegate* layout_delegate = ChromeLayoutDelegate::Get();
273 const int vertical_padding = layout_delegate->GetMetric( 273 const int vertical_padding = layout_delegate->GetDistanceMetric(
274 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); 274 ChromeDistanceMetric::RELATED_CONTROL_VERTICAL);
275 if (prompt_->ShouldShowPermissions()) { 275 if (prompt_->ShouldShowPermissions()) {
276 layout->AddPaddingRow(0, vertical_padding); 276 layout->AddPaddingRow(0, vertical_padding);
277 layout->StartRow(0, column_set_id); 277 layout->StartRow(0, column_set_id);
278 layout->AddView(new views::Separator(), 3, 1, views::GridLayout::FILL, 278 layout->AddView(new views::Separator(), 3, 1, views::GridLayout::FILL,
279 views::GridLayout::FILL); 279 views::GridLayout::FILL);
280 } 280 }
281 281
282 const int content_width = 282 const int content_width = left_column_width +
283 left_column_width + 283 layout_delegate->GetDistanceMetric(
284 layout_delegate->GetMetric(LayoutDelegate::Metric::PANEL_CONTENT_MARGIN) + 284 ChromeDistanceMetric::PANEL_CONTENT_MARGIN) +
285 kIconSize; 285 kIconSize;
286 286
287 // Create the scrollable view which will contain the permissions and retained 287 // Create the scrollable view which will contain the permissions and retained
288 // files/devices. It will span the full content width. 288 // files/devices. It will span the full content width.
289 CustomScrollableView* scrollable = new CustomScrollableView(); 289 CustomScrollableView* scrollable = new CustomScrollableView();
290 views::GridLayout* scroll_layout = new views::GridLayout(scrollable); 290 views::GridLayout* scroll_layout = new views::GridLayout(scrollable);
291 scrollable->SetLayoutManager(scroll_layout); 291 scrollable->SetLayoutManager(scroll_layout);
292 292
293 views::ColumnSet* scrollable_column_set = 293 views::ColumnSet* scrollable_column_set =
294 scroll_layout->AddColumnSet(column_set_id); 294 scroll_layout->AddColumnSet(column_set_id);
295 295
296 scrollable_column_set->AddColumn( 296 scrollable_column_set->AddColumn(
297 views::GridLayout::LEADING, views::GridLayout::LEADING, 297 views::GridLayout::LEADING, views::GridLayout::LEADING,
298 0, // no resizing 298 0, // no resizing
299 views::GridLayout::USE_PREF, content_width, content_width); 299 views::GridLayout::USE_PREF, content_width, content_width);
300 300
301 // Pad to the very right of the dialog, so the scrollbar will be on the edge. 301 // Pad to the very right of the dialog, so the scrollbar will be on the edge.
302 const int button_margin = 302 const int button_margin = layout_delegate->GetDistanceMetric(
303 layout_delegate->GetMetric(LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); 303 ChromeDistanceMetric::DIALOG_BUTTON_MARGIN);
304 scrollable_column_set->AddPaddingColumn(0, button_margin); 304 scrollable_column_set->AddPaddingColumn(0, button_margin);
305 305
306 layout->StartRow(0, column_set_id); 306 layout->StartRow(0, column_set_id);
307 scroll_view_ = new views::ScrollView(); 307 scroll_view_ = new views::ScrollView();
308 scroll_view_->set_hide_horizontal_scrollbar(true); 308 scroll_view_->set_hide_horizontal_scrollbar(true);
309 scroll_view_->SetContents(scrollable); 309 scroll_view_->SetContents(scrollable);
310 layout->AddView(scroll_view_, 4, 1); 310 layout->AddView(scroll_view_, 4, 1);
311 311
312 if (prompt_->ShouldShowPermissions()) { 312 if (prompt_->ShouldShowPermissions()) {
313 bool has_permissions = 313 bool has_permissions =
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 394
395 bool ExtensionInstallDialogView::AddPermissions( 395 bool ExtensionInstallDialogView::AddPermissions(
396 views::GridLayout* layout, 396 views::GridLayout* layout,
397 ui::ResourceBundle& rb, 397 ui::ResourceBundle& rb,
398 int column_set_id, 398 int column_set_id,
399 int left_column_width, 399 int left_column_width,
400 ExtensionInstallPrompt::PermissionsType perm_type) { 400 ExtensionInstallPrompt::PermissionsType perm_type) {
401 if (prompt_->GetPermissionCount(perm_type) == 0) 401 if (prompt_->GetPermissionCount(perm_type) == 0)
402 return false; 402 return false;
403 403
404 const int vertical_padding = LayoutDelegate::Get()->GetMetric( 404 const int vertical_padding = ChromeLayoutDelegate::Get()->GetDistanceMetric(
405 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); 405 ChromeDistanceMetric::RELATED_CONTROL_VERTICAL);
406 layout->AddPaddingRow(0, vertical_padding); 406 layout->AddPaddingRow(0, vertical_padding);
407 407
408 layout->StartRow(0, column_set_id); 408 layout->StartRow(0, column_set_id);
409 views::Label* permissions_header = 409 views::Label* permissions_header =
410 new views::Label(prompt_->GetPermissionsHeading(perm_type)); 410 new views::Label(prompt_->GetPermissionsHeading(perm_type));
411 permissions_header->SetMultiLine(true); 411 permissions_header->SetMultiLine(true);
412 permissions_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); 412 permissions_header->SetHorizontalAlignment(gfx::ALIGN_LEFT);
413 permissions_header->SizeToFit(left_column_width); 413 permissions_header->SizeToFit(left_column_width);
414 layout->AddView(permissions_header); 414 layout->AddView(permissions_header);
415 415
(...skipping 19 matching lines...) Expand all
435 layout->AddView(details_container); 435 layout->AddView(details_container);
436 } 436 }
437 } 437 }
438 return true; 438 return true;
439 } 439 }
440 440
441 views::GridLayout* ExtensionInstallDialogView::CreateLayout( 441 views::GridLayout* ExtensionInstallDialogView::CreateLayout(
442 int left_column_width, 442 int left_column_width,
443 int column_set_id) { 443 int column_set_id) {
444 container_ = new views::View(); 444 container_ = new views::View();
445 LayoutDelegate* layout_delegate = LayoutDelegate::Get(); 445 ChromeLayoutDelegate* layout_delegate = ChromeLayoutDelegate::Get();
446 const int horizontal_margin = 446 const int horizontal_margin = layout_delegate->GetDistanceMetric(
447 layout_delegate->GetMetric(LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); 447 ChromeDistanceMetric::DIALOG_BUTTON_MARGIN);
448 const int bottom_margin = 448 const int bottom_margin = layout_delegate->GetDistanceMetric(
449 layout_delegate->GetMetric(LayoutDelegate::Metric::PANEL_CONTENT_MARGIN); 449 ChromeDistanceMetric::PANEL_CONTENT_MARGIN);
450 450
451 // This is views::GridLayout::CreatePanel(), but without a top or right 451 // This is views::GridLayout::CreatePanel(), but without a top or right
452 // margin. The empty dialog title will then become the top margin, and a 452 // margin. The empty dialog title will then become the top margin, and a
453 // padding column will be manually added to handle a right margin. This is 453 // padding column will be manually added to handle a right margin. This is
454 // done so that the extension icon can be shown on the right of the dialog 454 // done so that the extension icon can be shown on the right of the dialog
455 // title, but on the same y-axis, and the scroll view used to contain other 455 // title, but on the same y-axis, and the scroll view used to contain other
456 // content can have its scrollbar aligned with the right edge of the dialog. 456 // content can have its scrollbar aligned with the right edge of the dialog.
457 views::GridLayout* layout = new views::GridLayout(container_); 457 views::GridLayout* layout = new views::GridLayout(container_);
458 layout->SetInsets(0, horizontal_margin, bottom_margin, 0); 458 layout->SetInsets(0, horizontal_margin, bottom_margin, 0);
459 container_->SetLayoutManager(layout); 459 container_->SetLayoutManager(layout);
460 AddChildView(container_); 460 AddChildView(container_);
461 461
462 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); 462 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
463 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 463 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING,
464 0, // no resizing 464 0, // no resizing
465 views::GridLayout::USE_PREF, 465 views::GridLayout::USE_PREF,
466 0, // no fixed width 466 0, // no fixed width
467 left_column_width); 467 left_column_width);
468 column_set->AddPaddingColumn( 468 column_set->AddPaddingColumn(
469 0, layout_delegate->GetMetric( 469 0, layout_delegate->GetDistanceMetric(
470 LayoutDelegate::Metric::UNRELATED_CONTROL_HORIZONTAL_SPACING)); 470 ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL));
471 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, 471 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
472 0, // no resizing 472 0, // no resizing
473 views::GridLayout::USE_PREF, 473 views::GridLayout::USE_PREF,
474 0, // no fixed width 474 0, // no fixed width
475 kIconSize); 475 kIconSize);
476 column_set->AddPaddingColumn(0, horizontal_margin); 476 column_set->AddPaddingColumn(0, horizontal_margin);
477 477
478 layout->StartRow(0, column_set_id); 478 layout->StartRow(0, column_set_id);
479 views::Label* title = new views::Label(prompt_->GetDialogTitle(), 479 views::Label* title = new views::Label(prompt_->GetDialogTitle(),
480 views::style::CONTEXT_DIALOG_TITLE); 480 views::style::CONTEXT_DIALOG_TITLE);
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 column_set->AddPaddingColumn(0, padding); 647 column_set->AddPaddingColumn(0, padding);
648 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 648 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING,
649 0, views::GridLayout::FIXED, horizontal_space - padding, 649 0, views::GridLayout::FIXED, horizontal_space - padding,
650 0); 650 0);
651 } 651 }
652 652
653 void ExpandableContainerView::DetailsView::AddDetail( 653 void ExpandableContainerView::DetailsView::AddDetail(
654 const base::string16& detail) { 654 const base::string16& detail) {
655 layout_->StartRowWithPadding( 655 layout_->StartRowWithPadding(
656 0, 0, 0, 656 0, 0, 0,
657 LayoutDelegate::Get()->GetMetric( 657 ChromeLayoutDelegate::Get()->GetDistanceMetric(
658 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING_SMALL)); 658 ChromeDistanceMetric::RELATED_CONTROL_VERTICAL_SMALL));
659 views::Label* detail_label = 659 views::Label* detail_label =
660 new views::Label(PrepareForDisplay(detail, false)); 660 new views::Label(PrepareForDisplay(detail, false));
661 detail_label->SetMultiLine(true); 661 detail_label->SetMultiLine(true);
662 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 662 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
663 layout_->AddView(detail_label); 663 layout_->AddView(detail_label);
664 } 664 }
665 665
666 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const { 666 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const {
667 gfx::Size size = views::View::GetPreferredSize(); 667 gfx::Size size = views::View::GetPreferredSize();
668 return gfx::Size(size.width(), size.height() * state_); 668 return gfx::Size(size.width(), size.height() * state_);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 gfx::ImageSkia icon = gfx::CreateVectorIcon( 790 gfx::ImageSkia icon = gfx::CreateVectorIcon(
791 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey); 791 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey);
792 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon); 792 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon);
793 } 793 }
794 794
795 // static 795 // static
796 ExtensionInstallPrompt::ShowDialogCallback 796 ExtensionInstallPrompt::ShowDialogCallback
797 ExtensionInstallPrompt::GetViewsShowDialogCallback() { 797 ExtensionInstallPrompt::GetViewsShowDialogCallback() {
798 return base::Bind(&ShowExtensionInstallDialogImpl); 798 return base::Bind(&ShowExtensionInstallDialogImpl);
799 } 799 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698