views: Currently set window's frames.

This commit is contained in:
Cheng Zhao 2014-07-04 12:32:03 +08:00
parent 61db17412c
commit 0a38f3321e
4 changed files with 44 additions and 25 deletions

View 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) {

View 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_.

View 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;

2
vendor/brightray vendored

@ -1 +1 @@
Subproject commit f8baf4a4bad51536ab013b4ee2edd9d749df695d
Subproject commit b2e79c9803b61a9b90aa45af32686e8ef9d4c571