| 
									
										
										
										
											2017-03-15 13:56:06 +01:00
										 |  |  | #define WIN32_LEAN_AND_MEAN
 | 
					
						
							| 
									
										
										
										
											2017-05-18 15:06:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-18 15:58:12 -07:00
										 |  |  | #include "brightray/browser/win/win32_notification.h"
 | 
					
						
							| 
									
										
										
										
											2017-05-18 15:06:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-15 13:56:06 +01:00
										 |  |  | #include <windows.h>
 | 
					
						
							| 
									
										
										
										
											2017-05-18 15:06:57 -07:00
										 |  |  | #include <string>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-03 10:48:18 +02:00
										 |  |  | #include "third_party/skia/include/core/SkBitmap.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-15 13:56:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace brightray { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-03 10:38:21 +02:00
										 |  |  | void Win32Notification::Show( | 
					
						
							|  |  |  |     const base::string16& title, const base::string16& msg, | 
					
						
							|  |  |  |     const std::string& tag, const GURL& icon_url, | 
					
						
							| 
									
										
										
										
											2017-05-30 19:06:51 +10:00
										 |  |  |     const SkBitmap& icon, bool silent, | 
					
						
							|  |  |  |     bool has_reply, const base::string16& reply_placeholder) { | 
					
						
							| 
									
										
										
										
											2017-03-15 13:56:06 +01:00
										 |  |  |     auto presenter = static_cast<NotificationPresenterWin7*>(this->presenter()); | 
					
						
							| 
									
										
										
										
											2017-04-03 13:34:01 +02:00
										 |  |  |     if (!presenter) return; | 
					
						
							| 
									
										
										
										
											2017-03-15 13:56:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     HBITMAP image = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-03 13:34:01 +02:00
										 |  |  |     if (!icon.drawsNothing()) { | 
					
						
							|  |  |  |         if (icon.colorType() == kBGRA_8888_SkColorType) { | 
					
						
							| 
									
										
										
										
											2017-03-15 13:56:06 +01:00
										 |  |  |             icon.lockPixels(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             BITMAPINFOHEADER bmi = { sizeof(BITMAPINFOHEADER) }; | 
					
						
							|  |  |  |             bmi.biWidth = icon.width(); | 
					
						
							|  |  |  |             bmi.biHeight = -icon.height(); | 
					
						
							|  |  |  |             bmi.biPlanes = 1; | 
					
						
							|  |  |  |             bmi.biBitCount = 32; | 
					
						
							|  |  |  |             bmi.biCompression = BI_RGB; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             HDC hdcScreen = GetDC(NULL); | 
					
						
							| 
									
										
										
										
											2017-04-03 10:38:21 +02:00
										 |  |  |             image = CreateDIBitmap(hdcScreen, &bmi, CBM_INIT, icon.getPixels(), | 
					
						
							| 
									
										
										
										
											2017-04-05 11:53:37 +02:00
										 |  |  |                                    reinterpret_cast<BITMAPINFO*>(&bmi), | 
					
						
							|  |  |  |                                    DIB_RGB_COLORS); | 
					
						
							| 
									
										
										
										
											2017-03-15 13:56:06 +01:00
										 |  |  |             ReleaseDC(NULL, hdcScreen); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             icon.unlockPixels(); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Win32Notification* existing = nullptr; | 
					
						
							| 
									
										
										
										
											2017-04-03 13:34:01 +02:00
										 |  |  |     if (!tag.empty()) existing = presenter->GetNotificationObjectByTag(tag); | 
					
						
							| 
									
										
										
										
											2017-03-15 13:56:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-03 13:34:01 +02:00
										 |  |  |     if (existing) { | 
					
						
							| 
									
										
										
										
											2017-03-17 14:41:22 +01:00
										 |  |  |         existing->tag_.clear(); | 
					
						
							|  |  |  |         this->notification_ref_ = std::move(existing->notification_ref_); | 
					
						
							|  |  |  |         this->notification_ref_.Set(title, msg, image); | 
					
						
							| 
									
										
										
										
											2017-04-05 12:00:35 +02:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2017-03-17 14:41:22 +01:00
										 |  |  |         this->notification_ref_ = presenter->AddNotification(title, msg, image); | 
					
						
							| 
									
										
										
										
											2017-03-15 13:56:06 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-17 14:41:22 +01:00
										 |  |  |     this->tag_ = tag; | 
					
						
							| 
									
										
										
										
											2017-03-15 13:56:06 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-03 13:34:01 +02:00
										 |  |  |     if (image) DeleteObject(image); | 
					
						
							| 
									
										
										
										
											2017-03-15 13:56:06 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-03 12:11:39 +02:00
										 |  |  | void Win32Notification::Dismiss() { | 
					
						
							| 
									
										
										
										
											2017-03-17 14:41:22 +01:00
										 |  |  |     notification_ref_.Close(); | 
					
						
							| 
									
										
										
										
											2017-03-15 13:56:06 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-05 13:10:28 +02:00
										 |  |  | }   // namespace brightray
 |