Commit fcea258d authored by Peter Boström's avatar Peter Boström Committed by Commit Bot

Move toolbar avatar button to a separate class

More functionality is about to be added into this button so it's no
longer appropriate to bundle it into ToolbarView. Doing this as a
separate step to avoid large patches.

Bug: chromium:822070
Change-Id: I07f690ebeefa29f4ac4177cb59785bab01a56f0b
Reviewed-on: https://chromium-review.googlesource.com/1008628
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#550484}
parent 285019b6
......@@ -2266,6 +2266,8 @@ split_static_library("ui") {
sources += [
"views/profiles/avatar_button.cc",
"views/profiles/avatar_button.h",
"views/profiles/avatar_toolbar_button.cc",
"views/profiles/avatar_toolbar_button.h",
"views/profiles/user_manager_view.cc",
"views/profiles/user_manager_view.h",
]
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/profiles/avatar_toolbar_button.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/view_ids.h"
#include "chrome/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/models/menu_model.h"
#include "ui/base/theme_provider.h"
#include "ui/gfx/paint_vector_icon.h"
AvatarToolbarButton::AvatarToolbarButton(Profile* profile,
views::ButtonListener* listener)
: ToolbarButton(profile, listener, nullptr) {
set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON |
ui::EF_MIDDLE_MOUSE_BUTTON);
set_tag(IDC_SHOW_AVATAR_MENU);
if (profile->IsOffTheRecord()) {
SetTooltipText(
l10n_util::GetStringUTF16(IDS_INCOGNITO_AVATAR_BUTTON_TOOLTIP));
SetEnabled(false);
} else {
// TODO(pbos): Incorporate GetAvatarButtonTextForProfile. See
// AvatarButton.
SetTooltipText(l10n_util::GetStringUTF16(IDS_GENERIC_USER_AVATAR_LABEL));
SetAccessibleName(l10n_util::GetStringUTF16(IDS_GENERIC_USER_AVATAR_LABEL));
}
set_id(VIEW_ID_AVATAR_BUTTON);
Init();
}
void AvatarToolbarButton::UpdateIcon() {
const bool is_touch =
ui::MaterialDesignController::IsTouchOptimizedUiEnabled();
// TODO(pbos): Move these constants to LayoutProvider or LayoutConstants.
const int icon_size = is_touch ? 24 : 16;
// TODO(pbos): Account for incognito by either changing the icon and
// effectively disabling the menu or by not showing it at all in incognito.
SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kUserAccountAvatarIcon, icon_size,
GetThemeProvider()->GetColor(
ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON)));
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_TOOLBAR_BUTTON_H_
#define CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_TOOLBAR_BUTTON_H_
#include "chrome/browser/ui/views/toolbar/toolbar_button.h"
class AvatarToolbarButton : public ToolbarButton {
public:
AvatarToolbarButton(Profile* profile, views::ButtonListener* listener);
void UpdateIcon();
};
#endif // CHROME_BROWSER_UI_VIEWS_PROFILES_AVATAR_TOOLBAR_BUTTON_H_
......@@ -202,26 +202,8 @@ void ToolbarView::Init() {
// ChromeOS never shows a profile icon in the browser window.
#if !defined(OS_CHROMEOS)
if (ui::MaterialDesignController::IsNewerMaterialUi()) {
avatar_ = new ToolbarButton(browser_->profile(), this, nullptr);
avatar_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON |
ui::EF_MIDDLE_MOUSE_BUTTON);
avatar_->set_tag(IDC_SHOW_AVATAR_MENU);
if (browser_->profile()->IsOffTheRecord()) {
avatar_->SetTooltipText(
l10n_util::GetStringUTF16(IDS_INCOGNITO_AVATAR_BUTTON_TOOLTIP));
avatar_->SetEnabled(false);
} else {
// TODO(pbos): Incorporate GetAvatarButtonTextForProfile. See
// AvatarButton.
avatar_->SetTooltipText(
l10n_util::GetStringUTF16(IDS_GENERIC_USER_AVATAR_LABEL));
avatar_->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_GENERIC_USER_AVATAR_LABEL));
}
avatar_->set_id(VIEW_ID_AVATAR_BUTTON);
avatar_->Init();
}
if (ui::MaterialDesignController::IsNewerMaterialUi())
avatar_ = new AvatarToolbarButton(browser_->profile(), this);
#endif // !defined(OS_CHROMEOS)
app_menu_button_ = new BrowserAppMenuButton(this);
......@@ -767,8 +749,6 @@ void ToolbarView::LoadImages() {
const bool is_touch =
ui::MaterialDesignController::IsTouchOptimizedUiEnabled();
// TODO(pbos): Move these constants to LayoutProvider or LayoutConstants.
const int icon_size = is_touch ? 24 : 16;
const gfx::VectorIcon& back_image =
is_touch ? kBackArrowTouchIcon : vector_icons::kBackArrowIcon;
......@@ -789,13 +769,11 @@ void ToolbarView::LoadImages() {
home_->SetImage(views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(home_image, normal_color));
if (avatar_) {
// TODO(pbos): Account for incognito by either changing the icon and
// effectively disabling the menu or by not showing it at all in incognito.
avatar_->SetImage(
views::Button::STATE_NORMAL,
gfx::CreateVectorIcon(kUserAccountAvatarIcon, icon_size, normal_color));
}
#if !defined(OS_CHROMEOS)
if (avatar_)
avatar_->UpdateIcon();
#endif // !defined(OS_CHROMEOS)
app_menu_button_->UpdateIcon(false);
const SkColor ink_drop_color = color_utils::BlendTowardOppositeLuma(
......
......@@ -15,6 +15,7 @@
#include "chrome/browser/ui/toolbar/back_forward_menu_model.h"
#include "chrome/browser/ui/views/frame/toolbar_button_provider.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/profiles/avatar_toolbar_button.h"
#include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
#include "chrome/browser/upgrade_observer.h"
#include "components/prefs/pref_member.h"
......@@ -34,6 +35,7 @@
#endif // defined(OS_CHROMEOS)
class AppMenuButton;
class AvatarToolbarButton;
class BrowserAppMenuButton;
class Browser;
class HomeButton;
......@@ -105,7 +107,7 @@ class ToolbarView : public views::AccessiblePaneView,
ToolbarButton* back_button() const { return back_; }
ReloadButton* reload_button() const { return reload_; }
LocationBarView* location_bar() const { return location_bar_; }
ToolbarButton* avatar_button() const { return avatar_; }
AvatarToolbarButton* avatar_button() const { return avatar_; }
BrowserAppMenuButton* app_menu_button() const { return app_menu_button_; }
HomeButton* home_button() const { return home_; }
AppMenuIconController* app_menu_icon_controller() {
......@@ -217,7 +219,7 @@ class ToolbarView : public views::AccessiblePaneView,
HomeButton* home_ = nullptr;
LocationBarView* location_bar_ = nullptr;
BrowserActionsContainer* browser_actions_ = nullptr;
ToolbarButton* avatar_ = nullptr;
AvatarToolbarButton* avatar_ = nullptr;
BrowserAppMenuButton* app_menu_button_ = nullptr;
Browser* const browser_;
......
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