| 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 #import "chrome/browser/ui/cocoa/autofill/autofill_popup_base_view_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_popup_base_view_cocoa.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h" | 7 #include "chrome/browser/ui/autofill/autofill_popup_view_delegate.h" |
| 8 #include "chrome/browser/ui/autofill/popup_constants.h" | 8 #include "chrome/browser/ui/autofill/popup_constants.h" |
| 9 #include "ui/base/cocoa/window_size_constants.h" | 9 #include "ui/base/cocoa/window_size_constants.h" |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 return [NSColor grayColor]; | 41 return [NSColor grayColor]; |
| 42 } | 42 } |
| 43 | 43 |
| 44 #pragma mark - | 44 #pragma mark - |
| 45 #pragma mark Public methods | 45 #pragma mark Public methods |
| 46 | 46 |
| 47 - (id)initWithDelegate:(autofill::AutofillPopupViewDelegate*)delegate | 47 - (id)initWithDelegate:(autofill::AutofillPopupViewDelegate*)delegate |
| 48 frame:(NSRect)frame { | 48 frame:(NSRect)frame { |
| 49 self = [super initWithFrame:frame]; | 49 self = [super initWithFrame:frame]; |
| 50 if (self) | 50 if (self) |
| 51 delegate_ = delegate; | 51 popup_delegate_ = delegate; |
| 52 | 52 |
| 53 return self; | 53 return self; |
| 54 } | 54 } |
| 55 | 55 |
| 56 - (void)delegateDestroyed { | 56 - (void)delegateDestroyed { |
| 57 delegate_ = NULL; | 57 popup_delegate_ = NULL; |
| 58 } | 58 } |
| 59 | 59 |
| 60 - (void)drawSeparatorWithBounds:(NSRect)bounds { | 60 - (void)drawSeparatorWithBounds:(NSRect)bounds { |
| 61 [[self separatorColor] set]; | 61 [[self separatorColor] set]; |
| 62 [NSBezierPath fillRect:bounds]; | 62 [NSBezierPath fillRect:bounds]; |
| 63 } | 63 } |
| 64 | 64 |
| 65 // A slight optimization for drawing: | 65 // A slight optimization for drawing: |
| 66 // https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Cocoa
ViewsGuide/Optimizing/Optimizing.html | 66 // https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Cocoa
ViewsGuide/Optimizing/Optimizing.html |
| 67 - (BOOL)isOpaque { | 67 - (BOOL)isOpaque { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 83 NSBezierPath* path = [NSBezierPath bezierPathWithRect:borderRect]; | 83 NSBezierPath* path = [NSBezierPath bezierPathWithRect:borderRect]; |
| 84 [[self backgroundColor] setFill]; | 84 [[self backgroundColor] setFill]; |
| 85 [path fill]; | 85 [path fill]; |
| 86 [path setLineWidth:autofill::kPopupBorderThickness]; | 86 [path setLineWidth:autofill::kPopupBorderThickness]; |
| 87 [[self borderColor] setStroke]; | 87 [[self borderColor] setStroke]; |
| 88 [path stroke]; | 88 [path stroke]; |
| 89 } | 89 } |
| 90 | 90 |
| 91 - (void)mouseUp:(NSEvent*)theEvent { | 91 - (void)mouseUp:(NSEvent*)theEvent { |
| 92 // If the view is in the process of being destroyed, abort. | 92 // If the view is in the process of being destroyed, abort. |
| 93 if (!delegate_) | 93 if (!popup_delegate_) |
| 94 return; | 94 return; |
| 95 | 95 |
| 96 // Only accept single-click. | 96 // Only accept single-click. |
| 97 if ([theEvent clickCount] > 1) | 97 if ([theEvent clickCount] > 1) |
| 98 return; | 98 return; |
| 99 | 99 |
| 100 NSPoint location = [self convertPoint:[theEvent locationInWindow] | 100 NSPoint location = [self convertPoint:[theEvent locationInWindow] |
| 101 fromView:nil]; | 101 fromView:nil]; |
| 102 | 102 |
| 103 if (NSPointInRect(location, [self bounds])) { | 103 if (NSPointInRect(location, [self bounds])) { |
| 104 delegate_->SetSelectionAtPoint(gfx::Point(NSPointToCGPoint(location))); | 104 popup_delegate_->SetSelectionAtPoint( |
| 105 delegate_->AcceptSelectedLine(); | 105 gfx::Point(NSPointToCGPoint(location))); |
| 106 popup_delegate_->AcceptSelectedLine(); |
| 106 } | 107 } |
| 107 } | 108 } |
| 108 | 109 |
| 109 - (void)mouseMoved:(NSEvent*)theEvent { | 110 - (void)mouseMoved:(NSEvent*)theEvent { |
| 110 // If the view is in the process of being destroyed, abort. | 111 // If the view is in the process of being destroyed, abort. |
| 111 if (!delegate_) | 112 if (!popup_delegate_) |
| 112 return; | 113 return; |
| 113 | 114 |
| 114 NSPoint location = [self convertPoint:[theEvent locationInWindow] | 115 NSPoint location = [self convertPoint:[theEvent locationInWindow] |
| 115 fromView:nil]; | 116 fromView:nil]; |
| 116 | 117 |
| 117 delegate_->SetSelectionAtPoint(gfx::Point(NSPointToCGPoint(location))); | 118 popup_delegate_->SetSelectionAtPoint(gfx::Point(NSPointToCGPoint(location))); |
| 118 } | 119 } |
| 119 | 120 |
| 120 - (void)mouseDragged:(NSEvent*)theEvent { | 121 - (void)mouseDragged:(NSEvent*)theEvent { |
| 121 [self mouseMoved:theEvent]; | 122 [self mouseMoved:theEvent]; |
| 122 } | 123 } |
| 123 | 124 |
| 124 - (void)mouseExited:(NSEvent*)theEvent { | 125 - (void)mouseExited:(NSEvent*)theEvent { |
| 125 // If the view is in the process of being destroyed, abort. | 126 // If the view is in the process of being destroyed, abort. |
| 126 if (!delegate_) | 127 if (!popup_delegate_) |
| 127 return; | 128 return; |
| 128 | 129 |
| 129 delegate_->SelectionCleared(); | 130 popup_delegate_->SelectionCleared(); |
| 130 } | 131 } |
| 131 | 132 |
| 132 #pragma mark - | 133 #pragma mark - |
| 133 #pragma mark Messages from AutofillPopupViewBridge: | 134 #pragma mark Messages from AutofillPopupViewBridge: |
| 134 | 135 |
| 135 - (void)updateBoundsAndRedrawPopup { | 136 - (void)updateBoundsAndRedrawPopup { |
| 136 NSRect frame = NSRectFromCGRect(delegate_->popup_bounds().ToCGRect()); | 137 NSRect frame = NSRectFromCGRect(popup_delegate_->popup_bounds().ToCGRect()); |
| 137 | 138 |
| 138 // Flip coordinates back into Cocoa-land. The controller's platform-neutral | 139 // Flip coordinates back into Cocoa-land. The controller's platform-neutral |
| 139 // coordinate space places the origin at the top-left of the first screen, | 140 // coordinate space places the origin at the top-left of the first screen, |
| 140 // whereas Cocoa's coordinate space expects the origin to be at the | 141 // whereas Cocoa's coordinate space expects the origin to be at the |
| 141 // bottom-left of this same screen. | 142 // bottom-left of this same screen. |
| 142 NSScreen* screen = [[NSScreen screens] firstObject]; | 143 NSScreen* screen = [[NSScreen screens] firstObject]; |
| 143 frame.origin.y = NSMaxY([screen frame]) - NSMaxY(frame); | 144 frame.origin.y = NSMaxY([screen frame]) - NSMaxY(frame); |
| 144 | 145 |
| 145 // TODO(isherman): The view should support scrolling if the popup gets too | 146 // TODO(isherman): The view should support scrolling if the popup gets too |
| 146 // big to fit on the screen. | 147 // big to fit on the screen. |
| 147 [[self window] setFrame:frame display:YES]; | 148 [[self window] setFrame:frame display:YES]; |
| 148 [self setNeedsDisplay:YES]; | 149 [self setNeedsDisplay:YES]; |
| 149 } | 150 } |
| 150 | 151 |
| 151 - (void)showPopup { | 152 - (void)showPopup { |
| 152 NSWindow* window = | 153 NSWindow* window = |
| 153 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater | 154 [[NSWindow alloc] initWithContentRect:ui::kWindowSizeDeterminedLater |
| 154 styleMask:NSBorderlessWindowMask | 155 styleMask:NSBorderlessWindowMask |
| 155 backing:NSBackingStoreBuffered | 156 backing:NSBackingStoreBuffered |
| 156 defer:NO]; | 157 defer:NO]; |
| 157 [window setContentView:self]; | 158 [window setContentView:self]; |
| 158 | 159 |
| 159 // Telling Cocoa that the window is opaque enables some drawing optimizations. | 160 // Telling Cocoa that the window is opaque enables some drawing optimizations. |
| 160 [window setOpaque:YES]; | 161 [window setOpaque:YES]; |
| 161 | 162 |
| 162 [self updateBoundsAndRedrawPopup]; | 163 [self updateBoundsAndRedrawPopup]; |
| 163 [[delegate_->container_view() window] addChildWindow:window | 164 [[popup_delegate_->container_view() window] addChildWindow:window |
| 164 ordered:NSWindowAbove]; | 165 ordered:NSWindowAbove]; |
| 165 } | 166 } |
| 166 | 167 |
| 167 - (void)hidePopup { | 168 - (void)hidePopup { |
| 168 // Remove the child window before closing, otherwise it can mess up | 169 // Remove the child window before closing, otherwise it can mess up |
| 169 // display ordering. | 170 // display ordering. |
| 170 NSWindow* window = [self window]; | 171 NSWindow* window = [self window]; |
| 171 [[window parentWindow] removeChildWindow:window]; | 172 [[window parentWindow] removeChildWindow:window]; |
| 172 [window close]; | 173 [window close]; |
| 173 } | 174 } |
| 174 | 175 |
| 175 @end | 176 @end |
| OLD | NEW |