From 0a38f3321ea9901aef435308d84bdfa5544eda7b Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 4 Jul 2014 12:32:03 +0800 Subject: [PATCH] views: Currently set window's frames. --- atom/browser/native_window_views.cc | 60 ++++++++++++++++++---------- atom/browser/native_window_views.h | 6 +-- atom/browser/ui/message_box_views.cc | 1 + vendor/brightray | 2 +- 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 97ec074c64d..ced2513fac7 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -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& 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) { diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 075f3338fa5..2b039728850 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -69,10 +69,6 @@ class NativeWindowViews : public NativeWindow, virtual void UpdateDraggableRegions( const std::vector& 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 window_; views::WebView* web_view_; // managed by window_. diff --git a/atom/browser/ui/message_box_views.cc b/atom/browser/ui/message_box_views.cc index 4168d794b6c..a08f18708e7 100644 --- a/atom/browser/ui/message_box_views.cc +++ b/atom/browser/ui/message_box_views.cc @@ -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; diff --git a/vendor/brightray b/vendor/brightray index f8baf4a4bad..b2e79c9803b 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit f8baf4a4bad51536ab013b4ee2edd9d749df695d +Subproject commit b2e79c9803b61a9b90aa45af32686e8ef9d4c571