|
@@ -22,6 +22,11 @@
|
|
|
|
|
|
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.
|
|
|
class ScopedDisableResize {
|
|
|
public:
|
|
@@ -549,56 +554,18 @@ gfx::Rect NativeWindowMac::GetBounds() {
|
|
|
return bounds;
|
|
|
}
|
|
|
|
|
|
-void NativeWindowMac::SetContentSize(const gfx::Size& size) {
|
|
|
- if (!has_frame()) {
|
|
|
- SetSize(size);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- NSRect frame_nsrect = [window_ frame];
|
|
|
- NSSize frame = frame_nsrect.size;
|
|
|
- NSSize content = [window_ contentRectForFrameRect:frame_nsrect].size;
|
|
|
-
|
|
|
- int width = size.width() + frame.width - content.width;
|
|
|
- int height = size.height() + frame.height - content.height;
|
|
|
- frame_nsrect.origin.y -= height - frame_nsrect.size.height;
|
|
|
- frame_nsrect.size.width = width;
|
|
|
- frame_nsrect.size.height = height;
|
|
|
- [window_ setFrame:frame_nsrect display:YES];
|
|
|
-}
|
|
|
-
|
|
|
-gfx::Size NativeWindowMac::GetContentSize() {
|
|
|
- if (!has_frame())
|
|
|
- return GetSize();
|
|
|
-
|
|
|
- NSRect bounds = [[window_ contentView] bounds];
|
|
|
- return gfx::Size(bounds.size.width, bounds.size.height);
|
|
|
-}
|
|
|
-
|
|
|
-void NativeWindowMac::SetMinimumSize(const gfx::Size& size) {
|
|
|
- NSSize min_size = NSMakeSize(size.width(), size.height());
|
|
|
+void NativeWindowMac::SetContentSizeConstraints(
|
|
|
+ const extensions::SizeConstraints& size_constraints) {
|
|
|
NSView* content = [window_ contentView];
|
|
|
- [window_ setContentMinSize:[content convertSize:min_size toView:nil]];
|
|
|
-}
|
|
|
-
|
|
|
-gfx::Size NativeWindowMac::GetMinimumSize() {
|
|
|
- NSView* content = [window_ contentView];
|
|
|
- NSSize min_size = [content convertSize:[window_ contentMinSize]
|
|
|
- fromView:nil];
|
|
|
- return gfx::Size(min_size.width, min_size.height);
|
|
|
-}
|
|
|
-
|
|
|
-void NativeWindowMac::SetMaximumSize(const gfx::Size& size) {
|
|
|
- NSSize max_size = NSMakeSize(size.width(), size.height());
|
|
|
- NSView* content = [window_ contentView];
|
|
|
- [window_ setContentMaxSize:[content convertSize:max_size toView:nil]];
|
|
|
-}
|
|
|
-
|
|
|
-gfx::Size NativeWindowMac::GetMaximumSize() {
|
|
|
- NSView* content = [window_ contentView];
|
|
|
- NSSize max_size = [content convertSize:[window_ contentMaxSize]
|
|
|
- fromView:nil];
|
|
|
- return gfx::Size(max_size.width, max_size.height);
|
|
|
+ if (size_constraints.HasMinimumSize()) {
|
|
|
+ NSSize min_size = ToNSSize(size_constraints.GetMinimumSize());
|
|
|
+ [window_ setMinSize:[content convertSize:min_size toView:nil]];
|
|
|
+ }
|
|
|
+ if (size_constraints.HasMaximumSize()) {
|
|
|
+ NSSize max_size = ToNSSize(size_constraints.GetMaximumSize());
|
|
|
+ [window_ setMaxSize:[content convertSize:max_size toView:nil]];
|
|
|
+ }
|
|
|
+ NativeWindow::SetContentSizeConstraints(size_constraints);
|
|
|
}
|
|
|
|
|
|
void NativeWindowMac::SetResizable(bool resizable) {
|
|
@@ -821,6 +788,18 @@ void NativeWindowMac::HandleKeyboardEvent(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+gfx::Size NativeWindowMac::ContentSizeToWindowSize(const gfx::Size& size) {
|
|
|
+ NSRect content = NSMakeRect(0, 0, size.width(), size.height());
|
|
|
+ NSRect frame = [window_ frameRectForContentRect:content];
|
|
|
+ return gfx::Size(frame.size);
|
|
|
+}
|
|
|
+
|
|
|
+gfx::Size NativeWindowMac::WindowSizeToContentSize(const gfx::Size& size) {
|
|
|
+ NSRect frame = NSMakeRect(0, 0, size.width(), size.height());
|
|
|
+ NSRect content = [window_ contentRectForFrameRect:frame];
|
|
|
+ return gfx::Size(content.size);
|
|
|
+}
|
|
|
+
|
|
|
void NativeWindowMac::InstallView() {
|
|
|
// Make sure the bottom corner is rounded: http://crbug.com/396264.
|
|
|
[[window_ contentView] setWantsLayer:YES];
|