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

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

Issue 1777813002: MD - use new style of text button in infobars. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: uac button cleanup Created 4 years, 9 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
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 "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
(...skipping 10 matching lines...) Expand all
21 scoped_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar( 21 scoped_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar(
22 scoped_ptr<ConfirmInfoBarDelegate> delegate) { 22 scoped_ptr<ConfirmInfoBarDelegate> delegate) {
23 return make_scoped_ptr(new ConfirmInfoBar(std::move(delegate))); 23 return make_scoped_ptr(new ConfirmInfoBar(std::move(delegate)));
24 } 24 }
25 25
26 26
27 // ConfirmInfoBar ------------------------------------------------------------- 27 // ConfirmInfoBar -------------------------------------------------------------
28 28
29 ConfirmInfoBar::ConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate> delegate) 29 ConfirmInfoBar::ConfirmInfoBar(scoped_ptr<ConfirmInfoBarDelegate> delegate)
30 : InfoBarView(std::move(delegate)), 30 : InfoBarView(std::move(delegate)),
31 label_(NULL), 31 label_(nullptr),
32 ok_button_(NULL), 32 ok_button_(nullptr),
33 cancel_button_(NULL), 33 cancel_button_(nullptr),
34 link_(NULL) {} 34 link_(nullptr) {}
35 35
36 ConfirmInfoBar::~ConfirmInfoBar() { 36 ConfirmInfoBar::~ConfirmInfoBar() {
37 // Ensure |elevation_icon_setter_| is destroyed before |ok_button_|. 37 // Ensure |elevation_icon_setter_| is destroyed before |ok_button_|.
38 elevation_icon_setter_.reset(); 38 elevation_icon_setter_.reset();
39 } 39 }
40 40
41 void ConfirmInfoBar::Layout() { 41 void ConfirmInfoBar::Layout() {
42 InfoBarView::Layout(); 42 InfoBarView::Layout();
43 43
44 int x = StartX(); 44 int x = StartX();
(...skipping 12 matching lines...) Expand all
57 } 57 }
58 58
59 if (cancel_button_) 59 if (cancel_button_)
60 cancel_button_->SetPosition(gfx::Point(x, OffsetY(cancel_button_))); 60 cancel_button_->SetPosition(gfx::Point(x, OffsetY(cancel_button_)));
61 61
62 link_->SetPosition(gfx::Point(EndX() - link_->width(), OffsetY(link_))); 62 link_->SetPosition(gfx::Point(EndX() - link_->width(), OffsetY(link_)));
63 } 63 }
64 64
65 void ConfirmInfoBar::ViewHierarchyChanged( 65 void ConfirmInfoBar::ViewHierarchyChanged(
66 const ViewHierarchyChangedDetails& details) { 66 const ViewHierarchyChangedDetails& details) {
67 if (details.is_add && details.child == this && (label_ == NULL)) { 67 if (details.is_add && details.child == this && (label_ == nullptr)) {
68 ConfirmInfoBarDelegate* delegate = GetDelegate(); 68 ConfirmInfoBarDelegate* delegate = GetDelegate();
69 label_ = CreateLabel(delegate->GetMessageText()); 69 label_ = CreateLabel(delegate->GetMessageText());
70 AddViewToContentArea(label_); 70 AddViewToContentArea(label_);
71 71
72 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) { 72 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) {
73 ok_button_ = CreateTextButton(
74 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK));
73 if (delegate->OKButtonTriggersUACPrompt()) { 75 if (delegate->OKButtonTriggersUACPrompt()) {
74 // Use a label button even in MD mode as MD buttons don't support icons.
75 views::LabelButton* ok_button = CreateLabelButton(
76 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK));
77 elevation_icon_setter_.reset(new ElevationIconSetter( 76 elevation_icon_setter_.reset(new ElevationIconSetter(
78 ok_button, 77 ok_button_,
79 base::Bind(&ConfirmInfoBar::Layout, base::Unretained(this)))); 78 base::Bind(&ConfirmInfoBar::Layout, base::Unretained(this))));
80 ok_button_ = ok_button;
81 } else {
82 ok_button_ = CreateTextButton(
83 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK));
84 } 79 }
85 AddViewToContentArea(ok_button_); 80 AddViewToContentArea(ok_button_);
86 ok_button_->SizeToPreferredSize(); 81 ok_button_->SizeToPreferredSize();
87 } 82 }
88 83
89 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) { 84 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) {
90 cancel_button_ = CreateTextButton( 85 cancel_button_ = CreateTextButton(
91 this, 86 this,
92 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); 87 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL));
93 AddViewToContentArea(cancel_button_); 88 AddViewToContentArea(cancel_button_);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 } 133 }
139 134
140 int ConfirmInfoBar::NonLabelWidth() const { 135 int ConfirmInfoBar::NonLabelWidth() const {
141 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ? 136 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ?
142 0 : kEndOfLabelSpacing; 137 0 : kEndOfLabelSpacing;
143 if (ok_button_) 138 if (ok_button_)
144 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0); 139 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0);
145 width += cancel_button_ ? cancel_button_->width() : 0; 140 width += cancel_button_ ? cancel_button_->width() : 0;
146 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing); 141 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing);
147 } 142 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/confirm_infobar.h ('k') | chrome/browser/ui/views/infobars/infobar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698