Commit ad57ea3c authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

Make cancel the initially focused button in PWA installation confirmation dialogs

This CL makes "cancel" the initially focused button in PWA installation
confirmation dialogs. This is to prevent accidental installations if the
user holds down enter.
The "install" button is still coloured blue as if it were the default action.

Before: https://bugs.chromium.org/p/chromium/issues/attachment?aid=391193&signed_aid=oHH2Y0KPtmjQ0oX90XEI4A==&inline=1
After: https://bugs.chromium.org/p/chromium/issues/attachment?aid=392968&signed_aid=sk4b6UZkAkZ9U6T9qqwovw==&inline=1

Change-Id: I05ac2d11aa15077395c617e5ba067025de6d98ca
Bug: 957848
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1588070
Commit-Queue: Alan Cutter <alancutter@chromium.org>
Auto-Submit: Alan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarJay Harris <harrisjay@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660688}
parent b43b15f3
......@@ -16,9 +16,11 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/text_elider.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/window/dialog_client_view.h"
namespace {
......@@ -124,6 +126,11 @@ base::string16 PWAConfirmation::GetDialogButtonLabel(ui::DialogButton button) {
: IDS_CANCEL);
}
views::View* PWAConfirmation::GetInitiallyFocusedView(
views::DialogDelegateView* dialog) {
return dialog->GetDialogClientView()->cancel_button();
}
void PWAConfirmation::Accept() {
DCHECK(web_app_info_);
std::move(callback_).Run(true, std::move(web_app_info_));
......
......@@ -10,12 +10,18 @@
#include "chrome/common/web_application_info.h"
#include "ui/views/window/dialog_delegate.h"
namespace views {
class View;
}
// Provides the core UI for confirming the installation of a PWA for the
// |PWAConfirmationDialogView| and |PWAConfirmationBubbleView| form factors.
class PWAConfirmation {
public:
static base::string16 GetWindowTitle();
static base::string16 GetDialogButtonLabel(ui::DialogButton button);
static views::View* GetInitiallyFocusedView(
views::DialogDelegateView* dialog);
PWAConfirmation(views::DialogDelegateView* dialog,
std::unique_ptr<WebApplicationInfo> web_app_info,
......
......@@ -42,6 +42,10 @@ base::string16 PWAConfirmationBubbleView::GetDialogButtonLabel(
return PWAConfirmation::GetDialogButtonLabel(button);
}
views::View* PWAConfirmationBubbleView::GetInitiallyFocusedView() {
return PWAConfirmation::GetInitiallyFocusedView(this);
}
void PWAConfirmationBubbleView::WindowClosing() {
DCHECK_EQ(g_bubble_, this);
g_bubble_ = nullptr;
......
......@@ -24,6 +24,7 @@ class PWAConfirmationBubbleView : public LocationBarBubbleDelegateView {
bool ShouldShowCloseButton() const override;
base::string16 GetWindowTitle() const override;
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
views::View* GetInitiallyFocusedView() override;
void WindowClosing() override;
bool Accept() override;
......
......@@ -41,6 +41,10 @@ bool PWAConfirmationDialogView::ShouldShowCloseButton() const {
return false;
}
views::View* PWAConfirmationDialogView::GetInitiallyFocusedView() {
return PWAConfirmation::GetInitiallyFocusedView(this);
}
void PWAConfirmationDialogView::WindowClosing() {
pwa_confirmation_.WindowClosing();
}
......
......@@ -29,6 +29,7 @@ class PWAConfirmationDialogView : public views::DialogDelegateView {
ui::ModalType GetModalType() const override;
base::string16 GetWindowTitle() const override;
bool ShouldShowCloseButton() const override;
views::View* GetInitiallyFocusedView() override;
void WindowClosing() override;
// views::DialogDelegateView:
......
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