Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement win.setAspectRatio() on Windows #18306

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
102f4eb
feat: browser window setaspectratio function activate in windows os (…
MadfishDT Mar 6, 2019
0a6ea80
c-style casting fix
MadfishDT Mar 6, 2019
23b7377
fix: in window sizing handler, type casting operator iliegal usage fix
MadfishDT Mar 7, 2019
52f7186
doc: setAspectRatio parameter extraSize description change
MadfishDT Apr 25, 2019
ece8f68
fix after drag the window to its minimum size, not work aspect ratio
MadfishDT May 15, 2019
f2e36dd
Update atom/browser/native_window_views_win.cc
MadfishDT May 16, 2019
38c1e97
Update atom/browser/native_window_views_win.cc
MadfishDT May 16, 2019
cf89397
fix: fix zero risky code, remove useless code, fix size limit condito…
MadfishDT May 16, 2019
8ae510c
fix: move the temp variable in case scope
MadfishDT May 16, 2019
69cfb00
fix: remove 0x0 window size return case and remove useless type casting
MadfishDT May 20, 2019
1d7e0cb
Update atom/browser/native_window_views_win.cc
MadfishDT May 25, 2019
f28a942
Update docs/api/browser-window.md
MadfishDT May 25, 2019
b075131
Update atom/browser/native_window_views_win.cc
MadfishDT May 25, 2019
3057425
fix: rect variable duplicated decaration in windows views sizing even…
MadfishDT May 29, 2019
c721231
Merge branch 'master' into upstream/window-aspectratio
MadfishDT Jun 5, 2019
9229646
fix: document setAspectRatio parameter optional phase added
MadfishDT Jun 7, 2019
d649a46
Merge branch 'upstream/window-aspectratio' of https://github.com/Madf…
MadfishDT Jun 7, 2019
45ba6d1
Merge branch 'upstream/master' into upstream/window-aspectratio
MadfishDT Jul 26, 2019
9546e6a
Merge branch 'upstream/master' into upstream/window-aspectratio
MadfishDT Jul 26, 2019
a2cea07
Merge branch 'master' into upstream/window-aspectratio
MadfishDT Nov 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api/browser-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ Returns `Boolean` - Whether the window is in simple (pre-Lion) fullscreen mode.

Returns `Boolean` - Whether the window is in normal state (not maximized, not minimized, not in fullscreen mode).

#### `win.setAspectRatio(aspectRatio[, extraSize])` _macOS_ _Linux_
#### `win.setAspectRatio(aspectRatio[, extraSize])` _macOS_ _Linux_ _Windows_

* `aspectRatio` Float - The aspect ratio to maintain for some portion of the
content view.
Expand Down
1 change: 1 addition & 0 deletions shell/browser/native_window_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class NativeWindowViews : public NativeWindow,

#if defined(OS_WIN)
void HandleSizeEvent(WPARAM w_param, LPARAM l_param);
void HandleSizingEvent(WPARAM w_param, LPARAM l_param);
void SetForwardMouseMessages(bool forward);
static LRESULT CALLBACK SubclassProc(HWND hwnd,
UINT msg,
Expand Down
53 changes: 53 additions & 0 deletions shell/browser/native_window_views_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
return false;
case WM_SIZING: {
bool prevent_default = false;
HandleSizingEvent(w_param, l_param);
NotifyWindowWillResize(gfx::Rect(*reinterpret_cast<RECT*>(l_param)),
&prevent_default);
if (prevent_default) {
Expand Down Expand Up @@ -476,6 +477,58 @@ bool NativeWindowViews::PreHandleMSG(UINT message,
}
}

void NativeWindowViews::HandleSizingEvent(WPARAM w_param, LPARAM l_param) {
double aspect_ratio = GetAspectRatio();
if (aspect_ratio <= 0.0) {
return;
}

RECT* window_rect = reinterpret_cast<RECT*>(l_param);
int width = window_rect->right - window_rect->left;
int height = window_rect->bottom - window_rect->top;

double result_width = 0;
double result_height = 0;

gfx::Size win_fit_size(width, height);
const gfx::Size min_fit_size = GetMinimumSize();
win_fit_size.SetToMax(min_fit_size);

switch ((UINT)w_param) {
case WMSZ_LEFT:
case WMSZ_RIGHT:
result_width = win_fit_size.width();
result_height = result_width / aspect_ratio;
break;
case WMSZ_TOP:
case WMSZ_BOTTOM:
result_height = win_fit_size.height();
result_width = result_height * aspect_ratio;
break;
case WMSZ_TOPLEFT:
case WMSZ_TOPRIGHT:
case WMSZ_BOTTOMLEFT:
case WMSZ_BOTTOMRIGHT: {
result_width = height * aspect_ratio;
result_height = height;

double temp_width = width;
double temp_height = width / aspect_ratio;

if (abs(temp_width * temp_height) > abs(result_width * result_height)) {
result_width = temp_width;
result_height = temp_height;
}
break;
}
default:
return;
}

window_rect->right = window_rect->left + result_width;
window_rect->bottom = window_rect->top + result_height;
}

void NativeWindowViews::HandleSizeEvent(WPARAM w_param, LPARAM l_param) {
// Here we handle the WM_SIZE event in order to figure out what is the current
// window state and notify the user accordingly.
Expand Down