-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ConsentV2] Add the consent dialog view
This CL implements the complete consent dialog view. Mock: https://screenshot.googleplex.com/BWL9oYXggrXJfci Screenshot: https://screenshot.googleplex.com/7GAshxrJbNA8dfN (cherry picked from commit ed06c8f) Bug: 1318685 Change-Id: Iaa0c9368a1f5010b524e87b4690025d75456c2c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3603024 Reviewed-by: Peter Kasting <pkasting@chromium.org> Commit-Queue: Mei Liang <meiliang@chromium.org> Cr-Original-Commit-Position: refs/heads/main@{#1005546} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3680288 Reviewed-by: Prudhvikumar Bommana <pbommana@google.com> Owners-Override: Prudhvikumar Bommana <pbommana@google.com> Commit-Queue: Prudhvikumar Bommana <pbommana@google.com> Cr-Commit-Position: refs/branch-heads/5060@{#430} Cr-Branched-From: b83393d-refs/heads/main@{#1002911}
- Loading branch information
Mei Liang
authored and
Chromium LUCI CQ
committed
May 31, 2022
1 parent
b5ebee0
commit fd8a954
Showing
6 changed files
with
180 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
chrome/browser/ui/views/commerce/ntp_discount_consent_dialog_view.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// Copyright 2022 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/commerce/ntp_discount_consent_dialog_view.h" | ||
|
||
#include "base/callback_helpers.h" | ||
#include "chrome/browser/cart/chrome_cart.mojom.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/browser/ui/browser_window.h" | ||
#include "components/constrained_window/constrained_window_views.h" | ||
#include "ui/views/widget/widget.h" | ||
#include "ui/views/window/dialog_delegate.h" | ||
|
||
#include "chrome/browser/ui/views/accessibility/theme_tracking_non_accessible_image_view.h" | ||
#include "chrome/browser/ui/views/chrome_layout_provider.h" | ||
#include "chrome/browser/ui/views/chrome_typography.h" | ||
#include "chrome/grit/theme_resources.h" | ||
#include "components/strings/grit/components_strings.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "ui/base/resource/resource_bundle.h" | ||
#include "ui/views/controls/label.h" | ||
#include "ui/views/layout/box_layout.h" | ||
|
||
namespace { | ||
// Spacing between child of the Discount Consent Dialog View | ||
constexpr int kChildSpacing = 24; | ||
} // namespace | ||
|
||
// static | ||
void NtpDiscountConsentDialogView::Show(Browser* browser, | ||
ActionCallback callback) { | ||
constrained_window::CreateBrowserModalDialogViews( | ||
std::make_unique<NtpDiscountConsentDialogView>(std::move(callback)), | ||
browser->window()->GetNativeWindow()) | ||
->Show(); | ||
} | ||
|
||
NtpDiscountConsentDialogView::NtpDiscountConsentDialogView( | ||
ActionCallback callback) | ||
: callback_(std::move(callback)) { | ||
// Set up dialog properties. | ||
SetModalType(ui::MODAL_TYPE_WINDOW); | ||
SetShowCloseButton(false); | ||
SetOwnedByWidget(true); | ||
// TODO(meiliang@): Set text for the button. | ||
SetButtons(ui::DIALOG_BUTTON_CANCEL | ui::DIALOG_BUTTON_OK); | ||
set_fixed_width(views::LayoutProvider::Get()->GetDistanceMetric( | ||
DISTANCE_LARGE_MODAL_DIALOG_PREFERRED_WIDTH)); | ||
|
||
SetAcceptCallback(base::BindOnce(&NtpDiscountConsentDialogView::OnAccept, | ||
base::Unretained(this))); | ||
SetCancelCallback(base::BindOnce(&NtpDiscountConsentDialogView::OnReject, | ||
base::Unretained(this))); | ||
SetCloseCallback(base::BindOnce(&NtpDiscountConsentDialogView::OnDismiss, | ||
base::Unretained(this))); | ||
|
||
// Set up dialog content view. | ||
SetLayoutManager(std::make_unique<views::BoxLayout>( | ||
views::BoxLayout::Orientation::kVertical, | ||
ChromeLayoutProvider::Get()->GetInsetsMetric(views::INSETS_DIALOG), | ||
kChildSpacing)); | ||
|
||
ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | ||
|
||
AddChildView(std::make_unique<ThemeTrackingNonAccessibleImageView>( | ||
*bundle.GetImageSkiaNamed(IDR_NTP_CART_DISCOUNT_CONSENT_LIGHT), | ||
*bundle.GetImageSkiaNamed(IDR_NTP_CART_DISCOUNT_CONSENT_DARK), | ||
base::BindRepeating(&NtpDiscountConsentDialogView::GetBackgroundColor, | ||
base::Unretained(this)))); | ||
|
||
auto title_label = std::make_unique<views::Label>( | ||
l10n_util::GetStringUTF16(IDS_NATIVE_NTP_CART_DISCOUNT_CONSENT_TITLE), | ||
CONTEXT_HEADLINE, views::style::STYLE_PRIMARY); | ||
auto* title = AddChildView(std::move(title_label)); | ||
title->SetMultiLine(true); | ||
|
||
auto consent_label = std::make_unique<views::Label>( | ||
l10n_util::GetStringUTF16(IDS_NATIVE_NTP_CART_DISCOUNT_CONSENT_BODY), | ||
views::style::CONTEXT_DIALOG_BODY_TEXT, views::style::STYLE_SECONDARY); | ||
auto* consent = AddChildView(std::move(consent_label)); | ||
consent->SetMultiLine(true); | ||
} | ||
|
||
NtpDiscountConsentDialogView::~NtpDiscountConsentDialogView() = default; | ||
|
||
SkColor NtpDiscountConsentDialogView::GetBackgroundColor() { | ||
return GetWidget()->GetColorProvider()->GetColor(ui::kColorDialogBackground); | ||
} | ||
|
||
void NtpDiscountConsentDialogView::OnAccept() { | ||
assert(callback_); | ||
std::move(callback_).Run(chrome_cart::mojom::ConsentStatus::ACCEPTED); | ||
} | ||
|
||
void NtpDiscountConsentDialogView::OnReject() { | ||
assert(callback_); | ||
std::move(callback_).Run(chrome_cart::mojom::ConsentStatus::REJECTED); | ||
} | ||
|
||
void NtpDiscountConsentDialogView::OnDismiss() { | ||
assert(callback_); | ||
std::move(callback_).Run(chrome_cart::mojom::ConsentStatus::DISMISSED); | ||
} |
34 changes: 34 additions & 0 deletions
34
chrome/browser/ui/views/commerce/ntp_discount_consent_dialog_view.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2022 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_COMMERCE_NTP_DISCOUNT_CONSENT_DIALOG_VIEW_H_ | ||
#define CHROME_BROWSER_UI_VIEWS_COMMERCE_NTP_DISCOUNT_CONSENT_DIALOG_VIEW_H_ | ||
|
||
#include "base/callback_helpers.h" | ||
#include "chrome/browser/cart/chrome_cart.mojom.h" | ||
#include "ui/views/window/dialog_delegate.h" | ||
|
||
class Browser; | ||
|
||
class NtpDiscountConsentDialogView : public views::DialogDelegateView { | ||
public: | ||
using ActionCallback = | ||
base::OnceCallback<void(chrome_cart::mojom::ConsentStatus)>; | ||
static void Show(Browser* browser, ActionCallback callback); | ||
explicit NtpDiscountConsentDialogView(ActionCallback callback); | ||
~NtpDiscountConsentDialogView() override; | ||
|
||
private: | ||
ActionCallback callback_; | ||
|
||
SkColor GetBackgroundColor(); | ||
// Called when the accept button is clicked. | ||
void OnAccept(); | ||
// Called when the reject button is clicked. | ||
void OnReject(); | ||
// Called when the Esc key is used. | ||
void OnDismiss(); | ||
}; | ||
|
||
#endif // CHROME_BROWSER_UI_VIEWS_COMMERCE_NTP_DISCOUNT_CONSENT_DIALOG_VIEW_H_ |
33 changes: 33 additions & 0 deletions
33
chrome/browser/ui/views/commerce/ntp_discount_consent_dialog_view_browsertest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2022 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/commerce/ntp_discount_consent_dialog_view.h" | ||
|
||
#include "chrome/browser/ui/test/test_browser_dialog.h" | ||
#include "content/public/test/browser_test.h" | ||
|
||
// Test harness for integration tests using NtpDiscountConsentView. | ||
class NtpDiscountConsentDialogViewBrowserTest : public DialogBrowserTest { | ||
public: | ||
NtpDiscountConsentDialogViewBrowserTest() = default; | ||
|
||
NtpDiscountConsentDialogViewBrowserTest( | ||
const NtpDiscountConsentDialogViewBrowserTest&) = delete; | ||
NtpDiscountConsentDialogViewBrowserTest& operator=( | ||
const NtpDiscountConsentDialogViewBrowserTest&) = delete; | ||
|
||
// DialogBrowserTest: | ||
void ShowUi(const std::string& name) override { | ||
NtpDiscountConsentDialogView::Show( | ||
browser(), | ||
base::BindOnce([](chrome_cart::mojom::ConsentStatus status) {})); | ||
} | ||
}; | ||
|
||
// Shows the dialog for bookmarking all tabs. This shows a BookmarkEditorView | ||
// dialog, with a tree view, where a user can rename and select a parent folder. | ||
IN_PROC_BROWSER_TEST_F(NtpDiscountConsentDialogViewBrowserTest, | ||
InvokeUi_default) { | ||
ShowAndVerifyUi(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters