-
Notifications
You must be signed in to change notification settings - Fork 922
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added search promotion button in omnibox
- Loading branch information
Showing
19 changed files
with
319 additions
and
5 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
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
Binary file added
BIN
+793 Bytes
.../default_100_percent/brave/brave_search_conversion_button_brave_search_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+834 Bytes
app/theme/default_100_percent/brave/brave_search_conversion_button_ddg_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.72 KB
.../default_200_percent/brave/brave_search_conversion_button_brave_search_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.78 KB
app/theme/default_200_percent/brave/brave_search_conversion_button_ddg_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
159 changes: 159 additions & 0 deletions
159
browser/ui/views/location_bar/brave_search_conversion_promotion_button_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,159 @@ | ||
/* Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. */ | ||
|
||
#include "brave/browser/ui/views/location_bar/brave_search_conversion_promotion_button_view.h" | ||
|
||
#include "brave/browser/ui/color/brave_color_id.h" | ||
#include "brave/components/vector_icons/vector_icons.h" | ||
#include "brave/grit/brave_generated_resources.h" | ||
#include "brave/grit/brave_theme_resources.h" | ||
#include "chrome/browser/ui/layout_constants.h" | ||
#include "ui/base/l10n/l10n_util.h" | ||
#include "ui/base/metadata/metadata_impl_macros.h" | ||
#include "ui/base/models/image_model.h" | ||
#include "ui/base/resource/resource_bundle.h" | ||
#include "ui/gfx/font_list.h" | ||
#include "ui/views/background.h" | ||
#include "ui/views/controls/button/image_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/painter.h" | ||
|
||
using views::BoxLayout; | ||
|
||
BraveSearchConversionPromotionButtonView:: | ||
BraveSearchConversionPromotionButtonView() { | ||
// Hovering on close button should not make this as normal state. | ||
SetNotifyEnterExitOnChild(true); | ||
SetLayoutManager( | ||
std::make_unique<BoxLayout>(BoxLayout::Orientation::kHorizontal, | ||
gfx::Insets::VH(0, 6), | ||
/*between_child_spacing*/ 4)) | ||
->set_cross_axis_alignment(BoxLayout::CrossAxisAlignment::kCenter); | ||
SetTooltipText( | ||
l10n_util::GetStringUTF16(IDS_BRAVE_SEARCH_CONVERSION_BUTTON_TOOLTIP)); | ||
AddChildViews(); | ||
Update(); | ||
} | ||
|
||
BraveSearchConversionPromotionButtonView:: | ||
~BraveSearchConversionPromotionButtonView() = default; | ||
|
||
void BraveSearchConversionPromotionButtonView::StateChanged( | ||
views::Button::ButtonState old_state) { | ||
Update(); | ||
} | ||
|
||
void BraveSearchConversionPromotionButtonView::OnThemeChanged() { | ||
Button::OnThemeChanged(); | ||
SetupShadow(); | ||
Update(); | ||
} | ||
|
||
float BraveSearchConversionPromotionButtonView::GetCornerRadius() const { | ||
return GetLayoutConstant(LOCATION_BAR_CHILD_CORNER_RADIUS); | ||
} | ||
|
||
void BraveSearchConversionPromotionButtonView::UpdateBackgroundAndBorders() { | ||
auto* cp = GetColorProvider(); | ||
if (!cp) { | ||
return; | ||
} | ||
|
||
const auto bg_color = | ||
cp->GetColor(GetState() == views::Button::STATE_NORMAL | ||
? kColorSearchConversionButtonBackground | ||
: kColorSearchConversionButtonBackgroundHovered); | ||
const auto stroke_color = cp->GetColor(kColorSearchConversionButtonBorder); | ||
SetBackground(views::CreateBackgroundFromPainter( | ||
views::Painter::CreateRoundRectWith1PxBorderPainter( | ||
bg_color, stroke_color, GetCornerRadius(), SkBlendMode::kSrcOver, | ||
true /* antialias */, true /* should_border_scale */))); | ||
} | ||
|
||
void BraveSearchConversionPromotionButtonView::AddChildViews() { | ||
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | ||
AddChildView(std::make_unique<views::ImageView>()) | ||
->SetImage( | ||
*rb.GetImageSkiaNamed(IDR_BRAVE_SEARCH_CONVERSION_BUTTON_DDG_ICON)); | ||
|
||
AddChildView( | ||
std::make_unique<views::ImageView>(ui::ImageModel::FromVectorIcon( | ||
kLeoCaratLastIcon, kColorSearchConversionButtonCaratRight, 14))); | ||
AddChildView(std::make_unique<views::ImageView>( | ||
ui::ImageModel::FromImageSkia(*rb.GetImageSkiaNamed( | ||
IDR_BRAVE_SEARCH_CONVERSION_BUTTON_BRAVE_SEARCH_ICON)))); | ||
|
||
auto title_font_list = | ||
views::Label::GetDefaultFontList() | ||
.DeriveWithWeight(gfx::Font::Weight::SEMIBOLD) | ||
.DeriveWithStyle(gfx::Font::NORMAL) | ||
.DeriveWithHeightUpperBound(18) | ||
.DeriveWithSizeDelta( | ||
12 - views::Label::GetDefaultFontList().GetFontSize()); | ||
views::Label::CustomFont custom_font{title_font_list}; | ||
auto* button_label = AddChildView(std::make_unique<views::Label>( | ||
l10n_util::GetStringUTF16(IDS_BRAVE_SEARCH_CONVERSION_BUTTON_LABEL), | ||
custom_font)); | ||
button_label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT); | ||
button_label->SetVerticalAlignment(gfx::VerticalAlignment::ALIGN_MIDDLE); | ||
button_label->SetEnabledColorId(kColorSearchConversionButtonText); | ||
button_label->SetBackgroundColor(SK_ColorTRANSPARENT); | ||
|
||
auto set_image = [](views::ImageButton* close_button, | ||
views::Button::ButtonState state, int color_id) { | ||
close_button->SetImageModel(state, ui::ImageModel::FromVectorIcon( | ||
kLeoCloseCircleIcon, color_id, 16)); | ||
}; | ||
auto* close_button = AddChildView(std::make_unique<views::ImageButton>()); | ||
set_image(close_button, views::Button::STATE_NORMAL, | ||
kColorSearchConversionButtonCloseButton); | ||
set_image(close_button, views::Button::STATE_HOVERED, | ||
kColorSearchConversionButtonCloseButtonHovered); | ||
close_button->SetTooltipText(l10n_util::GetStringUTF16( | ||
IDS_BRAVE_SEARCH_CONVERSION_CLOSE_BUTTON_TOOLTIP)); | ||
} | ||
|
||
void BraveSearchConversionPromotionButtonView::Update() { | ||
UpdateBackgroundAndBorders(); | ||
UpdateShadow(); | ||
} | ||
|
||
void BraveSearchConversionPromotionButtonView::SetupShadow() { | ||
auto* cp = GetColorProvider(); | ||
if (!cp) { | ||
return; | ||
} | ||
|
||
ViewShadow::ShadowParameters shadow_config1{ | ||
.offset_x = 0, | ||
.offset_y = 1, | ||
.blur_radius = 0, | ||
.shadow_color = cp->GetColor(kColorSearchConversionButtonShadow1)}; | ||
|
||
const int radius = GetCornerRadius(); | ||
ViewShadow::ShadowParameters shadow_config2{ | ||
.offset_x = 0, | ||
.offset_y = 1, | ||
.blur_radius = radius, | ||
.shadow_color = cp->GetColor(kColorSearchConversionButtonShadow2)}; | ||
|
||
shadow1_ = std::make_unique<ViewShadow>(this, radius, shadow_config1); | ||
shadow2_ = std::make_unique<ViewShadow>(this, radius, shadow_config2); | ||
} | ||
|
||
void BraveSearchConversionPromotionButtonView::UpdateShadow() { | ||
if (!shadow1_ || !shadow2_) { | ||
return; | ||
} | ||
|
||
const bool is_hovered = GetState() == views::Button::STATE_HOVERED; | ||
shadow1_->SetVisible(is_hovered); | ||
shadow2_->SetVisible(is_hovered); | ||
} | ||
|
||
BEGIN_METADATA(BraveSearchConversionPromotionButtonView) | ||
END_METADATA |
42 changes: 42 additions & 0 deletions
42
browser/ui/views/location_bar/brave_search_conversion_promotion_button_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,42 @@ | ||
/* Copyright (c) 2024 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 https://mozilla.org/MPL/2.0/. */ | ||
|
||
#ifndef BRAVE_BROWSER_UI_VIEWS_LOCATION_BAR_BRAVE_SEARCH_CONVERSION_PROMOTION_BUTTON_VIEW_H_ | ||
#define BRAVE_BROWSER_UI_VIEWS_LOCATION_BAR_BRAVE_SEARCH_CONVERSION_PROMOTION_BUTTON_VIEW_H_ | ||
|
||
#include <memory> | ||
|
||
#include "base/memory/raw_ptr.h" | ||
#include "brave/browser/ui/views/view_shadow.h" | ||
#include "ui/base/metadata/metadata_header_macros.h" | ||
#include "ui/views/controls/button/button.h" | ||
|
||
class ViewShadow; | ||
|
||
class BraveSearchConversionPromotionButtonView : public views::Button { | ||
METADATA_HEADER(BraveSearchConversionPromotionButtonView, views::Button) | ||
|
||
public: | ||
BraveSearchConversionPromotionButtonView(); | ||
~BraveSearchConversionPromotionButtonView() override; | ||
|
||
private: | ||
// views::Button overrides: | ||
void StateChanged(views::Button::ButtonState old_state) override; | ||
void OnThemeChanged() override; | ||
|
||
void Update(); | ||
|
||
float GetCornerRadius() const; | ||
void UpdateBackgroundAndBorders(); | ||
void AddChildViews(); | ||
void SetupShadow(); | ||
void UpdateShadow(); | ||
|
||
std::unique_ptr<ViewShadow> shadow1_; | ||
std::unique_ptr<ViewShadow> shadow2_; | ||
}; | ||
|
||
#endif // BRAVE_BROWSER_UI_VIEWS_LOCATION_BAR_BRAVE_SEARCH_CONVERSION_PROMOTION_BUTTON_VIEW_H_ |
Oops, something went wrong.