Chromium Code Reviews| 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 <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 @interface ViewsNSWindowCloseAnimator : NSObject<NSAnimationDelegate> { | 30 @interface ViewsNSWindowCloseAnimator : NSObject<NSAnimationDelegate> { |
| 31 @private | 31 @private |
| 32 base::scoped_nsobject<NSWindow> window_; | 32 base::scoped_nsobject<NSWindow> window_; |
| 33 base::scoped_nsobject<NSAnimation> animation_; | 33 base::scoped_nsobject<NSAnimation> animation_; |
| 34 } | 34 } |
| 35 | 35 |
| 36 + (void)closeWindowWithAnimation:(NSWindow*)window; | 36 + (void)closeWindowWithAnimation:(NSWindow*)window; |
| 37 | 37 |
| 38 @end | 38 @end |
| 39 | 39 |
| 40 extern "C" { | |
| 41 | |
| 42 typedef int32_t CGSWindow; | |
| 43 typedef int32_t CGSConnection; | |
| 44 CGSConnection _CGSDefaultConnection(); | |
| 45 OSStatus CGSGetWindowBounds( | |
| 46 CGSConnection connection, CGSWindow window, CGRect* bounds); | |
| 47 | |
| 48 } | |
| 49 | |
| 40 namespace views { | 50 namespace views { |
| 41 namespace { | 51 namespace { |
| 42 | 52 |
| 43 NSInteger StyleMaskForParams(const Widget::InitParams& params) { | 53 NSInteger StyleMaskForParams(const Widget::InitParams& params) { |
| 44 // If the Widget is modal, it will be displayed as a sheet. This works best if | 54 // If the Widget is modal, it will be displayed as a sheet. This works best if |
| 45 // it has NSTitledWindowMask. For example, with NSBorderlessWindowMask, the | 55 // it has NSTitledWindowMask. For example, with NSBorderlessWindowMask, the |
| 46 // parent window still accepts input. | 56 // parent window still accepts input. |
| 47 if (params.delegate && | 57 if (params.delegate && |
| 48 params.delegate->GetModalType() == ui::MODAL_TYPE_WINDOW) | 58 params.delegate->GetModalType() == ui::MODAL_TYPE_WINDOW) |
| 49 return NSTitledWindowMask; | 59 return NSTitledWindowMask; |
| 50 | 60 |
| 51 // TODO(tapted): Determine better masks when there are use cases for it. | 61 // TODO(tapted): Determine better masks when there are use cases for it. |
| 52 if (params.remove_standard_frame) | 62 if (params.remove_standard_frame) |
| 53 return NSBorderlessWindowMask; | 63 return NSBorderlessWindowMask; |
| 54 | 64 |
| 55 if (params.type == Widget::InitParams::TYPE_WINDOW) { | 65 if (params.type == Widget::InitParams::TYPE_WINDOW) { |
| 56 return NSTitledWindowMask | NSClosableWindowMask | | 66 return NSTitledWindowMask | NSClosableWindowMask | |
| 57 NSMiniaturizableWindowMask | NSResizableWindowMask | | 67 NSMiniaturizableWindowMask | NSResizableWindowMask | |
| 58 NSTexturedBackgroundWindowMask; | 68 NSTexturedBackgroundWindowMask; |
| 59 } | 69 } |
| 60 return NSBorderlessWindowMask; | 70 return NSBorderlessWindowMask; |
| 61 } | 71 } |
| 62 | 72 |
| 73 // -[NSWindow frame] doesn't update during a window drag. This is not what | |
| 74 // toolkit-views expects, so ask the window server directly. | |
| 75 NSRect FrameIncludingDrag(NSWindow* window) { | |
| 76 CGRect bounds = NSZeroRect; | |
| 77 CGSGetWindowBounds(_CGSDefaultConnection(), [window windowNumber], &bounds); | |
| 78 NSRect rect = ScreenRectToNSRect(gfx::Rect(bounds)); | |
| 79 | |
| 80 // If no mouse buttons are down, there is no drag. So it should match the | |
| 81 // window frame. | |
| 82 //DCHECK([NSEvent pressedMouseButtons] == 0 || | |
|
tapted
2016/03/10 11:51:19
This DCHECK would actually fail, which surprised m
themblsha
2016/03/10 17:18:58
Done.
| |
| 83 // NSEqualRects(rect, [window frame])); | |
| 84 return rect; | |
| 85 } | |
| 86 | |
| 63 } // namespace | 87 } // namespace |
| 64 | 88 |
| 65 //////////////////////////////////////////////////////////////////////////////// | 89 //////////////////////////////////////////////////////////////////////////////// |
| 66 // NativeWidgetMac, public: | 90 // NativeWidgetMac, public: |
| 67 | 91 |
| 68 NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate) | 92 NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate) |
| 69 : delegate_(delegate), | 93 : delegate_(delegate), |
| 70 bridge_(new BridgedNativeWidget(this)), | 94 bridge_(new BridgedNativeWidget(this)), |
| 71 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) { | 95 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) { |
| 72 } | 96 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 | 218 |
| 195 void NativeWidgetMac::ReorderNativeViews() { | 219 void NativeWidgetMac::ReorderNativeViews() { |
| 196 if (bridge_) | 220 if (bridge_) |
| 197 bridge_->SetRootView(GetWidget()->GetRootView()); | 221 bridge_->SetRootView(GetWidget()->GetRootView()); |
| 198 } | 222 } |
| 199 | 223 |
| 200 void NativeWidgetMac::ViewRemoved(View* view) { | 224 void NativeWidgetMac::ViewRemoved(View* view) { |
| 201 // TODO(tapted): Something for drag and drop might be needed here in future. | 225 // TODO(tapted): Something for drag and drop might be needed here in future. |
| 202 // See http://crbug.com/464581. A NOTIMPLEMENTED() here makes a lot of spam, | 226 // See http://crbug.com/464581. A NOTIMPLEMENTED() here makes a lot of spam, |
| 203 // so only emit it when a drag and drop could be likely. | 227 // so only emit it when a drag and drop could be likely. |
| 204 if (IsMouseButtonDown()) | 228 // if (IsMouseButtonDown()) |
|
tapted
2016/03/10 11:51:19
nit: uncomment (sorry for the log spam - drag and
themblsha
2016/03/10 17:18:58
Done.
| |
| 205 NOTIMPLEMENTED(); | 229 // NOTIMPLEMENTED(); |
| 206 } | 230 } |
| 207 | 231 |
| 208 void NativeWidgetMac::SetNativeWindowProperty(const char* name, void* value) { | 232 void NativeWidgetMac::SetNativeWindowProperty(const char* name, void* value) { |
| 209 if (bridge_) | 233 if (bridge_) |
| 210 bridge_->SetNativeWindowProperty(name, value); | 234 bridge_->SetNativeWindowProperty(name, value); |
| 211 } | 235 } |
| 212 | 236 |
| 213 void* NativeWidgetMac::GetNativeWindowProperty(const char* name) const { | 237 void* NativeWidgetMac::GetNativeWindowProperty(const char* name) const { |
| 214 if (bridge_) | 238 if (bridge_) |
| 215 return bridge_->GetNativeWindowProperty(name); | 239 return bridge_->GetNativeWindowProperty(name); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 // Everyhing happens upon show. | 313 // Everyhing happens upon show. |
| 290 } | 314 } |
| 291 | 315 |
| 292 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { | 316 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { |
| 293 return gfx::ScreenRectFromNSRect([GetNativeWindow() frame]); | 317 return gfx::ScreenRectFromNSRect([GetNativeWindow() frame]); |
| 294 } | 318 } |
| 295 | 319 |
| 296 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { | 320 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { |
| 297 NSWindow* window = GetNativeWindow(); | 321 NSWindow* window = GetNativeWindow(); |
| 298 return gfx::ScreenRectFromNSRect( | 322 return gfx::ScreenRectFromNSRect( |
| 299 [window contentRectForFrameRect:[window frame]]); | 323 [window contentRectForFrameRect:FrameIncludingDrag(window)]); |
| 300 } | 324 } |
| 301 | 325 |
| 302 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { | 326 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { |
| 303 return bridge_ ? bridge_->GetRestoredBounds() : gfx::Rect(); | 327 return bridge_ ? bridge_->GetRestoredBounds() : gfx::Rect(); |
| 304 } | 328 } |
| 305 | 329 |
| 306 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { | 330 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { |
| 307 if (bridge_) | 331 if (bridge_) |
| 308 bridge_->SetBounds(bounds); | 332 bridge_->SetBounds(bounds); |
| 309 } | 333 } |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 } | 565 } |
| 542 | 566 |
| 543 gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const { | 567 gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const { |
| 544 return gfx::ScreenRectFromNSRect([[GetNativeWindow() screen] visibleFrame]); | 568 return gfx::ScreenRectFromNSRect([[GetNativeWindow() screen] visibleFrame]); |
| 545 } | 569 } |
| 546 | 570 |
| 547 Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop( | 571 Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop( |
| 548 const gfx::Vector2d& drag_offset, | 572 const gfx::Vector2d& drag_offset, |
| 549 Widget::MoveLoopSource source, | 573 Widget::MoveLoopSource source, |
| 550 Widget::MoveLoopEscapeBehavior escape_behavior) { | 574 Widget::MoveLoopEscapeBehavior escape_behavior) { |
| 551 NOTIMPLEMENTED(); | 575 if (!bridge_) |
| 552 return Widget::MOVE_LOOP_CANCELED; | 576 return Widget::MOVE_LOOP_CANCELED; |
| 577 | |
| 578 return bridge_->RunMoveLoop(drag_offset); | |
| 553 } | 579 } |
| 554 | 580 |
| 555 void NativeWidgetMac::EndMoveLoop() { | 581 void NativeWidgetMac::EndMoveLoop() { |
| 556 NOTIMPLEMENTED(); | 582 if (bridge_) |
| 583 bridge_->EndMoveLoop(); | |
| 557 } | 584 } |
| 558 | 585 |
| 559 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { | 586 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { |
| 560 NOTIMPLEMENTED(); | 587 NOTIMPLEMENTED(); |
| 561 } | 588 } |
| 562 | 589 |
| 563 void NativeWidgetMac::SetVisibilityAnimationDuration( | 590 void NativeWidgetMac::SetVisibilityAnimationDuration( |
| 564 const base::TimeDelta& duration) { | 591 const base::TimeDelta& duration) { |
| 565 NOTIMPLEMENTED(); | 592 NOTIMPLEMENTED(); |
| 566 } | 593 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 733 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; | 760 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; |
| 734 } | 761 } |
| 735 | 762 |
| 736 - (void)animationDidEnd:(NSAnimation*)animation { | 763 - (void)animationDidEnd:(NSAnimation*)animation { |
| 737 [window_ close]; | 764 [window_ close]; |
| 738 [animation_ setDelegate:nil]; | 765 [animation_ setDelegate:nil]; |
| 739 [self release]; | 766 [self release]; |
| 740 } | 767 } |
| 741 | 768 |
| 742 @end | 769 @end |
| OLD | NEW |