OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/notifications/balloon.h" | 5 #include "chrome/browser/notifications/balloon.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/notifications/balloon_collection.h" | 8 #include "chrome/browser/notifications/balloon_collection.h" |
9 #include "chrome/browser/notifications/notification.h" | 9 #include "chrome/browser/notifications/notification.h" |
10 #include "chrome/browser/renderer_host/site_instance.h" | 10 #include "chrome/browser/renderer_host/site_instance.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 Balloon::~Balloon() { | 21 Balloon::~Balloon() { |
22 } | 22 } |
23 | 23 |
24 void Balloon::SetPosition(const gfx::Point& upper_left, bool reposition) { | 24 void Balloon::SetPosition(const gfx::Point& upper_left, bool reposition) { |
25 position_ = upper_left; | 25 position_ = upper_left; |
26 if (reposition && balloon_view_.get()) | 26 if (reposition && balloon_view_.get()) |
27 balloon_view_->RepositionToBalloon(); | 27 balloon_view_->RepositionToBalloon(); |
28 } | 28 } |
29 | 29 |
30 void Balloon::SetContentPreferredSize(const gfx::Size& size) { | 30 void Balloon::SetContentPreferredSize(const gfx::Size& size) { |
31 gfx::Size new_size(size); | 31 collection_->ResizeBalloon(this, size); |
32 #if defined(OS_MACOSX) | |
33 // TODO(levin): Make all of the code that went in with this change to be | |
34 // cross-platform. See http://crbug.com/64720 | |
35 // Only allow the size of notifications to grow. This stops the balloon | |
36 // from jumping between sizes due to dynamic content. For example, the | |
37 // balloon's contents may adjust due to changes in | |
38 // document.body.clientHeight. | |
39 new_size.set_height(std::max(new_size.height(), content_size_.height())); | |
40 | |
41 if (content_size_ == new_size) | |
42 return; | |
43 #endif | |
44 collection_->ResizeBalloon(this, new_size); | |
45 } | 32 } |
46 | 33 |
47 void Balloon::set_view(BalloonView* balloon_view) { | 34 void Balloon::set_view(BalloonView* balloon_view) { |
48 balloon_view_.reset(balloon_view); | 35 balloon_view_.reset(balloon_view); |
49 } | 36 } |
50 | 37 |
51 void Balloon::Show() { | 38 void Balloon::Show() { |
52 notification_->Display(); | 39 notification_->Display(); |
53 if (balloon_view_.get()) { | 40 if (balloon_view_.get()) { |
54 balloon_view_->Show(this); | 41 balloon_view_->Show(this); |
(...skipping 18 matching lines...) Expand all Loading... |
73 notification_->Close(by_user); | 60 notification_->Close(by_user); |
74 collection_->OnBalloonClosed(this); | 61 collection_->OnBalloonClosed(this); |
75 } | 62 } |
76 | 63 |
77 void Balloon::CloseByScript() { | 64 void Balloon::CloseByScript() { |
78 // A user-initiated close begins with the view and then closes this object; | 65 // A user-initiated close begins with the view and then closes this object; |
79 // we simulate that with a script-initiated close but pass |by_user|=false. | 66 // we simulate that with a script-initiated close but pass |by_user|=false. |
80 DCHECK(balloon_view_.get()); | 67 DCHECK(balloon_view_.get()); |
81 balloon_view_->Close(false); | 68 balloon_view_->Close(false); |
82 } | 69 } |
OLD | NEW |