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

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: Final feedback addressed 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_provider.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 ChromeLayoutProvider::Get()->GetDistanceMetric(
90 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING) * 90 views::DISTANCE_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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // files/devices (if there are any; post-install-permissions prompt only). 229 // files/devices (if there are any; post-install-permissions prompt only).
230 int left_column_width = 230 int left_column_width =
231 (prompt_->ShouldShowPermissions() || prompt_->GetRetainedFileCount() > 0) 231 (prompt_->ShouldShowPermissions() || prompt_->GetRetainedFileCount() > 0)
232 ? kPermissionsLeftColumnWidth 232 ? kPermissionsLeftColumnWidth
233 : kNoPermissionsLeftColumnWidth; 233 : kNoPermissionsLeftColumnWidth;
234 if (is_external_install()) 234 if (is_external_install())
235 left_column_width = kExternalInstallLeftColumnWidth; 235 left_column_width = kExternalInstallLeftColumnWidth;
236 236
237 int column_set_id = 0; 237 int column_set_id = 0;
238 views::GridLayout* layout = CreateLayout(left_column_width, column_set_id); 238 views::GridLayout* layout = CreateLayout(left_column_width, column_set_id);
239 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
239 240
240 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 241 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
241 242
242 if (prompt_->has_webstore_data()) { 243 if (prompt_->has_webstore_data()) {
243 layout->StartRow(0, column_set_id); 244 layout->StartRow(0, column_set_id);
244 views::View* rating = new views::View(); 245 views::View* rating = new views::View();
245 rating->SetLayoutManager(new views::BoxLayout( 246 rating->SetLayoutManager(new views::BoxLayout(
246 views::BoxLayout::kHorizontal, 0, 0, 0)); 247 views::BoxLayout::kHorizontal, 0, 0, 0));
247 layout->AddView(rating); 248 layout->AddView(rating);
248 prompt_->AppendRatingStars(AddResourceIcon, rating); 249 prompt_->AppendRatingStars(AddResourceIcon, rating);
249 250
250 int rating_text_context, user_count_text_context; 251 int rating_text_context, user_count_text_context;
251 if (LayoutDelegate::Get()->IsHarmonyMode()) { 252 if (provider->IsHarmonyMode()) {
252 rating_text_context = CONTEXT_BODY_TEXT_LARGE; 253 rating_text_context = CONTEXT_BODY_TEXT_LARGE;
253 user_count_text_context = CONTEXT_BODY_TEXT_SMALL; 254 user_count_text_context = CONTEXT_BODY_TEXT_SMALL;
254 } else { 255 } else {
255 rating_text_context = user_count_text_context = CONTEXT_DEPRECATED_SMALL; 256 rating_text_context = user_count_text_context = CONTEXT_DEPRECATED_SMALL;
256 } 257 }
257 views::Label* rating_count = 258 views::Label* rating_count =
258 new views::Label(prompt_->GetRatingCount(), rating_text_context, 259 new views::Label(prompt_->GetRatingCount(), rating_text_context,
259 views::style::STYLE_PRIMARY); 260 views::style::STYLE_PRIMARY);
260 // Add some space between the stars and the rating count. 261 // Add some space between the stars and the rating count.
261 rating_count->SetBorder(views::CreateEmptyBorder(0, 2, 0, 0)); 262 rating_count->SetBorder(views::CreateEmptyBorder(0, 2, 0, 0));
262 rating->AddChildView(rating_count); 263 rating->AddChildView(rating_count);
263 264
264 layout->StartRow(0, column_set_id); 265 layout->StartRow(0, column_set_id);
265 views::Label* user_count = new views::Label( 266 views::Label* user_count = new views::Label(
266 prompt_->GetUserCount(), user_count_text_context, STYLE_SECONDARY); 267 prompt_->GetUserCount(), user_count_text_context, STYLE_SECONDARY);
267 user_count->SetAutoColorReadabilityEnabled(false); 268 user_count->SetAutoColorReadabilityEnabled(false);
268 user_count->SetEnabledColor(SK_ColorGRAY); 269 user_count->SetEnabledColor(SK_ColorGRAY);
269 layout->AddView(user_count); 270 layout->AddView(user_count);
270 } 271 }
271 272
272 LayoutDelegate* layout_delegate = LayoutDelegate::Get(); 273 const int vertical_padding =
273 const int vertical_padding = layout_delegate->GetMetric( 274 provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL);
274 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING);
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 =
283 left_column_width + 283 left_column_width +
284 layout_delegate->GetMetric(LayoutDelegate::Metric::PANEL_CONTENT_MARGIN) + 284 provider->GetDistanceMetric(DISTANCE_PANEL_CONTENT_MARGIN) + kIconSize;
285 kIconSize;
286 285
287 // Create the scrollable view which will contain the permissions and retained 286 // Create the scrollable view which will contain the permissions and retained
288 // files/devices. It will span the full content width. 287 // files/devices. It will span the full content width.
289 CustomScrollableView* scrollable = new CustomScrollableView(); 288 CustomScrollableView* scrollable = new CustomScrollableView();
290 views::GridLayout* scroll_layout = new views::GridLayout(scrollable); 289 views::GridLayout* scroll_layout = new views::GridLayout(scrollable);
291 scrollable->SetLayoutManager(scroll_layout); 290 scrollable->SetLayoutManager(scroll_layout);
292 291
293 views::ColumnSet* scrollable_column_set = 292 views::ColumnSet* scrollable_column_set =
294 scroll_layout->AddColumnSet(column_set_id); 293 scroll_layout->AddColumnSet(column_set_id);
295 294
296 scrollable_column_set->AddColumn( 295 scrollable_column_set->AddColumn(
297 views::GridLayout::LEADING, views::GridLayout::LEADING, 296 views::GridLayout::LEADING, views::GridLayout::LEADING,
298 0, // no resizing 297 0, // no resizing
299 views::GridLayout::USE_PREF, content_width, content_width); 298 views::GridLayout::USE_PREF, content_width, content_width);
300 299
301 // Pad to the very right of the dialog, so the scrollbar will be on the edge. 300 // Pad to the very right of the dialog, so the scrollbar will be on the edge.
302 const int button_margin = 301 const int button_margin =
303 layout_delegate->GetMetric(LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); 302 provider->GetDistanceMetric(DISTANCE_DIALOG_BUTTON_MARGIN);
304 scrollable_column_set->AddPaddingColumn(0, button_margin); 303 scrollable_column_set->AddPaddingColumn(0, button_margin);
305 304
306 layout->StartRow(0, column_set_id); 305 layout->StartRow(0, column_set_id);
307 scroll_view_ = new views::ScrollView(); 306 scroll_view_ = new views::ScrollView();
308 scroll_view_->set_hide_horizontal_scrollbar(true); 307 scroll_view_->set_hide_horizontal_scrollbar(true);
309 scroll_view_->SetContents(scrollable); 308 scroll_view_->SetContents(scrollable);
310 layout->AddView(scroll_view_, 4, 1); 309 layout->AddView(scroll_view_, 4, 1);
311 310
312 if (prompt_->ShouldShowPermissions()) { 311 if (prompt_->ShouldShowPermissions()) {
313 bool has_permissions = 312 bool has_permissions =
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 393
395 bool ExtensionInstallDialogView::AddPermissions( 394 bool ExtensionInstallDialogView::AddPermissions(
396 views::GridLayout* layout, 395 views::GridLayout* layout,
397 ui::ResourceBundle& rb, 396 ui::ResourceBundle& rb,
398 int column_set_id, 397 int column_set_id,
399 int left_column_width, 398 int left_column_width,
400 ExtensionInstallPrompt::PermissionsType perm_type) { 399 ExtensionInstallPrompt::PermissionsType perm_type) {
401 if (prompt_->GetPermissionCount(perm_type) == 0) 400 if (prompt_->GetPermissionCount(perm_type) == 0)
402 return false; 401 return false;
403 402
404 const int vertical_padding = LayoutDelegate::Get()->GetMetric( 403 const int vertical_padding = ChromeLayoutProvider::Get()->GetDistanceMetric(
405 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); 404 views::DISTANCE_RELATED_CONTROL_VERTICAL);
406 layout->AddPaddingRow(0, vertical_padding); 405 layout->AddPaddingRow(0, vertical_padding);
407 406
408 layout->StartRow(0, column_set_id); 407 layout->StartRow(0, column_set_id);
409 views::Label* permissions_header = 408 views::Label* permissions_header =
410 new views::Label(prompt_->GetPermissionsHeading(perm_type)); 409 new views::Label(prompt_->GetPermissionsHeading(perm_type));
411 permissions_header->SetMultiLine(true); 410 permissions_header->SetMultiLine(true);
412 permissions_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); 411 permissions_header->SetHorizontalAlignment(gfx::ALIGN_LEFT);
413 permissions_header->SizeToFit(left_column_width); 412 permissions_header->SizeToFit(left_column_width);
414 layout->AddView(permissions_header); 413 layout->AddView(permissions_header);
415 414
(...skipping 19 matching lines...) Expand all
435 layout->AddView(details_container); 434 layout->AddView(details_container);
436 } 435 }
437 } 436 }
438 return true; 437 return true;
439 } 438 }
440 439
441 views::GridLayout* ExtensionInstallDialogView::CreateLayout( 440 views::GridLayout* ExtensionInstallDialogView::CreateLayout(
442 int left_column_width, 441 int left_column_width,
443 int column_set_id) { 442 int column_set_id) {
444 container_ = new views::View(); 443 container_ = new views::View();
445 LayoutDelegate* layout_delegate = LayoutDelegate::Get(); 444 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
446 const int horizontal_margin = 445 const int horizontal_margin =
447 layout_delegate->GetMetric(LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); 446 provider->GetDistanceMetric(DISTANCE_DIALOG_BUTTON_MARGIN);
448 const int bottom_margin = 447 const int bottom_margin =
449 layout_delegate->GetMetric(LayoutDelegate::Metric::PANEL_CONTENT_MARGIN); 448 provider->GetDistanceMetric(DISTANCE_PANEL_CONTENT_MARGIN);
450 449
451 // This is views::GridLayout::CreatePanel(), but without a top or right 450 // 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 451 // 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 452 // 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 453 // 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 454 // 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. 455 // content can have its scrollbar aligned with the right edge of the dialog.
457 views::GridLayout* layout = new views::GridLayout(container_); 456 views::GridLayout* layout = new views::GridLayout(container_);
458 layout->SetInsets(0, horizontal_margin, bottom_margin, 0); 457 layout->SetInsets(0, horizontal_margin, bottom_margin, 0);
459 container_->SetLayoutManager(layout); 458 container_->SetLayoutManager(layout);
460 AddChildView(container_); 459 AddChildView(container_);
461 460
462 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); 461 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
463 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 462 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING,
464 0, // no resizing 463 0, // no resizing
465 views::GridLayout::USE_PREF, 464 views::GridLayout::USE_PREF,
466 0, // no fixed width 465 0, // no fixed width
467 left_column_width); 466 left_column_width);
468 column_set->AddPaddingColumn( 467 column_set->AddPaddingColumn(
469 0, layout_delegate->GetMetric( 468 0, provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL));
470 LayoutDelegate::Metric::UNRELATED_CONTROL_HORIZONTAL_SPACING));
471 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, 469 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
472 0, // no resizing 470 0, // no resizing
473 views::GridLayout::USE_PREF, 471 views::GridLayout::USE_PREF,
474 0, // no fixed width 472 0, // no fixed width
475 kIconSize); 473 kIconSize);
476 column_set->AddPaddingColumn(0, horizontal_margin); 474 column_set->AddPaddingColumn(0, horizontal_margin);
477 475
478 layout->StartRow(0, column_set_id); 476 layout->StartRow(0, column_set_id);
479 views::Label* title = new views::Label(prompt_->GetDialogTitle(), 477 views::Label* title = new views::Label(prompt_->GetDialogTitle(),
480 views::style::CONTEXT_DIALOG_TITLE); 478 views::style::CONTEXT_DIALOG_TITLE);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 views::ColumnSet* column_set = layout_->AddColumnSet(0); 643 views::ColumnSet* column_set = layout_->AddColumnSet(0);
646 const int padding = GetLeftPaddingForBulletedItems(parent_bulleted); 644 const int padding = GetLeftPaddingForBulletedItems(parent_bulleted);
647 column_set->AddPaddingColumn(0, padding); 645 column_set->AddPaddingColumn(0, padding);
648 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 646 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING,
649 0, views::GridLayout::FIXED, horizontal_space - padding, 647 0, views::GridLayout::FIXED, horizontal_space - padding,
650 0); 648 0);
651 } 649 }
652 650
653 void ExpandableContainerView::DetailsView::AddDetail( 651 void ExpandableContainerView::DetailsView::AddDetail(
654 const base::string16& detail) { 652 const base::string16& detail) {
655 layout_->StartRowWithPadding( 653 layout_->StartRowWithPadding(0, 0, 0,
656 0, 0, 0, 654 ChromeLayoutProvider::Get()->GetDistanceMetric(
657 LayoutDelegate::Get()->GetMetric( 655 DISTANCE_RELATED_CONTROL_VERTICAL_SMALL));
658 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING_SMALL));
659 views::Label* detail_label = 656 views::Label* detail_label =
660 new views::Label(PrepareForDisplay(detail, false)); 657 new views::Label(PrepareForDisplay(detail, false));
661 detail_label->SetMultiLine(true); 658 detail_label->SetMultiLine(true);
662 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 659 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
663 layout_->AddView(detail_label); 660 layout_->AddView(detail_label);
664 } 661 }
665 662
666 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const { 663 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const {
667 gfx::Size size = views::View::GetPreferredSize(); 664 gfx::Size size = views::View::GetPreferredSize();
668 return gfx::Size(size.width(), size.height() * state_); 665 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( 787 gfx::ImageSkia icon = gfx::CreateVectorIcon(
791 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey); 788 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey);
792 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon); 789 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon);
793 } 790 }
794 791
795 // static 792 // static
796 ExtensionInstallPrompt::ShowDialogCallback 793 ExtensionInstallPrompt::ShowDialogCallback
797 ExtensionInstallPrompt::GetViewsShowDialogCallback() { 794 ExtensionInstallPrompt::GetViewsShowDialogCallback() {
798 return base::Bind(&ShowExtensionInstallDialogImpl); 795 return base::Bind(&ShowExtensionInstallDialogImpl);
799 } 796 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698