win: Implement setContentSize API.
authorCheng Zhao <zcbenz@gmail.com>
Sun, 18 May 2014 13:27:23 +0000 (21:27 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Sun, 18 May 2014 13:27:23 +0000 (21:27 +0800)
atom/browser/native_window_win.cc
atom/browser/native_window_win.h

index b2563c2..28dd6de 100644 (file)
@@ -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();
index ac91272..ce4c829 100644 (file)
@@ -115,6 +115,8 @@ class NativeWindowWin : public NativeWindow,
   typedef struct { int position; ui::MenuModel* model; } MenuItem;
   typedef std::map<ui::Accelerator, MenuItem> 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<SkRegion> draggable_region_;
 
+  bool use_content_size_;
+
   bool resizable_;
   string16 title_;
   gfx::Size minimum_size_;