Commit 39af2cf6 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Relayout location bar buttons when MD mode changes

BUG=737995,881371
R=pkasting

Change-Id: Icc068573b4b10e618ee9bce39cc6970b8b077152
Reviewed-on: https://chromium-review.googlesource.com/c/1258252
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596350}
parent 25b107c8
...@@ -144,23 +144,18 @@ IconLabelBubbleView::IconLabelBubbleView(const gfx::FontList& font_list) ...@@ -144,23 +144,18 @@ IconLabelBubbleView::IconLabelBubbleView(const gfx::FontList& font_list)
GetOmniboxStateAlpha(OmniboxPartState::SELECTED)); GetOmniboxStateAlpha(OmniboxPartState::SELECTED));
} }
// Bubbles are given the full internal height of the location bar so that all UpdateBorder();
// child views in the location bar have the same height. The visible height of
// the bubble should be smaller, so use an empty border to shrink down the
// content bounds so the background gets painted correctly.
SetBorder(views::CreateEmptyBorder(
gfx::Insets(GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING),
GetLayoutInsets(LOCATION_BAR_ICON_INTERIOR_PADDING).left())));
set_notify_enter_exit_on_child(true); set_notify_enter_exit_on_child(true);
// Flip the canvas in RTL so the separator is drawn on the correct side. // Flip the canvas in RTL so the separator is drawn on the correct side.
separator_view_->EnableCanvasFlippingForRTLUI(true); separator_view_->EnableCanvasFlippingForRTLUI(true);
}
IconLabelBubbleView::~IconLabelBubbleView() { md_observer_.Add(ui::MaterialDesignController::GetInstance());
} }
IconLabelBubbleView::~IconLabelBubbleView() {}
void IconLabelBubbleView::InkDropAnimationStarted() { void IconLabelBubbleView::InkDropAnimationStarted() {
separator_view_->UpdateOpacity(); separator_view_->UpdateOpacity();
} }
...@@ -218,6 +213,16 @@ bool IconLabelBubbleView::IsBubbleShowing() const { ...@@ -218,6 +213,16 @@ bool IconLabelBubbleView::IsBubbleShowing() const {
return false; return false;
} }
void IconLabelBubbleView::UpdateBorder() {
// Bubbles are given the full internal height of the location bar so that all
// child views in the location bar have the same height. The visible height of
// the bubble should be smaller, so use an empty border to shrink down the
// content bounds so the background gets painted correctly.
SetBorder(views::CreateEmptyBorder(
gfx::Insets(GetLayoutConstant(LOCATION_BAR_BUBBLE_VERTICAL_PADDING),
GetLayoutInsets(LOCATION_BAR_ICON_INTERIOR_PADDING).left())));
}
gfx::Size IconLabelBubbleView::CalculatePreferredSize() const { gfx::Size IconLabelBubbleView::CalculatePreferredSize() const {
// Height will be ignored by the LocationBarView. // Height will be ignored by the LocationBarView.
return GetSizeForLabelWidth(label_->GetPreferredSize().width()); return GetSizeForLabelWidth(label_->GetPreferredSize().width());
...@@ -419,6 +424,15 @@ void IconLabelBubbleView::AnimationCanceled(const gfx::Animation* animation) { ...@@ -419,6 +424,15 @@ void IconLabelBubbleView::AnimationCanceled(const gfx::Animation* animation) {
AnimationEnded(animation); AnimationEnded(animation);
} }
void IconLabelBubbleView::OnMdModeChanged() {
UpdateBorder();
// PreferredSizeChanged() incurs an expensive layout of the location bar, so
// only call it when this view is showing.
if (visible())
PreferredSizeChanged();
}
SkColor IconLabelBubbleView::GetParentBackgroundColor() const { SkColor IconLabelBubbleView::GetParentBackgroundColor() const {
return GetNativeTheme()->GetSystemColor( return GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_TextfieldDefaultBackground); ui::NativeTheme::kColorId_TextfieldDefaultBackground);
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/scoped_observer.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "ui/base/material_design/material_design_controller_observer.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/views/animation/ink_drop_host_view.h" #include "ui/views/animation/ink_drop_host_view.h"
...@@ -33,7 +35,8 @@ class InkDropContainerView; ...@@ -33,7 +35,8 @@ class InkDropContainerView;
// base for the classes that handle the location icon (including the EV bubble), // base for the classes that handle the location icon (including the EV bubble),
// tab-to-search UI, and content settings. // tab-to-search UI, and content settings.
class IconLabelBubbleView : public views::InkDropObserver, class IconLabelBubbleView : public views::InkDropObserver,
public views::Button { public views::Button,
public ui::MaterialDesignControllerObserver {
public: public:
static constexpr int kTrailingPaddingPreMd = 2; static constexpr int kTrailingPaddingPreMd = 2;
...@@ -122,6 +125,9 @@ class IconLabelBubbleView : public views::InkDropObserver, ...@@ -122,6 +125,9 @@ class IconLabelBubbleView : public views::InkDropObserver,
// prevent the bubble from reshowing on a mouse release. // prevent the bubble from reshowing on a mouse release.
virtual bool IsBubbleShowing() const; virtual bool IsBubbleShowing() const;
// Sets the border padding around this view.
virtual void UpdateBorder();
// views::InkDropHostView: // views::InkDropHostView:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
void Layout() override; void Layout() override;
...@@ -147,6 +153,9 @@ class IconLabelBubbleView : public views::InkDropObserver, ...@@ -147,6 +153,9 @@ class IconLabelBubbleView : public views::InkDropObserver,
void AnimationProgressed(const gfx::Animation* animation) override; void AnimationProgressed(const gfx::Animation* animation) override;
void AnimationCanceled(const gfx::Animation* animation) override; void AnimationCanceled(const gfx::Animation* animation) override;
// ui::MaterialDesignControllerObserver:
void OnMdModeChanged() override;
const gfx::FontList& font_list() const { return label_->font_list(); } const gfx::FontList& font_list() const { return label_->font_list(); }
SkColor GetParentBackgroundColor() const; SkColor GetParentBackgroundColor() const;
...@@ -246,6 +255,10 @@ class IconLabelBubbleView : public views::InkDropObserver, ...@@ -246,6 +255,10 @@ class IconLabelBubbleView : public views::InkDropObserver,
double pause_animation_state_ = 0.0; double pause_animation_state_ = 0.0;
double open_state_fraction_ = 0.0; double open_state_fraction_ = 0.0;
ScopedObserver<ui::MaterialDesignController,
ui::MaterialDesignControllerObserver>
md_observer_{this};
DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView); DISALLOW_COPY_AND_ASSIGN(IconLabelBubbleView);
}; };
......
...@@ -156,6 +156,7 @@ LocationBarView::LocationBarView(Browser* browser, ...@@ -156,6 +156,7 @@ LocationBarView::LocationBarView(Browser* browser,
bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(), bookmarks::prefs::kEditBookmarksEnabled, profile->GetPrefs(),
base::Bind(&LocationBarView::UpdateWithoutTabRestore, base::Bind(&LocationBarView::UpdateWithoutTabRestore,
base::Unretained(this))); base::Unretained(this)));
md_observer_.Add(ui::MaterialDesignController::GetInstance());
} }
LocationBarView::~LocationBarView() {} LocationBarView::~LocationBarView() {}
...@@ -659,10 +660,8 @@ void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) { ...@@ -659,10 +660,8 @@ void LocationBarView::OnNativeThemeChanged(const ui::NativeTheme* theme) {
} }
void LocationBarView::ChildPreferredSizeChanged(views::View* child) { void LocationBarView::ChildPreferredSizeChanged(views::View* child) {
if (child != page_action_icon_container_view_)
return;
Layout(); Layout();
SchedulePaint();
} }
void LocationBarView::Update(const WebContents* contents) { void LocationBarView::Update(const WebContents* contents) {
...@@ -1329,6 +1328,15 @@ void LocationBarView::SetFocusAndSelection(bool select_all) { ...@@ -1329,6 +1328,15 @@ void LocationBarView::SetFocusAndSelection(bool select_all) {
FocusLocation(select_all); FocusLocation(select_all);
} }
////////////////////////////////////////////////////////////////////////////////
// LocationBarView, private ui::MaterialDesignControllerObserver implementation:
void LocationBarView::OnMdModeChanged() {
RefreshLocationIcon();
Layout();
SchedulePaint();
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// LocationBarView, private static methods: // LocationBarView, private static methods:
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h" #include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
#include "components/prefs/pref_member.h" #include "components/prefs/pref_member.h"
#include "components/security_state/core/security_state.h" #include "components/security_state/core/security_state.h"
#include "ui/base/material_design/material_design_controller_observer.h"
#include "ui/gfx/animation/animation_delegate.h" #include "ui/gfx/animation/animation_delegate.h"
#include "ui/gfx/animation/slide_animation.h" #include "ui/gfx/animation/slide_animation.h"
#include "ui/gfx/font.h" #include "ui/gfx/font.h"
...@@ -78,7 +79,8 @@ class LocationBarView : public LocationBar, ...@@ -78,7 +79,8 @@ class LocationBarView : public LocationBar,
public DropdownBarHostDelegate, public DropdownBarHostDelegate,
public views::ButtonListener, public views::ButtonListener,
public ContentSettingImageView::Delegate, public ContentSettingImageView::Delegate,
public PageActionIconView::Delegate { public PageActionIconView::Delegate,
public ui::MaterialDesignControllerObserver {
public: public:
class Delegate { class Delegate {
public: public:
...@@ -386,6 +388,9 @@ class LocationBarView : public LocationBar, ...@@ -386,6 +388,9 @@ class LocationBarView : public LocationBar,
// DropdownBarHostDelegate: // DropdownBarHostDelegate:
void SetFocusAndSelection(bool select_all) override; void SetFocusAndSelection(bool select_all) override;
// ui::MaterialDesignControllerObserver:
void OnMdModeChanged() override;
// Returns the total amount of space reserved above or below the content, // Returns the total amount of space reserved above or below the content,
// which is the vertical edge thickness plus the padding next to it. // which is the vertical edge thickness plus the padding next to it.
static int GetTotalVerticalPadding(); static int GetTotalVerticalPadding();
...@@ -488,6 +493,10 @@ class LocationBarView : public LocationBar, ...@@ -488,6 +493,10 @@ class LocationBarView : public LocationBar,
// The focus ring, if one is in use. // The focus ring, if one is in use.
std::unique_ptr<views::FocusRing> focus_ring_; std::unique_ptr<views::FocusRing> focus_ring_;
ScopedObserver<ui::MaterialDesignController,
ui::MaterialDesignControllerObserver>
md_observer_{this};
// Used to scope the lifetime of asynchronous icon fetch callbacks to the // Used to scope the lifetime of asynchronous icon fetch callbacks to the
// lifetime of the object. Weak pointers issued by this factory are // lifetime of the object. Weak pointers issued by this factory are
// invalidated whenever we start a new icon fetch, so don't use this weak // invalidated whenever we start a new icon fetch, so don't use this weak
......
...@@ -53,8 +53,6 @@ PageActionIconView::PageActionIconView(CommandUpdater* command_updater, ...@@ -53,8 +53,6 @@ PageActionIconView::PageActionIconView(CommandUpdater* command_updater,
command_id_(command_id), command_id_(command_id),
active_(false), active_(false),
suppress_mouse_released_action_(false) { suppress_mouse_released_action_(false) {
SetBorder(views::CreateEmptyBorder(
GetLayoutInsets(LOCATION_BAR_ICON_INTERIOR_PADDING)));
if (ui::MaterialDesignController::IsNewerMaterialUi()) { if (ui::MaterialDesignController::IsNewerMaterialUi()) {
// Ink drop ripple opacity. // Ink drop ripple opacity.
set_ink_drop_visible_opacity( set_ink_drop_visible_opacity(
...@@ -246,6 +244,17 @@ void PageActionIconView::OnBoundsChanged(const gfx::Rect& previous_bounds) { ...@@ -246,6 +244,17 @@ void PageActionIconView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
IconLabelBubbleView::OnBoundsChanged(previous_bounds); IconLabelBubbleView::OnBoundsChanged(previous_bounds);
} }
void PageActionIconView::OnMdModeChanged() {
icon_size_ = GetLayoutConstant(LOCATION_BAR_ICON_SIZE);
UpdateIconImage();
IconLabelBubbleView::OnMdModeChanged();
}
void PageActionIconView::UpdateBorder() {
SetBorder(views::CreateEmptyBorder(
GetLayoutInsets(LOCATION_BAR_ICON_INTERIOR_PADDING)));
}
void PageActionIconView::SetIconColor(SkColor icon_color) { void PageActionIconView::SetIconColor(SkColor icon_color) {
icon_color_ = icon_color; icon_color_ = icon_color;
UpdateIconImage(); UpdateIconImage();
......
...@@ -120,8 +120,10 @@ class PageActionIconView : public IconLabelBubbleView { ...@@ -120,8 +120,10 @@ class PageActionIconView : public IconLabelBubbleView {
// Gets the given vector icon in the correct color and size based on |active|. // Gets the given vector icon in the correct color and size based on |active|.
virtual const gfx::VectorIcon& GetVectorIcon() const = 0; virtual const gfx::VectorIcon& GetVectorIcon() const = 0;
// views::View: // IconLabelBubbleView:
void OnBoundsChanged(const gfx::Rect& previous_bounds) override; void OnBoundsChanged(const gfx::Rect& previous_bounds) override;
void OnMdModeChanged() override;
void UpdateBorder() override;
// Updates the icon image after some state has changed. // Updates the icon image after some state has changed.
void UpdateIconImage(); void UpdateIconImage();
......
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