Commit 676bd99c authored by Thomas Tangl's avatar Thomas Tangl Committed by Commit Bot

[Dice] Display accounts submenu in bookmarks bubble

When the drop down arrow on the DiceSigninButton is
clicked, a submenu listing all GAIA web accounts
except the first one should be displayed. This CL
adds this feature.

Screenshot:
https://drive.google.com/file/d/1va4fXSFtf7PastkuXgVUc5B5mrFIEZzJ/view?usp=sharing

Bug: 812282
Change-Id: I52a73392dc6543fc44d2553c76f046685fb17672
Reviewed-on: https://chromium-review.googlesource.com/922204
Commit-Queue: Thomas Tangl <tangltom@chromium.org>
Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537617}
parent e611939e
...@@ -4,9 +4,7 @@ ...@@ -4,9 +4,7 @@
#include "chrome/browser/ui/views/sync/dice_bubble_sync_promo_view.h" #include "chrome/browser/ui/views/sync/dice_bubble_sync_promo_view.h"
#include <memory>
#include <utility> #include <utility>
#include <vector>
#include "base/logging.h" #include "base/logging.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -61,6 +59,15 @@ DiceBubbleSyncPromoView::DiceBubbleSyncPromoView( ...@@ -61,6 +59,15 @@ DiceBubbleSyncPromoView::DiceBubbleSyncPromoView(
profiles::GetPlaceholderAvatarIconResourceID()); profiles::GetPlaceholderAvatarIconResourceID());
} }
signin_button_ = new DiceSigninButton(accounts[0], account_icon, this); signin_button_ = new DiceSigninButton(accounts[0], account_icon, this);
// Store account information for submenu.
accounts_for_submenu_.assign(accounts.begin() + 1, accounts.end());
AccountTrackerService* tracker_service =
AccountTrackerServiceFactory::GetForProfile(profile);
for (auto account : accounts_for_submenu_) {
images_for_submenu_.push_back(
tracker_service->GetAccountImage(account.account_id));
}
} }
AddChildView(signin_button_); AddChildView(signin_button_);
} }
...@@ -70,20 +77,30 @@ DiceBubbleSyncPromoView::~DiceBubbleSyncPromoView() = default; ...@@ -70,20 +77,30 @@ DiceBubbleSyncPromoView::~DiceBubbleSyncPromoView() = default;
void DiceBubbleSyncPromoView::ButtonPressed(views::Button* sender, void DiceBubbleSyncPromoView::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
if (sender == signin_button_) { if (sender == signin_button_) {
DVLOG(1) << "Sign In button pressed"; EnableSync(signin_button_->account());
delegate_->OnEnableSync(signin_button_->account().value_or(AccountInfo()));
return; return;
} }
if (sender == signin_button_->drop_down_arrow()) { if (sender == signin_button_->drop_down_arrow()) {
DVLOG(1) << "Drop down arrow pressed"; // Display a submenu listing the GAIA web accounts (except the first one).
// TODO(msarda): Show the other accounts menu. // Using base::Unretained(this) is safe here because |dice_accounts_menu_|
// is owned by |DiceBubbleSyncPromoView|, i.e. |this|.
dice_accounts_menu_ = std::make_unique<DiceAccountsMenu>(
accounts_for_submenu_, images_for_submenu_,
base::BindOnce(&DiceBubbleSyncPromoView::EnableSync,
base::Unretained(this)));
dice_accounts_menu_->Show(signin_button_);
return; return;
} }
NOTREACHED(); NOTREACHED();
} }
void DiceBubbleSyncPromoView::EnableSync(
const base::Optional<AccountInfo>& account) {
delegate_->OnEnableSync(signin_button_->account().value_or(AccountInfo()));
}
const char* DiceBubbleSyncPromoView::GetClassName() const { const char* DiceBubbleSyncPromoView::GetClassName() const {
return "DiceBubbleSyncPromoView"; return "DiceBubbleSyncPromoView";
} }
...@@ -5,8 +5,12 @@ ...@@ -5,8 +5,12 @@
#ifndef CHROME_BROWSER_UI_VIEWS_SYNC_DICE_BUBBLE_SYNC_PROMO_VIEW_H_ #ifndef CHROME_BROWSER_UI_VIEWS_SYNC_DICE_BUBBLE_SYNC_PROMO_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_SYNC_DICE_BUBBLE_SYNC_PROMO_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_SYNC_DICE_BUBBLE_SYNC_PROMO_VIEW_H_
#include <memory>
#include <vector>
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/ui/sync/bubble_sync_promo_delegate.h" #include "chrome/browser/ui/sync/bubble_sync_promo_delegate.h"
#include "chrome/browser/ui/views/profiles/dice_accounts_menu.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -40,6 +44,10 @@ class DiceBubbleSyncPromoView : public views::View, ...@@ -40,6 +44,10 @@ class DiceBubbleSyncPromoView : public views::View,
void ButtonPressed(views::Button* sender, const ui::Event& event) override; void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private: private:
// Used to enable sync in the DiceAccountsMenu and when |signin_button_| is
// pressed.
void EnableSync(const base::Optional<AccountInfo>& account);
// views::View: // views::View:
const char* GetClassName() const override; const char* GetClassName() const override;
...@@ -47,6 +55,13 @@ class DiceBubbleSyncPromoView : public views::View, ...@@ -47,6 +55,13 @@ class DiceBubbleSyncPromoView : public views::View,
BubbleSyncPromoDelegate* delegate_; BubbleSyncPromoDelegate* delegate_;
DiceSigninButton* signin_button_ = nullptr; DiceSigninButton* signin_button_ = nullptr;
// Accounts submenu that is shown when |signin_button_->drop_down_arrow()| is
// pressed.
std::unique_ptr<DiceAccountsMenu> dice_accounts_menu_;
std::vector<AccountInfo> accounts_for_submenu_;
std::vector<gfx::Image> images_for_submenu_;
DISALLOW_COPY_AND_ASSIGN(DiceBubbleSyncPromoView); DISALLOW_COPY_AND_ASSIGN(DiceBubbleSyncPromoView);
}; };
#endif // CHROME_BROWSER_UI_VIEWS_SYNC_DICE_BUBBLE_SYNC_PROMO_VIEW_H_ #endif // CHROME_BROWSER_UI_VIEWS_SYNC_DICE_BUBBLE_SYNC_PROMO_VIEW_H_
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