Skip to content

Commit

Permalink
Forward preferred size changes from BraveActionsContainer
Browse files Browse the repository at this point in the history
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 brave/brave-browser#1276
  • Loading branch information
hferreiro committed Oct 9, 2018
1 parent db19fa4 commit c0ab2fd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
16 changes: 11 additions & 5 deletions browser/ui/views/brave_actions/brave_actions_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,20 @@ void BraveActionsContainer::AddAction(const extensions::Extension* extension,
// The button view
actions_[id].view_ = std::make_unique<ToolbarActionView>(
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();
}
}
Expand Down Expand Up @@ -244,3 +246,7 @@ void BraveActionsContainer::OnExtensionActionUpdated(
UpdateActionState(extension_action->extension_id());
}
// end ExtensionActionAPI::Observer

void BraveActionsContainer::ChildPreferredSizeChanged(views::View* child) {
PreferredSizeChanged();
}
3 changes: 3 additions & 0 deletions browser/ui/views/brave_actions/brave_actions_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions browser/ui/views/location_bar/brave_location_bar_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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|.
Expand Down
3 changes: 3 additions & 0 deletions browser/ui/views/location_bar/brave_location_bar_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c0ab2fd

Please sign in to comment.