34 static PRLogModuleInfo* gWindowChromeServiceLog = nsnull;
35 #define TRACE(args) PR_LOG(gWindowChromeServiceLog, PR_LOG_DEBUG, args)
36 #define LOG(args) PR_LOG(gWindowChromeServiceLog, PR_LOG_WARN, args)
47 #include "../NativeWindowFromNode.h"
57 mDwmIsCompositionEnabled(NULL)
60 if (!gWindowChromeServiceLog) {
61 gWindowChromeServiceLog = PR_NewLogModule(
"sbWindowChromeService");
64 TRACE((
"sbWindowChromeService[0x%x] - ctor",
this));
68 "sbWindowChromeService constructed twice!");
75 "DwmIsCompositionEnabled");
80 sbWindowChromeService::~sbWindowChromeService()
93 if (!
self || !
self->mDwmIsCompositionEnabled) {
97 BOOL isDWMCompositionEnabled = FALSE;
98 HRESULT hr =
self->mDwmIsCompositionEnabled(&isDWMCompositionEnabled);
103 return isDWMCompositionEnabled != FALSE;
107 NS_IMETHODIMP sbWindowChromeService::HideChrome(
nsISupports *aWindow,
110 NS_ENSURE_ARG_POINTER(aWindow);
114 NS_ENSURE_TRUE(hWnd, NS_ERROR_INVALID_ARG);
117 LONG style = ::GetWindowLong(hWnd, GWL_STYLE);
118 BOOL success = ::SetWindowSubclass(hWnd,
122 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
127 ::SetWindowLong(hWnd, GWL_STYLE, style);
131 BOOL wasSubclassed = ::GetWindowSubclass(hWnd,
136 ::SetWindowLong(hWnd, GWL_STYLE, oldStyle);
137 BOOL success = ::RemoveWindowSubclass(hWnd,
140 NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
148 sbWindowChromeService::GetIsCompositionEnabled(PRBool *aIsCompositionEnabled)
150 NS_ENSURE_ARG_POINTER(aIsCompositionEnabled);
161 UINT_PTR uIdSubclass,
166 return DefSubclassProc(hWnd, uMsg, wParam, lParam);
168 TRACE((
"%s: WndProc(%p, %08x)", __FUNCTION__, hWnd, uMsg));
182 NCCALCSIZE_PARAMS* params = (NCCALCSIZE_PARAMS*)lParam;
183 bool willMinimize = (params->rgrc[0].left == -32000) &&
184 (params->rgrc[0].top == -32000);
189 if (IsZoomed(hWnd)) {
195 RECT* rectWindow = ¶ms->rgrc[0];
197 int xSize = ::GetSystemMetrics(SM_CXSIZEFRAME);
198 int ySize = ::GetSystemMetrics(SM_CYSIZEFRAME);
200 HMONITOR hMon = ::MonitorFromRect(rectWindow, MONITOR_DEFAULTTONULL);
202 MONITORINFO monInfo = {0};
203 monInfo.cbSize =
sizeof(monInfo);
204 BOOL success = ::GetMonitorInfo(hMon, &monInfo);
206 ::CopyRect(&rectMon, &monInfo.rcWork);
209 ::CopyRect(&rectMon, rectWindow);
214 ::CopyRect(&rectMon, rectWindow);
217 const LONG TOLERANCE = 2;
218 if (rectMon.
top > rectWindow->
top &&
219 rectMon.
top - rectWindow->
top < ySize + TOLERANCE)
221 rectWindow->
top += ySize;
224 rectWindow->
bottom - rectMon.
bottom < ySize + TOLERANCE)
226 rectWindow->
bottom -= ySize;
228 if (rectMon.
left > rectWindow->
left &&
229 rectMon.
left - rectWindow->
left < xSize + TOLERANCE)
231 rectWindow->
left += xSize;
234 rectWindow->
right - rectMon.
right < xSize + TOLERANCE)
236 rectWindow->
right -= xSize;
243 APPBARDATA appbarData = {
sizeof(APPBARDATA)};
244 appbarData.hWnd = hWnd;
247 HMONITOR selfMon = ::MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST),
250 appbarData.uEdge = ABE_TOP;
251 wnd = (HWND)::SHAppBarMessage(ABM_GETAUTOHIDEBAR, &appbarData);
253 targetMon = ::MonitorFromWindow(wnd, MONITOR_DEFAULTTONEAREST);
254 if (targetMon == selfMon) {
259 params->rgrc[0].bottom -= 1;
262 appbarData.uEdge = ABE_RIGHT;
263 wnd = (HWND)::SHAppBarMessage(ABM_GETAUTOHIDEBAR, &appbarData);
265 targetMon = ::MonitorFromWindow(wnd, MONITOR_DEFAULTTONEAREST);
266 if (targetMon == selfMon) {
267 params->rgrc[0].right -= 1;
270 appbarData.uEdge = ABE_BOTTOM;
271 wnd = (HWND)::SHAppBarMessage(ABM_GETAUTOHIDEBAR, &appbarData);
273 targetMon = ::MonitorFromWindow(wnd, MONITOR_DEFAULTTONEAREST);
274 if (targetMon == selfMon) {
275 params->rgrc[0].bottom -= 1;
278 appbarData.uEdge = ABE_LEFT;
279 wnd = (HWND)::SHAppBarMessage(ABM_GETAUTOHIDEBAR, &appbarData);
281 targetMon = ::MonitorFromWindow(wnd, MONITOR_DEFAULTTONEAREST);
282 if (targetMon == selfMon) {
283 params->rgrc[0].left += 1;
304 RECT rectMon = {0}, rectWindow;
305 BOOL success = ::GetWindowRect(hWnd, &rectWindow);
307 ::SetRect(&rectWindow, -1, -1, -1, -1);
310 HMONITOR hMon = ::MonitorFromWindow(hWnd, MONITOR_DEFAULTTONULL);
312 MONITORINFO monInfo = {0};
313 monInfo.cbSize =
sizeof(monInfo);
314 success = ::GetMonitorInfo(hMon, &monInfo);
316 ::CopyRect(&rectMon, &monInfo.rcMonitor);
319 if (!::EqualRect(&rectMon, &rectWindow)) {
320 return DefSubclassProc(hWnd, uMsg, wParam, lParam);
325 ::SetWindowTheme(hWnd, L
"", L
"");
333 TRACE((
"WM_NCPAINT(%p)", hWnd));
341 InvalidateRgn(hWnd, NULL, FALSE);
344 return DefSubclassProc(hWnd, uMsg, wParam, lParam);
353 return DefSubclassProc(hWnd, uMsg, wParam, lParam);
HRESULT(WINAPI * t_DwmIsCompositionEnabled)(BOOL *)
NS_IMPL_ISUPPORTS1(sbWindowChromeService, sbIWindowChromeService)
static nsresult LoadLibrary(nsCOMPtr< nsIFile > aLibDir, nsString aLibPath)
static LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
t_DwmIsCompositionEnabled mDwmIsCompositionEnabled
HRESULT(WINAPI * t_DwmIsCompositionEnabled)(BOOL *)
static bool IsCompositionEnabled(const sbWindowChromeService *self)
Component used to do platform-level tricks to hide the window chrome. Expected to only be used by sys...
static UINT_PTR gSubclassId
static void * get(nsISupports *window)
NS_DECL_ISUPPORTS NS_DECL_SBIWINDOWCHROMESERVICE sbWindowChromeService()