| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 8 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 9 #include "ui/base/window_open_disposition.h" | 9 #include "ui/base/window_open_disposition.h" |
| 10 #include "ui/views/controls/button/text_button.h" | 10 #include "ui/views/controls/button/text_button.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 // This must happen after adding all other children so InfoBarView can ensure | 94 // This must happen after adding all other children so InfoBarView can ensure |
| 95 // the close button is the last child. | 95 // the close button is the last child. |
| 96 InfoBarView::ViewHierarchyChanged(is_add, parent, child); | 96 InfoBarView::ViewHierarchyChanged(is_add, parent, child); |
| 97 } | 97 } |
| 98 | 98 |
| 99 void ConfirmInfoBar::ButtonPressed(views::Button* sender, | 99 void ConfirmInfoBar::ButtonPressed(views::Button* sender, |
| 100 const ui::Event& event) { | 100 const ui::Event& event) { |
| 101 if (!owned()) | 101 if (!owner()) |
| 102 return; // We're closing; don't call anything, it might access the owner. | 102 return; // We're closing; don't call anything, it might access the owner. |
| 103 ConfirmInfoBarDelegate* delegate = GetDelegate(); | 103 ConfirmInfoBarDelegate* delegate = GetDelegate(); |
| 104 if ((ok_button_ != NULL) && sender == ok_button_) { | 104 if ((ok_button_ != NULL) && sender == ok_button_) { |
| 105 if (delegate->Accept()) | 105 if (delegate->Accept()) |
| 106 RemoveSelf(); | 106 RemoveSelf(); |
| 107 } else if ((cancel_button_ != NULL) && (sender == cancel_button_)) { | 107 } else if ((cancel_button_ != NULL) && (sender == cancel_button_)) { |
| 108 if (delegate->Cancel()) | 108 if (delegate->Cancel()) |
| 109 RemoveSelf(); | 109 RemoveSelf(); |
| 110 } else { | 110 } else { |
| 111 InfoBarView::ButtonPressed(sender, event); | 111 InfoBarView::ButtonPressed(sender, event); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 int ConfirmInfoBar::ContentMinimumWidth() const { | 115 int ConfirmInfoBar::ContentMinimumWidth() const { |
| 116 int width = (link_ == NULL) ? 0 : kEndOfLabelSpacing; // Space before link | 116 int width = (link_ == NULL) ? 0 : kEndOfLabelSpacing; // Space before link |
| 117 int before_cancel_spacing = kEndOfLabelSpacing; | 117 int before_cancel_spacing = kEndOfLabelSpacing; |
| 118 if (ok_button_ != NULL) { | 118 if (ok_button_ != NULL) { |
| 119 width += kEndOfLabelSpacing + ok_button_->GetPreferredSize().width(); | 119 width += kEndOfLabelSpacing + ok_button_->GetPreferredSize().width(); |
| 120 before_cancel_spacing = kButtonButtonSpacing; | 120 before_cancel_spacing = kButtonButtonSpacing; |
| 121 } | 121 } |
| 122 return width + ((cancel_button_ == NULL) ? 0 : | 122 return width + ((cancel_button_ == NULL) ? 0 : |
| 123 (before_cancel_spacing + cancel_button_->GetPreferredSize().width())); | 123 (before_cancel_spacing + cancel_button_->GetPreferredSize().width())); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void ConfirmInfoBar::LinkClicked(views::Link* source, int event_flags) { | 126 void ConfirmInfoBar::LinkClicked(views::Link* source, int event_flags) { |
| 127 if (!owned()) | 127 if (!owner()) |
| 128 return; // We're closing; don't call anything, it might access the owner. | 128 return; // We're closing; don't call anything, it might access the owner. |
| 129 DCHECK(link_ != NULL); | 129 DCHECK(link_ != NULL); |
| 130 DCHECK_EQ(link_, source); | 130 DCHECK_EQ(link_, source); |
| 131 if (GetDelegate()->LinkClicked(ui::DispositionFromEventFlags(event_flags))) | 131 if (GetDelegate()->LinkClicked(ui::DispositionFromEventFlags(event_flags))) |
| 132 RemoveSelf(); | 132 RemoveSelf(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() { | 135 ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() { |
| 136 return delegate()->AsConfirmInfoBarDelegate(); | 136 return delegate()->AsConfirmInfoBarDelegate(); |
| 137 } | 137 } |
| OLD | NEW |