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 // | |
76 // Note: Moving the window using the window server is asynchronous, and it can | |
77 // continue sending the frame updates (using NSWindowMovedEventType event) even | |
78 // after the mouse button is released. | |
79 NSRect FrameIncludingDrag(NSWindow* window) { | |
80 CGRect bounds = NSZeroRect; | |
81 CGSGetWindowBounds(_CGSDefaultConnection(), [window windowNumber], &bounds); | |
82 const NSRect rect = ScreenRectToNSRect(gfx::Rect(bounds)); | |
tapted
2016/03/11 09:38:28
perhaps
NSRect rect = ScreenRectToNSRect(gfx::Re
themblsha
2016/04/05 17:20:42
Done. Although the code now lives inside NativeWid
| |
83 const NSSize size = [window frame].size; | |
84 return NSMakeRect(rect.origin.x, rect.origin.y, size.width, size.height); | |
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 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 DCHECK(bridge_->parent()); | 312 DCHECK(bridge_->parent()); |
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 NSRect frame_rect = [window frame]; |
299 [window contentRectForFrameRect:[window frame]]); | 323 if (bridge_->IsRunMoveLoopActive()) |
324 frame_rect = FrameIncludingDrag(window); | |
325 return gfx::ScreenRectFromNSRect([window contentRectForFrameRect:frame_rect]); | |
300 } | 326 } |
301 | 327 |
302 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { | 328 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { |
303 return bridge_ ? bridge_->GetRestoredBounds() : gfx::Rect(); | 329 return bridge_ ? bridge_->GetRestoredBounds() : gfx::Rect(); |
304 } | 330 } |
305 | 331 |
306 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { | 332 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { |
307 if (bridge_) | 333 if (bridge_) |
308 bridge_->SetBounds(bounds); | 334 bridge_->SetBounds(bounds); |
309 } | 335 } |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
541 } | 567 } |
542 | 568 |
543 gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const { | 569 gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const { |
544 return gfx::ScreenRectFromNSRect([[GetNativeWindow() screen] visibleFrame]); | 570 return gfx::ScreenRectFromNSRect([[GetNativeWindow() screen] visibleFrame]); |
545 } | 571 } |
546 | 572 |
547 Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop( | 573 Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop( |
548 const gfx::Vector2d& drag_offset, | 574 const gfx::Vector2d& drag_offset, |
549 Widget::MoveLoopSource source, | 575 Widget::MoveLoopSource source, |
550 Widget::MoveLoopEscapeBehavior escape_behavior) { | 576 Widget::MoveLoopEscapeBehavior escape_behavior) { |
551 NOTIMPLEMENTED(); | 577 if (!bridge_) |
552 return Widget::MOVE_LOOP_CANCELED; | 578 return Widget::MOVE_LOOP_CANCELED; |
579 | |
580 return bridge_->RunMoveLoop(drag_offset); | |
553 } | 581 } |
554 | 582 |
555 void NativeWidgetMac::EndMoveLoop() { | 583 void NativeWidgetMac::EndMoveLoop() { |
556 NOTIMPLEMENTED(); | 584 if (bridge_) |
585 bridge_->EndMoveLoop(); | |
557 } | 586 } |
558 | 587 |
559 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { | 588 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { |
560 NOTIMPLEMENTED(); | 589 NOTIMPLEMENTED(); |
561 } | 590 } |
562 | 591 |
563 void NativeWidgetMac::SetVisibilityAnimationDuration( | 592 void NativeWidgetMac::SetVisibilityAnimationDuration( |
564 const base::TimeDelta& duration) { | 593 const base::TimeDelta& duration) { |
565 NOTIMPLEMENTED(); | 594 NOTIMPLEMENTED(); |
566 } | 595 } |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; | 762 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; |
734 } | 763 } |
735 | 764 |
736 - (void)animationDidEnd:(NSAnimation*)animation { | 765 - (void)animationDidEnd:(NSAnimation*)animation { |
737 [window_ close]; | 766 [window_ close]; |
738 [animation_ setDelegate:nil]; | 767 [animation_ setDelegate:nil]; |
739 [self release]; | 768 [self release]; |
740 } | 769 } |
741 | 770 |
742 @end | 771 @end |
OLD | NEW |