refactor: migrate to View::AddChildView(std::unique_ptr<ui::View*>)
(#46474)
* refactor: use AddChildView(std::unique_ptr<View>) in OpaqueFrameView::CreateButton() Xref: https://issues.chromium.org/issues/40485510 * refactor: use AddChildView(std::unique_ptr<View>) in MenuBar::RebuildChildren() * refactor: use AddChildView(std::unique_ptr<View>) for ClientFrameViewLinux labels * refactor: use AddChildView(std::unique_ptr<View>) for ClientFrameViewLinux buttons * refactor: use AddChildView(std::unique_ptr<View>) in AutofillPopupView * refactor: use AddChildViewRaw() to flag the edge cases that we still need to fix * chore: use west coast const for consistency
This commit is contained in:
parent
a6875c732c
commit
85dce12be3
10 changed files with 30 additions and 32 deletions
|
@ -323,7 +323,7 @@ void NativeWindowMac::SetContentView(views::View* view) {
|
||||||
root_view->RemoveChildView(content_view());
|
root_view->RemoveChildView(content_view());
|
||||||
|
|
||||||
set_content_view(view);
|
set_content_view(view);
|
||||||
root_view->AddChildView(content_view());
|
root_view->AddChildViewRaw(content_view());
|
||||||
|
|
||||||
root_view->DeprecatedLayoutImmediately();
|
root_view->DeprecatedLayoutImmediately();
|
||||||
}
|
}
|
||||||
|
|
|
@ -480,7 +480,7 @@ void NativeWindowViews::SetContentView(views::View* view) {
|
||||||
}
|
}
|
||||||
set_content_view(view);
|
set_content_view(view);
|
||||||
focused_view_ = view;
|
focused_view_ = view;
|
||||||
root_view_.GetMainView()->AddChildView(content_view());
|
root_view_.GetMainView()->AddChildViewRaw(content_view());
|
||||||
root_view_.GetMainView()->DeprecatedLayoutImmediately();
|
root_view_.GetMainView()->DeprecatedLayoutImmediately();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -90,8 +90,8 @@ InspectableWebContentsView::InspectableWebContentsView(
|
||||||
}
|
}
|
||||||
|
|
||||||
devtools_web_view_->SetVisible(false);
|
devtools_web_view_->SetVisible(false);
|
||||||
AddChildView(devtools_web_view_.get());
|
AddChildViewRaw(devtools_web_view_.get());
|
||||||
AddChildView(GetContentsView());
|
AddChildViewRaw(GetContentsView());
|
||||||
}
|
}
|
||||||
|
|
||||||
InspectableWebContentsView::~InspectableWebContentsView() {
|
InspectableWebContentsView::~InspectableWebContentsView() {
|
||||||
|
|
|
@ -215,9 +215,10 @@ void AutofillPopupView::CreateChildViews() {
|
||||||
RemoveAllChildViews();
|
RemoveAllChildViews();
|
||||||
|
|
||||||
for (int i = 0; i < popup_->line_count(); ++i) {
|
for (int i = 0; i < popup_->line_count(); ++i) {
|
||||||
auto* child_view = new AutofillPopupChildView(popup_->value_at(i));
|
auto child_view =
|
||||||
|
std::make_unique<AutofillPopupChildView>(popup_->value_at(i));
|
||||||
child_view->set_drag_controller(this);
|
child_view->set_drag_controller(this);
|
||||||
AddChildView(child_view);
|
AddChildView(std::move(child_view));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,6 @@ class AutofillPopupChildView : public views::View {
|
||||||
AutofillPopupChildView(const AutofillPopupChildView&) = delete;
|
AutofillPopupChildView(const AutofillPopupChildView&) = delete;
|
||||||
AutofillPopupChildView& operator=(const AutofillPopupChildView&) = delete;
|
AutofillPopupChildView& operator=(const AutofillPopupChildView&) = delete;
|
||||||
|
|
||||||
private:
|
|
||||||
~AutofillPopupChildView() override = default;
|
~AutofillPopupChildView() override = default;
|
||||||
|
|
||||||
std::u16string suggestion_;
|
std::u16string suggestion_;
|
||||||
|
|
|
@ -84,20 +84,20 @@ ClientFrameViewLinux::ClientFrameViewLinux()
|
||||||
views::FrameButton::kMaximize,
|
views::FrameButton::kMaximize,
|
||||||
views::FrameButton::kClose} {
|
views::FrameButton::kClose} {
|
||||||
for (auto& button : nav_buttons_) {
|
for (auto& button : nav_buttons_) {
|
||||||
button.button = new views::ImageButton();
|
auto image_button = std::make_unique<views::ImageButton>();
|
||||||
button.button->SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE);
|
image_button->SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE);
|
||||||
button.button->SetAccessibleName(
|
image_button->SetAccessibleName(
|
||||||
l10n_util::GetStringUTF16(button.accessibility_id));
|
l10n_util::GetStringUTF16(button.accessibility_id));
|
||||||
AddChildView(button.button);
|
button.button = AddChildView(std::move(image_button));
|
||||||
}
|
}
|
||||||
|
|
||||||
title_ = new views::Label();
|
auto title = std::make_unique<views::Label>();
|
||||||
title_->SetSubpixelRenderingEnabled(false);
|
title->SetSubpixelRenderingEnabled(false);
|
||||||
title_->SetAutoColorReadabilityEnabled(false);
|
title->SetAutoColorReadabilityEnabled(false);
|
||||||
title_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
|
title->SetHorizontalAlignment(gfx::ALIGN_CENTER);
|
||||||
title_->SetVerticalAlignment(gfx::ALIGN_MIDDLE);
|
title->SetVerticalAlignment(gfx::ALIGN_MIDDLE);
|
||||||
title_->SetTextStyle(views::style::STYLE_TAB_ACTIVE);
|
title->SetTextStyle(views::style::STYLE_TAB_ACTIVE);
|
||||||
AddChildView(title_);
|
title_ = AddChildView(std::move(title));
|
||||||
|
|
||||||
native_theme_observer_.Observe(theme_);
|
native_theme_observer_.Observe(theme_);
|
||||||
|
|
||||||
|
@ -293,8 +293,7 @@ void ClientFrameViewLinux::Layout(PassKey) {
|
||||||
title_bounds.Inset(theme_values_.title_padding);
|
title_bounds.Inset(theme_values_.title_padding);
|
||||||
|
|
||||||
title_->SetVisible(true);
|
title_->SetVisible(true);
|
||||||
title_->SetBounds(title_bounds.x(), title_bounds.y(), title_bounds.width(),
|
title_->SetBoundsRect(title_bounds);
|
||||||
title_bounds.height());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientFrameViewLinux::OnPaint(gfx::Canvas* canvas) {
|
void ClientFrameViewLinux::OnPaint(gfx::Canvas* canvas) {
|
||||||
|
|
|
@ -95,7 +95,7 @@ class ClientFrameViewLinux : public FramelessView,
|
||||||
void (views::Widget::*callback)();
|
void (views::Widget::*callback)();
|
||||||
int accessibility_id;
|
int accessibility_id;
|
||||||
int hit_test_id;
|
int hit_test_id;
|
||||||
RAW_PTR_EXCLUSION views::ImageButton* button{nullptr};
|
raw_ptr<views::ImageButton> button = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ThemeValues {
|
struct ThemeValues {
|
||||||
|
@ -132,7 +132,7 @@ class ClientFrameViewLinux : public FramelessView,
|
||||||
raw_ptr<ui::NativeTheme> theme_;
|
raw_ptr<ui::NativeTheme> theme_;
|
||||||
ThemeValues theme_values_;
|
ThemeValues theme_values_;
|
||||||
|
|
||||||
RAW_PTR_EXCLUSION views::Label* title_;
|
raw_ptr<views::Label> title_;
|
||||||
|
|
||||||
std::unique_ptr<ui::NavButtonProvider> nav_button_provider_;
|
std::unique_ptr<ui::NavButtonProvider> nav_button_provider_;
|
||||||
std::array<NavButton, kNavButtonCount> nav_buttons_;
|
std::array<NavButton, kNavButtonCount> nav_buttons_;
|
||||||
|
|
|
@ -229,11 +229,11 @@ void MenuBar::RefreshColorCache(const ui::NativeTheme* theme) {
|
||||||
void MenuBar::RebuildChildren() {
|
void MenuBar::RebuildChildren() {
|
||||||
RemoveAllChildViews();
|
RemoveAllChildViews();
|
||||||
for (size_t i = 0, n = GetItemCount(); i < n; ++i) {
|
for (size_t i = 0, n = GetItemCount(); i < n; ++i) {
|
||||||
auto* button = new SubmenuButton(
|
auto button = std::make_unique<SubmenuButton>(
|
||||||
base::BindRepeating(&MenuBar::ButtonPressed, base::Unretained(this), i),
|
base::BindRepeating(&MenuBar::ButtonPressed, base::Unretained(this), i),
|
||||||
menu_model_->GetLabelAt(i), background_color_);
|
menu_model_->GetLabelAt(i), background_color_);
|
||||||
button->SetID(i);
|
button->SetID(i);
|
||||||
AddChildView(button);
|
AddChildView(std::move(button));
|
||||||
}
|
}
|
||||||
UpdateViewColors();
|
UpdateViewColors();
|
||||||
}
|
}
|
||||||
|
|
|
@ -297,7 +297,7 @@ views::Button* OpaqueFrameView::CreateButton(
|
||||||
int ht_component,
|
int ht_component,
|
||||||
const gfx::VectorIcon& icon_image,
|
const gfx::VectorIcon& icon_image,
|
||||||
views::Button::PressedCallback callback) {
|
views::Button::PressedCallback callback) {
|
||||||
views::FrameCaptionButton* button = new views::FrameCaptionButton(
|
auto button = std::make_unique<views::FrameCaptionButton>(
|
||||||
views::Button::PressedCallback(), icon_type, ht_component);
|
views::Button::PressedCallback(), icon_type, ht_component);
|
||||||
button->SetImage(button->GetIcon(), views::FrameCaptionButton::Animate::kNo,
|
button->SetImage(button->GetIcon(), views::FrameCaptionButton::Animate::kNo,
|
||||||
icon_image);
|
icon_image);
|
||||||
|
@ -306,12 +306,11 @@ views::Button* OpaqueFrameView::CreateButton(
|
||||||
button->SetCallback(std::move(callback));
|
button->SetCallback(std::move(callback));
|
||||||
button->SetAccessibleName(l10n_util::GetStringUTF16(accessibility_string_id));
|
button->SetAccessibleName(l10n_util::GetStringUTF16(accessibility_string_id));
|
||||||
button->SetID(view_id);
|
button->SetID(view_id);
|
||||||
AddChildView(button);
|
|
||||||
|
|
||||||
button->SetPaintToLayer();
|
button->SetPaintToLayer();
|
||||||
button->layer()->SetFillsBoundsOpaquely(false);
|
button->layer()->SetFillsBoundsOpaquely(false);
|
||||||
|
|
||||||
return button;
|
return AddChildView(std::move(button));
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Insets OpaqueFrameView::FrameBorderInsets(bool restored) const {
|
gfx::Insets OpaqueFrameView::FrameBorderInsets(bool restored) const {
|
||||||
|
|
|
@ -67,11 +67,11 @@ class WinCaptionButtonContainer : public views::View,
|
||||||
void OnWidgetBoundsChanged(views::Widget* widget,
|
void OnWidgetBoundsChanged(views::Widget* widget,
|
||||||
const gfx::Rect& new_bounds) override;
|
const gfx::Rect& new_bounds) override;
|
||||||
|
|
||||||
raw_ptr<WinFrameView> const frame_view_;
|
const raw_ptr<WinFrameView> frame_view_;
|
||||||
raw_ptr<WinCaptionButton> const minimize_button_;
|
const raw_ptr<WinCaptionButton> minimize_button_;
|
||||||
raw_ptr<WinCaptionButton> const maximize_button_;
|
const raw_ptr<WinCaptionButton> maximize_button_;
|
||||||
raw_ptr<WinCaptionButton> const restore_button_;
|
const raw_ptr<WinCaptionButton> restore_button_;
|
||||||
raw_ptr<WinCaptionButton> const close_button_;
|
const raw_ptr<WinCaptionButton> close_button_;
|
||||||
|
|
||||||
base::ScopedObservation<views::Widget, views::WidgetObserver>
|
base::ScopedObservation<views::Widget, views::WidgetObserver>
|
||||||
widget_observation_{this};
|
widget_observation_{this};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue