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 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 if (modal_type == ui::MODAL_TYPE_NONE) | 286 if (modal_type == ui::MODAL_TYPE_NONE) |
287 return; | 287 return; |
288 | 288 |
289 // System modal windows not implemented (or used) on Mac. | 289 // System modal windows not implemented (or used) on Mac. |
290 DCHECK_NE(ui::MODAL_TYPE_SYSTEM, modal_type); | 290 DCHECK_NE(ui::MODAL_TYPE_SYSTEM, modal_type); |
291 DCHECK(bridge_->parent()); | 291 DCHECK(bridge_->parent()); |
292 // Everyhing happens upon show. | 292 // Everyhing happens upon show. |
293 } | 293 } |
294 | 294 |
295 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { | 295 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { |
296 return gfx::ScreenRectFromNSRect([GetNativeWindow() frame]); | 296 // -[NSWindow frame] doesn't update during a window drag. This is not what |
| 297 // toolkit-views expects, so ask the window server directly. |
| 298 // |
| 299 // Note: Moving the window using the window server is asynchronous, and it can |
| 300 // continue sending the frame updates (using NSWindowMovedEventType event) |
| 301 // even after the mouse button is released. |
| 302 NSRect frame_rect = [GetNativeWindow() frame]; |
| 303 if (bridge_->IsRunMoveLoopActive()) |
| 304 frame_rect = bridge_->WindowServerFrame(); |
| 305 return gfx::ScreenRectFromNSRect(frame_rect); |
297 } | 306 } |
298 | 307 |
299 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { | 308 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { |
300 NSWindow* window = GetNativeWindow(); | 309 NSWindow* window = GetNativeWindow(); |
301 return gfx::ScreenRectFromNSRect( | 310 NSRect frame_rect = [window frame]; |
302 [window contentRectForFrameRect:[window frame]]); | 311 // -[NSWindow frame] doesn't update during a window drag. This is not what |
| 312 // toolkit-views expects, so ask the window server directly. |
| 313 // |
| 314 // Note: Moving the window using the window server is asynchronous, and it can |
| 315 // continue sending the frame updates (using NSWindowMovedEventType event) |
| 316 // even after the mouse button is released. |
| 317 if (bridge_->IsRunMoveLoopActive()) |
| 318 frame_rect = bridge_->WindowServerFrame(); |
| 319 return gfx::ScreenRectFromNSRect([window contentRectForFrameRect:frame_rect]); |
303 } | 320 } |
304 | 321 |
305 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { | 322 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { |
306 return bridge_ ? bridge_->GetRestoredBounds() : gfx::Rect(); | 323 return bridge_ ? bridge_->GetRestoredBounds() : gfx::Rect(); |
307 } | 324 } |
308 | 325 |
309 std::string NativeWidgetMac::GetWorkspace() const { | 326 std::string NativeWidgetMac::GetWorkspace() const { |
310 return std::string(); | 327 return std::string(); |
311 } | 328 } |
312 | 329 |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 } | 561 } |
545 | 562 |
546 gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const { | 563 gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const { |
547 return gfx::ScreenRectFromNSRect([[GetNativeWindow() screen] visibleFrame]); | 564 return gfx::ScreenRectFromNSRect([[GetNativeWindow() screen] visibleFrame]); |
548 } | 565 } |
549 | 566 |
550 Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop( | 567 Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop( |
551 const gfx::Vector2d& drag_offset, | 568 const gfx::Vector2d& drag_offset, |
552 Widget::MoveLoopSource source, | 569 Widget::MoveLoopSource source, |
553 Widget::MoveLoopEscapeBehavior escape_behavior) { | 570 Widget::MoveLoopEscapeBehavior escape_behavior) { |
554 NOTIMPLEMENTED(); | 571 if (!bridge_) |
555 return Widget::MOVE_LOOP_CANCELED; | 572 return Widget::MOVE_LOOP_CANCELED; |
| 573 |
| 574 return bridge_->RunMoveLoop(drag_offset); |
556 } | 575 } |
557 | 576 |
558 void NativeWidgetMac::EndMoveLoop() { | 577 void NativeWidgetMac::EndMoveLoop() { |
559 NOTIMPLEMENTED(); | 578 if (bridge_) |
| 579 bridge_->EndMoveLoop(); |
560 } | 580 } |
561 | 581 |
562 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { | 582 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { |
563 NOTIMPLEMENTED(); | 583 NOTIMPLEMENTED(); |
564 } | 584 } |
565 | 585 |
566 void NativeWidgetMac::SetVisibilityAnimationDuration( | 586 void NativeWidgetMac::SetVisibilityAnimationDuration( |
567 const base::TimeDelta& duration) { | 587 const base::TimeDelta& duration) { |
568 NOTIMPLEMENTED(); | 588 NOTIMPLEMENTED(); |
569 } | 589 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; | 760 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; |
741 } | 761 } |
742 | 762 |
743 - (void)animationDidEnd:(NSAnimation*)animation { | 763 - (void)animationDidEnd:(NSAnimation*)animation { |
744 [window_ close]; | 764 [window_ close]; |
745 [animation_ setDelegate:nil]; | 765 [animation_ setDelegate:nil]; |
746 [self release]; | 766 [self release]; |
747 } | 767 } |
748 | 768 |
749 @end | 769 @end |
OLD | NEW |