Skip to content

Commit

Permalink
Use Infobar for WDP CTA
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed Nov 22, 2022
1 parent 9fc2df9 commit 714b52b
Show file tree
Hide file tree
Showing 41 changed files with 1,359 additions and 66 deletions.
16 changes: 16 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,22 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
<message name="IDS_ACC_BRAVE_SEARCH_CONVERSION_DISMISS_BUTTON" desc="Announcement when the dismiss button is focused.">
Dismiss Brave search conversion, press Enter to remove this suggestion
</message>
<!-- web Discovery InfoBar -->
<message name="IDS_WEB_DISCOVERY_INFOBAR_MESSAGE" desc="The text for web discovery infobar message">
Help improve <ph name="SEARCH_NAME">$1<ex>Brave Search</ex></ph> by sending anonymous usage data. <ph name="MORE_INFO">$2<ex>More info</ex></ph>
</message>
<message name="IDS_WEB_DISCOVERY_INFOBAR_MESSAGE_BRAVE_SEARCH" desc="The text for brave search part in message">
Brave Search
</message>
<message name="IDS_WEB_DISCOVERY_INFOBAR_MESSAGE_MORE_INFO" desc="The text for more info link part in message">
More info
</message>
<message name="IDS_WEB_DISCOVERY_INFOBAR_OK_BUTTON_LABEL" desc="The text for ok button in infobar">
OK
</message>
<message name="IDS_WEB_DISCOVERY_INFOBAR_NO_THANKS_LABEL" desc="The text for no thanks button in infobar">
No thanks
</message>
</if>

<!-- Brave Ads -->
Expand Down
3 changes: 3 additions & 0 deletions app/theme/brave_theme_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@
<structure type="chrome_scaled_image" name="IDR_PROFILE_AVATAR_88" file="common/avatars/avatar_bonbon_royal.png" />
<structure type="chrome_scaled_image" name="IDR_PROFILE_AVATAR_89" file="common/avatars/avatar_bonbon_ninja.png" />

<structure type="chrome_scaled_image" name="IDR_BRAVE_WEB_DISCOVERY_INFOBAR_BG_GRAPHIC" file="brave/brave_web_discovery_infobar_bg_graphic.png" />
<structure type="chrome_scaled_image" name="IDR_BRAVE_WEB_DISCOVERY_INFOBAR_BG_GRAPHIC_DARK" file="brave/brave_web_discovery_infobar_bg_graphic_dark.png" />
<structure type="chrome_scaled_image" name="IDR_BRAVE_WEB_DISCOVERY_INFOBAR_ICON" file="brave/brave_web_discovery_infobar_icon.png" />
<structure type="chrome_scaled_image" name="IDR_BRAVE_SEARCH_CONVERSION_BANNER_GRAPHIC" file="brave/brave_search_conversion_banner_graphic.png" />
<structure type="chrome_scaled_image" name="IDR_BRAVE_SEARCH_CONVERSION_BANNER_GRAPHIC_DARK" file="brave/brave_search_conversion_banner_graphic_dark.png" />
<structure type="chrome_scaled_image" name="IDR_BRAVE_SEARCH_LOGO_IN_SEARCH_PROMOTION" file="brave/brave_search_logo_in_search_promotion.png" />
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/vector_icons/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ aggregate_vector_icons("brave_vector_icons") {
"sidebar_toolbar_button_right.icon",
"vpn_indicator.icon",
"wallet_toolbar_button.icon",
"web_discovery_infobar_close_button.icon",
]

if (enable_sidebar) {
Expand Down
21 changes: 21 additions & 0 deletions app/vector_icons/web_discovery_infobar_close_button.icon
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) 2022 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.

CANVAS_DIMENSIONS, 20,
MOVE_TO, 4.99f, 4.99f,
R_ARC_TO, 0.71f, 0.71f, 0, 0, 0, 0, 1,
LINE_TO, 9, 10,
LINE_TO, 4.99f, 14.01f,
R_ARC_TO, 0.71f, 0.71f, 0, 1, 0, 1, 1,
LINE_TO, 10, 11,
R_LINE_TO, 4.01f, 4.01f,
R_ARC_TO, 0.71f, 0.71f, 0, 0, 0, 1, -1,
LINE_TO, 11, 10,
R_LINE_TO, 4.01f, -4.01f,
R_ARC_TO, 0.71f, 0.71f, 0, 1, 0, -1, -1,
LINE_TO, 10, 9,
LINE_TO, 6, 4.99f,
R_ARC_TO, 0.71f, 0.71f, 0, 0, 0, -1, 0,
CLOSE
1 change: 1 addition & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
#if BUILDFLAG(ENABLE_EXTENSIONS)
// Web discovery extension, default false
registry->RegisterBooleanPref(kWebDiscoveryEnabled, false);
registry->RegisterDictionaryPref(kWebDiscoveryCTAState);
#endif

#if BUILDFLAG(ENABLE_SPEEDREADER)
Expand Down
5 changes: 5 additions & 0 deletions browser/ui/color/brave_color_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
E_CPONLY(kColorLocationBarFocusRing) \
E_CPONLY(kColorDialogDontAskAgainButton) \
E_CPONLY(kColorDialogDontAskAgainButtonHovered) \
E_CPONLY(kColorWebDiscoveryInfoBarBackground) \
E_CPONLY(kColorWebDiscoveryInfoBarMessage) \
E_CPONLY(kColorWebDiscoveryInfoBarLink) \
E_CPONLY(kColorWebDiscoveryInfoBarNoThanks) \
E_CPONLY(kColorWebDiscoveryInfoBarClose)

#define BRAVE_SEARCH_CONVERSION_COLOR_IDS \
E_CPONLY(kColorSearchConversionBannerTypeBackgroundBorder) \
Expand Down
16 changes: 16 additions & 0 deletions browser/ui/color/brave_color_mixer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@ void AddBraveLightThemeColorMixer(ui::ColorProvider* provider,
SkColorSetRGB(0xF0, 0xF2, 0xFF))};
#endif

mixer[kColorWebDiscoveryInfoBarBackground] = {
SkColorSetRGB(0xFF, 0xFF, 0xFF)};
mixer[kColorWebDiscoveryInfoBarMessage] = {SkColorSetRGB(0x1D, 0x1F, 0x25)};
mixer[kColorWebDiscoveryInfoBarLink] = {SkColorSetRGB(0x4C, 0x54, 0xD2)};
mixer[kColorWebDiscoveryInfoBarNoThanks] = {SkColorSetRGB(0x6B, 0x70, 0x84)};
mixer[kColorWebDiscoveryInfoBarClose] = {SkColorSetRGB(0x6B, 0x70, 0x84)};

// Colors for HelpBubble. IDs are defined in
// chrome/browser/ui/color/chrome_color_id.h
mixer[kColorFeaturePromoBubbleBackground] = {SK_ColorWHITE};
Expand Down Expand Up @@ -353,6 +360,15 @@ void AddBraveDarkThemeColorMixer(ui::ColorProvider* provider,
SkColorSetRGB(0xF0, 0xF2, 0xFF))};
#endif

mixer[kColorWebDiscoveryInfoBarBackground] = {
SkColorSetRGB(0x1A, 0x1C, 0x22)};
mixer[kColorWebDiscoveryInfoBarMessage] = {SkColorSetRGB(0xFF, 0xFF, 0xFF)};
mixer[kColorWebDiscoveryInfoBarLink] = {SkColorSetRGB(0xA6, 0xAB, 0xEC)};
mixer[kColorWebDiscoveryInfoBarNoThanks] = {
SkColorSetARGB(0xBF, 0xEC, 0xEF, 0xF2)};
mixer[kColorWebDiscoveryInfoBarClose] = {
SkColorSetARGB(0xBF, 0x8C, 0x90, 0xA1)};

// Colors for HelpBubble. IDs are defined in
// chrome/browser/ui/color/chrome_color_id.h
mixer[kColorFeaturePromoBubbleBackground] = {SkColorSetRGB(0x12, 0x13, 0x16)};
Expand Down
8 changes: 8 additions & 0 deletions browser/ui/views/infobars/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ source_set("brave_wayback_machine") {
# Remove when https://github.com/brave/brave-browser/issues/10652 is resolved
check_includes = false
sources = [
"brave_infobar_container_view.cc",
"brave_infobar_container_view.h",
"brave_wayback_machine_infobar_button_container.cc",
"brave_wayback_machine_infobar_button_container.h",
"brave_wayback_machine_infobar_contents_view.cc",
Expand All @@ -10,6 +12,12 @@ source_set("brave_wayback_machine") {
"brave_wayback_machine_infobar_throbber.h",
"brave_wayback_machine_infobar_view.cc",
"brave_wayback_machine_infobar_view.h",
"custom_styled_label.cc",
"custom_styled_label.h",
"web_discovery_infobar_content_view.cc",

This comment has been minimized.

Copy link
@bridiver

bridiver Dec 23, 2022

Collaborator

why is this in brave_wayback_machine?

"web_discovery_infobar_content_view.h",
"web_discovery_infobar_view.cc",
"web_discovery_infobar_view.h",
]

deps = [
Expand Down
19 changes: 19 additions & 0 deletions browser/ui/views/infobars/brave_infobar_container_view.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* Copyright (c) 2022 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/views/infobars/brave_infobar_container_view.h"

#include <memory>

BraveInfoBarContainerView::BraveInfoBarContainerView(
infobars::InfoBarContainer::Delegate* delegate)
: InfoBarContainerView(delegate) {
// To hide shadow, replace it with empty view.
DCHECK(content_shadow_);
RemoveChildView(content_shadow_);
content_shadow_ = AddChildView(std::make_unique<views::View>());
}

BraveInfoBarContainerView::~BraveInfoBarContainerView() = default;
21 changes: 21 additions & 0 deletions browser/ui/views/infobars/brave_infobar_container_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright (c) 2022 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "chrome/browser/ui/views/infobars/infobar_container_view.h"

#ifndef BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_INFOBAR_CONTAINER_VIEW_H_
#define BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_INFOBAR_CONTAINER_VIEW_H_

class BraveInfoBarContainerView : public InfoBarContainerView {
public:
explicit BraveInfoBarContainerView(
infobars::InfoBarContainer::Delegate* delegate);
BraveInfoBarContainerView(const BraveInfoBarContainerView&) = delete;
BraveInfoBarContainerView& operator=(const BraveInfoBarContainerView&) =
delete;
~BraveInfoBarContainerView() override;
};

#endif // BRAVE_BROWSER_UI_VIEWS_INFOBARS_BRAVE_INFOBAR_CONTAINER_VIEW_H_
49 changes: 49 additions & 0 deletions browser/ui/views/infobars/custom_styled_label.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* Copyright (c) 2022 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/views/infobars/custom_styled_label.h"

#include <utility>

#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/views/controls/link_fragment.h"

CustomStyledLabel::~CustomStyledLabel() = default;

std::unique_ptr<views::Label> CustomStyledLabel::CreateLabel(
const std::u16string& text,
const RangeStyleInfo& style_info,
const gfx::Range& range,
views::LinkFragment** previous_link_fragment) const {
if (style_info.text_style != views::style::STYLE_LINK)
return StyledLabel::CreateLabel(text, style_info, range,
previous_link_fragment);

std::unique_ptr<views::Label> result;
auto link = std::make_unique<views::LinkFragment>(
text, text_context_, views::style::STYLE_LINK, *previous_link_fragment);
*previous_link_fragment = link.get();
link->SetCallback(style_info.callback);
link->SetFontList(style_info.custom_font.value());
if (!style_info.accessible_name.empty())
link->SetAccessibleName(style_info.accessible_name);

result = std::move(link);

if (style_info.override_color)
result->SetEnabledColor(style_info.override_color.value());
if (!style_info.tooltip.empty())
result->SetTooltipText(style_info.tooltip);
if (!style_info.accessible_name.empty())
result->SetAccessibleName(style_info.accessible_name);
if (displayed_on_background_color_)
result->SetBackgroundColor(displayed_on_background_color_.value());
result->SetAutoColorReadabilityEnabled(auto_color_readability_enabled_);
result->SetSubpixelRenderingEnabled(subpixel_rendering_enabled_);
return result;
}

BEGIN_METADATA(CustomStyledLabel, views::StyledLabel)
END_METADATA
34 changes: 34 additions & 0 deletions browser/ui/views/infobars/custom_styled_label.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* Copyright (c) 2022 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_VIEWS_INFOBARS_CUSTOM_STYLED_LABEL_H_
#define BRAVE_BROWSER_UI_VIEWS_INFOBARS_CUSTOM_STYLED_LABEL_H_

#include <memory>
#include <string>

#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/controls/styled_label.h"

// TODO(simonhong): Move common place if needed.
// StyledLabel doesn't allow using custom font for link style.
// Use for setting custom font for link.
class CustomStyledLabel : public views::StyledLabel {
public:
METADATA_HEADER(CustomStyledLabel);
using StyledLabel::StyledLabel;
CustomStyledLabel(const CustomStyledLabel&) = delete;
CustomStyledLabel& operator=(const CustomStyledLabel&) = delete;
~CustomStyledLabel() override;

private:
std::unique_ptr<views::Label> CreateLabel(
const std::u16string& text,
const RangeStyleInfo& style_info,
const gfx::Range& range,
views::LinkFragment** previous_link_component) const override;
};

#endif // BRAVE_BROWSER_UI_VIEWS_INFOBARS_CUSTOM_STYLED_LABEL_H_
Loading

0 comments on commit 714b52b

Please sign in to comment.