Commit 950402fd authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Remove InfoBarView::child_container_.

We need to clip infobar child elements to the "bar" portion of the infobar.
Previously, this couldn't be done simply by clipping to the infobar bounds,
because the top arrow meant the infobar bounds extended up past the bar.  Now
that arrows are dead, |child_container_| is no longer necessary.

BUG=none
TEST=none

Change-Id: Ib9c2ec62638eff1043d6e7a43bdb6648e0a08289
Reviewed-on: https://chromium-review.googlesource.com/989286
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#547519}
parent 9f185605
......@@ -86,15 +86,15 @@ void AlternateNavInfoBarView::ViewHierarchyChanged(
DCHECK_NE(base::string16::npos, offset);
label_1_text_ = message_text.substr(0, offset);
label_1_ = CreateLabel(label_1_text_);
AddViewToContentArea(label_1_);
AddChildView(label_1_);
link_text_ = delegate->GetLinkText();
link_ = CreateLink(link_text_, this);
AddViewToContentArea(link_);
AddChildView(link_);
label_2_text_ = message_text.substr(offset);
label_2_ = CreateLabel(label_2_text_);
AddViewToContentArea(label_2_);
AddChildView(label_2_);
}
// This must happen after adding all other children so InfoBarView can ensure
......
......@@ -78,7 +78,7 @@ void ConfirmInfoBar::ViewHierarchyChanged(
if (details.is_add && details.child == this && (label_ == nullptr)) {
ConfirmInfoBarDelegate* delegate = GetDelegate();
label_ = CreateLabel(delegate->GetMessageText());
AddViewToContentArea(label_);
AddChildView(label_);
if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) {
ok_button_ = CreateButton(ConfirmInfoBarDelegate::BUTTON_OK);
......@@ -98,7 +98,7 @@ void ConfirmInfoBar::ViewHierarchyChanged(
base::string16 link_text(delegate->GetLinkText());
link_ = CreateLink(link_text, this);
AddViewToContentArea(link_);
AddChildView(link_);
}
// This must happen after adding all other children so InfoBarView can ensure
......@@ -148,7 +148,7 @@ views::MdTextButton* ConfirmInfoBar::CreateButton(
new gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_TOAST_CONTROL_VERTICAL),
0));
AddViewToContentArea(button);
AddChildView(button);
button->SizeToPreferredSize();
return button;
}
......
......@@ -89,19 +89,15 @@ gfx::Insets GetCloseButtonSpacing() {
InfoBarView::InfoBarView(std::unique_ptr<infobars::InfoBarDelegate> delegate)
: infobars::InfoBar(std::move(delegate)),
views::ExternalFocusTracker(this, nullptr),
child_container_(new views::View()) {
views::ExternalFocusTracker(this, nullptr) {
set_owned_by_client(); // InfoBar deletes itself at the appropriate time.
SetBackground(std::make_unique<InfoBarBackground>());
SetEventTargeter(std::make_unique<views::ViewTargeter>(this));
AddChildView(child_container_);
// Clip child layers; without this, buttons won't look correct during
// animation.
SetPaintToLayer();
layer()->SetFillsBoundsOpaquely(false);
child_container_->SetPaintToLayer();
child_container_->layer()->SetMasksToBounds(true);
layer()->SetMasksToBounds(true);
}
const infobars::InfoBarContainer::Delegate* InfoBarView::container_delegate()
......@@ -141,14 +137,6 @@ void InfoBarView::AssignWidths(Labels* labels, int available_width) {
}
void InfoBarView::Layout() {
child_container_->SetBounds(
0, arrow_height(), width(),
bar_height() - InfoBarContainerDelegate::kSeparatorLineHeight);
// |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_|.
const int spacing = GetElementSpacing();
int start_x = 0;
if (icon_) {
......@@ -187,7 +175,7 @@ void InfoBarView::ViewHierarchyChanged(
new gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric(
DISTANCE_TOAST_LABEL_VERTICAL),
0));
child_container_->AddChildView(icon_);
AddChildView(icon_);
}
close_button_ = views::CreateVectorImageButton(this);
......@@ -202,13 +190,13 @@ void InfoBarView::ViewHierarchyChanged(
close_button_spacing.bottom(), 0));
// Subclasses should already be done adding child views by this point (see
// related DCHECK in Layout()).
child_container_->AddChildView(close_button_);
AddChildView(close_button_);
}
// Ensure the infobar is tall enough to display its contents.
int height = 0;
for (int i = 0; i < child_container_->child_count(); ++i) {
View* child = child_container_->child_at(i);
for (int i = 0; i < child_count(); ++i) {
View* child = child_at(i);
const gfx::Insets* const margins = child->GetProperty(views::kMarginsKey);
const int margin_height = margins ? margins->height() : 0;
height = std::max(height, child->height() + margin_height);
......@@ -218,8 +206,7 @@ void InfoBarView::ViewHierarchyChanged(
void InfoBarView::OnThemeChanged() {
const SkColor background_color = GetColor(kBackgroundColor);
child_container_->SetBackground(
views::CreateSolidBackground(background_color));
background()->SetNativeControlColor(background_color);
const SkColor text_color = GetColor(kTextColor);
if (close_button_) {
......@@ -227,8 +214,8 @@ void InfoBarView::OnThemeChanged() {
text_color);
}
for (int i = 0; i < child_container_->child_count(); ++i) {
View* child = child_container_->child_at(i);
for (int i = 0; i < child_count(); ++i) {
View* child = child_at(i);
LabelType label_type = child->GetProperty(kLabelType);
if (label_type != LabelType::kNone) {
auto* label = static_cast<views::Label*>(child);
......@@ -274,10 +261,6 @@ int InfoBarView::OffsetY(views::View* view) const {
(bar_target_height() - bar_height());
}
void InfoBarView::AddViewToContentArea(views::View* view) {
child_container_->AddChildView(view);
}
// static
void InfoBarView::AssignWidthsSorted(Labels* labels, int available_width) {
if (labels->empty())
......
......@@ -80,11 +80,6 @@ class InfoBarView : public infobars::InfoBar,
// animate open and closed.
int OffsetY(views::View* view) const;
protected:
// Adds |view| to the content area, i.e. |child_container_|. The |view| won't
// automatically get any layout, so should still be laid out manually.
void AddViewToContentArea(views::View* view);
private:
// Does the actual work for AssignWidths(). Assumes |labels| is sorted by
// decreasing preferred width.
......@@ -114,10 +109,6 @@ class InfoBarView : public infobars::InfoBar,
// labels.
void SetLabelDetails(views::Label* label) const;
// This container holds the children and clips their painting during
// animation.
views::View* child_container_;
// The optional icon at the left edge of the InfoBar.
views::ImageView* icon_ = nullptr;
......
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