Add BrowserWindow::setContentSize.

This commit is contained in:
Cheng Zhao 2014-05-15 16:05:35 +08:00
parent 511a49f6fb
commit 5150fd6946
9 changed files with 33 additions and 1 deletions

View file

@ -181,6 +181,10 @@ std::vector<int> Window::GetSize() {
return result;
}
void Window::SetContentSize(int width, int height) {
window_->SetContentSize(gfx::Size(width, height));
}
std::vector<int> Window::GetContentSize() {
std::vector<int> result(2);
gfx::Size size = window_->GetContentSize();
@ -339,8 +343,9 @@ void Window::BuildPrototype(v8::Isolate* isolate,
.SetMethod("setFullScreen", &Window::SetFullscreen)
.SetMethod("isFullScreen", &Window::IsFullscreen)
.SetMethod("getSize", &Window::GetSize)
.SetMethod("getContentSize", &Window::GetContentSize)
.SetMethod("setSize", &Window::SetSize)
.SetMethod("getContentSize", &Window::GetContentSize)
.SetMethod("setContentSize", &Window::SetContentSize)
.SetMethod("setMinimumSize", &Window::SetMinimumSize)
.SetMethod("getMinimumSize", &Window::GetMinimumSize)
.SetMethod("setMaximumSize", &Window::SetMaximumSize)

View file

@ -73,6 +73,7 @@ class Window : public mate::EventEmitter,
bool IsFullscreen();
void SetSize(int width, int height);
std::vector<int> GetSize();
void SetContentSize(int width, int height);
std::vector<int> GetContentSize();
void SetMinimumSize(int width, int height);
std::vector<int> GetMinimumSize();

View file

@ -111,6 +111,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
virtual bool IsFullscreen() = 0;
virtual void SetSize(const gfx::Size& size) = 0;
virtual gfx::Size GetSize() = 0;
virtual void SetContentSize(const gfx::Size& size) = 0;
virtual gfx::Size GetContentSize() = 0;
virtual void SetMinimumSize(const gfx::Size& size) = 0;
virtual gfx::Size GetMinimumSize() = 0;

View file

@ -262,6 +262,11 @@ gfx::Size NativeWindowGtk::GetSize() {
return gfx::Size(frame_extents.width, frame_extents.height);
}
void NativeWindowGtk::SetContentSize(const gfx::Size& size) {
GtkAllocation size = { 0, 0, size.width(), size.height() };
gtk_widget_size_allocate(GetWebContents()->GetView()->GetNativeView(), &size);
}
gfx::Size NativeWindowGtk::GetContentSize() {
gint width, height;
gtk_window_get_size(window_, &width, &height);

View file

@ -46,6 +46,7 @@ class NativeWindowGtk : public NativeWindow,
virtual bool IsFullscreen() OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE;
virtual void SetContentSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetContentSize() OVERRIDE;
virtual void SetMinimumSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetMinimumSize() OVERRIDE;

View file

@ -38,6 +38,7 @@ class NativeWindowMac : public NativeWindow {
virtual bool IsFullscreen() OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE;
virtual void SetContentSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetContentSize() OVERRIDE;
virtual void SetMinimumSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetMinimumSize() OVERRIDE;

View file

@ -305,6 +305,19 @@ gfx::Size NativeWindowMac::GetSize() {
return gfx::Size(frame.size.width, frame.size.height);
}
void NativeWindowMac::SetContentSize(const gfx::Size& size) {
NSRect frame_nsrect = [window_ frame];
NSSize frame = frame_nsrect.size;
NSSize content = [window_ contentRectForFrameRect:frame_nsrect].size;
int width = size.width() + frame.width - content.width;
int height = size.height() + frame.height - content.height;
frame_nsrect.origin.y -= height - frame_nsrect.size.height;
frame_nsrect.size.width = width;
frame_nsrect.size.height = height;
[window_ setFrame:frame_nsrect display:YES];
}
gfx::Size NativeWindowMac::GetContentSize() {
NSRect bounds = [[window_ contentView] bounds];
return gfx::Size(bounds.size.width, bounds.size.height);

View file

@ -295,6 +295,10 @@ gfx::Size NativeWindowWin::GetSize() {
return window_->GetWindowBoundsInScreen().size();
}
void NativeWindowWin::SetContentSize(const gfx::Size& size) {
// FIXME
}
gfx::Size NativeWindowWin::GetContentSize() {
return window_->GetClientAreaBoundsInScreen().size();
}

View file

@ -53,6 +53,7 @@ class NativeWindowWin : public NativeWindow,
virtual bool IsFullscreen() OVERRIDE;
virtual void SetSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE;
virtual void SetContentSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetContentSize() OVERRIDE;
virtual void SetMinimumSize(const gfx::Size& size) OVERRIDE;
virtual gfx::Size GetMinimumSize() OVERRIDE;