Commit 1aed0eb8 authored by Allen Bauer's avatar Allen Bauer Committed by Commit Bot

Return std::unique_ptr from ScrollView::CreateScrollViewWithBorder().

Bug: 966519
Change-Id: I9473da0496cfa56151773e1a218f55f8769a1419
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1627751
Commit-Queue: Allen Bauer <kylixrd@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663106}
parent 88b55c4c
...@@ -740,8 +740,10 @@ LockDebugView::LockDebugView(mojom::TrayActionState initial_note_action_state, ...@@ -740,8 +740,10 @@ LockDebugView::LockDebugView(mojom::TrayActionState initial_note_action_state,
std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical)); std::make_unique<views::BoxLayout>(views::BoxLayout::kVertical));
UpdatePerUserActionContainer(); UpdatePerUserActionContainer();
auto make_scroll = [](views::View* content, int height) -> views::View* { auto make_scroll = [](views::View* content,
views::ScrollView* scroll = views::ScrollView::CreateScrollViewWithBorder(); int height) -> std::unique_ptr<views::View> {
std::unique_ptr<views::ScrollView> scroll =
views::ScrollView::CreateScrollViewWithBorder();
scroll->SetPreferredSize(gfx::Size(600, height)); scroll->SetPreferredSize(gfx::Size(600, height));
scroll->SetContents(base::WrapUnique(content)); scroll->SetContents(base::WrapUnique(content));
scroll->SetBackgroundColor(SK_ColorTRANSPARENT); scroll->SetBackgroundColor(SK_ColorTRANSPARENT);
......
...@@ -490,8 +490,8 @@ views::View* CollectedCookiesViews::CreateAllowedPane() { ...@@ -490,8 +490,8 @@ views::View* CollectedCookiesViews::CreateAllowedPane() {
layout->StartRow(1.0, single_column_layout_id); layout->StartRow(1.0, single_column_layout_id);
allowed_cookies_tree_ = allowed_cookies_tree.get(); allowed_cookies_tree_ = allowed_cookies_tree.get();
layout->AddView(CreateScrollView(std::move(allowed_cookies_tree)), 1, 1, layout->AddView(CreateScrollView(std::move(allowed_cookies_tree)).release(),
views::GridLayout::FILL, views::GridLayout::FILL, 1, 1, views::GridLayout::FILL, views::GridLayout::FILL,
kTreeViewWidth, kTreeViewHeight); kTreeViewWidth, kTreeViewHeight);
layout->AddPaddingRow(views::GridLayout::kFixedSize, layout->AddPaddingRow(views::GridLayout::kFixedSize,
unrelated_vertical_distance); unrelated_vertical_distance);
...@@ -557,8 +557,8 @@ views::View* CollectedCookiesViews::CreateBlockedPane() { ...@@ -557,8 +557,8 @@ views::View* CollectedCookiesViews::CreateBlockedPane() {
layout->StartRow(1.0, single_column_layout_id); layout->StartRow(1.0, single_column_layout_id);
blocked_cookies_tree_ = blocked_cookies_tree.get(); blocked_cookies_tree_ = blocked_cookies_tree.get();
layout->AddView(CreateScrollView(std::move(blocked_cookies_tree)), 1, 1, layout->AddView(CreateScrollView(std::move(blocked_cookies_tree)).release(),
views::GridLayout::FILL, views::GridLayout::FILL, 1, 1, views::GridLayout::FILL, views::GridLayout::FILL,
kTreeViewWidth, kTreeViewHeight); kTreeViewWidth, kTreeViewHeight);
layout->AddPaddingRow(views::GridLayout::kFixedSize, layout->AddPaddingRow(views::GridLayout::kFixedSize,
unrelated_vertical_distance); unrelated_vertical_distance);
...@@ -615,10 +615,9 @@ std::unique_ptr<views::View> CollectedCookiesViews::CreateButtonsPane() { ...@@ -615,10 +615,9 @@ std::unique_ptr<views::View> CollectedCookiesViews::CreateButtonsPane() {
return view; return view;
} }
views::View* CollectedCookiesViews::CreateScrollView( std::unique_ptr<views::View> CollectedCookiesViews::CreateScrollView(
std::unique_ptr<views::TreeView> pane) { std::unique_ptr<views::TreeView> pane) {
views::ScrollView* scroll_view = auto scroll_view = views::ScrollView::CreateScrollViewWithBorder();
views::ScrollView::CreateScrollViewWithBorder();
scroll_view->SetContents(std::move(pane)); scroll_view->SetContents(std::move(pane));
return scroll_view; return scroll_view;
} }
......
...@@ -85,7 +85,8 @@ class CollectedCookiesViews : public views::DialogDelegateView, ...@@ -85,7 +85,8 @@ class CollectedCookiesViews : public views::DialogDelegateView,
std::unique_ptr<views::View> CreateButtonsPane(); std::unique_ptr<views::View> CreateButtonsPane();
// Creates and returns a containing ScrollView around the given tree view. // Creates and returns a containing ScrollView around the given tree view.
views::View* CreateScrollView(std::unique_ptr<views::TreeView> pane); std::unique_ptr<views::View> CreateScrollView(
std::unique_ptr<views::TreeView> pane);
void EnableControls(); void EnableControls();
......
...@@ -103,7 +103,7 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( ...@@ -103,7 +103,7 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
2, // selection_border_thickness 2, // selection_border_thickness
5); // focus_rectangle_inset 5); // focus_rectangle_inset
views::ScrollView* screen_scroll_view = std::unique_ptr<views::ScrollView> screen_scroll_view =
views::ScrollView::CreateScrollViewWithBorder(); views::ScrollView::CreateScrollViewWithBorder();
base::string16 screen_title_text = l10n_util::GetStringUTF16( base::string16 screen_title_text = l10n_util::GetStringUTF16(
IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_SCREEN); IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_SCREEN);
...@@ -118,7 +118,7 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( ...@@ -118,7 +118,7 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
kGenericScreenStyle.item_size.height() * 2); kGenericScreenStyle.item_size.height() * 2);
screen_scroll_view->set_hide_horizontal_scrollbar(true); screen_scroll_view->set_hide_horizontal_scrollbar(true);
pane_->AddTab(screen_title_text, screen_scroll_view); pane_->AddTab(screen_title_text, screen_scroll_view.release());
pane_->set_listener(this); pane_->set_listener(this);
break; break;
} }
...@@ -135,7 +135,7 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( ...@@ -135,7 +135,7 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
2, // selection_border_thickness 2, // selection_border_thickness
5); // focus_rectangle_inset 5); // focus_rectangle_inset
views::ScrollView* window_scroll_view = std::unique_ptr<views::ScrollView> window_scroll_view =
views::ScrollView::CreateScrollViewWithBorder(); views::ScrollView::CreateScrollViewWithBorder();
base::string16 window_title_text = l10n_util::GetStringUTF16( base::string16 window_title_text = l10n_util::GetStringUTF16(
IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_WINDOW); IDS_DESKTOP_MEDIA_PICKER_SOURCE_TYPE_WINDOW);
...@@ -149,7 +149,7 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView( ...@@ -149,7 +149,7 @@ DesktopMediaPickerDialogView::DesktopMediaPickerDialogView(
kWindowStyle.item_size.height() * 2); kWindowStyle.item_size.height() * 2);
window_scroll_view->set_hide_horizontal_scrollbar(true); window_scroll_view->set_hide_horizontal_scrollbar(true);
pane_->AddTab(window_title_text, window_scroll_view); pane_->AddTab(window_title_text, window_scroll_view.release());
pane_->set_listener(this); pane_->set_listener(this);
break; break;
} }
......
...@@ -116,14 +116,16 @@ void MediaGalleriesDialogViews::InitChildViews() { ...@@ -116,14 +116,16 @@ void MediaGalleriesDialogViews::InitChildViews() {
// Message text. // Message text.
const int vertical_padding = const int vertical_padding =
provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL); provider->GetDistanceMetric(views::DISTANCE_RELATED_CONTROL_VERTICAL);
views::Label* subtext = new views::Label(controller_->GetSubtext()); auto subtext = std::make_unique<views::Label>(controller_->GetSubtext());
subtext->SetMultiLine(true); subtext->SetMultiLine(true);
subtext->SetHorizontalAlignment(gfx::ALIGN_LEFT); subtext->SetHorizontalAlignment(gfx::ALIGN_LEFT);
// Get the height here rather than inline because the order of evaluation for
// parameters may differ between platforms.
const int subtext_height = subtext->GetHeightForWidth(dialog_content_width);
layout->StartRow(views::GridLayout::kFixedSize, column_set_id); layout->StartRow(views::GridLayout::kFixedSize, column_set_id);
layout->AddView( layout->AddView(subtext.release(), 1, 1, views::GridLayout::FILL,
subtext, 1, 1, views::GridLayout::LEADING, dialog_content_width,
views::GridLayout::FILL, views::GridLayout::LEADING, subtext_height);
dialog_content_width, subtext->GetHeightForWidth(dialog_content_width));
layout->AddPaddingRow(views::GridLayout::kFixedSize, vertical_padding); layout->AddPaddingRow(views::GridLayout::kFixedSize, vertical_padding);
// Scrollable area for checkboxes. // Scrollable area for checkboxes.
...@@ -143,17 +145,16 @@ void MediaGalleriesDialogViews::InitChildViews() { ...@@ -143,17 +145,16 @@ void MediaGalleriesDialogViews::InitChildViews() {
// Header and separator line. // Header and separator line.
if (!section_headers[i].empty() && !entries.empty()) { if (!section_headers[i].empty() && !entries.empty()) {
views::Separator* separator = new views::Separator(); scroll_container->AddChildView(std::make_unique<views::Separator>());
scroll_container->AddChildView(separator);
views::Label* header = new views::Label(section_headers[i]); auto header = std::make_unique<views::Label>(section_headers[i]);
header->SetMultiLine(true); header->SetMultiLine(true);
header->SetHorizontalAlignment(gfx::ALIGN_LEFT); header->SetHorizontalAlignment(gfx::ALIGN_LEFT);
header->SetBorder(views::CreateEmptyBorder( header->SetBorder(views::CreateEmptyBorder(
vertical_padding, vertical_padding,
provider->GetInsetsMetric(views::INSETS_DIALOG).left(), provider->GetInsetsMetric(views::INSETS_DIALOG).left(),
vertical_padding, 0)); vertical_padding, 0));
scroll_container->AddChildView(header); scroll_container->AddChildView(std::move(header));
} }
// Checkboxes. // Checkboxes.
...@@ -168,11 +169,11 @@ void MediaGalleriesDialogViews::InitChildViews() { ...@@ -168,11 +169,11 @@ void MediaGalleriesDialogViews::InitChildViews() {
// Add the scrollable area to the outer dialog view. It will squeeze against // Add the scrollable area to the outer dialog view. It will squeeze against
// the title/subtitle and buttons to occupy all available space in the dialog. // the title/subtitle and buttons to occupy all available space in the dialog.
auto* scroll_view = views::ScrollView::CreateScrollViewWithBorder(); auto scroll_view = views::ScrollView::CreateScrollViewWithBorder();
scroll_view->SetContents(std::move(scroll_container)); scroll_view->SetContents(std::move(scroll_container));
layout->StartRowWithPadding(1.0, column_set_id, views::GridLayout::kFixedSize, layout->StartRowWithPadding(1.0, column_set_id, views::GridLayout::kFixedSize,
vertical_padding); vertical_padding);
layout->AddView(scroll_view, 1.0, 1.0, views::GridLayout::FILL, layout->AddView(scroll_view.release(), 1.0, 1.0, views::GridLayout::FILL,
views::GridLayout::FILL, dialog_content_width, views::GridLayout::FILL, dialog_content_width,
kScrollAreaHeight); kScrollAreaHeight);
} }
......
...@@ -224,8 +224,8 @@ ScrollView::~ScrollView() { ...@@ -224,8 +224,8 @@ ScrollView::~ScrollView() {
} }
// static // static
ScrollView* ScrollView::CreateScrollViewWithBorder() { std::unique_ptr<ScrollView> ScrollView::CreateScrollViewWithBorder() {
auto* scroll_view = new ScrollView(); auto scroll_view = std::make_unique<ScrollView>();
scroll_view->AddBorder(); scroll_view->AddBorder();
return scroll_view; return scroll_view;
} }
......
...@@ -50,7 +50,7 @@ class VIEWS_EXPORT ScrollView : public View, public ScrollBarController { ...@@ -50,7 +50,7 @@ class VIEWS_EXPORT ScrollView : public View, public ScrollBarController {
~ScrollView() override; ~ScrollView() override;
// Creates a ScrollView with a theme specific border. // Creates a ScrollView with a theme specific border.
static ScrollView* CreateScrollViewWithBorder(); static std::unique_ptr<ScrollView> CreateScrollViewWithBorder();
// Returns the ScrollView for which |contents| is its contents, or null if // Returns the ScrollView for which |contents| is its contents, or null if
// |contents| is not in a ScrollView. // |contents| is not in a ScrollView.
......
...@@ -170,7 +170,7 @@ TableView::~TableView() { ...@@ -170,7 +170,7 @@ TableView::~TableView() {
// static // static
std::unique_ptr<ScrollView> TableView::CreateScrollViewWithTable( std::unique_ptr<ScrollView> TableView::CreateScrollViewWithTable(
std::unique_ptr<TableView> table) { std::unique_ptr<TableView> table) {
auto scroll_view = base::WrapUnique(ScrollView::CreateScrollViewWithBorder()); auto scroll_view = ScrollView::CreateScrollViewWithBorder();
auto* table_ptr = table.get(); auto* table_ptr = table.get();
scroll_view->SetContents(std::move(table)); scroll_view->SetContents(std::move(table));
table_ptr->CreateHeaderIfNecessary(scroll_view.get()); table_ptr->CreateHeaderIfNecessary(scroll_view.get());
......
...@@ -115,7 +115,7 @@ TreeView::~TreeView() { ...@@ -115,7 +115,7 @@ TreeView::~TreeView() {
// static // static
std::unique_ptr<ScrollView> TreeView::CreateScrollViewWithTree( std::unique_ptr<ScrollView> TreeView::CreateScrollViewWithTree(
std::unique_ptr<TreeView> tree) { std::unique_ptr<TreeView> tree) {
auto scroll_view = base::WrapUnique(ScrollView::CreateScrollViewWithBorder()); auto scroll_view = ScrollView::CreateScrollViewWithBorder();
scroll_view->SetContents(std::move(tree)); scroll_view->SetContents(std::move(tree));
return scroll_view; return scroll_view;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment