Commit 38b2046f authored by siyua's avatar siyua Committed by Commit Bot

Add Details For Migration Dialogs

1) Add card information, card scroll bar view

2) Add migratable_card_view.*

3) Add OnMigrationFinished() to update the dialog content (title,
instruction, card list, button label, etc)

4) Add logic for controller to update checkbox state(checked/unchecked)

Bug: 852904
Change-Id: I3cec17eb432b51e50d6d32dd8925224e6cf19594
Reviewed-on: https://chromium-review.googlesource.com/1178983
Commit-Queue: Siyu An <siyua@chromium.org>
Reviewed-by: default avatarMathieu Perreault <mathp@chromium.org>
Reviewed-by: default avatarFabio Tirelo <ftirelo@chromium.org>
Reviewed-by: default avatarBret Sepulveda <bsep@chromium.org>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Cr-Commit-Position: refs/heads/master@{#586435}
parent ff82a486
......@@ -2816,6 +2816,8 @@ jumbo_split_static_library("ui") {
"views/autofill/local_card_migration_bubble_views.h",
"views/autofill/local_card_migration_dialog_view.cc",
"views/autofill/local_card_migration_dialog_view.h",
"views/autofill/migratable_card_view.cc",
"views/autofill/migratable_card_view.h",
"views/autofill/save_card_bubble_views.cc",
"views/autofill/save_card_bubble_views.h",
"views/autofill/save_card_manage_cards_bubble_views.cc",
......
......@@ -17,6 +17,7 @@ class LocalCardMigrationDialog {
virtual void ShowDialog(
base::OnceClosure user_accepted_migration_closure) = 0;
virtual void CloseDialog() = 0;
virtual void OnMigrationFinished() = 0;
protected:
LocalCardMigrationDialog() {}
......@@ -28,4 +29,4 @@ class LocalCardMigrationDialog {
} // namespace autofill
#endif // CHROME_BROWSER_UI_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_H_
\ No newline at end of file
#endif // CHROME_BROWSER_UI_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_H_
......@@ -56,8 +56,8 @@ void LocalCardMigrationDialogControllerImpl::SetViewState(
view_state_ = view_state;
}
std::vector<MigratableCreditCard>&
LocalCardMigrationDialogControllerImpl::GetCardList() {
const std::vector<MigratableCreditCard>&
LocalCardMigrationDialogControllerImpl::GetCardList() const {
return migratable_credit_cards_;
}
......@@ -66,6 +66,10 @@ void LocalCardMigrationDialogControllerImpl::SetCardList(
migratable_credit_cards_ = migratable_credit_cards;
}
void LocalCardMigrationDialogControllerImpl::OnCardSelected(int index) {
migratable_credit_cards_[index].ToggleChosen();
}
void LocalCardMigrationDialogControllerImpl::OnDialogClosed() {
if (local_card_migration_dialog_)
local_card_migration_dialog_ = nullptr;
......
......@@ -31,8 +31,9 @@ class LocalCardMigrationDialogControllerImpl
// LocalCardMigrationDialogController:
LocalCardMigrationDialogState GetViewState() const override;
void SetViewState(LocalCardMigrationDialogState view_state) override;
std::vector<MigratableCreditCard>& GetCardList() override;
const std::vector<MigratableCreditCard>& GetCardList() const override;
void SetCardList(std::vector<MigratableCreditCard>& card_list) override;
void OnCardSelected(int index) override;
void OnDialogClosed() override;
protected:
......@@ -47,6 +48,9 @@ class LocalCardMigrationDialogControllerImpl
LocalCardMigrationDialogState view_state_;
// TODO(crbug.com/867194): Currently we will not handle the case of local
// cards added/deleted during migration. migratable_credit_cards_ are local
// cards presented when the user accepts the intermediate bubble.
std::vector<MigratableCreditCard> migratable_credit_cards_;
DISALLOW_COPY_AND_ASSIGN(LocalCardMigrationDialogControllerImpl);
......
......@@ -2,11 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_VIEWS_H_
#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_VIEWS_H_
#ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_VIEW_H_
#include "base/macros.h"
#include "chrome/browser/ui/autofill/local_card_migration_dialog.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget_observer.h"
#include "ui/views/window/dialog_delegate.h"
......@@ -17,13 +18,16 @@ class WebContents;
namespace views {
class Label;
class Separator;
} // namespace views
namespace autofill {
class LocalCardMigrationDialogController;
class MigratableCardView;
class LocalCardMigrationDialogView : public LocalCardMigrationDialog,
public views::ButtonListener,
public views::DialogDelegateView,
public views::WidgetObserver {
public:
......@@ -34,6 +38,7 @@ class LocalCardMigrationDialogView : public LocalCardMigrationDialog,
// LocalCardMigrationDialog
void ShowDialog(base::OnceClosure user_accepted_migration_closure) override;
void CloseDialog() override;
void OnMigrationFinished() override;
// views::DialogDelegateView
gfx::Size CalculatePreferredSize() const override;
......@@ -41,13 +46,18 @@ class LocalCardMigrationDialogView : public LocalCardMigrationDialog,
void AddedToWidget() override;
bool ShouldShowCloseButton() const override;
base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
bool IsDialogButtonEnabled(ui::DialogButton button) const override;
bool Accept() override;
bool Cancel() override;
// views::WidgetObserver
void OnWidgetClosing(views::Widget* widget) override;
// views::ButtonListener
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private:
void Init();
base::string16 GetDialogTitle() const;
base::string16 GetDialogInstruction() const;
int GetHeaderImageId() const;
......@@ -55,14 +65,30 @@ class LocalCardMigrationDialogView : public LocalCardMigrationDialog,
base::string16 GetCancelButtonLabel() const;
void OnSaveButtonClicked();
void OnCancelButtonClicked();
void OnViewCardsButtonClicked();
void OpenUrl(const GURL& url);
void SetMigrationIsPending(bool is_pending);
LocalCardMigrationDialogController* controller_;
content::WebContents* web_contents_;
views::Label* title_;
// Contains title, explanation and card scroll bar view.
views::View* content_container_ = nullptr;
views::Label* title_ = nullptr;
views::Label* explanation_text_ = nullptr;
// A list of MigratableCardView.
views::View* card_list_view_ = nullptr;
// Separates the card scroll bar view and the legal message.
views::Separator* separator_ = nullptr;
views::Label* explanation_text_;
// Whether the uploading is in progress and results are
// pending.
bool migration_pending_ = false;
base::OnceClosure user_accepted_migration_closure_;
......@@ -71,4 +97,4 @@ class LocalCardMigrationDialogView : public LocalCardMigrationDialog,
} // namespace autofill
#endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_VIEWS_H_
\ No newline at end of file
#endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_LOCAL_CARD_MIGRATION_DIALOG_VIEW_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/autofill/migratable_card_view.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/autofill/local_card_migration_dialog_state.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "components/autofill/core/browser/local_card_migration_manager.h"
#include "components/grit/components_scaled_resources.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/image_button_factory.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
namespace autofill {
constexpr char MigratableCardView::kViewClassName[] = "MigratableCardView";
MigratableCardView::MigratableCardView(
const MigratableCreditCard& migratable_credit_card,
views::ButtonListener* listener,
int card_index) {
Init(migratable_credit_card, listener, card_index);
}
MigratableCardView::~MigratableCardView() = default;
void MigratableCardView::SetCheckboxEnabled(bool checkbox_enabled) {
checkbox_->SetEnabled(checkbox_enabled);
}
void MigratableCardView::UpdateCardView(
LocalCardMigrationDialogState dialog_state) {
checkbox_->SetVisible(false);
switch (dialog_state) {
case LocalCardMigrationDialogState::kFinished:
migration_succeeded_image_->SetVisible(true);
break;
case LocalCardMigrationDialogState::kActionRequired:
migration_failed_image_->SetVisible(true);
delete_card_from_local_button_->SetVisible(true);
break;
case LocalCardMigrationDialogState::kOffered:
NOTREACHED();
break;
}
}
const char* MigratableCardView::GetClassName() const {
return kViewClassName;
}
void MigratableCardView::Init(
const MigratableCreditCard& migratable_credit_card,
views::ButtonListener* listener,
int card_index) {
ChromeLayoutProvider* provider = ChromeLayoutProvider::Get();
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::kHorizontal, gfx::Insets(),
provider->GetDistanceMetric(DISTANCE_RELATED_CONTROL_HORIZONTAL_SMALL)));
checkbox_ = new views::Checkbox(base::string16());
checkbox_->SetChecked(migratable_credit_card.is_chosen());
checkbox_->set_tag(card_index);
checkbox_->SetVisible(true);
AddChildView(checkbox_);
constexpr int kMigrationResultImageSize = 16;
migration_succeeded_image_ = new views::ImageView();
migration_succeeded_image_->SetImage(
gfx::CreateVectorIcon(vector_icons::kCheckCircleIcon,
kMigrationResultImageSize, gfx::kGoogleGreen700));
migration_succeeded_image_->SetVisible(false);
AddChildView(migration_succeeded_image_);
migration_failed_image_ = new views::ImageView();
migration_failed_image_->SetImage(gfx::CreateVectorIcon(
kBrowserToolsErrorIcon, kMigrationResultImageSize, gfx::kGoogleRed700));
migration_failed_image_->SetVisible(false);
AddChildView(migration_failed_image_);
std::unique_ptr<views::ImageView> card_image =
std::make_unique<views::ImageView>();
card_image->SetImage(
rb.GetImageNamed(CreditCard::IconResourceId(
migratable_credit_card.credit_card().network()))
.AsImageSkia());
AddChildView(card_image.release());
std::unique_ptr<views::Label> card_description =
std::make_unique<views::Label>(
migratable_credit_card.credit_card().NetworkAndLastFourDigits(),
views::style::CONTEXT_LABEL);
AddChildView(card_description.release());
std::unique_ptr<views::Label> card_expiration =
std::make_unique<views::Label>(migratable_credit_card.credit_card()
.AbbreviatedExpirationDateForDisplay(),
views::style::CONTEXT_LABEL);
AddChildView(card_expiration.release());
delete_card_from_local_button_ = views::CreateVectorImageButton(listener);
views::SetImageFromVectorIcon(delete_card_from_local_button_, kTrashCanIcon);
// TODO(crbug.com/867194): Add tooltip and tag for the
// delete_card_from_local_button_.
delete_card_from_local_button_->SetVisible(false);
AddChildView(delete_card_from_local_button_);
}
} // namespace autofill
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_MIGRATABLE_CARD_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_MIGRATABLE_CARD_VIEW_H_
#include "base/macros.h"
#include "ui/views/view.h"
namespace views {
class ButtonListener;
class Checkbox;
class ImageButton;
class ImageView;
} // namespace views
namespace autofill {
enum class LocalCardMigrationDialogState;
class MigratableCreditCard;
// A view composed of a checkbox or an image indicating migration results, card
// network image, card network, last four digits of card number and card
// expiration date. Used by LocalCardMigrationDialogView.
class MigratableCardView : public views::View {
public:
static const char kViewClassName[];
MigratableCardView(const MigratableCreditCard& migratable_credit_card,
views::ButtonListener* listener,
int card_index);
~MigratableCardView() override;
void SetCheckboxEnabled(bool checkbox_enabled);
void UpdateCardView(LocalCardMigrationDialogState dialog_state);
// views::View
const char* GetClassName() const override;
private:
void Init(const MigratableCreditCard& migratable_credit_card,
views::ButtonListener* listener,
int card_index);
views::Checkbox* checkbox_ = nullptr;
views::ImageView* migration_succeeded_image_ = nullptr;
views::ImageView* migration_failed_image_ = nullptr;
views::ImageButton* delete_card_from_local_button_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(MigratableCardView);
};
} // namespace autofill
#endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_MIGRATABLE_CARD_VIEW_H_
......@@ -158,6 +158,8 @@ int ChromeLayoutProvider::GetDistanceMetric(int metric) const {
return kSmallSnapPoint;
case DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH:
return kMediumSnapPoint;
case DISTANCE_LARGE_MODAL_DIALOG_PREFERRED_WIDTH:
return kLargeSnapPoint;
default:
return LayoutProvider::GetDistanceMetric(metric);
}
......
......@@ -32,7 +32,7 @@ class MigratableCreditCard {
CreditCard credit_card() const { return credit_card_; }
bool is_chosen() const { return is_chosen_; }
void set_is_chosen(bool is_chosen) { is_chosen_ = is_chosen; }
void ToggleChosen() { is_chosen_ = !is_chosen(); }
private:
// The main card information of the current migratable card.
......
......@@ -26,8 +26,11 @@ class LocalCardMigrationDialogController {
virtual LocalCardMigrationDialogState GetViewState() const = 0;
virtual void SetViewState(LocalCardMigrationDialogState view_state) = 0;
virtual std::vector<MigratableCreditCard>& GetCardList() = 0;
virtual const std::vector<MigratableCreditCard>& GetCardList() const = 0;
// TODO(crbug.com/867194): Ensure this would not be called when migration is
// happending.
virtual void SetCardList(std::vector<MigratableCreditCard>& card_list) = 0;
virtual void OnCardSelected(int index) = 0;
virtual void OnDialogClosed() = 0;
private:
......
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