Commit 488df1af authored by Robert Liao's avatar Robert Liao Committed by Commit Bot

Update LayoutExampleBase::CreateCombobox to Use Ownership Best Practices

CreateCombobox is now known as CreateAndAddCombobox.

Change-Id: I6143d33c0ee9efdf7c0a63d20deb6d23e9bb969d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2169377
Auto-Submit: Robert Liao <robliao@chromium.org>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Commit-Queue: Robert Liao <robliao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#763560}
parent 7c40a304
......@@ -38,12 +38,12 @@ void BoxLayoutExample::CreateAdditionalControls(int vertical_pos) {
static const char* cross_axis_values[4] = {"Stretch", "Start", "Center",
"End"};
orientation_ = CreateCombobox(base::ASCIIToUTF16("Orientation"),
orientation_values, 2, &vertical_pos);
main_axis_alignment_ = CreateCombobox(base::ASCIIToUTF16("Main axis"),
main_axis_values, 3, &vertical_pos);
cross_axis_alignment_ = CreateCombobox(base::ASCIIToUTF16("Cross axis"),
cross_axis_values, 4, &vertical_pos);
orientation_ = CreateAndAddCombobox(base::ASCIIToUTF16("Orientation"),
orientation_values, 2, &vertical_pos);
main_axis_alignment_ = CreateAndAddCombobox(
base::ASCIIToUTF16("Main axis"), main_axis_values, 3, &vertical_pos);
cross_axis_alignment_ = CreateAndAddCombobox(
base::ASCIIToUTF16("Cross axis"), cross_axis_values, 4, &vertical_pos);
between_child_spacing_ =
CreateTextfield(base::ASCIIToUTF16("Child spacing"), &vertical_pos);
......
......@@ -38,12 +38,12 @@ void FlexLayoutExample::CreateAdditionalControls(int vertical_pos) {
static const char* const cross_axis_values[4] = {"Stretch", "Start", "Center",
"End"};
orientation_ = CreateCombobox(base::ASCIIToUTF16("Orientation"),
orientation_values, 2, &vertical_pos);
main_axis_alignment_ = CreateCombobox(base::ASCIIToUTF16("Main axis"),
main_axis_values, 3, &vertical_pos);
cross_axis_alignment_ = CreateCombobox(base::ASCIIToUTF16("Cross axis"),
cross_axis_values, 4, &vertical_pos);
orientation_ = CreateAndAddCombobox(base::ASCIIToUTF16("Orientation"),
orientation_values, 2, &vertical_pos);
main_axis_alignment_ = CreateAndAddCombobox(
base::ASCIIToUTF16("Main axis"), main_axis_values, 3, &vertical_pos);
cross_axis_alignment_ = CreateAndAddCombobox(
base::ASCIIToUTF16("Cross axis"), cross_axis_values, 4, &vertical_pos);
CreateMarginsTextFields(base::ASCIIToUTF16("Interior margin"),
&interior_margin_, &vertical_pos);
......
......@@ -139,25 +139,28 @@ LayoutExampleBase::LayoutExampleBase(const char* title) : ExampleBase(title) {}
LayoutExampleBase::~LayoutExampleBase() = default;
Combobox* LayoutExampleBase::CreateCombobox(const base::string16& label_text,
const char* const* items,
int count,
int* vertical_pos) {
Label* label = new Label(label_text);
Combobox* LayoutExampleBase::CreateAndAddCombobox(
const base::string16& label_text,
const char* const* items,
int count,
int* vertical_pos) {
auto label = std::make_unique<Label>(label_text);
label->SetPosition(gfx::Point(kLayoutExampleLeftPadding, *vertical_pos));
label->SizeToPreferredSize();
Combobox* combo_box =
new Combobox(std::make_unique<ExampleComboboxModel>(items, count));
auto combo_box = std::make_unique<Combobox>(
std::make_unique<ExampleComboboxModel>(items, count));
combo_box->SetPosition(
gfx::Point(label->x() + label->width() + kLayoutExampleVerticalSpacing,
*vertical_pos));
combo_box->SizeToPreferredSize();
combo_box->set_listener(this);
label->SetSize(gfx::Size(label->width(), combo_box->height()));
control_panel_->AddChildView(label);
control_panel_->AddChildView(combo_box);
*vertical_pos += combo_box->height() + kLayoutExampleVerticalSpacing;
return combo_box;
control_panel_->AddChildView(std::move(label));
auto* combo_box_ptr = control_panel_->AddChildView(std::move(combo_box));
*vertical_pos += combo_box_ptr->height() + kLayoutExampleVerticalSpacing;
return combo_box_ptr;
}
Textfield* LayoutExampleBase::CreateRawTextfield(int vertical_pos,
......
......@@ -81,12 +81,12 @@ class VIEWS_EXAMPLES_EXPORT LayoutExampleBase : public ExampleBase,
protected:
View* layout_panel() { return layout_panel_; }
// Creates a Combobox with a label with |label_text| to the left. Adjust
// |vertical_pos| to |vertical_pos| + combo_box->height() + kSpacing.
Combobox* CreateCombobox(const base::string16& label_text,
const char* const* items,
int count,
int* vertical_pos);
// Creates and adds a Combobox with a label with |label_text| to the left.
// Adjust |vertical_pos| to |vertical_pos| + combo_box->height() + kSpacing.
Combobox* CreateAndAddCombobox(const base::string16& label_text,
const char* const* items,
int count,
int* vertical_pos);
// Creates just a Textfield at the current position of |horizontal_pos| and
// |vertical_pos|. Update |horizontal_pos| to |horizontal_pos| +
......
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