Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: src/engine/NotificationWindow.cpp

Issue 6505394822184960: Issue 1109 - Support notifications (Closed)
Left Patch Set: add border and shadow and remove title background Created July 3, 2015, 1:37 p.m.
Right Patch Set: fix obtaining of DPI value of content (NotificationWindow) of NotificationBorderWindow Created Aug. 18, 2015, 9:43 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
1 #include <cassert> 18 #include <cassert>
2 #include "NotificationWindow.h" 19 #include "NotificationWindow.h"
3 #include "../shared/Utils.h" 20 #include "../shared/Utils.h"
4 #include <algorithm> 21 #include <algorithm>
5 #include <fstream> 22 #include <fstream>
6 #include "../shared/MsHTMLUtils.h" 23 #include "../shared/MsHTMLUtils.h"
7 24
8 // it is taken from src/plugin/Resource.h 25 // it is taken from src/plugin/Resource.h
9 #define IDI_ICON_ENABLED 301 26 #define IDI_ICON_ENABLED 301
10 27
11 namespace { 28 namespace {
12 // DIP = device independant pixels, as DPI is 96 29 // DIP = device independant pixels, as DPI is 96
13 const uint32_t kWindowWidth = 400 /*DIP*/; 30 const uint32_t kWindowWidth = 400 /*DIP*/;
14 const uint32_t kWindowHeight = 120 /*DIP*/; 31 const uint32_t kWindowHeight = 120 /*DIP*/;
15 const uint32_t kIconSize = 64 /*DIP*/; 32 const uint32_t kIconSize = 64 /*DIP*/;
33 const uint32_t kIconPadding = 10 /*DIP*/;
16 34
17 // offsets from boundaries of working area of screen 35 // offsets from boundaries of working area of screen
18 const uint32_t kWindowMarginRight = 50 /*DIP*/; 36 const uint32_t kWindowMarginRight = 50 /*DIP*/;
19 const uint32_t kWindowMarginBottom = 20 /*DIP*/; 37 const uint32_t kWindowMarginBottom = 20 /*DIP*/;
20 38
21 std::vector<uint16_t> iconSizes = []()->std::vector<uint16_t> 39 std::vector<uint16_t> iconSizes = []()->std::vector<uint16_t>
22 { 40 {
23 std::vector<uint16_t> iconSizes; 41 std::vector<uint16_t> iconSizes;
24 iconSizes.emplace_back(16); 42 iconSizes.emplace_back(16);
25 iconSizes.emplace_back(19); 43 iconSizes.emplace_back(19);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 assert(linkIDCounter == m_links.size() && "The amount of links in the text is different from the amount of provided links"); 135 assert(linkIDCounter == m_links.size() && "The amount of links in the text is different from the amount of provided links");
118 m_htmlPage = ReplaceMulti(m_htmlPage, L"<!--Title-->", ToUtf16String(notificat ion.GetTitle())); 136 m_htmlPage = ReplaceMulti(m_htmlPage, L"<!--Title-->", ToUtf16String(notificat ion.GetTitle()));
119 m_htmlPage = ReplaceMulti(m_htmlPage, L"<!--Body-->", body); 137 m_htmlPage = ReplaceMulti(m_htmlPage, L"<!--Body-->", body);
120 } 138 }
121 139
122 NotificationWindow::~NotificationWindow() 140 NotificationWindow::~NotificationWindow()
123 { 141 {
124 } 142 }
125 143
126 LRESULT NotificationWindow::OnCreate(const CREATESTRUCT* /*createStruct*/) { 144 LRESULT NotificationWindow::OnCreate(const CREATESTRUCT* /*createStruct*/) {
145 {
146 DCHandle hdc(GetDC());
147 m_dpi = hdc.GetDeviceCaps(LOGPIXELSX);
148 }
127 m_bgColor.CreateSolidBrush(RGB(255, 255, 255)); 149 m_bgColor.CreateSolidBrush(RGB(255, 255, 255));
128 150
129 m_icon.Create(m_hWnd, 151 CRect iconRect(CPoint(0, 0), CSize(kIconSize + 2 * kIconPadding, kIconSize + 2 * kIconPadding));
130 DPIAware(CRect(CPoint(0, 0), CSize(kIconSize, kIconSize))), 152 m_icon.Create(m_hWnd, DPIAware(iconRect), nullptr, WS_CHILD | WS_VISIBLE | SS_ BITMAP | SS_CENTERIMAGE);
131 nullptr, WS_CHILD | WS_VISIBLE | SS_BITMAP | SS_CENTERIMAGE);
132 LoadABPIcon(); 153 LoadABPIcon();
133 154
134 m_axIE.Create(m_hWnd, DPIAware(CRect(CPoint(kIconSize, 0), CSize(kWindowWidth - kIconSize, kWindowHeight))), 155 m_axIE.Create(m_hWnd, DPIAware(CRect(CPoint(iconRect.right, 0), CSize(kWindowW idth - iconRect.right, kWindowHeight))),
135 L"", WS_CHILD | WS_VISIBLE, 0, kHTMLDocumentCtrlID); 156 L"", WS_CHILD | WS_VISIBLE, 0, kHTMLDocumentCtrlID);
136 m_axIE.CreateControl((L"mshtml:" + m_htmlPage).c_str()); 157 m_axIE.CreateControl((L"mshtml:" + m_htmlPage).c_str());
137 ATL::CComPtr<IAxWinAmbientDispatch> axWinAmbient; 158 ATL::CComPtr<IAxWinAmbientDispatch> axWinAmbient;
138 if (SUCCEEDED(m_axIE.QueryHost(&axWinAmbient))) { 159 if (SUCCEEDED(m_axIE.QueryHost(&axWinAmbient))) {
139 // disable web browser context menu 160 // disable web browser context menu
140 axWinAmbient->put_AllowContextMenu(VARIANT_FALSE); 161 axWinAmbient->put_AllowContextMenu(VARIANT_FALSE);
141 // make web browser DPI aware, so the browser itself sets zoom level and 162 // make web browser DPI aware, so the browser itself sets zoom level and
142 // cares about rendering (not zooming) in the proper size. 163 // cares about rendering (not zooming) in the proper size.
143 DWORD docFlags; 164 DWORD docFlags;
144 axWinAmbient->get_DocHostFlags(&docFlags); 165 axWinAmbient->get_DocHostFlags(&docFlags);
(...skipping 20 matching lines...) Expand all
165 186
166 LRESULT NotificationWindow::OnClick(UINT /*msg*/, WPARAM /*wParam*/, LPARAM /*lP aram*/, BOOL& /*handled*/) 187 LRESULT NotificationWindow::OnClick(UINT /*msg*/, WPARAM /*wParam*/, LPARAM /*lP aram*/, BOOL& /*handled*/)
167 { 188 {
168 if(m_onClickCallback) 189 if(m_onClickCallback)
169 m_onClickCallback(); 190 m_onClickCallback();
170 return 0; 191 return 0;
171 } 192 }
172 193
173 void NotificationWindow::OnSize(uint32_t wParam, CSize size) 194 void NotificationWindow::OnSize(uint32_t wParam, CSize size)
174 { 195 {
196 if (m_icon)
197 {
198 CRect rect(CPoint(0, 0), DPIAware(CSize(kIconSize + 2 * kIconPadding, kIconS ize + 2 * kIconPadding)));
199 m_icon.SetWindowPos(0, &rect, SWP_NOMOVE);
200 }
175 if (m_axIE) 201 if (m_axIE)
176 { 202 {
177 size.cx -= kIconSize; 203 size.cx -= DPIAware(kIconSize + 2 * kIconPadding);
178 CRect rect(CPoint(0, 0), size); 204 CRect rect(CPoint(0, 0), size);
179 m_axIE.SetWindowPos(0, &rect, SWP_NOMOVE); 205 m_axIE.SetWindowPos(0, &rect, SWP_NOMOVE);
180 } 206 }
181 SetMsgHandled(false); 207 SetMsgHandled(false);
182 } 208 }
183 209
184 void NotificationWindow::OnDestroy() 210 void NotificationWindow::OnDestroy()
185 { 211 {
186 AtlAdviseSinkMap(this, false); 212 AtlAdviseSinkMap(this, false);
187 // and proceed as usual 213 // and proceed as usual
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 if (hIcon == nullptr) 282 if (hIcon == nullptr)
257 { 283 {
258 return; 284 return;
259 } 285 }
260 286
261 HDC screenDC = m_icon.GetDC(); 287 HDC screenDC = m_icon.GetDC();
262 DCHandle tmpDC(::CreateCompatibleDC(screenDC)); 288 DCHandle tmpDC(::CreateCompatibleDC(screenDC));
263 ScopedObjectHandle<HBITMAP> bitmap; 289 ScopedObjectHandle<HBITMAP> bitmap;
264 bitmap = CreateCompatibleBitmap(screenDC, DPIAware(kIconSize), DPIAware(kIconS ize)); 290 bitmap = CreateCompatibleBitmap(screenDC, DPIAware(kIconSize), DPIAware(kIconS ize));
265 HBITMAP prevBitmap = tmpDC.SelectBitmap(bitmap); 291 HBITMAP prevBitmap = tmpDC.SelectBitmap(bitmap);
266 RECT tmpRect = {0, 0, DPIAware(kIconSize), DPIAware(kIconSize)}; 292 CRect tmpRect(CPoint(0, 0), DPIAware(CSize(kIconSize, kIconSize)));
267 FillRect(tmpDC, &tmpRect, m_bgColor); 293 FillRect(tmpDC, &tmpRect, m_bgColor);
268 ::DrawIconEx(tmpDC, 0, 0, hIcon, DPIAware(kIconSize), DPIAware(kIconSize), 0, nullptr, DI_NORMAL); 294 ::DrawIconEx(tmpDC, 0, 0, hIcon, tmpRect.Width(), tmpRect.Height(), 0, nullptr , DI_NORMAL);
269 m_iconImg.Attach(bitmap.Detach()); 295 m_iconImg.Attach(bitmap.Detach());
270 tmpDC.SelectBitmap(prevBitmap); 296 tmpDC.SelectBitmap(prevBitmap);
271 m_icon.SetBitmap(m_iconImg); 297 m_icon.SetBitmap(m_iconImg);
272 } 298 }
273 299
274 POINT NotificationBorderWindow::GetWindowCoordinates() { 300 POINT NotificationBorderWindow::GetWindowCoordinates() {
275 HMONITOR primaryMonitor = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTOPRIMARY); 301 HMONITOR primaryMonitor = MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTOPRIMARY);
276 { 302 {
277 DCHandle hdc(GetDC()); 303 DCHandle hdc(GetDC());
278 m_dpi = hdc.GetDeviceCaps(LOGPIXELSX); 304 m_dpi = hdc.GetDeviceCaps(LOGPIXELSX);
Oleksandr 2015/08/18 11:47:40 Is this still needed, seeing that we now get dpi i
sergei 2015/08/18 11:58:40 It's a little bit odd. `GetWindowCoordinates` is a
279 } 305 }
280 MONITORINFO monitorInfo = {}; 306 MONITORINFO monitorInfo = {};
281 monitorInfo.cbSize = sizeof(monitorInfo); 307 monitorInfo.cbSize = sizeof(monitorInfo);
282 GetMonitorInfo(primaryMonitor, &monitorInfo); 308 GetMonitorInfo(primaryMonitor, &monitorInfo);
283 int windowX = monitorInfo.rcWork.right - DPIAware(kWindowWidth + kWindowMargin Right); 309 int windowX = monitorInfo.rcWork.right - DPIAware(kWindowWidth + kWindowMargin Right);
284 int windowY = monitorInfo.rcWork.bottom - DPIAware(kWindowHeight + kWindowMarg inBottom); 310 int windowY = monitorInfo.rcWork.bottom - DPIAware(kWindowHeight + kWindowMarg inBottom);
285 POINT coords = {windowX, windowY}; 311 POINT coords = {windowX, windowY};
286 return coords; 312 return coords;
287 } 313 }
288 314
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 { 362 {
337 DestroyWindow(); 363 DestroyWindow();
338 return 0; 364 return 0;
339 } 365 }
340 366
341 void NotificationBorderWindow::OnFinalMessage(HWND) { 367 void NotificationBorderWindow::OnFinalMessage(HWND) {
342 if (!!m_onDestroyedCallback) { 368 if (!!m_onDestroyedCallback) {
343 m_onDestroyedCallback(); 369 m_onDestroyedCallback();
344 } 370 }
345 } 371 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld