win32_notification.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #define WIN32_LEAN_AND_MEAN
  2. #include "brightray/browser/win/win32_notification.h"
  3. #include <windows.h>
  4. #include <string>
  5. #include <vector>
  6. #include "third_party/skia/include/core/SkBitmap.h"
  7. namespace brightray {
  8. void Win32Notification::Show(const NotificationOptions& options) {
  9. auto presenter = static_cast<NotificationPresenterWin7*>(this->presenter());
  10. if (!presenter)
  11. return;
  12. HBITMAP image = NULL;
  13. if (!options.icon.drawsNothing()) {
  14. if (options.icon.colorType() == kBGRA_8888_SkColorType) {
  15. BITMAPINFOHEADER bmi = {sizeof(BITMAPINFOHEADER)};
  16. bmi.biWidth = options.icon.width();
  17. bmi.biHeight = -options.icon.height();
  18. bmi.biPlanes = 1;
  19. bmi.biBitCount = 32;
  20. bmi.biCompression = BI_RGB;
  21. HDC hdcScreen = GetDC(NULL);
  22. image =
  23. CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, options.icon.getPixels(),
  24. reinterpret_cast<BITMAPINFO*>(&bmi), DIB_RGB_COLORS);
  25. ReleaseDC(NULL, hdcScreen);
  26. }
  27. }
  28. Win32Notification* existing = nullptr;
  29. if (!options.tag.empty())
  30. existing = presenter->GetNotificationObjectByTag(options.tag);
  31. if (existing) {
  32. existing->tag_.clear();
  33. this->notification_ref_ = std::move(existing->notification_ref_);
  34. this->notification_ref_.Set(options.title, options.msg, image);
  35. } else {
  36. this->notification_ref_ =
  37. presenter->AddNotification(options.title, options.msg, image);
  38. }
  39. this->tag_ = options.tag;
  40. if (image)
  41. DeleteObject(image);
  42. }
  43. void Win32Notification::Dismiss() {
  44. notification_ref_.Close();
  45. }
  46. } // namespace brightray