diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-11-18 16:35:47 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-11-18 15:45:54 +0000 |
commit | 32f5a1c56531e4210bc4cf8d8c7825d66e081888 (patch) | |
tree | eeeec6822f4d738d8454525233fd0e2e3a659e6d /chromium/components/media_message_center/media_notification_background_ash_impl.cc | |
parent | 99677208ff3b216fdfec551fbe548da5520cd6fb (diff) | |
download | qtwebengine-chromium-32f5a1c56531e4210bc4cf8d8c7825d66e081888.tar.gz |
BASELINE: Update Chromium to 87.0.4280.67
Change-Id: Ib157360be8c2ffb2c73125751a89f60e049c1d54
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/components/media_message_center/media_notification_background_ash_impl.cc')
-rw-r--r-- | chromium/components/media_message_center/media_notification_background_ash_impl.cc | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/chromium/components/media_message_center/media_notification_background_ash_impl.cc b/chromium/components/media_message_center/media_notification_background_ash_impl.cc new file mode 100644 index 00000000000..091d78fe26c --- /dev/null +++ b/chromium/components/media_message_center/media_notification_background_ash_impl.cc @@ -0,0 +1,99 @@ +// 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 "components/media_message_center/media_notification_background_ash_impl.h" + +#include "ui/gfx/canvas.h" +#include "ui/gfx/image/image_skia_operations.h" +#include "ui/gfx/skia_util.h" +#include "ui/views/view.h" + +namespace media_message_center { + +namespace { + +constexpr SkColor kBackgroundColor = SK_ColorTRANSPARENT; +constexpr SkColor kForegroundColor = SK_ColorWHITE; + +constexpr gfx::Size kArtworkSize(80, 80); +constexpr int kArtworkBottomMargin = 16; +constexpr int kArtworkRightMargin = 16; +constexpr int kArtworkCornerRadius = 4; + +gfx::Size ScaleToFitSize(const gfx::Size& image_size) { + if ((image_size.width() > kArtworkSize.width() || + image_size.height() > kArtworkSize.height()) || + (image_size.width() < kArtworkSize.width() && + image_size.height() < kArtworkSize.height())) { + const float scale = std::min( + kArtworkSize.width() / static_cast<float>(image_size.width()), + kArtworkSize.height() / static_cast<float>(image_size.height())); + return gfx::ScaleToFlooredSize(image_size, scale); + } + + return image_size; +} + +} // namespace + +gfx::Rect MediaNotificationBackgroundAshImpl::GetArtworkBounds( + const gfx::Rect& view_bounds) const { + gfx::Size target_size = ScaleToFitSize(artwork_.size()); + + int vertical_offset = (kArtworkSize.height() - target_size.height()) / 2; + int horizontal_offset = (kArtworkSize.width() - target_size.width()) / 2; + + return gfx::Rect(view_bounds.right() - kArtworkRightMargin - + kArtworkSize.width() + horizontal_offset, + view_bounds.bottom() - kArtworkBottomMargin - + kArtworkSize.height() + vertical_offset, + target_size.width(), target_size.height()); +} + +void MediaNotificationBackgroundAshImpl::Paint(gfx::Canvas* canvas, + views::View* view) const { + gfx::Rect source_bounds(0, 0, artwork_.width(), artwork_.height()); + gfx::Rect target_bounds = GetArtworkBounds(view->GetContentsBounds()); + + SkPath path; + path.addRoundRect(gfx::RectToSkRect(target_bounds), kArtworkCornerRadius, + kArtworkCornerRadius); + + canvas->ClipPath(path, true); + + canvas->DrawImageInt( + artwork_, source_bounds.x(), source_bounds.y(), source_bounds.width(), + source_bounds.height(), target_bounds.x(), target_bounds.y(), + target_bounds.width(), target_bounds.height(), false /* filter */); +} + +void MediaNotificationBackgroundAshImpl::UpdateArtwork( + const gfx::ImageSkia& image) { + if (artwork_.BackedBySameObjectAs(image)) + return; + + artwork_ = image; +} + +bool MediaNotificationBackgroundAshImpl::UpdateCornerRadius(int top_radius, + int bottom_radius) { + return false; +} + +bool MediaNotificationBackgroundAshImpl::UpdateArtworkMaxWidthPct( + double max_width_pct) { + return false; +} + +SkColor MediaNotificationBackgroundAshImpl::GetBackgroundColor( + const views::View& owner) const { + return kBackgroundColor; +} + +SkColor MediaNotificationBackgroundAshImpl::GetForegroundColor( + const views::View& owner) const { + return kForegroundColor; +} + +} // namespace media_message_center |