Commit c2fc3ef3 authored by Hyunjun Shin's avatar Hyunjun Shin Committed by Commit Bot

Prefer unique_ptr to raw pointer to add child view

Call views::View::AddChildView() with unique_pointer.

c/b/u/v/location_bar/* are applied.

Bug: 648382
Change-Id: Iaf34b5d29644beaf5aecea44d39e5eed9f02e340
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1688072Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Reviewed-by: default avatarmanuk hovanesian <manukh@chromium.org>
Commit-Queue: Sang Woo Ko <sangwoo108@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678967}
parent 2f5633df
...@@ -356,6 +356,7 @@ HyeockJin Kim <kherootz@gmail.com> ...@@ -356,6 +356,7 @@ HyeockJin Kim <kherootz@gmail.com>
Hyungchan Kim <inlinechan@gmail.com> Hyungchan Kim <inlinechan@gmail.com>
Hyungwook Lee <hyungwook.lee@navercorp.com> Hyungwook Lee <hyungwook.lee@navercorp.com>
Hyungwook Lee <withlhw@gmail.com> Hyungwook Lee <withlhw@gmail.com>
Hyunjun Shin <hyunjun.shin2@navercorp.com>
Hyunjune Kim <hyunjune.kim@samsung.com> Hyunjune Kim <hyunjune.kim@samsung.com>
Hyunki Baik <hyunki.baik@samsung.com> Hyunki Baik <hyunki.baik@samsung.com>
Ian Cullinan <cullinan@amazon.com> Ian Cullinan <cullinan@amazon.com>
......
...@@ -97,32 +97,32 @@ bool ShouldDisplayUrl(content::WebContents* contents) { ...@@ -97,32 +97,32 @@ bool ShouldDisplayUrl(content::WebContents* contents) {
class CustomTabBarTitleOriginView : public views::View { class CustomTabBarTitleOriginView : public views::View {
public: public:
explicit CustomTabBarTitleOriginView(SkColor background_color) { explicit CustomTabBarTitleOriginView(SkColor background_color) {
title_label_ = new views::Label(base::string16(), CONTEXT_BODY_TEXT_LARGE, auto title_label = std::make_unique<views::Label>(
views::style::TextStyle::STYLE_PRIMARY); base::string16(), CONTEXT_BODY_TEXT_LARGE,
location_label_ = new views::Label( views::style::TextStyle::STYLE_PRIMARY);
auto location_label = std::make_unique<views::Label>(
base::string16(), CONTEXT_BODY_TEXT_SMALL, STYLE_SECONDARY, base::string16(), CONTEXT_BODY_TEXT_SMALL, STYLE_SECONDARY,
gfx::DirectionalityMode::DIRECTIONALITY_AS_URL); gfx::DirectionalityMode::DIRECTIONALITY_AS_URL);
title_label_->SetBackgroundColor(background_color); title_label->SetBackgroundColor(background_color);
title_label_->SetElideBehavior(gfx::ElideBehavior::ELIDE_TAIL); title_label->SetElideBehavior(gfx::ElideBehavior::ELIDE_TAIL);
title_label_->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT); title_label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);
title_label_->SetProperty(views::kFlexBehaviorKey, title_label->SetProperty(views::kFlexBehaviorKey,
views::FlexSpecification::ForSizeRule( views::FlexSpecification::ForSizeRule(
views::MinimumFlexSizeRule::kScaleToMinimum, views::MinimumFlexSizeRule::kScaleToMinimum,
views::MaximumFlexSizeRule::kPreferred)); views::MaximumFlexSizeRule::kPreferred));
location_label_->SetBackgroundColor(background_color); location_label->SetBackgroundColor(background_color);
location_label_->SetElideBehavior(gfx::ElideBehavior::ELIDE_HEAD); location_label->SetElideBehavior(gfx::ElideBehavior::ELIDE_HEAD);
location_label_->SetHorizontalAlignment( location_label->SetHorizontalAlignment(
gfx::HorizontalAlignment::ALIGN_LEFT); gfx::HorizontalAlignment::ALIGN_LEFT);
location_label_->SetProperty( location_label->SetProperty(views::kFlexBehaviorKey,
views::kFlexBehaviorKey, views::FlexSpecification::ForSizeRule(
views::FlexSpecification::ForSizeRule( views::MinimumFlexSizeRule::kScaleToMinimum,
views::MinimumFlexSizeRule::kScaleToMinimum, views::MaximumFlexSizeRule::kPreferred));
views::MaximumFlexSizeRule::kPreferred));
AddChildView(title_label_); title_label_ = AddChildView(std::move(title_label));
AddChildView(location_label_); location_label_ = AddChildView(std::move(location_label));
auto* layout = SetLayoutManager(std::make_unique<views::FlexLayout>()); auto* layout = SetLayoutManager(std::make_unique<views::FlexLayout>());
layout->SetOrientation(views::LayoutOrientation::kVertical) layout->SetOrientation(views::LayoutOrientation::kVertical)
...@@ -203,15 +203,16 @@ CustomTabBarView::CustomTabBarView(BrowserView* browser_view, ...@@ -203,15 +203,16 @@ CustomTabBarView::CustomTabBarView(BrowserView* browser_view,
close_button_ = AddChildView(CreateCloseButton(this, foreground_color)); close_button_ = AddChildView(CreateCloseButton(this, foreground_color));
location_icon_view_ = new LocationIconView(font_list, this); location_icon_view_ =
AddChildView(location_icon_view_); AddChildView(std::make_unique<LocationIconView>(font_list, this));
title_origin_view_ = new CustomTabBarTitleOriginView(background_color_); auto title_origin_view =
title_origin_view_->SetProperty( std::make_unique<CustomTabBarTitleOriginView>(background_color_);
title_origin_view->SetProperty(
views::kFlexBehaviorKey, views::FlexSpecification::ForSizeRule( views::kFlexBehaviorKey, views::FlexSpecification::ForSizeRule(
views::MinimumFlexSizeRule::kScaleToMinimum, views::MinimumFlexSizeRule::kScaleToMinimum,
views::MaximumFlexSizeRule::kPreferred)); views::MaximumFlexSizeRule::kPreferred));
AddChildView(title_origin_view_); title_origin_view_ = AddChildView(std::move(title_origin_view));
layout_manager_ = SetLayoutManager(std::make_unique<views::FlexLayout>()); layout_manager_ = SetLayoutManager(std::make_unique<views::FlexLayout>());
layout_manager_->SetOrientation(views::LayoutOrientation::kHorizontal) layout_manager_->SetOrientation(views::LayoutOrientation::kHorizontal)
......
...@@ -177,49 +177,49 @@ void LocationBarView::Init() { ...@@ -177,49 +177,49 @@ void LocationBarView::Init() {
const gfx::FontList& font_list = views::style::GetFont( const gfx::FontList& font_list = views::style::GetFont(
CONTEXT_OMNIBOX_PRIMARY, views::style::STYLE_PRIMARY); CONTEXT_OMNIBOX_PRIMARY, views::style::STYLE_PRIMARY);
location_icon_view_ = new LocationIconView(font_list, this); auto location_icon_view = std::make_unique<LocationIconView>(font_list, this);
location_icon_view_->set_drag_controller(this); location_icon_view->set_drag_controller(this);
AddChildView(location_icon_view_); location_icon_view_ = AddChildView(std::move(location_icon_view));
// Initialize the Omnibox view. // Initialize the Omnibox view.
omnibox_view_ = new OmniboxViewViews( auto omnibox_view = std::make_unique<OmniboxViewViews>(
this, std::make_unique<ChromeOmniboxClient>(this, profile()), this, std::make_unique<ChromeOmniboxClient>(this, profile()),
is_popup_mode_, this, font_list); is_popup_mode_, this, font_list);
omnibox_view_->Init(); omnibox_view->Init();
AddChildView(omnibox_view_); omnibox_view_ = AddChildView(std::move(omnibox_view));
RefreshBackground(); RefreshBackground();
// Initialize the inline autocomplete view which is visible only when IME is // Initialize the inline autocomplete view which is visible only when IME is
// turned on. Use the same font with the omnibox and highlighted background. // turned on. Use the same font with the omnibox and highlighted background.
ime_inline_autocomplete_view_ = auto ime_inline_autocomplete_view = std::make_unique<views::Label>(
new views::Label(base::string16(), {font_list}); base::string16(), views::Label::CustomFont{font_list});
ime_inline_autocomplete_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT); ime_inline_autocomplete_view->SetHorizontalAlignment(gfx::ALIGN_LEFT);
ime_inline_autocomplete_view_->SetAutoColorReadabilityEnabled(false); ime_inline_autocomplete_view->SetAutoColorReadabilityEnabled(false);
ime_inline_autocomplete_view_->SetBackground(views::CreateSolidBackground( ime_inline_autocomplete_view->SetBackground(views::CreateSolidBackground(
GetColor(OmniboxPart::LOCATION_BAR_IME_AUTOCOMPLETE_BACKGROUND))); GetColor(OmniboxPart::LOCATION_BAR_IME_AUTOCOMPLETE_BACKGROUND)));
ime_inline_autocomplete_view_->SetEnabledColor( ime_inline_autocomplete_view->SetEnabledColor(
GetColor(OmniboxPart::LOCATION_BAR_IME_AUTOCOMPLETE_TEXT)); GetColor(OmniboxPart::LOCATION_BAR_IME_AUTOCOMPLETE_TEXT));
ime_inline_autocomplete_view_->SetVisible(false); ime_inline_autocomplete_view->SetVisible(false);
AddChildView(ime_inline_autocomplete_view_); ime_inline_autocomplete_view_ =
AddChildView(std::move(ime_inline_autocomplete_view));
selected_keyword_view_ = new SelectedKeywordView(this, font_list, profile()); selected_keyword_view_ = AddChildView(
AddChildView(selected_keyword_view_); std::make_unique<SelectedKeywordView>(this, font_list, profile()));
keyword_hint_view_ = new KeywordHintView(this, profile()); keyword_hint_view_ =
AddChildView(keyword_hint_view_); AddChildView(std::make_unique<KeywordHintView>(this, profile()));
SkColor icon_color = GetColor(OmniboxPart::RESULTS_ICON); SkColor icon_color = GetColor(OmniboxPart::RESULTS_ICON);
std::vector<std::unique_ptr<ContentSettingImageModel>> models = std::vector<std::unique_ptr<ContentSettingImageModel>> models =
ContentSettingImageModel::GenerateContentSettingImageModels(); ContentSettingImageModel::GenerateContentSettingImageModels();
for (auto& model : models) { for (auto& model : models) {
ContentSettingImageView* image_view = auto image_view = std::make_unique<ContentSettingImageView>(
new ContentSettingImageView(std::move(model), this, font_list); std::move(model), this, font_list);
image_view->SetIconColor(icon_color); image_view->SetIconColor(icon_color);
content_setting_views_.push_back(image_view);
image_view->SetVisible(false); image_view->SetVisible(false);
AddChildView(image_view); content_setting_views_.push_back(AddChildView(std::move(image_view)));
} }
OmniboxPageActionIconContainerView::Params params; OmniboxPageActionIconContainerView::Params params;
...@@ -259,33 +259,37 @@ void LocationBarView::Init() { ...@@ -259,33 +259,37 @@ void LocationBarView::Init() {
params.browser = browser_; params.browser = browser_;
params.command_updater = command_updater(); params.command_updater = command_updater();
params.page_action_icon_delegate = this; params.page_action_icon_delegate = this;
omnibox_page_action_icon_container_view_ = omnibox_page_action_icon_container_view_ = AddChildView(
new OmniboxPageActionIconContainerView(params); std::make_unique<OmniboxPageActionIconContainerView>(params));
AddChildView(omnibox_page_action_icon_container_view_);
std::vector<std::unique_ptr<PageActionIconView>> page_action_icons;
if (browser_) { if (browser_) {
// Add icons only when feature is not enabled. Otherwise icons will // Add icons only when feature is not enabled. Otherwise icons will
// be added to the ToolbarPageActionIconContainerView. // be added to the ToolbarPageActionIconContainerView.
if (!base::FeatureList::IsEnabled( if (!base::FeatureList::IsEnabled(
autofill::features::kAutofillEnableToolbarStatusChip)) { autofill::features::kAutofillEnableToolbarStatusChip)) {
save_credit_card_icon_view_ = new autofill::SaveCardIconView( auto save_credit_card_icon_view =
command_updater(), browser_, this, font_list); std::make_unique<autofill::SaveCardIconView>(
page_action_icons_.push_back(save_credit_card_icon_view_); command_updater(), browser_, this, font_list);
save_credit_card_icon_view_ = save_credit_card_icon_view.get();
local_card_migration_icon_view_ = page_action_icons.push_back(std::move(save_credit_card_icon_view));
new autofill::LocalCardMigrationIconView(command_updater(), browser_,
this, font_list); auto local_card_migration_icon_view =
page_action_icons_.push_back(local_card_migration_icon_view_); std::make_unique<autofill::LocalCardMigrationIconView>(
command_updater(), browser_, this, font_list);
local_card_migration_icon_view_ = local_card_migration_icon_view.get();
page_action_icons.push_back(std::move(local_card_migration_icon_view));
} }
auto star_view =
page_action_icons_.push_back( std::make_unique<StarView>(command_updater(), browser_, this);
star_view_ = new StarView(command_updater(), browser_, this)); star_view_ = star_view.get();
page_action_icons.push_back(std::move(star_view));
} }
for (PageActionIconView* icon_view : page_action_icons_) { for (auto& icon_view : page_action_icons) {
icon_view->SetVisible(false); icon_view->SetVisible(false);
icon_view->SetIconColor(icon_color); icon_view->SetIconColor(icon_color);
AddChildView(icon_view); page_action_icons_.push_back(AddChildView(std::move(icon_view)));
} }
auto clear_all_button = views::CreateVectorImageButton(this); auto clear_all_button = views::CreateVectorImageButton(this);
......
...@@ -51,6 +51,8 @@ class PageActionIconView : public IconLabelBubbleView { ...@@ -51,6 +51,8 @@ class PageActionIconView : public IconLabelBubbleView {
virtual const OmniboxView* GetOmniboxView() const; virtual const OmniboxView* GetOmniboxView() const;
}; };
~PageActionIconView() override;
// Updates the color of the icon, this must be set before the icon is drawn. // Updates the color of the icon, this must be set before the icon is drawn.
void SetIconColor(SkColor icon_color); void SetIconColor(SkColor icon_color);
...@@ -81,7 +83,6 @@ class PageActionIconView : public IconLabelBubbleView { ...@@ -81,7 +83,6 @@ class PageActionIconView : public IconLabelBubbleView {
int command_id, int command_id,
Delegate* delegate, Delegate* delegate,
const gfx::FontList& = gfx::FontList()); const gfx::FontList& = gfx::FontList());
~PageActionIconView() override;
// Returns true if a related bubble is showing. // Returns true if a related bubble is showing.
bool IsBubbleShowing() const override; bool IsBubbleShowing() const override;
......
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