Refactor notification options

This commit is contained in:
Samuel Attard 2017-06-24 21:03:27 +10:00
parent b8be81f101
commit 7eb14243eb
11 changed files with 80 additions and 116 deletions

View file

@ -10,50 +10,49 @@
namespace brightray {
void Win32Notification::Show(
const base::string16& title, const base::string16& msg,
const std::string& tag, const GURL& icon_url,
const SkBitmap& icon, bool silent,
bool has_reply, const base::string16& reply_placeholder,
const std::vector<NotificationAction> actions) {
void Win32Notification::Show(const NotificationOptions& options) {
auto presenter = static_cast<NotificationPresenterWin7*>(this->presenter());
if (!presenter) return;
HBITMAP image = NULL;
if (!icon.drawsNothing()) {
if (icon.colorType() == kBGRA_8888_SkColorType) {
icon.lockPixels();
if (!options.icon.drawsNothing()) {
if (options.icon.colorType() == kBGRA_8888_SkColorType) {
options.icon.lockPixels();
BITMAPINFOHEADER bmi = { sizeof(BITMAPINFOHEADER) };
bmi.biWidth = icon.width();
bmi.biHeight = -icon.height();
bmi.biWidth = options.icon.width();
bmi.biHeight = -options.icon.height();
bmi.biPlanes = 1;
bmi.biBitCount = 32;
bmi.biCompression = BI_RGB;
HDC hdcScreen = GetDC(NULL);
image = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, icon.getPixels(),
image = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT,
options.icon.getPixels(),
reinterpret_cast<BITMAPINFO*>(&bmi),
DIB_RGB_COLORS);
ReleaseDC(NULL, hdcScreen);
icon.unlockPixels();
options.icon.unlockPixels();
}
}
Win32Notification* existing = nullptr;
if (!tag.empty()) existing = presenter->GetNotificationObjectByTag(tag);
if (!options.tag.empty())
existing = presenter->GetNotificationObjectByTag(options.tag);
if (existing) {
existing->tag_.clear();
this->notification_ref_ = std::move(existing->notification_ref_);
this->notification_ref_.Set(title, msg, image);
this->notification_ref_.Set(options.title, options.msg, image);
} else {
this->notification_ref_ = presenter->AddNotification(title, msg, image);
this->notification_ref_ = presenter->AddNotification(options.title,
options.msg,
image);
}
this->tag_ = tag;
this->tag_ = options.tag;
if (image) DeleteObject(image);
}