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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 #include "ui/native_theme/common_theme.h" | 42 #include "ui/native_theme/common_theme.h" |
43 #include "ui/views/border.h" | 43 #include "ui/views/border.h" |
44 #include "ui/views/controls/button/image_button.h" | 44 #include "ui/views/controls/button/image_button.h" |
45 #include "ui/views/controls/image_view.h" | 45 #include "ui/views/controls/image_view.h" |
46 #include "ui/views/controls/label.h" | 46 #include "ui/views/controls/label.h" |
47 #include "ui/views/controls/link.h" | 47 #include "ui/views/controls/link.h" |
48 #include "ui/views/controls/scroll_view.h" | 48 #include "ui/views/controls/scroll_view.h" |
49 #include "ui/views/controls/separator.h" | 49 #include "ui/views/controls/separator.h" |
50 #include "ui/views/layout/box_layout.h" | 50 #include "ui/views/layout/box_layout.h" |
51 #include "ui/views/layout/grid_layout.h" | 51 #include "ui/views/layout/grid_layout.h" |
52 #include "ui/views/layout/layout_constants.h" | |
53 #include "ui/views/widget/widget.h" | 52 #include "ui/views/widget/widget.h" |
54 | 53 |
55 using content::OpenURLParams; | 54 using content::OpenURLParams; |
56 using content::Referrer; | 55 using content::Referrer; |
57 using extensions::ExperienceSamplingEvent; | 56 using extensions::ExperienceSamplingEvent; |
58 | 57 |
59 namespace { | 58 namespace { |
60 | 59 |
61 // Width of the bullet column in BulletedView. | 60 // Width of the bullet column in BulletedView. |
62 const int kBulletWidth = 20; | 61 const int kBulletWidth = 20; |
63 | 62 |
64 // Size of extension icon in top left of dialog. | 63 // Size of extension icon in top left of dialog. |
65 const int kIconSize = 64; | 64 const int kIconSize = 64; |
66 | 65 |
67 // The maximum height of the scroll view before it will show a scrollbar. | 66 // The maximum height of the scroll view before it will show a scrollbar. |
68 const int kScrollViewMaxHeight = 250; | 67 const int kScrollViewMaxHeight = 250; |
69 | 68 |
70 // Width of the left column of the dialog when the extension requests | 69 // Width of the left column of the dialog when the extension requests |
71 // permissions. | 70 // permissions. |
72 const int kPermissionsLeftColumnWidth = 250; | 71 const int kPermissionsLeftColumnWidth = 250; |
73 | 72 |
74 // Width of the left column of the dialog when the extension requests no | 73 // Width of the left column of the dialog when the extension requests no |
75 // permissions. | 74 // permissions. |
76 const int kNoPermissionsLeftColumnWidth = 200; | 75 const int kNoPermissionsLeftColumnWidth = 200; |
77 | 76 |
78 // Width of the left column for external install prompts. The text is long in | 77 // Width of the left column for external install prompts. The text is long in |
79 // this case, so make it wider than normal. | 78 // this case, so make it wider than normal. |
80 const int kExternalInstallLeftColumnWidth = 350; | 79 const int kExternalInstallLeftColumnWidth = 350; |
81 | 80 |
81 // Get the appropriate indentation for an item if its parent is using bullet | |
82 // points. If the parent is using bullets for its items, then a padding of one | |
83 // unit will make the child item (which has no bullet) look like a sibling of | |
84 // its parent. Therefore increase the indentation by one more unit to show that | |
85 // it is in fact a child item (with no missing bullet) and not a sibling. | |
86 int GetLeftPaddingForBulletedItems(const bool parent_bulleted) { | |
tapted
2017/03/22 03:05:59
nit: no need for `const`
Patti Lor
2017/03/22 05:57:40
Done.
| |
87 return LayoutDelegate::Get()->GetMetric( | |
88 LayoutDelegate::Metric::RELATED_BUTTON_HORIZONTAL_SPACING) * | |
89 (parent_bulleted ? 2 : 1); | |
90 } | |
91 | |
82 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) { | 92 void AddResourceIcon(const gfx::ImageSkia* skia_image, void* data) { |
83 views::View* parent = static_cast<views::View*>(data); | 93 views::View* parent = static_cast<views::View*>(data); |
84 views::ImageView* image_view = new views::ImageView(); | 94 views::ImageView* image_view = new views::ImageView(); |
85 image_view->SetImage(*skia_image); | 95 image_view->SetImage(*skia_image); |
86 parent->AddChildView(image_view); | 96 parent->AddChildView(image_view); |
87 } | 97 } |
88 | 98 |
89 // Creates a string for displaying |message| to the user. If it has to look | 99 // Creates a string for displaying |message| to the user. If it has to look |
90 // like a entry in a bullet point list, one is added. | 100 // like a entry in a bullet point list, one is added. |
91 base::string16 PrepareForDisplay(const base::string16& message, | 101 base::string16 PrepareForDisplay(const base::string16& message, |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
240 rating->AddChildView(rating_count); | 250 rating->AddChildView(rating_count); |
241 | 251 |
242 layout->StartRow(0, column_set_id); | 252 layout->StartRow(0, column_set_id); |
243 views::Label* user_count = | 253 views::Label* user_count = |
244 new views::Label(prompt_->GetUserCount(), small_font_list); | 254 new views::Label(prompt_->GetUserCount(), small_font_list); |
245 user_count->SetAutoColorReadabilityEnabled(false); | 255 user_count->SetAutoColorReadabilityEnabled(false); |
246 user_count->SetEnabledColor(SK_ColorGRAY); | 256 user_count->SetEnabledColor(SK_ColorGRAY); |
247 layout->AddView(user_count); | 257 layout->AddView(user_count); |
248 } | 258 } |
249 | 259 |
260 LayoutDelegate* layout_delegate = LayoutDelegate::Get(); | |
261 const int vertical_padding = layout_delegate->GetMetric( | |
262 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); | |
250 if (prompt_->ShouldShowPermissions()) { | 263 if (prompt_->ShouldShowPermissions()) { |
251 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 264 layout->AddPaddingRow(0, vertical_padding); |
252 layout->StartRow(0, column_set_id); | 265 layout->StartRow(0, column_set_id); |
253 layout->AddView(new views::Separator(), 3, 1, views::GridLayout::FILL, | 266 layout->AddView(new views::Separator(), 3, 1, views::GridLayout::FILL, |
254 views::GridLayout::FILL); | 267 views::GridLayout::FILL); |
255 } | 268 } |
256 | 269 |
257 const int content_width = left_column_width + | 270 const int content_width = |
258 LayoutDelegate::Get()->GetMetric( | 271 left_column_width + |
259 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN) + | 272 layout_delegate->GetMetric(LayoutDelegate::Metric::PANEL_CONTENT_MARGIN) + |
260 kIconSize; | 273 kIconSize; |
261 | 274 |
262 // Create the scrollable view which will contain the permissions and retained | 275 // Create the scrollable view which will contain the permissions and retained |
263 // files/devices. It will span the full content width. | 276 // files/devices. It will span the full content width. |
264 CustomScrollableView* scrollable = new CustomScrollableView(); | 277 CustomScrollableView* scrollable = new CustomScrollableView(); |
265 views::GridLayout* scroll_layout = new views::GridLayout(scrollable); | 278 views::GridLayout* scroll_layout = new views::GridLayout(scrollable); |
266 scrollable->SetLayoutManager(scroll_layout); | 279 scrollable->SetLayoutManager(scroll_layout); |
267 | 280 |
268 views::ColumnSet* scrollable_column_set = | 281 views::ColumnSet* scrollable_column_set = |
269 scroll_layout->AddColumnSet(column_set_id); | 282 scroll_layout->AddColumnSet(column_set_id); |
270 | 283 |
271 scrollable_column_set->AddColumn( | 284 scrollable_column_set->AddColumn( |
272 views::GridLayout::LEADING, views::GridLayout::LEADING, | 285 views::GridLayout::LEADING, views::GridLayout::LEADING, |
273 0, // no resizing | 286 0, // no resizing |
274 views::GridLayout::USE_PREF, content_width, content_width); | 287 views::GridLayout::USE_PREF, content_width, content_width); |
275 | 288 |
276 // Pad to the very right of the dialog, so the scrollbar will be on the edge. | 289 // Pad to the very right of the dialog, so the scrollbar will be on the edge. |
277 scrollable_column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); | 290 const int button_margin = |
291 layout_delegate->GetMetric(LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); | |
292 scrollable_column_set->AddPaddingColumn(0, button_margin); | |
278 | 293 |
279 layout->StartRow(0, column_set_id); | 294 layout->StartRow(0, column_set_id); |
280 scroll_view_ = new views::ScrollView(); | 295 scroll_view_ = new views::ScrollView(); |
281 scroll_view_->set_hide_horizontal_scrollbar(true); | 296 scroll_view_->set_hide_horizontal_scrollbar(true); |
282 scroll_view_->SetContents(scrollable); | 297 scroll_view_->SetContents(scrollable); |
283 layout->AddView(scroll_view_, 4, 1); | 298 layout->AddView(scroll_view_, 4, 1); |
284 | 299 |
285 if (prompt_->ShouldShowPermissions()) { | 300 if (prompt_->ShouldShowPermissions()) { |
286 bool has_permissions = | 301 bool has_permissions = |
287 prompt_->GetPermissionCount( | 302 prompt_->GetPermissionCount( |
288 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS) > 0; | 303 ExtensionInstallPrompt::PermissionsType::ALL_PERMISSIONS) > 0; |
289 if (has_permissions) { | 304 if (has_permissions) { |
290 AddPermissions( | 305 AddPermissions( |
291 scroll_layout, rb, column_set_id, content_width, | 306 scroll_layout, rb, column_set_id, content_width, |
292 ExtensionInstallPrompt::PermissionsType::REGULAR_PERMISSIONS); | 307 ExtensionInstallPrompt::PermissionsType::REGULAR_PERMISSIONS); |
293 AddPermissions( | 308 AddPermissions( |
294 scroll_layout, rb, column_set_id, content_width, | 309 scroll_layout, rb, column_set_id, content_width, |
295 ExtensionInstallPrompt::PermissionsType::WITHHELD_PERMISSIONS); | 310 ExtensionInstallPrompt::PermissionsType::WITHHELD_PERMISSIONS); |
296 } else { | 311 } else { |
297 scroll_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 312 scroll_layout->AddPaddingRow(0, vertical_padding); |
298 scroll_layout->StartRow(0, column_set_id); | 313 scroll_layout->StartRow(0, column_set_id); |
299 views::Label* permission_label = new views::Label( | 314 views::Label* permission_label = new views::Label( |
300 l10n_util::GetStringUTF16(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS)); | 315 l10n_util::GetStringUTF16(IDS_EXTENSION_NO_SPECIAL_PERMISSIONS)); |
301 permission_label->SetMultiLine(true); | 316 permission_label->SetMultiLine(true); |
302 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 317 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
303 permission_label->SizeToFit(content_width); | 318 permission_label->SizeToFit(content_width); |
304 scroll_layout->AddView(permission_label); | 319 scroll_layout->AddView(permission_label); |
305 } | 320 } |
306 } | 321 } |
307 | 322 |
308 if (prompt_->GetRetainedFileCount()) { | 323 if (prompt_->GetRetainedFileCount()) { |
309 scroll_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 324 scroll_layout->AddPaddingRow(0, vertical_padding); |
310 | 325 |
311 scroll_layout->StartRow(0, column_set_id); | 326 scroll_layout->StartRow(0, column_set_id); |
312 views::Label* retained_files_header = | 327 views::Label* retained_files_header = |
313 new views::Label(prompt_->GetRetainedFilesHeading()); | 328 new views::Label(prompt_->GetRetainedFilesHeading()); |
314 retained_files_header->SetMultiLine(true); | 329 retained_files_header->SetMultiLine(true); |
315 retained_files_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 330 retained_files_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
316 retained_files_header->SizeToFit(content_width); | 331 retained_files_header->SizeToFit(content_width); |
317 scroll_layout->AddView(retained_files_header); | 332 scroll_layout->AddView(retained_files_header); |
318 | 333 |
319 scroll_layout->StartRow(0, column_set_id); | 334 scroll_layout->StartRow(0, column_set_id); |
320 PermissionDetails details; | 335 PermissionDetails details; |
321 for (size_t i = 0; i < prompt_->GetRetainedFileCount(); ++i) { | 336 for (size_t i = 0; i < prompt_->GetRetainedFileCount(); ++i) { |
322 details.push_back(prompt_->GetRetainedFile(i)); | 337 details.push_back(prompt_->GetRetainedFile(i)); |
323 } | 338 } |
324 ExpandableContainerView* issue_advice_view = | 339 ExpandableContainerView* issue_advice_view = |
325 new ExpandableContainerView(details, content_width, false); | 340 new ExpandableContainerView(details, content_width, false); |
326 scroll_layout->AddView(issue_advice_view); | 341 scroll_layout->AddView(issue_advice_view); |
327 } | 342 } |
328 | 343 |
329 if (prompt_->GetRetainedDeviceCount()) { | 344 if (prompt_->GetRetainedDeviceCount()) { |
330 scroll_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 345 scroll_layout->AddPaddingRow(0, vertical_padding); |
331 | 346 |
332 scroll_layout->StartRow(0, column_set_id); | 347 scroll_layout->StartRow(0, column_set_id); |
333 views::Label* retained_devices_header = | 348 views::Label* retained_devices_header = |
334 new views::Label(prompt_->GetRetainedDevicesHeading()); | 349 new views::Label(prompt_->GetRetainedDevicesHeading()); |
335 retained_devices_header->SetMultiLine(true); | 350 retained_devices_header->SetMultiLine(true); |
336 retained_devices_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 351 retained_devices_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
337 retained_devices_header->SizeToFit(content_width); | 352 retained_devices_header->SizeToFit(content_width); |
338 scroll_layout->AddView(retained_devices_header); | 353 scroll_layout->AddView(retained_devices_header); |
339 | 354 |
340 scroll_layout->StartRow(0, column_set_id); | 355 scroll_layout->StartRow(0, column_set_id); |
341 PermissionDetails details; | 356 PermissionDetails details; |
342 for (size_t i = 0; i < prompt_->GetRetainedDeviceCount(); ++i) { | 357 for (size_t i = 0; i < prompt_->GetRetainedDeviceCount(); ++i) { |
343 details.push_back(prompt_->GetRetainedDeviceMessageString(i)); | 358 details.push_back(prompt_->GetRetainedDeviceMessageString(i)); |
344 } | 359 } |
345 ExpandableContainerView* issue_advice_view = | 360 ExpandableContainerView* issue_advice_view = |
346 new ExpandableContainerView(details, content_width, false); | 361 new ExpandableContainerView(details, content_width, false); |
347 scroll_layout->AddView(issue_advice_view); | 362 scroll_layout->AddView(issue_advice_view); |
348 } | 363 } |
349 | 364 |
350 DCHECK_GE(prompt_->type(), 0); | 365 DCHECK_GE(prompt_->type(), 0); |
351 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallPrompt.Type", | 366 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallPrompt.Type", |
352 prompt_->type(), | 367 prompt_->type(), |
353 ExtensionInstallPrompt::NUM_PROMPT_TYPES); | 368 ExtensionInstallPrompt::NUM_PROMPT_TYPES); |
354 | 369 |
355 scroll_view_->ClipHeightTo( | 370 scroll_view_->ClipHeightTo( |
356 0, | 371 0, |
357 std::min(kScrollViewMaxHeight, scrollable->GetPreferredSize().height())); | 372 std::min(kScrollViewMaxHeight, scrollable->GetPreferredSize().height())); |
358 | 373 |
359 dialog_size_ = gfx::Size( | 374 dialog_size_ = gfx::Size(content_width + 2 * button_margin, |
360 content_width + 2 * views::kButtonHEdgeMarginNew, | 375 container_->GetPreferredSize().height()); |
361 container_->GetPreferredSize().height()); | |
362 | 376 |
363 std::string event_name = ExperienceSamplingEvent::kExtensionInstallDialog; | 377 std::string event_name = ExperienceSamplingEvent::kExtensionInstallDialog; |
364 event_name.append( | 378 event_name.append( |
365 ExtensionInstallPrompt::PromptTypeToString(prompt_->type())); | 379 ExtensionInstallPrompt::PromptTypeToString(prompt_->type())); |
366 sampling_event_ = ExperienceSamplingEvent::Create(event_name); | 380 sampling_event_ = ExperienceSamplingEvent::Create(event_name); |
367 } | 381 } |
368 | 382 |
369 bool ExtensionInstallDialogView::AddPermissions( | 383 bool ExtensionInstallDialogView::AddPermissions( |
370 views::GridLayout* layout, | 384 views::GridLayout* layout, |
371 ui::ResourceBundle& rb, | 385 ui::ResourceBundle& rb, |
372 int column_set_id, | 386 int column_set_id, |
373 int left_column_width, | 387 int left_column_width, |
374 ExtensionInstallPrompt::PermissionsType perm_type) { | 388 ExtensionInstallPrompt::PermissionsType perm_type) { |
375 if (prompt_->GetPermissionCount(perm_type) == 0) | 389 if (prompt_->GetPermissionCount(perm_type) == 0) |
376 return false; | 390 return false; |
377 | 391 |
378 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 392 const int vertical_padding = LayoutDelegate::Get()->GetMetric( |
393 LayoutDelegate::Metric::RELATED_CONTROL_VERTICAL_SPACING); | |
394 layout->AddPaddingRow(0, vertical_padding); | |
379 | 395 |
380 layout->StartRow(0, column_set_id); | 396 layout->StartRow(0, column_set_id); |
381 views::Label* permissions_header = | 397 views::Label* permissions_header = |
382 new views::Label(prompt_->GetPermissionsHeading(perm_type)); | 398 new views::Label(prompt_->GetPermissionsHeading(perm_type)); |
383 permissions_header->SetMultiLine(true); | 399 permissions_header->SetMultiLine(true); |
384 permissions_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 400 permissions_header->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
385 permissions_header->SizeToFit(left_column_width); | 401 permissions_header->SizeToFit(left_column_width); |
386 layout->AddView(permissions_header); | 402 layout->AddView(permissions_header); |
387 | 403 |
388 for (size_t i = 0; i < prompt_->GetPermissionCount(perm_type); ++i) { | 404 for (size_t i = 0; i < prompt_->GetPermissionCount(perm_type); ++i) { |
389 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 405 layout->AddPaddingRow(0, vertical_padding); |
390 layout->StartRow(0, column_set_id); | 406 layout->StartRow(0, column_set_id); |
391 views::Label* permission_label = | 407 views::Label* permission_label = |
392 new views::Label(prompt_->GetPermission(i, perm_type)); | 408 new views::Label(prompt_->GetPermission(i, perm_type)); |
393 | 409 |
394 permission_label->SetMultiLine(true); | 410 permission_label->SetMultiLine(true); |
395 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 411 permission_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
396 permission_label->SizeToFit(left_column_width - kBulletWidth); | 412 permission_label->SizeToFit(left_column_width - kBulletWidth); |
397 layout->AddView(new BulletedView(permission_label)); | 413 layout->AddView(new BulletedView(permission_label)); |
398 | 414 |
399 // If we have more details to provide, show them in collapsed form. | 415 // If we have more details to provide, show them in collapsed form. |
400 if (!prompt_->GetPermissionsDetails(i, perm_type).empty()) { | 416 if (!prompt_->GetPermissionsDetails(i, perm_type).empty()) { |
401 layout->StartRow(0, column_set_id); | 417 layout->StartRow(0, column_set_id); |
402 PermissionDetails details; | 418 PermissionDetails details; |
403 details.push_back(PrepareForDisplay( | 419 details.push_back(PrepareForDisplay( |
404 prompt_->GetPermissionsDetails(i, perm_type), false)); | 420 prompt_->GetPermissionsDetails(i, perm_type), false)); |
405 ExpandableContainerView* details_container = | 421 ExpandableContainerView* details_container = |
406 new ExpandableContainerView(details, left_column_width, true); | 422 new ExpandableContainerView(details, left_column_width, true); |
407 layout->AddView(details_container); | 423 layout->AddView(details_container); |
408 } | 424 } |
409 } | 425 } |
410 return true; | 426 return true; |
411 } | 427 } |
412 | 428 |
413 views::GridLayout* ExtensionInstallDialogView::CreateLayout( | 429 views::GridLayout* ExtensionInstallDialogView::CreateLayout( |
414 int left_column_width, | 430 int left_column_width, |
415 int column_set_id) { | 431 int column_set_id) { |
416 container_ = new views::View(); | 432 container_ = new views::View(); |
417 // This is basically views::GridLayout::CreatePanel, but without a top or | 433 LayoutDelegate* layout_delegate = LayoutDelegate::Get(); |
418 // right margin (we effectively get a top margin anyway from the empty dialog | 434 const int horizontal_margin = |
419 // title, and we add an explicit padding column as a right margin below). | 435 layout_delegate->GetMetric(LayoutDelegate::Metric::DIALOG_BUTTON_MARGIN); |
436 const int bottom_margin = | |
437 layout_delegate->GetMetric(LayoutDelegate::Metric::PANEL_CONTENT_MARGIN); | |
438 | |
439 // This is views::GridLayout::CreatePanel(), but without a top or right | |
440 // margin. The empty dialog title will then become the top margin, and a | |
441 // padding column will be manually added to handle a right margin. This is | |
442 // done so that the extension icon can be shown on the right of the dialog | |
443 // title, but on the same y-axis, and the scroll view used to contain other | |
444 // content can have its scrollbar aligned with the right edge of the dialog. | |
420 views::GridLayout* layout = new views::GridLayout(container_); | 445 views::GridLayout* layout = new views::GridLayout(container_); |
421 layout->SetInsets(0, views::kButtonHEdgeMarginNew, | 446 layout->SetInsets(0, horizontal_margin, bottom_margin, 0); |
422 LayoutDelegate::Get()->GetMetric( | |
423 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN), | |
424 0); | |
425 container_->SetLayoutManager(layout); | 447 container_->SetLayoutManager(layout); |
426 AddChildView(container_); | 448 AddChildView(container_); |
427 | 449 |
428 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); | 450 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); |
429 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, | 451 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, |
430 0, // no resizing | 452 0, // no resizing |
431 views::GridLayout::USE_PREF, | 453 views::GridLayout::USE_PREF, |
432 0, // no fixed width | 454 0, // no fixed width |
433 left_column_width); | 455 left_column_width); |
434 column_set->AddPaddingColumn( | 456 column_set->AddPaddingColumn( |
435 0, LayoutDelegate::Get()->GetMetric( | 457 0, layout_delegate->GetMetric( |
436 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN)); | 458 LayoutDelegate::Metric::UNRELATED_CONTROL_HORIZONTAL_SPACING)); |
437 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, | 459 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, |
438 0, // no resizing | 460 0, // no resizing |
439 views::GridLayout::USE_PREF, | 461 views::GridLayout::USE_PREF, |
440 0, // no fixed width | 462 0, // no fixed width |
441 kIconSize); | 463 kIconSize); |
442 column_set->AddPaddingColumn(0, views::kButtonHEdgeMarginNew); | 464 column_set->AddPaddingColumn(0, horizontal_margin); |
443 | 465 |
444 layout->StartRow(0, column_set_id); | 466 layout->StartRow(0, column_set_id); |
445 views::Label* title = | 467 views::Label* title = |
446 new views::Label(prompt_->GetDialogTitle(), | 468 new views::Label(prompt_->GetDialogTitle(), |
447 ui::ResourceBundle::GetSharedInstance().GetFontList( | 469 ui::ResourceBundle::GetSharedInstance().GetFontList( |
448 ui::ResourceBundle::MediumFont)); | 470 ui::ResourceBundle::MediumFont)); |
449 title->SetMultiLine(true); | 471 title->SetMultiLine(true); |
450 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 472 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
451 title->SizeToFit(left_column_width); | 473 title->SizeToFit(left_column_width); |
452 | 474 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 } | 597 } |
576 | 598 |
577 // ExpandableContainerView::DetailsView ---------------------------------------- | 599 // ExpandableContainerView::DetailsView ---------------------------------------- |
578 | 600 |
579 ExpandableContainerView::DetailsView::DetailsView(int horizontal_space, | 601 ExpandableContainerView::DetailsView::DetailsView(int horizontal_space, |
580 bool parent_bulleted) | 602 bool parent_bulleted) |
581 : layout_(new views::GridLayout(this)), | 603 : layout_(new views::GridLayout(this)), |
582 state_(0) { | 604 state_(0) { |
583 SetLayoutManager(layout_); | 605 SetLayoutManager(layout_); |
584 views::ColumnSet* column_set = layout_->AddColumnSet(0); | 606 views::ColumnSet* column_set = layout_->AddColumnSet(0); |
585 // If the parent is using bullets for its items, then a padding of one unit | 607 int padding = GetLeftPaddingForBulletedItems(parent_bulleted); |
tapted
2017/03/22 03:05:59
nit: inline below (`padding` temporary no required
Patti Lor
2017/03/22 05:57:41
Done - replaced in 2 places.
| |
586 // will make the child item (which has no bullet) look like a sibling of its | |
587 // parent. Therefore increase the indentation by one more unit to show that it | |
588 // is in fact a child item (with no missing bullet) and not a sibling. | |
589 int padding = | |
590 views::kRelatedControlHorizontalSpacing * (parent_bulleted ? 2 : 1); | |
591 column_set->AddPaddingColumn(0, padding); | 608 column_set->AddPaddingColumn(0, padding); |
592 column_set->AddColumn(views::GridLayout::LEADING, | 609 column_set->AddColumn(views::GridLayout::LEADING, |
593 views::GridLayout::LEADING, | 610 views::GridLayout::LEADING, |
594 0, | 611 0, |
595 views::GridLayout::FIXED, | 612 views::GridLayout::FIXED, |
596 horizontal_space - padding, | 613 horizontal_space - padding, |
597 0); | 614 0); |
598 } | 615 } |
599 | 616 |
600 void ExpandableContainerView::DetailsView::AddDetail( | 617 void ExpandableContainerView::DetailsView::AddDetail( |
601 const base::string16& detail) { | 618 const base::string16& detail) { |
602 layout_->StartRowWithPadding(0, 0, | 619 layout_->StartRowWithPadding( |
603 0, views::kRelatedControlSmallVerticalSpacing); | 620 0, 0, 0, |
621 LayoutDelegate::Get()->GetMetric( | |
622 LayoutDelegate::Metric::RELATED_CONTROL_HORIZONTAL_SPACING)); | |
tapted
2017/03/22 03:05:59
For this, I suggest
constexpr int kPaddingAboveDe
Patti Lor
2017/03/22 05:57:41
Done. I also updated all the constants in the anon
| |
604 views::Label* detail_label = | 623 views::Label* detail_label = |
605 new views::Label(PrepareForDisplay(detail, false)); | 624 new views::Label(PrepareForDisplay(detail, false)); |
606 detail_label->SetMultiLine(true); | 625 detail_label->SetMultiLine(true); |
607 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 626 detail_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
608 layout_->AddView(detail_label); | 627 layout_->AddView(detail_label); |
609 } | 628 } |
610 | 629 |
611 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const { | 630 gfx::Size ExpandableContainerView::DetailsView::GetPreferredSize() const { |
612 gfx::Size size = views::View::GetPreferredSize(); | 631 gfx::Size size = views::View::GetPreferredSize(); |
613 return gfx::Size(size.width(), size.height() * state_); | 632 return gfx::Size(size.width(), size.height() * state_); |
(...skipping 28 matching lines...) Expand all Loading... | |
642 | 661 |
643 details_view_ = new DetailsView(horizontal_space, parent_bulleted); | 662 details_view_ = new DetailsView(horizontal_space, parent_bulleted); |
644 | 663 |
645 layout->StartRow(0, column_set_id); | 664 layout->StartRow(0, column_set_id); |
646 layout->AddView(details_view_); | 665 layout->AddView(details_view_); |
647 | 666 |
648 for (size_t i = 0; i < details.size(); ++i) | 667 for (size_t i = 0; i < details.size(); ++i) |
649 details_view_->AddDetail(details[i]); | 668 details_view_->AddDetail(details[i]); |
650 | 669 |
651 // Make sure the link width column is as wide as needed for both Show and | 670 // Make sure the link width column is as wide as needed for both Show and |
652 // Hide details, so that the arrow doesn't shift horizontally when we | 671 // Hide details, so that the arrow doesn't shift horizontally when we toggle. |
653 // toggle. | |
654 views::Link* link = new views::Link( | 672 views::Link* link = new views::Link( |
655 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS)); | 673 l10n_util::GetStringUTF16(IDS_EXTENSIONS_HIDE_DETAILS)); |
656 int link_col_width = link->GetPreferredSize().width(); | 674 int link_col_width = link->GetPreferredSize().width(); |
657 link->SetText(l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); | 675 link->SetText(l10n_util::GetStringUTF16(IDS_EXTENSIONS_SHOW_DETAILS)); |
658 link_col_width = std::max(link_col_width, link->GetPreferredSize().width()); | 676 link_col_width = std::max(link_col_width, link->GetPreferredSize().width()); |
659 | 677 |
660 column_set = layout->AddColumnSet(++column_set_id); | 678 column_set = layout->AddColumnSet(++column_set_id); |
661 // Padding to the left of the More Details column. If the parent is using | 679 // Padding to the left of the More Details column. |
662 // bullets for its items, then a padding of one unit will make the child | 680 column_set->AddPaddingColumn(0, |
663 // item (which has no bullet) look like a sibling of its parent. Therefore | 681 GetLeftPaddingForBulletedItems(parent_bulleted)); |
664 // increase the indentation by one more unit to show that it is in fact a | |
665 // child item (with no missing bullet) and not a sibling. | |
666 column_set->AddPaddingColumn( | |
667 0, views::kRelatedControlHorizontalSpacing * (parent_bulleted ? 2 : 1)); | |
668 // The More Details column. | 682 // The More Details column. |
669 column_set->AddColumn(views::GridLayout::LEADING, | 683 column_set->AddColumn(views::GridLayout::LEADING, |
670 views::GridLayout::LEADING, | 684 views::GridLayout::LEADING, |
671 0, | 685 0, |
672 views::GridLayout::FIXED, | 686 views::GridLayout::FIXED, |
673 link_col_width, | 687 link_col_width, |
674 link_col_width); | 688 link_col_width); |
675 // The Up/Down arrow column. | 689 // The Up/Down arrow column. |
676 column_set->AddColumn(views::GridLayout::LEADING, | 690 column_set->AddColumn(views::GridLayout::LEADING, |
677 views::GridLayout::TRAILING, | 691 views::GridLayout::TRAILING, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
740 gfx::ImageSkia icon = gfx::CreateVectorIcon( | 754 gfx::ImageSkia icon = gfx::CreateVectorIcon( |
741 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey); | 755 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey); |
742 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon); | 756 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon); |
743 } | 757 } |
744 | 758 |
745 // static | 759 // static |
746 ExtensionInstallPrompt::ShowDialogCallback | 760 ExtensionInstallPrompt::ShowDialogCallback |
747 ExtensionInstallPrompt::GetViewsShowDialogCallback() { | 761 ExtensionInstallPrompt::GetViewsShowDialogCallback() { |
748 return base::Bind(&ShowExtensionInstallDialogImpl); | 762 return base::Bind(&ShowExtensionInstallDialogImpl); |
749 } | 763 } |
OLD | NEW |