Index: chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm |
diff --git a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm |
index 54dabd7e16754fdf1a212e2dc9d5c4adebf71d33..2dce1d78ab380018af1b763d8ebb9bcbef60f487 100644 |
--- a/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm |
+++ b/chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_cell.mm |
@@ -424,13 +424,52 @@ size_t CalculatePositionsInFrame( |
[super drawInteriorWithFrame:cellFrame inView:controlView]; |
} |
+- (BOOL)canDropAtLocationInWindow:(NSPoint)location |
+ ofView:(AutocompleteTextField*)controlView { |
+ NSRect cellFrame = [controlView bounds]; |
+ const BOOL flipped = [controlView isFlipped]; |
+ const NSPoint locationInView = |
+ [controlView convertPoint:location fromView:nil]; |
+ |
+ // If we have decorations, the drop can't occur at their horizontal padding. |
+ if (!leftDecorations_.empty()) { |
+ NSRect leftPaddingFrame = cellFrame; |
+ leftPaddingFrame.size.width = LeftDecorationXOffset(); |
+ if (NSMouseInRect(locationInView, leftPaddingFrame, flipped)) |
shrike
2016/09/16 18:28:41
You could also just say if (locationInView.x < Lef
spqchan
2016/09/20 21:00:00
Done.
|
+ return false; |
+ } |
+ |
+ if (!rightDecorations_.empty()) { |
shrike
2016/09/16 18:28:41
Do you think we really need this check? Seems like
spqchan
2016/09/20 21:00:00
I think it's better to be consistent with the left
|
+ NSRect rightPaddingFrame = cellFrame; |
+ rightPaddingFrame.origin.x = NSMaxX(cellFrame) - kRightDecorationXOffset; |
+ rightPaddingFrame.size.width = kRightDecorationXOffset; |
+ if (NSMouseInRect(locationInView, rightPaddingFrame, flipped)) |
+ return false; |
+ } |
+ |
+ LocationBarDecoration* decoration = |
+ [self decorationForLocationInWindow:location |
+ inRect:cellFrame |
+ ofView:controlView]; |
+ return !decoration; |
+} |
+ |
- (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent |
inRect:(NSRect)cellFrame |
ofView:(AutocompleteTextField*)controlView |
{ |
+ return [self decorationForLocationInWindow:[theEvent locationInWindow] |
+ inRect:cellFrame |
+ ofView:controlView]; |
+} |
+ |
+- (LocationBarDecoration*)decorationForLocationInWindow:(NSPoint)location |
+ inRect:(NSRect)cellFrame |
+ ofView:(AutocompleteTextField*) |
+ controlView { |
const BOOL flipped = [controlView isFlipped]; |
- const NSPoint location = |
- [controlView convertPoint:[theEvent locationInWindow] fromView:nil]; |
+ const NSPoint locationInView = |
+ [controlView convertPoint:location fromView:nil]; |
std::vector<LocationBarDecoration*> decorations; |
std::vector<NSRect> decorationFrames; |
@@ -439,7 +478,7 @@ size_t CalculatePositionsInFrame( |
&decorations, &decorationFrames, &textFrame); |
for (size_t i = 0; i < decorations.size(); ++i) { |
- if (NSMouseInRect(location, decorationFrames[i], flipped)) |
+ if (NSMouseInRect(locationInView, decorationFrames[i], flipped)) |
return decorations[i]; |
} |