Commit 11285c2b authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

Fix notification inline settings border on aero

We draw our own shadows on Windows if aero glass is enabled. Those
shadows are drawn within the MessageView bounds, reducing the inner
available size by GetInsets(). We need to take that into account when
setting the preferred size of the header view, large image view and,
more importantly, when clipping the ink drop ripple for the inline
settings background.

Screenshots: https://imgur.com/2LLCkGj

Bug: None
Change-Id: I8167da9b6881e1f10384044e2035bcb87847b7e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2396338Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Richard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806936}
parent 2c1b7d65
...@@ -73,8 +73,7 @@ constexpr gfx::Size kActionButtonMinSize(0, 32); ...@@ -73,8 +73,7 @@ constexpr gfx::Size kActionButtonMinSize(0, 32);
// and merge with contradicting |kNotificationIconSize|. // and merge with contradicting |kNotificationIconSize|.
constexpr gfx::Size kIconViewSize(36, 36); constexpr gfx::Size kIconViewSize(36, 36);
constexpr gfx::Insets kLargeImageContainerPadding(0, 16, 16, 16); constexpr gfx::Insets kLargeImageContainerPadding(0, 16, 16, 16);
constexpr gfx::Size kLargeImageMinSize(328, 0); constexpr int kLargeImageMaxHeight = 218;
constexpr gfx::Size kLargeImageMaxSize(328, 218);
constexpr gfx::Insets kLeftContentPadding(2, 4, 0, 4); constexpr gfx::Insets kLeftContentPadding(2, 4, 0, 4);
constexpr gfx::Insets kLeftContentPaddingWithIcon(2, 4, 0, 12); constexpr gfx::Insets kLeftContentPaddingWithIcon(2, 4, 0, 12);
constexpr gfx::Insets kInputTextfieldPadding(16, 16, 16, 0); constexpr gfx::Insets kInputTextfieldPadding(16, 16, 16, 0);
...@@ -265,15 +264,16 @@ void CompactTitleMessageView::set_message(const base::string16& message) { ...@@ -265,15 +264,16 @@ void CompactTitleMessageView::set_message(const base::string16& message) {
// LargeImageView ////////////////////////////////////////////////////////////// // LargeImageView //////////////////////////////////////////////////////////////
LargeImageView::LargeImageView() = default; LargeImageView::LargeImageView(const gfx::Size& max_size)
: max_size_(max_size), min_size_(max_size_.width(), /*height=*/0) {}
LargeImageView::~LargeImageView() = default; LargeImageView::~LargeImageView() = default;
void LargeImageView::SetImage(const gfx::ImageSkia& image) { void LargeImageView::SetImage(const gfx::ImageSkia& image) {
image_ = image; image_ = image;
gfx::Size preferred_size = GetResizedImageSize(); gfx::Size preferred_size = GetResizedImageSize();
preferred_size.SetToMax(kLargeImageMinSize); preferred_size.SetToMax(min_size_);
preferred_size.SetToMin(kLargeImageMaxSize); preferred_size.SetToMin(max_size_);
SetPreferredSize(preferred_size); SetPreferredSize(preferred_size);
SchedulePaint(); SchedulePaint();
Layout(); Layout();
...@@ -284,7 +284,7 @@ void LargeImageView::OnPaint(gfx::Canvas* canvas) { ...@@ -284,7 +284,7 @@ void LargeImageView::OnPaint(gfx::Canvas* canvas) {
gfx::Size resized_size = GetResizedImageSize(); gfx::Size resized_size = GetResizedImageSize();
gfx::Size drawn_size = resized_size; gfx::Size drawn_size = resized_size;
drawn_size.SetToMin(kLargeImageMaxSize); drawn_size.SetToMin(max_size_);
gfx::Rect drawn_bounds = GetContentsBounds(); gfx::Rect drawn_bounds = GetContentsBounds();
drawn_bounds.ClampToCenteredSize(drawn_size); drawn_bounds.ClampToCenteredSize(drawn_size);
...@@ -309,19 +309,18 @@ void LargeImageView::OnThemeChanged() { ...@@ -309,19 +309,18 @@ void LargeImageView::OnThemeChanged() {
} }
// Returns expected size of the image right after resizing. // Returns expected size of the image right after resizing.
// The GetResizedImageSize().width() <= kLargeImageMaxSize.width() holds, but // The GetResizedImageSize().width() <= max_size_.width() holds, but
// GetResizedImageSize().height() may be larger than kLargeImageMaxSize.height() // GetResizedImageSize().height() may be larger than max_size_.height().
// In this case, the overflown part will be just cutted off from the view. // In this case, the overflown part will be just cutted off from the view.
gfx::Size LargeImageView::GetResizedImageSize() { gfx::Size LargeImageView::GetResizedImageSize() {
gfx::Size original_size = image_.size(); gfx::Size original_size = image_.size();
if (original_size.width() <= kLargeImageMaxSize.width()) if (original_size.width() <= max_size_.width())
return image_.size(); return image_.size();
const double proportion = const double proportion =
original_size.height() / static_cast<double>(original_size.width()); original_size.height() / static_cast<double>(original_size.width());
gfx::Size resized_size; gfx::Size resized_size;
resized_size.SetSize(kLargeImageMaxSize.width(), resized_size.SetSize(max_size_.width(), max_size_.width() * proportion);
kLargeImageMaxSize.width() * proportion);
return resized_size; return resized_size;
} }
...@@ -517,7 +516,8 @@ class NotificationInkDropImpl : public views::InkDropImpl { ...@@ -517,7 +516,8 @@ class NotificationInkDropImpl : public views::InkDropImpl {
class NotificationViewMD::NotificationViewMDPathGenerator class NotificationViewMD::NotificationViewMDPathGenerator
: public views::HighlightPathGenerator { : public views::HighlightPathGenerator {
public: public:
NotificationViewMDPathGenerator() = default; explicit NotificationViewMDPathGenerator(gfx::Insets insets)
: insets_(std::move(insets)) {}
NotificationViewMDPathGenerator(const NotificationViewMDPathGenerator&) = NotificationViewMDPathGenerator(const NotificationViewMDPathGenerator&) =
delete; delete;
NotificationViewMDPathGenerator& operator=( NotificationViewMDPathGenerator& operator=(
...@@ -528,6 +528,7 @@ class NotificationViewMD::NotificationViewMDPathGenerator ...@@ -528,6 +528,7 @@ class NotificationViewMD::NotificationViewMDPathGenerator
gfx::RectF bounds = rect; gfx::RectF bounds = rect;
if (!preferred_size_.IsEmpty()) if (!preferred_size_.IsEmpty())
bounds.set_size(gfx::SizeF(preferred_size_)); bounds.set_size(gfx::SizeF(preferred_size_));
bounds.Inset(insets_);
gfx::RoundedCornersF corner_radius(top_radius_, top_radius_, bottom_radius_, gfx::RoundedCornersF corner_radius(top_radius_, top_radius_, bottom_radius_,
bottom_radius_); bottom_radius_);
return gfx::RRectF(bounds, corner_radius); return gfx::RRectF(bounds, corner_radius);
...@@ -540,6 +541,7 @@ class NotificationViewMD::NotificationViewMDPathGenerator ...@@ -540,6 +541,7 @@ class NotificationViewMD::NotificationViewMDPathGenerator
private: private:
int top_radius_ = 0; int top_radius_ = 0;
int bottom_radius_ = 0; int bottom_radius_ = 0;
gfx::Insets insets_;
// This custom PathGenerator is used for the ink drop clipping bounds. By // This custom PathGenerator is used for the ink drop clipping bounds. By
// setting |preferred_size_| we set the correct clip bounds in // setting |preferred_size_| we set the correct clip bounds in
...@@ -581,6 +583,8 @@ NotificationViewMD::NotificationViewMD(const Notification& notification) ...@@ -581,6 +583,8 @@ NotificationViewMD::NotificationViewMD(const Notification& notification)
// |header_row_| contains app_icon, app_name, control buttons, etc... // |header_row_| contains app_icon, app_name, control buttons, etc...
header_row_ = new NotificationHeaderView(this); header_row_ = new NotificationHeaderView(this);
header_row_->SetPreferredSize(header_row_->GetPreferredSize() -
gfx::Size(GetInsets().width(), 0));
control_buttons_view_ = header_row_->AddChildView( control_buttons_view_ = header_row_->AddChildView(
std::make_unique<NotificationControlButtonsView>(this)); std::make_unique<NotificationControlButtonsView>(this));
AddChildView(header_row_); AddChildView(header_row_);
...@@ -639,7 +643,7 @@ NotificationViewMD::NotificationViewMD(const Notification& notification) ...@@ -639,7 +643,7 @@ NotificationViewMD::NotificationViewMD(const Notification& notification)
AddPreTargetHandler(click_activator_.get()); AddPreTargetHandler(click_activator_.get());
auto highlight_path_generator = auto highlight_path_generator =
std::make_unique<NotificationViewMDPathGenerator>(); std::make_unique<NotificationViewMDPathGenerator>(GetInsets());
highlight_path_generator_ = highlight_path_generator.get(); highlight_path_generator_ = highlight_path_generator.get();
views::HighlightPathGenerator::Install(this, views::HighlightPathGenerator::Install(this,
std::move(highlight_path_generator)); std::move(highlight_path_generator));
...@@ -1105,7 +1109,10 @@ void NotificationViewMD::CreateOrUpdateImageView( ...@@ -1105,7 +1109,10 @@ void NotificationViewMD::CreateOrUpdateImageView(
std::make_unique<views::FillLayout>()); std::make_unique<views::FillLayout>());
image_container_view_->SetBorder( image_container_view_->SetBorder(
views::CreateEmptyBorder(kLargeImageContainerPadding)); views::CreateEmptyBorder(kLargeImageContainerPadding));
image_container_view_->AddChildView(new LargeImageView()); int max_width = kNotificationWidth - kLargeImageContainerPadding.width() -
GetInsets().width();
image_container_view_->AddChildView(std::make_unique<LargeImageView>(
gfx::Size(max_width, kLargeImageMaxHeight)));
// Insert the created image container just after the |content_row_|. // Insert the created image container just after the |content_row_|.
AddChildViewAt(image_container_view_, GetIndexOf(content_row_) + 1); AddChildViewAt(image_container_view_, GetIndexOf(content_row_) + 1);
......
...@@ -87,7 +87,7 @@ class CompactTitleMessageView : public views::View { ...@@ -87,7 +87,7 @@ class CompactTitleMessageView : public views::View {
class LargeImageView : public views::View { class LargeImageView : public views::View {
public: public:
LargeImageView(); explicit LargeImageView(const gfx::Size& max_size);
~LargeImageView() override; ~LargeImageView() override;
void SetImage(const gfx::ImageSkia& image); void SetImage(const gfx::ImageSkia& image);
...@@ -99,6 +99,8 @@ class LargeImageView : public views::View { ...@@ -99,6 +99,8 @@ class LargeImageView : public views::View {
private: private:
gfx::Size GetResizedImageSize(); gfx::Size GetResizedImageSize();
gfx::Size max_size_;
gfx::Size min_size_;
gfx::ImageSkia image_; gfx::ImageSkia image_;
DISALLOW_COPY_AND_ASSIGN(LargeImageView); DISALLOW_COPY_AND_ASSIGN(LargeImageView);
...@@ -209,6 +211,7 @@ class MESSAGE_CENTER_EXPORT NotificationViewMD ...@@ -209,6 +211,7 @@ class MESSAGE_CENTER_EXPORT NotificationViewMD
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, AppNameWebNotification); FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, AppNameWebNotification);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, CreateOrUpdateTest); FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, CreateOrUpdateTest);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, ExpandLongMessage); FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, ExpandLongMessage);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, InkDropClipRect);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, InlineSettings); FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, InlineSettings);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest,
InlineSettingsInkDropAnimation); InlineSettingsInkDropAnimation);
......
...@@ -23,7 +23,9 @@ ...@@ -23,7 +23,9 @@
#include "ui/message_center/views/notification_header_view.h" #include "ui/message_center/views/notification_header_view.h"
#include "ui/message_center/views/padded_button.h" #include "ui/message_center/views/padded_button.h"
#include "ui/message_center/views/proportional_image_view.h" #include "ui/message_center/views/proportional_image_view.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_observer.h" #include "ui/views/animation/ink_drop_observer.h"
#include "ui/views/animation/test/ink_drop_impl_test_api.h"
#include "ui/views/controls/button/image_button.h" #include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/label_button.h" #include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/radio_button.h" #include "ui/views/controls/button/radio_button.h"
...@@ -1228,6 +1230,42 @@ TEST_F(NotificationViewMDTest, InlineSettingsInkDropAnimation) { ...@@ -1228,6 +1230,42 @@ TEST_F(NotificationViewMDTest, InlineSettingsInkDropAnimation) {
EXPECT_FALSE(ink_drop_stopped()); EXPECT_FALSE(ink_drop_stopped());
} }
TEST_F(NotificationViewMDTest, PreferredSize) {
std::unique_ptr<Notification> notification = CreateSimpleNotification();
notification->set_type(NotificationType::NOTIFICATION_TYPE_IMAGE);
UpdateNotificationViews(*notification);
// Collapsed preferred width is determined by the header view.
notification_view()->SetExpanded(false);
EXPECT_EQ(kNotificationWidth,
notification_view()->GetPreferredSize().width());
// Ensure expanded preferred width is not extended by the image view.
notification_view()->SetExpanded(true);
EXPECT_EQ(kNotificationWidth,
notification_view()->GetPreferredSize().width());
}
TEST_F(NotificationViewMDTest, InkDropClipRect) {
std::unique_ptr<Notification> notification = CreateSimpleNotification();
notification->set_type(NotificationType::NOTIFICATION_TYPE_IMAGE);
UpdateNotificationViews(*notification);
// Toggle inline settings to show ink drop background.
notification_view()->ToggleInlineSettings(DummyEvent());
auto* ink_drop =
static_cast<views::InkDropImpl*>(notification_view()->GetInkDrop());
views::test::InkDropImplTestApi ink_drop_test_api(ink_drop);
gfx::Rect clip_rect = ink_drop_test_api.GetRootLayer()->clip_rect();
// Expect clip rect to honor the insets to draw the shadow.
gfx::Insets insets = notification_view()->GetInsets();
EXPECT_EQ(notification_view()->GetPreferredSize() - insets.size(),
clip_rect.size());
EXPECT_EQ(gfx::Point(insets.left(), insets.top()), clip_rect.origin());
}
TEST_F(NotificationViewMDTest, TestClick) { TEST_F(NotificationViewMDTest, TestClick) {
std::unique_ptr<Notification> notification = CreateSimpleNotification(); std::unique_ptr<Notification> notification = CreateSimpleNotification();
delegate_->set_expecting_click(true); delegate_->set_expecting_click(true);
......
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