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