| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/widget/native_widget_mac.h" | 5 #include "ui/views/widget/native_widget_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 12 #import "ui/base/cocoa/window_size_constants.h" |
| 12 #include "ui/gfx/font_list.h" | 13 #include "ui/gfx/font_list.h" |
| 13 #import "ui/gfx/mac/coordinate_conversion.h" | 14 #import "ui/gfx/mac/coordinate_conversion.h" |
| 14 #include "ui/native_theme/native_theme.h" | 15 #include "ui/native_theme/native_theme.h" |
| 15 #import "ui/views/cocoa/bridged_content_view.h" | 16 #import "ui/views/cocoa/bridged_content_view.h" |
| 16 #import "ui/views/cocoa/bridged_native_widget.h" | 17 #import "ui/views/cocoa/bridged_native_widget.h" |
| 17 #import "ui/views/cocoa/native_widget_mac_nswindow.h" | 18 #import "ui/views/cocoa/native_widget_mac_nswindow.h" |
| 18 #import "ui/views/cocoa/views_nswindow_delegate.h" | 19 #import "ui/views/cocoa/views_nswindow_delegate.h" |
| 19 #include "ui/views/window/native_frame_view.h" | 20 #include "ui/views/window/native_frame_view.h" |
| 20 | 21 |
| 21 namespace views { | 22 namespace views { |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 NSInteger StyleMaskForParams(const Widget::InitParams& params) { | 25 NSInteger StyleMaskForParams(const Widget::InitParams& params) { |
| 25 // TODO(tapted): Determine better masks when there are use cases for it. | 26 // TODO(tapted): Determine better masks when there are use cases for it. |
| 26 if (params.remove_standard_frame) | 27 if (params.remove_standard_frame) |
| 27 return NSBorderlessWindowMask; | 28 return NSBorderlessWindowMask; |
| 28 | 29 |
| 29 if (params.type == Widget::InitParams::TYPE_WINDOW) { | 30 if (params.type == Widget::InitParams::TYPE_WINDOW) { |
| 30 return NSTitledWindowMask | NSClosableWindowMask | | 31 return NSTitledWindowMask | NSClosableWindowMask | |
| 31 NSMiniaturizableWindowMask | NSResizableWindowMask; | 32 NSMiniaturizableWindowMask | NSResizableWindowMask; |
| 32 } | 33 } |
| 33 return NSBorderlessWindowMask; | 34 return NSBorderlessWindowMask; |
| 34 } | 35 } |
| 35 | 36 |
| 36 NSRect ValidateContentRect(NSRect content_rect) { | |
| 37 // A contentRect with zero width or height is a banned practice in Chrome, due | |
| 38 // to unpredictable OSX treatment. For now, silently give a minimum dimension. | |
| 39 // TODO(tapted): Add a DCHECK, or add emulation logic (e.g. to auto-hide). | |
| 40 if (NSWidth(content_rect) == 0) | |
| 41 content_rect.size.width = 1; | |
| 42 | |
| 43 if (NSHeight(content_rect) == 0) | |
| 44 content_rect.size.height = 1; | |
| 45 | |
| 46 return content_rect; | |
| 47 } | |
| 48 | |
| 49 gfx::Size WindowSizeForClientAreaSize(NSWindow* window, const gfx::Size& size) { | 37 gfx::Size WindowSizeForClientAreaSize(NSWindow* window, const gfx::Size& size) { |
| 50 NSRect content_rect = NSMakeRect(0, 0, size.width(), size.height()); | 38 NSRect content_rect = NSMakeRect(0, 0, size.width(), size.height()); |
| 51 NSRect frame_rect = [window frameRectForContentRect:content_rect]; | 39 NSRect frame_rect = [window frameRectForContentRect:content_rect]; |
| 52 return gfx::Size(NSWidth(frame_rect), NSHeight(frame_rect)); | 40 return gfx::Size(NSWidth(frame_rect), NSHeight(frame_rect)); |
| 53 } | 41 } |
| 54 | 42 |
| 55 } // namespace | 43 } // namespace |
| 56 | 44 |
| 57 //////////////////////////////////////////////////////////////////////////////// | 45 //////////////////////////////////////////////////////////////////////////////// |
| 58 // NativeWidgetMac, public: | 46 // NativeWidgetMac, public: |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 delete this; | 80 delete this; |
| 93 } | 81 } |
| 94 | 82 |
| 95 //////////////////////////////////////////////////////////////////////////////// | 83 //////////////////////////////////////////////////////////////////////////////// |
| 96 // NativeWidgetMac, internal::NativeWidgetPrivate implementation: | 84 // NativeWidgetMac, internal::NativeWidgetPrivate implementation: |
| 97 | 85 |
| 98 void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { | 86 void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { |
| 99 ownership_ = params.ownership; | 87 ownership_ = params.ownership; |
| 100 | 88 |
| 101 NSInteger style_mask = StyleMaskForParams(params); | 89 NSInteger style_mask = StyleMaskForParams(params); |
| 102 NSRect content_rect = ValidateContentRect( | |
| 103 [NSWindow contentRectForFrameRect:gfx::ScreenRectToNSRect(params.bounds) | |
| 104 styleMask:style_mask]); | |
| 105 | |
| 106 base::scoped_nsobject<NSWindow> window([[NativeWidgetMacNSWindow alloc] | 90 base::scoped_nsobject<NSWindow> window([[NativeWidgetMacNSWindow alloc] |
| 107 initWithContentRect:content_rect | 91 initWithContentRect:ui::kWindowSizeDeterminedLater |
| 108 styleMask:style_mask | 92 styleMask:style_mask |
| 109 backing:NSBackingStoreBuffered | 93 backing:NSBackingStoreBuffered |
| 110 defer:YES]); | 94 defer:YES]); |
| 111 [window setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. | 95 [window setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. |
| 112 bridge_->Init(window, params); | 96 bridge_->Init(window, params); |
| 113 | 97 |
| 114 delegate_->OnNativeWidgetCreated(true); | 98 delegate_->OnNativeWidgetCreated(true); |
| 115 | 99 |
| 116 bridge_->SetFocusManager(GetWidget()->GetFocusManager()); | 100 bridge_->SetFocusManager(GetWidget()->GetFocusManager()); |
| 117 | 101 |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 } | 618 } |
| 635 | 619 |
| 636 // static | 620 // static |
| 637 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() { | 621 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() { |
| 638 NOTIMPLEMENTED(); | 622 NOTIMPLEMENTED(); |
| 639 return gfx::FontList(); | 623 return gfx::FontList(); |
| 640 } | 624 } |
| 641 | 625 |
| 642 } // namespace internal | 626 } // namespace internal |
| 643 } // namespace views | 627 } // namespace views |
| OLD | NEW |