From 8ae66cab9d56ced2f0412bb710d64752b08998c9 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sun, 18 May 2014 21:27:23 +0800 Subject: [PATCH] win: Implement setContentSize API. --- atom/browser/native_window_win.cc | 34 ++++++++++++++++++------------- atom/browser/native_window_win.h | 4 ++++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/atom/browser/native_window_win.cc b/atom/browser/native_window_win.cc index b2563c2113ef..28dd6dea9185 100644 --- a/atom/browser/native_window_win.cc +++ b/atom/browser/native_window_win.cc @@ -203,6 +203,7 @@ NativeWindowWin::NativeWindowWin(content::WebContents* web_contents, : NativeWindow(web_contents, options), window_(new views::Widget), web_view_(new views::WebView(NULL)), + use_content_size_(false), resizable_(true) { views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); params.delegate = this; @@ -216,18 +217,12 @@ NativeWindowWin::NativeWindowWin(content::WebContents* web_contents, options->GetInteger(switches::kWidth, &width); options->GetInteger(switches::kHeight, &height); - bool use_content_size = false; - options->GetBoolean(switches::kUseContentSize, &use_content_size); - if (has_frame_ && use_content_size) { - gfx::Size window = window_->GetWindowBoundsInScreen().size(); - gfx::Size client = window_->GetClientAreaBoundsInScreen().size(); - width += window.width() - client.width(); - height += window.height() - client.height(); - } - gfx::Size size(width, height); - window_->CenterWindow(size); + options->GetBoolean(switches::kUseContentSize, &use_content_size_); + if (has_frame_ && use_content_size_) + ClientAreaSizeToWindowSize(&size); + window_->CenterWindow(size); window_->UpdateWindowIcon(); web_view_->SetWebContents(web_contents); @@ -305,7 +300,9 @@ gfx::Size NativeWindowWin::GetSize() { } void NativeWindowWin::SetContentSize(const gfx::Size& size) { - // FIXME + gfx::Size resized(size); + ClientAreaSizeToWindowSize(&resized); + SetSize(resized); } gfx::Size NativeWindowWin::GetContentSize() { @@ -393,9 +390,11 @@ void NativeWindowWin::SetMenu(ui::MenuModel* menu_model) { RegisterAccelerators(); // Resize the window so SetMenu won't change client area size. - gfx::Size size = GetSize(); - size.set_height(size.height() + GetSystemMetrics(SM_CYMENU)); - SetSize(size); + if (use_content_size_) { + gfx::Size size = GetSize(); + size.set_height(size.height() + GetSystemMetrics(SM_CYMENU)); + SetSize(size); + } } void NativeWindowWin::UpdateDraggableRegions( @@ -514,6 +513,13 @@ views::NonClientFrameView* NativeWindowWin::CreateNonClientFrameView( return new NativeWindowFramelessView(widget, this); } +void NativeWindowWin::ClientAreaSizeToWindowSize(gfx::Size* size) { + gfx::Size window = window_->GetWindowBoundsInScreen().size(); + gfx::Size client = window_->GetClientAreaBoundsInScreen().size(); + size->set_width(size->width() + window.width() - client.width()); + size->set_height(size->height() + window.height() - client.height()); +} + void NativeWindowWin::OnViewWasResized() { // Set the window shape of the RWHV. gfx::Size sz = web_view_->size(); diff --git a/atom/browser/native_window_win.h b/atom/browser/native_window_win.h index ac912728f6b0..ce4c829f24a6 100644 --- a/atom/browser/native_window_win.h +++ b/atom/browser/native_window_win.h @@ -115,6 +115,8 @@ class NativeWindowWin : public NativeWindow, typedef struct { int position; ui::MenuModel* model; } MenuItem; typedef std::map AcceleratorTable; + void ClientAreaSizeToWindowSize(gfx::Size* size); + void OnViewWasResized(); // Register accelerators supported by the menu model. @@ -131,6 +133,8 @@ class NativeWindowWin : public NativeWindow, scoped_ptr draggable_region_; + bool use_content_size_; + bool resizable_; string16 title_; gfx::Size minimum_size_;