Commit be452be4 authored by Thomas Tellier's avatar Thomas Tellier Committed by Commit Bot

[CrOs] Make login bubbles use default positioning strategies

Bug: 1109266
Change-Id: Ia930e9aa352fe24eb5b10ecad2b47d4a7d2b21c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2414394
Commit-Queue: Thomas Tellier <tellier@google.com>
Reviewed-by: default avatarRoman Aleksandrov <raleksandrov@google.com>
Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821563}
parent 7ac640da
...@@ -619,8 +619,8 @@ component("ash") { ...@@ -619,8 +619,8 @@ component("ash") {
"login/ui/login_pin_view.h", "login/ui/login_pin_view.h",
"login/ui/login_public_account_user_view.cc", "login/ui/login_public_account_user_view.cc",
"login/ui/login_public_account_user_view.h", "login/ui/login_public_account_user_view.h",
"login/ui/login_unpositioned_tooltip_view.cc", "login/ui/login_tooltip_view.cc",
"login/ui/login_unpositioned_tooltip_view.h", "login/ui/login_tooltip_view.h",
"login/ui/login_user_menu_view.cc", "login/ui/login_user_menu_view.cc",
"login/ui/login_user_menu_view.h", "login/ui/login_user_menu_view.h",
"login/ui/login_user_view.cc", "login/ui/login_user_view.cc",
......
...@@ -228,12 +228,12 @@ bool LoginScreenTestApi::IsEnterpriseEnrollmentButtonShown() { ...@@ -228,12 +228,12 @@ bool LoginScreenTestApi::IsEnterpriseEnrollmentButtonShown() {
} }
// static // static
bool LoginScreenTestApi::IsUserAddingScreenBubbleShown() { bool LoginScreenTestApi::IsUserAddingScreenIndicatorShown() {
LockScreen::TestApi lock_screen_test(LockScreen::Get()); LockScreen::TestApi lock_screen_test(LockScreen::Get());
LockContentsView::TestApi lock_contents_test( LockContentsView::TestApi lock_contents_test(
lock_screen_test.contents_view()); lock_screen_test.contents_view());
views::View* bubble = lock_contents_test.user_adding_screen_bubble(); views::View* indicator = lock_contents_test.user_adding_screen_indicator();
return bubble && bubble->GetVisible(); return indicator && indicator->GetVisible();
} }
// static // static
......
This diff is collapsed.
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "ash/login/ui/login_data_dispatcher.h" #include "ash/login/ui/login_data_dispatcher.h"
#include "ash/login/ui/login_display_style.h" #include "ash/login/ui/login_display_style.h"
#include "ash/login/ui/login_error_bubble.h" #include "ash/login/ui/login_error_bubble.h"
#include "ash/login/ui/login_unpositioned_tooltip_view.h" #include "ash/login/ui/login_tooltip_view.h"
#include "ash/login/ui/non_accessible_view.h" #include "ash/login/ui/non_accessible_view.h"
#include "ash/public/cpp/keyboard/keyboard_controller_observer.h" #include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
#include "ash/public/cpp/login_accelerators.h" #include "ash/public/cpp/login_accelerators.h"
...@@ -72,9 +72,7 @@ class ASH_EXPORT LockContentsView ...@@ -72,9 +72,7 @@ class ASH_EXPORT LockContentsView
public: public:
METADATA_HEADER(LockContentsView); METADATA_HEADER(LockContentsView);
class AuthErrorBubble; class AuthErrorBubble;
class ManagementPopUp; class ManagementBubble;
class LoginTooltipView;
class UserAddingPopUp;
class UserState; class UserState;
enum class BottomIndicatorState { enum class BottomIndicatorState {
...@@ -101,7 +99,7 @@ class ASH_EXPORT LockContentsView ...@@ -101,7 +99,7 @@ class ASH_EXPORT LockContentsView
LoginErrorBubble* detachable_base_error_bubble() const; LoginErrorBubble* detachable_base_error_bubble() const;
LoginErrorBubble* warning_banner_bubble() const; LoginErrorBubble* warning_banner_bubble() const;
LoginErrorBubble* supervised_user_deprecation_bubble() const; LoginErrorBubble* supervised_user_deprecation_bubble() const;
views::View* user_adding_screen_bubble() const; views::View* user_adding_screen_indicator() const;
views::View* system_info() const; views::View* system_info() const;
views::View* bottom_status_indicator() const; views::View* bottom_status_indicator() const;
BottomIndicatorState bottom_status_indicator_status() const; BottomIndicatorState bottom_status_indicator_status() const;
...@@ -303,6 +301,10 @@ class ASH_EXPORT LockContentsView ...@@ -303,6 +301,10 @@ class ASH_EXPORT LockContentsView
// device is enrolled. // device is enrolled.
void LayoutBottomStatusIndicator(); void LayoutBottomStatusIndicator();
// Lay out the user adding screen indicator. This is called when a secondary
// user is being added.
void LayoutUserAddingScreenIndicator();
// Lay out the expanded public session view. // Lay out the expanded public session view.
void LayoutPublicSessionView(); void LayoutPublicSessionView();
...@@ -459,10 +461,10 @@ class ASH_EXPORT LockContentsView ...@@ -459,10 +461,10 @@ class ASH_EXPORT LockContentsView
// Bubble for displaying easy-unlock tooltips. // Bubble for displaying easy-unlock tooltips.
LoginTooltipView* tooltip_bubble_; LoginTooltipView* tooltip_bubble_;
// Bubble for displaying management details. // Bubble for displaying management details.
ManagementPopUp* management_bubble_; ManagementBubble* management_bubble_;
// Bubble for displaying a warning message when a secondary user is being // Indicator at top of screen for displaying a warning message when a
// added. // secondary user is being added.
UserAddingPopUp* user_adding_screen_bubble_ = nullptr; views::View* user_adding_screen_indicator_ = nullptr;
// Bubble for displaying warning banner message. // Bubble for displaying warning banner message.
LoginErrorBubble* warning_banner_bubble_; LoginErrorBubble* warning_banner_bubble_;
// Bubble for displaying supervised user deprecation message. // Bubble for displaying supervised user deprecation message.
......
...@@ -35,7 +35,7 @@ constexpr int kBubblePaddingDp = 16; ...@@ -35,7 +35,7 @@ constexpr int kBubblePaddingDp = 16;
constexpr int kBubbleBetweenChildSpacingDp = 16; constexpr int kBubbleBetweenChildSpacingDp = 16;
// Border radius of the rounded bubble. // Border radius of the rounded bubble.
constexpr int kErrorBubbleBorderRadius = 8; constexpr int kBubbleBorderRadius = 8;
// The amount of time for bubble show/hide animation. // The amount of time for bubble show/hide animation.
constexpr base::TimeDelta kBubbleAnimationDuration = constexpr base::TimeDelta kBubbleAnimationDuration =
...@@ -81,7 +81,7 @@ class LoginBubbleHandler : public ui::EventHandler { ...@@ -81,7 +81,7 @@ class LoginBubbleHandler : public ui::EventHandler {
if (login_views_utils::HasFocusInAnyChildView(bubble_)) if (login_views_utils::HasFocusInAnyChildView(bubble_))
return; return;
if (!bubble_->IsPersistent()) if (!bubble_->is_persistent())
bubble_->Hide(); bubble_->Hide();
} }
...@@ -105,7 +105,7 @@ class LoginBubbleHandler : public ui::EventHandler { ...@@ -105,7 +105,7 @@ class LoginBubbleHandler : public ui::EventHandler {
return; return;
} }
if (!bubble_->IsPersistent()) if (!bubble_->is_persistent())
bubble_->Hide(); bubble_->Hide();
} }
...@@ -141,7 +141,7 @@ void LoginBaseBubbleView::EnsureLayer() { ...@@ -141,7 +141,7 @@ void LoginBaseBubbleView::EnsureLayer() {
layer()->SetBackgroundBlur( layer()->SetBackgroundBlur(
static_cast<float>(AshColorProvider::LayerBlurSigma::kBlurDefault)); static_cast<float>(AshColorProvider::LayerBlurSigma::kBlurDefault));
SetBackground(views::CreateRoundedRectBackground(background_color, SetBackground(views::CreateRoundedRectBackground(background_color,
kErrorBubbleBorderRadius)); kBubbleBorderRadius));
layer()->SetFillsBoundsOpaquely(false); layer()->SetFillsBoundsOpaquely(false);
} }
...@@ -169,21 +169,55 @@ LoginButton* LoginBaseBubbleView::GetBubbleOpener() const { ...@@ -169,21 +169,55 @@ LoginButton* LoginBaseBubbleView::GetBubbleOpener() const {
return nullptr; return nullptr;
} }
bool LoginBaseBubbleView::IsPersistent() const {
return false;
}
void LoginBaseBubbleView::SetPersistent(bool persistent) {}
gfx::Point LoginBaseBubbleView::CalculatePosition() { gfx::Point LoginBaseBubbleView::CalculatePosition() {
if (GetAnchorView()) { if (!GetAnchorView())
gfx::Point bottom_left = GetAnchorView()->bounds().bottom_left(); return gfx::Point();
ConvertPointToTarget(GetAnchorView()->parent() /*source*/,
parent() /*target*/, &bottom_left);
return bottom_left;
}
return gfx::Point(); // Views' positions are defined in the parents' coordinate system. Therefore,
// the position of the bubble needs to be returned in its parent's coordinate
// system. kTryBeforeThenAfter and kTryAfterThenBefore use strategies implying
// to know the bounds of the entire window; therefore, resulting position is
// calculated by using the root view's coordinates system. kShowAbove and
// kShowBelow are less complicated, they only use the coordinate system of the
// the anchor view's parent.
gfx::Point anchor_position = GetAnchorView()->bounds().origin();
ConvertPointToTarget(GetAnchorView()->parent() /*source*/,
GetAnchorView()->GetWidget()->GetRootView() /*target*/,
&anchor_position);
auto bounds = GetBoundsAvailableToShowBubble();
gfx::Size bubble_size(width() + 2 * horizontal_padding_,
height() + vertical_padding_);
gfx::Point result;
View* source;
switch (positioning_strategy_) {
case PositioningStrategy::kTryBeforeThenAfter:
result = login_views_utils::CalculateBubblePositionBeforeAfterStrategy(
{anchor_position, GetAnchorView()->size()}, bubble_size, bounds);
source = GetAnchorView()->GetWidget()->GetRootView();
break;
case PositioningStrategy::kTryAfterThenBefore:
result = login_views_utils::CalculateBubblePositionAfterBeforeStrategy(
{anchor_position, GetAnchorView()->size()}, bubble_size, bounds);
source = GetAnchorView()->GetWidget()->GetRootView();
break;
case PositioningStrategy::kShowAbove: {
gfx::Point top_center = GetAnchorView()->bounds().top_center();
result = top_center - gfx::Vector2d(GetPreferredSize().width() / 2,
GetPreferredSize().height());
source = GetAnchorView()->parent();
break;
}
case PositioningStrategy::kShowBelow: {
result = GetAnchorView()->bounds().bottom_left();
source = GetAnchorView()->parent();
break;
}
}
// Get position of the bubble surrounded by paddings.
result.Offset(horizontal_padding_, 0);
ConvertPointToTarget(source /*source*/, parent() /*target*/, &result);
return result;
} }
void LoginBaseBubbleView::SetAnchorView(views::View* anchor_view) { void LoginBaseBubbleView::SetAnchorView(views::View* anchor_view) {
...@@ -226,36 +260,10 @@ void LoginBaseBubbleView::OnBlur() { ...@@ -226,36 +260,10 @@ void LoginBaseBubbleView::OnBlur() {
Hide(); Hide();
} }
gfx::Point LoginBaseBubbleView::CalculatePositionUsingDefaultStrategy( void LoginBaseBubbleView::SetPadding(int horizontal_padding,
PositioningStrategy strategy, int vertical_padding) {
int horizontal_padding, horizontal_padding_ = horizontal_padding;
int vertical_padding) const { vertical_padding_ = vertical_padding;
if (!GetAnchorView())
return gfx::Point();
gfx::Point anchor_position = GetAnchorView()->bounds().origin();
ConvertPointToTarget(GetAnchorView()->parent() /*source*/,
GetAnchorView()->GetWidget()->GetRootView() /*target*/,
&anchor_position);
auto bounds = GetBoundsAvailableToShowBubble();
gfx::Size bubble_size(width() + 2 * horizontal_padding,
height() + vertical_padding);
gfx::Point result = gfx::Point();
switch (strategy) {
case PositioningStrategy::kShowOnLeftSideOrRightSide:
result = login_views_utils::CalculateBubblePositionLeftRightStrategy(
{anchor_position, GetAnchorView()->size()}, bubble_size, bounds);
break;
case PositioningStrategy::kShowOnRightSideOrLeftSide:
result = login_views_utils::CalculateBubblePositionRightLeftStrategy(
{anchor_position, GetAnchorView()->size()}, bubble_size, bounds);
break;
}
// Get position of the bubble surrounded by paddings.
result.Offset(horizontal_padding, 0);
ConvertPointToTarget(GetAnchorView()->GetWidget()->GetRootView() /*source*/,
parent() /*target*/, &result);
return result;
} }
gfx::Rect LoginBaseBubbleView::GetBoundsAvailableToShowBubble() const { gfx::Rect LoginBaseBubbleView::GetBoundsAvailableToShowBubble() const {
......
...@@ -20,12 +20,27 @@ class LoginBubbleHandler; ...@@ -20,12 +20,27 @@ class LoginBubbleHandler;
class ASH_EXPORT LoginBaseBubbleView : public views::View, class ASH_EXPORT LoginBaseBubbleView : public views::View,
public ui::LayerAnimationObserver { public ui::LayerAnimationObserver {
public: public:
enum class PositioningStrategy {
// Try to show the bubble after the anchor (on the right side in LTR), if
// there is no space show before.
kTryAfterThenBefore,
// Try to show the bubble before the anchor (on the left side in LTR), if
// there is no space show after.
kTryBeforeThenAfter,
// Show the bubble above the anchor.
kShowAbove,
// Show the bubble on the bottom left of the anchor.
kShowBelow,
};
// Without specifying a parent_window, the bubble will default to being in the // Without specifying a parent_window, the bubble will default to being in the
// same container as anchor_view. // same container as anchor_view.
explicit LoginBaseBubbleView(views::View* anchor_view); explicit LoginBaseBubbleView(views::View* anchor_view);
explicit LoginBaseBubbleView(views::View* anchor_view, explicit LoginBaseBubbleView(views::View* anchor_view,
gfx::NativeView parent_window); gfx::NativeView parent_window);
~LoginBaseBubbleView() override; ~LoginBaseBubbleView() override;
LoginBaseBubbleView(const LoginBaseBubbleView&) = delete;
LoginBaseBubbleView& operator=(const LoginBaseBubbleView&) = delete;
void Show(); void Show();
void Hide(); void Hide();
...@@ -34,12 +49,9 @@ class ASH_EXPORT LoginBaseBubbleView : public views::View, ...@@ -34,12 +49,9 @@ class ASH_EXPORT LoginBaseBubbleView : public views::View,
virtual LoginButton* GetBubbleOpener() const; virtual LoginButton* GetBubbleOpener() const;
// Returns whether or not this bubble should show persistently. // Returns whether or not this bubble should show persistently.
virtual bool IsPersistent() const; bool is_persistent() const { return is_persistent_; }
// Change the persistence of the bubble. // Change the persistence of the bubble.
virtual void SetPersistent(bool persistent); void set_persistent(bool is_persistent) { is_persistent_ = is_persistent; }
// Determine the position of the bubble prior to showing.
virtual gfx::Point CalculatePosition();
void SetAnchorView(views::View* anchor_view); void SetAnchorView(views::View* anchor_view);
views::View* GetAnchorView() const { return anchor_view_; } views::View* GetAnchorView() const { return anchor_view_; }
...@@ -55,20 +67,12 @@ class ASH_EXPORT LoginBaseBubbleView : public views::View, ...@@ -55,20 +67,12 @@ class ASH_EXPORT LoginBaseBubbleView : public views::View,
void Layout() override; void Layout() override;
void OnBlur() override; void OnBlur() override;
protected: void set_positioning_strategy(PositioningStrategy positioning_strategy) {
enum class PositioningStrategy { positioning_strategy_ = positioning_strategy;
// Try to show bubble on the right side of the anchor, if there is no space }
// show on the left side. void SetPadding(int horizontal_padding, int vertical_padding);
kShowOnRightSideOrLeftSide,
// Try to show bubble on the left side of the anchor, if there is no space
// show on the right side.
kShowOnLeftSideOrRightSide,
};
// Returns calculated position using default positioning strategies.
gfx::Point CalculatePositionUsingDefaultStrategy(PositioningStrategy strategy,
int horizontal_padding,
int vertical_padding) const;
protected:
// Return area where bubble could be shown in. // Return area where bubble could be shown in.
gfx::Rect GetBoundsAvailableToShowBubble() const; gfx::Rect GetBoundsAvailableToShowBubble() const;
...@@ -83,11 +87,19 @@ class ASH_EXPORT LoginBaseBubbleView : public views::View, ...@@ -83,11 +87,19 @@ class ASH_EXPORT LoginBaseBubbleView : public views::View,
gfx::Rect GetWorkArea() const; gfx::Rect GetWorkArea() const;
void ScheduleAnimation(bool visible); void ScheduleAnimation(bool visible);
// Determine the position of the bubble prior to showing.
gfx::Point CalculatePosition();
views::View* anchor_view_; views::View* anchor_view_;
std::unique_ptr<LoginBubbleHandler> bubble_handler_; std::unique_ptr<LoginBubbleHandler> bubble_handler_;
DISALLOW_COPY_AND_ASSIGN(LoginBaseBubbleView); bool is_persistent_ = false;
// Positioning strategy of the bubble.
PositioningStrategy positioning_strategy_ = PositioningStrategy::kShowBelow;
int horizontal_padding_ = 0;
int vertical_padding_ = 0;
}; };
} // namespace ash } // namespace ash
......
...@@ -26,14 +26,11 @@ constexpr int kAlertIconSizeDp = 20; ...@@ -26,14 +26,11 @@ constexpr int kAlertIconSizeDp = 20;
} // namespace } // namespace
LoginErrorBubble::LoginErrorBubble() LoginErrorBubble::LoginErrorBubble()
: LoginErrorBubble(nullptr /*content*/, : LoginErrorBubble(nullptr /*content*/, nullptr /*anchor_view*/) {}
nullptr /*anchor_view*/,
false /*is_persistent*/) {}
LoginErrorBubble::LoginErrorBubble(views::View* content, LoginErrorBubble::LoginErrorBubble(views::View* content,
views::View* anchor_view, views::View* anchor_view)
bool is_persistent) : LoginBaseBubbleView(anchor_view) {
: LoginBaseBubbleView(anchor_view), is_persistent_(is_persistent) {
views::ImageView* alert_icon = new views::ImageView(); views::ImageView* alert_icon = new views::ImageView();
alert_icon->SetPreferredSize(gfx::Size(kAlertIconSizeDp, kAlertIconSizeDp)); alert_icon->SetPreferredSize(gfx::Size(kAlertIconSizeDp, kAlertIconSizeDp));
alert_icon->SetImage( alert_icon->SetImage(
...@@ -64,14 +61,6 @@ void LoginErrorBubble::SetAccessibleName(const base::string16& name) { ...@@ -64,14 +61,6 @@ void LoginErrorBubble::SetAccessibleName(const base::string16& name) {
accessible_name_ = name; accessible_name_ = name;
} }
bool LoginErrorBubble::IsPersistent() const {
return is_persistent_;
}
void LoginErrorBubble::SetPersistent(bool persistent) {
is_persistent_ = persistent;
}
const char* LoginErrorBubble::GetClassName() const { const char* LoginErrorBubble::GetClassName() const {
return "LoginErrorBubble"; return "LoginErrorBubble";
} }
......
...@@ -15,9 +15,7 @@ namespace ash { ...@@ -15,9 +15,7 @@ namespace ash {
class ASH_EXPORT LoginErrorBubble : public LoginBaseBubbleView { class ASH_EXPORT LoginErrorBubble : public LoginBaseBubbleView {
public: public:
LoginErrorBubble(); LoginErrorBubble();
LoginErrorBubble(views::View* content, LoginErrorBubble(views::View* content, views::View* anchor_view);
views::View* anchor_view,
bool is_persistent);
~LoginErrorBubble() override; ~LoginErrorBubble() override;
void SetContent(views::View* content); void SetContent(views::View* content);
...@@ -29,17 +27,12 @@ class ASH_EXPORT LoginErrorBubble : public LoginBaseBubbleView { ...@@ -29,17 +27,12 @@ class ASH_EXPORT LoginErrorBubble : public LoginBaseBubbleView {
// on bubble show – when the alert event occurs. // on bubble show – when the alert event occurs.
void SetAccessibleName(const base::string16& name); void SetAccessibleName(const base::string16& name);
// LoginBaseBubbleView:
bool IsPersistent() const override;
void SetPersistent(bool persistent) override;
// views::View: // views::View:
const char* GetClassName() const override; const char* GetClassName() const override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
private: private:
views::View* content_ = nullptr; views::View* content_ = nullptr;
bool is_persistent_;
// Accessibility data. // Accessibility data.
base::string16 accessible_name_; base::string16 accessible_name_;
......
...@@ -26,8 +26,8 @@ TEST_F(LoginErrorBubbleTest, PersistentEventHandling) { ...@@ -26,8 +26,8 @@ TEST_F(LoginErrorBubbleTest, PersistentEventHandling) {
views::style::CONTEXT_LABEL, views::style::CONTEXT_LABEL,
views::style::STYLE_PRIMARY); views::style::STYLE_PRIMARY);
auto* bubble = new LoginErrorBubble(label /*content*/, anchor_view, auto* bubble = new LoginErrorBubble(label /*content*/, anchor_view);
true /*is_persistent*/); bubble->set_persistent(true);
container->AddChildView(bubble); container->AddChildView(bubble);
EXPECT_FALSE(bubble->GetVisible()); EXPECT_FALSE(bubble->GetVisible());
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "ash/login/ui/login_unpositioned_tooltip_view.h" #include "ash/login/ui/login_tooltip_view.h"
#include "ash/login/ui/non_accessible_view.h" #include "ash/login/ui/non_accessible_view.h"
#include "ash/login/ui/views_utils.h" #include "ash/login/ui/views_utils.h"
...@@ -24,9 +24,8 @@ constexpr int kInfoIconSizeDp = 20; ...@@ -24,9 +24,8 @@ constexpr int kInfoIconSizeDp = 20;
} // namespace } // namespace
LoginUnpositionedTooltipView::LoginUnpositionedTooltipView( LoginTooltipView::LoginTooltipView(const base::string16& message,
const base::string16& message, views::View* anchor_view)
views::View* anchor_view)
: LoginBaseBubbleView(anchor_view) { : LoginBaseBubbleView(anchor_view) {
views::ImageView* info_icon = new views::ImageView(); views::ImageView* info_icon = new views::ImageView();
info_icon->SetPreferredSize(gfx::Size(kInfoIconSizeDp, kInfoIconSizeDp)); info_icon->SetPreferredSize(gfx::Size(kInfoIconSizeDp, kInfoIconSizeDp));
...@@ -38,14 +37,13 @@ LoginUnpositionedTooltipView::LoginUnpositionedTooltipView( ...@@ -38,14 +37,13 @@ LoginUnpositionedTooltipView::LoginUnpositionedTooltipView(
AddChildView(label_); AddChildView(label_);
} }
LoginUnpositionedTooltipView::~LoginUnpositionedTooltipView() = default; LoginTooltipView::~LoginTooltipView() = default;
void LoginUnpositionedTooltipView::SetText(const base::string16& message) { void LoginTooltipView::SetText(const base::string16& message) {
label_->SetText(message); label_->SetText(message);
} }
void LoginUnpositionedTooltipView::GetAccessibleNodeData( void LoginTooltipView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
ui::AXNodeData* node_data) {
node_data->role = ax::mojom::Role::kTooltip; node_data->role = ax::mojom::Role::kTooltip;
} }
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef ASH_LOGIN_UI_LOGIN_UNPOSITIONED_TOOLTIP_VIEW_H_ #ifndef ASH_LOGIN_UI_LOGIN_TOOLTIP_VIEW_H_
#define ASH_LOGIN_UI_LOGIN_UNPOSITIONED_TOOLTIP_VIEW_H_ #define ASH_LOGIN_UI_LOGIN_TOOLTIP_VIEW_H_
#include "ash/login/ui/login_base_bubble_view.h" #include "ash/login/ui/login_base_bubble_view.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
...@@ -15,13 +15,10 @@ class Label; ...@@ -15,13 +15,10 @@ class Label;
namespace ash { namespace ash {
// TODO(crbug.com/1109266): Get rid of this class and make class LoginTooltipView : public LoginBaseBubbleView {
// LoginBaseBubbleView more configurable.
class LoginUnpositionedTooltipView : public LoginBaseBubbleView {
public: public:
LoginUnpositionedTooltipView(const base::string16& message, LoginTooltipView(const base::string16& message, views::View* anchor_view);
views::View* anchor_view); ~LoginTooltipView() override;
~LoginUnpositionedTooltipView() override;
void SetText(const base::string16& message); void SetText(const base::string16& message);
...@@ -34,9 +31,9 @@ class LoginUnpositionedTooltipView : public LoginBaseBubbleView { ...@@ -34,9 +31,9 @@ class LoginUnpositionedTooltipView : public LoginBaseBubbleView {
private: private:
views::Label* label_ = nullptr; views::Label* label_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(LoginUnpositionedTooltipView); DISALLOW_COPY_AND_ASSIGN(LoginTooltipView);
}; };
} // namespace ash } // namespace ash
#endif // ASH_LOGIN_UI_LOGIN_UNPOSITIONED_TOOLTIP_VIEW_H_ #endif // ASH_LOGIN_UI_LOGIN_TOOLTIP_VIEW_H_
...@@ -191,6 +191,10 @@ LoginUserMenuView::LoginUserMenuView( ...@@ -191,6 +191,10 @@ LoginUserMenuView::LoginUserMenuView(
remove_user_button_->SetID(kUserMenuRemoveUserButtonIdForTest); remove_user_button_->SetID(kUserMenuRemoveUserButtonIdForTest);
AddChildView(remove_user_button_); AddChildView(remove_user_button_);
} }
set_positioning_strategy(PositioningStrategy::kTryAfterThenBefore);
SetPadding(kHorizontalPaddingLoginUserMenuViewDp,
kVerticalPaddingLoginUserMenuViewDp);
} }
LoginUserMenuView::~LoginUserMenuView() = default; LoginUserMenuView::~LoginUserMenuView() = default;
...@@ -243,13 +247,6 @@ void LoginUserMenuView::ButtonPressed(views::Button* sender, ...@@ -243,13 +247,6 @@ void LoginUserMenuView::ButtonPressed(views::Button* sender,
std::move(on_remove_user_requested_).Run(); std::move(on_remove_user_requested_).Run();
} }
gfx::Point LoginUserMenuView::CalculatePosition() {
return CalculatePositionUsingDefaultStrategy(
PositioningStrategy::kShowOnRightSideOrLeftSide,
kHorizontalPaddingLoginUserMenuViewDp,
kVerticalPaddingLoginUserMenuViewDp);
}
void LoginUserMenuView::RequestFocus() { void LoginUserMenuView::RequestFocus() {
// This view has no actual interesting contents to focus, so immediately // This view has no actual interesting contents to focus, so immediately
// forward to the button. // forward to the button.
......
...@@ -49,7 +49,6 @@ class ASH_EXPORT LoginUserMenuView : public LoginBaseBubbleView, ...@@ -49,7 +49,6 @@ class ASH_EXPORT LoginUserMenuView : public LoginBaseBubbleView,
// LoginBaseBubbleView: // LoginBaseBubbleView:
LoginButton* GetBubbleOpener() const override; LoginButton* GetBubbleOpener() const override;
gfx::Point CalculatePosition() override;
// views::ButtonListener: // views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override; void ButtonPressed(views::Button* sender, const ui::Event& event) override;
......
...@@ -148,13 +148,13 @@ views::View* GetBubbleContainer(views::View* view) { ...@@ -148,13 +148,13 @@ views::View* GetBubbleContainer(views::View* view) {
return container; return container;
} }
gfx::Point CalculateBubblePositionLeftRightStrategy(gfx::Rect anchor, gfx::Point CalculateBubblePositionBeforeAfterStrategy(gfx::Rect anchor,
gfx::Size bubble, gfx::Size bubble,
gfx::Rect bounds) { gfx::Rect bounds) {
gfx::Rect result(anchor.x() - bubble.width(), anchor.y(), bubble.width(), gfx::Rect result(anchor.x() - bubble.width(), anchor.y(), bubble.width(),
bubble.height()); bubble.height());
// Trying to show on the left side. // Trying to show before (on the left side in LTR).
// If there is not enough space show on the right side. // If there is not enough space show after (on the right side in LTR).
if (result.x() < bounds.x()) { if (result.x() < bounds.x()) {
result.Offset(anchor.width() + result.width(), 0); result.Offset(anchor.width() + result.width(), 0);
} }
...@@ -162,13 +162,13 @@ gfx::Point CalculateBubblePositionLeftRightStrategy(gfx::Rect anchor, ...@@ -162,13 +162,13 @@ gfx::Point CalculateBubblePositionLeftRightStrategy(gfx::Rect anchor,
return result.origin(); return result.origin();
} }
gfx::Point CalculateBubblePositionRightLeftStrategy(gfx::Rect anchor, gfx::Point CalculateBubblePositionAfterBeforeStrategy(gfx::Rect anchor,
gfx::Size bubble, gfx::Size bubble,
gfx::Rect bounds) { gfx::Rect bounds) {
gfx::Rect result(anchor.x() + anchor.width(), anchor.y(), bubble.width(), gfx::Rect result(anchor.x() + anchor.width(), anchor.y(), bubble.width(),
bubble.height()); bubble.height());
// Trying to show on the right side. // Trying to show after (on the right side in LTR).
// If there is not enough space show on the left side. // If there is not enough space show before (on the left side in LTR).
if (result.right() > bounds.right()) { if (result.right() > bounds.right()) {
result.Offset(-anchor.width() - result.width(), 0); result.Offset(-anchor.width() - result.width(), 0);
} }
......
...@@ -44,12 +44,12 @@ views::Label* CreateBubbleLabel( ...@@ -44,12 +44,12 @@ views::Label* CreateBubbleLabel(
// Get the bubble container for |view| to place a LoginBaseBubbleView. // Get the bubble container for |view| to place a LoginBaseBubbleView.
views::View* GetBubbleContainer(views::View* view); views::View* GetBubbleContainer(views::View* view);
ASH_EXPORT gfx::Point CalculateBubblePositionLeftRightStrategy( ASH_EXPORT gfx::Point CalculateBubblePositionAfterBeforeStrategy(
gfx::Rect anchor, gfx::Rect anchor,
gfx::Size bubble, gfx::Size bubble,
gfx::Rect bounds); gfx::Rect bounds);
ASH_EXPORT gfx::Point CalculateBubblePositionRightLeftStrategy( ASH_EXPORT gfx::Point CalculateBubblePositionBeforeAfterStrategy(
gfx::Rect anchor, gfx::Rect anchor,
gfx::Size bubble, gfx::Size bubble,
gfx::Rect bounds); gfx::Rect bounds);
......
...@@ -23,78 +23,78 @@ class ViewsUtilsUnittest : public testing::Test { ...@@ -23,78 +23,78 @@ class ViewsUtilsUnittest : public testing::Test {
} // namespace } // namespace
TEST_F(ViewsUtilsUnittest, LeftRightStrategySimpleTest) { TEST_F(ViewsUtilsUnittest, BeforeAfterStrategySimpleTest) {
const gfx::Rect anchor(10, 10, 10, 10); const gfx::Rect anchor(10, 10, 10, 10);
const gfx::Size bubble(5, 5); const gfx::Size bubble(5, 5);
const gfx::Rect bounds(20, 20); const gfx::Rect bounds(20, 20);
const gfx::Point result_point(anchor.x() - bubble.width(), anchor.y()); const gfx::Point result_point(anchor.x() - bubble.width(), anchor.y());
EXPECT_EQ(result_point, EXPECT_EQ(result_point,
CalculateBubblePositionLeftRightStrategy(anchor, bubble, bounds)); CalculateBubblePositionBeforeAfterStrategy(anchor, bubble, bounds));
} }
TEST_F(ViewsUtilsUnittest, LeftRightStrategyNotEnoughHeightBottom) { TEST_F(ViewsUtilsUnittest, BeforeAfterStrategyNotEnoughHeightBottom) {
const gfx::Rect anchor(10, 10, 10, 10); const gfx::Rect anchor(10, 10, 10, 10);
const gfx::Size bubble(5, 15); const gfx::Size bubble(5, 15);
const gfx::Rect bounds(20, 20); const gfx::Rect bounds(20, 20);
const gfx::Point result_point(anchor.x() - bubble.width(), const gfx::Point result_point(anchor.x() - bubble.width(),
bounds.height() - bubble.height()); bounds.height() - bubble.height());
EXPECT_EQ(result_point, EXPECT_EQ(result_point,
CalculateBubblePositionLeftRightStrategy(anchor, bubble, bounds)); CalculateBubblePositionBeforeAfterStrategy(anchor, bubble, bounds));
} }
TEST_F(ViewsUtilsUnittest, LeftRightStrategyNotEnoughHeightBottomAndTop) { TEST_F(ViewsUtilsUnittest, BeforeAfterStrategyNotEnoughHeightBottomAndTop) {
const gfx::Rect anchor(10, 10, 10, 10); const gfx::Rect anchor(10, 10, 10, 10);
const gfx::Size bubble(5, 25); const gfx::Size bubble(5, 25);
const gfx::Rect bounds(20, 20); const gfx::Rect bounds(20, 20);
const gfx::Point result_point(anchor.x() - bubble.width(), bounds.y()); const gfx::Point result_point(anchor.x() - bubble.width(), bounds.y());
EXPECT_EQ(result_point, EXPECT_EQ(result_point,
CalculateBubblePositionLeftRightStrategy(anchor, bubble, bounds)); CalculateBubblePositionBeforeAfterStrategy(anchor, bubble, bounds));
} }
TEST_F(ViewsUtilsUnittest, LeftRightStrategyNotEnoughWidthLeft) { TEST_F(ViewsUtilsUnittest, BeforeAfterStrategyNotEnoughWidthBefore) {
const gfx::Rect anchor(2, 10, 10, 10); const gfx::Rect anchor(2, 10, 10, 10);
const gfx::Size bubble(5, 5); const gfx::Size bubble(5, 5);
const gfx::Rect bounds(20, 20); const gfx::Rect bounds(20, 20);
const gfx::Point result_point(anchor.x() + anchor.width(), anchor.y()); const gfx::Point result_point(anchor.x() + anchor.width(), anchor.y());
EXPECT_EQ(result_point, EXPECT_EQ(result_point,
CalculateBubblePositionLeftRightStrategy(anchor, bubble, bounds)); CalculateBubblePositionBeforeAfterStrategy(anchor, bubble, bounds));
} }
TEST_F(ViewsUtilsUnittest, RightLeftStrategySimpleTest) { TEST_F(ViewsUtilsUnittest, AfterBeforeStrategySimpleTest) {
const gfx::Rect anchor(0, 10, 10, 10); const gfx::Rect anchor(0, 10, 10, 10);
const gfx::Size bubble(5, 5); const gfx::Size bubble(5, 5);
const gfx::Rect bounds(20, 20); const gfx::Rect bounds(20, 20);
const gfx::Point result_point(anchor.x() + anchor.width(), anchor.y()); const gfx::Point result_point(anchor.x() + anchor.width(), anchor.y());
EXPECT_EQ(result_point, EXPECT_EQ(result_point,
CalculateBubblePositionRightLeftStrategy(anchor, bubble, bounds)); CalculateBubblePositionAfterBeforeStrategy(anchor, bubble, bounds));
} }
TEST_F(ViewsUtilsUnittest, RightLeftStrategyNotEnoughHeightBottom) { TEST_F(ViewsUtilsUnittest, AfterBeforeStrategyNotEnoughHeightBottom) {
const gfx::Rect anchor(0, 10, 10, 10); const gfx::Rect anchor(0, 10, 10, 10);
const gfx::Size bubble(5, 15); const gfx::Size bubble(5, 15);
const gfx::Rect bounds(20, 20); const gfx::Rect bounds(20, 20);
const gfx::Point result_point(anchor.x() + anchor.width(), const gfx::Point result_point(anchor.x() + anchor.width(),
bounds.height() - bubble.height()); bounds.height() - bubble.height());
EXPECT_EQ(result_point, EXPECT_EQ(result_point,
CalculateBubblePositionRightLeftStrategy(anchor, bubble, bounds)); CalculateBubblePositionAfterBeforeStrategy(anchor, bubble, bounds));
} }
TEST_F(ViewsUtilsUnittest, RightLeftStrategyNotEnoughHeightBottomAndTop) { TEST_F(ViewsUtilsUnittest, AfterBeforeStrategyNotEnoughHeightBottomAndTop) {
const gfx::Rect anchor(0, 10, 10, 10); const gfx::Rect anchor(0, 10, 10, 10);
const gfx::Size bubble(5, 25); const gfx::Size bubble(5, 25);
const gfx::Rect bounds(20, 20); const gfx::Rect bounds(20, 20);
const gfx::Point result_point(anchor.x() + anchor.width(), bounds.y()); const gfx::Point result_point(anchor.x() + anchor.width(), bounds.y());
EXPECT_EQ(result_point, EXPECT_EQ(result_point,
CalculateBubblePositionRightLeftStrategy(anchor, bubble, bounds)); CalculateBubblePositionAfterBeforeStrategy(anchor, bubble, bounds));
} }
TEST_F(ViewsUtilsUnittest, RightLeftStrategyNotEnoughWidthRight) { TEST_F(ViewsUtilsUnittest, AfterBeforeStrategyNotEnoughWidthAfter) {
const gfx::Rect anchor(10, 10, 10, 10); const gfx::Rect anchor(10, 10, 10, 10);
const gfx::Size bubble(5, 5); const gfx::Size bubble(5, 5);
const gfx::Rect bounds(20, 20); const gfx::Rect bounds(20, 20);
const gfx::Point result_point(anchor.x() - bubble.width(), anchor.y()); const gfx::Point result_point(anchor.x() - bubble.width(), anchor.y());
EXPECT_EQ(result_point, EXPECT_EQ(result_point,
CalculateBubblePositionRightLeftStrategy(anchor, bubble, bounds)); CalculateBubblePositionAfterBeforeStrategy(anchor, bubble, bounds));
} }
} // namespace login_views_utils } // namespace login_views_utils
......
...@@ -36,7 +36,7 @@ class ASH_PUBLIC_EXPORT LoginScreenTestApi { ...@@ -36,7 +36,7 @@ class ASH_PUBLIC_EXPORT LoginScreenTestApi {
static bool IsParentAccessButtonShown(); static bool IsParentAccessButtonShown();
static bool IsEnterpriseEnrollmentButtonShown(); static bool IsEnterpriseEnrollmentButtonShown();
static bool IsWarningBubbleShown(); static bool IsWarningBubbleShown();
static bool IsUserAddingScreenBubbleShown(); static bool IsUserAddingScreenIndicatorShown();
static bool IsSystemInfoShown(); static bool IsSystemInfoShown();
static bool IsPasswordFieldShown(const AccountId& account_id); static bool IsPasswordFieldShown(const AccountId& account_id);
static bool IsDisplayPasswordButtonShown(const AccountId& account_id); static bool IsDisplayPasswordButtonShown(const AccountId& account_id);
......
...@@ -583,7 +583,7 @@ IN_PROC_BROWSER_TEST_F(UserAddingScreenViewBasedTest, InfoBubbleVisible) { ...@@ -583,7 +583,7 @@ IN_PROC_BROWSER_TEST_F(UserAddingScreenViewBasedTest, InfoBubbleVisible) {
EXPECT_EQ(session_manager::SessionManager::Get()->session_state(), EXPECT_EQ(session_manager::SessionManager::Get()->session_state(),
session_manager::SessionState::LOGIN_PRIMARY); session_manager::SessionState::LOGIN_PRIMARY);
EXPECT_FALSE(ash::LoginScreenTestApi::IsUserAddingScreenBubbleShown()); EXPECT_FALSE(ash::LoginScreenTestApi::IsUserAddingScreenIndicatorShown());
LoginUser(users[0].account_id); LoginUser(users[0].account_id);
EXPECT_EQ(user_manager::UserManager::Get()->GetLoggedInUsers().size(), 1u); EXPECT_EQ(user_manager::UserManager::Get()->GetLoggedInUsers().size(), 1u);
...@@ -601,7 +601,7 @@ IN_PROC_BROWSER_TEST_F(UserAddingScreenViewBasedTest, InfoBubbleVisible) { ...@@ -601,7 +601,7 @@ IN_PROC_BROWSER_TEST_F(UserAddingScreenViewBasedTest, InfoBubbleVisible) {
EXPECT_EQ(session_manager::SessionManager::Get()->session_state(), EXPECT_EQ(session_manager::SessionManager::Get()->session_state(),
session_manager::SessionState::LOGIN_SECONDARY); session_manager::SessionState::LOGIN_SECONDARY);
EXPECT_TRUE(ash::LoginScreenTestApi::IsUserAddingScreenBubbleShown()); EXPECT_TRUE(ash::LoginScreenTestApi::IsUserAddingScreenIndicatorShown());
AddUser(users[i].account_id); AddUser(users[i].account_id);
users_in_session_order_.push_back(users[i].account_id); users_in_session_order_.push_back(users[i].account_id);
......
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