Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7244)

Unified Diff: chrome/browser/ui/views/infobars/infobar_view.cc

Issue 1700383002: [MD] Fix clipping of infobar child elements (particularly close button). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adjust comment Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/infobars/infobar_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/infobars/infobar_view.cc
diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc
index 8f4c01a6d3450d14fc973bb55f71d91c05c2af0e..340996301a7bf3313dfe4614b8063065b5a648c6 100644
--- a/chrome/browser/ui/views/infobars/infobar_view.cc
+++ b/chrome/browser/ui/views/infobars/infobar_view.cc
@@ -79,12 +79,24 @@ const int InfoBarView::kEndOfLabelSpacing = views::kItemLabelSpacing;
InfoBarView::InfoBarView(scoped_ptr<infobars::InfoBarDelegate> delegate)
: infobars::InfoBar(std::move(delegate)),
- views::ExternalFocusTracker(this, NULL),
- icon_(NULL),
- close_button_(NULL) {
+ views::ExternalFocusTracker(this, nullptr),
+ child_container_(new views::View()),
+ icon_(nullptr),
+ close_button_(nullptr) {
set_owned_by_client(); // InfoBar deletes itself at the appropriate time.
set_background(
new InfoBarBackground(infobars::InfoBar::delegate()->GetInfoBarType()));
+
+ AddChildView(child_container_);
+
+ if (ui::MaterialDesignController::IsModeMaterial()) {
+ child_container_->SetPaintToLayer(true);
+ child_container_->layer()->SetMasksToBounds(true);
+ // Since MD doesn't use a gradient, we can set a solid bg color.
+ child_container_->set_background(
+ views::Background::CreateSolidBackground(infobars::InfoBar::GetTopColor(
+ infobars::InfoBar::delegate()->GetInfoBarType())));
+ }
}
InfoBarView::~InfoBarView() {
@@ -208,6 +220,12 @@ void InfoBarView::Layout() {
height() - InfoBarContainerDelegate::kSeparatorLineHeight));
}
+ child_container_->SetBounds(0, arrow_height(), width(), bar_height());
+ // |child_container_| should be the only child.
+ DCHECK_EQ(1, child_count());
+
+ // Even though other views are technically grandchildren, we'll lay them out
+ // here on behalf of |child_container_|.
int start_x = kEdgeItemPadding;
if (icon_ != NULL) {
icon_->SetPosition(gfx::Point(start_x, OffsetY(icon_)));
@@ -233,7 +251,7 @@ void InfoBarView::ViewHierarchyChanged(
icon_ = new views::ImageView;
icon_->SetImage(image.ToImageSkia());
icon_->SizeToPreferredSize();
- AddChildView(icon_);
+ child_container_->AddChildView(icon_);
}
if (ui::MaterialDesignController::IsModeMaterial()) {
@@ -256,13 +274,13 @@ void InfoBarView::ViewHierarchyChanged(
close_button_->SetAccessibleName(
l10n_util::GetStringUTF16(IDS_ACCNAME_CLOSE));
close_button_->SetFocusable(true);
- AddChildView(close_button_);
+ child_container_->AddChildView(close_button_);
} else if ((close_button_ != NULL) && (details.parent == this) &&
(details.child != close_button_) && (close_button_->parent() == this) &&
(child_at(child_count() - 1) != close_button_)) {
// For accessibility, ensure the close button is the last child view.
RemoveChildView(close_button_);
- AddChildView(close_button_);
+ child_container_->AddChildView(close_button_);
}
// Ensure the infobar is tall enough to display its contents.
@@ -277,19 +295,6 @@ void InfoBarView::ViewHierarchyChanged(
SetBarTargetHeight(height);
}
-void InfoBarView::PaintChildren(const ui::PaintContext& context) {
- // TODO(scr): This really should be the |fill_path_|, but the clipPath seems
- // broken on non-Windows platforms (crbug.com/75154). For now, just clip to
- // the bar bounds.
- //
- // canvas->sk_canvas()->clipPath(fill_path_);
- DCHECK_EQ(total_height(), height())
- << "Infobar piecewise heights do not match overall height";
- ui::ClipRecorder clip_recorder(context);
- clip_recorder.ClipRect(gfx::Rect(0, arrow_height(), width(), bar_height()));
- views::View::PaintChildren(context);
-}
-
void InfoBarView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (!owner())
@@ -317,9 +322,8 @@ int InfoBarView::EndX() const {
}
int InfoBarView::OffsetY(views::View* view) const {
- return arrow_height() +
- std::max((bar_target_height() - view->height()) / 2, 0) -
- (bar_target_height() - bar_height());
+ return std::max((bar_target_height() - view->height()) / 2, 0) -
+ (bar_target_height() - bar_height());
}
const infobars::InfoBarContainer::Delegate* InfoBarView::container_delegate()
@@ -344,6 +348,10 @@ void InfoBarView::RunMenuAt(ui::MenuModel* menu_model,
ui::MENU_SOURCE_NONE));
}
+void InfoBarView::AddViewToContentArea(views::View* view) {
+ child_container_->AddChildView(view);
+}
+
// static
void InfoBarView::AssignWidthsSorted(Labels* labels, int available_width) {
if (labels->empty())
« no previous file with comments | « chrome/browser/ui/views/infobars/infobar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698