| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/cocoa/base_view.h" | 5 #include "chrome/browser/cocoa/base_view.h" |
| 6 | 6 |
| 7 @implementation BaseView | 7 @implementation BaseView |
| 8 | 8 |
| 9 - (id)initWithFrame:(NSRect)frame { | 9 - (id)initWithFrame:(NSRect)frame { |
| 10 self = [super initWithFrame:frame]; | 10 self = [super initWithFrame:frame]; |
| 11 if (self) { | 11 if (self) { |
| 12 trackingArea_ = | 12 trackingArea_ = |
| 13 [[NSTrackingArea alloc] initWithRect:frame | 13 [[NSTrackingArea alloc] initWithRect:frame |
| 14 options:NSTrackingMouseMoved | | 14 options:NSTrackingMouseMoved | |
| 15 NSTrackingMouseEnteredAndExited | |
| 15 NSTrackingActiveInActiveApp | | 16 NSTrackingActiveInActiveApp | |
| 16 NSTrackingInVisibleRect | 17 NSTrackingInVisibleRect |
| 17 owner:self | 18 owner:self |
| 18 userInfo:nil]; | 19 userInfo:nil]; |
| 19 [self addTrackingArea:trackingArea_]; | 20 [self addTrackingArea:trackingArea_]; |
| 20 } | 21 } |
| 21 return self; | 22 return self; |
| 22 } | 23 } |
| 23 | 24 |
| 24 - (void)dealloc { | 25 - (void)dealloc { |
| 25 [self removeTrackingArea:trackingArea_]; | 26 [self removeTrackingArea:trackingArea_]; |
| 26 [trackingArea_ release]; | 27 [trackingArea_ release]; |
| 27 | 28 |
| 28 [super dealloc]; | 29 [super dealloc]; |
| 29 } | 30 } |
| 30 | 31 |
| 31 - (void)mouseEvent:(NSEvent *)theEvent { | 32 - (void)mouseEvent:(NSEvent *)theEvent { |
| 32 // This method left intentionally blank. | 33 // This method left intentionally blank. |
| 33 } | 34 } |
| 34 | 35 |
| 35 - (void)keyEvent:(NSEvent *)theEvent { | 36 - (void)keyEvent:(NSEvent *)theEvent { |
| 36 // This method left intentionally blank. | 37 // This method left intentionally blank. |
| 37 } | 38 } |
| 38 | 39 |
| 39 - (void)mouseDown:(NSEvent *)theEvent { | 40 - (void)mouseDown:(NSEvent *)theEvent { |
| 41 dragging_ = YES; |
| 40 [self mouseEvent:theEvent]; | 42 [self mouseEvent:theEvent]; |
| 41 } | 43 } |
| 42 | 44 |
| 43 - (void)rightMouseDown:(NSEvent *)theEvent { | 45 - (void)rightMouseDown:(NSEvent *)theEvent { |
| 44 [self mouseEvent:theEvent]; | 46 [self mouseEvent:theEvent]; |
| 45 } | 47 } |
| 46 | 48 |
| 47 - (void)otherMouseDown:(NSEvent *)theEvent { | 49 - (void)otherMouseDown:(NSEvent *)theEvent { |
| 48 [self mouseEvent:theEvent]; | 50 [self mouseEvent:theEvent]; |
| 49 } | 51 } |
| 50 | 52 |
| 51 - (void)mouseUp:(NSEvent *)theEvent { | 53 - (void)mouseUp:(NSEvent *)theEvent { |
| 52 [self mouseEvent:theEvent]; | 54 [self mouseEvent:theEvent]; |
| 55 |
| 56 dragging_ = NO; |
| 57 if (pendingExitEvent_.get()) { |
| 58 NSEvent* exitEvent = |
| 59 [NSEvent enterExitEventWithType:NSMouseExited |
| 60 location:[theEvent locationInWindow] |
| 61 modifierFlags:[theEvent modifierFlags] |
| 62 timestamp:[theEvent timestamp] |
| 63 windowNumber:[theEvent windowNumber] |
| 64 context:[theEvent context] |
| 65 eventNumber:[pendingExitEvent_.get() eventNumber] |
| 66 trackingNumber:[pendingExitEvent_.get() trackingNumber] |
| 67 userData:[pendingExitEvent_.get() userData]]; |
| 68 [self mouseEvent:exitEvent]; |
| 69 pendingExitEvent_.reset(); |
| 70 } |
| 53 } | 71 } |
| 54 | 72 |
| 55 - (void)rightMouseUp:(NSEvent *)theEvent { | 73 - (void)rightMouseUp:(NSEvent *)theEvent { |
| 56 [self mouseEvent:theEvent]; | 74 [self mouseEvent:theEvent]; |
| 57 } | 75 } |
| 58 | 76 |
| 59 - (void)otherMouseUp:(NSEvent *)theEvent { | 77 - (void)otherMouseUp:(NSEvent *)theEvent { |
| 60 [self mouseEvent:theEvent]; | 78 [self mouseEvent:theEvent]; |
| 61 } | 79 } |
| 62 | 80 |
| 63 - (void)mouseMoved:(NSEvent *)theEvent { | 81 - (void)mouseMoved:(NSEvent *)theEvent { |
| 64 [self mouseEvent:theEvent]; | 82 [self mouseEvent:theEvent]; |
| 65 } | 83 } |
| 66 | 84 |
| 67 - (void)mouseDragged:(NSEvent *)theEvent { | 85 - (void)mouseDragged:(NSEvent *)theEvent { |
| 68 [self mouseEvent:theEvent]; | 86 [self mouseEvent:theEvent]; |
| 69 } | 87 } |
| 70 | 88 |
| 71 - (void)rightMouseDragged:(NSEvent *)theEvent { | 89 - (void)rightMouseDragged:(NSEvent *)theEvent { |
| 72 [self mouseEvent:theEvent]; | 90 [self mouseEvent:theEvent]; |
| 73 } | 91 } |
| 74 | 92 |
| 75 - (void)otherMouseDragged:(NSEvent *)theEvent { | 93 - (void)otherMouseDragged:(NSEvent *)theEvent { |
| 76 [self mouseEvent:theEvent]; | 94 [self mouseEvent:theEvent]; |
| 77 } | 95 } |
| 78 | 96 |
| 79 - (void)mouseEntered:(NSEvent *)theEvent { | 97 - (void)mouseEntered:(NSEvent *)theEvent { |
| 98 if (pendingExitEvent_.get()) { |
| 99 pendingExitEvent_.reset(); |
| 100 return; |
| 101 } |
| 102 |
| 80 [self mouseEvent:theEvent]; | 103 [self mouseEvent:theEvent]; |
| 81 } | 104 } |
| 82 | 105 |
| 83 - (void)mouseExited:(NSEvent *)theEvent { | 106 - (void)mouseExited:(NSEvent *)theEvent { |
| 107 // The tracking area will send an exit event even during a drag, which isn't |
| 108 // how the event flow for drags should work. This stores the exit event, and |
| 109 // sends it when the drag completes instead. |
| 110 if (dragging_) { |
| 111 pendingExitEvent_.reset([theEvent retain]); |
| 112 return; |
| 113 } |
| 114 |
| 84 [self mouseEvent:theEvent]; | 115 [self mouseEvent:theEvent]; |
| 85 } | 116 } |
| 86 | 117 |
| 87 - (void)keyDown:(NSEvent *)theEvent { | 118 - (void)keyDown:(NSEvent *)theEvent { |
| 88 [self keyEvent:theEvent]; | 119 [self keyEvent:theEvent]; |
| 89 } | 120 } |
| 90 | 121 |
| 91 - (void)keyUp:(NSEvent *)theEvent { | 122 - (void)keyUp:(NSEvent *)theEvent { |
| 92 [self keyEvent:theEvent]; | 123 [self keyEvent:theEvent]; |
| 93 } | 124 } |
| 94 | 125 |
| 95 - (void)flagsChanged:(NSEvent *)theEvent { | 126 - (void)flagsChanged:(NSEvent *)theEvent { |
| 96 [self keyEvent:theEvent]; | 127 [self keyEvent:theEvent]; |
| 97 } | 128 } |
| 98 | 129 |
| 99 - (gfx::Rect)NSRectToRect:(NSRect)rect { | 130 - (gfx::Rect)NSRectToRect:(NSRect)rect { |
| 100 gfx::Rect new_rect(NSRectToCGRect(rect)); | 131 gfx::Rect new_rect(NSRectToCGRect(rect)); |
| 101 new_rect.set_y([self bounds].size.height - new_rect.y() - new_rect.height()); | 132 new_rect.set_y([self bounds].size.height - new_rect.y() - new_rect.height()); |
| 102 return new_rect; | 133 return new_rect; |
| 103 } | 134 } |
| 104 | 135 |
| 105 - (NSRect)RectToNSRect:(gfx::Rect)rect { | 136 - (NSRect)RectToNSRect:(gfx::Rect)rect { |
| 106 NSRect new_rect(NSRectFromCGRect(rect.ToCGRect())); | 137 NSRect new_rect(NSRectFromCGRect(rect.ToCGRect())); |
| 107 new_rect.origin.y = | 138 new_rect.origin.y = |
| 108 [self bounds].size.height - new_rect.origin.y - new_rect.size.height; | 139 [self bounds].size.height - new_rect.origin.y - new_rect.size.height; |
| 109 return new_rect; | 140 return new_rect; |
| 110 } | 141 } |
| 111 | 142 |
| 112 @end | 143 @end |
| OLD | NEW |