| 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" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 if (params.remove_standard_frame) | 27 if (params.remove_standard_frame) |
| 28 return NSBorderlessWindowMask; | 28 return NSBorderlessWindowMask; |
| 29 | 29 |
| 30 if (params.type == Widget::InitParams::TYPE_WINDOW) { | 30 if (params.type == Widget::InitParams::TYPE_WINDOW) { |
| 31 return NSTitledWindowMask | NSClosableWindowMask | | 31 return NSTitledWindowMask | NSClosableWindowMask | |
| 32 NSMiniaturizableWindowMask | NSResizableWindowMask; | 32 NSMiniaturizableWindowMask | NSResizableWindowMask; |
| 33 } | 33 } |
| 34 return NSBorderlessWindowMask; | 34 return NSBorderlessWindowMask; |
| 35 } | 35 } |
| 36 | 36 |
| 37 gfx::Size WindowSizeForClientAreaSize(NSWindow* window, const gfx::Size& size) { | |
| 38 NSRect content_rect = NSMakeRect(0, 0, size.width(), size.height()); | |
| 39 NSRect frame_rect = [window frameRectForContentRect:content_rect]; | |
| 40 return gfx::Size(NSWidth(frame_rect), NSHeight(frame_rect)); | |
| 41 } | |
| 42 | |
| 43 } // namespace | 37 } // namespace |
| 44 | 38 |
| 45 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
| 46 // NativeWidgetMac, public: | 40 // NativeWidgetMac, public: |
| 47 | 41 |
| 48 NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate) | 42 NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate) |
| 49 : delegate_(delegate), | 43 : delegate_(delegate), |
| 50 bridge_(new BridgedNativeWidget(this)), | 44 bridge_(new BridgedNativeWidget(this)), |
| 51 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) { | 45 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) { |
| 52 } | 46 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 // NativeWidgetMac, internal::NativeWidgetPrivate implementation: | 78 // NativeWidgetMac, internal::NativeWidgetPrivate implementation: |
| 85 | 79 |
| 86 void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { | 80 void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { |
| 87 ownership_ = params.ownership; | 81 ownership_ = params.ownership; |
| 88 base::scoped_nsobject<NSWindow> window([CreateNSWindow(params) retain]); | 82 base::scoped_nsobject<NSWindow> window([CreateNSWindow(params) retain]); |
| 89 [window setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. | 83 [window setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. |
| 90 bridge_->Init(window, params); | 84 bridge_->Init(window, params); |
| 91 | 85 |
| 92 delegate_->OnNativeWidgetCreated(true); | 86 delegate_->OnNativeWidgetCreated(true); |
| 93 | 87 |
| 94 OnSizeConstraintsChanged(); | |
| 95 | |
| 96 bridge_->SetFocusManager(GetWidget()->GetFocusManager()); | 88 bridge_->SetFocusManager(GetWidget()->GetFocusManager()); |
| 97 | 89 |
| 98 DCHECK(GetWidget()->GetRootView()); | 90 DCHECK(GetWidget()->GetRootView()); |
| 99 bridge_->SetRootView(GetWidget()->GetRootView()); | 91 bridge_->SetRootView(GetWidget()->GetRootView()); |
| 100 | 92 |
| 101 // "Infer" must be handled by ViewsDelegate::OnBeforeWidgetInit(). | 93 // "Infer" must be handled by ViewsDelegate::OnBeforeWidgetInit(). |
| 102 DCHECK_NE(Widget::InitParams::INFER_OPACITY, params.opacity); | 94 DCHECK_NE(Widget::InitParams::INFER_OPACITY, params.opacity); |
| 103 bool translucent = params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW; | 95 bool translucent = params.opacity == Widget::InitParams::TRANSLUCENT_WINDOW; |
| 104 bridge_->CreateLayer(params.layer_type, translucent); | 96 bridge_->CreateLayer(params.layer_type, translucent); |
| 105 } | 97 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 | 191 |
| 200 internal::InputMethodDelegate* NativeWidgetMac::GetInputMethodDelegate() { | 192 internal::InputMethodDelegate* NativeWidgetMac::GetInputMethodDelegate() { |
| 201 return bridge_.get(); | 193 return bridge_.get(); |
| 202 } | 194 } |
| 203 | 195 |
| 204 ui::InputMethod* NativeWidgetMac::GetHostInputMethod() { | 196 ui::InputMethod* NativeWidgetMac::GetHostInputMethod() { |
| 205 return bridge_ ? bridge_->GetHostInputMethod() : NULL; | 197 return bridge_ ? bridge_->GetHostInputMethod() : NULL; |
| 206 } | 198 } |
| 207 | 199 |
| 208 void NativeWidgetMac::CenterWindow(const gfx::Size& size) { | 200 void NativeWidgetMac::CenterWindow(const gfx::Size& size) { |
| 209 SetSize(WindowSizeForClientAreaSize(GetNativeWindow(), size)); | 201 SetSize( |
| 202 BridgedNativeWidget::GetWindowSizeForClientSize(GetNativeWindow(), size)); |
| 210 // Note that this is not the precise center of screen, but it is the standard | 203 // Note that this is not the precise center of screen, but it is the standard |
| 211 // location for windows like dialogs to appear on screen for Mac. | 204 // location for windows like dialogs to appear on screen for Mac. |
| 212 // TODO(tapted): If there is a parent window, center in that instead. | 205 // TODO(tapted): If there is a parent window, center in that instead. |
| 213 [GetNativeWindow() center]; | 206 [GetNativeWindow() center]; |
| 214 } | 207 } |
| 215 | 208 |
| 216 void NativeWidgetMac::GetWindowPlacement( | 209 void NativeWidgetMac::GetWindowPlacement( |
| 217 gfx::Rect* bounds, | 210 gfx::Rect* bounds, |
| 218 ui::WindowShowState* show_state) const { | 211 ui::WindowShowState* show_state) const { |
| 219 *bounds = GetRestoredBounds(); | 212 *bounds = GetRestoredBounds(); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 void NativeWidgetMac::SetVisibilityAnimationTransition( | 501 void NativeWidgetMac::SetVisibilityAnimationTransition( |
| 509 Widget::VisibilityTransition transition) { | 502 Widget::VisibilityTransition transition) { |
| 510 NOTIMPLEMENTED(); | 503 NOTIMPLEMENTED(); |
| 511 } | 504 } |
| 512 | 505 |
| 513 ui::NativeTheme* NativeWidgetMac::GetNativeTheme() const { | 506 ui::NativeTheme* NativeWidgetMac::GetNativeTheme() const { |
| 514 return ui::NativeTheme::instance(); | 507 return ui::NativeTheme::instance(); |
| 515 } | 508 } |
| 516 | 509 |
| 517 void NativeWidgetMac::OnRootViewLayout() { | 510 void NativeWidgetMac::OnRootViewLayout() { |
| 518 NOTIMPLEMENTED(); | 511 // Ensure possible changes to the non-client view (e.g. Minimum/Maximum size) |
| 512 // propagate through to the NSWindow properties. |
| 513 OnSizeConstraintsChanged(); |
| 519 } | 514 } |
| 520 | 515 |
| 521 bool NativeWidgetMac::IsTranslucentWindowOpacitySupported() const { | 516 bool NativeWidgetMac::IsTranslucentWindowOpacitySupported() const { |
| 522 return false; | 517 return false; |
| 523 } | 518 } |
| 524 | 519 |
| 525 void NativeWidgetMac::OnSizeConstraintsChanged() { | 520 void NativeWidgetMac::OnSizeConstraintsChanged() { |
| 526 bridge_->OnSizeConstraintsChanged(); | 521 bridge_->OnSizeConstraintsChanged(); |
| 527 } | 522 } |
| 528 | 523 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 } | 632 } |
| 638 | 633 |
| 639 // static | 634 // static |
| 640 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() { | 635 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() { |
| 641 NOTIMPLEMENTED(); | 636 NOTIMPLEMENTED(); |
| 642 return gfx::FontList(); | 637 return gfx::FontList(); |
| 643 } | 638 } |
| 644 | 639 |
| 645 } // namespace internal | 640 } // namespace internal |
| 646 } // namespace views | 641 } // namespace views |
| OLD | NEW |