views: Implement NativeWindow::SetSizeConstraints
This commit is contained in:
parent
8577f2b52f
commit
a76ea00249
6 changed files with 71 additions and 109 deletions
|
@ -186,7 +186,8 @@ NativeWindowViews::NativeWindowViews(
|
||||||
// will not allow us to resize the window larger than scree.
|
// will not allow us to resize the window larger than scree.
|
||||||
// Setting directly to INT_MAX somehow doesn't work, so we just devide
|
// Setting directly to INT_MAX somehow doesn't work, so we just devide
|
||||||
// by 10, which should still be large enough.
|
// by 10, which should still be large enough.
|
||||||
maximum_size_.SetSize(INT_MAX / 10, INT_MAX / 10);
|
SetContentSizeConstraints(extensions::SizeConstraints(
|
||||||
|
gfx::Size(), gfx::Size(INT_MAX / 10, INT_MAX / 10)));
|
||||||
|
|
||||||
int width = 800, height = 600;
|
int width = 800, height = 600;
|
||||||
options.Get(switches::kWidth, &width);
|
options.Get(switches::kWidth, &width);
|
||||||
|
@ -271,11 +272,6 @@ NativeWindowViews::NativeWindowViews(
|
||||||
set_background(views::Background::CreateStandardPanelBackground());
|
set_background(views::Background::CreateStandardPanelBackground());
|
||||||
AddChildView(web_view_);
|
AddChildView(web_view_);
|
||||||
|
|
||||||
if (has_frame() &&
|
|
||||||
options.Get(switches::kUseContentSize, &use_content_size_) &&
|
|
||||||
use_content_size_)
|
|
||||||
bounds = ContentBoundsToWindowBounds(bounds);
|
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
// Save initial window state.
|
// Save initial window state.
|
||||||
if (fullscreen)
|
if (fullscreen)
|
||||||
|
@ -316,8 +312,14 @@ NativeWindowViews::NativeWindowViews(
|
||||||
if (transparent() && !has_frame())
|
if (transparent() && !has_frame())
|
||||||
wm::SetShadowType(GetNativeWindow(), wm::SHADOW_TYPE_NONE);
|
wm::SetShadowType(GetNativeWindow(), wm::SHADOW_TYPE_NONE);
|
||||||
|
|
||||||
|
gfx::Size size = bounds.size();
|
||||||
|
if (has_frame() &&
|
||||||
|
options.Get(switches::kUseContentSize, &use_content_size_) &&
|
||||||
|
use_content_size_)
|
||||||
|
size = ContentSizeToWindowSize(size);
|
||||||
|
|
||||||
window_->UpdateWindowIcon();
|
window_->UpdateWindowIcon();
|
||||||
window_->CenterWindow(bounds.size());
|
window_->CenterWindow(size);
|
||||||
Layout();
|
Layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,60 +442,6 @@ gfx::Rect NativeWindowViews::GetBounds() {
|
||||||
return window_->GetWindowBoundsInScreen();
|
return window_->GetWindowBoundsInScreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowViews::SetSizeConstraints(
|
|
||||||
const extensions::SizeConstraints& size_constraints) {
|
|
||||||
}
|
|
||||||
|
|
||||||
extensions::SizeConstraints NativeWindowViews::GetSizeConstraints() {
|
|
||||||
return extensions::SizeConstraints();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindowViews::SetContentSizeConstraints(
|
|
||||||
const extensions::SizeConstraints& size_constraints) {
|
|
||||||
}
|
|
||||||
|
|
||||||
extensions::SizeConstraints NativeWindowViews::GetContentSizeConstraints() {
|
|
||||||
return extensions::SizeConstraints();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindowViews::SetContentSize(const gfx::Size& size) {
|
|
||||||
if (!has_frame()) {
|
|
||||||
NativeWindow::SetSize(size);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
gfx::Rect bounds = window_->GetWindowBoundsInScreen();
|
|
||||||
bounds.set_size(size);
|
|
||||||
SetBounds(ContentBoundsToWindowBounds(bounds));
|
|
||||||
}
|
|
||||||
|
|
||||||
gfx::Size NativeWindowViews::GetContentSize() {
|
|
||||||
if (!has_frame())
|
|
||||||
return GetSize();
|
|
||||||
|
|
||||||
gfx::Size content_size =
|
|
||||||
window_->non_client_view()->frame_view()->GetBoundsForClientView().size();
|
|
||||||
if (menu_bar_ && menu_bar_visible_)
|
|
||||||
content_size.set_height(content_size.height() - kMenuBarHeight);
|
|
||||||
return content_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindowViews::SetMinimumSize(const gfx::Size& size) {
|
|
||||||
minimum_size_ = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
gfx::Size NativeWindowViews::GetMinimumSize() {
|
|
||||||
return minimum_size_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindowViews::SetMaximumSize(const gfx::Size& size) {
|
|
||||||
maximum_size_ = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
gfx::Size NativeWindowViews::GetMaximumSize() {
|
|
||||||
return maximum_size_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindowViews::SetResizable(bool resizable) {
|
void NativeWindowViews::SetResizable(bool resizable) {
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
// WS_MAXIMIZEBOX => Maximize button
|
// WS_MAXIMIZEBOX => Maximize button
|
||||||
|
@ -929,6 +877,47 @@ gfx::Size NativeWindowViews::WindowSizeToFramelessSize(
|
||||||
return window_bounds.size();
|
return window_bounds.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gfx::Size NativeWindowViews::ContentSizeToWindowSize(const gfx::Size& size) {
|
||||||
|
if (!has_frame())
|
||||||
|
return size;
|
||||||
|
|
||||||
|
gfx::Size window_size(size);
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
gfx::Rect dpi_bounds =
|
||||||
|
gfx::Rect(gfx::Point(), gfx::win::DIPToScreenSize(size));
|
||||||
|
gfx::Rect window_bounds = gfx::win::ScreenToDIPRect(
|
||||||
|
window_->non_client_view()->GetWindowBoundsForClientBounds(dpi_bounds));
|
||||||
|
window_size = window_bounds.size();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (menu_bar_ && menu_bar_visible_)
|
||||||
|
window_size.set_height(window_size.height() + kMenuBarHeight);
|
||||||
|
return window_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx::Size NativeWindowViews::WindowSizeToContentSize(const gfx::Size& size) {
|
||||||
|
if (!has_frame())
|
||||||
|
return size;
|
||||||
|
|
||||||
|
gfx::Size content_size(size);
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
content_size = gfx::win::DIPToScreenSize(content_size);
|
||||||
|
RECT rect;
|
||||||
|
SetRectEmpty(&rect);
|
||||||
|
HWND hwnd = GetAcceleratedWidget();
|
||||||
|
DWORD style = ::GetWindowLong(hwnd, GWL_STYLE);
|
||||||
|
DWORD ex_style = ::GetWindowLong(hwnd, GWL_EXSTYLE);
|
||||||
|
AdjustWindowRectEx(&rect, style, FALSE, ex_style);
|
||||||
|
content_size.set_width(content_size.width() - (rect.right - rect.left));
|
||||||
|
content_size.set_height(content_size.height() - (rect.bottom - rect.top));
|
||||||
|
content_size = gfx::win::ScreenToDIPSize(content_size);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (menu_bar_ && menu_bar_visible_)
|
||||||
|
content_size.set_height(content_size.height() - kMenuBarHeight);
|
||||||
|
return content_size;
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowViews::HandleKeyboardEvent(
|
void NativeWindowViews::HandleKeyboardEvent(
|
||||||
content::WebContents*,
|
content::WebContents*,
|
||||||
const content::NativeWebKeyboardEvent& event) {
|
const content::NativeWebKeyboardEvent& event) {
|
||||||
|
@ -970,6 +959,14 @@ void NativeWindowViews::HandleKeyboardEvent(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gfx::Size NativeWindowViews::GetMinimumSize() {
|
||||||
|
return NativeWindow::GetMinimumSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx::Size NativeWindowViews::GetMaximumSize() {
|
||||||
|
return NativeWindow::GetMaximumSize();
|
||||||
|
}
|
||||||
|
|
||||||
bool NativeWindowViews::AcceleratorPressed(const ui::Accelerator& accelerator) {
|
bool NativeWindowViews::AcceleratorPressed(const ui::Accelerator& accelerator) {
|
||||||
return accelerator_util::TriggerAcceleratorTableCommand(
|
return accelerator_util::TriggerAcceleratorTableCommand(
|
||||||
&accelerator_table_, accelerator);
|
&accelerator_table_, accelerator);
|
||||||
|
@ -992,26 +989,6 @@ void NativeWindowViews::RegisterAccelerators(ui::MenuModel* menu_model) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Rect NativeWindowViews::ContentBoundsToWindowBounds(
|
|
||||||
const gfx::Rect& bounds) {
|
|
||||||
gfx::Point origin = bounds.origin();
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
gfx::Rect dpi_bounds = gfx::win::DIPToScreenRect(bounds);
|
|
||||||
gfx::Rect window_bounds = gfx::win::ScreenToDIPRect(
|
|
||||||
window_->non_client_view()->GetWindowBoundsForClientBounds(dpi_bounds));
|
|
||||||
#else
|
|
||||||
gfx::Rect window_bounds =
|
|
||||||
window_->non_client_view()->GetWindowBoundsForClientBounds(bounds);
|
|
||||||
#endif
|
|
||||||
// The window's position would also be changed, but we only want to change
|
|
||||||
// the size.
|
|
||||||
window_bounds.set_origin(origin);
|
|
||||||
|
|
||||||
if (menu_bar_ && menu_bar_visible_)
|
|
||||||
window_bounds.set_height(window_bounds.height() + kMenuBarHeight);
|
|
||||||
return window_bounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
ui::WindowShowState NativeWindowViews::GetRestoredState() {
|
ui::WindowShowState NativeWindowViews::GetRestoredState() {
|
||||||
if (IsMaximized())
|
if (IsMaximized())
|
||||||
return ui::SHOW_STATE_MAXIMIZED;
|
return ui::SHOW_STATE_MAXIMIZED;
|
||||||
|
|
|
@ -63,18 +63,6 @@ class NativeWindowViews : public NativeWindow,
|
||||||
bool IsFullscreen() const override;
|
bool IsFullscreen() const override;
|
||||||
void SetBounds(const gfx::Rect& bounds) override;
|
void SetBounds(const gfx::Rect& bounds) override;
|
||||||
gfx::Rect GetBounds() override;
|
gfx::Rect GetBounds() override;
|
||||||
void SetSizeConstraints(
|
|
||||||
const extensions::SizeConstraints& size_constraints) override;
|
|
||||||
extensions::SizeConstraints GetSizeConstraints() override;
|
|
||||||
void SetContentSizeConstraints(
|
|
||||||
const extensions::SizeConstraints& size_constraints) override;
|
|
||||||
extensions::SizeConstraints GetContentSizeConstraints() override;
|
|
||||||
void SetContentSize(const gfx::Size& size) override;
|
|
||||||
gfx::Size GetContentSize() override;
|
|
||||||
void SetMinimumSize(const gfx::Size& size) override;
|
|
||||||
gfx::Size GetMinimumSize() override;
|
|
||||||
void SetMaximumSize(const gfx::Size& size) override;
|
|
||||||
gfx::Size GetMaximumSize() override;
|
|
||||||
void SetResizable(bool resizable) override;
|
void SetResizable(bool resizable) override;
|
||||||
bool IsResizable() override;
|
bool IsResizable() override;
|
||||||
void SetAlwaysOnTop(bool top) override;
|
void SetAlwaysOnTop(bool top) override;
|
||||||
|
@ -148,20 +136,20 @@ class NativeWindowViews : public NativeWindow,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// NativeWindow:
|
// NativeWindow:
|
||||||
|
gfx::Size ContentSizeToWindowSize(const gfx::Size& size) override;
|
||||||
|
gfx::Size WindowSizeToContentSize(const gfx::Size& size) override;
|
||||||
void HandleKeyboardEvent(
|
void HandleKeyboardEvent(
|
||||||
content::WebContents*,
|
content::WebContents*,
|
||||||
const content::NativeWebKeyboardEvent& event) override;
|
const content::NativeWebKeyboardEvent& event) override;
|
||||||
|
|
||||||
// views::View:
|
// views::View:
|
||||||
|
gfx::Size GetMinimumSize() override;
|
||||||
|
gfx::Size GetMaximumSize() override;
|
||||||
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
||||||
|
|
||||||
// Register accelerators supported by the menu model.
|
// Register accelerators supported by the menu model.
|
||||||
void RegisterAccelerators(ui::MenuModel* menu_model);
|
void RegisterAccelerators(ui::MenuModel* menu_model);
|
||||||
|
|
||||||
// Converts between client area and window area, since we include the menu bar
|
|
||||||
// in client area we need to substract/add menu bar's height in convertions.
|
|
||||||
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& content_bounds);
|
|
||||||
|
|
||||||
// Returns the restore state for the window.
|
// Returns the restore state for the window.
|
||||||
ui::WindowShowState GetRestoredState();
|
ui::WindowShowState GetRestoredState();
|
||||||
|
|
||||||
|
@ -203,8 +191,6 @@ class NativeWindowViews : public NativeWindow,
|
||||||
bool use_content_size_;
|
bool use_content_size_;
|
||||||
bool resizable_;
|
bool resizable_;
|
||||||
std::string title_;
|
std::string title_;
|
||||||
gfx::Size minimum_size_;
|
|
||||||
gfx::Size maximum_size_;
|
|
||||||
gfx::Size widget_size_;
|
gfx::Size widget_size_;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(NativeWindowViews);
|
DISALLOW_COPY_AND_ASSIGN(NativeWindowViews);
|
||||||
|
|
|
@ -104,11 +104,11 @@ gfx::Size FramelessView::GetPreferredSize() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Size FramelessView::GetMinimumSize() const {
|
gfx::Size FramelessView::GetMinimumSize() const {
|
||||||
return window_->GetMinimumSize();
|
return static_cast<NativeWindow*>(window_)->GetMinimumSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Size FramelessView::GetMaximumSize() const {
|
gfx::Size FramelessView::GetMaximumSize() const {
|
||||||
return window_->GetMaximumSize();
|
return static_cast<NativeWindow*>(window_)->GetMaximumSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* FramelessView::GetClassName() const {
|
const char* FramelessView::GetClassName() const {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
#include "atom/browser/ui/views/native_frame_view.h"
|
#include "atom/browser/ui/views/native_frame_view.h"
|
||||||
|
|
||||||
#include "atom/browser/native_window_views.h"
|
#include "atom/browser/native_window.h"
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
@ -14,8 +14,7 @@ const char kViewClassName[] = "AtomNativeFrameView";
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
NativeFrameView::NativeFrameView(NativeWindowViews* window,
|
NativeFrameView::NativeFrameView(NativeWindow* window, views::Widget* widget)
|
||||||
views::Widget* widget)
|
|
||||||
: views::NativeFrameView(widget),
|
: views::NativeFrameView(widget),
|
||||||
window_(window) {
|
window_(window) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,13 +9,13 @@
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
class NativeWindowViews;
|
class NativeWindow;
|
||||||
|
|
||||||
// Like the views::NativeFrameView, but returns the min/max size from the
|
// Like the views::NativeFrameView, but returns the min/max size from the
|
||||||
// NativeWindowViews.
|
// NativeWindowViews.
|
||||||
class NativeFrameView : public views::NativeFrameView {
|
class NativeFrameView : public views::NativeFrameView {
|
||||||
public:
|
public:
|
||||||
NativeFrameView(NativeWindowViews* window, views::Widget* widget);
|
NativeFrameView(NativeWindow* window, views::Widget* widget);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// views::View:
|
// views::View:
|
||||||
|
@ -24,7 +24,7 @@ class NativeFrameView : public views::NativeFrameView {
|
||||||
const char* GetClassName() const override;
|
const char* GetClassName() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NativeWindowViews* window_; // weak ref.
|
NativeWindow* window_; // weak ref.
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(NativeFrameView);
|
DISALLOW_COPY_AND_ASSIGN(NativeFrameView);
|
||||||
};
|
};
|
||||||
|
|
|
@ -41,13 +41,13 @@ int WinFrameView::NonClientHitTest(const gfx::Point& point) {
|
||||||
|
|
||||||
gfx::Size WinFrameView::GetMinimumSize() const {
|
gfx::Size WinFrameView::GetMinimumSize() const {
|
||||||
gfx::Size size = window_->WindowSizeToFramelessSize(
|
gfx::Size size = window_->WindowSizeToFramelessSize(
|
||||||
window_->GetMinimumSize());
|
FramelessView::GetMinimumSize());
|
||||||
return gfx::win::DIPToScreenSize(size);
|
return gfx::win::DIPToScreenSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Size WinFrameView::GetMaximumSize() const {
|
gfx::Size WinFrameView::GetMaximumSize() const {
|
||||||
gfx::Size size = window_->WindowSizeToFramelessSize(
|
gfx::Size size = window_->WindowSizeToFramelessSize(
|
||||||
window_->GetMaximumSize());
|
FramelessView::GetMaximumSize());
|
||||||
return gfx::win::DIPToScreenSize(size);
|
return gfx::win::DIPToScreenSize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue