Commit 441287d1 authored by spqchan's avatar spqchan Committed by Commit bot

[Mac] Fix for security indicator drag&drop navigation

Reject drops that land on the omnibox decorations

BUG=588381

Review-Url: https://codereview.chromium.org/2324593002
Cr-Commit-Position: refs/heads/master@{#420768}
parent 59e3a9e0
......@@ -513,12 +513,21 @@ const CGFloat kAnimationDuration = 0.2;
// TODO(viettrungluu): crbug.com/30809 -- this is a hack since it steals focus
// and doesn't return it.
[[self window] makeFirstResponder:self];
return [dropHandler_ draggingEntered:sender];
bool canDropAtLocation =
[[self cell] canDropAtLocationInWindow:[sender draggingLocation]
ofView:self];
return canDropAtLocation ? [dropHandler_ draggingEntered:sender]
: NSDragOperationNone;
}
// (URLDropTarget protocol)
- (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
return [dropHandler_ draggingUpdated:sender];
bool canDropAtLocation =
[[self cell] canDropAtLocationInWindow:[sender draggingLocation]
ofView:self];
return canDropAtLocation ? [dropHandler_ draggingUpdated:sender]
: NSDragOperationNone;
}
// (URLDropTarget protocol)
......
......@@ -64,6 +64,18 @@ class LocationBarDecoration;
- (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration
inFrame:(NSRect)cellFrame;
// Returns true if it's okay to drop dragged data into the view at the
// given location.
- (BOOL)canDropAtLocationInWindow:(NSPoint)location
ofView:(AutocompleteTextField*)controlView;
// Find the decoration under the location in the window. Return |NULL| if
// there's nothing in the location.
- (LocationBarDecoration*)decorationForLocationInWindow:(NSPoint)location
inRect:(NSRect)cellFrame
ofView:(AutocompleteTextField*)
field;
// Find the decoration under the event. |NULL| if |theEvent| is not
// over anything.
- (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent
......
......@@ -424,13 +424,44 @@ size_t CalculatePositionsInFrame(
[super drawInteriorWithFrame:cellFrame inView:controlView];
}
- (BOOL)canDropAtLocationInWindow:(NSPoint)location
ofView:(AutocompleteTextField*)controlView {
NSRect cellFrame = [controlView bounds];
const NSPoint locationInView =
[controlView convertPoint:location fromView:nil];
// If we have decorations, the drop can't occur at their horizontal padding.
if (!leftDecorations_.empty() && locationInView.x < LeftDecorationXOffset())
return false;
if (!rightDecorations_.empty() &&
locationInView.x > NSWidth(cellFrame) - kRightDecorationXOffset) {
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 +470,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];
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment