views: Currently set window's frames.
authorCheng Zhao <zcbenz@gmail.com>
Fri, 4 Jul 2014 04:32:03 +0000 (12:32 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 4 Jul 2014 04:32:03 +0000 (12:32 +0800)
atom/browser/native_window_views.cc
atom/browser/native_window_views.h
atom/browser/ui/message_box_views.cc
vendor/brightray

index 97ec074..ced2513 100644 (file)
@@ -17,7 +17,7 @@
 #include "ui/views/controls/webview/webview.h"
 #include "ui/views/layout/fill_layout.h"
 #include "ui/views/window/client_view.h"
-#include "ui/views/window/native_frame_view.h"
+#include "ui/views/window/custom_frame_view.h"
 #include "ui/views/widget/widget.h"
 
 namespace atom {
@@ -54,19 +54,30 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
 
   views::Widget::InitParams params;
   params.delegate = this;
+  params.type = has_frame_ ? views::Widget::InitParams::TYPE_WINDOW :
+                             views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
   params.top_level = true;
-  params.remove_standard_frame = !has_frame_;
+  params.remove_standard_frame = true;
   window_->Init(params);
 
+  // Add web view.
+  SetLayoutManager(new views::FillLayout);
+  set_background(views::Background::CreateStandardPanelBackground());
+  web_view_->SetWebContents(web_contents);
+  AddChildView(web_view_);
+
   int width = 800, height = 600;
   options.Get(switches::kWidth, &width);
   options.Get(switches::kHeight, &height);
-  window_->CenterWindow(gfx::Size(width, height));
 
-  SetLayoutManager(new views::FillLayout);
-  set_background(views::Background::CreateStandardPanelBackground());
+  bool use_content_size;
+  gfx::Rect bounds(0, 0, width, height);
+  if (has_frame_ &&
+      options.Get(switches::kUseContentSize, &use_content_size) &&
+      use_content_size)
+    bounds = window_->non_client_view()->GetWindowBoundsForClientBounds(bounds);
 
-  web_view_->SetWebContents(web_contents);
+  window_->CenterWindow(bounds.size());
 }
 
 NativeWindowViews::~NativeWindowViews() {
@@ -140,13 +151,23 @@ gfx::Size NativeWindowViews::GetSize() {
 }
 
 void NativeWindowViews::SetContentSize(const gfx::Size& size) {
-  // FIXME
-  SetSize(size);
+  if (!has_frame_) {
+    SetSize(size);
+    return;
+  }
+
+  gfx::Rect bounds = window_->GetWindowBoundsInScreen();
+  bounds.set_size(size);
+  window_->SetBounds(
+      window_->non_client_view()->GetWindowBoundsForClientBounds(bounds));
 }
 
 gfx::Size NativeWindowViews::GetContentSize() {
-  // FIXME
-  return GetSize();
+  if (!has_frame_)
+    return GetSize();
+
+  return window_->non_client_view()->frame_view()->
+      GetBoundsForClientView().size();
 }
 
 void NativeWindowViews::SetMinimumSize(const gfx::Size& size) {
@@ -166,7 +187,6 @@ gfx::Size NativeWindowViews::GetMaximumSize() {
 }
 
 void NativeWindowViews::SetResizable(bool resizable) {
-  // FIXME
   resizable_ = resizable;
 }
 
@@ -179,8 +199,7 @@ void NativeWindowViews::SetAlwaysOnTop(bool top) {
 }
 
 bool NativeWindowViews::IsAlwaysOnTop() {
-  // FIXME
-  return false;
+  return window_->IsAlwaysOnTop();
 }
 
 void NativeWindowViews::Center() {
@@ -226,13 +245,7 @@ gfx::NativeWindow NativeWindowViews::GetNativeWindow() {
 
 void NativeWindowViews::UpdateDraggableRegions(
     const std::vector<DraggableRegion>& regions) {
-}
-
-void NativeWindowViews::ViewHierarchyChanged(
-  const ViewHierarchyChangedDetails& details) {
-  if (details.is_add && details.child == this) {
-    AddChildView(web_view_);
-  }
+  // FIXME
 }
 
 void NativeWindowViews::DeleteDelegate() {
@@ -286,6 +299,13 @@ views::ClientView* NativeWindowViews::CreateClientView(views::Widget* widget) {
   return new NativeWindowClientView(widget, this);
 }
 
+views::NonClientFrameView* NativeWindowViews::CreateNonClientFrameView(
+    views::Widget* widget) {
+  views::CustomFrameView* frame_view = new views::CustomFrameView;
+  frame_view->Init(widget);
+  return frame_view;
+}
+
 // static
 NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
                                    const mate::Dictionary& options) {
index 075f333..2b03972 100644 (file)
@@ -69,10 +69,6 @@ class NativeWindowViews : public NativeWindow,
   virtual void UpdateDraggableRegions(
       const std::vector<DraggableRegion>& regions) OVERRIDE;
 
-  // views::View:
-  virtual void ViewHierarchyChanged(
-      const ViewHierarchyChangedDetails& details) OVERRIDE;
-
   // views::WidgetDelegate:
   virtual void DeleteDelegate() OVERRIDE;
   virtual views::View* GetInitiallyFocusedView() OVERRIDE;
@@ -86,6 +82,8 @@ class NativeWindowViews : public NativeWindow,
   virtual const views::Widget* GetWidget() const OVERRIDE;
   virtual views::View* GetContentsView() OVERRIDE;
   virtual views::ClientView* CreateClientView(views::Widget* widget) OVERRIDE;
+  virtual views::NonClientFrameView* CreateNonClientFrameView(
+      views::Widget* widget) OVERRIDE;
 
   scoped_ptr<views::Widget> window_;
   views::WebView* web_view_;  // managed by window_.
index 4168d79..a08f187 100644 (file)
@@ -127,6 +127,7 @@ MessageDialog::MessageDialog(NativeWindow* parent_window,
   views::Widget::InitParams widget_params;
   widget_params.delegate = this;
   widget_params.top_level = true;
+  widget_params.remove_standard_frame = true;
   if (parent_window)
     widget_params.parent = parent_window->GetNativeWindow();
   widget_ = new views::Widget;
index f8baf4a..b2e79c9 160000 (submodule)
@@ -1 +1 @@
-Subproject commit f8baf4a4bad51536ab013b4ee2edd9d749df695d
+Subproject commit b2e79c9803b61a9b90aa45af32686e8ef9d4c571