Commit 9f757c66 authored by Quan Nguyen's avatar Quan Nguyen Committed by Commit Bot

cros: Move bubble opener parameter into LoginBaseBubbleView

Removes another stateful component of LoginBubble to make it easier to
refactor in subsequent CLs.

Bug: 905512
Change-Id: If3dca30e9bb531ca1acb829e79db07be6f86d3d8
Reviewed-on: https://chromium-review.googlesource.com/c/1336969
Commit-Queue: Quan Nguyen <qnnguyen@chromium.org>
Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608484}
parent 3d1e2e08
...@@ -46,6 +46,10 @@ LoginBaseBubbleView::LoginBaseBubbleView(views::View* anchor_view, ...@@ -46,6 +46,10 @@ LoginBaseBubbleView::LoginBaseBubbleView(views::View* anchor_view,
LoginBaseBubbleView::~LoginBaseBubbleView() = default; LoginBaseBubbleView::~LoginBaseBubbleView() = default;
LoginButton* LoginBaseBubbleView::GetBubbleOpener() const {
return nullptr;
}
void LoginBaseBubbleView::OnBeforeBubbleWidgetInit( void LoginBaseBubbleView::OnBeforeBubbleWidgetInit(
views::Widget::InitParams* params, views::Widget::InitParams* params,
views::Widget* widget) const { views::Widget* widget) const {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define ASH_LOGIN_UI_LOGIN_BASE_BUBBLE_VIEW_H_ #define ASH_LOGIN_UI_LOGIN_BASE_BUBBLE_VIEW_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/login/ui/login_button.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h" #include "ui/views/bubble/bubble_dialog_delegate_view.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -21,6 +22,9 @@ class ASH_EXPORT LoginBaseBubbleView : public views::BubbleDialogDelegateView { ...@@ -21,6 +22,9 @@ class ASH_EXPORT LoginBaseBubbleView : public views::BubbleDialogDelegateView {
gfx::NativeView parent_window); gfx::NativeView parent_window);
~LoginBaseBubbleView() override; ~LoginBaseBubbleView() override;
// Returns the button responsible for opening this bubble.
virtual LoginButton* GetBubbleOpener() const;
// views::BubbleDialogDelegateView: // views::BubbleDialogDelegateView:
void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params, void OnBeforeBubbleWidgetInit(views::Widget::InitParams* params,
views::Widget* widget) const override; views::Widget* widget) const override;
......
...@@ -185,11 +185,13 @@ class LoginUserMenuView : public LoginBaseBubbleView, ...@@ -185,11 +185,13 @@ class LoginUserMenuView : public LoginBaseBubbleView,
user_manager::UserType type, user_manager::UserType type,
bool is_owner, bool is_owner,
views::View* anchor_view, views::View* anchor_view,
LoginButton* bubble_opener_,
bool show_remove_user, bool show_remove_user,
base::OnceClosure on_remove_user_warning_shown, base::OnceClosure on_remove_user_warning_shown,
base::OnceClosure on_remove_user_requested) base::OnceClosure on_remove_user_requested)
: LoginBaseBubbleView(anchor_view), : LoginBaseBubbleView(anchor_view),
bubble_(bubble), bubble_(bubble),
bubble_opener_(bubble_opener_),
on_remove_user_warning_shown_(std::move(on_remove_user_warning_shown)), on_remove_user_warning_shown_(std::move(on_remove_user_warning_shown)),
on_remove_user_requested_(std::move(on_remove_user_requested)) { on_remove_user_requested_(std::move(on_remove_user_requested)) {
// This view has content the user can interact with if the remove user // This view has content the user can interact with if the remove user
...@@ -325,6 +327,9 @@ class LoginUserMenuView : public LoginBaseBubbleView, ...@@ -325,6 +327,9 @@ class LoginUserMenuView : public LoginBaseBubbleView,
~LoginUserMenuView() override = default; ~LoginUserMenuView() override = default;
// LoginBaseBubbleView:
LoginButton* GetBubbleOpener() const override { return bubble_opener_; }
// views::View: // views::View:
const char* GetClassName() const override { return "LoginUserMenuView"; } const char* GetClassName() const override { return "LoginUserMenuView"; }
gfx::Size CalculatePreferredSize() const override { gfx::Size CalculatePreferredSize() const override {
...@@ -384,6 +389,7 @@ class LoginUserMenuView : public LoginBaseBubbleView, ...@@ -384,6 +389,7 @@ class LoginUserMenuView : public LoginBaseBubbleView,
private: private:
LoginBubble* bubble_ = nullptr; LoginBubble* bubble_ = nullptr;
LoginButton* bubble_opener_ = nullptr;
base::OnceClosure on_remove_user_warning_shown_; base::OnceClosure on_remove_user_warning_shown_;
base::OnceClosure on_remove_user_requested_; base::OnceClosure on_remove_user_requested_;
views::View* remove_user_confirm_data_ = nullptr; views::View* remove_user_confirm_data_ = nullptr;
...@@ -472,12 +478,12 @@ void LoginBubble::ShowUserMenu(const base::string16& username, ...@@ -472,12 +478,12 @@ void LoginBubble::ShowUserMenu(const base::string16& username,
CloseImmediately(); CloseImmediately();
flags_ = kFlagsNone; flags_ = kFlagsNone;
bubble_opener_ = bubble_opener; bubble_view_ = new LoginUserMenuView(
bubble_view_ = new LoginUserMenuView(this, username, email, type, is_owner, this, username, email, type, is_owner, anchor_view, bubble_opener,
anchor_view, show_remove_user, show_remove_user, std::move(on_remove_user_warning_shown),
std::move(on_remove_user_warning_shown), std::move(on_remove_user_requested));
std::move(on_remove_user_requested)); bool had_focus = bubble_view_->GetBubbleOpener() &&
bool had_focus = bubble_opener_->HasFocus(); bubble_view_->GetBubbleOpener()->HasFocus();
Show(); Show();
if (had_focus) { if (had_focus) {
// Try to focus the bubble view only if the bubble opener was focused. // Try to focus the bubble view only if the bubble opener was focused.
...@@ -495,14 +501,13 @@ void LoginBubble::ShowTooltip(const base::string16& message, ...@@ -495,14 +501,13 @@ void LoginBubble::ShowTooltip(const base::string16& message,
Show(); Show();
} }
void LoginBubble::ShowSelectionMenu(LoginMenuView* menu, void LoginBubble::ShowSelectionMenu(LoginMenuView* menu) {
LoginButton* bubble_opener) {
if (bubble_view_) if (bubble_view_)
CloseImmediately(); CloseImmediately();
flags_ = kFlagsNone; flags_ = kFlagsNone;
bubble_opener_ = bubble_opener; const bool had_focus =
const bool had_focus = bubble_opener_->HasFocus(); menu->GetBubbleOpener() && menu->GetBubbleOpener()->HasFocus();
// Transfer the ownership of |menu| to bubble widget. // Transfer the ownership of |menu| to bubble widget.
bubble_view_ = menu; bubble_view_ = menu;
...@@ -566,7 +571,8 @@ void LoginBubble::OnKeyEvent(ui::KeyEvent* event) { ...@@ -566,7 +571,8 @@ void LoginBubble::OnKeyEvent(ui::KeyEvent* event) {
// If current focus view is the button view, don't process the event here, // If current focus view is the button view, don't process the event here,
// let the button logic handle the event and determine show/hide behavior. // let the button logic handle the event and determine show/hide behavior.
if (bubble_opener_ && bubble_opener_->HasFocus()) if (bubble_view_->GetBubbleOpener() &&
bubble_view_->GetBubbleOpener()->HasFocus())
return; return;
// If |bubble_view_| is interactive do not close it. // If |bubble_view_| is interactive do not close it.
...@@ -632,8 +638,9 @@ void LoginBubble::ProcessPressedEvent(const ui::LocatedEvent* event) { ...@@ -632,8 +638,9 @@ void LoginBubble::ProcessPressedEvent(const ui::LocatedEvent* event) {
// If the user clicks on the button view, don't process the event here, // If the user clicks on the button view, don't process the event here,
// let the button logic handle the event and determine show/hide behavior. // let the button logic handle the event and determine show/hide behavior.
if (bubble_opener_) { if (bubble_view_->GetBubbleOpener()) {
gfx::Rect bubble_opener_bounds = bubble_opener_->GetBoundsInScreen(); gfx::Rect bubble_opener_bounds =
bubble_view_->GetBubbleOpener()->GetBoundsInScreen();
if (bubble_opener_bounds.Contains(screen_location)) if (bubble_opener_bounds.Contains(screen_location))
return; return;
} }
...@@ -646,10 +653,11 @@ void LoginBubble::ScheduleAnimation(bool visible) { ...@@ -646,10 +653,11 @@ void LoginBubble::ScheduleAnimation(bool visible) {
if (!bubble_view_ || is_visible_ == visible) if (!bubble_view_ || is_visible_ == visible)
return; return;
if (bubble_opener_) { if (bubble_view_->GetBubbleOpener()) {
bubble_opener_->AnimateInkDrop(visible ? views::InkDropState::ACTIVATED bubble_view_->GetBubbleOpener()->AnimateInkDrop(
: views::InkDropState::DEACTIVATED, visible ? views::InkDropState::ACTIVATED
nullptr /*event*/); : views::InkDropState::DEACTIVATED,
nullptr /*event*/);
} }
ui::Layer* layer = bubble_view_->layer(); ui::Layer* layer = bubble_view_->layer();
...@@ -685,7 +693,6 @@ void LoginBubble::Reset(bool widget_already_closing) { ...@@ -685,7 +693,6 @@ void LoginBubble::Reset(bool widget_already_closing) {
if (!widget_already_closing) if (!widget_already_closing)
bubble_view_->GetWidget()->Close(); bubble_view_->GetWidget()->Close();
is_visible_ = false; is_visible_ = false;
bubble_opener_ = nullptr;
bubble_view_ = nullptr; bubble_view_ = nullptr;
flags_ = kFlagsNone; flags_ = kFlagsNone;
} }
......
...@@ -74,7 +74,7 @@ class ASH_EXPORT LoginBubble : public views::WidgetObserver, ...@@ -74,7 +74,7 @@ class ASH_EXPORT LoginBubble : public views::WidgetObserver,
void ShowTooltip(const base::string16& message, views::View* anchor_view); void ShowTooltip(const base::string16& message, views::View* anchor_view);
// Shows a selection menu. // Shows a selection menu.
void ShowSelectionMenu(LoginMenuView* menu, LoginButton* bubble_opener); void ShowSelectionMenu(LoginMenuView* menu);
// Schedule animation for closing the bubble. // Schedule animation for closing the bubble.
// The bubble widget will be closed when the animation is ended. // The bubble widget will be closed when the animation is ended.
...@@ -133,9 +133,6 @@ class ASH_EXPORT LoginBubble : public views::WidgetObserver, ...@@ -133,9 +133,6 @@ class ASH_EXPORT LoginBubble : public views::WidgetObserver,
LoginBaseBubbleView* bubble_view_ = nullptr; LoginBaseBubbleView* bubble_view_ = nullptr;
// A button that could open/close the bubble.
LoginButton* bubble_opener_ = nullptr;
// The status of bubble after animation ends. // The status of bubble after animation ends.
bool is_visible_ = false; bool is_visible_ = false;
......
...@@ -106,9 +106,9 @@ class LoginBubbleTest : public LoginTestBase { ...@@ -106,9 +106,9 @@ class LoginBubbleTest : public LoginTestBase {
} }
void ShowSelectionMenu(const LoginMenuView::OnSelect& on_select) { void ShowSelectionMenu(const LoginMenuView::OnSelect& on_select) {
LoginMenuView* view = LoginMenuView* view = new LoginMenuView(PopulateMenuItems(), container_,
new LoginMenuView(PopulateMenuItems(), container_, on_select); bubble_opener_, on_select);
bubble_->ShowSelectionMenu(view, bubble_opener_); bubble_->ShowSelectionMenu(view);
} }
// Owned by test widget view hierarchy. // Owned by test widget view hierarchy.
......
...@@ -358,10 +358,10 @@ class RightPaneView : public NonAccessibleView, ...@@ -358,10 +358,10 @@ class RightPaneView : public NonAccessibleView,
if (!language_menu_->IsVisible() && !language_items_.empty()) { if (!language_menu_->IsVisible() && !language_items_.empty()) {
LoginMenuView* view = new LoginMenuView( LoginMenuView* view = new LoginMenuView(
language_items_, language_selection_ /*anchor_view*/, language_items_, language_selection_ /*anchor_view*/,
language_selection_ /*bubble_opener*/,
base::BindRepeating(&RightPaneView::OnLanguageSelected, base::BindRepeating(&RightPaneView::OnLanguageSelected,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
language_menu_->ShowSelectionMenu( language_menu_->ShowSelectionMenu(view);
view, language_selection_ /*bubble_opener*/);
} else { } else {
language_menu_->Close(); language_menu_->Close();
} }
...@@ -369,10 +369,10 @@ class RightPaneView : public NonAccessibleView, ...@@ -369,10 +369,10 @@ class RightPaneView : public NonAccessibleView,
if (!keyboard_menu_->IsVisible() && !keyboard_items_.empty()) { if (!keyboard_menu_->IsVisible() && !keyboard_items_.empty()) {
LoginMenuView* view = new LoginMenuView( LoginMenuView* view = new LoginMenuView(
keyboard_items_, keyboard_selection_ /*anchor_view*/, keyboard_items_, keyboard_selection_ /*anchor_view*/,
keyboard_selection_ /*bubble_opener*/,
base::BindRepeating(&RightPaneView::OnKeyboardSelected, base::BindRepeating(&RightPaneView::OnKeyboardSelected,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
keyboard_menu_->ShowSelectionMenu( keyboard_menu_->ShowSelectionMenu(view);
view, keyboard_selection_ /*bubble_opener*/);
} else { } else {
keyboard_menu_->Close(); keyboard_menu_->Close();
} }
......
...@@ -123,8 +123,9 @@ LoginMenuView::Item::Item() = default; ...@@ -123,8 +123,9 @@ LoginMenuView::Item::Item() = default;
LoginMenuView::LoginMenuView(const std::vector<Item>& items, LoginMenuView::LoginMenuView(const std::vector<Item>& items,
views::View* anchor_view, views::View* anchor_view,
LoginButton* opener,
const OnSelect& on_select) const OnSelect& on_select)
: LoginBaseBubbleView(anchor_view), on_select_(on_select) { : LoginBaseBubbleView(anchor_view), opener_(opener), on_select_(on_select) {
set_can_activate(true); set_can_activate(true);
set_margins(gfx::Insets()); set_margins(gfx::Insets());
set_color(kMenuBackgroundColor); set_color(kMenuBackgroundColor);
...@@ -194,6 +195,10 @@ int LoginMenuView::FindNextItem(bool reverse) { ...@@ -194,6 +195,10 @@ int LoginMenuView::FindNextItem(bool reverse) {
return current_index; return current_index;
} }
LoginButton* LoginMenuView::GetBubbleOpener() const {
return opener_;
}
void LoginMenuView::OnFocus() { void LoginMenuView::OnFocus() {
// Forward the focus to the selected child view. // Forward the focus to the selected child view.
contents_->child_at(selected_index_)->RequestFocus(); contents_->child_at(selected_index_)->RequestFocus();
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/login/ui/login_base_bubble_view.h" #include "ash/login/ui/login_base_bubble_view.h"
#include "ash/login/ui/login_button.h"
#include "base/callback.h" #include "base/callback.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -46,12 +47,16 @@ class ASH_EXPORT LoginMenuView : public LoginBaseBubbleView { ...@@ -46,12 +47,16 @@ class ASH_EXPORT LoginMenuView : public LoginBaseBubbleView {
LoginMenuView(const std::vector<Item>& items, LoginMenuView(const std::vector<Item>& items,
views::View* anchor_view, views::View* anchor_view,
LoginButton* opener_,
const OnSelect& on_select); const OnSelect& on_select);
~LoginMenuView() override; ~LoginMenuView() override;
void OnHighLightChange(int item_index, bool by_selection); void OnHighLightChange(int item_index, bool by_selection);
int FindNextItem(bool reverse); int FindNextItem(bool reverse);
// LoginBaseBubbleView:
LoginButton* GetBubbleOpener() const override;
// views::View: // views::View:
void OnFocus() override; void OnFocus() override;
bool OnKeyPressed(const ui::KeyEvent& event) override; bool OnKeyPressed(const ui::KeyEvent& event) override;
...@@ -64,6 +69,8 @@ class ASH_EXPORT LoginMenuView : public LoginBaseBubbleView { ...@@ -64,6 +69,8 @@ class ASH_EXPORT LoginMenuView : public LoginBaseBubbleView {
// Owned by ScrollView. // Owned by ScrollView.
views::View* contents_ = nullptr; views::View* contents_ = nullptr;
LoginButton* opener_ = nullptr;
const OnSelect on_select_; const OnSelect on_select_;
int selected_index_ = 0; int selected_index_ = 0;
......
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