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" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 } | 65 } |
| 66 | 66 |
| 67 void ConfirmInfoBar::ViewHierarchyChanged( | 67 void ConfirmInfoBar::ViewHierarchyChanged( |
| 68 const ViewHierarchyChangedDetails& details) { | 68 const ViewHierarchyChangedDetails& details) { |
| 69 if (details.is_add && details.child == this && (label_ == nullptr)) { | 69 if (details.is_add && details.child == this && (label_ == nullptr)) { |
| 70 ConfirmInfoBarDelegate* delegate = GetDelegate(); | 70 ConfirmInfoBarDelegate* delegate = GetDelegate(); |
| 71 label_ = CreateLabel(delegate->GetMessageText()); | 71 label_ = CreateLabel(delegate->GetMessageText()); |
| 72 AddViewToContentArea(label_); | 72 AddViewToContentArea(label_); |
| 73 | 73 |
| 74 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) { | 74 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) { |
| 75 if (ui::MaterialDesignController::IsModeMaterial()) { | 75 ok_button_ = views::MdTextButton::Create( |
| 76 views::MdTextButton* button = views::MdTextButton::Create( | 76 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); |
| 77 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); | 77 ok_button_->SetCallToAction(true); |
| 78 button->SetCallToAction(true); | |
| 79 ok_button_ = button; | |
| 80 } else { | |
| 81 ok_button_ = CreateTextButton( | |
| 82 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); | |
| 83 } | |
| 84 if (delegate->OKButtonTriggersUACPrompt()) { | 78 if (delegate->OKButtonTriggersUACPrompt()) { |
| 85 elevation_icon_setter_.reset(new ElevationIconSetter( | 79 elevation_icon_setter_.reset(new ElevationIconSetter( |
| 86 ok_button_, | 80 ok_button_, |
| 87 base::Bind(&ConfirmInfoBar::Layout, base::Unretained(this)))); | 81 base::Bind(&ConfirmInfoBar::Layout, base::Unretained(this)))); |
| 88 } | 82 } |
| 89 AddViewToContentArea(ok_button_); | 83 AddViewToContentArea(ok_button_); |
| 90 ok_button_->SizeToPreferredSize(); | 84 ok_button_->SizeToPreferredSize(); |
| 91 } | 85 } |
| 92 | 86 |
| 93 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) { | 87 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) { |
| 94 if (ui::MaterialDesignController::IsModeMaterial()) { | 88 cancel_button_ = views::MdTextButton::Create( |
| 95 views::MdTextButton* button = views::MdTextButton::Create( | 89 this, |
| 96 this, | 90 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); |
| 97 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); | 91 if (delegate->GetButtons() == ConfirmInfoBarDelegate::BUTTON_CANCEL) { |
| 98 if (delegate->GetButtons() == ConfirmInfoBarDelegate::BUTTON_CANCEL) { | 92 // Apply CTA only if the cancel button is the only button. |
| 99 // Apply CTA only if the cancel button is the only button. | 93 cancel_button_->SetCallToAction(true); |
| 100 button->SetCallToAction(true); | |
| 101 } else { | |
| 102 // Otherwise set the bg color to white and the text color to black. | |
| 103 // TODO(estade): These should be removed and moved into the native | |
| 104 // theme. Also, infobars should always use the normal (non-incognito) | |
| 105 // native theme. | |
| 106 button->set_bg_color_override(SK_ColorWHITE); | |
| 107 button->SetEnabledTextColors(kTextColor); | |
| 108 } | |
| 109 cancel_button_ = button; | |
| 110 } else { | 94 } else { |
| 111 cancel_button_ = CreateTextButton( | 95 // Otherwise set the bg color to white and the text color to black. |
| 112 this, | 96 // TODO(estade): These should be removed and moved into the native |
| 113 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); | 97 // theme. Also, infobars should always use the normal (non-incognito) |
| 98 // native theme. | |
|
Peter Kasting
2016/09/19 19:04:06
Were you waiting on removing pre-MD to implement t
Evan Stade
2016/09/19 20:06:02
the blocker at this point is figuring out an elega
Peter Kasting
2016/09/19 20:12:48
Ah. Is there a bug tracking figuring this out? I
| |
| 99 cancel_button_->set_bg_color_override(SK_ColorWHITE); | |
| 100 cancel_button_->SetEnabledTextColors(kTextColor); | |
| 114 } | 101 } |
| 115 AddViewToContentArea(cancel_button_); | 102 AddViewToContentArea(cancel_button_); |
| 116 cancel_button_->SizeToPreferredSize(); | 103 cancel_button_->SizeToPreferredSize(); |
| 117 } | 104 } |
| 118 | 105 |
| 119 base::string16 link_text(delegate->GetLinkText()); | 106 base::string16 link_text(delegate->GetLinkText()); |
| 120 link_ = CreateLink(link_text, this); | 107 link_ = CreateLink(link_text, this); |
| 121 AddViewToContentArea(link_); | 108 AddViewToContentArea(link_); |
| 122 } | 109 } |
| 123 | 110 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 } | 147 } |
| 161 | 148 |
| 162 int ConfirmInfoBar::NonLabelWidth() const { | 149 int ConfirmInfoBar::NonLabelWidth() const { |
| 163 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ? | 150 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ? |
| 164 0 : kEndOfLabelSpacing; | 151 0 : kEndOfLabelSpacing; |
| 165 if (ok_button_) | 152 if (ok_button_) |
| 166 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0); | 153 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0); |
| 167 width += cancel_button_ ? cancel_button_->width() : 0; | 154 width += cancel_button_ ? cancel_button_->width() : 0; |
| 168 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing); | 155 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing); |
| 169 } | 156 } |
| OLD | NEW |