diff --git a/ui/brave_custom_notification/BUILD.gn b/ui/brave_custom_notification/BUILD.gn index af6f2d44e77f..457c5e1274e9 100644 --- a/ui/brave_custom_notification/BUILD.gn +++ b/ui/brave_custom_notification/BUILD.gn @@ -58,8 +58,6 @@ source_set("brave_custom_notification") { "notification_view_factory.h", "padded_button.cc", "padded_button.h", - "proportional_image_view.cc", - "proportional_image_view.h", ] deps += [ "//ui/compositor", diff --git a/ui/brave_custom_notification/ad_notification_view_md.cc b/ui/brave_custom_notification/ad_notification_view_md.cc index 3046f5b42dd9..45150063b49b 100644 --- a/ui/brave_custom_notification/ad_notification_view_md.cc +++ b/ui/brave_custom_notification/ad_notification_view_md.cc @@ -22,7 +22,6 @@ #include "brave/ui/brave_custom_notification/notification_control_buttons_view.h" #include "brave/ui/brave_custom_notification/notification_header_view.h" #include "brave/ui/brave_custom_notification/padded_button.h" -#include "brave/ui/brave_custom_notification/proportional_image_view.h" #include "brave/ui/brave_custom_notification/public/cpp/constants.h" #include "brave/ui/brave_custom_notification/public/cpp/notification.h" #include "build/build_config.h" @@ -71,14 +70,9 @@ namespace { // Dimensions. constexpr gfx::Insets kContentRowPadding(0, 12, 16, 12); constexpr gfx::Size kIconViewSize(36, 36); -constexpr gfx::Insets kLargeImageContainerPadding(0, 16, 16, 16); -constexpr gfx::Size kLargeImageMinSize(328, 0); -constexpr gfx::Size kLargeImageMaxSize(328, 218); constexpr gfx::Insets kLeftContentPadding(2, 4, 0, 4); constexpr gfx::Insets kLeftContentPaddingWithIcon(2, 4, 0, 12); -// Background color of the large image. -constexpr SkColor kLargeImageBackgroundColor = SkColorSetRGB(0xf5, 0xf5, 0xf5); // Background color of the inline settings. constexpr SkColor kInlineSettingsBackgroundColor = SkColorSetRGB(0xEE, 0xEE, 0xEE); @@ -147,65 +141,6 @@ class ClickActivator : public ui::EventHandler { } // anonymous namespace -// LargeImageView ////////////////////////////////////////////////////////////// - -LargeImageView::LargeImageView() { - SetBackground(views::CreateSolidBackground(kLargeImageBackgroundColor)); -} - -LargeImageView::~LargeImageView() = default; - -void LargeImageView::SetImage(const gfx::ImageSkia& image) { - image_ = image; - gfx::Size preferred_size = GetResizedImageSize(); - preferred_size.SetToMax(kLargeImageMinSize); - preferred_size.SetToMin(kLargeImageMaxSize); - SetPreferredSize(preferred_size); - SchedulePaint(); - Layout(); -} - -void LargeImageView::OnPaint(gfx::Canvas* canvas) { - views::View::OnPaint(canvas); - - gfx::Size resized_size = GetResizedImageSize(); - gfx::Size drawn_size = resized_size; - drawn_size.SetToMin(kLargeImageMaxSize); - gfx::Rect drawn_bounds = GetContentsBounds(); - drawn_bounds.ClampToCenteredSize(drawn_size); - - gfx::ImageSkia resized_image = gfx::ImageSkiaOperations::CreateResizedImage( - image_, skia::ImageOperations::RESIZE_BEST, resized_size); - - // Cut off the overflown part. - gfx::ImageSkia drawn_image = gfx::ImageSkiaOperations::ExtractSubset( - resized_image, gfx::Rect(drawn_size)); - - canvas->DrawImageInt(drawn_image, drawn_bounds.x(), drawn_bounds.y()); -} - -const char* LargeImageView::GetClassName() const { - return "LargeImageView"; -} - -// Returns expected size of the image right after resizing. -// The GetResizedImageSize().width() <= kLargeImageMaxSize.width() holds, but -// GetResizedImageSize().height() may be larger than kLargeImageMaxSize.height() -// In this case, the overflown part will be just cutted off from the view. -gfx::Size LargeImageView::GetResizedImageSize() { - return kLargeImageMaxSize; - gfx::Size original_size = image_.size(); - if (original_size.width() <= kLargeImageMaxSize.width()) - return image_.size(); - - const double proportion = - original_size.height() / static_cast(original_size.width()); - gfx::Size resized_size; - resized_size.SetSize(kLargeImageMaxSize.width(), - kLargeImageMaxSize.width() * proportion); - return resized_size; -} - // NotificationInkDropImpl ///////////////////////////////////////////////////// class NotificationInkDropImpl : public views::InkDropImpl { @@ -267,7 +202,6 @@ void AdNotificationViewMD::CreateOrUpdateViews(const Notification& notification) CreateOrUpdateTitleView(notification); CreateOrUpdateNotificationView(notification); CreateOrUpdateSmallIconView(notification); - CreateOrUpdateImageView(notification); UpdateViewForExpandedState(expanded_); } @@ -494,7 +428,6 @@ void AdNotificationViewMD::CreateOrUpdateContextTitleView( header_row_->SetAccentColor(SK_ColorTRANSPARENT); header_row_->SetBackgroundColor(kNotificationBackgroundColor); header_row_->SetAppNameElideBehavior(gfx::ELIDE_TAIL); - header_row_->SetSummaryText(base::string16()); base::string16 app_name; if (notification.UseOriginAsContextMessage()) { @@ -582,41 +515,6 @@ void AdNotificationViewMD::CreateOrUpdateSmallIconView( } } -void AdNotificationViewMD::CreateOrUpdateImageView( - const Notification& notification) { - if (notification.image().IsEmpty()) { - if (image_container_view_) { - DCHECK(Contains(image_container_view_)); - delete image_container_view_; - image_container_view_ = nullptr; - } - return; - } - - if (!image_container_view_) { - image_container_view_ = new views::View(); - - gfx::Size preferred_size = kLargeImageMaxSize; - SetPreferredSize(preferred_size); - - - image_container_view_->SetLayoutManager( - std::make_unique()); - image_container_view_->SetBorder( - views::CreateEmptyBorder(kLargeImageContainerPadding)); - image_container_view_->SetBackground( - views::CreateSolidBackground(kImageBackgroundColor)); - image_container_view_->AddChildView(new LargeImageView()); - - // Insert the created image container just after the |content_row_|. - image_container_view_->SetSize(kLargeImageMaxSize); - AddChildViewAt(image_container_view_, GetIndexOf(content_row_) + 1); - } - - static_cast(image_container_view_->children().front()) - ->SetImage(notification.image().AsImageSkia()); -} - bool AdNotificationViewMD::IsExpandable() { return false; } @@ -626,10 +524,6 @@ void AdNotificationViewMD::UpdateViewForExpandedState(bool expanded) { message_view_->SetMaxLines(expanded ? kMaxLinesForExpandedNotificationView : kMaxLinesForNotificationView); } - if (image_container_view_) { - image_container_view_->SetSize(kLargeImageMaxSize); - image_container_view_->SetVisible(expanded); - } for (size_t i = kMaxLinesForNotificationView; i < item_views_.size(); ++i) { item_views_[i]->SetVisible(expanded); @@ -640,8 +534,6 @@ void AdNotificationViewMD::UpdateViewForExpandedState(bool expanded) { int max_items = expanded ? item_views_.size() : kMaxLinesForNotificationView; if (list_items_count_ > max_items) header_row_->SetOverflowIndicator(list_items_count_ - max_items); - else if (!item_views_.empty()) - header_row_->SetSummaryText(base::string16()); right_content_->SetVisible(true); left_content_->SetBorder(views::CreateEmptyBorder(kLeftContentPadding)); diff --git a/ui/brave_custom_notification/ad_notification_view_md.h b/ui/brave_custom_notification/ad_notification_view_md.h index ed3a1802e267..2c5503e7b47b 100644 --- a/ui/brave_custom_notification/ad_notification_view_md.h +++ b/ui/brave_custom_notification/ad_notification_view_md.h @@ -31,25 +31,6 @@ class Textfield; namespace brave_custom_notification { class NotificationHeaderView; -class ProportionalImageView; - -class LargeImageView : public views::View { - public: - LargeImageView(); - ~LargeImageView() override; - - void SetImage(const gfx::ImageSkia& image); - - void OnPaint(gfx::Canvas* canvas) override; - const char* GetClassName() const override; - - private: - gfx::Size GetResizedImageSize(); - - gfx::ImageSkia image_; - - DISALLOW_COPY_AND_ASSIGN(LargeImageView); -}; // View that displays all current types of notification (web, basic, image, and // list) except the custom notification. Future notification types may be diff --git a/ui/brave_custom_notification/message_popup_view.cc b/ui/brave_custom_notification/message_popup_view.cc index cf023b8af8c4..b56829c00ed8 100644 --- a/ui/brave_custom_notification/message_popup_view.cc +++ b/ui/brave_custom_notification/message_popup_view.cc @@ -27,6 +27,12 @@ namespace brave_custom_notification { namespace { static std::map g_notifications_; +static const int kPopupX = 30; +static const int kPopupY = 30; +static const int kPopupBaseWidth = 300; +static const int kPopupBaseHeight = 100; +static const int kBodyPixelLineHeight = 10; +static const int kBodyCharactersPerLine = 40; } // static @@ -57,7 +63,7 @@ MessagePopupView::MessagePopupView(const Notification& notification) : views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; params.z_order = ui::ZOrderLevel::kFloatingWindow; - params.bounds = { 30, 30, 300, 100 + GetBodyHeight(notification.message())}; + params.bounds = { kPopupX, kPopupY, kPopupBaseWidth, kPopupBaseHeight + GetBodyHeight(notification.message())}; #if defined(OS_LINUX) && !defined(OS_CHROMEOS) // Make the widget explicitly activatable as TYPE_POPUP is not activatable by // default but we need focus for the inline reply textarea. @@ -85,7 +91,6 @@ MessagePopupView::MessagePopupView(const Notification& notification) : NotificationView* message_view_ = NotificationViewFactory::Create(notification); popup_window_->SetContentsView(message_view_); set_notify_enter_exit_on_child(true); - // g_message_popup_view = this; } MessagePopupView::~MessagePopupView() {} @@ -143,7 +148,7 @@ bool MessagePopupView::IsWidgetValid() const { } int MessagePopupView::GetBodyHeight(const base::string16& message) { - return (10 * (message.size() / 40)) + 10; + return (kBodyPixelLineHeight * (message.size() / kBodyCharactersPerLine)); } } // namespace brave_custom_notification diff --git a/ui/brave_custom_notification/notification_header_view.cc b/ui/brave_custom_notification/notification_header_view.cc index 3ffa129d2a49..333249ef47ab 100644 --- a/ui/brave_custom_notification/notification_header_view.cc +++ b/ui/brave_custom_notification/notification_header_view.cc @@ -234,11 +234,6 @@ void NotificationHeaderView::SetAppNameElideBehavior( app_name_view_->SetElideBehavior(elide_behavior); } -void NotificationHeaderView::SetSummaryText(const base::string16& text) { - summary_text_view_->SetText(text); - UpdateSummaryTextVisibility(); -} - void NotificationHeaderView::SetOverflowIndicator(int count) { summary_text_view_->SetText(l10n_util::GetStringFUTF16Int( IDS_MESSAGE_CENTER_LIST_NOTIFICATION_HEADER_OVERFLOW_INDICATOR, count)); diff --git a/ui/brave_custom_notification/notification_header_view.h b/ui/brave_custom_notification/notification_header_view.h index a8828ef14177..c19748849973 100644 --- a/ui/brave_custom_notification/notification_header_view.h +++ b/ui/brave_custom_notification/notification_header_view.h @@ -27,10 +27,6 @@ class NotificationHeaderView : public views::Button { void SetAppIcon(const gfx::ImageSkia& img); void SetAppName(const base::string16& name); void SetAppNameElideBehavior(gfx::ElideBehavior elide_behavior); - - // Summary and overflow indicator are all the same UI element so are - // mutually exclusive. - void SetSummaryText(const base::string16& text); void SetOverflowIndicator(int count); // Set the unified theme color used among the app icon, app name, and expand diff --git a/ui/brave_custom_notification/notification_view.cc b/ui/brave_custom_notification/notification_view.cc index d248bd7f1b26..b13f30d6eade 100644 --- a/ui/brave_custom_notification/notification_view.cc +++ b/ui/brave_custom_notification/notification_view.cc @@ -39,6 +39,9 @@ namespace brave_custom_notification { namespace { +static const int kWindowsShadowElevation = 2; +static const int kWindowsShadowRadius = 0; + bool ShouldShowAeroShadowBorder() { #if defined(OS_WIN) return ui::win::IsAeroGlassEnabled(); @@ -77,7 +80,7 @@ NotificationView::NotificationView(const Notification& notification) : notificat // If Aero is enabled, set shadow border. if (ShouldShowAeroShadowBorder()) { - const auto& shadow = gfx::ShadowDetails::Get(2, 0); + const auto& shadow = gfx::ShadowDetails::Get(kWindowsShadowElevation, kWindowsShadowRadius); gfx::Insets ninebox_insets = gfx::ShadowValue::GetBlurRegion(shadow.values); SetBorder(views::CreateBorderPainter( views::Painter::CreateImagePainter(shadow.ninebox_image, diff --git a/ui/brave_custom_notification/proportional_image_view.cc b/ui/brave_custom_notification/proportional_image_view.cc deleted file mode 100644 index 4bf5b29ac055..000000000000 --- a/ui/brave_custom_notification/proportional_image_view.cc +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright (c) 2020 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/ui/brave_custom_notification/proportional_image_view.h" - -#include "ui/gfx/canvas.h" -#include "ui/gfx/image/image_skia_operations.h" - -namespace brave_custom_notification { - -const char ProportionalImageView::kViewClassName[] = "ProportionalImageView"; - -ProportionalImageView::ProportionalImageView(const gfx::Size& view_size) { - SetPreferredSize(view_size); -} - -ProportionalImageView::~ProportionalImageView() {} - -void ProportionalImageView::SetImage(const gfx::ImageSkia& image, - const gfx::Size& max_image_size) { - image_ = image; - max_image_size_ = max_image_size; - SchedulePaint(); -} - -void ProportionalImageView::OnPaint(gfx::Canvas* canvas) { - views::View::OnPaint(canvas); - - gfx::Size draw_size = GetImageDrawingSize(); - if (draw_size.IsEmpty()) - return; - - gfx::Rect draw_bounds = GetContentsBounds(); - draw_bounds.ClampToCenteredSize(draw_size); - - gfx::ImageSkia image = - (image_.size() == draw_size) - ? image_ - : gfx::ImageSkiaOperations::CreateResizedImage( - image_, skia::ImageOperations::RESIZE_BEST, draw_size); - canvas->DrawImageInt(image, draw_bounds.x(), draw_bounds.y()); -} - -const char* ProportionalImageView::GetClassName() const { - return kViewClassName; -} - -gfx::Size ProportionalImageView::GetImageSizeForContainerSize(const gfx::Size& container_size, - const gfx::Size& image_size) { - if (container_size.IsEmpty() || image_size.IsEmpty()) - return gfx::Size(); - - gfx::Size scaled_size = image_size; - double proportion = - scaled_size.height() / static_cast(scaled_size.width()); - // We never want to return an empty image given a non-empty container and - // image, so round the height to 1. - scaled_size.SetSize(container_size.width(), - std::max(0.5 + container_size.width() * proportion, 1.0)); - if (scaled_size.height() > container_size.height()) { - scaled_size.SetSize( - std::max(0.5 + container_size.height() / proportion, 1.0), - container_size.height()); - } - - return scaled_size; -} - -gfx::Size ProportionalImageView::GetImageDrawingSize() { - if (!GetVisible()) - return gfx::Size(); - - gfx::Size max_size = max_image_size_; - max_size.SetToMin(GetContentsBounds().size()); - return GetImageSizeForContainerSize(max_size, image_.size()); -} - -} // namespace brave_custom_notification diff --git a/ui/brave_custom_notification/proportional_image_view.h b/ui/brave_custom_notification/proportional_image_view.h deleted file mode 100644 index e1a30628b1d5..000000000000 --- a/ui/brave_custom_notification/proportional_image_view.h +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright (c) 2020 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_UI_BRAVE_CUSTOM_NOTIFICATION_VIEWS_PROPORTIONAL_IMAGE_VIEW_H_ -#define BRAVE_UI_BRAVE_CUSTOM_NOTIFICATION_VIEWS_PROPORTIONAL_IMAGE_VIEW_H_ - -#include "base/macros.h" -#include "ui/gfx/image/image_skia.h" -#include "ui/views/view.h" - -namespace brave_custom_notification { - -// ProportionalImageViews scale and center their images while preserving their -// original proportions. -class ProportionalImageView : public views::View { - public: - // Internal class name. - static const char kViewClassName[]; - - explicit ProportionalImageView(const gfx::Size& view_size); - ~ProportionalImageView() override; - - // |image| is scaled to fit within |view_size| and |max_image_size| while - // maintaining its original aspect ratio. It is then centered within the view. - void SetImage(const gfx::ImageSkia& image, - const gfx::Size& max_image_size); - - const gfx::ImageSkia& image() const { return image_; } - - // Overridden from views::View: - void OnPaint(gfx::Canvas* canvas) override; - const char* GetClassName() const override; - - private: - gfx::Size GetImageSizeForContainerSize(const gfx::Size& container_size, - const gfx::Size& image_size); - gfx::Size GetImageDrawingSize(); - - gfx::ImageSkia image_; - gfx::Size max_image_size_; - - DISALLOW_COPY_AND_ASSIGN(ProportionalImageView); -}; - -} - -#endif