Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/infobars/confirm_infobar.h" | 5 #include "chrome/browser/ui/views/infobars/confirm_infobar.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "chrome/browser/infobars/infobar_service.h" | 11 #include "chrome/browser/infobars/infobar_service.h" |
| 12 #include "chrome/browser/ui/views/elevation_icon_setter.h" | 12 #include "chrome/browser/ui/views/elevation_icon_setter.h" |
| 13 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" | |
| 13 #include "components/infobars/core/confirm_infobar_delegate.h" | 14 #include "components/infobars/core/confirm_infobar_delegate.h" |
| 14 #include "ui/base/material_design/material_design_controller.h" | 15 #include "ui/base/material_design/material_design_controller.h" |
| 15 #include "ui/base/window_open_disposition.h" | 16 #include "ui/base/window_open_disposition.h" |
| 16 #include "ui/native_theme/native_theme.h" | 17 #include "ui/native_theme/native_theme.h" |
| 17 #include "ui/views/controls/button/label_button.h" | 18 #include "ui/views/controls/button/label_button.h" |
| 18 #include "ui/views/controls/button/md_text_button.h" | 19 #include "ui/views/controls/button/md_text_button.h" |
| 19 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
| 20 #include "ui/views/controls/link.h" | 21 #include "ui/views/controls/link.h" |
| 21 #include "ui/views/layout/layout_constants.h" | |
| 22 | |
| 23 namespace { | |
| 24 | |
| 25 constexpr int kButtonButtonSpacing = views::kRelatedButtonHSpacing; | |
| 26 constexpr int kEndOfLabelSpacing = views::kItemLabelSpacing; | |
| 27 | |
| 28 } // namespace | |
| 29 | 22 |
| 30 // InfoBarService ------------------------------------------------------------- | 23 // InfoBarService ------------------------------------------------------------- |
| 31 | 24 |
| 32 std::unique_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar( | 25 std::unique_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar( |
| 33 std::unique_ptr<ConfirmInfoBarDelegate> delegate) { | 26 std::unique_ptr<ConfirmInfoBarDelegate> delegate) { |
| 34 return base::MakeUnique<ConfirmInfoBar>(std::move(delegate)); | 27 return base::MakeUnique<ConfirmInfoBar>(std::move(delegate)); |
| 35 } | 28 } |
| 36 | 29 |
| 37 | 30 |
| 38 // ConfirmInfoBar ------------------------------------------------------------- | 31 // ConfirmInfoBar ------------------------------------------------------------- |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 57 InfoBarView::Layout(); | 50 InfoBarView::Layout(); |
| 58 | 51 |
| 59 int x = StartX(); | 52 int x = StartX(); |
| 60 Labels labels; | 53 Labels labels; |
| 61 labels.push_back(label_); | 54 labels.push_back(label_); |
| 62 labels.push_back(link_); | 55 labels.push_back(link_); |
| 63 AssignWidths(&labels, std::max(0, EndX() - x - NonLabelWidth())); | 56 AssignWidths(&labels, std::max(0, EndX() - x - NonLabelWidth())); |
| 64 | 57 |
| 65 label_->SetPosition(gfx::Point(x, OffsetY(label_))); | 58 label_->SetPosition(gfx::Point(x, OffsetY(label_))); |
| 66 if (!label_->text().empty()) | 59 if (!label_->text().empty()) |
| 67 x = label_->bounds().right() + kEndOfLabelSpacing; | 60 x = label_->bounds().right() + |
| 61 ChromeLayoutProvider::Get()->GetDistanceMetric( | |
|
Peter Kasting
2017/04/14 07:42:32
Nit: Pull layout provider out to a temp for reuse
ananta
2017/04/14 18:32:33
Done.
| |
| 62 DISTANCE_RELATED_LABEL_HORIZONTAL); | |
| 68 | 63 |
| 69 if (ok_button_) { | 64 if (ok_button_) { |
| 70 ok_button_->SetPosition(gfx::Point(x, OffsetY(ok_button_))); | 65 ok_button_->SetPosition(gfx::Point(x, OffsetY(ok_button_))); |
| 71 x = ok_button_->bounds().right() + kButtonButtonSpacing; | 66 x = ok_button_->bounds().right() + |
| 67 ChromeLayoutProvider::Get()->GetDistanceMetric( | |
| 68 views::DISTANCE_RELATED_BUTTON_HORIZONTAL); | |
| 72 } | 69 } |
| 73 | 70 |
| 74 if (cancel_button_) | 71 if (cancel_button_) |
| 75 cancel_button_->SetPosition(gfx::Point(x, OffsetY(cancel_button_))); | 72 cancel_button_->SetPosition(gfx::Point(x, OffsetY(cancel_button_))); |
| 76 | 73 |
| 77 link_->SetPosition(gfx::Point(EndX() - link_->width(), OffsetY(link_))); | 74 link_->SetPosition(gfx::Point(EndX() - link_->width(), OffsetY(link_))); |
| 78 } | 75 } |
| 79 | 76 |
| 80 void ConfirmInfoBar::ViewHierarchyChanged( | 77 void ConfirmInfoBar::ViewHierarchyChanged( |
| 81 const ViewHierarchyChangedDetails& details) { | 78 const ViewHierarchyChangedDetails& details) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 DCHECK_EQ(link_, source); | 143 DCHECK_EQ(link_, source); |
| 147 if (GetDelegate()->LinkClicked(ui::DispositionFromEventFlags(event_flags))) | 144 if (GetDelegate()->LinkClicked(ui::DispositionFromEventFlags(event_flags))) |
| 148 RemoveSelf(); | 145 RemoveSelf(); |
| 149 } | 146 } |
| 150 | 147 |
| 151 ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() { | 148 ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() { |
| 152 return delegate()->AsConfirmInfoBarDelegate(); | 149 return delegate()->AsConfirmInfoBarDelegate(); |
| 153 } | 150 } |
| 154 | 151 |
| 155 int ConfirmInfoBar::NonLabelWidth() const { | 152 int ConfirmInfoBar::NonLabelWidth() const { |
| 156 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ? | 153 int related_label_horizontal_spacing = |
|
Peter Kasting
2017/04/14 07:42:32
Nit: Try for a shorter name if it's still readable
ananta
2017/04/14 18:32:33
Done.
| |
| 157 0 : kEndOfLabelSpacing; | 154 ChromeLayoutProvider::Get()->GetDistanceMetric( |
| 155 DISTANCE_RELATED_LABEL_HORIZONTAL); | |
| 156 int related_button_horizontal_spacing = | |
| 157 ChromeLayoutProvider::Get()->GetDistanceMetric( | |
| 158 views::DISTANCE_RELATED_BUTTON_HORIZONTAL); | |
| 159 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) | |
| 160 ? 0 | |
| 161 : related_label_horizontal_spacing; | |
| 158 if (ok_button_) | 162 if (ok_button_) |
| 159 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0); | 163 width += ok_button_->width() + |
| 164 (cancel_button_ ? related_button_horizontal_spacing : 0); | |
| 160 width += cancel_button_ ? cancel_button_->width() : 0; | 165 width += cancel_button_ ? cancel_button_->width() : 0; |
| 161 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing); | 166 return width + ((link_->text().empty() || !width) |
| 167 ? 0 | |
| 168 : related_label_horizontal_spacing); | |
| 162 } | 169 } |
| OLD | NEW |