Skip to content
This repository was archived by the owner on Sep 2, 2021. It is now read-only.

Commit d258997

Browse files
committed
Merge pull request #498 from adobe/jeff/various-fixes
fixes initial placement, move and size issues
2 parents 89977a9 + e8b88f9 commit d258997

File tree

4 files changed

+105
-2
lines changed

4 files changed

+105
-2
lines changed

appshell/cef_host_window.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,20 @@ BOOL cef_host_window::HandleSize(BOOL bMinimize)
168168
}
169169
SetProp(L"WasMinimized", (HANDLE)bMinimize);
170170
#endif
171+
NotifyWindowMovedOrResized();
172+
return FALSE;
173+
}
171174

175+
void cef_host_window::NotifyWindowMovedOrResized()
176+
{
177+
if (GetBrowser() && GetBrowser()->GetHost()) {
178+
GetBrowser()->GetHost()->NotifyMoveOrResizeStarted();
179+
}
180+
}
181+
182+
BOOL cef_host_window::HandleMoveOrMoving()
183+
{
184+
NotifyWindowMovedOrResized();
172185
return FALSE;
173186
}
174187

@@ -198,6 +211,11 @@ LRESULT cef_host_window::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
198211
if (HandleInitMenuPopup((HMENU)wParam))
199212
return 0L;
200213
break;
214+
case WM_MOVING:
215+
case WM_MOVE:
216+
if (HandleMoveOrMoving())
217+
return 0L;
218+
break;
201219
}
202220

203221

appshell/cef_host_window.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ class cef_host_window : public cef_host_window_base
6363
// Message Handlers
6464
BOOL HandleInitMenuPopup(HMENU hMenuPopup);
6565
BOOL HandleSize(BOOL bMinimize);
66+
BOOL HandleMoveOrMoving();
6667

6768
// Command Implementation
6869
BOOL DoCommand(UINT commandId, CefRefPtr<CommandCallback> callback = 0);
6970
BOOL DoCommand(const CefString& commandString, CefRefPtr<CommandCallback> callback = 0);
7071

7172
// Implementation
7273
virtual void DoRepaintClientArea();
74+
void NotifyWindowMovedOrResized();
7375

7476
// Helper to get a command string from command id
7577
CefString GetCommandString(UINT commandId);

appshell/cef_main_window.cpp

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,60 @@ LPCWSTR cef_main_window::GetBracketsWindowTitleText()
9999
return szTitle;
100100
}
101101

102+
void cef_main_window::EnsureWindowRectVisibility(int& left, int& top, int& width, int& height, int showCmd)
103+
{
104+
static const int kWindowFrameSize = 8;
105+
106+
// don't check if we're already letting
107+
// Windows determine the window placement
108+
if (left == CW_USEDEFAULT &&
109+
top == CW_USEDEFAULT &&
110+
width == CW_USEDEFAULT &&
111+
height == CW_USEDEFAULT) {
112+
return;
113+
}
114+
115+
// The virtual display is the bounding rect of all monitors
116+
// see http://msdn.microsoft.com/en-us/library/dd162729(v=vs.85).aspx
117+
118+
int xScreen = ::GetSystemMetrics(SM_XVIRTUALSCREEN);
119+
int yScreen = ::GetSystemMetrics(SM_YVIRTUALSCREEN);
120+
int cxScreen = ::GetSystemMetrics(SM_CXVIRTUALSCREEN);
121+
int cyScreen = ::GetSystemMetrics(SM_CYVIRTUALSCREEN);
122+
123+
// make a copy, we need to adjust the comparison
124+
// if it's a maximized window because the OS move the
125+
// origin of the window by 8 pixes to releive the borders
126+
// from the monitor for legacy apps
127+
int xLeft = left;
128+
int xTop = top;
129+
int xWidth = width;
130+
int xHeight = height;
131+
132+
if (showCmd == SW_MAXIMIZE) {
133+
xLeft += kWindowFrameSize;
134+
xTop += kWindowFrameSize;
135+
xWidth -= kWindowFrameSize * 2;
136+
xHeight -= kWindowFrameSize * 2;
137+
}
138+
139+
// Make sure the window fits inside the virtual screen.
140+
// If it doesn't then we let windows decide the window placement
141+
if (xLeft < xScreen ||
142+
xTop < yScreen ||
143+
xLeft + xWidth > xScreen + cxScreen ||
144+
xTop + xHeight > yScreen + cyScreen) {
145+
146+
// something was off-screen so reposition
147+
// to the default window placement
148+
left = CW_USEDEFAULT;
149+
top = CW_USEDEFAULT;
150+
width = CW_USEDEFAULT;
151+
height = CW_USEDEFAULT;
152+
}
153+
}
154+
155+
102156
// Create Method. Call this to create a cef_main_window instance
103157
BOOL cef_main_window::Create()
104158
{
@@ -108,10 +162,14 @@ BOOL cef_main_window::Create()
108162
int top = CW_USEDEFAULT;
109163
int width = CW_USEDEFAULT;
110164
int height = CW_USEDEFAULT;
165+
111166
int showCmd = SW_SHOW;
112167

113168
LoadWindowRestoreRect(left, top, width, height, showCmd);
114169

170+
// make sure the window is visible
171+
EnsureWindowRectVisibility(left, top, width, height, showCmd);
172+
115173
DWORD styles = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_EX_COMPOSITED;
116174

117175
if (showCmd == SW_MAXIMIZE)
@@ -353,8 +411,32 @@ void cef_main_window::RestoreWindowPlacement(int showCmd)
353411
GetRegistryInt(::kWindowPostionFolder, ::kPrefRestoreRight, NULL, (int&)wp.rcNormalPosition.right);
354412
GetRegistryInt(::kWindowPostionFolder, ::kPrefRestoreBottom, NULL, (int&)wp.rcNormalPosition.bottom);
355413

356-
// This returns FALSE on failure but not sure what we could do in that case
357-
SetWindowPlacement(&wp);
414+
::NormalizeRect(wp.rcNormalPosition);
415+
416+
int left = wp.rcNormalPosition.left;
417+
int top = wp.rcNormalPosition.top;
418+
int width = wp.rcNormalPosition.right - left;
419+
int height = wp.rcNormalPosition.bottom - top;
420+
421+
EnsureWindowRectVisibility(left, top, width, height, SW_SHOWNORMAL);
422+
423+
// presumably they would all be set to CW_USEDEFAULT
424+
// but we check for any out-of-bounds value and
425+
// bypass the restore rect as to let Windows decide
426+
if (left != CW_USEDEFAULT &&
427+
top != CW_USEDEFAULT &&
428+
height != CW_USEDEFAULT &&
429+
width != CW_USEDEFAULT) {
430+
431+
wp.rcNormalPosition.left = left;
432+
wp.rcNormalPosition.top = top;
433+
434+
wp.rcNormalPosition.right = wp.rcNormalPosition.left + width;
435+
wp.rcNormalPosition.bottom = wp.rcNormalPosition.top + height;
436+
437+
// This returns FALSE on failure but not sure what we could do in that case
438+
SetWindowPlacement(&wp);
439+
}
358440
}
359441

360442
ShowWindow(showCmd);

appshell/cef_main_window.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class cef_main_window : public cef_host_window
4747
void SaveWindowRestoreRect();
4848
void LoadWindowRestoreRect(int& left, int& top, int& width, int& height, int& showCmd);
4949
void RestoreWindowPlacement(int showCmd);
50+
void EnsureWindowRectVisibility(int& left, int& top, int& width, int& height, int showCmd);
5051

5152
// Message Handlers
5253
BOOL HandleEraseBackground(HDC hdc);

0 commit comments

Comments
 (0)