Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(306)

Side by Side Diff: ui/views/widget/native_widget_mac.mm

Issue 1747803003: MacViews: Implement Tab Dragging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests and review issues. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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;
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 if (modal_type == ui::MODAL_TYPE_NONE) 295 if (modal_type == ui::MODAL_TYPE_NONE)
286 return; 296 return;
287 297
288 // System modal windows not implemented (or used) on Mac. 298 // System modal windows not implemented (or used) on Mac.
289 DCHECK_NE(ui::MODAL_TYPE_SYSTEM, modal_type); 299 DCHECK_NE(ui::MODAL_TYPE_SYSTEM, modal_type);
290 DCHECK(bridge_->parent()); 300 DCHECK(bridge_->parent());
291 // Everyhing happens upon show. 301 // Everyhing happens upon show.
292 } 302 }
293 303
294 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { 304 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const {
295 return gfx::ScreenRectFromNSRect([GetNativeWindow() frame]); 305 // -[NSWindow frame] doesn't update during a window drag. This is not what
306 // toolkit-views expects, so ask the window server directly.
307 //
308 // Note: Moving the window using the window server is asynchronous, and it can
309 // continue sending the frame updates (using NSWindowMovedEventType event)
310 // even after the mouse button is released.
311 NSRect frame_rect = [GetNativeWindow() frame];
312 if (bridge_->IsRunMoveLoopActive())
313 frame_rect = gfx::ScreenRectToNSRect(WindowServerFrame());
314 return gfx::ScreenRectFromNSRect(frame_rect);
315 }
316
317 gfx::Rect NativeWidgetMac::WindowServerFrame() const {
318 CGRect bounds = NSZeroRect;
319 CGSGetWindowBounds(_CGSDefaultConnection(), [GetNativeWindow() windowNumber],
320 &bounds);
321 NSRect rect = ScreenRectToNSRect(gfx::Rect(bounds));
322 rect.size = [GetNativeWindow() frame].size;
323 return gfx::ScreenRectFromNSRect(rect);
296 } 324 }
297 325
298 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { 326 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const {
299 NSWindow* window = GetNativeWindow(); 327 NSWindow* window = GetNativeWindow();
300 return gfx::ScreenRectFromNSRect( 328 NSRect frame_rect = [window frame];
301 [window contentRectForFrameRect:[window frame]]); 329 // -[NSWindow frame] doesn't update during a window drag. This is not what
330 // toolkit-views expects, so ask the window server directly.
331 //
332 // Note: Moving the window using the window server is asynchronous, and it can
333 // continue sending the frame updates (using NSWindowMovedEventType event)
334 // even after the mouse button is released.
335 if (bridge_->IsRunMoveLoopActive())
336 frame_rect = gfx::ScreenRectToNSRect(WindowServerFrame());
337 return gfx::ScreenRectFromNSRect([window contentRectForFrameRect:frame_rect]);
302 } 338 }
303 339
304 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { 340 gfx::Rect NativeWidgetMac::GetRestoredBounds() const {
305 return bridge_ ? bridge_->GetRestoredBounds() : gfx::Rect(); 341 return bridge_ ? bridge_->GetRestoredBounds() : gfx::Rect();
306 } 342 }
307 343
308 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { 344 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) {
309 if (bridge_) 345 if (bridge_)
310 bridge_->SetBounds(bounds); 346 bridge_->SetBounds(bounds);
311 } 347 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 } 575 }
540 576
541 gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const { 577 gfx::Rect NativeWidgetMac::GetWorkAreaBoundsInScreen() const {
542 return gfx::ScreenRectFromNSRect([[GetNativeWindow() screen] visibleFrame]); 578 return gfx::ScreenRectFromNSRect([[GetNativeWindow() screen] visibleFrame]);
543 } 579 }
544 580
545 Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop( 581 Widget::MoveLoopResult NativeWidgetMac::RunMoveLoop(
546 const gfx::Vector2d& drag_offset, 582 const gfx::Vector2d& drag_offset,
547 Widget::MoveLoopSource source, 583 Widget::MoveLoopSource source,
548 Widget::MoveLoopEscapeBehavior escape_behavior) { 584 Widget::MoveLoopEscapeBehavior escape_behavior) {
549 NOTIMPLEMENTED(); 585 if (!bridge_)
550 return Widget::MOVE_LOOP_CANCELED; 586 return Widget::MOVE_LOOP_CANCELED;
587
588 return bridge_->RunMoveLoop(drag_offset);
551 } 589 }
552 590
553 void NativeWidgetMac::EndMoveLoop() { 591 void NativeWidgetMac::EndMoveLoop() {
554 NOTIMPLEMENTED(); 592 if (bridge_)
593 bridge_->EndMoveLoop();
555 } 594 }
556 595
557 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) { 596 void NativeWidgetMac::SetVisibilityChangedAnimationsEnabled(bool value) {
558 NOTIMPLEMENTED(); 597 NOTIMPLEMENTED();
559 } 598 }
560 599
561 void NativeWidgetMac::SetVisibilityAnimationDuration( 600 void NativeWidgetMac::SetVisibilityAnimationDuration(
562 const base::TimeDelta& duration) { 601 const base::TimeDelta& duration) {
563 NOTIMPLEMENTED(); 602 NOTIMPLEMENTED();
564 } 603 }
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window]; 770 [[ViewsNSWindowCloseAnimator alloc] initWithWindow:window];
732 } 771 }
733 772
734 - (void)animationDidEnd:(NSAnimation*)animation { 773 - (void)animationDidEnd:(NSAnimation*)animation {
735 [window_ close]; 774 [window_ close];
736 [animation_ setDelegate:nil]; 775 [animation_ setDelegate:nil];
737 [self release]; 776 [self release];
738 } 777 }
739 778
740 @end 779 @end
OLDNEW
« ui/views/widget/native_widget_mac.h ('K') | « ui/views/widget/native_widget_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698