From 0d4d2080ca61c76350019db0770f5a9a2887c41b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 4 May 2015 12:43:40 +0800 Subject: [PATCH] Implement size and position APIs with bounds API --- atom/browser/native_window.cc | 16 ++++++++++++++++ atom/browser/native_window.h | 8 ++++---- atom/browser/native_window_mac.h | 4 ---- atom/browser/native_window_mac.mm | 21 --------------------- atom/browser/native_window_views.cc | 35 +++-------------------------------- atom/browser/native_window_views.h | 4 ---- 6 files changed, 23 insertions(+), 65 deletions(-) diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 2920178..5bef1ac 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -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) { } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 7205671..32c3493 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -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; diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 0fa3fe9..8a6d141 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -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; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 53d0a48..9071763 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -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_) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 3b283dd..4c99f88 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -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(); diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 978aac8..15f073d 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -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; -- 2.7.4