Chromium Code Reviews| 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 b2204e6d360038a8c2e0d9be8d942ee738fb992c..63119a87ef7dc9bf1bd221b393c6176ce625f71b 100644 |
| --- a/chrome/browser/ui/views/infobars/infobar_view.cc |
| +++ b/chrome/browser/ui/views/infobars/infobar_view.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/memory/ptr_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/ui/infobar_container_delegate.h" |
| +#include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" |
| #include "chrome/browser/ui/views/infobars/infobar_background.h" |
| #include "chrome/grit/generated_resources.h" |
| #include "chrome/grit/theme_resources.h" |
| @@ -35,7 +36,6 @@ |
| #include "ui/views/controls/label.h" |
| #include "ui/views/controls/link.h" |
| #include "ui/views/controls/menu/menu_runner.h" |
| -#include "ui/views/layout/layout_constants.h" |
| #include "ui/views/widget/widget.h" |
| #include "ui/views/window/non_client_view.h" |
| @@ -44,10 +44,6 @@ |
| namespace { |
| -const int kEdgeItemPadding = views::kRelatedControlHorizontalSpacing; |
| -const int kIconToLabelSpacing = views::kRelatedControlHorizontalSpacing; |
| -const int kBeforeCloseButtonSpacing = views::kUnrelatedControlHorizontalSpacing; |
| - |
| bool SortLabelsByDecreasingWidth(views::Label* label_1, views::Label* label_2) { |
| return label_1->GetPreferredSize().width() > |
| label_2->GetPreferredSize().width(); |
| @@ -130,22 +126,30 @@ void InfoBarView::Layout() { |
| // |child_container_| should be the only child. |
| DCHECK_EQ(1, child_count()); |
| + int related_control_distance_horizontal = |
| + ChromeLayoutProvider::Get()->GetDistanceMetric( |
| + views::DISTANCE_RELATED_CONTROL_HORIZONTAL); |
| + int unrelated_control_distance_horizontal = |
| + ChromeLayoutProvider::Get()->GetDistanceMetric( |
| + DISTANCE_UNRELATED_CONTROL_HORIZONTAL); |
| // Even though other views are technically grandchildren, we'll lay them out |
| // here on behalf of |child_container_|. |
| - int start_x = kEdgeItemPadding; |
| + int start_x = related_control_distance_horizontal; |
| if (icon_ != NULL) { |
| icon_->SetPosition(gfx::Point(start_x, OffsetY(icon_))); |
| - start_x = icon_->bounds().right() + kIconToLabelSpacing; |
| + start_x = icon_->bounds().right() + related_control_distance_horizontal; |
| } |
| int content_minimum_width = ContentMinimumWidth(); |
| close_button_->SizeToPreferredSize(); |
| - close_button_->SetPosition(gfx::Point( |
| - std::max( |
| - start_x + content_minimum_width + |
| - ((content_minimum_width > 0) ? kBeforeCloseButtonSpacing : 0), |
| - width() - kEdgeItemPadding - close_button_->width()), |
| - OffsetY(close_button_))); |
| + close_button_->SetPosition( |
| + gfx::Point(std::max(start_x + content_minimum_width + |
| + ((content_minimum_width > 0) |
| + ? unrelated_control_distance_horizontal |
| + : 0), |
| + width() - related_control_distance_horizontal - |
| + close_button_->width()), |
| + OffsetY(close_button_))); |
| // For accessibility reasons, the close button should come last. |
| DCHECK_EQ(close_button_->parent()->child_count() - 1, |
| @@ -204,12 +208,17 @@ int InfoBarView::StartX() const { |
| // Ensure we don't return a value greater than EndX(), so children can safely |
| // set something's width to "EndX() - StartX()" without risking that being |
| // negative. |
| - return std::min(EndX(), (icon_ != NULL) ? |
| - (icon_->bounds().right() + kIconToLabelSpacing) : kEdgeItemPadding); |
| + int related_control_horizontal_spacing = |
| + ChromeLayoutProvider::Get()->GetDistanceMetric( |
| + views::DISTANCE_RELATED_CONTROL_HORIZONTAL); |
| + return std::min(EndX(), (icon_ != NULL) ? (icon_->bounds().right() + |
| + related_control_horizontal_spacing) |
| + : related_control_horizontal_spacing); |
|
Peter Kasting
2017/04/14 07:42:32
Nit: Simpler:
const int padding = ChromeLayoutP
ananta
2017/04/14 18:32:33
Done.
|
| } |
| int InfoBarView::EndX() const { |
| - return close_button_->x() - kBeforeCloseButtonSpacing; |
| + return close_button_->x() - ChromeLayoutProvider::Get()->GetDistanceMetric( |
| + DISTANCE_UNRELATED_CONTROL_HORIZONTAL); |
| } |
| int InfoBarView::OffsetY(views::View* view) const { |
| @@ -280,10 +289,17 @@ void InfoBarView::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| } |
| gfx::Size InfoBarView::GetPreferredSize() const { |
| + int related_control_horizontal_spacing = |
| + ChromeLayoutProvider::Get()->GetDistanceMetric( |
| + views::DISTANCE_RELATED_CONTROL_HORIZONTAL); |
| + int unrelated_control_horizontal_spacing = |
| + ChromeLayoutProvider::Get()->GetDistanceMetric( |
| + DISTANCE_UNRELATED_CONTROL_HORIZONTAL); |
| return gfx::Size( |
| - kEdgeItemPadding + (icon_ ? (icon_->width() + kIconToLabelSpacing) : 0) + |
| - ContentMinimumWidth() + kBeforeCloseButtonSpacing + |
| - close_button_->width() + kEdgeItemPadding, |
| + related_control_horizontal_spacing + |
| + (icon_ ? (icon_->width() + related_control_horizontal_spacing) : 0) + |
| + ContentMinimumWidth() + unrelated_control_horizontal_spacing + |
| + close_button_->width() + related_control_horizontal_spacing, |
| total_height()); |
| } |