Commit d1169765 authored by Yicheng Li's avatar Yicheng Li Committed by Commit Bot

ash: Dismiss in-session auth dialog when it loses focus

This behavior is approved in UI concept review. So we also remove
the cancel button.

Bug: b/156258540
Change-Id: I9604d15cb7db7f379c96c692d25bf51d14b2ca10
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2505443
Commit-Queue: Yicheng Li <yichengli@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823449}
parent b755ea5e
......@@ -33,13 +33,8 @@
namespace ash {
namespace {
enum class ButtonId {
kCancel,
};
// TODO(b/164195709): Move these strings to a grd file.
const char kTitle[] = "Verify it's you";
const char kCancelButtonText[] = "Cancel";
const int kContainerPreferredWidth = 512;
const int kSpacingAfterTitle = 16;
......@@ -383,20 +378,12 @@ void AuthDialogContentsView::AddActionButtonsView() {
buttons_layout->set_main_axis_alignment(
views::BoxLayout::MainAxisAlignment::kEnd);
cancel_button_ =
AddButton(kCancelButtonText, static_cast<int>(ButtonId::kCancel),
action_view_container_);
action_view_container_->SetPreferredSize(
gfx::Size(kContainerPreferredWidth, cancel_button_->height()));
// TODO(b/156258540): Add a "Need help?" button that links to a HC article.
}
void AuthDialogContentsView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == cancel_button_) {
// Cancel() deletes |this|.
InSessionAuthDialogController::Get()->Cancel();
}
// TODO(b/156258540): Add a "Need help?" button that links to a HC article.
}
views::LabelButton* AuthDialogContentsView::AddButton(const std::string& text,
......
......@@ -113,9 +113,6 @@ class AuthDialogContentsView : public views::View,
// Flags of auth methods that should be visible.
uint32_t auth_methods_ = 0u;
// Cancel all operations and close th dialog.
views::LabelButton* cancel_button_ = nullptr;
// Container which holds action buttons.
views::View* action_view_container_ = nullptr;
......
......@@ -35,7 +35,7 @@ std::unique_ptr<views::Widget> CreateAuthDialogWidget(
params.shadow_elevation = 3;
params.delegate->SetInitiallyFocusedView(contents_view.get());
params.delegate->SetModalType(ui::MODAL_TYPE_WINDOW);
params.delegate->SetModalType(ui::MODAL_TYPE_NONE);
params.delegate->SetOwnedByWidget(true);
std::unique_ptr<views::Widget> widget = std::make_unique<views::Widget>();
......
......@@ -13,6 +13,8 @@
#include "base/callback.h"
#include "base/strings/string_util.h"
#include "ui/aura/window.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/focus_controller.h"
namespace ash {
......@@ -96,6 +98,7 @@ void InSessionAuthDialogControllerImpl::OnPinCanAuthenticate(
}
window_tracker_.Remove(source_window);
Shell::Get()->focus_controller()->AddObserver(this);
dialog_ = std::make_unique<InSessionAuthDialog>(auth_methods, source_window);
}
......@@ -109,6 +112,7 @@ void InSessionAuthDialogControllerImpl::DestroyAuthenticationDialog() {
dialog_.reset();
window_tracker_.RemoveAll();
Shell::Get()->focus_controller()->RemoveObserver(this);
}
void InSessionAuthDialogControllerImpl::AuthenticateUserWithPin(
......@@ -170,4 +174,12 @@ void InSessionAuthDialogControllerImpl::Cancel() {
std::move(finish_callback_).Run(false);
}
void InSessionAuthDialogControllerImpl::OnWindowFocused(
aura::Window* gained_focus,
aura::Window* lost_focus) {
if (dialog_ && lost_focus == dialog_->widget()->GetNativeWindow()) {
Cancel();
}
}
} // namespace ash
......@@ -12,6 +12,7 @@
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/aura/window_tracker.h"
class AccountId;
......@@ -26,7 +27,9 @@ class InSessionAuthDialogClient;
class WebAuthnRequestRegistrarImpl;
// InSessionAuthDialogControllerImpl persists as long as UI is running.
class InSessionAuthDialogControllerImpl : public InSessionAuthDialogController {
class InSessionAuthDialogControllerImpl
: public InSessionAuthDialogController,
public aura::client::FocusChangeObserver {
public:
InSessionAuthDialogControllerImpl();
InSessionAuthDialogControllerImpl(const InSessionAuthDialogControllerImpl&) =
......@@ -46,6 +49,10 @@ class InSessionAuthDialogControllerImpl : public InSessionAuthDialogController {
base::OnceCallback<void(bool, FingerprintState)> callback) override;
void Cancel() override;
// aura::client::FocusChangeObserver overrides
void OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) override;
private:
bool IsFingerprintAvailable(const AccountId& account_id);
void OnStartFingerprintAuthSession(AccountId 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