From c0ab2fd1fd060bdea97b71dd7734fb7293783b1f Mon Sep 17 00:00:00 2001 From: Henrique Ferreiro Date: Tue, 9 Oct 2018 10:10:33 +0200 Subject: [PATCH] Forward preferred size changes from `BraveActionsContainer` When a `BraveAction` is added, the size change isn't properly notified to `BraveLocationBarView`. This commit implements `ChildPreferredSizeChanged()` in both `BraveActionsContainer` and `BraveLocationBarView`, and makes sure the action's preferred size is set after calling `AddChildView()`. Fixes https://github.com/brave/brave-browser/issues/1276 --- .../brave_actions/brave_actions_container.cc | 16 +++++++++++----- .../brave_actions/brave_actions_container.h | 3 +++ .../location_bar/brave_location_bar_view.cc | 7 +++++++ .../views/location_bar/brave_location_bar_view.h | 3 +++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/browser/ui/views/brave_actions/brave_actions_container.cc b/browser/ui/views/brave_actions/brave_actions_container.cc index 9418b7765d49..f9de0748fca9 100644 --- a/browser/ui/views/brave_actions/brave_actions_container.cc +++ b/browser/ui/views/brave_actions/brave_actions_container.cc @@ -105,18 +105,20 @@ void BraveActionsContainer::AddAction(const extensions::Extension* extension, // The button view actions_[id].view_ = std::make_unique( actions_[id].view_controller_.get(), this); - // we control destruction - actions_[id].view_->set_owned_by_client(); - // Sets overall size of button but not image graphic. We set a large width - // in order to give space for the bubble. - actions_[id].view_->SetPreferredSize(gfx::Size(32, 24)); // Add extension view after separator view + // `AddChildView` should be called first, so that changes that modify + // layout (e.g. preferred size) are forwarded to its parent if (actions_[id].position_ != ACTION_ANY_POSITION) { DCHECK(actions_[id].position_ > 0); AddChildViewAt(actions_[id].view_.get(), actions_[id].position_); } else { AddChildView(actions_[id].view_.get()); } + // we control destruction + actions_[id].view_->set_owned_by_client(); + // Sets overall size of button but not image graphic. We set a large width + // in order to give space for the bubble. + actions_[id].view_->SetPreferredSize(gfx::Size(32, 24)); Update(); } } @@ -244,3 +246,7 @@ void BraveActionsContainer::OnExtensionActionUpdated( UpdateActionState(extension_action->extension_id()); } // end ExtensionActionAPI::Observer + +void BraveActionsContainer::ChildPreferredSizeChanged(views::View* child) { + PreferredSizeChanged(); +} diff --git a/browser/ui/views/brave_actions/brave_actions_container.h b/browser/ui/views/brave_actions/brave_actions_container.h index c76242cc90c1..63a8a58824f3 100644 --- a/browser/ui/views/brave_actions/brave_actions_container.h +++ b/browser/ui/views/brave_actions/brave_actions_container.h @@ -70,6 +70,9 @@ class BraveActionsContainer : public views::View, content::WebContents* web_contents, content::BrowserContext* browser_context) override; + // views::View: + void ChildPreferredSizeChanged(views::View* child) override; + private: // Special positions in the container designators enum ActionPosition : int { diff --git a/browser/ui/views/location_bar/brave_location_bar_view.cc b/browser/ui/views/location_bar/brave_location_bar_view.cc index 4aca9db80429..a8cec4a56fc6 100644 --- a/browser/ui/views/location_bar/brave_location_bar_view.cc +++ b/browser/ui/views/location_bar/brave_location_bar_view.cc @@ -100,6 +100,13 @@ void BraveLocationBarView::OnThemeChanged() { RefreshBackground(); } +void BraveLocationBarView::ChildPreferredSizeChanged(views::View* child) { + if (child != brave_actions_) + return; + + Layout(); +} + // Provide base class implementation for Update override that has been added to // header via a patch. This should never be called as the only instantiated // implementation should be our |BraveLocationBarView|. diff --git a/browser/ui/views/location_bar/brave_location_bar_view.h b/browser/ui/views/location_bar/brave_location_bar_view.h index 9bc17e6395dc..27f19c8f1103 100644 --- a/browser/ui/views/location_bar/brave_location_bar_view.h +++ b/browser/ui/views/location_bar/brave_location_bar_view.h @@ -19,8 +19,11 @@ class BraveLocationBarView : public LocationBarView { void Layout() override; void Update(const content::WebContents* contents) override; void OnChanged() override; + + // views::View: gfx::Size CalculatePreferredSize() const override; void OnThemeChanged() override; + void ChildPreferredSizeChanged(views::View* child) override; private: void UpdateBookmarkStarVisibility() override;