Chromium Code Reviews| 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_views.h" | 5 #include "chrome/browser/ui/views/notifications/balloon_view_views.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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 const SkColor kControlBarSeparatorLineColor = SkColorSetRGB(180, 180, 180); | 86 const SkColor kControlBarSeparatorLineColor = SkColorSetRGB(180, 180, 180); |
| 87 | 87 |
| 88 } // namespace | 88 } // namespace |
| 89 | 89 |
| 90 BalloonViewImpl::BalloonViewImpl(BalloonCollection* collection) | 90 BalloonViewImpl::BalloonViewImpl(BalloonCollection* collection) |
| 91 : balloon_(NULL), | 91 : balloon_(NULL), |
| 92 collection_(collection), | 92 collection_(collection), |
| 93 frame_container_(NULL), | 93 frame_container_(NULL), |
| 94 html_container_(NULL), | 94 html_container_(NULL), |
| 95 html_contents_(NULL), | 95 html_contents_(NULL), |
| 96 method_factory_(this), | |
| 97 close_button_(NULL), | 96 close_button_(NULL), |
| 98 animation_(NULL), | 97 animation_(NULL), |
| 99 options_menu_model_(NULL), | 98 options_menu_model_(NULL), |
| 100 options_menu_button_(NULL), | 99 options_menu_button_(NULL), |
| 101 enable_web_ui_(false) { | 100 enable_web_ui_(false), |
| 102 // This object is not to be deleted by the views hierarchy, | 101 closed_by_user_(false) { |
| 103 // as it is owned by the balloon. | 102 // We're owned by Balloon and don't want to be deleted by our parent View. |
| 104 set_owned_by_client(); | 103 set_owned_by_client(); |
| 105 | 104 |
| 106 views::BubbleBorder* bubble_border = | 105 views::BubbleBorder* bubble_border = |
| 107 new views::BubbleBorder(views::BubbleBorder::FLOAT, | 106 new views::BubbleBorder(views::BubbleBorder::FLOAT, |
| 108 views::BubbleBorder::NO_SHADOW); | 107 views::BubbleBorder::NO_SHADOW); |
| 109 set_border(bubble_border); | 108 set_border(bubble_border); |
| 110 } | 109 } |
| 111 | 110 |
| 112 BalloonViewImpl::~BalloonViewImpl() { | 111 BalloonViewImpl::~BalloonViewImpl() { |
| 113 } | 112 } |
| 114 | 113 |
| 115 void BalloonViewImpl::Close(bool by_user) { | 114 void BalloonViewImpl::Close(bool by_user) { |
| 116 animation_->Stop(); | 115 animation_->Stop(); |
| 117 html_contents_->Shutdown(); | 116 html_contents_->Shutdown(); |
| 118 // Detach contents from widget before then close. | 117 // Detach contents from widget before then close. |
| 119 // This is necessary because a widget may be deleted | 118 // This is necessary because a widget may be deleted |
| 120 // after this when chrome is shutting down. | 119 // after this when chrome is shutting down. |
| 121 html_container_->GetRootView()->RemoveAllChildViews(true); | 120 html_container_->GetRootView()->RemoveAllChildViews(true); |
| 122 html_container_->Close(); | 121 html_container_->Close(); |
| 123 frame_container_->GetRootView()->RemoveAllChildViews(true); | 122 frame_container_->GetRootView()->RemoveAllChildViews(true); |
| 124 frame_container_->Close(); | 123 frame_container_->Close(); |
| 125 // Post the tast at the end to sure this this WidgetDelegate | 124 closed_by_user_ = by_user; |
| 126 // instance is avaiable when Widget::CloseNow gets called. | 125 // |frame_container_->::Close()| is async. When processed it'll call back to |
| 127 MessageLoop::current()->PostTask(FROM_HERE, | 126 // DeleteDelegate() and we'll cleanup. |
|
stevenjb
2012/10/16 16:43:41
nit: it will, we will
sky
2012/10/16 16:45:06
What's wrong with contractions?
stevenjb
2012/10/16 16:59:53
Strunk & White says don't use them :) But they can
| |
| 128 base::Bind(&BalloonViewImpl::DelayedClose, | |
| 129 method_factory_.GetWeakPtr(), | |
| 130 by_user)); | |
| 131 } | 127 } |
| 132 | 128 |
| 133 gfx::Size BalloonViewImpl::GetSize() const { | 129 gfx::Size BalloonViewImpl::GetSize() const { |
| 134 // BalloonView has no size if it hasn't been shown yet (which is when | 130 // BalloonView has no size if it hasn't been shown yet (which is when |
| 135 // balloon_ is set). | 131 // balloon_ is set). |
| 136 if (!balloon_) | 132 if (!balloon_) |
| 137 return gfx::Size(0, 0); | 133 return gfx::Size(0, 0); |
| 138 | 134 |
| 139 return gfx::Size(GetTotalWidth(), GetTotalHeight()); | 135 return gfx::Size(GetTotalWidth(), GetTotalHeight()); |
| 140 } | 136 } |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 162 } | 158 } |
| 163 | 159 |
| 164 void BalloonViewImpl::OnDisplayChanged() { | 160 void BalloonViewImpl::OnDisplayChanged() { |
| 165 collection_->DisplayChanged(); | 161 collection_->DisplayChanged(); |
| 166 } | 162 } |
| 167 | 163 |
| 168 void BalloonViewImpl::OnWorkAreaChanged() { | 164 void BalloonViewImpl::OnWorkAreaChanged() { |
| 169 collection_->DisplayChanged(); | 165 collection_->DisplayChanged(); |
| 170 } | 166 } |
| 171 | 167 |
| 168 void BalloonViewImpl::DeleteDelegate() { | |
| 169 balloon_->OnClose(closed_by_user_); | |
| 170 } | |
| 171 | |
| 172 void BalloonViewImpl::ButtonPressed(views::Button* sender, | 172 void BalloonViewImpl::ButtonPressed(views::Button* sender, |
| 173 const ui::Event&) { | 173 const ui::Event&) { |
| 174 // The only button currently is the close button. | 174 // The only button currently is the close button. |
| 175 DCHECK(sender == close_button_); | 175 DCHECK(sender == close_button_); |
| 176 Close(true); | 176 Close(true); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void BalloonViewImpl::DelayedClose(bool by_user) { | |
| 180 balloon_->OnClose(by_user); | |
| 181 } | |
| 182 | |
| 183 gfx::Size BalloonViewImpl::GetPreferredSize() { | 179 gfx::Size BalloonViewImpl::GetPreferredSize() { |
| 184 return gfx::Size(1000, 1000); | 180 return gfx::Size(1000, 1000); |
| 185 } | 181 } |
| 186 | 182 |
| 187 void BalloonViewImpl::SizeContentsWindow() { | 183 void BalloonViewImpl::SizeContentsWindow() { |
| 188 if (!html_container_ || !frame_container_) | 184 if (!html_container_ || !frame_container_) |
| 189 return; | 185 return; |
| 190 | 186 |
| 191 gfx::Rect contents_rect = GetContentsRectangle(); | 187 gfx::Rect contents_rect = GetContentsRectangle(); |
| 192 html_container_->SetBounds(contents_rect); | 188 html_container_->SetBounds(contents_rect); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 return; | 529 return; |
| 534 } | 530 } |
| 535 | 531 |
| 536 // If the renderer process attached to this balloon is disconnected | 532 // If the renderer process attached to this balloon is disconnected |
| 537 // (e.g., because of a crash), we want to close the balloon. | 533 // (e.g., because of a crash), we want to close the balloon. |
| 538 notification_registrar_.Remove( | 534 notification_registrar_.Remove( |
| 539 this, chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, | 535 this, chrome::NOTIFICATION_NOTIFY_BALLOON_DISCONNECTED, |
| 540 content::Source<Balloon>(balloon_)); | 536 content::Source<Balloon>(balloon_)); |
| 541 Close(false); | 537 Close(false); |
| 542 } | 538 } |
| OLD | NEW |