| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 if (modal_type == ui::MODAL_TYPE_NONE) | 285 if (modal_type == ui::MODAL_TYPE_NONE) |
| 286 return; | 286 return; |
| 287 | 287 |
| 288 // System modal windows not implemented (or used) on Mac. | 288 // System modal windows not implemented (or used) on Mac. |
| 289 DCHECK_NE(ui::MODAL_TYPE_SYSTEM, modal_type); | 289 DCHECK_NE(ui::MODAL_TYPE_SYSTEM, modal_type); |
| 290 DCHECK(bridge_->parent()); | 290 DCHECK(bridge_->parent()); |
| 291 // Everyhing happens upon show. | 291 // Everyhing happens upon show. |
| 292 } | 292 } |
| 293 | 293 |
| 294 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { | 294 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { |
| 295 return gfx::ScreenRectFromNSRect([GetNativeWindow() frame]); | 295 // -[NSWindow frame] doesn't update during a window drag. This is not what |
| 296 // toolkit-views expects, so ask the window server directly. |
| 297 // |
| 298 // Note: Moving the window using the window server is asynchronous, and it can |
| 299 // continue sending the frame updates (using NSWindowMovedEventType event) |
| 300 // even after the mouse button is released. |
| 301 NSRect frame_rect = [GetNativeWindow() frame]; |
| 302 if (bridge_->IsRunMoveLoopActive()) |
| 303 frame_rect = bridge_->WindowServerFrame(); |
| 304 return gfx::ScreenRectFromNSRect(frame_rect); |
| 296 } | 305 } |
| 297 | 306 |
| 298 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { | 307 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { |
| 299 NSWindow* window = GetNativeWindow(); | 308 NSWindow* window = GetNativeWindow(); |
| 300 return gfx::ScreenRectFromNSRect( | 309 NSRect frame_rect = [window frame]; |
| 301 [window contentRectForFrameRect:[window frame]]); | 310 // -[NSWindow frame] doesn't update during a window drag. This is not what |
| 311 // toolkit-views expects, so ask the window server directly. |
| 312 // |
| 313 // Note: Moving the window using the window server is asynchronous, and it can |
| 314 // continue sending the frame updates (using NSWindowMovedEventType event) |
| 315 // even after the mouse button is released. |
| 316 if (bridge_->IsRunMoveLoopActive()) |
| 317 frame_rect = bridge_->WindowServerFrame(); |
| 318 return gfx::ScreenRectFromNSRect([window contentRectForFrameRect:frame_rect]); |
| 302 } | 319 } |
| 303 | 320 |
| 304 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { | 321 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { |
| 305 return bridge_ ? bridge_->GetRestoredBounds() : gfx::Rect(); | 322 return bridge_ ? bridge_->GetRestoredBounds() : gfx::Rect(); |
| 306 } | 323 } |
| 307 | 324 |
| 308 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { | 325 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { |
| 309 if (bridge_) | 326 if (bridge_) |
| 310 bridge_->SetBounds(bounds); | 327 bridge_->SetBounds(bounds); |
| 311 } | 328 } |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 } | 556 } |
| 540 | 557 |
| 541 gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const { | 558 gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const { |
| 542 return gfx::ScreenRectFromNSRect([[GetNativeWindow() screen] visibleFrame]); | 559 return gfx::ScreenRectFromNSRect([[GetNativeWindow() screen] visibleFrame]); |
| 543 } | 560 } |
| 544 | 561 |
| 545 Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop( | 562 Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop( |
| 546 const gfx::Vector2d& drag_offset, | 563 const gfx::Vector2d& drag_offset, |
| 547 Widget::MoveLoopSource source, | 564 Widget::MoveLoopSource source, |
| 548 Widget::MoveLoopEscapeBehavior escape_behavior) { | 565 Widget::MoveLoopEscapeBehavior escape_behavior) { |
| 549 NOTIMPLEMENTED(); | 566 if (!bridge_) |
| 550 return Widget::MOVE_LOOP_CANCELED; | 567 return Widget::MOVE_LOOP_CANCELED; |
| 568 |
| 569 return bridge_->RunMoveLoop(drag_offset); |
| 551 } | 570 } |
| 552 | 571 |
| 553 void NativeWidgetMac::EndMoveLoop() { | 572 void NativeWidgetMac::EndMoveLoop() { |
| 554 NOTIMPLEMENTED(); | 573 if (bridge_) |
| 574 bridge_->EndMoveLoop(); |
| 555 } | 575 } |
| 556 | 576 |
| 557 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { | 577 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { |
| 558 NOTIMPLEMENTED(); | 578 NOTIMPLEMENTED(); |
| 559 } | 579 } |
| 560 | 580 |
| 561 void NativeWidgetMac::SetVisibilityAnimationDuration( | 581 void NativeWidgetMac::SetVisibilityAnimationDuration( |
| 562 const base::TimeDelta& duration) { | 582 const base::TimeDelta& duration) { |
| 563 NOTIMPLEMENTED(); | 583 NOTIMPLEMENTED(); |
| 564 } | 584 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; | 751 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; |
| 732 } | 752 } |
| 733 | 753 |
| 734 - (void)animationDidEnd:(NSAnimation*)animation { | 754 - (void)animationDidEnd:(NSAnimation*)animation { |
| 735 [window_ close]; | 755 [window_ close]; |
| 736 [animation_ setDelegate:nil]; | 756 [animation_ setDelegate:nil]; |
| 737 [self release]; | 757 [self release]; |
| 738 } | 758 } |
| 739 | 759 |
| 740 @end | 760 @end |
| OLD | NEW |