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

Unified Diff: chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm

Issue 2870059: [Mac] Adjust omnibox decoration dragging to keep image under mouse. (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: Move method per Trung. Created 10 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/cocoa/location_bar/bubble_decoration.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm
diff --git a/chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm b/chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm
index 83bf1ef5e72c952a3af2d2f024d58b9470d0b0d5..edb9a64b3bfe69fbdd89b074d4f60798b89a9221 100644
--- a/chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm
+++ b/chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.mm
@@ -331,24 +331,37 @@ size_t CalculatePositionsInFrame(
NSPasteboard* pboard = decoration->GetDragPasteboard();
DCHECK(pboard);
- // TODO(shess): My understanding is that the -isFlipped
- // adjustment should not be necessary. But without it, the
- // image is nowhere near the cursor. Perhaps the decorations's
- // rect is incorrectly calculated?
- // http://crbug.com/40711
- NSPoint dragPoint = decorationRect.origin;
- if ([controlView isFlipped])
- dragPoint.y += NSHeight(decorationRect);
-
NSImage* image = decoration->GetDragImage();
DCHECK(image);
- [controlView dragImage:image
- at:dragPoint
- offset:NSZeroSize
- event:event ? event : theEvent
- pasteboard:pboard
- source:self
- slideBack:YES];
+
+ NSRect dragImageRect = decoration->GetDragImageFrame(decorationRect);
+
+ // If the original click is not within |dragImageRect|, then
+ // center the image under the mouse. Otherwise, will drag from
+ // where the click was on the image.
+ const NSPoint mousePoint =
+ [controlView convertPoint:[theEvent locationInWindow] fromView:nil];
+ if (!NSMouseInRect(mousePoint, dragImageRect, [controlView isFlipped])) {
+ dragImageRect.origin =
+ NSMakePoint(mousePoint.x - NSWidth(dragImageRect) / 2.0,
+ mousePoint.y - NSHeight(dragImageRect) / 2.0);
+ }
+
+ // -[NSView dragImage:at:*] wants the images lower-left point,
+ // regardless of -isFlipped. Converting the rect to window base
+ // coordinates doesn't require any special-casing. Note that
+ // -[NSView dragFile:fromRect:*] takes a rect rather than a
+ // point, likely for this exact reason.
+ const NSPoint dragPoint =
+ [controlView convertRect:dragImageRect toView:nil].origin;
+ [[controlView window] dragImage:image
+ at:dragPoint
+ offset:NSZeroSize
+ event:theEvent
+ pasteboard:pboard
+ source:self
+ slideBack:YES];
+
return YES;
}
« no previous file with comments | « no previous file | chrome/browser/cocoa/location_bar/bubble_decoration.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698