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/notifications/balloon_view.h" | 5 #include "chrome/browser/ui/views/notifications/balloon_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 views::BubbleBorder* bubble_border = | 117 views::BubbleBorder* bubble_border = |
118 new views::BubbleBorder(views::BubbleBorder::FLOAT, | 118 new views::BubbleBorder(views::BubbleBorder::FLOAT, |
119 views::BubbleBorder::NO_SHADOW); | 119 views::BubbleBorder::NO_SHADOW); |
120 set_border(bubble_border); | 120 set_border(bubble_border); |
121 } | 121 } |
122 | 122 |
123 BalloonViewImpl::~BalloonViewImpl() { | 123 BalloonViewImpl::~BalloonViewImpl() { |
124 } | 124 } |
125 | 125 |
126 void BalloonViewImpl::Close(bool by_user) { | 126 void BalloonViewImpl::Close(bool by_user) { |
| 127 animation_->Stop(); |
| 128 html_contents_->Shutdown(); |
| 129 // Detach contents from widget before then close. |
| 130 // This is necessary because a widget may be deleted |
| 131 // after this when chrome is shutting down. |
| 132 html_container_->GetRootView()->RemoveAllChildViews(true); |
| 133 html_container_->Close(); |
| 134 frame_container_->GetRootView()->RemoveAllChildViews(true); |
| 135 frame_container_->Close(); |
| 136 // Post the tast at the end to sure this this WidgetDelegate |
| 137 // instance is avaiable when Widget::CloseNow gets called. |
127 MessageLoop::current()->PostTask(FROM_HERE, | 138 MessageLoop::current()->PostTask(FROM_HERE, |
128 base::Bind(&BalloonViewImpl::DelayedClose, | 139 base::Bind(&BalloonViewImpl::DelayedClose, |
129 method_factory_.GetWeakPtr(), | 140 method_factory_.GetWeakPtr(), |
130 by_user)); | 141 by_user)); |
131 } | 142 } |
132 | 143 |
133 gfx::Size BalloonViewImpl::GetSize() const { | 144 gfx::Size BalloonViewImpl::GetSize() const { |
134 // BalloonView has no size if it hasn't been shown yet (which is when | 145 // BalloonView has no size if it hasn't been shown yet (which is when |
135 // balloon_ is set). | 146 // balloon_ is set). |
136 if (!balloon_) | 147 if (!balloon_) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 180 } |
170 | 181 |
171 void BalloonViewImpl::ButtonPressed(views::Button* sender, | 182 void BalloonViewImpl::ButtonPressed(views::Button* sender, |
172 const views::Event&) { | 183 const views::Event&) { |
173 // The only button currently is the close button. | 184 // The only button currently is the close button. |
174 DCHECK(sender == close_button_); | 185 DCHECK(sender == close_button_); |
175 Close(true); | 186 Close(true); |
176 } | 187 } |
177 | 188 |
178 void BalloonViewImpl::DelayedClose(bool by_user) { | 189 void BalloonViewImpl::DelayedClose(bool by_user) { |
179 html_contents_->Shutdown(); | |
180 html_container_->CloseNow(); | |
181 // The BalloonViewImpl has to be detached from frame_container_ now | |
182 // because CloseNow on linux/views destroys the view hierachy | |
183 // asynchronously. | |
184 frame_container_->GetRootView()->RemoveAllChildViews(true); | |
185 frame_container_->CloseNow(); | |
186 balloon_->OnClose(by_user); | 190 balloon_->OnClose(by_user); |
187 } | 191 } |
188 | 192 |
189 gfx::Size BalloonViewImpl::GetPreferredSize() { | 193 gfx::Size BalloonViewImpl::GetPreferredSize() { |
190 return gfx::Size(1000, 1000); | 194 return gfx::Size(1000, 1000); |
191 } | 195 } |
192 | 196 |
193 void BalloonViewImpl::SizeContentsWindow() { | 197 void BalloonViewImpl::SizeContentsWindow() { |
194 if (!html_container_ || !frame_container_) | 198 if (!html_container_ || !frame_container_) |
195 return; | 199 return; |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 return; | 532 return; |
529 } | 533 } |
530 | 534 |
531 // If the renderer process attached to this balloon is disconnected | 535 // If the renderer process attached to this balloon is disconnected |
532 // (e.g., because of a crash), we want to close the balloon. | 536 // (e.g., because of a crash), we want to close the balloon. |
533 notification_registrar_.Remove( | 537 notification_registrar_.Remove( |
534 this, chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, | 538 this, chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, |
535 content::Source<Balloon>(balloon_)); | 539 content::Source<Balloon>(balloon_)); |
536 Close(false); | 540 Close(false); |
537 } | 541 } |
OLD | NEW |