| 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 "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 const ViewHierarchyChangedDetails& details) { | 67 const ViewHierarchyChangedDetails& details) { |
| 68 if (details.is_add && details.child == this && (label_ == nullptr)) { | 68 if (details.is_add && details.child == this && (label_ == nullptr)) { |
| 69 ConfirmInfoBarDelegate* delegate = GetDelegate(); | 69 ConfirmInfoBarDelegate* delegate = GetDelegate(); |
| 70 label_ = CreateLabel(delegate->GetMessageText()); | 70 label_ = CreateLabel(delegate->GetMessageText()); |
| 71 AddViewToContentArea(label_); | 71 AddViewToContentArea(label_); |
| 72 | 72 |
| 73 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) { | 73 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_OK) { |
| 74 if (ui::MaterialDesignController::IsModeMaterial()) { | 74 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 75 views::MdTextButton* button = CreateMdTextButton( | 75 views::MdTextButton* button = CreateMdTextButton( |
| 76 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); | 76 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); |
| 77 // If this is the only button, weak call to action. Otherwise, strong | 77 button->SetCallToAction(views::MdTextButton::STRONG_CALL_TO_ACTION); |
| 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; | 78 ok_button_ = button; |
| 84 } else { | 79 } else { |
| 85 ok_button_ = CreateTextButton( | 80 ok_button_ = CreateTextButton( |
| 86 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); | 81 this, delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_OK)); |
| 87 } | 82 } |
| 88 if (delegate->OKButtonTriggersUACPrompt()) { | 83 if (delegate->OKButtonTriggersUACPrompt()) { |
| 89 elevation_icon_setter_.reset(new ElevationIconSetter( | 84 elevation_icon_setter_.reset(new ElevationIconSetter( |
| 90 ok_button_, | 85 ok_button_, |
| 91 base::Bind(&ConfirmInfoBar::Layout, base::Unretained(this)))); | 86 base::Bind(&ConfirmInfoBar::Layout, base::Unretained(this)))); |
| 92 } | 87 } |
| 93 AddViewToContentArea(ok_button_); | 88 AddViewToContentArea(ok_button_); |
| 94 ok_button_->SizeToPreferredSize(); | 89 ok_button_->SizeToPreferredSize(); |
| 95 } | 90 } |
| 96 | 91 |
| 97 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) { | 92 if (delegate->GetButtons() & ConfirmInfoBarDelegate::BUTTON_CANCEL) { |
| 98 if (ui::MaterialDesignController::IsModeMaterial()) { | 93 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 99 views::MdTextButton* button = CreateMdTextButton( | 94 views::MdTextButton* button = CreateMdTextButton( |
| 100 this, | 95 this, |
| 101 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); | 96 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); |
| 102 // If this is the only button, weak call to action. Otherwise, no call | 97 // Apply CTA only if the cancel button is the only button. |
| 103 // to action. | 98 if (delegate->GetButtons() == ConfirmInfoBarDelegate::BUTTON_CANCEL) |
| 104 button->SetCallToAction( | 99 button->SetCallToAction(views::MdTextButton::STRONG_CALL_TO_ACTION); |
| 105 delegate->GetButtons() == ConfirmInfoBarDelegate::BUTTON_CANCEL | |
| 106 ? views::MdTextButton::WEAK_CALL_TO_ACTION | |
| 107 : views::MdTextButton::NO_CALL_TO_ACTION); | |
| 108 cancel_button_ = button; | 100 cancel_button_ = button; |
| 109 } else { | 101 } else { |
| 110 cancel_button_ = CreateTextButton( | 102 cancel_button_ = CreateTextButton( |
| 111 this, | 103 this, |
| 112 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); | 104 delegate->GetButtonLabel(ConfirmInfoBarDelegate::BUTTON_CANCEL)); |
| 113 } | 105 } |
| 114 AddViewToContentArea(cancel_button_); | 106 AddViewToContentArea(cancel_button_); |
| 115 cancel_button_->SizeToPreferredSize(); | 107 cancel_button_->SizeToPreferredSize(); |
| 116 } | 108 } |
| 117 | 109 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 } | 151 } |
| 160 | 152 |
| 161 int ConfirmInfoBar::NonLabelWidth() const { | 153 int ConfirmInfoBar::NonLabelWidth() const { |
| 162 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ? | 154 int width = (label_->text().empty() || (!ok_button_ && !cancel_button_)) ? |
| 163 0 : kEndOfLabelSpacing; | 155 0 : kEndOfLabelSpacing; |
| 164 if (ok_button_) | 156 if (ok_button_) |
| 165 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0); | 157 width += ok_button_->width() + (cancel_button_ ? kButtonButtonSpacing : 0); |
| 166 width += cancel_button_ ? cancel_button_->width() : 0; | 158 width += cancel_button_ ? cancel_button_->width() : 0; |
| 167 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing); | 159 return width + ((link_->text().empty() || !width) ? 0 : kEndOfLabelSpacing); |
| 168 } | 160 } |
| OLD | NEW |