Commit a5e46636 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Change ButtonPressed overrides to callbacks: ash/login/

Bug: 772945
Change-Id: I51af3cf1070b81f8458dec3a6e28cb1625944dc2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518711
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824112}
parent 5a9883f5
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "components/session_manager/session_manager_types.h" #include "components/session_manager/session_manager_types.h"
#include "ui/events/base_event_utils.h" #include "ui/events/base_event_utils.h"
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
#include "ui/views/test/button_test_api.h"
namespace ash { namespace ash {
...@@ -53,7 +54,7 @@ class ParentAccessControllerImplTest : public LoginTestBase { ...@@ -53,7 +54,7 @@ class ParentAccessControllerImplTest : public LoginTestBase {
void SimulateButtonPress(views::Button* button) { void SimulateButtonPress(views::Button* button) {
ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), 0, 0); ui::EventTimeForNow(), 0, 0);
view_->ButtonPressed(button, event); views::test::ButtonTestApi(button).NotifyClick(event);
} }
// Called when ParentAccessView finished processing. // Called when ParentAccessView finished processing.
......
...@@ -88,7 +88,7 @@ bool SimulateButtonPressedForTesting(LoginShelfView::ButtonId button_id) { ...@@ -88,7 +88,7 @@ bool SimulateButtonPressedForTesting(LoginShelfView::ButtonId button_id) {
if (!button->GetEnabled()) if (!button->GetEnabled())
return false; return false;
views::test::ButtonTestApi(static_cast<views::Button*>(button)) views::test::ButtonTestApi(views::Button::AsButton(button))
.NotifyClick(ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(), .NotifyClick(ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(),
gfx::PointF(), base::TimeTicks(), 0, 0)); gfx::PointF(), base::TimeTicks(), 0, 0));
return true; return true;
...@@ -513,7 +513,10 @@ bool LoginScreenTestApi::ExpandPublicSessionPod(const AccountId& account_id) { ...@@ -513,7 +513,10 @@ bool LoginScreenTestApi::ExpandPublicSessionPod(const AccountId& account_id) {
ADD_FAILURE() << "Arrow button not visible"; ADD_FAILURE() << "Arrow button not visible";
return false; return false;
} }
public_account_test.OnArrowTap(); views::test::ButtonTestApi(
views::Button::AsButton(public_account_test.arrow_button()))
.NotifyClick(ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(),
gfx::PointF(), base::TimeTicks(), 0, 0));
return lock_contents_test.expanded_view(); return lock_contents_test.expanded_view();
} }
...@@ -567,7 +570,10 @@ void LoginScreenTestApi::ClickPublicExpandedAdvancedViewButton() { ...@@ -567,7 +570,10 @@ void LoginScreenTestApi::ClickPublicExpandedAdvancedViewButton() {
lock_screen_test.contents_view()); lock_screen_test.contents_view());
LoginExpandedPublicAccountView::TestApi expanded_test( LoginExpandedPublicAccountView::TestApi expanded_test(
lock_contents_test.expanded_view()); lock_contents_test.expanded_view());
expanded_test.OnAdvancedButtonTap(); views::test::ButtonTestApi(
views::Button::AsButton(expanded_test.advanced_view_button()))
.NotifyClick(ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(),
gfx::PointF(), base::TimeTicks(), 0, 0));
} }
// static // static
...@@ -577,7 +583,10 @@ void LoginScreenTestApi::ClickPublicExpandedSubmitButton() { ...@@ -577,7 +583,10 @@ void LoginScreenTestApi::ClickPublicExpandedSubmitButton() {
lock_screen_test.contents_view()); lock_screen_test.contents_view());
LoginExpandedPublicAccountView::TestApi expanded_test( LoginExpandedPublicAccountView::TestApi expanded_test(
lock_contents_test.expanded_view()); lock_contents_test.expanded_view());
expanded_test.OnSubmitButtonTap(); views::test::ButtonTestApi(
views::Button::AsButton(expanded_test.submit_button()))
.NotifyClick(ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(),
gfx::PointF(), base::TimeTicks(), 0, 0));
} }
// static // static
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "ui/events/types/event_type.h" #include "ui/events/types/event_type.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/test/button_test_api.h"
namespace ash { namespace ash {
...@@ -45,7 +46,7 @@ class SecurityTokenRequestControllerTest : public LoginTestBase { ...@@ -45,7 +46,7 @@ class SecurityTokenRequestControllerTest : public LoginTestBase {
void SimulateButtonPress(views::Button* button) { void SimulateButtonPress(views::Button* button) {
ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), 0, 0); ui::EventTimeForNow(), 0, 0);
view_->ButtonPressed(button, event); views::test::ButtonTestApi(button).NotifyClick(event);
} }
void StartRequest(int attempts_left = -1) { void StartRequest(int attempts_left = -1) {
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
namespace ash { namespace ash {
BottomStatusIndicator::BottomStatusIndicator(TappedCallback on_tapped_callback) BottomStatusIndicator::BottomStatusIndicator(TappedCallback on_tapped_callback)
: LabelButton(this), on_tapped_callback_(std::move(on_tapped_callback)) { : LabelButton(std::move(on_tapped_callback)) {
label()->SetAutoColorReadabilityEnabled(false); label()->SetAutoColorReadabilityEnabled(false);
label()->SetFontList( label()->SetFontList(
views::Label::GetDefaultFontList().DeriveWithSizeDelta(1)); views::Label::GetDefaultFontList().DeriveWithSizeDelta(1));
...@@ -34,13 +34,6 @@ void BottomStatusIndicator::SetIcon(const gfx::VectorIcon& vector_icon, ...@@ -34,13 +34,6 @@ void BottomStatusIndicator::SetIcon(const gfx::VectorIcon& vector_icon,
vector_icon, AshColorProvider::Get()->GetContentLayerColor(type))); vector_icon, AshColorProvider::Get()->GetContentLayerColor(type)));
} }
void BottomStatusIndicator::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK(sender == this);
DCHECK(on_tapped_callback_);
on_tapped_callback_.Run();
}
void BottomStatusIndicator::GetAccessibleNodeData(ui::AXNodeData* node_data) { void BottomStatusIndicator::GetAccessibleNodeData(ui::AXNodeData* node_data) {
node_data->role = role_; node_data->role = role_;
node_data->SetName(label()->GetText()); node_data->SetName(label()->GetText());
......
...@@ -17,8 +17,7 @@ struct VectorIcon; ...@@ -17,8 +17,7 @@ struct VectorIcon;
namespace ash { namespace ash {
class BottomStatusIndicator : public views::LabelButton, class BottomStatusIndicator : public views::LabelButton {
public views::ButtonListener {
public: public:
using TappedCallback = base::RepeatingClosure; using TappedCallback = base::RepeatingClosure;
...@@ -32,14 +31,10 @@ class BottomStatusIndicator : public views::LabelButton, ...@@ -32,14 +31,10 @@ class BottomStatusIndicator : public views::LabelButton,
void set_role_for_accessibility(ax::mojom::Role role) { role_ = role; } void set_role_for_accessibility(ax::mojom::Role role) { role_ = role; }
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::View: // views::View:
void GetAccessibleNodeData(ui::AXNodeData* node_data) override; void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
private: private:
TappedCallback on_tapped_callback_;
ax::mojom::Role role_ = ax::mojom::Role::kStaticText; ax::mojom::Role role_ = ax::mojom::Role::kStaticText;
}; };
......
...@@ -362,21 +362,13 @@ class UserAddingScreenIndicator : public views::View { ...@@ -362,21 +362,13 @@ class UserAddingScreenIndicator : public views::View {
} // namespace } // namespace
class LockContentsView::AuthErrorBubble : public LoginErrorBubble, class LockContentsView::AuthErrorBubble : public LoginErrorBubble {
public views::ButtonListener {
public: public:
AuthErrorBubble() { AuthErrorBubble() {
set_positioning_strategy(PositioningStrategy::kTryAfterThenBefore); set_positioning_strategy(PositioningStrategy::kTryAfterThenBefore);
SetPadding(kHorizontalPaddingAuthErrorBubbleDp, SetPadding(kHorizontalPaddingAuthErrorBubbleDp,
kVerticalPaddingAuthErrorBubbleDp); kVerticalPaddingAuthErrorBubbleDp);
} }
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override {
Shell::Get()->login_screen_controller()->ShowAccountAccessHelpApp(
GetWidget()->GetNativeWindow());
Hide();
}
}; };
class LockContentsView::ManagementBubble : public LoginTooltipView { class LockContentsView::ManagementBubble : public LoginTooltipView {
...@@ -2104,7 +2096,9 @@ void LockContentsView::ShowAuthErrorMessage() { ...@@ -2104,7 +2096,9 @@ void LockContentsView::ShowAuthErrorMessage() {
label->SetAutoColorReadabilityEnabled(false); label->SetAutoColorReadabilityEnabled(false);
auto learn_more_button = std::make_unique<SystemLabelButton>( auto learn_more_button = std::make_unique<SystemLabelButton>(
auth_error_bubble_, l10n_util::GetStringUTF16(IDS_ASH_LEARN_MORE), base::BindRepeating(&LockContentsView::LearnMoreButtonPressed,
base::Unretained(this)),
l10n_util::GetStringUTF16(IDS_ASH_LEARN_MORE),
SystemLabelButton::DisplayType::DEFAULT, /*multiline*/ true); SystemLabelButton::DisplayType::DEFAULT, /*multiline*/ true);
auto container = std::make_unique<NonAccessibleView>(kAuthErrorContainerName); auto container = std::make_unique<NonAccessibleView>(kAuthErrorContainerName);
...@@ -2202,6 +2196,12 @@ void LockContentsView::OnPublicAccountTapped(bool is_primary) { ...@@ -2202,6 +2196,12 @@ void LockContentsView::OnPublicAccountTapped(bool is_primary) {
SetDisplayStyle(DisplayStyle::kExclusivePublicAccountExpandedView); SetDisplayStyle(DisplayStyle::kExclusivePublicAccountExpandedView);
} }
void LockContentsView::LearnMoreButtonPressed() {
Shell::Get()->login_screen_controller()->ShowAccountAccessHelpApp(
GetWidget()->GetNativeWindow());
auth_error_bubble_->Hide();
}
std::unique_ptr<LoginBigUserView> LockContentsView::AllocateLoginBigUserView( std::unique_ptr<LoginBigUserView> LockContentsView::AllocateLoginBigUserView(
const LoginUserInfo& user, const LoginUserInfo& user,
bool is_primary) { bool is_primary) {
......
...@@ -374,6 +374,8 @@ class ASH_EXPORT LockContentsView ...@@ -374,6 +374,8 @@ class ASH_EXPORT LockContentsView
// Called when the public account is tapped. // Called when the public account is tapped.
void OnPublicAccountTapped(bool is_primary); void OnPublicAccountTapped(bool is_primary);
void LearnMoreButtonPressed();
// Helper method to allocate a LoginBigUserView instance. // Helper method to allocate a LoginBigUserView instance.
std::unique_ptr<LoginBigUserView> AllocateLoginBigUserView( std::unique_ptr<LoginBigUserView> AllocateLoginBigUserView(
const LoginUserInfo& user, const LoginUserInfo& user,
......
This diff is collapsed.
...@@ -28,7 +28,7 @@ enum class TrayActionState; ...@@ -28,7 +28,7 @@ enum class TrayActionState;
} }
// Contains the debug UI row (ie, add user, toggle PIN buttons). // Contains the debug UI row (ie, add user, toggle PIN buttons).
class LockDebugView : public views::View, public views::ButtonListener { class LockDebugView : public views::View {
public: public:
LockDebugView(mojom::TrayActionState initial_note_action_state, LockDebugView(mojom::TrayActionState initial_note_action_state,
LockScreen::ScreenType screen_type); LockScreen::ScreenType screen_type);
...@@ -37,9 +37,6 @@ class LockDebugView : public views::View, public views::ButtonListener { ...@@ -37,9 +37,6 @@ class LockDebugView : public views::View, public views::ButtonListener {
// views::View: // views::View:
void Layout() override; void Layout() override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
LockContentsView* lock() { return lock_; } LockContentsView* lock() { return lock_; }
private: private:
...@@ -53,7 +50,36 @@ class LockDebugView : public views::View, public views::ButtonListener { ...@@ -53,7 +50,36 @@ class LockDebugView : public views::View, public views::ButtonListener {
kDetachableBaseFailed, kDetachableBaseFailed,
}; };
// Cycle through the various types of auth error bubbles that can be shown on // Adds or removes users.
void AddOrRemoveUsersButtonPressed(int delta);
// Iteratively adds more info to the system info labels to test 7 permutations
// and then disables the button.
void AddSystemInfoButtonPressed();
// Enables/disables auth. This is useful for testing auth failure scenarios on
// Linux Desktop builds, where the cryptohome dbus stub accepts all passwords
// as valid.
void ToggleAuthButtonPressed();
void AddKioskAppButtonPressed();
void RemoveKioskAppButtonPressed();
void ToggleDebugDetachableBaseButtonPressed();
void CycleDetachableBaseStatusButtonPressed();
void CycleDetachableBaseIdButtonPressed();
// Shows or hides warning banner.
void ToggleWarningBannerButtonPressed();
void ToggleManagedSessionDisclosureButtonPressed();
// Updates the last used detachable base.
void UseDetachableBaseButtonPressed(int index);
// Converts this user to regular user or public account.
void TogglePublicAccountButtonPressed(int index);
// Cycles through the various types of auth error bubbles that can be shown on
// the login screen. // the login screen.
void CycleAuthErrorMessage(); void CycleAuthErrorMessage();
...@@ -67,7 +93,7 @@ class LockDebugView : public views::View, public views::ButtonListener { ...@@ -67,7 +93,7 @@ class LockDebugView : public views::View, public views::ButtonListener {
// Creates a button on the debug row that cannot be focused. // Creates a button on the debug row that cannot be focused.
views::LabelButton* AddButton(const std::string& text, views::LabelButton* AddButton(const std::string& text,
int id, views::Button::PressedCallback callback,
views::View* container); views::View* container);
LockContentsView* lock_ = nullptr; LockContentsView* lock_ = nullptr;
...@@ -75,9 +101,12 @@ class LockDebugView : public views::View, public views::ButtonListener { ...@@ -75,9 +101,12 @@ class LockDebugView : public views::View, public views::ButtonListener {
// Debug container which holds the entire debug UI. // Debug container which holds the entire debug UI.
views::View* container_ = nullptr; views::View* container_ = nullptr;
// Container which holds global actions. Each child button has an id which can // Container which holds global actions.
// be used to identify it.
views::View* global_action_view_container_ = nullptr; views::View* global_action_view_container_ = nullptr;
// Global add system info button. Reference is needed to dynamically disable.
views::LabelButton* global_action_add_system_info_ = nullptr;
// Global toggle auth button. Reference is needed to update the string. // Global toggle auth button. Reference is needed to update the string.
views::LabelButton* global_action_toggle_auth_ = nullptr; views::LabelButton* global_action_toggle_auth_ = nullptr;
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "components/media_message_center/media_notification_util.h" #include "components/media_message_center/media_notification_util.h"
#include "components/vector_icons/vector_icons.h" #include "components/vector_icons/vector_icons.h"
#include "services/media_session/public/cpp/util.h" #include "services/media_session/public/cpp/util.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
#include "services/media_session/public/mojom/media_session_service.mojom.h" #include "services/media_session/public/mojom/media_session_service.mojom.h"
#include "ui/accessibility/ax_enums.mojom.h" #include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
...@@ -140,11 +139,20 @@ const gfx::VectorIcon& GetVectorIconForMediaAction(MediaSessionAction action) { ...@@ -140,11 +139,20 @@ const gfx::VectorIcon& GetVectorIconForMediaAction(MediaSessionAction action) {
// MediaActionButton is an image button with a custom ink drop mask. // MediaActionButton is an image button with a custom ink drop mask.
class MediaActionButton : public views::ImageButton { class MediaActionButton : public views::ImageButton {
public: public:
MediaActionButton(views::ButtonListener* listener, MediaActionButton(LockScreenMediaControlsView* view,
int icon_size, int icon_size,
MediaSessionAction action, MediaSessionAction action,
const base::string16& accessible_name) const base::string16& accessible_name)
: views::ImageButton(listener), icon_size_(icon_size) { : views::ImageButton(base::BindRepeating(
// Handle dynamically-updated button tags without rebinding.
[](LockScreenMediaControlsView* controls,
MediaActionButton* button) {
controls->ButtonPressed(
media_message_center::GetActionFromButtonTag(*button));
},
view,
this)),
icon_size_(icon_size) {
SetInkDropMode(views::Button::InkDropMode::ON); SetInkDropMode(views::Button::InkDropMode::ON);
SetHasInkDropActionOnClick(true); SetHasInkDropActionOnClick(true);
SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER); SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER);
...@@ -634,21 +642,6 @@ void LockScreenMediaControlsView::OnImplicitAnimationsCompleted() { ...@@ -634,21 +642,6 @@ void LockScreenMediaControlsView::OnImplicitAnimationsCompleted() {
Dismiss(); Dismiss();
} }
void LockScreenMediaControlsView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (!base::Contains(enabled_actions_,
media_message_center::GetActionFromButtonTag(*sender)) ||
!media_session_id_.has_value()) {
return;
}
auto action = media_message_center::GetActionFromButtonTag(*sender);
base::UmaHistogramEnumeration(kMediaControlsUserActionHistogramName, action);
media_session::PerformMediaSessionAction(action, media_controller_remote_);
}
void LockScreenMediaControlsView::OnGestureEvent(ui::GestureEvent* event) { void LockScreenMediaControlsView::OnGestureEvent(ui::GestureEvent* event) {
gfx::Point point_in_screen = event->location(); gfx::Point point_in_screen = event->location();
ConvertPointToScreen(this, &point_in_screen); ConvertPointToScreen(this, &point_in_screen);
...@@ -687,6 +680,16 @@ void LockScreenMediaControlsView::OnSuspend() { ...@@ -687,6 +680,16 @@ void LockScreenMediaControlsView::OnSuspend() {
Hide(HideReason::kDeviceSleep); Hide(HideReason::kDeviceSleep);
} }
void LockScreenMediaControlsView::ButtonPressed(
media_session::mojom::MediaSessionAction action) {
if (base::Contains(enabled_actions_, action) &&
media_session_id_.has_value()) {
base::UmaHistogramEnumeration(kMediaControlsUserActionHistogramName,
action);
media_session::PerformMediaSessionAction(action, media_controller_remote_);
}
}
void LockScreenMediaControlsView::FlushForTesting() { void LockScreenMediaControlsView::FlushForTesting() {
media_controller_remote_.FlushForTesting(); media_controller_remote_.FlushForTesting();
} }
......
...@@ -13,11 +13,13 @@ ...@@ -13,11 +13,13 @@
#include "mojo/public/cpp/bindings/receiver.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "services/media_session/public/mojom/media_controller.mojom.h" #include "services/media_session/public/mojom/media_controller.mojom.h"
#include "services/media_session/public/mojom/media_session.mojom.h"
#include "ui/compositor/layer_animation_observer.h" #include "ui/compositor/layer_animation_observer.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/metadata/metadata_header_macros.h" #include "ui/views/metadata/metadata_header_macros.h"
#include "ui/views/view.h"
namespace views { namespace views {
class Button;
class Label; class Label;
class ImageView; class ImageView;
} // namespace views } // namespace views
...@@ -40,7 +42,6 @@ class ASH_EXPORT LockScreenMediaControlsView ...@@ -40,7 +42,6 @@ class ASH_EXPORT LockScreenMediaControlsView
public media_session::mojom::MediaControllerObserver, public media_session::mojom::MediaControllerObserver,
public media_session::mojom::MediaControllerImageObserver, public media_session::mojom::MediaControllerImageObserver,
public base::PowerObserver, public base::PowerObserver,
public views::ButtonListener,
public ui::ImplicitAnimationObserver { public ui::ImplicitAnimationObserver {
public: public:
METADATA_HEADER(LockScreenMediaControlsView); METADATA_HEADER(LockScreenMediaControlsView);
...@@ -127,15 +128,14 @@ class ASH_EXPORT LockScreenMediaControlsView ...@@ -127,15 +128,14 @@ class ASH_EXPORT LockScreenMediaControlsView
// ui::ImplicitAnimationObserver: // ui::ImplicitAnimationObserver:
void OnImplicitAnimationsCompleted() override; void OnImplicitAnimationsCompleted() override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// ui::EventHandler: // ui::EventHandler:
void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
// base::PowerObserver: // base::PowerObserver:
void OnSuspend() override; void OnSuspend() override;
void ButtonPressed(media_session::mojom::MediaSessionAction action);
void FlushForTesting(); void FlushForTesting();
void set_media_controller_for_testing( void set_media_controller_for_testing(
......
...@@ -540,8 +540,7 @@ class LoginAuthUserView::FingerprintView : public views::View { ...@@ -540,8 +540,7 @@ class LoginAuthUserView::FingerprintView : public views::View {
}; };
// Consists of challenge-response icon view and a label. // Consists of challenge-response icon view and a label.
class LoginAuthUserView::ChallengeResponseView : public views::View, class LoginAuthUserView::ChallengeResponseView : public views::View {
public views::ButtonListener {
public: public:
enum class State { kInitial, kAuthenticating, kFailure }; enum class State { kInitial, kAuthenticating, kFailure };
...@@ -555,7 +554,9 @@ class LoginAuthUserView::ChallengeResponseView : public views::View, ...@@ -555,7 +554,9 @@ class LoginAuthUserView::ChallengeResponseView : public views::View,
layout->set_cross_axis_alignment( layout->set_cross_axis_alignment(
views::BoxLayout::CrossAxisAlignment::kCenter); views::BoxLayout::CrossAxisAlignment::kCenter);
auto arrow_button_view = std::make_unique<ArrowButtonView>( auto arrow_button_view = std::make_unique<ArrowButtonView>(
/*listener=*/this, kChallengeResponseArrowSizeDp); base::BindRepeating(&ChallengeResponseView::ArrowButtonPressed,
base::Unretained(this)),
kChallengeResponseArrowSizeDp);
arrow_button_view->SetInstallFocusRingOnFocus(true); arrow_button_view->SetInstallFocusRingOnFocus(true);
views::InstallCircleHighlightPathGenerator(arrow_button_view.get()); views::InstallCircleHighlightPathGenerator(arrow_button_view.get());
arrow_button_ = AddChildView(std::move(arrow_button_view)); arrow_button_ = AddChildView(std::move(arrow_button_view));
...@@ -588,17 +589,6 @@ class LoginAuthUserView::ChallengeResponseView : public views::View, ...@@ -588,17 +589,6 @@ class LoginAuthUserView::ChallengeResponseView : public views::View,
~ChallengeResponseView() override = default; ~ChallengeResponseView() override = default;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override {
if (sender == arrow_button_) {
// Ignore further clicks while handling the previous one.
if (state_ != State::kAuthenticating)
on_start_tap_.Run();
} else {
NOTREACHED();
}
}
void SetState(State state) { void SetState(State state) {
if (state_ == state) if (state_ == state)
return; return;
...@@ -656,6 +646,12 @@ class LoginAuthUserView::ChallengeResponseView : public views::View, ...@@ -656,6 +646,12 @@ class LoginAuthUserView::ChallengeResponseView : public views::View,
} }
} }
void ArrowButtonPressed() {
// Ignore further clicks while handling the previous one.
if (state_ != State::kAuthenticating)
on_start_tap_.Run();
}
base::RepeatingClosure on_start_tap_; base::RepeatingClosure on_start_tap_;
State state_ = State::kInitial; State state_ = State::kInitial;
ArrowButtonView* arrow_button_ = nullptr; ArrowButtonView* arrow_button_ = nullptr;
...@@ -1035,8 +1031,9 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user, ...@@ -1035,8 +1031,9 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user,
gfx::Insets(kPinPasswordToggleButtonPaddingTop, 0, 0, 0))); gfx::Insets(kPinPasswordToggleButtonPaddingTop, 0, 0, 0)));
pin_password_toggle_ = pin_password_toggle_ =
toggle_container->AddChildView(std::make_unique<SystemLabelButton>( toggle_container->AddChildView(std::make_unique<SystemLabelButton>(
this, GetPinPasswordToggleText(), base::BindRepeating(&LoginAuthUserView::OnSwitchButtonClicked,
SystemLabelButton::DisplayType::DEFAULT, base::Unretained(this)),
GetPinPasswordToggleText(), SystemLabelButton::DisplayType::DEFAULT,
/*multiline*/ false)); /*multiline*/ false));
pin_password_toggle_->SetMaxSize( pin_password_toggle_->SetMaxSize(
gfx::Size(/*ignored*/ 0, kPinPasswordToggleButtonHeight)); gfx::Size(/*ignored*/ 0, kPinPasswordToggleButtonHeight));
...@@ -1067,7 +1064,9 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user, ...@@ -1067,7 +1064,9 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user,
l10n_util::GetStringUTF16(IDS_ASH_LOCK_SCREEN_VERIFY_ACCOUNT_MESSAGE); l10n_util::GetStringUTF16(IDS_ASH_LOCK_SCREEN_VERIFY_ACCOUNT_MESSAGE);
} }
auto online_sign_in_message = std::make_unique<SystemLabelButton>( auto online_sign_in_message = std::make_unique<SystemLabelButton>(
this, button_message, SystemLabelButton::DisplayType::ALERT_WITH_ICON, base::BindRepeating(&LoginAuthUserView::OnOnlineSignInMessageTap,
base::Unretained(this)),
button_message, SystemLabelButton::DisplayType::ALERT_WITH_ICON,
/*multiline*/ false); /*multiline*/ false);
online_sign_in_message_ = online_sign_in_message.get(); online_sign_in_message_ = online_sign_in_message.get();
...@@ -1507,16 +1506,6 @@ void LoginAuthUserView::RequestFocus() { ...@@ -1507,16 +1506,6 @@ void LoginAuthUserView::RequestFocus() {
password_view_->RequestFocus(); password_view_->RequestFocus();
} }
void LoginAuthUserView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
DCHECK(sender == online_sign_in_message_ || sender == pin_password_toggle_);
if (sender == online_sign_in_message_) {
OnOnlineSignInMessageTap();
} else if (sender == pin_password_toggle_) {
OnSwitchButtonClicked();
}
}
void LoginAuthUserView::OnAuthSubmit(const base::string16& password) { void LoginAuthUserView::OnAuthSubmit(const base::string16& password) {
// Pressing enter when the password field is empty and tap-to-unlock is // Pressing enter when the password field is empty and tap-to-unlock is
// enabled should attempt unlock. // enabled should attempt unlock.
......
...@@ -38,8 +38,7 @@ class LoginPinInputView; ...@@ -38,8 +38,7 @@ class LoginPinInputView;
// This class will make call mojo authentication APIs directly. The embedder can // This class will make call mojo authentication APIs directly. The embedder can
// receive some events about the results of those mojo // receive some events about the results of those mojo
// authentication attempts (ie, success/failure). // authentication attempts (ie, success/failure).
class ASH_EXPORT LoginAuthUserView : public NonAccessibleView, class ASH_EXPORT LoginAuthUserView : public NonAccessibleView {
public views::ButtonListener {
public: public:
// Flags which describe the set of currently visible auth methods. // Flags which describe the set of currently visible auth methods.
enum AuthMethods { enum AuthMethods {
...@@ -182,9 +181,6 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView, ...@@ -182,9 +181,6 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
void RequestFocus() override; void RequestFocus() override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private: private:
struct UiState; struct UiState;
class FingerprintView; class FingerprintView;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "ui/views/controls/textfield/textfield.h" #include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/textfield/textfield_test_api.h" #include "ui/views/controls/textfield/textfield_test_api.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#include "ui/views/test/button_test_api.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
using testing::_; using testing::_;
...@@ -263,7 +264,7 @@ TEST_P(LoginAuthUserViewUnittest, OnlineSignInMessage) { ...@@ -263,7 +264,7 @@ TEST_P(LoginAuthUserViewUnittest, OnlineSignInMessage) {
ShowGaiaSignin(user_view->current_user().basic_user_info.account_id)); ShowGaiaSignin(user_view->current_user().basic_user_info.account_id));
const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), 0, 0); ui::EventTimeForNow(), 0, 0);
view_->ButtonPressed(online_sign_in_message, event); views::test::ButtonTestApi(online_sign_in_message).NotifyClick(event);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// The online sign-in message is invisible for all other auth methods. // The online sign-in message is invisible for all other auth methods.
...@@ -448,7 +449,8 @@ TEST_P(LoginAuthUserViewUnittest, PinAutosubmitFieldModes) { ...@@ -448,7 +449,8 @@ TEST_P(LoginAuthUserViewUnittest, PinAutosubmitFieldModes) {
// Clicking on the switch button changes to the password field // Clicking on the switch button changes to the password field
const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), const ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), 0, 0); ui::EventTimeForNow(), 0, 0);
view_->ButtonPressed(auth_test.pin_password_toggle(), event); views::test::ButtonTestApi(auth_test.pin_password_toggle())
.NotifyClick(event);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::PWD_WITH_TOGGLE); ExpectModeVisibility(LoginAuthUserView::InputFieldMode::PWD_WITH_TOGGLE);
SetAuthMethods(LoginAuthUserView::AUTH_NONE); // Clear state for next run. SetAuthMethods(LoginAuthUserView::AUTH_NONE); // Clear state for next run.
......
...@@ -129,9 +129,8 @@ class LoginExpandedPublicAccountEventHandler : public ui::EventHandler { ...@@ -129,9 +129,8 @@ class LoginExpandedPublicAccountEventHandler : public ui::EventHandler {
// Button with text on the left side and an icon on the right side. // Button with text on the left side and an icon on the right side.
class SelectionButtonView : public LoginButton { class SelectionButtonView : public LoginButton {
public: public:
SelectionButtonView(const base::string16& text, SelectionButtonView(PressedCallback callback, const base::string16& text)
views::ButtonListener* listener) : LoginButton(std::move(callback)) {
: LoginButton(listener) {
SetPaintToLayer(); SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false); layer()->SetFillsBoundsOpaquely(false);
SetFocusBehavior(FocusBehavior::ALWAYS); SetFocusBehavior(FocusBehavior::ALWAYS);
...@@ -292,7 +291,7 @@ class MonitoringWarningView : public NonAccessibleView { ...@@ -292,7 +291,7 @@ class MonitoringWarningView : public NonAccessibleView {
}; };
// Implements the right part of the expanded public session view. // Implements the right part of the expanded public session view.
class RightPaneView : public NonAccessibleView, public views::ButtonListener { class RightPaneView : public NonAccessibleView {
public: public:
explicit RightPaneView(const base::RepeatingClosure& on_learn_more_tapped) { explicit RightPaneView(const base::RepeatingClosure& on_learn_more_tapped) {
SetPreferredSize( SetPreferredSize(
...@@ -336,9 +335,10 @@ class RightPaneView : public NonAccessibleView, public views::ButtonListener { ...@@ -336,9 +335,10 @@ class RightPaneView : public NonAccessibleView, public views::ButtonListener {
// Create button to show/hide advanced view. // Create button to show/hide advanced view.
advanced_view_button_ = new SelectionButtonView( advanced_view_button_ = new SelectionButtonView(
base::BindRepeating(&RightPaneView::AdvancedViewButtonPressed,
base::Unretained(this)),
l10n_util::GetStringUTF16( l10n_util::GetStringUTF16(
IDS_ASH_LOGIN_PUBLIC_SESSION_LANGUAGE_AND_INPUT), IDS_ASH_LOGIN_PUBLIC_SESSION_LANGUAGE_AND_INPUT));
this);
advanced_view_button_->SetTextColor(kPublicSessionBlueColor); advanced_view_button_->SetTextColor(kPublicSessionBlueColor);
advanced_view_button_->SetIcon(kLoginScreenButtonDropdownIcon, advanced_view_button_->SetIcon(kLoginScreenButtonDropdownIcon,
kPublicSessionBlueColor); kPublicSessionBlueColor);
...@@ -354,8 +354,9 @@ class RightPaneView : public NonAccessibleView, public views::ButtonListener { ...@@ -354,8 +354,9 @@ class RightPaneView : public NonAccessibleView, public views::ButtonListener {
// Creates button to open the menu. // Creates button to open the menu.
auto create_menu_button = auto create_menu_button =
[&](const base::string16& text) -> SelectionButtonView* { [&](views::Button::PressedCallback callback,
auto* button = new SelectionButtonView(text, this); const base::string16& text) -> SelectionButtonView* {
auto* button = new SelectionButtonView(std::move(callback), text);
button->SetPreferredSize( button->SetPreferredSize(
gfx::Size(kSelectionBoxWidthDp, kSelectionBoxHeightDp)); gfx::Size(kSelectionBoxWidthDp, kSelectionBoxHeightDp));
button->SetMargins(kLeftMarginForSelectionButton, button->SetMargins(kLeftMarginForSelectionButton,
...@@ -375,12 +376,18 @@ class RightPaneView : public NonAccessibleView, public views::ButtonListener { ...@@ -375,12 +376,18 @@ class RightPaneView : public NonAccessibleView, public views::ButtonListener {
views::Label* language_title = CreateLabel( views::Label* language_title = CreateLabel(
l10n_util::GetStringUTF16(IDS_ASH_LOGIN_LANGUAGE_SELECTION_SELECT), l10n_util::GetStringUTF16(IDS_ASH_LOGIN_LANGUAGE_SELECTION_SELECT),
kSelectionMenuTitleColor); kSelectionMenuTitleColor);
language_selection_ = create_menu_button(base::string16()); language_selection_ = create_menu_button(
base::BindRepeating(&RightPaneView::LanguageSelectionButtonPressed,
base::Unretained(this)),
base::string16());
views::Label* keyboard_title = CreateLabel( views::Label* keyboard_title = CreateLabel(
l10n_util::GetStringUTF16(IDS_ASH_LOGIN_KEYBOARD_SELECTION_SELECT), l10n_util::GetStringUTF16(IDS_ASH_LOGIN_KEYBOARD_SELECTION_SELECT),
kSelectionMenuTitleColor); kSelectionMenuTitleColor);
keyboard_selection_ = create_menu_button(base::string16()); keyboard_selection_ = create_menu_button(
base::BindRepeating(&RightPaneView::KeyboardSelectionButtonPressed,
base::Unretained(this)),
base::string16());
advanced_view_->AddChildView(language_title); advanced_view_->AddChildView(language_title);
advanced_view_->AddChildView( advanced_view_->AddChildView(
...@@ -393,7 +400,10 @@ class RightPaneView : public NonAccessibleView, public views::ButtonListener { ...@@ -393,7 +400,10 @@ class RightPaneView : public NonAccessibleView, public views::ButtonListener {
create_padding(kSpacingBetweenSelectionTitleAndButtonDp)); create_padding(kSpacingBetweenSelectionTitleAndButtonDp));
advanced_view_->AddChildView(keyboard_selection_); advanced_view_->AddChildView(keyboard_selection_);
submit_button_ = new ArrowButtonView(this, kArrowButtonSizeDp); submit_button_ = new ArrowButtonView(
base::BindRepeating(&RightPaneView::SubmitButtonPressed,
base::Unretained(this)),
kArrowButtonSizeDp);
submit_button_->SetBackgroundColor(kArrowButtonColor); submit_button_->SetBackgroundColor(kArrowButtonColor);
AddChildView(submit_button_); AddChildView(submit_button_);
} }
...@@ -435,49 +445,6 @@ class RightPaneView : public NonAccessibleView, public views::ButtonListener { ...@@ -435,49 +445,6 @@ class RightPaneView : public NonAccessibleView, public views::ButtonListener {
bounds.bottom() - kArrowButtonSizeDp)); bounds.bottom() - kArrowButtonSizeDp));
} }
void ButtonPressed(views::Button* sender, const ui::Event& event) override {
if (sender == advanced_view_button_) {
show_advanced_view_ = !show_advanced_view_;
show_advanced_changed_by_user_ = true;
Layout();
} else if (sender == submit_button_) {
// TODO(crbug.com/984021) change to LaunchSamlPublicSession which would
// take selected_language_item_.value, selected_keyboard_item_.value too.
if (current_user_.public_account_info->using_saml) {
Shell::Get()->login_screen_controller()->ShowGaiaSignin(
current_user_.basic_user_info.account_id);
} else {
Shell::Get()->login_screen_controller()->LaunchPublicSession(
current_user_.basic_user_info.account_id,
selected_language_item_.value, selected_keyboard_item_.value);
}
} else if (sender == language_selection_) {
DCHECK(language_menu_view_);
if (language_menu_view_->GetVisible()) {
language_menu_view_->Hide();
} else {
bool opener_had_focus = language_selection_->HasFocus();
language_menu_view_->Show();
if (opener_had_focus)
language_menu_view_->RequestFocus();
}
} else if (sender == keyboard_selection_) {
DCHECK(keyboard_menu_view_);
if (keyboard_menu_view_->GetVisible()) {
keyboard_menu_view_->Hide();
} else {
bool opener_had_focus = keyboard_selection_->HasFocus();
keyboard_menu_view_->Show();
if (opener_had_focus)
keyboard_menu_view_->RequestFocus();
}
}
}
void UpdateForUser(const LoginUserInfo& user) { void UpdateForUser(const LoginUserInfo& user) {
DCHECK_EQ(user.basic_user_info.type, DCHECK_EQ(user.basic_user_info.type,
user_manager::USER_TYPE_PUBLIC_ACCOUNT); user_manager::USER_TYPE_PUBLIC_ACCOUNT);
...@@ -611,6 +578,53 @@ class RightPaneView : public NonAccessibleView, public views::ButtonListener { ...@@ -611,6 +578,53 @@ class RightPaneView : public NonAccessibleView, public views::ButtonListener {
private: private:
friend class LoginExpandedPublicAccountView::TestApi; friend class LoginExpandedPublicAccountView::TestApi;
void AdvancedViewButtonPressed() {
show_advanced_view_ = !show_advanced_view_;
show_advanced_changed_by_user_ = true;
Layout();
}
void SubmitButtonPressed() {
// TODO(crbug.com/984021) change to LaunchSamlPublicSession which would
// take selected_language_item_.value, selected_keyboard_item_.value too.
if (current_user_.public_account_info->using_saml) {
Shell::Get()->login_screen_controller()->ShowGaiaSignin(
current_user_.basic_user_info.account_id);
} else {
Shell::Get()->login_screen_controller()->LaunchPublicSession(
current_user_.basic_user_info.account_id,
selected_language_item_.value, selected_keyboard_item_.value);
}
}
void LanguageSelectionButtonPressed() {
DCHECK(language_menu_view_);
if (language_menu_view_->GetVisible()) {
language_menu_view_->Hide();
} else {
bool opener_had_focus = language_selection_->HasFocus();
language_menu_view_->Show();
if (opener_had_focus)
language_menu_view_->RequestFocus();
}
}
void KeyboardSelectionButtonPressed() {
DCHECK(keyboard_menu_view_);
if (keyboard_menu_view_->GetVisible()) {
keyboard_menu_view_->Hide();
} else {
bool opener_had_focus = keyboard_selection_->HasFocus();
keyboard_menu_view_->Show();
if (opener_had_focus)
keyboard_menu_view_->RequestFocus();
}
}
bool show_advanced_view_ = false; bool show_advanced_view_ = false;
LoginUserInfo current_user_; LoginUserInfo current_user_;
...@@ -760,20 +774,6 @@ std::vector<LocaleItem> LoginExpandedPublicAccountView::TestApi::GetLocales() { ...@@ -760,20 +774,6 @@ std::vector<LocaleItem> LoginExpandedPublicAccountView::TestApi::GetLocales() {
return locales; return locales;
} }
void LoginExpandedPublicAccountView::TestApi::OnAdvancedButtonTap() {
view_->right_pane_->ButtonPressed(
views::Button::AsButton(advanced_view_button()),
ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(), gfx::PointF(),
base::TimeTicks(), 0, 0));
}
void LoginExpandedPublicAccountView::TestApi::OnSubmitButtonTap() {
view_->right_pane_->ButtonPressed(
views::Button::AsButton(submit_button()),
ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(), gfx::PointF(),
base::TimeTicks(), 0, 0));
}
LoginExpandedPublicAccountView::LoginExpandedPublicAccountView( LoginExpandedPublicAccountView::LoginExpandedPublicAccountView(
const OnPublicSessionViewDismissed& on_dismissed) const OnPublicSessionViewDismissed& on_dismissed)
: NonAccessibleView(kLoginExpandedPublicAccountViewClassName), : NonAccessibleView(kLoginExpandedPublicAccountViewClassName),
......
...@@ -56,9 +56,6 @@ class ASH_EXPORT LoginExpandedPublicAccountView : public NonAccessibleView { ...@@ -56,9 +56,6 @@ class ASH_EXPORT LoginExpandedPublicAccountView : public NonAccessibleView {
bool SelectKeyboard(const std::string& ime_id); bool SelectKeyboard(const std::string& ime_id);
std::vector<LocaleItem> GetLocales(); std::vector<LocaleItem> GetLocales();
void OnAdvancedButtonTap();
void OnSubmitButtonTap();
private: private:
LoginExpandedPublicAccountView* const view_; LoginExpandedPublicAccountView* const view_;
}; };
......
...@@ -31,11 +31,14 @@ namespace { ...@@ -31,11 +31,14 @@ namespace {
constexpr SkColor kMenuBackgroundColor = SkColorSetRGB(0x3C, 0x40, 0x43); constexpr SkColor kMenuBackgroundColor = SkColorSetRGB(0x3C, 0x40, 0x43);
class MenuItemView : public views::Button, public views::ButtonListener { class MenuItemView : public views::Button {
public: public:
MenuItemView(const LoginMenuView::Item& item, MenuItemView(const LoginMenuView::Item& item,
const LoginMenuView::OnHighlight& on_highlight) const LoginMenuView::OnHighlight& on_highlight)
: views::Button(this), item_(item), on_highlight_(on_highlight) { : views::Button(base::BindRepeating(&MenuItemView::ButtonPressed,
base::Unretained(this))),
item_(item),
on_highlight_(on_highlight) {
SetFocusBehavior(FocusBehavior::ALWAYS); SetFocusBehavior(FocusBehavior::ALWAYS);
SetLayoutManager(std::make_unique<views::BoxLayout>( SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal)); views::BoxLayout::Orientation::kHorizontal));
...@@ -71,15 +74,6 @@ class MenuItemView : public views::Button, public views::ButtonListener { ...@@ -71,15 +74,6 @@ class MenuItemView : public views::Button, public views::ButtonListener {
return GetPreferredSize().height(); return GetPreferredSize().height();
} }
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override {
DCHECK(sender == this);
if (item_.is_group)
return;
on_highlight_.Run(true /*by_selection*/);
}
void OnHover(bool has_hover) { void OnHover(bool has_hover) {
if (has_hover && !item_.is_group) if (has_hover && !item_.is_group)
RequestFocus(); RequestFocus();
...@@ -93,6 +87,11 @@ class MenuItemView : public views::Button, public views::ButtonListener { ...@@ -93,6 +87,11 @@ class MenuItemView : public views::Button, public views::ButtonListener {
const LoginMenuView::Item& item() const { return item_; } const LoginMenuView::Item& item() const { return item_; }
private: private:
void ButtonPressed() {
if (!item_.is_group)
on_highlight_.Run(true /*by_selection*/);
}
const LoginMenuView::Item item_; const LoginMenuView::Item item_;
const LoginMenuView::OnHighlight on_highlight_; const LoginMenuView::OnHighlight on_highlight_;
std::unique_ptr<HoverNotifier> hover_notifier_; std::unique_ptr<HoverNotifier> hover_notifier_;
......
...@@ -51,12 +51,6 @@ views::View* LoginPublicAccountUserView::TestApi::arrow_button() const { ...@@ -51,12 +51,6 @@ views::View* LoginPublicAccountUserView::TestApi::arrow_button() const {
return view_->arrow_button_; return view_->arrow_button_;
} }
void LoginPublicAccountUserView::TestApi::OnArrowTap() const {
view_->ButtonPressed(views::Button::AsButton(arrow_button()),
ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::PointF(),
gfx::PointF(), base::TimeTicks(), 0, 0));
}
LoginPublicAccountUserView::Callbacks::Callbacks() = default; LoginPublicAccountUserView::Callbacks::Callbacks() = default;
LoginPublicAccountUserView::Callbacks::Callbacks(const Callbacks& other) = LoginPublicAccountUserView::Callbacks::Callbacks(const Callbacks& other) =
...@@ -79,8 +73,10 @@ LoginPublicAccountUserView::LoginPublicAccountUserView( ...@@ -79,8 +73,10 @@ LoginPublicAccountUserView::LoginPublicAccountUserView(
base::BindRepeating(&LoginPublicAccountUserView::OnUserViewTap, base::BindRepeating(&LoginPublicAccountUserView::OnUserViewTap,
base::Unretained(this)), base::Unretained(this)),
base::RepeatingClosure(), base::RepeatingClosure()); base::RepeatingClosure(), base::RepeatingClosure());
auto arrow_button = auto arrow_button = std::make_unique<ArrowButtonView>(
std::make_unique<ArrowButtonView>(this, kArrowButtonSizeDp); base::BindRepeating(&LoginPublicAccountUserView::ArrowButtonPressed,
base::Unretained(this)),
kArrowButtonSizeDp);
arrow_button->SetBackgroundColor(kArrowButtonBackground); arrow_button->SetBackgroundColor(kArrowButtonBackground);
arrow_button->SetFocusPainter(nullptr); arrow_button->SetFocusPainter(nullptr);
...@@ -150,18 +146,14 @@ gfx::Size LoginPublicAccountUserView::CalculatePreferredSize() const { ...@@ -150,18 +146,14 @@ gfx::Size LoginPublicAccountUserView::CalculatePreferredSize() const {
return size; return size;
} }
void LoginPublicAccountUserView::ButtonPressed(views::Button* sender, void LoginPublicAccountUserView::ArrowButtonPressed() {
const ui::Event& event) { DCHECK(arrow_button_);
if (sender == arrow_button_) { // If the pod isn't active, activate it first.
DCHECK(arrow_button_); if (!auth_enabled_)
// If the pod isn't active, activate it first. OnUserViewTap();
if (!auth_enabled_) {
OnUserViewTap(); DCHECK(auth_enabled_);
} on_public_account_tap_.Run();
DCHECK(auth_enabled_);
on_public_account_tap_.Run();
}
} }
void LoginPublicAccountUserView::OnUserViewTap() { void LoginPublicAccountUserView::OnUserViewTap() {
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/login/ui/login_user_view.h" #include "ash/login/ui/login_user_view.h"
#include "ash/login/ui/non_accessible_view.h" #include "ash/login/ui/non_accessible_view.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace ash { namespace ash {
...@@ -18,8 +17,7 @@ class HoverNotifier; ...@@ -18,8 +17,7 @@ class HoverNotifier;
// This is the big user view for the public account user. It wraps a UserView // This is the big user view for the public account user. It wraps a UserView
// and a arrow button below. // and a arrow button below.
class ASH_EXPORT LoginPublicAccountUserView : public NonAccessibleView, class ASH_EXPORT LoginPublicAccountUserView : public NonAccessibleView {
public views::ButtonListener {
public: public:
// TestApi is used for tests to get internal implementation details. // TestApi is used for tests to get internal implementation details.
class ASH_EXPORT TestApi { class ASH_EXPORT TestApi {
...@@ -29,8 +27,6 @@ class ASH_EXPORT LoginPublicAccountUserView : public NonAccessibleView, ...@@ -29,8 +27,6 @@ class ASH_EXPORT LoginPublicAccountUserView : public NonAccessibleView,
views::View* arrow_button() const; views::View* arrow_button() const;
void OnArrowTap() const;
private: private:
LoginPublicAccountUserView* const view_; LoginPublicAccountUserView* const view_;
}; };
...@@ -59,13 +55,12 @@ class ASH_EXPORT LoginPublicAccountUserView : public NonAccessibleView, ...@@ -59,13 +55,12 @@ class ASH_EXPORT LoginPublicAccountUserView : public NonAccessibleView,
// views::View: // views::View:
gfx::Size CalculatePreferredSize() const override; gfx::Size CalculatePreferredSize() const override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
bool auth_enabled() const { return auth_enabled_; } bool auth_enabled() const { return auth_enabled_; }
LoginUserView* user_view() { return user_view_; } LoginUserView* user_view() { return user_view_; }
private: private:
void ArrowButtonPressed();
// Called when the user view has been tapped and it will run |on_tap_|. // Called when the user view has been tapped and it will run |on_tap_|.
void OnUserViewTap(); void OnUserViewTap();
......
...@@ -71,8 +71,8 @@ class TrappedFocusSearch : public views::FocusSearch { ...@@ -71,8 +71,8 @@ class TrappedFocusSearch : public views::FocusSearch {
// A button that holds a child view. // A button that holds a child view.
class RemoveUserButton : public SystemLabelButton { class RemoveUserButton : public SystemLabelButton {
public: public:
RemoveUserButton(views::ButtonListener* listener, LoginUserMenuView* bubble) RemoveUserButton(PressedCallback callback, LoginUserMenuView* bubble)
: SystemLabelButton(listener, : SystemLabelButton(std::move(callback),
l10n_util::GetStringUTF16( l10n_util::GetStringUTF16(
IDS_ASH_LOGIN_POD_REMOVE_ACCOUNT_ACCESSIBLE_NAME), IDS_ASH_LOGIN_POD_REMOVE_ACCOUNT_ACCESSIBLE_NAME),
SystemLabelButton::DisplayType::DEFAULT, SystemLabelButton::DisplayType::DEFAULT,
...@@ -213,7 +213,10 @@ LoginUserMenuView::LoginUserMenuView( ...@@ -213,7 +213,10 @@ LoginUserMenuView::LoginUserMenuView(
remove_user_confirm_data_->AddChildView( remove_user_confirm_data_->AddChildView(
login_views_utils::CreateBubbleLabel(part2, gfx::kGoogleGrey200, this)); login_views_utils::CreateBubbleLabel(part2, gfx::kGoogleGrey200, this));
remove_user_button_ = new RemoveUserButton(this, this); remove_user_button_ = new RemoveUserButton(
base::BindRepeating(&LoginUserMenuView::RemoveUserButtonPressed,
base::Unretained(this)),
this);
remove_user_button_->SetID(kUserMenuRemoveUserButtonIdForTest); remove_user_button_->SetID(kUserMenuRemoveUserButtonIdForTest);
AddChildView(remove_user_button_); AddChildView(remove_user_button_);
...@@ -245,37 +248,6 @@ LoginButton* LoginUserMenuView::GetBubbleOpener() const { ...@@ -245,37 +248,6 @@ LoginButton* LoginUserMenuView::GetBubbleOpener() const {
return bubble_opener_; return bubble_opener_;
} }
void LoginUserMenuView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
// Show confirmation warning. The user has to click the button again before
// we actually allow the exit.
if (!remove_user_confirm_data_->GetVisible()) {
remove_user_confirm_data_->SetVisible(true);
if (managed_user_data_)
managed_user_data_->SetVisible(false);
remove_user_button_->SetDisplayType(
SystemLabelButton::DisplayType::ALERT_NO_ICON);
Layout();
// Change the node's description to force assistive technologies, like
// ChromeVox, to report the updated description.
remove_user_button_->GetViewAccessibility().OverrideDescription(
warning_message_);
if (on_remove_user_warning_shown_)
std::move(on_remove_user_warning_shown_).Run();
return;
}
// Immediately hide the bubble with no animation before running the remove
// user callback. If an animation is triggered while the the views hierarchy
// for this bubble is being torn down, we can get a crash.
SetVisible(false);
if (on_remove_user_requested_)
std::move(on_remove_user_requested_).Run();
}
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.
...@@ -316,4 +288,34 @@ views::View* LoginUserMenuView::GetFocusTraversableParentView() { ...@@ -316,4 +288,34 @@ views::View* LoginUserMenuView::GetFocusTraversableParentView() {
return nullptr; return nullptr;
} }
void LoginUserMenuView::RemoveUserButtonPressed() {
// Show confirmation warning. The user has to click the button again before
// we actually allow the exit.
if (!remove_user_confirm_data_->GetVisible()) {
remove_user_confirm_data_->SetVisible(true);
if (managed_user_data_)
managed_user_data_->SetVisible(false);
remove_user_button_->SetDisplayType(
SystemLabelButton::DisplayType::ALERT_NO_ICON);
Layout();
// Change the node's description to force assistive technologies, like
// ChromeVox, to report the updated description.
remove_user_button_->GetViewAccessibility().OverrideDescription(
warning_message_);
if (on_remove_user_warning_shown_)
std::move(on_remove_user_warning_shown_).Run();
return;
}
// Immediately hide the bubble with no animation before running the remove
// user callback. If an animation is triggered while the the views hierarchy
// for this bubble is being torn down, we can get a crash.
SetVisible(false);
if (on_remove_user_requested_)
std::move(on_remove_user_requested_).Run();
}
} // namespace ash } // namespace ash
...@@ -20,7 +20,6 @@ struct LoginUserInfo; ...@@ -20,7 +20,6 @@ struct LoginUserInfo;
class RemoveUserButton; class RemoveUserButton;
class ASH_EXPORT LoginUserMenuView : public LoginBaseBubbleView, class ASH_EXPORT LoginUserMenuView : public LoginBaseBubbleView,
public views::ButtonListener,
public views::FocusTraversable { public views::FocusTraversable {
public: public:
class TestApi { class TestApi {
...@@ -52,9 +51,6 @@ class ASH_EXPORT LoginUserMenuView : public LoginBaseBubbleView, ...@@ -52,9 +51,6 @@ class ASH_EXPORT LoginUserMenuView : public LoginBaseBubbleView,
// LoginBaseBubbleView: // LoginBaseBubbleView:
LoginButton* GetBubbleOpener() const override; LoginButton* GetBubbleOpener() const override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::View: // views::View:
void RequestFocus() override; void RequestFocus() override;
bool HasFocus() const override; bool HasFocus() const override;
...@@ -68,6 +64,8 @@ class ASH_EXPORT LoginUserMenuView : public LoginBaseBubbleView, ...@@ -68,6 +64,8 @@ class ASH_EXPORT LoginUserMenuView : public LoginBaseBubbleView,
views::View* GetFocusTraversableParentView() override; views::View* GetFocusTraversableParentView() override;
private: private:
void RemoveUserButtonPressed();
LoginButton* bubble_opener_ = nullptr; LoginButton* bubble_opener_ = nullptr;
base::RepeatingClosure on_remove_user_warning_shown_; base::RepeatingClosure on_remove_user_warning_shown_;
base::RepeatingClosure on_remove_user_requested_; base::RepeatingClosure on_remove_user_requested_;
......
...@@ -308,8 +308,8 @@ class LoginUserView::UserLabel : public NonAccessibleView { ...@@ -308,8 +308,8 @@ class LoginUserView::UserLabel : public NonAccessibleView {
// have any children (ie, the dropdown button). // have any children (ie, the dropdown button).
class LoginUserView::TapButton : public views::Button { class LoginUserView::TapButton : public views::Button {
public: public:
explicit TapButton(LoginUserView* parent) TapButton(PressedCallback callback, LoginUserView* parent)
: views::Button(parent), parent_(parent) {} : views::Button(std::move(callback)), parent_(parent) {}
~TapButton() override = default; ~TapButton() override = default;
// views::Button: // views::Button:
...@@ -413,7 +413,8 @@ LoginUserView::LoginUserView( ...@@ -413,7 +413,8 @@ LoginUserView::LoginUserView(
2 * (kDistanceBetweenUsernameAndDropdownDp + kDropdownIconSizeDp); 2 * (kDistanceBetweenUsernameAndDropdownDp + kDropdownIconSizeDp);
user_label_ = new UserLabel(style, label_width); user_label_ = new UserLabel(style, label_width);
if (show_dropdown) { if (show_dropdown) {
dropdown_ = new LoginButton(this); dropdown_ = new LoginButton(base::BindRepeating(
&LoginUserView::DropdownButtonPressed, base::Unretained(this)));
dropdown_->SetHasInkDropActionOnClick(false); dropdown_->SetHasInkDropActionOnClick(false);
dropdown_->SetPreferredSize( dropdown_->SetPreferredSize(
gfx::Size(kDropdownIconSizeDp, kDropdownIconSizeDp)); gfx::Size(kDropdownIconSizeDp, kDropdownIconSizeDp));
...@@ -422,7 +423,7 @@ LoginUserView::LoginUserView( ...@@ -422,7 +423,7 @@ LoginUserView::LoginUserView(
gfx::CreateVectorIcon(kLockScreenDropdownIcon, gfx::kGoogleGrey200)); gfx::CreateVectorIcon(kLockScreenDropdownIcon, gfx::kGoogleGrey200));
dropdown_->SetFocusBehavior(FocusBehavior::ALWAYS); dropdown_->SetFocusBehavior(FocusBehavior::ALWAYS);
} }
tap_button_ = new TapButton(this); tap_button_ = new TapButton(on_tap_, this);
SetTapEnabled(true); SetTapEnabled(true);
switch (style) { switch (style) {
...@@ -554,44 +555,35 @@ void LoginUserView::RequestFocus() { ...@@ -554,44 +555,35 @@ void LoginUserView::RequestFocus() {
tap_button_->RequestFocus(); tap_button_->RequestFocus();
} }
void LoginUserView::ButtonPressed(views::Button* sender, void LoginUserView::OnHover(bool has_hover) {
const ui::Event& event) { UpdateOpacity();
// Handle click on the dropdown arrow. }
if (sender == dropdown_) {
DCHECK(dropdown_);
DCHECK(menu_);
// If menu is showing, just close it
if (menu_->GetVisible()) {
menu_->Hide();
return;
}
bool opener_focused =
menu_->GetBubbleOpener() && menu_->GetBubbleOpener()->HasFocus();
if (!menu_->parent())
login_views_utils::GetBubbleContainer(this)->AddChildView(menu_);
// Reset state in case the remove-user button was clicked once previously.
menu_->ResetState();
menu_->Show();
// If the menu was opened by pressing Enter on the focused dropdown, focus void LoginUserView::DropdownButtonPressed() {
// should automatically go to the remove-user button (for keyboard DCHECK(dropdown_);
// accessibility). DCHECK(menu_);
if (opener_focused)
menu_->RequestFocus();
// If menu is showing, just close it
if (menu_->GetVisible()) {
menu_->Hide();
return; return;
} }
// Run generic on_tap handler for any other click. bool opener_focused =
on_tap_.Run(); menu_->GetBubbleOpener() && menu_->GetBubbleOpener()->HasFocus();
}
void LoginUserView::OnHover(bool has_hover) { if (!menu_->parent())
UpdateOpacity(); login_views_utils::GetBubbleContainer(this)->AddChildView(menu_);
// Reset state in case the remove-user button was clicked once previously.
menu_->ResetState();
menu_->Show();
// If the menu was opened by pressing Enter on the focused dropdown, focus
// should automatically go to the remove-user button (for keyboard
// accessibility).
if (opener_focused)
menu_->RequestFocus();
} }
void LoginUserView::UpdateCurrentUserState() { void LoginUserView::UpdateCurrentUserState() {
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "ash/login/ui/login_user_menu_view.h" #include "ash/login/ui/login_user_menu_view.h"
#include "ash/public/cpp/login_types.h" #include "ash/public/cpp/login_types.h"
#include "base/macros.h" #include "base/macros.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h" #include "ui/views/view.h"
namespace ash { namespace ash {
...@@ -21,8 +20,7 @@ class LoginButton; ...@@ -21,8 +20,7 @@ class LoginButton;
// Display the user's profile icon, name, and a menu icon in various layout // Display the user's profile icon, name, and a menu icon in various layout
// styles. // styles.
class ASH_EXPORT LoginUserView : public views::View, class ASH_EXPORT LoginUserView : public views::View {
public views::ButtonListener {
public: public:
// TestApi is used for tests to get internal implementation details. // TestApi is used for tests to get internal implementation details.
class ASH_EXPORT TestApi { class ASH_EXPORT TestApi {
...@@ -81,9 +79,6 @@ class ASH_EXPORT LoginUserView : public views::View, ...@@ -81,9 +79,6 @@ class ASH_EXPORT LoginUserView : public views::View,
void Layout() override; void Layout() override;
void RequestFocus() override; void RequestFocus() override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private: private:
class UserImage; class UserImage;
class UserLabel; class UserLabel;
...@@ -92,6 +87,8 @@ class ASH_EXPORT LoginUserView : public views::View, ...@@ -92,6 +87,8 @@ class ASH_EXPORT LoginUserView : public views::View,
// Called when hover state changes. // Called when hover state changes.
void OnHover(bool has_hover); void OnHover(bool has_hover);
void DropdownButtonPressed();
// Updates UI element values so they reflect the data in |current_user_|. // Updates UI element values so they reflect the data in |current_user_|.
void UpdateCurrentUserState(); void UpdateCurrentUserState();
// Updates view opacity based on input state and |force_opaque_|. // Updates view opacity based on input state and |force_opaque_|.
......
...@@ -178,11 +178,11 @@ class BubbleTargeterDelegate : public views::MaskedTargeterDelegate { ...@@ -178,11 +178,11 @@ class BubbleTargeterDelegate : public views::MaskedTargeterDelegate {
// The action button foreground - an image button with actionable area matching // The action button foreground - an image button with actionable area matching
// the (small) bubble shape centered in the top right corner of the action // the (small) bubble shape centered in the top right corner of the action
// button bounds. // button bounds.
class NoteActionLaunchButton::ActionButton : public views::ImageButton, class NoteActionLaunchButton::ActionButton : public views::ImageButton {
public views::ButtonListener {
public: public:
explicit ActionButton(NoteActionLaunchButton::BackgroundView* background) explicit ActionButton(NoteActionLaunchButton::BackgroundView* background)
: views::ImageButton(this), : views::ImageButton(base::BindRepeating(&ActionButton::ButtonPressed,
base::Unretained(this))),
background_(background), background_(background),
event_targeter_delegate_(kLargeBubbleRadiusDp, kSmallBubbleRadiusDp) { event_targeter_delegate_(kLargeBubbleRadiusDp, kSmallBubbleRadiusDp) {
SetAccessibleName( SetAccessibleName(
...@@ -269,19 +269,6 @@ class NoteActionLaunchButton::ActionButton : public views::ImageButton, ...@@ -269,19 +269,6 @@ class NoteActionLaunchButton::ActionButton : public views::ImageButton,
views::ImageButton::OnGestureEvent(event); views::ImageButton::OnGestureEvent(event);
} }
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override {
UserMetricsRecorder::RecordUserClickOnTray(
LoginMetricsRecorder::TrayClickTarget::kTrayActionNoteButton);
if (event.IsKeyEvent()) {
Shell::Get()->tray_action()->RequestNewLockScreenNote(
mojom::LockScreenNoteOrigin::kLockScreenButtonKeyboard);
} else {
Shell::Get()->tray_action()->RequestNewLockScreenNote(
mojom::LockScreenNoteOrigin::kLockScreenButtonTap);
}
}
private: private:
// Updates the background view size and opacity depending on the current note // Updates the background view size and opacity depending on the current note
// action button state. // action button state.
...@@ -294,6 +281,18 @@ class NoteActionLaunchButton::ActionButton : public views::ImageButton, ...@@ -294,6 +281,18 @@ class NoteActionLaunchButton::ActionButton : public views::ImageButton,
show_large_bubble ? kLargeBubbleOpacity : kSmallBubbleOpacity); show_large_bubble ? kLargeBubbleOpacity : kSmallBubbleOpacity);
} }
void ButtonPressed(const ui::Event& event) {
UserMetricsRecorder::RecordUserClickOnTray(
LoginMetricsRecorder::TrayClickTarget::kTrayActionNoteButton);
if (event.IsKeyEvent()) {
Shell::Get()->tray_action()->RequestNewLockScreenNote(
mojom::LockScreenNoteOrigin::kLockScreenButtonKeyboard);
} else {
Shell::Get()->tray_action()->RequestNewLockScreenNote(
mojom::LockScreenNoteOrigin::kLockScreenButtonTap);
}
}
// Called when a fling is detected - if the gesture direction was bottom-left, // Called when a fling is detected - if the gesture direction was bottom-left,
// it requests a new lock screen note. // it requests a new lock screen note.
void MaybeActivateActionOnFling(ui::GestureEvent* event) { void MaybeActivateActionOnFling(ui::GestureEvent* event) {
......
...@@ -95,9 +95,8 @@ PinRequest::~PinRequest() = default; ...@@ -95,9 +95,8 @@ PinRequest::~PinRequest() = default;
// Label button that displays focus ring. // Label button that displays focus ring.
class PinRequestView::FocusableLabelButton : public views::LabelButton { class PinRequestView::FocusableLabelButton : public views::LabelButton {
public: public:
FocusableLabelButton(views::ButtonListener* listener, FocusableLabelButton(PressedCallback callback, const base::string16& text)
const base::string16& text) : views::LabelButton(std::move(callback), text) {
: views::LabelButton(listener, text) {
SetInstallFocusRingOnFocus(true); SetInstallFocusRingOnFocus(true);
focus_ring()->SetColor(ShelfConfig::Get()->shelf_focus_border_color()); focus_ring()->SetColor(ShelfConfig::Get()->shelf_focus_border_color());
SetFocusBehavior(FocusBehavior::ALWAYS); SetFocusBehavior(FocusBehavior::ALWAYS);
...@@ -251,7 +250,8 @@ PinRequestView::PinRequestView(PinRequest request, Delegate* delegate) ...@@ -251,7 +250,8 @@ PinRequestView::PinRequestView(PinRequest request, Delegate* delegate)
back_button_view->SetLayoutManager(std::move(back_button_layout)); back_button_view->SetLayoutManager(std::move(back_button_layout));
header->AddChildView(back_button_view); header->AddChildView(back_button_view);
back_button_ = new LoginButton(this); back_button_ = new LoginButton(
base::BindRepeating(&PinRequestView::OnBack, base::Unretained(this)));
back_button_->SetPreferredSize( back_button_->SetPreferredSize(
gfx::Size(kBackButtonSizeDp, kBackButtonSizeDp)); gfx::Size(kBackButtonSizeDp, kBackButtonSizeDp));
back_button_->SetBackground( back_button_->SetBackground(
...@@ -364,7 +364,12 @@ PinRequestView::PinRequestView(PinRequest request, Delegate* delegate) ...@@ -364,7 +364,12 @@ PinRequestView::PinRequestView(PinRequest request, Delegate* delegate)
AddChildView(footer); AddChildView(footer);
help_button_ = new FocusableLabelButton( help_button_ = new FocusableLabelButton(
this, l10n_util::GetStringUTF16(IDS_ASH_LOGIN_PIN_REQUEST_HELP)); base::BindRepeating(
[](PinRequestView* view) {
view->delegate_->OnHelp(view->GetWidget()->GetNativeWindow());
},
this),
l10n_util::GetStringUTF16(IDS_ASH_LOGIN_PIN_REQUEST_HELP));
help_button_->SetPaintToLayer(); help_button_->SetPaintToLayer();
help_button_->layer()->SetFillsBoundsOpaquely(false); help_button_->layer()->SetFillsBoundsOpaquely(false);
help_button_->SetTextSubpixelRenderingEnabled(false); help_button_->SetTextSubpixelRenderingEnabled(false);
...@@ -376,7 +381,9 @@ PinRequestView::PinRequestView(PinRequest request, Delegate* delegate) ...@@ -376,7 +381,9 @@ PinRequestView::PinRequestView(PinRequest request, Delegate* delegate)
footer->AddChildView(horizontal_spacer); footer->AddChildView(horizontal_spacer);
bottom_layout->SetFlexForView(horizontal_spacer, 1); bottom_layout->SetFlexForView(horizontal_spacer, 1);
submit_button_ = new ArrowButtonView(this, kArrowButtonSizeDp); submit_button_ = new ArrowButtonView(
base::BindRepeating(&PinRequestView::SubmitCode, base::Unretained(this)),
kArrowButtonSizeDp);
submit_button_->SetBackgroundColor(kArrowButtonColor); submit_button_->SetBackgroundColor(kArrowButtonColor);
submit_button_->SetPreferredSize( submit_button_->SetPreferredSize(
gfx::Size(kArrowButtonSizeDp, kArrowButtonSizeDp)); gfx::Size(kArrowButtonSizeDp, kArrowButtonSizeDp));
...@@ -422,17 +429,6 @@ base::string16 PinRequestView::GetAccessibleWindowTitle() const { ...@@ -422,17 +429,6 @@ base::string16 PinRequestView::GetAccessibleWindowTitle() const {
return default_accessible_title_; return default_accessible_title_;
} }
void PinRequestView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == back_button_) {
OnBack();
} else if (sender == help_button_) {
delegate_->OnHelp(GetWidget()->GetNativeWindow());
} else if (sender == submit_button_) {
SubmitCode();
}
}
void PinRequestView::OnTabletModeStarted() { void PinRequestView::OnTabletModeStarted() {
if (!pin_keyboard_always_enabled_) { if (!pin_keyboard_always_enabled_) {
VLOG(1) << "Showing PIN keyboard in PinRequestView"; VLOG(1) << "Showing PIN keyboard in PinRequestView";
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "ash/public/cpp/login_types.h" #include "ash/public/cpp/login_types.h"
#include "ash/public/cpp/tablet_mode_observer.h" #include "ash/public/cpp/tablet_mode_observer.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/window/dialog_delegate.h" #include "ui/views/window/dialog_delegate.h"
namespace views { namespace views {
...@@ -71,7 +70,6 @@ struct ASH_EXPORT PinRequest { ...@@ -71,7 +70,6 @@ struct ASH_EXPORT PinRequest {
// The view that allows for input of pins to authorize certain actions. // The view that allows for input of pins to authorize certain actions.
class ASH_EXPORT PinRequestView : public views::DialogDelegateView, class ASH_EXPORT PinRequestView : public views::DialogDelegateView,
public views::ButtonListener,
public TabletModeObserver { public TabletModeObserver {
public: public:
enum class SubmissionResult { enum class SubmissionResult {
...@@ -133,9 +131,6 @@ class ASH_EXPORT PinRequestView : public views::DialogDelegateView, ...@@ -133,9 +131,6 @@ class ASH_EXPORT PinRequestView : public views::DialogDelegateView,
views::View* GetInitiallyFocusedView() override; views::View* GetInitiallyFocusedView() override;
base::string16 GetAccessibleWindowTitle() const override; base::string16 GetAccessibleWindowTitle() const override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// TabletModeObserver: // TabletModeObserver:
void OnTabletModeStarted() override; void OnTabletModeStarted() override;
void OnTabletModeEnded() override; void OnTabletModeEnded() override;
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/textfield/textfield.h" #include "ui/views/controls/textfield/textfield.h"
#include "ui/views/test/button_test_api.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
namespace ash { namespace ash {
...@@ -117,7 +118,7 @@ class PinRequestViewTest : public LoginTestBase, ...@@ -117,7 +118,7 @@ class PinRequestViewTest : public LoginTestBase,
PinRequestView::TestApi test_api(view); PinRequestView::TestApi test_api(view);
ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::MouseEvent event(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
ui::EventTimeForNow(), 0, 0); ui::EventTimeForNow(), 0, 0);
view->ButtonPressed(test_api.back_button(), event); views::test::ButtonTestApi(test_api.back_button()).NotifyClick(event);
} }
void SimulateFailedValidation() { void SimulateFailedValidation() {
......
...@@ -52,11 +52,11 @@ SkPath GetSystemButtonHighlightPath(const views::View* view) { ...@@ -52,11 +52,11 @@ SkPath GetSystemButtonHighlightPath(const views::View* view) {
} // namespace } // namespace
SystemLabelButton::SystemLabelButton(views::ButtonListener* listener, SystemLabelButton::SystemLabelButton(PressedCallback callback,
const base::string16& text, const base::string16& text,
DisplayType display_type, DisplayType display_type,
bool multiline) bool multiline)
: LabelButton(listener, text), display_type_(display_type) { : LabelButton(std::move(callback), text), display_type_(display_type) {
SetImageLabelSpacing(kSystemButtonImageLabelSpacing); SetImageLabelSpacing(kSystemButtonImageLabelSpacing);
if (multiline) { if (multiline) {
label()->SetMultiLine(true); label()->SetMultiLine(true);
......
...@@ -15,7 +15,7 @@ class ASH_EXPORT SystemLabelButton : public views::LabelButton { ...@@ -15,7 +15,7 @@ class ASH_EXPORT SystemLabelButton : public views::LabelButton {
public: public:
enum class DisplayType { DEFAULT, ALERT_NO_ICON, ALERT_WITH_ICON }; enum class DisplayType { DEFAULT, ALERT_NO_ICON, ALERT_WITH_ICON };
SystemLabelButton(views::ButtonListener* listener, SystemLabelButton(PressedCallback callback,
const base::string16& text, const base::string16& text,
DisplayType display_type, DisplayType display_type,
bool multiline = false); bool multiline = false);
......
...@@ -86,13 +86,15 @@ class FullscreenAlertBubbleView : public views::View { ...@@ -86,13 +86,15 @@ class FullscreenAlertBubbleView : public views::View {
auto* dismiss = auto* dismiss =
button_container->AddChildView(std::make_unique<SystemLabelButton>( button_container->AddChildView(std::make_unique<SystemLabelButton>(
nullptr, l10n_util::GetStringUTF16(IDS_DISMISS_BUTTON), views::Button::PressedCallback(),
l10n_util::GetStringUTF16(IDS_DISMISS_BUTTON),
SystemLabelButton::DisplayType::DEFAULT)); SystemLabelButton::DisplayType::DEFAULT));
dismiss->SetCallback(on_dismiss); dismiss->SetCallback(on_dismiss);
auto* exit_fullscreen = auto* exit_fullscreen =
button_container->AddChildView(std::make_unique<SystemLabelButton>( button_container->AddChildView(std::make_unique<SystemLabelButton>(
nullptr, l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_BUTTON), views::Button::PressedCallback(),
l10n_util::GetStringUTF16(IDS_EXIT_FULLSCREEN_BUTTON),
SystemLabelButton::DisplayType::ALERT_NO_ICON)); SystemLabelButton::DisplayType::ALERT_NO_ICON));
exit_fullscreen->SetCallback(on_exit_fullscreen); exit_fullscreen->SetCallback(on_exit_fullscreen);
} }
......
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