OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/tab_contents/confirm_infobar_delegate.h" | 8 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" |
9 #include "chrome/browser/ui/views/event_utils.h" | 9 #include "chrome/browser/ui/views/event_utils.h" |
10 #include "views/controls/button/text_button.h" | 10 #include "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 views::Event& event) { | 100 const views::Event& event) { |
| 101 if (!owned()) |
| 102 return; // We're closing; don't call anything, it might access the owner. |
101 ConfirmInfoBarDelegate* delegate = GetDelegate(); | 103 ConfirmInfoBarDelegate* delegate = GetDelegate(); |
102 if ((ok_button_ != NULL) && sender == ok_button_) { | 104 if ((ok_button_ != NULL) && sender == ok_button_) { |
103 if (delegate->Accept()) | 105 if (delegate->Accept()) |
104 RemoveSelf(); | 106 RemoveSelf(); |
105 } else if ((cancel_button_ != NULL) && (sender == cancel_button_)) { | 107 } else if ((cancel_button_ != NULL) && (sender == cancel_button_)) { |
106 if (delegate->Cancel()) | 108 if (delegate->Cancel()) |
107 RemoveSelf(); | 109 RemoveSelf(); |
108 } else { | 110 } else { |
109 InfoBarView::ButtonPressed(sender, event); | 111 InfoBarView::ButtonPressed(sender, event); |
110 } | 112 } |
111 } | 113 } |
112 | 114 |
113 int ConfirmInfoBar::ContentMinimumWidth() const { | 115 int ConfirmInfoBar::ContentMinimumWidth() const { |
114 int width = (link_ == NULL) ? 0 : kEndOfLabelSpacing; // Space before link | 116 int width = (link_ == NULL) ? 0 : kEndOfLabelSpacing; // Space before link |
115 int before_cancel_spacing = kEndOfLabelSpacing; | 117 int before_cancel_spacing = kEndOfLabelSpacing; |
116 if (ok_button_ != NULL) { | 118 if (ok_button_ != NULL) { |
117 width += kEndOfLabelSpacing + ok_button_->GetPreferredSize().width(); | 119 width += kEndOfLabelSpacing + ok_button_->GetPreferredSize().width(); |
118 before_cancel_spacing = kButtonButtonSpacing; | 120 before_cancel_spacing = kButtonButtonSpacing; |
119 } | 121 } |
120 return width + ((cancel_button_ == NULL) ? 0 : | 122 return width + ((cancel_button_ == NULL) ? 0 : |
121 (before_cancel_spacing + cancel_button_->GetPreferredSize().width())); | 123 (before_cancel_spacing + cancel_button_->GetPreferredSize().width())); |
122 } | 124 } |
123 | 125 |
124 void ConfirmInfoBar::LinkClicked(views::Link* source, int event_flags) { | 126 void ConfirmInfoBar::LinkClicked(views::Link* source, int event_flags) { |
| 127 if (!owned()) |
| 128 return; // We're closing; don't call anything, it might access the owner. |
125 DCHECK(link_ != NULL); | 129 DCHECK(link_ != NULL); |
126 DCHECK_EQ(link_, source); | 130 DCHECK_EQ(link_, source); |
127 if (GetDelegate()->LinkClicked( | 131 if (GetDelegate()->LinkClicked( |
128 event_utils::DispositionFromEventFlags(event_flags))) | 132 event_utils::DispositionFromEventFlags(event_flags))) |
129 RemoveSelf(); | 133 RemoveSelf(); |
130 } | 134 } |
131 | 135 |
132 ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() { | 136 ConfirmInfoBarDelegate* ConfirmInfoBar::GetDelegate() { |
133 return delegate()->AsConfirmInfoBarDelegate(); | 137 return delegate()->AsConfirmInfoBarDelegate(); |
134 } | 138 } |
OLD | NEW |