Implement size and position APIs with bounds API
This commit is contained in:
parent
7142cae041
commit
0d4d2080ca
6 changed files with 23 additions and 65 deletions
|
@ -237,6 +237,22 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
|
||||||
Show();
|
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) {
|
void NativeWindow::SetRepresentedFilename(const std::string& filename) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,8 +114,10 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
||||||
virtual bool IsFullscreen() const = 0;
|
virtual bool IsFullscreen() const = 0;
|
||||||
virtual void SetBounds(const gfx::Rect& bounds) = 0;
|
virtual void SetBounds(const gfx::Rect& bounds) = 0;
|
||||||
virtual gfx::Rect GetBounds() = 0;
|
virtual gfx::Rect GetBounds() = 0;
|
||||||
virtual void SetSize(const gfx::Size& size) = 0;
|
virtual void SetSize(const gfx::Size& size);
|
||||||
virtual gfx::Size GetSize() = 0;
|
virtual gfx::Size GetSize();
|
||||||
|
virtual void SetPosition(const gfx::Point& position);
|
||||||
|
virtual gfx::Point GetPosition();
|
||||||
virtual void SetContentSize(const gfx::Size& size) = 0;
|
virtual void SetContentSize(const gfx::Size& size) = 0;
|
||||||
virtual gfx::Size GetContentSize() = 0;
|
virtual gfx::Size GetContentSize() = 0;
|
||||||
virtual void SetMinimumSize(const gfx::Size& size) = 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 void SetAlwaysOnTop(bool top) = 0;
|
||||||
virtual bool IsAlwaysOnTop() = 0;
|
virtual bool IsAlwaysOnTop() = 0;
|
||||||
virtual void Center() = 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 void SetTitle(const std::string& title) = 0;
|
||||||
virtual std::string GetTitle() = 0;
|
virtual std::string GetTitle() = 0;
|
||||||
virtual void FlashFrame(bool flash) = 0;
|
virtual void FlashFrame(bool flash) = 0;
|
||||||
|
|
|
@ -46,8 +46,6 @@ class NativeWindowMac : public NativeWindow {
|
||||||
bool IsFullscreen() const override;
|
bool IsFullscreen() const override;
|
||||||
void SetBounds(const gfx::Rect& bounds) override;
|
void SetBounds(const gfx::Rect& bounds) override;
|
||||||
gfx::Rect GetBounds() override;
|
gfx::Rect GetBounds() override;
|
||||||
void SetSize(const gfx::Size& size) override;
|
|
||||||
gfx::Size GetSize() override;
|
|
||||||
void SetContentSize(const gfx::Size& size) override;
|
void SetContentSize(const gfx::Size& size) override;
|
||||||
gfx::Size GetContentSize() override;
|
gfx::Size GetContentSize() override;
|
||||||
void SetMinimumSize(const gfx::Size& size) override;
|
void SetMinimumSize(const gfx::Size& size) override;
|
||||||
|
@ -59,8 +57,6 @@ class NativeWindowMac : public NativeWindow {
|
||||||
void SetAlwaysOnTop(bool top) override;
|
void SetAlwaysOnTop(bool top) override;
|
||||||
bool IsAlwaysOnTop() override;
|
bool IsAlwaysOnTop() override;
|
||||||
void Center() override;
|
void Center() override;
|
||||||
void SetPosition(const gfx::Point& position) override;
|
|
||||||
gfx::Point GetPosition() override;
|
|
||||||
void SetTitle(const std::string& title) override;
|
void SetTitle(const std::string& title) override;
|
||||||
std::string GetTitle() override;
|
std::string GetTitle() override;
|
||||||
void FlashFrame(bool flash) override;
|
void FlashFrame(bool flash) override;
|
||||||
|
|
|
@ -478,19 +478,6 @@ gfx::Rect NativeWindowMac::GetBounds() {
|
||||||
return bounds;
|
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) {
|
void NativeWindowMac::SetContentSize(const gfx::Size& size) {
|
||||||
NSRect frame_nsrect = [window_ frame];
|
NSRect frame_nsrect = [window_ frame];
|
||||||
NSSize frame = frame_nsrect.size;
|
NSSize frame = frame_nsrect.size;
|
||||||
|
@ -561,14 +548,6 @@ void NativeWindowMac::Center() {
|
||||||
[window_ 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) {
|
void NativeWindowMac::SetTitle(const std::string& title) {
|
||||||
// We don't want the title to show in transparent window.
|
// We don't want the title to show in transparent window.
|
||||||
if (transparent_)
|
if (transparent_)
|
||||||
|
|
|
@ -391,31 +391,15 @@ gfx::Rect NativeWindowViews::GetBounds() {
|
||||||
return window_->GetWindowBoundsInScreen();
|
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) {
|
void NativeWindowViews::SetContentSize(const gfx::Size& size) {
|
||||||
if (!has_frame_) {
|
if (!has_frame_) {
|
||||||
SetSize(size);
|
NativeWindow::SetSize(size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Rect bounds = window_->GetWindowBoundsInScreen();
|
gfx::Rect bounds = window_->GetWindowBoundsInScreen();
|
||||||
SetSize(ContentBoundsToWindowBounds(gfx::Rect(bounds.origin(), size)).size());
|
bounds.set_size(size);
|
||||||
|
SetBounds(ContentBoundsToWindowBounds(bounds));
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Size NativeWindowViews::GetContentSize() {
|
gfx::Size NativeWindowViews::GetContentSize() {
|
||||||
|
@ -505,19 +489,6 @@ void NativeWindowViews::Center() {
|
||||||
window_->CenterWindow(GetSize());
|
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) {
|
void NativeWindowViews::SetTitle(const std::string& title) {
|
||||||
title_ = title;
|
title_ = title;
|
||||||
window_->UpdateWindowTitle();
|
window_->UpdateWindowTitle();
|
||||||
|
|
|
@ -51,8 +51,6 @@ class NativeWindowViews : public NativeWindow,
|
||||||
bool IsFullscreen() const override;
|
bool IsFullscreen() const override;
|
||||||
void SetBounds(const gfx::Rect& bounds) override;
|
void SetBounds(const gfx::Rect& bounds) override;
|
||||||
gfx::Rect GetBounds() override;
|
gfx::Rect GetBounds() override;
|
||||||
void SetSize(const gfx::Size& size) override;
|
|
||||||
gfx::Size GetSize() override;
|
|
||||||
void SetContentSize(const gfx::Size& size) override;
|
void SetContentSize(const gfx::Size& size) override;
|
||||||
gfx::Size GetContentSize() override;
|
gfx::Size GetContentSize() override;
|
||||||
void SetMinimumSize(const gfx::Size& size) override;
|
void SetMinimumSize(const gfx::Size& size) override;
|
||||||
|
@ -64,8 +62,6 @@ class NativeWindowViews : public NativeWindow,
|
||||||
void SetAlwaysOnTop(bool top) override;
|
void SetAlwaysOnTop(bool top) override;
|
||||||
bool IsAlwaysOnTop() override;
|
bool IsAlwaysOnTop() override;
|
||||||
void Center() override;
|
void Center() override;
|
||||||
void SetPosition(const gfx::Point& position) override;
|
|
||||||
gfx::Point GetPosition() override;
|
|
||||||
void SetTitle(const std::string& title) override;
|
void SetTitle(const std::string& title) override;
|
||||||
std::string GetTitle() override;
|
std::string GetTitle() override;
|
||||||
void FlashFrame(bool flash) override;
|
void FlashFrame(bool flash) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue