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