| 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 @interface ViewsNSWindowCloseAnimator : NSObject<NSAnimationDelegate> { | 27 @interface ViewsNSWindowCloseAnimator : NSObject<NSAnimationDelegate> { |
| 28 @private | 28 @private |
| 29 base::scoped_nsobject<NSWindow> window_; | 29 base::scoped_nsobject<NSWindow> window_; |
| 30 base::scoped_nsobject<NSAnimation> animation_; | 30 base::scoped_nsobject<NSAnimation> animation_; |
| 31 } | 31 } |
| 32 | 32 |
| 33 + (void)closeWindowWithAnimation:(NSWindow*)window; | 33 + (void)closeWindowWithAnimation:(NSWindow*)window; |
| 34 | 34 |
| 35 @end | 35 @end |
| 36 | 36 |
| 37 extern "C" { |
| 38 |
| 39 typedef int32 CGSWindow; |
| 40 typedef int32 CGSConnection; |
| 41 CGSConnection _CGSDefaultConnection(); |
| 42 OSStatus CGSGetWindowBounds( |
| 43 CGSConnection connection, CGSWindow window, CGRect* bounds); |
| 44 |
| 45 } |
| 46 |
| 37 namespace views { | 47 namespace views { |
| 38 namespace { | 48 namespace { |
| 39 | 49 |
| 40 NSInteger StyleMaskForParams(const Widget::InitParams& params) { | 50 NSInteger StyleMaskForParams(const Widget::InitParams& params) { |
| 41 // TODO(tapted): Determine better masks when there are use cases for it. | 51 // TODO(tapted): Determine better masks when there are use cases for it. |
| 42 if (params.remove_standard_frame) | 52 if (params.remove_standard_frame) |
| 43 return NSBorderlessWindowMask; | 53 return NSBorderlessWindowMask; |
| 44 | 54 |
| 45 if (params.type == Widget::InitParams::TYPE_WINDOW) { | 55 if (params.type == Widget::InitParams::TYPE_WINDOW) { |
| 46 return NSTitledWindowMask | NSClosableWindowMask | | 56 return NSTitledWindowMask | NSClosableWindowMask | |
| 47 NSMiniaturizableWindowMask | NSResizableWindowMask | | 57 NSMiniaturizableWindowMask | NSResizableWindowMask | |
| 48 NSTexturedBackgroundWindowMask; | 58 NSTexturedBackgroundWindowMask; |
| 49 } | 59 } |
| 50 return NSBorderlessWindowMask; | 60 return NSBorderlessWindowMask; |
| 51 } | 61 } |
| 52 | 62 |
| 63 // -[NSWindow frame] doesn't update during a window drag. This is not what |
| 64 // toolkit-views expects, so ask the window server directly. |
| 65 NSRect FrameIncludingDrag(NSWindow* window) { |
| 66 CGRect bounds = NSZeroRect; |
| 67 CGSGetWindowBounds(_CGSDefaultConnection(), [window windowNumber], &bounds); |
| 68 NSRect rect = ScreenRectToNSRect(gfx::Rect(bounds)); |
| 69 |
| 70 // If no mouse buttons are down, there is no drag. So it should match the |
| 71 // window frame. |
| 72 //DCHECK([NSEvent pressedMouseButtons] == 0 || |
| 73 // NSEqualRects(rect, [window frame])); |
| 74 return rect; |
| 75 } |
| 76 |
| 53 } // namespace | 77 } // namespace |
| 54 | 78 |
| 55 //////////////////////////////////////////////////////////////////////////////// | 79 //////////////////////////////////////////////////////////////////////////////// |
| 56 // NativeWidgetMac, public: | 80 // NativeWidgetMac, public: |
| 57 | 81 |
| 58 NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate) | 82 NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate) |
| 59 : delegate_(delegate), | 83 : delegate_(delegate), |
| 60 bridge_(new BridgedNativeWidget(this)), | 84 bridge_(new BridgedNativeWidget(this)), |
| 61 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) { | 85 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) { |
| 62 } | 86 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 const ui::Layer* NativeWidgetMac::GetLayer() const { | 197 const ui::Layer* NativeWidgetMac::GetLayer() const { |
| 174 return bridge_ ? bridge_->layer() : nullptr; | 198 return bridge_ ? bridge_->layer() : nullptr; |
| 175 } | 199 } |
| 176 | 200 |
| 177 void NativeWidgetMac::ReorderNativeViews() { | 201 void NativeWidgetMac::ReorderNativeViews() { |
| 178 if (bridge_) | 202 if (bridge_) |
| 179 bridge_->SetRootView(GetWidget()->GetRootView()); | 203 bridge_->SetRootView(GetWidget()->GetRootView()); |
| 180 } | 204 } |
| 181 | 205 |
| 182 void NativeWidgetMac::ViewRemoved(View* view) { | 206 void NativeWidgetMac::ViewRemoved(View* view) { |
| 183 NOTIMPLEMENTED(); | 207 //NOTIMPLEMENTED(); |
| 184 } | 208 } |
| 185 | 209 |
| 186 void NativeWidgetMac::SetNativeWindowProperty(const char* name, void* value) { | 210 void NativeWidgetMac::SetNativeWindowProperty(const char* name, void* value) { |
| 187 if (bridge_) | 211 if (bridge_) |
| 188 bridge_->SetNativeWindowProperty(name, value); | 212 bridge_->SetNativeWindowProperty(name, value); |
| 189 } | 213 } |
| 190 | 214 |
| 191 void* NativeWidgetMac::GetNativeWindowProperty(const char* name) const { | 215 void* NativeWidgetMac::GetNativeWindowProperty(const char* name) const { |
| 192 if (bridge_) | 216 if (bridge_) |
| 193 return bridge_->GetNativeWindowProperty(name); | 217 return bridge_->GetNativeWindowProperty(name); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // Everyhing happens upon show. | 291 // Everyhing happens upon show. |
| 268 } | 292 } |
| 269 | 293 |
| 270 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { | 294 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { |
| 271 return gfx::ScreenRectFromNSRect([GetNativeWindow() frame]); | 295 return gfx::ScreenRectFromNSRect([GetNativeWindow() frame]); |
| 272 } | 296 } |
| 273 | 297 |
| 274 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { | 298 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { |
| 275 NSWindow* window = GetNativeWindow(); | 299 NSWindow* window = GetNativeWindow(); |
| 276 return gfx::ScreenRectFromNSRect( | 300 return gfx::ScreenRectFromNSRect( |
| 277 [window contentRectForFrameRect:[window frame]]); | 301 [window contentRectForFrameRect:FrameIncludingDrag(window)]); |
| 278 } | 302 } |
| 279 | 303 |
| 280 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { | 304 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { |
| 281 return bridge_ ? bridge_->GetRestoredBounds() : gfx::Rect(); | 305 return bridge_ ? bridge_->GetRestoredBounds() : gfx::Rect(); |
| 282 } | 306 } |
| 283 | 307 |
| 284 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { | 308 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { |
| 285 if (bridge_) | 309 if (bridge_) |
| 286 bridge_->SetBounds(bounds); | 310 bridge_->SetBounds(bounds); |
| 287 } | 311 } |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 | 533 |
| 510 gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const { | 534 gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const { |
| 511 NOTIMPLEMENTED(); | 535 NOTIMPLEMENTED(); |
| 512 return gfx::Rect(); | 536 return gfx::Rect(); |
| 513 } | 537 } |
| 514 | 538 |
| 515 Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop( | 539 Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop( |
| 516 const gfx::Vector2d& drag_offset, | 540 const gfx::Vector2d& drag_offset, |
| 517 Widget::MoveLoopSource source, | 541 Widget::MoveLoopSource source, |
| 518 Widget::MoveLoopEscapeBehavior escape_behavior) { | 542 Widget::MoveLoopEscapeBehavior escape_behavior) { |
| 519 NOTIMPLEMENTED(); | 543 if (!bridge_) |
| 520 return Widget::MOVE_LOOP_CANCELED; | 544 return Widget::MOVE_LOOP_CANCELED; |
| 545 |
| 546 DLOG(INFO) << "RunMoveLoop: " << source << " , " << escape_behavior |
| 547 << " offset=" << drag_offset.ToString(); |
| 548 |
| 549 return bridge_->RunMoveLoop(drag_offset); |
| 521 } | 550 } |
| 522 | 551 |
| 523 void NativeWidgetMac::EndMoveLoop() { | 552 void NativeWidgetMac::EndMoveLoop() { |
| 524 NOTIMPLEMENTED(); | 553 if (bridge_) |
| 554 bridge_->EndMoveLoop(); |
| 525 } | 555 } |
| 526 | 556 |
| 527 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { | 557 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { |
| 528 NOTIMPLEMENTED(); | 558 NOTIMPLEMENTED(); |
| 529 } | 559 } |
| 530 | 560 |
| 531 void NativeWidgetMac::SetVisibilityAnimationDuration( | 561 void NativeWidgetMac::SetVisibilityAnimationDuration( |
| 532 const base::TimeDelta& duration) { | 562 const base::TimeDelta& duration) { |
| 533 NOTIMPLEMENTED(); | 563 NOTIMPLEMENTED(); |
| 534 } | 564 } |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; | 724 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; |
| 695 } | 725 } |
| 696 | 726 |
| 697 - (void)animationDidEnd:(NSAnimation*)animation { | 727 - (void)animationDidEnd:(NSAnimation*)animation { |
| 698 [window_ close]; | 728 [window_ close]; |
| 699 [animation_ setDelegate:nil]; | 729 [animation_ setDelegate:nil]; |
| 700 [self release]; | 730 [self release]; |
| 701 } | 731 } |
| 702 | 732 |
| 703 @end | 733 @end |
| OLD | NEW |