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

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

Issue 2888563004: Delete panel metrics and define insets in terms of distance metrics. (Closed)
Patch Set: one wrong conversion Created 3 years, 7 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>
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL); 276 provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL);
277 if (prompt_->ShouldShowPermissions()) { 277 if (prompt_->ShouldShowPermissions()) {
278 layout->AddPaddingRow(0, vertical_padding); 278 layout->AddPaddingRow(0, vertical_padding);
279 layout->StartRow(0, column_set_id); 279 layout->StartRow(0, column_set_id);
280 layout->AddView(new views::Separator(), 3, 1, views::GridLayout::FILL, 280 layout->AddView(new views::Separator(), 3, 1, views::GridLayout::FILL,
281 views::GridLayout::FILL); 281 views::GridLayout::FILL);
282 } 282 }
283 283
284 const int content_width = 284 const int content_width =
285 left_column_width + 285 left_column_width +
286 provider->GetDistanceMetric(DISTANCE_PANEL_CONTENT_MARGIN) + kIconSize; 286 provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL) +
287 kIconSize;
287 288
288 // Create the scrollable view which will contain the permissions and retained 289 // Create the scrollable view which will contain the permissions and retained
289 // files/devices. It will span the full content width. 290 // files/devices. It will span the full content width.
290 CustomScrollableView* scrollable = new CustomScrollableView(); 291 CustomScrollableView* scrollable = new CustomScrollableView();
291 views::GridLayout* scroll_layout = new views::GridLayout(scrollable); 292 views::GridLayout* scroll_layout = new views::GridLayout(scrollable);
292 scrollable->SetLayoutManager(scroll_layout); 293 scrollable->SetLayoutManager(scroll_layout);
293 294
294 views::ColumnSet* scrollable_column_set = 295 views::ColumnSet* scrollable_column_set =
295 scroll_layout->AddColumnSet(column_set_id); 296 scroll_layout->AddColumnSet(column_set_id);
296 297
297 scrollable_column_set->AddColumn( 298 scrollable_column_set->AddColumn(
298 views::GridLayout::LEADING, views::GridLayout::LEADING, 299 views::GridLayout::LEADING, views::GridLayout::LEADING,
299 0, // no resizing 300 0, // no resizing
300 views::GridLayout::USE_PREF, content_width, content_width); 301 views::GridLayout::USE_PREF, content_width, content_width);
301 302
302 // Pad to the very right of the dialog, so the scrollbar will be on the edge. 303 // Pad to the very right of the dialog, so the scrollbar will be on the edge.
303 const int button_margin = 304 const gfx::Insets button_row_insets =
304 provider->GetDistanceMetric(DISTANCE_DIALOG_BUTTON_MARGIN); 305 provider->GetInsetsMetric(views::INSETS_DIALOG_BUTTON_ROW);
305 scrollable_column_set->AddPaddingColumn(0, button_margin); 306 scrollable_column_set->AddPaddingColumn(0, button_row_insets.right());
306 307
307 layout->StartRow(0, column_set_id); 308 layout->StartRow(0, column_set_id);
308 scroll_view_ = new views::ScrollView(); 309 scroll_view_ = new views::ScrollView();
309 scroll_view_->set_hide_horizontal_scrollbar(true); 310 scroll_view_->set_hide_horizontal_scrollbar(true);
310 scroll_view_->SetContents(scrollable); 311 scroll_view_->SetContents(scrollable);
311 layout->AddView(scroll_view_, 4, 1); 312 layout->AddView(scroll_view_, 4, 1);
312 313
313 if (prompt_->ShouldShowPermissions()) { 314 if (prompt_->ShouldShowPermissions()) {
314 bool has_permissions = 315 bool has_permissions =
315 prompt_->GetPermissionCount( 316 prompt_->GetPermissionCount(
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 378
378 DCHECK_GE(prompt_->type(), 0); 379 DCHECK_GE(prompt_->type(), 0);
379 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallPrompt.Type", 380 UMA_HISTOGRAM_ENUMERATION("Extensions.InstallPrompt.Type",
380 prompt_->type(), 381 prompt_->type(),
381 ExtensionInstallPrompt::NUM_PROMPT_TYPES); 382 ExtensionInstallPrompt::NUM_PROMPT_TYPES);
382 383
383 scroll_view_->ClipHeightTo( 384 scroll_view_->ClipHeightTo(
384 0, 385 0,
385 std::min(kScrollViewMaxHeight, scrollable->GetPreferredSize().height())); 386 std::min(kScrollViewMaxHeight, scrollable->GetPreferredSize().height()));
386 387
387 dialog_size_ = gfx::Size(content_width + 2 * button_margin, 388 dialog_size_ = gfx::Size(content_width + button_row_insets.width(),
388 container_->GetPreferredSize().height()); 389 container_->GetPreferredSize().height());
389 390
390 std::string event_name = ExperienceSamplingEvent::kExtensionInstallDialog; 391 std::string event_name = ExperienceSamplingEvent::kExtensionInstallDialog;
391 event_name.append( 392 event_name.append(
392 ExtensionInstallPrompt::PromptTypeToString(prompt_->type())); 393 ExtensionInstallPrompt::PromptTypeToString(prompt_->type()));
393 sampling_event_ = ExperienceSamplingEvent::Create(event_name); 394 sampling_event_ = ExperienceSamplingEvent::Create(event_name);
394 } 395 }
395 396
396 bool ExtensionInstallDialogView::AddPermissions( 397 bool ExtensionInstallDialogView::AddPermissions(
397 views::GridLayout* layout, 398 views::GridLayout* layout,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 } 438 }
438 } 439 }
439 return true; 440 return true;
440 } 441 }
441 442
442 views::GridLayout* ExtensionInstallDialogView::CreateLayout( 443 views::GridLayout* ExtensionInstallDialogView::CreateLayout(
443 int left_column_width, 444 int left_column_width,
444 int column_set_id) { 445 int column_set_id) {
445 container_ = new views::View(); 446 container_ = new views::View();
446 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); 447 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
447 const int horizontal_margin = 448 const gfx::Insets content_insets =
448 provider->GetDistanceMetric(DISTANCE_DIALOG_BUTTON_MARGIN); 449 provider->GetInsetsMetric(views::INSETS_DIALOG_CONTENTS);
449 const int bottom_margin =
450 provider->GetDistanceMetric(DISTANCE_PANEL_CONTENT_MARGIN);
451 450
452 // This is views::GridLayout::CreatePanel(), but without a top or right 451 // This is views::GridLayout::CreatePanel(), but without a top or right
453 // margin. The empty dialog title will then become the top margin, and a 452 // margin. The empty dialog title will then become the top margin, and a
454 // padding column will be manually added to handle a right margin. This is 453 // padding column will be manually added to handle a right margin. This is
455 // done so that the extension icon can be shown on the right of the dialog 454 // done so that the extension icon can be shown on the right of the dialog
456 // title, but on the same y-axis, and the scroll view used to contain other 455 // title, but on the same y-axis, and the scroll view used to contain other
457 // content can have its scrollbar aligned with the right edge of the dialog. 456 // content can have its scrollbar aligned with the right edge of the dialog.
458 views::GridLayout* layout = new views::GridLayout(container_); 457 views::GridLayout* layout = new views::GridLayout(container_);
459 container_->SetLayoutManager(layout); 458 container_->SetLayoutManager(layout);
460 container_->SetBorder( 459 container_->SetBorder(views::CreateEmptyBorder(0, content_insets.left(),
461 views::CreateEmptyBorder(0, horizontal_margin, bottom_margin, 0)); 460 content_insets.bottom(), 0));
462 AddChildView(container_); 461 AddChildView(container_);
463 462
464 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); 463 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id);
465 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 464 column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING,
466 0, // no resizing 465 0, // no resizing
467 views::GridLayout::USE_PREF, 466 views::GridLayout::USE_PREF,
468 0, // no fixed width 467 0, // no fixed width
469 left_column_width); 468 left_column_width);
470 column_set->AddPaddingColumn( 469 column_set->AddPaddingColumn(
471 0, provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL)); 470 0, provider->GetDistanceMetric(DISTANCE_UNRELATED_CONTROL_HORIZONTAL));
472 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING, 471 column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::LEADING,
473 0, // no resizing 472 0, // no resizing
474 views::GridLayout::USE_PREF, 473 views::GridLayout::USE_PREF,
475 0, // no fixed width 474 0, // no fixed width
476 kIconSize); 475 kIconSize);
477 column_set->AddPaddingColumn(0, horizontal_margin); 476 column_set->AddPaddingColumn(0, content_insets.right());
478 477
479 layout->StartRow(0, column_set_id); 478 layout->StartRow(0, column_set_id);
480 views::Label* title = new views::Label(prompt_->GetDialogTitle(), 479 views::Label* title = new views::Label(prompt_->GetDialogTitle(),
481 views::style::CONTEXT_DIALOG_TITLE); 480 views::style::CONTEXT_DIALOG_TITLE);
482 title->SetMultiLine(true); 481 title->SetMultiLine(true);
483 title->SetHorizontalAlignment(gfx::ALIGN_LEFT); 482 title->SetHorizontalAlignment(gfx::ALIGN_LEFT);
484 title->SizeToFit(left_column_width); 483 title->SizeToFit(left_column_width);
485 484
486 // Center align the title along the vertical axis. 485 // Center align the title along the vertical axis.
487 layout->AddView(title, 1, 1, views::GridLayout::LEADING, 486 layout->AddView(title, 1, 1, views::GridLayout::LEADING,
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 gfx::ImageSkia icon = gfx::CreateVectorIcon( 789 gfx::ImageSkia icon = gfx::CreateVectorIcon(
791 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey); 790 expanded ? kCaretUpIcon : kCaretDownIcon, gfx::kChromeIconGrey);
792 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon); 791 arrow_toggle_->SetImage(views::Button::STATE_NORMAL, &icon);
793 } 792 }
794 793
795 // static 794 // static
796 ExtensionInstallPrompt::ShowDialogCallback 795 ExtensionInstallPrompt::ShowDialogCallback
797 ExtensionInstallPrompt::GetViewsShowDialogCallback() { 796 ExtensionInstallPrompt::GetViewsShowDialogCallback() {
798 return base::Bind(&ShowExtensionInstallDialogImpl); 797 return base::Bind(&ShowExtensionInstallDialogImpl);
799 } 798 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698