• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/notifications/balloon.h"
6 
7 #include "base/logging.h"
8 #include "chrome/browser/notifications/balloon_collection.h"
9 #include "chrome/browser/notifications/notification.h"
10 #include "content/browser/site_instance.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/gfx/size.h"
13 
Balloon(const Notification & notification,Profile * profile,BalloonCollection * collection)14 Balloon::Balloon(const Notification& notification, Profile* profile,
15                  BalloonCollection* collection)
16     : profile_(profile),
17       notification_(new Notification(notification)),
18       collection_(collection) {
19 }
20 
~Balloon()21 Balloon::~Balloon() {
22 }
23 
SetPosition(const gfx::Point & upper_left,bool reposition)24 void Balloon::SetPosition(const gfx::Point& upper_left, bool reposition) {
25   position_ = upper_left;
26   if (reposition && balloon_view_.get())
27     balloon_view_->RepositionToBalloon();
28 }
29 
SetContentPreferredSize(const gfx::Size & size)30 void Balloon::SetContentPreferredSize(const gfx::Size& size) {
31   collection_->ResizeBalloon(this, size);
32 }
33 
set_view(BalloonView * balloon_view)34 void Balloon::set_view(BalloonView* balloon_view) {
35   balloon_view_.reset(balloon_view);
36 }
37 
Show()38 void Balloon::Show() {
39   notification_->Display();
40   if (balloon_view_.get()) {
41     balloon_view_->Show(this);
42     balloon_view_->RepositionToBalloon();
43   }
44 }
45 
Update(const Notification & notification)46 void Balloon::Update(const Notification& notification) {
47   notification_->Close(false);
48   notification_.reset(new Notification(notification));
49   notification_->Display();
50   if (balloon_view_.get()) {
51     balloon_view_->Update();
52   }
53 }
54 
OnClick()55 void Balloon::OnClick() {
56   notification_->Click();
57 }
58 
OnClose(bool by_user)59 void Balloon::OnClose(bool by_user) {
60   notification_->Close(by_user);
61   collection_->OnBalloonClosed(this);
62 }
63 
CloseByScript()64 void Balloon::CloseByScript() {
65   // A user-initiated close begins with the view and then closes this object;
66   // we simulate that with a script-initiated close but pass |by_user|=false.
67   DCHECK(balloon_view_.get());
68   balloon_view_->Close(false);
69 }
70