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

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: Deleted LayoutDelegate and HarmonyLayoutDelegate. 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_typography.h" 28 #include "chrome/browser/ui/views/harmony/chrome_typography.h"
29 #include "chrome/browser/ui/views/harmony/layout_delegate.h" 29 #include "chrome/browser/ui/views/harmony/chrome_views_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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 // Width of the left column for external install prompts. The text is long in 78 // Width of the left column for external install prompts. The text is long in
79 // this case, so make it wider than normal. 79 // this case, so make it wider than normal.
80 constexpr int kExternalInstallLeftColumnWidth = 350; 80 constexpr int kExternalInstallLeftColumnWidth = 350;
81 81
82 // Get the appropriate indentation for an item if its parent is using bullet 82 // Get the appropriate indentation for an item if its parent is using bullet
83 // points. If the parent is using bullets for its items, then a padding of one 83 // points. If the parent is using bullets for its items, then a padding of one
84 // unit will make the child item (which has no bullet) look like a sibling of 84 // unit will make the child item (which has no bullet) look like a sibling of
85 // its parent. Therefore increase the indentation by one more unit to show that 85 // its parent. Therefore increase the indentation by one more unit to show that
86 // it is in fact a child item (with no missing bullet) and not a sibling. 86 // it is in fact a child item (with no missing bullet) and not a sibling.
87 int GetLeftPaddingForBulletedItems(bool parent_bulleted) { 87 int GetLeftPaddingForBulletedItems(bool parent_bulleted) {
88 return LayoutDelegate::Get()->GetMetric( 88 return ChromeViewsLayoutDelegate::Get()->GetDistanceMetric(
89 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING) * 89 ChromeDistanceMetric::RELATED_CONTROL_HORIZONTAL) *
90 (parent_bulleted ? 2 : 1); 90 (parent_bulleted ? 2 : 1);
91 } 91 }
92 92
93 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) { 93 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) {
94 views::View* parent = static_cast<views::View*>(data); 94 views::View* parent = static_cast<views::View*>(data);
95 views::ImageView* image_view = new views::ImageView(); 95 views::ImageView* image_view = new views::ImageView();
96 image_view->SetImage(*skia_image); 96 image_view->SetImage(*skia_image);
97 parent->AddChildView(image_view); 97 parent->AddChildView(image_view);
98 } 98 }
99 99
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 236
237 if (prompt_->has_webstore_data()) { 237 if (prompt_->has_webstore_data()) {
238 layout->StartRow(0, column_set_id); 238 layout->StartRow(0, column_set_id);
239 views::View* rating = new views::View(); 239 views::View* rating = new views::View();
240 rating->SetLayoutManager(new views::BoxLayout( 240 rating->SetLayoutManager(new views::BoxLayout(
241 views::BoxLayout::kHorizontal, 0, 0, 0)); 241 views::BoxLayout::kHorizontal, 0, 0, 0));
242 layout->AddView(rating); 242 layout->AddView(rating);
243 prompt_->AppendRatingStars(AddResourceIcon, rating); 243 prompt_->AppendRatingStars(AddResourceIcon, rating);
244 244
245 int rating_text_context, user_count_text_context; 245 int rating_text_context, user_count_text_context;
246 if (LayoutDelegate::Get()->IsHarmonyMode()) { 246 if (ChromeViewsLayoutDelegate::Get()->IsHarmonyMode()) {
247 rating_text_context = CONTEXT_BODY_TEXT_LARGE; 247 rating_text_context = CONTEXT_BODY_TEXT_LARGE;
248 user_count_text_context = CONTEXT_BODY_TEXT_SMALL; 248 user_count_text_context = CONTEXT_BODY_TEXT_SMALL;
249 } else { 249 } else {
250 rating_text_context = user_count_text_context = CONTEXT_DEPRECATED_SMALL; 250 rating_text_context = user_count_text_context = CONTEXT_DEPRECATED_SMALL;
251 } 251 }
252 views::Label* rating_count = 252 views::Label* rating_count =
253 new views::Label(prompt_->GetRatingCount(), rating_text_context, 253 new views::Label(prompt_->GetRatingCount(), rating_text_context,
254 views::style::STYLE_PRIMARY); 254 views::style::STYLE_PRIMARY);
255 // Add some space between the stars and the rating count. 255 // Add some space between the stars and the rating count.
256 rating_count->SetBorder(views::CreateEmptyBorder(0, 2, 0, 0)); 256 rating_count->SetBorder(views::CreateEmptyBorder(0, 2, 0, 0));
257 rating->AddChildView(rating_count); 257 rating->AddChildView(rating_count);
258 258
259 layout->StartRow(0, column_set_id); 259 layout->StartRow(0, column_set_id);
260 views::Label* user_count = new views::Label( 260 views::Label* user_count = new views::Label(
261 prompt_->GetUserCount(), user_count_text_context, STYLE_SECONDARY); 261 prompt_->GetUserCount(), user_count_text_context, STYLE_SECONDARY);
262 user_count->SetAutoColorReadabilityEnabled(false); 262 user_count->SetAutoColorReadabilityEnabled(false);
263 user_count->SetEnabledColor(SK_ColorGRAY); 263 user_count->SetEnabledColor(SK_ColorGRAY);
264 layout->AddView(user_count); 264 layout->AddView(user_count);
265 } 265 }
266 266
267 LayoutDelegate* layout_delegate = LayoutDelegate::Get(); 267 ChromeViewsLayoutDelegate* layout_delegate = ChromeViewsLayoutDelegate::Get();
268 const int vertical_padding = layout_delegate->GetMetric( 268 const int vertical_padding = layout_delegate->GetDistanceMetric(
269 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); 269 ChromeDistanceMetric::RELATED_CONTROL_VERTICAL);
270 if (prompt_->ShouldShowPermissions()) { 270 if (prompt_->ShouldShowPermissions()) {
271 layout->AddPaddingRow(0, vertical_padding); 271 layout->AddPaddingRow(0, vertical_padding);
272 layout->StartRow(0, column_set_id); 272 layout->StartRow(0, column_set_id);
273 layout->AddView(new views::Separator(), 3, 1, views::GridLayout::FILL, 273 layout->AddView(new views::Separator(), 3, 1, views::GridLayout::FILL,
274 views::GridLayout::FILL); 274 views::GridLayout::FILL);
275 } 275 }
276 276
277 const int content_width = 277 const int content_width = left_column_width +
278 left_column_width + 278 layout_delegate->GetDistanceMetric(
279 layout_delegate->GetMetric(LayoutDelegate::Metric::PANEL_CONTENT_MARGIN) + 279 ChromeDistanceMetric::PANEL_CONTENT_MARGIN) +
280 kIconSize; 280 kIconSize;
281 281
282 // Create the scrollable view which will contain the permissions and retained 282 // Create the scrollable view which will contain the permissions and retained
283 // files/devices. It will span the full content width. 283 // files/devices. It will span the full content width.
284 CustomScrollableView* scrollable = new CustomScrollableView(); 284 CustomScrollableView* scrollable = new CustomScrollableView();
285 views::GridLayout* scroll_layout = new views::GridLayout(scrollable); 285 views::GridLayout* scroll_layout = new views::GridLayout(scrollable);
286 scrollable->SetLayoutManager(scroll_layout); 286 scrollable->SetLayoutManager(scroll_layout);
287 287
288 views::ColumnSet* scrollable_column_set = 288 views::ColumnSet* scrollable_column_set =
289 scroll_layout->AddColumnSet(column_set_id); 289 scroll_layout->AddColumnSet(column_set_id);
290 290
291 scrollable_column_set->AddColumn( 291 scrollable_column_set->AddColumn(
292 views::GridLayout::LEADING, views::GridLayout::LEADING, 292 views::GridLayout::LEADING, views::GridLayout::LEADING,
293 0, // no resizing 293 0, // no resizing
294 views::GridLayout::USE_PREF, content_width, content_width); 294 views::GridLayout::USE_PREF, content_width, content_width);
295 295
296 // Pad to the very right of the dialog, so the scrollbar will be on the edge. 296 // Pad to the very right of the dialog, so the scrollbar will be on the edge.
297 const int button_margin = 297 const int button_margin = layout_delegate->GetDistanceMetric(
298 layout_delegate->GetMetric(LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); 298 ChromeDistanceMetric::DIALOG_BUTTON_MARGIN);
299 scrollable_column_set->AddPaddingColumn(0, button_margin); 299 scrollable_column_set->AddPaddingColumn(0, button_margin);
300 300
301 layout->StartRow(0, column_set_id); 301 layout->StartRow(0, column_set_id);
302 scroll_view_ = new views::ScrollView(); 302 scroll_view_ = new views::ScrollView();
303 scroll_view_->set_hide_horizontal_scrollbar(true); 303 scroll_view_->set_hide_horizontal_scrollbar(true);
304 scroll_view_->SetContents(scrollable); 304 scroll_view_->SetContents(scrollable);
305 layout->AddView(scroll_view_, 4, 1); 305 layout->AddView(scroll_view_, 4, 1);
306 306
307 if (prompt_->ShouldShowPermissions()) { 307 if (prompt_->ShouldShowPermissions()) {
308 bool has_permissions = 308 bool has_permissions =
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 389
390 bool ExtensionInstallDialogView::AddPermissions( 390 bool ExtensionInstallDialogView::AddPermissions(
391 views::GridLayout* layout, 391 views::GridLayout* layout,
392 ui::ResourceBundle& rb, 392 ui::ResourceBundle& rb,
393 int column_set_id, 393 int column_set_id,
394 int left_column_width, 394 int left_column_width,
395 ExtensionInstallPrompt::PermissionsType perm_type) { 395 ExtensionInstallPrompt::PermissionsType perm_type) {
396 if (prompt_->GetPermissionCount(perm_type) == 0) 396 if (prompt_->GetPermissionCount(perm_type) == 0)
397 return false; 397 return false;
398 398
399 const int vertical_padding = LayoutDelegate::Get()->GetMetric( 399 const int vertical_padding =
400 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); 400 ChromeViewsLayoutDelegate::Get()->GetDistanceMetric(
401 ChromeDistanceMetric::RELATED_CONTROL_VERTICAL);
401 layout->AddPaddingRow(0, vertical_padding); 402 layout->AddPaddingRow(0, vertical_padding);
402 403
403 layout->StartRow(0, column_set_id); 404 layout->StartRow(0, column_set_id);
404 views::Label* permissions_header = 405 views::Label* permissions_header =
405 new views::Label(prompt_->GetPermissionsHeading(perm_type)); 406 new views::Label(prompt_->GetPermissionsHeading(perm_type));
406 permissions_header->SetMultiLine(true); 407 permissions_header->SetMultiLine(true);
407 permissions_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); 408 permissions_header->SetHorizontalAlignment(gfx::ALIGN_LEFT);
408 permissions_header->SizeToFit(left_column_width); 409 permissions_header->SizeToFit(left_column_width);
409 layout->AddView(permissions_header); 410 layout->AddView(permissions_header);
410 411
(...skipping 19 matching lines...) Expand all
430 layout->AddView(details_container); 431 layout->AddView(details_container);
431 } 432 }
432 } 433 }
433 return true; 434 return true;
434 } 435 }
435 436
436 views::GridLayout* ExtensionInstallDialogView::CreateLayout( 437 views::GridLayout* ExtensionInstallDialogView::CreateLayout(
437 int left_column_width, 438 int left_column_width,
438 int column_set_id) { 439 int column_set_id) {
439 container_ = new views::View(); 440 container_ = new views::View();
440 LayoutDelegate* layout_delegate = LayoutDelegate::Get(); 441 ChromeViewsLayoutDelegate* layout_delegate = ChromeViewsLayoutDelegate::Get();
441 const int horizontal_margin = 442 const int horizontal_margin = layout_delegate->GetDistanceMetric(
442 layout_delegate->GetMetric(LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); 443 ChromeDistanceMetric::DIALOG_BUTTON_MARGIN);
443 const int bottom_margin = 444 const int bottom_margin = layout_delegate->GetDistanceMetric(
444 layout_delegate->GetMetric(LayoutDelegate::Metric::PANEL_CONTENT_MARGIN); 445 ChromeDistanceMetric::PANEL_CONTENT_MARGIN);
445 446
446 // This is views::GridLayout::CreatePanel(), but without a top or right 447 // This is views::GridLayout::CreatePanel(), but without a top or right
447 // margin. The empty dialog title will then become the top margin, and a 448 // margin. The empty dialog title will then become the top margin, and a
448 // padding column will be manually added to handle a right margin. This is 449 // padding column will be manually added to handle a right margin. This is
449 // done so that the extension icon can be shown on the right of the dialog 450 // done so that the extension icon can be shown on the right of the dialog
450 // title, but on the same y-axis, and the scroll view used to contain other 451 // title, but on the same y-axis, and the scroll view used to contain other
451 // content can have its scrollbar aligned with the right edge of the dialog. 452 // content can have its scrollbar aligned with the right edge of the dialog.
452 views::GridLayout* layout = new views::GridLayout(container_); 453 views::GridLayout* layout = new views::GridLayout(container_);
453 layout->SetInsets(0, horizontal_margin, bottom_margin, 0); 454 layout->SetInsets(0, horizontal_margin, bottom_margin, 0);
454 container_->SetLayoutManager(layout); 455 container_->SetLayoutManager(layout);
455 AddChildView(container_); 456 AddChildView(container_);
456 457
457 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); 458 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
458 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 459 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING,
459 0, // no resizing 460 0, // no resizing
460 views::GridLayout::USE_PREF, 461 views::GridLayout::USE_PREF,
461 0, // no fixed width 462 0, // no fixed width
462 left_column_width); 463 left_column_width);
463 column_set->AddPaddingColumn( 464 column_set->AddPaddingColumn(
464 0, layout_delegate->GetMetric( 465 0, layout_delegate->GetDistanceMetric(
465 LayoutDelegate::Metric::UNRELATED_CONTROL_HORIZONTAL_SPACING)); 466 ChromeDistanceMetric::UNRELATED_CONTROL_HORIZONTAL));
466 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, 467 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
467 0, // no resizing 468 0, // no resizing
468 views::GridLayout::USE_PREF, 469 views::GridLayout::USE_PREF,
469 0, // no fixed width 470 0, // no fixed width
470 kIconSize); 471 kIconSize);
471 column_set->AddPaddingColumn(0, horizontal_margin); 472 column_set->AddPaddingColumn(0, horizontal_margin);
472 473
473 layout->StartRow(0, column_set_id); 474 layout->StartRow(0, column_set_id);
474 views::Label* title = new views::Label(prompt_->GetDialogTitle(), 475 views::Label* title = new views::Label(prompt_->GetDialogTitle(),
475 views::style::CONTEXT_DIALOG_TITLE); 476 views::style::CONTEXT_DIALOG_TITLE);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 column_set->AddPaddingColumn(0, padding); 614 column_set->AddPaddingColumn(0, padding);
614 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 615 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING,
615 0, views::GridLayout::FIXED, horizontal_space - padding, 616 0, views::GridLayout::FIXED, horizontal_space - padding,
616 0); 617 0);
617 } 618 }
618 619
619 void ExpandableContainerView::DetailsView::AddDetail( 620 void ExpandableContainerView::DetailsView::AddDetail(
620 const base::string16& detail) { 621 const base::string16& detail) {
621 layout_->StartRowWithPadding( 622 layout_->StartRowWithPadding(
622 0, 0, 0, 623 0, 0, 0,
623 LayoutDelegate::Get()->GetMetric( 624 ChromeViewsLayoutDelegate::Get()->GetDistanceMetric(
624 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING_SMALL)); 625 ChromeDistanceMetric::RELATED_CONTROL_VERTICAL_SMALL));
625 views::Label* detail_label = 626 views::Label* detail_label =
626 new views::Label(PrepareForDisplay(detail, false)); 627 new views::Label(PrepareForDisplay(detail, false));
627 detail_label->SetMultiLine(true); 628 detail_label->SetMultiLine(true);
628 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 629 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
629 layout_->AddView(detail_label); 630 layout_->AddView(detail_label);
630 } 631 }
631 632
632 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const { 633 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const {
633 gfx::Size size = views::View::GetPreferredSize(); 634 gfx::Size size = views::View::GetPreferredSize();
634 return gfx::Size(size.width(), size.height() * state_); 635 return gfx::Size(size.width(), size.height() * state_);
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 gfx::ImageSkia icon = gfx::CreateVectorIcon( 757 gfx::ImageSkia icon = gfx::CreateVectorIcon(
757 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey); 758 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey);
758 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon); 759 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon);
759 } 760 }
760 761
761 // static 762 // static
762 ExtensionInstallPrompt::ShowDialogCallback 763 ExtensionInstallPrompt::ShowDialogCallback
763 ExtensionInstallPrompt::GetViewsShowDialogCallback() { 764 ExtensionInstallPrompt::GetViewsShowDialogCallback() {
764 return base::Bind(&ShowExtensionInstallDialogImpl); 765 return base::Bind(&ShowExtensionInstallDialogImpl);
765 } 766 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698