Commit 09ac2af8 authored by Rachel Wong's avatar Rachel Wong Committed by Commit Bot

[consent toggle] Refactor privacy view into parent and child classes.

Currently, privacy_info_view is a launcher notice about Assistant privacy.

This CL separates privacy_info_view into two classes:
1) privacy_info_view.*, a parent class for privacy notices in the launcher;
2) assistant/assistant_privacy_info_view.*, which contains all the Assistant-specific methods and strings.

This allows us to create a new privacy notice for Suggested Content, which uses the same parent view but has its own methods and strings.

This CL should not make any functionality changes.

Bug: 1079169
Change-Id: I28324a9196ef2643e5fdcef122c13a8113ee2603
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2198848Reviewed-by: default avatarJenny Zhang <jennyz@chromium.org>
Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Reviewed-by: default avatarTony Yeoman <tby@chromium.org>
Commit-Queue: Rachel Wong <wrong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772481}
parent cd2237d3
......@@ -46,6 +46,8 @@ component("app_list") {
"views/assistant/assistant_main_view.h",
"views/assistant/assistant_page_view.cc",
"views/assistant/assistant_page_view.h",
"views/assistant/assistant_privacy_info_view.cc",
"views/assistant/assistant_privacy_info_view.h",
"views/contents_view.cc",
"views/contents_view.h",
"views/expand_arrow_view.cc",
......
// Copyright 2020 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 "ash/app_list/views/assistant/assistant_privacy_info_view.h"
#include "ash/app_list/app_list_view_delegate.h"
#include "ash/app_list/views/search_result_page_view.h"
#include "ash/assistant/util/i18n_util.h"
#include "ash/public/cpp/assistant/controller/assistant_controller.h"
#include "ui/strings/grit/ui_strings.h"
namespace ash {
AssistantPrivacyInfoView::AssistantPrivacyInfoView(
AppListViewDelegate* view_delegate,
SearchResultPageView* search_result_page_view)
: PrivacyInfoView(IDS_APP_LIST_ASSISTANT_PRIVACY_INFO),
view_delegate_(view_delegate),
search_result_page_view_(search_result_page_view) {}
AssistantPrivacyInfoView::~AssistantPrivacyInfoView() = default;
void AssistantPrivacyInfoView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (!IsCloseButton(sender))
return;
view_delegate_->MarkAssistantPrivacyInfoDismissed();
search_result_page_view_->OnAssistantPrivacyInfoViewCloseButtonPressed();
}
void AssistantPrivacyInfoView::StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) {
constexpr char url[] = "https://support.google.com/chromebook?p=assistant";
AssistantController::Get()->OpenUrl(
assistant::util::CreateLocalizedGURL(url));
}
} // namespace ash
// Copyright 2020 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 ASH_APP_LIST_VIEWS_ASSISTANT_ASSISTANT_PRIVACY_INFO_VIEW_H_
#define ASH_APP_LIST_VIEWS_ASSISTANT_ASSISTANT_PRIVACY_INFO_VIEW_H_
#include "ash/app_list/views/privacy_info_view.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/styled_label_listener.h"
namespace ash {
class AppListViewDelegate;
class SearchResultPageView;
// View representing Assistant's privacy info in the Launcher.
class AssistantPrivacyInfoView : public PrivacyInfoView {
public:
AssistantPrivacyInfoView(AppListViewDelegate* view_delegate,
SearchResultPageView* search_result_page_view);
AssistantPrivacyInfoView(const AssistantPrivacyInfoView&) = delete;
AssistantPrivacyInfoView& operator=(const AssistantPrivacyInfoView&) = delete;
~AssistantPrivacyInfoView() override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// views::StyledLabelListener:
void StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) override;
private:
AppListViewDelegate* const view_delegate_;
SearchResultPageView* const search_result_page_view_;
};
} // namespace ash
#endif // ASH_APP_LIST_VIEWS_ASSISTANT_ASSISTANT_PRIVACY_INFO_VIEW_H_
......@@ -4,10 +4,6 @@
#include "ash/app_list/views/privacy_info_view.h"
#include "ash/app_list/app_list_view_delegate.h"
#include "ash/app_list/views/search_result_page_view.h"
#include "ash/assistant/util/i18n_util.h"
#include "ash/public/cpp/assistant/controller/assistant_controller.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/paint_vector_icon.h"
......@@ -36,11 +32,8 @@ constexpr int kIconSizeDip = 20;
} // namespace
PrivacyInfoView::PrivacyInfoView(AppListViewDelegate* view_delegate,
SearchResultPageView* search_result_page_view)
: view_delegate_(view_delegate),
search_result_page_view_(search_result_page_view) {
InitLayout();
PrivacyInfoView::PrivacyInfoView(const int info_string_id) {
InitLayout(info_string_id);
}
PrivacyInfoView::~PrivacyInfoView() = default;
......@@ -91,27 +84,7 @@ void PrivacyInfoView::OnGestureEvent(ui::GestureEvent* event) {
}
}
void PrivacyInfoView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender != close_button_)
return;
// TODO(crbug/1079169): Update this method based on the specific view.
view_delegate_->MarkAssistantPrivacyInfoDismissed();
search_result_page_view_->OnAssistantPrivacyInfoViewCloseButtonPressed();
}
void PrivacyInfoView::StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) {
// TODO(crbug/1079169): Pass in this URL based on which privacy view is being
// shown.
constexpr char url[] = "https://support.google.com/chromebook?p=assistant";
AssistantController::Get()->OpenUrl(
assistant::util::CreateLocalizedGURL(url));
}
void PrivacyInfoView::InitLayout() {
void PrivacyInfoView::InitLayout(const int info_string_id) {
SetLayoutManager(std::make_unique<views::FillLayout>());
SetBorder(views::CreateEmptyBorder(gfx::Insets(kRowMarginDip)));
row_container_ = AddChildView(std::make_unique<views::View>());
......@@ -135,7 +108,7 @@ void PrivacyInfoView::InitLayout() {
InitInfoIcon();
// Text.
InitText();
InitText(info_string_id);
// Spacer.
layout_manager->SetFlexForView(
......@@ -153,12 +126,12 @@ void PrivacyInfoView::InitInfoIcon() {
gfx::kGoogleBlue600));
}
void PrivacyInfoView::InitText() {
void PrivacyInfoView::InitText(const int info_string_id) {
const base::string16 link =
l10n_util::GetStringUTF16(IDS_APP_LIST_LEARN_MORE);
size_t offset;
const base::string16 text = l10n_util::GetStringFUTF16(
IDS_APP_LIST_ASSISTANT_PRIVACY_INFO, link, &offset);
const base::string16 text =
l10n_util::GetStringFUTF16(info_string_id, link, &offset);
auto text_view = std::make_unique<views::StyledLabel>(text, this);
views::StyledLabel::RangeStyleInfo style;
style.custom_font = text_view->GetDefaultFontList().Derive(
......@@ -182,6 +155,7 @@ void PrivacyInfoView::InitCloseButton() {
gfx::kGoogleGrey700));
close_button->SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER);
close_button->SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE);
// TODO(crbug/1079169): Create a new string that is not Assistant-specific.
base::string16 close_button_label(
l10n_util::GetStringUTF16(IDS_APP_LIST_ASSISTANT_PRIVACY_INFO_CLOSE));
close_button->SetAccessibleName(close_button_label);
......@@ -206,4 +180,8 @@ void PrivacyInfoView::InitCloseButton() {
close_button_ = row_container_->AddChildView(std::move(close_button));
}
bool PrivacyInfoView::IsCloseButton(views::Button* button) const {
return button == close_button_;
}
} // namespace ash
......@@ -17,16 +17,11 @@ class StyledLabel;
namespace ash {
class AppListViewDelegate;
class SearchResultPageView;
// View representing privacy info in Launcher.
class PrivacyInfoView : public views::View,
public views::ButtonListener,
public views::StyledLabelListener {
public:
PrivacyInfoView(AppListViewDelegate* view_delegate,
SearchResultPageView* search_result_page_view);
~PrivacyInfoView() override;
// views::View:
......@@ -38,18 +33,15 @@ class PrivacyInfoView : public views::View,
void OnMouseEvent(ui::MouseEvent* event) override;
void OnGestureEvent(ui::GestureEvent* event) override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
protected:
explicit PrivacyInfoView(int info_string_id);
// views::StyledLabelListener:
void StyledLabelLinkClicked(views::StyledLabel* label,
const gfx::Range& range,
int event_flags) override;
bool IsCloseButton(views::Button* button) const;
private:
void InitLayout();
void InitLayout(int info_string_id);
void InitInfoIcon();
void InitText();
void InitText(int info_string_id);
void InitCloseButton();
views::View* row_container_ = nullptr; // Owned by view hierarchy.
......@@ -57,9 +49,6 @@ class PrivacyInfoView : public views::View,
views::StyledLabel* text_view_ = nullptr; // Owned by view hierarchy.
views::ImageButton* close_button_ = nullptr; // Owned by view hierarchy.
AppListViewDelegate* const view_delegate_;
SearchResultPageView* const search_result_page_view_;
DISALLOW_COPY_AND_ASSIGN(PrivacyInfoView);
};
......
......@@ -12,8 +12,8 @@
#include "ash/app_list/app_list_util.h"
#include "ash/app_list/app_list_view_delegate.h"
#include "ash/app_list/views/app_list_main_view.h"
#include "ash/app_list/views/assistant/assistant_privacy_info_view.h"
#include "ash/app_list/views/contents_view.h"
#include "ash/app_list/views/privacy_info_view.h"
#include "ash/app_list/views/search_box_view.h"
#include "ash/app_list/views/search_result_base_view.h"
#include "ash/app_list/views/search_result_list_view.h"
......@@ -175,7 +175,8 @@ SearchResultPageView::SearchResultPageView(AppListViewDelegate* view_delegate,
views::BoxLayout::Orientation::kVertical, gfx::Insets(), 0));
if (view_delegate_->ShouldShowAssistantPrivacyInfo()) {
assistant_privacy_info_view_ = new PrivacyInfoView(view_delegate_, this);
assistant_privacy_info_view_ =
new AssistantPrivacyInfoView(view_delegate_, this);
contents_view_->AddChildView(assistant_privacy_info_view_);
}
......
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