This source file includes following definitions.
- GetHorizontalMargin
- collection_
- SetPosition
- ResizeDueToAutoResize
- set_view
- Show
- Update
- OnClick
- OnClose
- OnButtonClick
- CloseByScript
- GetExtensionId
#include "chrome/browser/notifications/balloon.h"
#include "base/logging.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/notifications/balloon_collection.h"
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/profiles/profile.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#if !defined(USE_AURA)
int BalloonView::GetHorizontalMargin() {
return 0;
}
#endif
Balloon::Balloon(const Notification& notification, Profile* profile,
BalloonCollection* collection)
: profile_(profile),
notification_(new Notification(notification)),
collection_(collection) {
}
Balloon::~Balloon() {
}
void Balloon::SetPosition(const gfx::Point& upper_left, bool reposition) {
position_ = upper_left;
if (reposition && balloon_view_.get())
balloon_view_->RepositionToBalloon();
}
void Balloon::ResizeDueToAutoResize(const gfx::Size& size) {
collection_->ResizeBalloon(this, size);
}
void Balloon::set_view(BalloonView* balloon_view) {
balloon_view_.reset(balloon_view);
}
void Balloon::Show() {
notification_->Display();
if (balloon_view_.get()) {
balloon_view_->Show(this);
balloon_view_->RepositionToBalloon();
}
}
void Balloon::Update(const Notification& notification) {
notification_->Close(false);
notification_.reset(new Notification(notification));
notification_->Display();
if (balloon_view_.get()) {
balloon_view_->Update();
}
}
void Balloon::OnClick() {
notification_->Click();
}
void Balloon::OnClose(bool by_user) {
notification_->Close(by_user);
collection_->OnBalloonClosed(this);
}
void Balloon::OnButtonClick(int button_index) {
notification_->ButtonClick(button_index);
}
void Balloon::CloseByScript() {
DCHECK(balloon_view_.get());
balloon_view_->Close(false);
}
std::string Balloon::GetExtensionId() {
const ExtensionService* service = profile()->GetExtensionService();
const extensions::Extension* extension =
service->extensions()->GetExtensionOrAppByURL(
notification().origin_url());
return extension ? extension->id() : std::string();
}