]> khamidou — GitHub mirrors - electron.git/commitdiff
changes requested for pull request #2250 into electron master
authorMichael S. Barthelemy <msb@idiom.com>
Wed, 22 Jul 2015 14:23:31 +0000 (10:23 -0400)
committerMichael S. Barthelemy <msb@idiom.com>
Wed, 22 Jul 2015 14:23:31 +0000 (10:23 -0400)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_mac.mm
docs/api/browser-window.md

index e6d4ff4d4134ae1a62ce1da956cd752ec6cf9204..49a41cf51a932a315ad77548bef2bb203111b336 100644 (file)
@@ -249,9 +249,8 @@ bool Window::IsFullscreen() {
   return window_->IsFullscreen();
 }
 
-void Window::MaintainContentAspectRatio(double aspectRatio,
-                                        double width, double height) {
-  window_->MaintainContentAspectRatio(aspectRatio, gfx::Size(width, height));
+void Window::SetAspectRatio(double aspectRatio, gfx::Size extraSize) {
+  window_->SetAspectRatio(aspectRatio, extraSize);
 }
 
 void Window::SetBounds(const gfx::Rect& bounds) {
@@ -503,8 +502,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("isMinimized", &Window::IsMinimized)
       .SetMethod("setFullScreen", &Window::SetFullScreen)
       .SetMethod("isFullScreen", &Window::IsFullscreen)
-      .SetMethod("maintainContentAspectRatio",
-                 &Window::MaintainContentAspectRatio)
+      .SetMethod("setAspectRatio", &Window::SetAspectRatio)
       .SetMethod("getBounds", &Window::GetBounds)
       .SetMethod("setBounds", &Window::SetBounds)
       .SetMethod("getSize", &Window::GetSize)
index 313892a6b28637a0a0eec4f7168a3a8bf9e751fa..e0345bc2e3bf28b5735a1e083915b63e3374c1c0 100644 (file)
@@ -95,8 +95,7 @@ class Window : public mate::TrackableObject<Window>,
   bool IsMinimized();
   void SetFullScreen(bool fullscreen);
   bool IsFullscreen();
-  void MaintainContentAspectRatio(double aspectRatio,
-                                  double width, double height);
+  void SetAspectRatio(double aspectRatio, gfx::Size extraSize);
   void SetBounds(const gfx::Rect& bounds);
   gfx::Rect GetBounds();
   void SetSize(int width, int height);
index 544bfad46870243e580bee5983cbc04b07a78ab0..56999af945c5b2253810dc786a17be04abc348fa 100644 (file)
@@ -195,18 +195,18 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
     Show();
 }
 
-double NativeWindow::GetInteriorContentAspectRatio() {
-  return interiorContentAspectRatio;
+double NativeWindow::GetAspectRatio() {
+  return aspectRatio_;
 }
 
-gfx::Size NativeWindow::GetInteriorContentExtraSize() {
-  return interiorContentExtraSize;
+gfx::Size NativeWindow::GetAspectRatioExtraSize() {
+  return aspectRatioExtraSize_;
 }
 
-void NativeWindow::MaintainContentAspectRatio(double aspectRatio,
-                                              const gfx::Size& extraSize) {
-  interiorContentAspectRatio = aspectRatio;
-  interiorContentExtraSize = extraSize;
+void NativeWindow::SetAspectRatio(double aspectRatio,
+                                  const gfx::Size& extraSize) {
+  aspectRatio_ = aspectRatio;
+  aspectRatioExtraSize_ = extraSize;
 }
 
 void NativeWindow::SetSize(const gfx::Size& size) {
index ee0628422270c8e03d6c1e134b30f9ad36e22116..cc0bd7b8f5a20e46c911f1074f04f2f89bcb0fab 100644 (file)
@@ -107,10 +107,9 @@ class NativeWindow : public content::WebContentsObserver,
   virtual bool IsMinimized() = 0;
   virtual void SetFullScreen(bool fullscreen) = 0;
   virtual bool IsFullscreen() const = 0;
-  double GetInteriorContentAspectRatio();
-  virtual gfx::Size GetInteriorContentExtraSize();
-  virtual void MaintainContentAspectRatio(double aspectRatio,
-                                          const gfx::Size& extraSize);
+  double GetAspectRatio();
+  virtual gfx::Size GetAspectRatioExtraSize();
+  virtual void SetAspectRatio(double aspectRatio, const gfx::Size& extraSize);
   virtual void SetBounds(const gfx::Rect& bounds) = 0;
   virtual gfx::Rect GetBounds() = 0;
   virtual void SetSize(const gfx::Size& size);
@@ -291,8 +290,8 @@ class NativeWindow : public content::WebContentsObserver,
 
   // Used to maintain the aspect ratio of a view which is inside of the
   // content view.
-  double interiorContentAspectRatio = 0.0;
-  gfx::Size interiorContentExtraSize;
+  double aspectRatio_ = 0.0;
+  gfx::Size aspectRatioExtraSize_;
 
   // The page this window is viewing.
   brightray::InspectableWebContents* inspectable_web_contents_;
index f543aae1628dbdce177065a59b0fa7af47d310cf..9c13518c302dbde5a43166b16670fb48c6cd331f 100644 (file)
@@ -97,25 +97,25 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
 
 - (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize {
   NSSize newSize = frameSize;
-  double interiorContentAspectRatio = shell_->GetInteriorContentAspectRatio();
+  double aspectRatio = shell_->GetAspectRatio();
 
-  if (interiorContentAspectRatio > 0.0) {
-    NSRect windowFrame = [sender frame];
-    NSRect contentViewBounds = [[sender contentView] bounds];
-    gfx::Size interiorContentExtraSize = shell_->GetInteriorContentExtraSize();
-    double extraWidthPlusFrame = windowFrame.size.width - contentViewBounds.size.width + interiorContentExtraSize.width();
-    double extraHeightPlusFrame = windowFrame.size.height - contentViewBounds.size.height + interiorContentExtraSize.height();
+  if (aspectRatio > 0.0) {
+    gfx::Size windowFrameSize = shell_->GetSize();
+    gfx::Size contentViewSize = shell_->GetContentSize();
+    gfx::Size aspectRatioExtraSize = shell_->GetAspectRatioExtraSize();
+    double extraWidthPlusFrame = windowFrameSize.width() - contentViewSize.width() + aspectRatioExtraSize.width();
+    double extraHeightPlusFrame = windowFrameSize.height() - contentViewSize.height() + aspectRatioExtraSize.height();
 
-    newSize.width = roundf(((frameSize.height - extraHeightPlusFrame) * interiorContentAspectRatio) + extraWidthPlusFrame);
+    newSize.width = roundf(((frameSize.height - extraHeightPlusFrame) * aspectRatio) + extraWidthPlusFrame);
 
     // If the new width is less than the frame size use it as the primary constraint. This ensures that the value returned
     // by this method will never be larger than the users requested window size.
-    if (newSize.width < frameSize.width) {
-        newSize.height = roundf(((newSize.width - extraWidthPlusFrame) / interiorContentAspectRatio) + extraHeightPlusFrame);
+    if (newSize.width <= frameSize.width) {
+        newSize.height = roundf(((newSize.width - extraWidthPlusFrame) / aspectRatio) + extraHeightPlusFrame);
     }
     else {
-        newSize.height = roundf(((frameSize.width - extraWidthPlusFrame) / interiorContentAspectRatio) + extraHeightPlusFrame);
-        newSize.width = roundf(((newSize.height - extraHeightPlusFrame) * interiorContentAspectRatio) + extraWidthPlusFrame);
+        newSize.height = roundf(((frameSize.width - extraWidthPlusFrame) / aspectRatio) + extraHeightPlusFrame);
+        newSize.width = roundf(((newSize.height - extraHeightPlusFrame) * aspectRatio) + extraWidthPlusFrame);
     }
   }
 
index 48a118ffa3c274f5723b527f39969ca4900bab5f..25e2ba2958e76aac2dfcb4f3a9b8ac584c1d9013 100644 (file)
@@ -361,6 +361,17 @@ Sets whether the window should be in fullscreen mode.
 
 Returns whether the window is in fullscreen mode.
 
+### BrowserWindow.setAspectRatio(aspectRatio, [extraSize])
+
+* `aspectRatio` The aspect ratio we want to maintain for some portion of the content view.
+* `rect` Object - The extra size to not be included in the aspect ratio to be maintained.
+  * `width` Integer
+  * `height` Integer
+
+This will have a window maintain an aspect ratio. The extra size allows a developer to be able to have space, specifified in pixels, not included within the aspect ratio calculations. This API already takes into account the difference between a window's size and it's content size.
+
+Consider a normal window with an HD video player and associated controls. Perhaps there are 15 pixels of controls on the left edge, 25 pixels of controls on the right edge and 50 pixels of controls below the player. In order to maintain a 16:9 aspect ratio (standard aspect ratio for HD @1920x1080) within the player itself we would call this function with arguments of 16/9 and [ 40, 50 ]. The second argument doesn't care where the extra width and height are within the content view — only that they exist. Just sum any extra width and height areas you have within the overall content view.
+
 ### BrowserWindow.setBounds(options)
 
 * `options` Object