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/global_error_bubble_view.h" | 5 #include "chrome/browser/ui/views/global_error_bubble_view.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/ui/global_error/global_error.h" | 10 #include "chrome/browser/ui/global_error/global_error.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 message_labels.push_back(message_label); | 95 message_labels.push_back(message_label); |
96 } | 96 } |
97 | 97 |
98 base::string16 accept_string(error_->GetBubbleViewAcceptButtonLabel()); | 98 base::string16 accept_string(error_->GetBubbleViewAcceptButtonLabel()); |
99 scoped_ptr<views::LabelButton> accept_button( | 99 scoped_ptr<views::LabelButton> accept_button( |
100 new views::LabelButton(this, accept_string)); | 100 new views::LabelButton(this, accept_string)); |
101 accept_button->SetStyle(views::Button::STYLE_BUTTON); | 101 accept_button->SetStyle(views::Button::STYLE_BUTTON); |
102 accept_button->SetIsDefault(true); | 102 accept_button->SetIsDefault(true); |
103 accept_button->set_tag(TAG_ACCEPT_BUTTON); | 103 accept_button->set_tag(TAG_ACCEPT_BUTTON); |
104 if (error_->ShouldAddElevationIconToAcceptButton()) | 104 if (error_->ShouldAddElevationIconToAcceptButton()) |
105 elevation_icon_setter_.reset(new ElevationIconSetter(accept_button.get())); | 105 elevation_icon_setter_.reset( |
106 new ElevationIconSetter( | |
107 accept_button.get(), | |
108 base::Bind(&GlobalErrorBubbleView::UpdateBound, AsWeakPtr()))); | |
Peter Kasting
2015/02/21 01:06:27
Why not just pass &views::BubbleDelegateView::Size
xiaoling
2015/02/21 01:15:00
Because the function is the protected. Is there an
Peter Kasting
2015/02/21 01:21:49
Sorry, try passing &GlobalErrorBubbleView::SizeToC
xiaoling
2015/02/23 18:19:41
Thanks for the trick. It worked, although I'm not
| |
106 | 109 |
107 base::string16 cancel_string(error_->GetBubbleViewCancelButtonLabel()); | 110 base::string16 cancel_string(error_->GetBubbleViewCancelButtonLabel()); |
108 scoped_ptr<views::LabelButton> cancel_button; | 111 scoped_ptr<views::LabelButton> cancel_button; |
109 if (!cancel_string.empty()) { | 112 if (!cancel_string.empty()) { |
110 cancel_button.reset(new views::LabelButton(this, cancel_string)); | 113 cancel_button.reset(new views::LabelButton(this, cancel_string)); |
111 cancel_button->SetStyle(views::Button::STYLE_BUTTON); | 114 cancel_button->SetStyle(views::Button::STYLE_BUTTON); |
112 cancel_button->set_tag(TAG_CANCEL_BUTTON); | 115 cancel_button->set_tag(TAG_CANCEL_BUTTON); |
113 } | 116 } |
114 | 117 |
115 views::GridLayout* layout = new views::GridLayout(this); | 118 views::GridLayout* layout = new views::GridLayout(this); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 // Adjust the message label size in case buttons are too long. | 165 // Adjust the message label size in case buttons are too long. |
163 for (size_t i = 0; i < message_labels.size(); ++i) | 166 for (size_t i = 0; i < message_labels.size(); ++i) |
164 message_labels[i]->SizeToFit(layout->GetPreferredSize(this).width()); | 167 message_labels[i]->SizeToFit(layout->GetPreferredSize(this).width()); |
165 | 168 |
166 // These bubbles show at times where activation is sporadic (like at startup, | 169 // These bubbles show at times where activation is sporadic (like at startup, |
167 // or a new window opening). Make sure the bubble doesn't disappear before the | 170 // or a new window opening). Make sure the bubble doesn't disappear before the |
168 // user sees it, if the bubble needs to be acknowledged. | 171 // user sees it, if the bubble needs to be acknowledged. |
169 set_close_on_deactivate(error_->ShouldCloseOnDeactivate()); | 172 set_close_on_deactivate(error_->ShouldCloseOnDeactivate()); |
170 } | 173 } |
171 | 174 |
175 void GlobalErrorBubbleView::UpdateBound() { | |
176 views::BubbleDelegateView::SizeToContents(); | |
177 } | |
178 | |
172 GlobalErrorBubbleView::~GlobalErrorBubbleView() { | 179 GlobalErrorBubbleView::~GlobalErrorBubbleView() { |
173 // |elevation_icon_setter_| references |accept_button_|, so make sure it is | 180 // |elevation_icon_setter_| references |accept_button_|, so make sure it is |
174 // destroyed before |accept_button_|. | 181 // destroyed before |accept_button_|. |
175 elevation_icon_setter_.reset(); | 182 elevation_icon_setter_.reset(); |
176 } | 183 } |
177 | 184 |
178 void GlobalErrorBubbleView::ButtonPressed(views::Button* sender, | 185 void GlobalErrorBubbleView::ButtonPressed(views::Button* sender, |
179 const ui::Event& event) { | 186 const ui::Event& event) { |
180 if (error_) { | 187 if (error_) { |
181 if (sender->tag() == TAG_ACCEPT_BUTTON) | 188 if (sender->tag() == TAG_ACCEPT_BUTTON) |
(...skipping 11 matching lines...) Expand all Loading... | |
193 error_->BubbleViewDidClose(browser_); | 200 error_->BubbleViewDidClose(browser_); |
194 } | 201 } |
195 | 202 |
196 bool GlobalErrorBubbleView::ShouldShowCloseButton() const { | 203 bool GlobalErrorBubbleView::ShouldShowCloseButton() const { |
197 return error_ && error_->ShouldShowCloseButton(); | 204 return error_ && error_->ShouldShowCloseButton(); |
198 } | 205 } |
199 | 206 |
200 void GlobalErrorBubbleView::CloseBubbleView() { | 207 void GlobalErrorBubbleView::CloseBubbleView() { |
201 GetWidget()->Close(); | 208 GetWidget()->Close(); |
202 } | 209 } |
OLD | NEW |