Commit ab847d5f authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Relayout toolbar buttons when MD mode changes

BUG=737995,881371
R=pkasting

Change-Id: I4dc5b47f91c4330497bd26f3ae7ff4affe7ff193
Reviewed-on: https://chromium-review.googlesource.com/1250166
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595506}
parent 2892d91b
......@@ -68,11 +68,7 @@ AvatarToolbarButton::AvatarToolbarButton(Browser* browser)
AccountTrackerServiceFactory::GetForProfile(profile_));
}
// In non-touch mode we use a larger-than-normal icon size for avatars as 16dp
// is hard to read for user avatars. This constant is correspondingly smaller
// than GetLayoutInsets(TOOLBAR_BUTTON).
if (!ui::MaterialDesignController::IsTouchOptimizedUiEnabled())
SetLayoutInsets(GetLayoutInsets(TOOLBAR_BUTTON) - gfx::Insets(2));
SetInsets();
// Activate on press for left-mouse-button only to mimic other MenuButtons
// without drag-drop actions (specifically the adjacent browser menu).
......@@ -102,9 +98,11 @@ AvatarToolbarButton::AvatarToolbarButton(Browser* browser)
// outside as GetThemeProvider() is not available until the button is added to
// ToolbarView's hierarchy.
UpdateText();
md_observer_.Add(ui::MaterialDesignController::GetInstance());
}
AvatarToolbarButton::~AvatarToolbarButton() = default;
AvatarToolbarButton::~AvatarToolbarButton() {}
void AvatarToolbarButton::UpdateIcon() {
SetImage(views::Button::STATE_NORMAL, GetAvatarIcon());
......@@ -193,6 +191,11 @@ void AvatarToolbarButton::OnAccountRemoved(const AccountInfo& info) {
UpdateIcon();
}
void AvatarToolbarButton::OnMdModeChanged() {
SetInsets();
PreferredSizeChanged();
}
bool AvatarToolbarButton::IsIncognito() const {
return profile_->IsOffTheRecord() && !profile_->IsGuestSession();
}
......@@ -331,3 +334,12 @@ AvatarToolbarButton::SyncState AvatarToolbarButton::GetSyncState() const {
#endif // !defined(OS_CHROMEOS)
return SyncState::kNormal;
}
void AvatarToolbarButton::SetInsets() {
// In non-touch mode we use a larger-than-normal icon size for avatars as 16dp
// is hard to read for user avatars. This constant is correspondingly smaller
// than GetLayoutInsets(TOOLBAR_BUTTON).
SetLayoutInsets(ui::MaterialDesignController::IsTouchOptimizedUiEnabled()
? gfx::Insets()
: GetLayoutInsets(TOOLBAR_BUTTON) - gfx::Insets(2));
}
......@@ -14,6 +14,7 @@
#include "chrome/browser/ui/views/toolbar/toolbar_button.h"
#include "components/signin/core/browser/account_tracker_service.h"
#include "components/signin/core/browser/gaia_cookie_manager_service.h"
#include "ui/base/material_design/material_design_controller_observer.h"
#include "ui/events/event.h"
class Browser;
......@@ -22,7 +23,8 @@ class AvatarToolbarButton : public ToolbarButton,
public AvatarButtonErrorControllerDelegate,
public ProfileAttributesStorage::Observer,
public GaiaCookieManagerService::Observer,
public AccountTrackerService::Observer {
public AccountTrackerService::Observer,
public ui::MaterialDesignControllerObserver {
public:
explicit AvatarToolbarButton(Browser* browser);
~AvatarToolbarButton() override;
......@@ -62,6 +64,9 @@ class AvatarToolbarButton : public ToolbarButton,
const gfx::Image& image) override;
void OnAccountRemoved(const AccountInfo& info) override;
// ui::MaterialDesignControllerObserver:
void OnMdModeChanged() override;
bool IsIncognito() const;
bool ShouldShowGenericIcon() const;
base::string16 GetAvatarTooltipText() const;
......@@ -69,6 +74,8 @@ class AvatarToolbarButton : public ToolbarButton,
gfx::Image GetIconImageFromProfile() const;
SyncState GetSyncState() const;
void SetInsets();
Browser* const browser_;
Profile* const profile_;
......@@ -81,6 +88,8 @@ class AvatarToolbarButton : public ToolbarButton,
cookie_manager_service_observer_;
ScopedObserver<AccountTrackerService, AvatarToolbarButton>
account_tracker_service_observer_;
ScopedObserver<ui::MaterialDesignController, AvatarToolbarButton>
md_observer_{this};
DISALLOW_COPY_AND_ASSIGN(AvatarToolbarButton);
};
......
......@@ -68,11 +68,6 @@ BrowserAppMenuButton::BrowserAppMenuButton(ToolbarView* toolbar_view)
set_ink_drop_visible_opacity(kToolbarInkDropVisibleOpacity);
const int size = GetLayoutConstant(LOCATION_BAR_HEIGHT);
const int radii = ChromeLayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_MAXIMUM, gfx::Size(size, size));
set_ink_drop_corner_radii(radii, radii);
md_observer_.Add(ui::MaterialDesignController::GetInstance());
}
......@@ -152,6 +147,11 @@ void BrowserAppMenuButton::Layout() {
image()->SetBoundsRect(GetContentsBounds());
}
const int size = GetLayoutConstant(LOCATION_BAR_HEIGHT);
const int radii = ChromeLayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_MAXIMUM, gfx::Size(size, size));
set_ink_drop_corner_radii(radii, radii);
AppMenuButton::Layout();
}
......
......@@ -76,11 +76,6 @@ ToolbarActionView::ToolbarActionView(
set_ink_drop_visible_opacity(kToolbarInkDropVisibleOpacity);
const int size = GetLayoutConstant(LOCATION_BAR_HEIGHT);
const int radii = ChromeLayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_MAXIMUM, gfx::Size(size, size));
set_ink_drop_corner_radii(radii, radii);
UpdateState();
}
......@@ -307,6 +302,15 @@ void ToolbarActionView::ShowContextMenuForView(
DoShowContextMenu(source_type);
}
void ToolbarActionView::Layout() {
const int size = GetLayoutConstant(LOCATION_BAR_HEIGHT);
const int radii = ChromeLayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_MAXIMUM, gfx::Size(size, size));
set_ink_drop_corner_radii(radii, radii);
views::MenuButton::Layout();
}
void ToolbarActionView::DoShowContextMenu(
ui::MenuSourceType source_type) {
ui::MenuModel* context_menu_model = view_controller_->GetContextMenu();
......
......@@ -120,6 +120,9 @@ class ToolbarActionView : public views::MenuButton,
const gfx::Point& point,
ui::MenuSourceType source_type) override;
// views::View:
void Layout() override;
// Shows the context menu (if one exists) for the toolbar action.
void DoShowContextMenu(ui::MenuSourceType source_type);
......
......@@ -50,11 +50,6 @@ ToolbarButton::ToolbarButton(views::ButtonListener* listener,
set_ink_drop_visible_opacity(kToolbarInkDropVisibleOpacity);
const int size = GetLayoutConstant(LOCATION_BAR_HEIGHT);
const int radii = ChromeLayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_MAXIMUM, gfx::Size(size, size));
set_ink_drop_corner_radii(radii, radii);
SetImageLabelSpacing(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_RELATED_LABEL_HORIZONTAL_LIST));
SetHorizontalAlignment(gfx::ALIGN_RIGHT);
......@@ -192,8 +187,7 @@ void ToolbarButton::OnMouseReleased(const ui::MouseEvent& event) {
show_menu_factory_.InvalidateWeakPtrs();
}
void ToolbarButton::OnMouseCaptureLost() {
}
void ToolbarButton::OnMouseCaptureLost() {}
void ToolbarButton::OnMouseExited(const ui::MouseEvent& event) {
// Starting a drag results in a MouseExited, we need to ignore it.
......@@ -338,6 +332,15 @@ void ToolbarButton::OnMenuClosed() {
menu_model_adapter_.reset();
}
void ToolbarButton::Layout() {
const int size = GetLayoutConstant(LOCATION_BAR_HEIGHT);
const int radii = ChromeLayoutProvider::Get()->GetCornerRadiusMetric(
views::EMPHASIS_MAXIMUM, gfx::Size(size, size));
set_ink_drop_corner_radii(radii, radii);
views::LabelButton::Layout();
}
const char* ToolbarButton::GetClassName() const {
return "ToolbarButton";
}
......@@ -109,6 +109,9 @@ class ToolbarButton : public views::LabelButton,
// Callback for MenuModelAdapter.
void OnMenuClosed();
// views::View:
void Layout() override;
// views::ImageButton:
const char* GetClassName() 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