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

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

Issue 1831673002: [MD] Apply appropriate call to action styling to infobar buttons. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compile 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
« no previous file with comments | « no previous file | chrome/browser/ui/views/infobars/infobar_view.h » ('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 "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/ui/views/elevation_icon_setter.h" 11 #include "chrome/browser/ui/views/elevation_icon_setter.h"
12 #include "components/infobars/core/confirm_infobar_delegate.h" 12 #include "components/infobars/core/confirm_infobar_delegate.h"
13 #include "ui/base/material_design/material_design_controller.h" 13 #include "ui/base/material_design/material_design_controller.h"
14 #include "ui/base/window_open_disposition.h" 14 #include "ui/base/window_open_disposition.h"
15 #include "ui/views/controls/button/label_button.h" 15 #include "ui/views/controls/button/label_button.h"
16 #include "ui/views/controls/button/md_text_button.h"
16 #include "ui/views/controls/label.h" 17 #include "ui/views/controls/label.h"
17 #include "ui/views/controls/link.h" 18 #include "ui/views/controls/link.h"
18 19
19 // InfoBarService ------------------------------------------------------------- 20 // InfoBarService -------------------------------------------------------------
20 21
21 scoped_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar( 22 scoped_ptr<infobars::InfoBar> InfoBarService::CreateConfirmInfoBar(
22 scoped_ptr<ConfirmInfoBarDelegate> delegate) { 23 scoped_ptr<ConfirmInfoBarDelegate> delegate) {
23 return make_scoped_ptr(new ConfirmInfoBar(std::move(delegate))); 24 return make_scoped_ptr(new ConfirmInfoBar(std::move(delegate)));
24 } 25 }
25 26
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 64 }
64 65
65 void ConfirmInfoBar::ViewHierarchyChanged( 66 void ConfirmInfoBar::ViewHierarchyChanged(
66 const ViewHierarchyChangedDetails& details) { 67 const ViewHierarchyChangedDetails& details) {
67 if (details.is_add && details.child == this && (label_ == nullptr)) { 68 if (details.is_add && details.child == this && (label_ == nullptr)) {
68 ConfirmInfoBarDelegate* delegate = GetDelegate(); 69 ConfirmInfoBarDelegate* delegate = GetDelegate();
69 label_ = CreateLabel(delegate->GetMessageText()); 70 label_ = CreateLabel(delegate->GetMessageText());
70 AddViewToContentArea(label_); 71 AddViewToContentArea(label_);
71 72
72 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) { 73 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) {
73 ok_button_ = CreateTextButton( 74 if (ui::MaterialDesignController::IsModeMaterial()) {
74 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); 75 views::MdTextButton* button = CreateMdTextButton(
76 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK));
77 // If this is the only button, weak call to action. Otherwise, strong
78 // call to action.
79 button->SetCallToAction(
80 delegate->GetButtons() == ConfirmInfoBarDelegate::BUTTON_OK
81 ? views::MdTextButton::WEAK_CALL_TO_ACTION
82 : views::MdTextButton::STRONG_CALL_TO_ACTION);
83 ok_button_ = button;
84 } else {
85 ok_button_ = CreateTextButton(
86 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK));
87 }
Peter Kasting 2016/03/25 04:57:48 Nit: It seems unfortunate to have this mostly-dupl
Evan Stade 2016/03/28 19:13:43 I don't see this as a huge win because I don't see
75 if (delegate->OKButtonTriggersUACPrompt()) { 88 if (delegate->OKButtonTriggersUACPrompt()) {
76 elevation_icon_setter_.reset(new ElevationIconSetter( 89 elevation_icon_setter_.reset(new ElevationIconSetter(
77 ok_button_, 90 ok_button_,
78 base::Bind(&ConfirmInfoBar::Layout, base::Unretained(this)))); 91 base::Bind(&ConfirmInfoBar::Layout, base::Unretained(this))));
79 } 92 }
80 AddViewToContentArea(ok_button_); 93 AddViewToContentArea(ok_button_);
81 ok_button_->SizeToPreferredSize(); 94 ok_button_->SizeToPreferredSize();
82 } 95 }
83 96
84 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) { 97 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) {
85 cancel_button_ = CreateTextButton( 98 if (ui::MaterialDesignController::IsModeMaterial()) {
86 this, 99 views::MdTextButton* button = CreateMdTextButton(
87 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); 100 this,
101 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL));
102 // If this is the only button, weak call to action. Otherwise, no call
103 // to action.
104 button->SetCallToAction(
105 delegate->GetButtons() == ConfirmInfoBarDelegate::BUTTON_CANCEL
106 ? views::MdTextButton::WEAK_CALL_TO_ACTION
107 : views::MdTextButton::NO_CALL_TO_ACTION);
108 cancel_button_ = button;
109 } else {
110 cancel_button_ = CreateTextButton(
111 this,
112 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL));
113 }
88 AddViewToContentArea(cancel_button_); 114 AddViewToContentArea(cancel_button_);
89 cancel_button_->SizeToPreferredSize(); 115 cancel_button_->SizeToPreferredSize();
90 } 116 }
91 117
92 base::string16 link_text(delegate->GetLinkText()); 118 base::string16 link_text(delegate->GetLinkText());
93 link_ = CreateLink(link_text, this); 119 link_ = CreateLink(link_text, this);
94 AddViewToContentArea(link_); 120 AddViewToContentArea(link_);
95 } 121 }
96 122
97 // This must happen after adding all other children so InfoBarView can ensure 123 // This must happen after adding all other children so InfoBarView can ensure
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 159 }
134 160
135 int ConfirmInfoBar::NonLabelWidth() const { 161 int ConfirmInfoBar::NonLabelWidth() const {
136 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ? 162 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ?
137 0 : kEndOfLabelSpacing; 163 0 : kEndOfLabelSpacing;
138 if (ok_button_) 164 if (ok_button_)
139 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0); 165 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0);
140 width += cancel_button_ ? cancel_button_->width() : 0; 166 width += cancel_button_ ? cancel_button_->width() : 0;
141 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing); 167 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing);
142 } 168 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/infobars/infobar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698