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

Conversation

MadfishDT
Copy link
Contributor

Description of Change

Description of Change
Implemented win.setAspectRatio() on Windows by handling the WM_SIZING message.

Checklist

Release Notes
Notes: Implemented win.setAspectRatio() on Windows.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label May 15, 2019
atom/browser/native_window_views_win.cc Outdated Show resolved Hide resolved
atom/browser/native_window_views_win.cc Outdated Show resolved Hide resolved
atom/browser/native_window_views_win.cc Outdated Show resolved Hide resolved
atom/browser/native_window_views_win.cc Outdated Show resolved Hide resolved
atom/browser/native_window_views_win.cc Outdated Show resolved Hide resolved
atom/browser/native_window_views_win.cc Outdated Show resolved Hide resolved
docs/api/browser-window.md Outdated Show resolved Hide resolved
MadfishDT and others added 3 commits May 16, 2019 11:56
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label May 16, 2019
atom/browser/native_window_views_win.cc Outdated Show resolved Hide resolved
atom/browser/native_window_views_win.cc Outdated Show resolved Hide resolved
Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, though I'd like to have a second reviewer's eyes on this before merging.

@MadfishDT
Copy link
Contributor Author

@ckerr thanks all your review and advice

Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like views already has logic for handling aspect ratios: https://chromium.googlesource.com/chromium/src/+/master/ui/views/win/hwnd_message_handler.cc#890

Is there any way we can reuse that code instead of rewriting the event handler?

atom/browser/native_window_views_win.cc Outdated Show resolved Hide resolved
docs/api/browser-window.md Outdated Show resolved Hide resolved
atom/browser/native_window_views_win.cc Outdated Show resolved Hide resolved
Copy link
Member

@felixrieseberg felixrieseberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Late to the party, but with @nornagon's comments, this looks good!

@nornagon
Copy link
Member

Also, would love to get a test for this behaviour.

MadfishDT and others added 3 commits May 25, 2019 10:53
Co-Authored-By: Jeremy Apthorp <nornagon@nornagon.net>
Co-Authored-By: Jeremy Apthorp <nornagon@nornagon.net>
Co-Authored-By: Jeremy Apthorp <nornagon@nornagon.net>
@MadfishDT
Copy link
Contributor Author

@nornagon Thanks your advice, and I will try to reuse chromium code. chromium code look so nice. but I should find wayt how to get this function or class reference from chromium module. I will fully reference this code. very thanks ~

@codebytere codebytere requested a review from nornagon June 28, 2019 21:42
@CapOM
Copy link
Contributor

CapOM commented Jul 12, 2019

Hi I have tried to use widget()->setAspectRatio() from chromium api but it was not working properly. The size of the frame was not correct and it also disables the resizing of the window so it looks to me we should go with @MadfishDT 's solution. Here is what I tried:

diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc
index 4526e9365..62a6b78cb 100644
--- a/atom/browser/native_window_views.cc
+++ b/atom/browser/native_window_views.cc
@@ -1098,6 +1098,21 @@ bool NativeWindowViews::IsMenuBarVisible() {
   return root_view_->IsMenuBarVisible();
 }

+void NativeWindowViews::SetAspectRatio(double aspect_ratio,
+                                       const gfx::Size& extra_size) {
+  NativeWindow::SetAspectRatio(aspect_ratio, extra_size);
+  printf("- set aspect ratio to %f\n", aspect_ratio);
+  fflush(stdout);
+  // Reset the behaviour to default if aspect_ratio is set to 0 or less.
+  if (aspect_ratio > 0.0) {
+    printf("- set aspect ratio to %dx%d\n", 16, 9);
+    fflush(stdout);
+    widget()->SetAspectRatio(gfx::SizeF(16, 9));
+  } else {
+    widget()->SetAspectRatio(gfx::SizeF(1, 1));
+  }
+}
+
 void NativeWindowViews::SetVisibleOnAllWorkspaces(bool visible,
                                                   bool visibleOnFullScreen) {
   widget()->SetVisibleOnAllWorkspaces(visible);
diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h
index 3247b3f10..ee0da1dd5 100644
--- a/atom/browser/native_window_views.h
+++ b/atom/browser/native_window_views.h
@@ -121,6 +121,8 @@ class NativeWindowViews : public NativeWindow,
   bool IsMenuBarAutoHide() override;
   void SetMenuBarVisibility(bool visible) override;
   bool IsMenuBarVisible() override;
+  void SetAspectRatio(double aspect_ratio,
+                      const gfx::Size& extra_size) override;

   void SetVisibleOnAllWorkspaces(bool visible,
                                  bool visibleOnFullScreen) override;

@codebytere
Copy link
Member

@MadfishDT if you could please resolve conflicts that would be great

@jaehayoo

This comment has been minimized.

@MadfishDT
Copy link
Contributor Author

Sorry, I had some ear infection problem. so I could not touch code until yesterday. I will fix it as soon as possible. thanks all comments

@codebytere
Copy link
Member

no worries, thanks @MadfishDT!

Copy link
Member

@codebytere codebytere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks ok to me following latest review round of updates, but i'd like @nornagon's final sign-off here given that the last feedback was his.

@erickzhao
Copy link
Member

refs: #8036

@erickzhao
Copy link
Member

erickzhao commented Jul 29, 2019

Hi I have tried to use widget()->setAspectRatio() from chromium api but it was not working properly.

@CapOM I tried it exploring that on this branch here: https://github.com/electron/electron/tree/intern/set-aspect-ratio and it worked for me on Ubuntu.

I can test to see if it behaves as intended on Windows.
On my end, it seems like the window is 0 x 0 and can't be resized.

edit: opened #19516 as a tentative PR.

cc @MadfishDT @codebytere @nornagon

@jaehayoo
Copy link

jaehayoo commented Nov 6, 2019

I checked setAspectRation for Linux merged in master.
Is there any update for windows with this issue thread?
Maybe, Reviewers are waiting @nornagon's final sign-off.
@nornagon, Could you please follow up this?

Thanks,

@MadfishDT
Copy link
Contributor Author

MadfishDT commented Nov 12, 2019

I can fix Conflicted files. but I can't handling progress merge step.

@codebytere
Copy link
Member

codebytere commented Nov 12, 2019

@nornagon would you be able to give this final review?

@ssinam
Copy link

ssinam commented Nov 19, 2019

@nornagon Could you please give the final review? I'm also waiting merge of this great change since I need this function for my product.

Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for your patience.

I'm still 👎 on merging this:

@jaehayoo
Copy link

@nornagon
This important feature wasn't supported by electron, so I was really looking forward to this code being merged.
I hope the reviewer will help the author and merge the functionality with electron.

@ssinam
Copy link

ssinam commented Dec 17, 2019

@nornagon
This important feature wasn't supported by electron, so I was really looking forward to this code being merged.
I hope the reviewer will help the author and merge the functionality with electron.

I absolutely agree with you.

@jaehayoo
Copy link

@codebytere @nornagon @MadfishDT Is there any update?

@jaehayoo
Copy link

jaehayoo commented Jan 31, 2020

ref : #8036 #1336

@jaehayoo
Copy link

jaehayoo commented Apr 6, 2020

@MadfishDT Do you have any plans for @nornagon 's request ?

@codebytere codebytere requested a review from nornagon April 7, 2020 05:30
Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR has not changed since my last review.

@MadfishDT
Copy link
Contributor Author

Sorry I had some big project in my company and I changed my job(company). so I had no time for handling this issue and marchine for building electron. I am going to start fix code from next week.

@jaehayoo
Copy link

jaehayoo commented Jun 1, 2020

@MadfishDT Hi, Is there any update? :)

@zcbenz
Copy link
Member

zcbenz commented Dec 11, 2020

I'm closing this PR in favor of #26941, which reuses Chromium's code for implementing this API.

@zcbenz zcbenz closed this Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants