| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/ui/panels/panel_window_controller_cocoa.h" | 5 #include "chrome/browser/ui/panels/panel_window_controller_cocoa.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/bundle_locations.h" | 10 #include "base/mac/bundle_locations.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // Replicate specific 10.6 SDK declarations for building with prior SDKs. | 51 // Replicate specific 10.6 SDK declarations for building with prior SDKs. |
| 52 #if !defined(MAC_OS_X_VERSION_10_6) || \ | 52 #if !defined(MAC_OS_X_VERSION_10_6) || \ |
| 53 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 | 53 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 |
| 54 | 54 |
| 55 enum { | 55 enum { |
| 56 NSWindowCollectionBehaviorParticipatesInCycle = 1 << 5 | 56 NSWindowCollectionBehaviorParticipatesInCycle = 1 << 5 |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 #endif // MAC_OS_X_VERSION_10_6 | 59 #endif // MAC_OS_X_VERSION_10_6 |
| 60 | 60 |
| 61 namespace { |
| 62 |
| 63 // Converts a point from the Cocoa screen coordinates (with (0,0) in the |
| 64 // low-left corner of the primary screen) to the platfrom-independent screen |
| 65 // coordinates (with the (0,0) in the top-left corner). |
| 66 gfx::Point ConvertPointFromCocoaCoordinates(NSPoint point) { |
| 67 // Flip coordinates based on the primary screen. |
| 68 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 69 |
| 70 return gfx::Point(point.x, NSHeight([screen frame]) - point.y); |
| 71 } |
| 72 |
| 73 } // namespace |
| 74 |
| 61 @implementation PanelWindowCocoaImpl | 75 @implementation PanelWindowCocoaImpl |
| 62 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen { | 76 - (NSRect)constrainFrameRect:(NSRect)frameRect toScreen:(NSScreen *)screen { |
| 63 return frameRect; | 77 return frameRect; |
| 64 } | 78 } |
| 65 | 79 |
| 66 - (BOOL)canBecomeKeyWindow { | 80 - (BOOL)canBecomeKeyWindow { |
| 67 PanelWindowControllerCocoa* controller = | 81 PanelWindowControllerCocoa* controller = |
| 68 static_cast<PanelWindowControllerCocoa*>([self delegate]); | 82 static_cast<PanelWindowControllerCocoa*>([self delegate]); |
| 69 return [controller canBecomeKeyWindow]; | 83 return [controller canBecomeKeyWindow]; |
| 70 } | 84 } |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 409 |
| 396 [NSMenu popUpContextMenu:[settingsMenuController menu] | 410 [NSMenu popUpContextMenu:[settingsMenuController menu] |
| 397 withEvent:[NSApp currentEvent] | 411 withEvent:[NSApp currentEvent] |
| 398 forView:button]; | 412 forView:button]; |
| 399 } | 413 } |
| 400 | 414 |
| 401 - (BOOL)isDraggable { | 415 - (BOOL)isDraggable { |
| 402 return windowShim_->panel()->draggable(); | 416 return windowShim_->panel()->draggable(); |
| 403 } | 417 } |
| 404 | 418 |
| 405 - (void)startDrag { | 419 - (void)startDrag:(NSPoint)mouseLocation { |
| 406 animateOnBoundsChange_ = NO; | 420 animateOnBoundsChange_ = NO; |
| 407 windowShim_->panel()->manager()->StartDragging(windowShim_->panel()); | 421 windowShim_->panel()->manager()->StartDragging( |
| 422 windowShim_->panel(), ConvertPointFromCocoaCoordinates(mouseLocation)); |
| 408 } | 423 } |
| 409 | 424 |
| 410 - (void)endDrag:(BOOL)cancelled { | 425 - (void)endDrag:(BOOL)cancelled { |
| 411 animateOnBoundsChange_ = YES; | 426 animateOnBoundsChange_ = YES; |
| 412 windowShim_->panel()->manager()->EndDragging(cancelled); | 427 windowShim_->panel()->manager()->EndDragging(cancelled); |
| 413 } | 428 } |
| 414 | 429 |
| 415 - (void)dragWithDeltaX:(int)deltaX | 430 - (void)drag:(NSPoint)mouseLocation { |
| 416 deltaY:(int)deltaY { | 431 windowShim_->panel()->manager()->Drag( |
| 417 windowShim_->panel()->manager()->Drag(deltaX, deltaY); | 432 ConvertPointFromCocoaCoordinates(mouseLocation)); |
| 418 } | 433 } |
| 419 | 434 |
| 420 - (void)setPanelFrame:(NSRect)frame | 435 - (void)setPanelFrame:(NSRect)frame |
| 421 animate:(BOOL)animate { | 436 animate:(BOOL)animate { |
| 422 // Setup the whole window as the tracking area so that we can get notified | 437 // Setup the whole window as the tracking area so that we can get notified |
| 423 // when the mouse enters or leaves the window. This will make us be able to | 438 // when the mouse enters or leaves the window. This will make us be able to |
| 424 // show or hide settings button accordingly. | 439 // show or hide settings button accordingly. |
| 425 NSRect localBounds = frame; | 440 NSRect localBounds = frame; |
| 426 localBounds.origin = NSZeroPoint; | 441 localBounds.origin = NSZeroPoint; |
| 427 windowTrackingArea_.reset( | 442 windowTrackingArea_.reset( |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 } | 632 } |
| 618 | 633 |
| 619 - (BOOL)canBecomeKeyWindow { | 634 - (BOOL)canBecomeKeyWindow { |
| 620 // Panel can only gain focus if it is expanded. Minimized panels do not | 635 // Panel can only gain focus if it is expanded. Minimized panels do not |
| 621 // participate in Cmd-~ rotation. | 636 // participate in Cmd-~ rotation. |
| 622 // TODO(dimich): If it will be ever desired to expand/focus the Panel on | 637 // TODO(dimich): If it will be ever desired to expand/focus the Panel on |
| 623 // keyboard navigation or via main menu, the care should be taken to avoid | 638 // keyboard navigation or via main menu, the care should be taken to avoid |
| 624 // cases when minimized Panel is getting keyboard input, invisibly. | 639 // cases when minimized Panel is getting keyboard input, invisibly. |
| 625 return windowShim_->panel()->expansion_state() == Panel::EXPANDED; | 640 return windowShim_->panel()->expansion_state() == Panel::EXPANDED; |
| 626 } | 641 } |
| 642 |
| 643 - (void)setAlwaysOnTop:(bool)onTop { |
| 644 NSWindow* window = [self window]; |
| 645 [window setLevel:(onTop ? NSStatusWindowLevel : NSNormalWindowLevel)]; |
| 646 } |
| 627 @end | 647 @end |
| OLD | NEW |