Implement size and position APIs with bounds API
authorCheng Zhao <zcbenz@gmail.com>
Mon, 4 May 2015 04:43:40 +0000 (12:43 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 4 May 2015 04:47:56 +0000 (12:47 +0800)
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm
atom/browser/native_window_views.cc
atom/browser/native_window_views.h

index 2920178..5bef1ac 100644 (file)
@@ -237,6 +237,22 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
     Show();
 }
 
+void NativeWindow::SetSize(const gfx::Size& size) {
+  SetBounds(gfx::Rect(GetPosition(), size));
+}
+
+gfx::Size NativeWindow::GetSize() {
+  return GetBounds().size();
+}
+
+void NativeWindow::SetPosition(const gfx::Point& position) {
+  SetBounds(gfx::Rect(position, GetSize()));
+}
+
+gfx::Point NativeWindow::GetPosition() {
+  return GetBounds().origin();
+}
+
 void NativeWindow::SetRepresentedFilename(const std::string& filename) {
 }
 
index 7205671..32c3493 100644 (file)
@@ -114,8 +114,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   virtual bool IsFullscreen() const = 0;
   virtual void SetBounds(const gfx::Rect& bounds) = 0;
   virtual gfx::Rect GetBounds() = 0;
-  virtual void SetSize(const gfx::Size& size) = 0;
-  virtual gfx::Size GetSize() = 0;
+  virtual void SetSize(const gfx::Size& size);
+  virtual gfx::Size GetSize();
+  virtual void SetPosition(const gfx::Point& position);
+  virtual gfx::Point GetPosition();
   virtual void SetContentSize(const gfx::Size& size) = 0;
   virtual gfx::Size GetContentSize() = 0;
   virtual void SetMinimumSize(const gfx::Size& size) = 0;
@@ -127,8 +129,6 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   virtual void SetAlwaysOnTop(bool top) = 0;
   virtual bool IsAlwaysOnTop() = 0;
   virtual void Center() = 0;
-  virtual void SetPosition(const gfx::Point& position) = 0;
-  virtual gfx::Point GetPosition() = 0;
   virtual void SetTitle(const std::string& title) = 0;
   virtual std::string GetTitle() = 0;
   virtual void FlashFrame(bool flash) = 0;
index 0fa3fe9..8a6d141 100644 (file)
@@ -46,8 +46,6 @@ class NativeWindowMac : public NativeWindow {
   bool IsFullscreen() const override;
   void SetBounds(const gfx::Rect& bounds) override;
   gfx::Rect GetBounds() override;
-  void SetSize(const gfx::Size& size) override;
-  gfx::Size GetSize() override;
   void SetContentSize(const gfx::Size& size) override;
   gfx::Size GetContentSize() override;
   void SetMinimumSize(const gfx::Size& size) override;
@@ -59,8 +57,6 @@ class NativeWindowMac : public NativeWindow {
   void SetAlwaysOnTop(bool top) override;
   bool IsAlwaysOnTop() override;
   void Center() override;
-  void SetPosition(const gfx::Point& position) override;
-  gfx::Point GetPosition() override;
   void SetTitle(const std::string& title) override;
   std::string GetTitle() override;
   void FlashFrame(bool flash) override;
index 53d0a48..9071763 100644 (file)
@@ -478,19 +478,6 @@ gfx::Rect NativeWindowMac::GetBounds() {
   return bounds;
 }
 
-void NativeWindowMac::SetSize(const gfx::Size& size) {
-  NSRect frame = [window_ frame];
-  frame.origin.y -= size.height() - frame.size.height;
-  frame.size.width = size.width();
-  frame.size.height = size.height();
-
-  [window_ setFrame:frame display:YES];
-}
-
-gfx::Size NativeWindowMac::GetSize() {
-  return GetBounds().size();
-}
-
 void NativeWindowMac::SetContentSize(const gfx::Size& size) {
   NSRect frame_nsrect = [window_ frame];
   NSSize frame = frame_nsrect.size;
@@ -561,14 +548,6 @@ void NativeWindowMac::Center() {
   [window_ center];
 }
 
-void NativeWindowMac::SetPosition(const gfx::Point& position) {
-  SetBounds(gfx::Rect(position, GetSize()));
-}
-
-gfx::Point NativeWindowMac::GetPosition() {
-  return GetBounds().origin();
-}
-
 void NativeWindowMac::SetTitle(const std::string& title) {
   // We don't want the title to show in transparent window.
   if (transparent_)
index 3b283dd..4c99f88 100644 (file)
@@ -391,31 +391,15 @@ gfx::Rect NativeWindowViews::GetBounds() {
   return window_->GetWindowBoundsInScreen();
 }
 
-void NativeWindowViews::SetSize(const gfx::Size& size) {
-#if defined(USE_X11)
-  // On Linux the minimum and maximum size should be updated with window size
-  // when window is not resizable.
-  if (!resizable_) {
-    SetMaximumSize(size);
-    SetMinimumSize(size);
-  }
-#endif
-
-  window_->SetSize(size);
-}
-
-gfx::Size NativeWindowViews::GetSize() {
-  return GetBounds().size();
-}
-
 void NativeWindowViews::SetContentSize(const gfx::Size& size) {
   if (!has_frame_) {
-    SetSize(size);
+    NativeWindow::SetSize(size);
     return;
   }
 
   gfx::Rect bounds = window_->GetWindowBoundsInScreen();
-  SetSize(ContentBoundsToWindowBounds(gfx::Rect(bounds.origin(), size)).size());
+  bounds.set_size(size);
+  SetBounds(ContentBoundsToWindowBounds(bounds));
 }
 
 gfx::Size NativeWindowViews::GetContentSize() {
@@ -505,19 +489,6 @@ void NativeWindowViews::Center() {
   window_->CenterWindow(GetSize());
 }
 
-void NativeWindowViews::SetPosition(const gfx::Point& position) {
-  window_->SetBounds(gfx::Rect(position, GetSize()));
-}
-
-gfx::Point NativeWindowViews::GetPosition() {
-#if defined(OS_WIN)
-  if (IsMinimized())
-    return window_->GetRestoredBounds().origin();
-#endif
-
-  return window_->GetWindowBoundsInScreen().origin();
-}
-
 void NativeWindowViews::SetTitle(const std::string& title) {
   title_ = title;
   window_->UpdateWindowTitle();
index 978aac8..15f073d 100644 (file)
@@ -51,8 +51,6 @@ class NativeWindowViews : public NativeWindow,
   bool IsFullscreen() const override;
   void SetBounds(const gfx::Rect& bounds) override;
   gfx::Rect GetBounds() override;
-  void SetSize(const gfx::Size& size) override;
-  gfx::Size GetSize() override;
   void SetContentSize(const gfx::Size& size) override;
   gfx::Size GetContentSize() override;
   void SetMinimumSize(const gfx::Size& size) override;
@@ -64,8 +62,6 @@ class NativeWindowViews : public NativeWindow,
   void SetAlwaysOnTop(bool top) override;
   bool IsAlwaysOnTop() override;
   void Center() override;
-  void SetPosition(const gfx::Point& position) override;
-  gfx::Point GetPosition() override;
   void SetTitle(const std::string& title) override;
   std::string GetTitle() override;
   void FlashFrame(bool flash) override;