osx: Fix setting size constraints for frameless window
This commit is contained in:
parent
428c5b6d01
commit
6fea6cf58a
1 changed files with 14 additions and 7 deletions
|
@ -22,11 +22,6 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Converts gfx::Size to NSSize.
|
|
||||||
inline NSSize ToNSSize(const gfx::Size& size) {
|
|
||||||
return NSMakeSize(size.width(), size.height());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prevents window from resizing during the scope.
|
// Prevents window from resizing during the scope.
|
||||||
class ScopedDisableResize {
|
class ScopedDisableResize {
|
||||||
public:
|
public:
|
||||||
|
@ -556,13 +551,25 @@ gfx::Rect NativeWindowMac::GetBounds() {
|
||||||
|
|
||||||
void NativeWindowMac::SetContentSizeConstraints(
|
void NativeWindowMac::SetContentSizeConstraints(
|
||||||
const extensions::SizeConstraints& size_constraints) {
|
const extensions::SizeConstraints& size_constraints) {
|
||||||
|
auto convertSize = [this](const gfx::Size& size) {
|
||||||
|
// Our frameless window still has titlebar attached, so setting contentSize
|
||||||
|
// will result in actual content size being larger.
|
||||||
|
if (!has_frame()) {
|
||||||
|
NSRect frame = NSMakeRect(0, 0, size.width(), size.height());
|
||||||
|
NSRect content = [window_ contentRectForFrameRect:frame];
|
||||||
|
return content.size;
|
||||||
|
} else {
|
||||||
|
return NSMakeSize(size.width(), size.height());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
NSView* content = [window_ contentView];
|
NSView* content = [window_ contentView];
|
||||||
if (size_constraints.HasMinimumSize()) {
|
if (size_constraints.HasMinimumSize()) {
|
||||||
NSSize min_size = ToNSSize(size_constraints.GetMinimumSize());
|
NSSize min_size = convertSize(size_constraints.GetMinimumSize());
|
||||||
[window_ setContentMinSize:[content convertSize:min_size toView:nil]];
|
[window_ setContentMinSize:[content convertSize:min_size toView:nil]];
|
||||||
}
|
}
|
||||||
if (size_constraints.HasMaximumSize()) {
|
if (size_constraints.HasMaximumSize()) {
|
||||||
NSSize max_size = ToNSSize(size_constraints.GetMaximumSize());
|
NSSize max_size = convertSize(size_constraints.GetMaximumSize());
|
||||||
[window_ setContentMaxSize:[content convertSize:max_size toView:nil]];
|
[window_ setContentMaxSize:[content convertSize:max_size toView:nil]];
|
||||||
}
|
}
|
||||||
NativeWindow::SetContentSizeConstraints(size_constraints);
|
NativeWindow::SetContentSizeConstraints(size_constraints);
|
||||||
|
|
Loading…
Reference in a new issue