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

Side by Side Diff: chrome/browser/ui/views/infobars/confirm_infobar.cc

Issue 2812243007: Replace layout constants in chrome/browser/ui/views/infobars. (Closed)
Patch Set: Address review comments Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/views/infobars/infobar_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16 matching lines...) Expand all
55 48
56 void ConfirmInfoBar::Layout() { 49 void ConfirmInfoBar::Layout() {
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
58 ChromeLayoutProvider* layout_provider = ChromeLayoutProvider::Get();
59
65 label_->SetPosition(gfx::Point(x, OffsetY(label_))); 60 label_->SetPosition(gfx::Point(x, OffsetY(label_)));
66 if (!label_->text().empty()) 61 if (!label_->text().empty())
67 x = label_->bounds().right() + kEndOfLabelSpacing; 62 x = label_->bounds().right() +
63 layout_provider->GetDistanceMetric(DISTANCE_RELATED_LABEL_HORIZONTAL);
68 64
69 if (ok_button_) { 65 if (ok_button_) {
70 ok_button_->SetPosition(gfx::Point(x, OffsetY(ok_button_))); 66 ok_button_->SetPosition(gfx::Point(x, OffsetY(ok_button_)));
71 x = ok_button_->bounds().right() + kButtonButtonSpacing; 67 x = ok_button_->bounds().right() +
68 layout_provider->GetDistanceMetric(
69 views::DISTANCE_RELATED_BUTTON_HORIZONTAL);
72 } 70 }
73 71
74 if (cancel_button_) 72 if (cancel_button_)
75 cancel_button_->SetPosition(gfx::Point(x, OffsetY(cancel_button_))); 73 cancel_button_->SetPosition(gfx::Point(x, OffsetY(cancel_button_)));
76 74
77 link_->SetPosition(gfx::Point(EndX() - link_->width(), OffsetY(link_))); 75 link_->SetPosition(gfx::Point(EndX() - link_->width(), OffsetY(link_)));
78 } 76 }
79 77
80 void ConfirmInfoBar::ViewHierarchyChanged( 78 void ConfirmInfoBar::ViewHierarchyChanged(
81 const ViewHierarchyChangedDetails& details) { 79 const ViewHierarchyChangedDetails& details) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 DCHECK_EQ(link_, source); 144 DCHECK_EQ(link_, source);
147 if (GetDelegate()->LinkClicked(ui::DispositionFromEventFlags(event_flags))) 145 if (GetDelegate()->LinkClicked(ui::DispositionFromEventFlags(event_flags)))
148 RemoveSelf(); 146 RemoveSelf();
149 } 147 }
150 148
151 ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() { 149 ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() {
152 return delegate()->AsConfirmInfoBarDelegate(); 150 return delegate()->AsConfirmInfoBarDelegate();
153 } 151 }
154 152
155 int ConfirmInfoBar::NonLabelWidth() const { 153 int ConfirmInfoBar::NonLabelWidth() const {
156 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ? 154 ChromeLayoutProvider* layout_provider = ChromeLayoutProvider::Get();
157 0 : kEndOfLabelSpacing; 155
156 const int label_spacing =
157 layout_provider->GetDistanceMetric(DISTANCE_RELATED_LABEL_HORIZONTAL);
158 const int button_spacing = layout_provider->GetDistanceMetric(
159 views::DISTANCE_RELATED_BUTTON_HORIZONTAL);
160
161 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_))
162 ? 0
163 : label_spacing;
158 if (ok_button_) 164 if (ok_button_)
159 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0); 165 width += ok_button_->width() + (cancel_button_ ? button_spacing : 0);
160 width += cancel_button_ ? cancel_button_->width() : 0; 166 width += cancel_button_ ? cancel_button_->width() : 0;
161 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing); 167 return width + ((link_->text().empty() || !width) ? 0 : label_spacing);
162 } 168 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/infobars/infobar_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698