| 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 ac7a62b6cae8aa8bb33f52e219d486ad9cc55d0c..e188f2d8e507d1a8dd98f10addca4ee559a8beca 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
|
| @@ -165,6 +165,12 @@ size_t CalculatePositionsInFrame(
|
|
|
| } // namespace
|
|
|
| +@interface AutocompleteTextFieldCell ()
|
| +// Post an OnSetFocus notification to the observer of |controlView|.
|
| +- (void)focusNotificationFor:(NSEvent*)event
|
| + ofView:(AutocompleteTextField*)controlView;
|
| +@end
|
| +
|
| @implementation AutocompleteTextFieldCell
|
|
|
| @synthesize isPopupMode = isPopupMode_;
|
| @@ -411,6 +417,15 @@ size_t CalculatePositionsInFrame(
|
| - (BOOL)mouseDown:(NSEvent*)theEvent
|
| inRect:(NSRect)cellFrame
|
| ofView:(AutocompleteTextField*)controlView {
|
| + // TODO(groby): Factor this into three pieces - find target for event, handle
|
| + // delayed focus (for any and all events), execute mouseDown for target.
|
| +
|
| + // Check if this mouseDown was the reason the control became firstResponder.
|
| + // If not, discard focus event.
|
| + base::scoped_nsobject<NSEvent> focusEvent(focusEvent_.release());
|
| + if (![theEvent isEqual:focusEvent])
|
| + focusEvent.reset();
|
| +
|
| LocationBarDecoration* decoration =
|
| [self decorationForEvent:theEvent inRect:cellFrame ofView:controlView];
|
| if (!decoration || !decoration->AcceptsMousePress())
|
| @@ -481,6 +496,10 @@ size_t CalculatePositionsInFrame(
|
| ofView:controlView
|
| untilMouseUp:YES];
|
|
|
| + // Post delayed focus notification, if necessary.
|
| + if (focusEvent.get())
|
| + [self focusNotificationFor:focusEvent ofView:controlView];
|
| +
|
| // Set the proper state (hover or normal) once the mouse has been released,
|
| // and call |OnMousePressed| if the button was released while the mouse was
|
| // within the bounds of the button.
|
| @@ -807,4 +826,31 @@ static NSString* UnusedLegalNameForNewDropFile(NSURL* saveLocation,
|
| return [super showsFirstResponder] && !hideFocusState_;
|
| }
|
|
|
| +- (void)focusNotificationFor:(NSEvent*)event
|
| + ofView:(AutocompleteTextField*)controlView {
|
| + if ([controlView observer]) {
|
| + const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0;
|
| + [controlView observer]->OnSetFocus(controlDown);
|
| + }
|
| +}
|
| +
|
| +- (void)handleFocusEvent:(NSEvent*)event
|
| + ofView:(AutocompleteTextField*)controlView {
|
| + // Only intercept left button click. All other events cause immediate focus.
|
| + if ([event type] == NSLeftMouseDown) {
|
| + LocationBarDecoration* decoration =
|
| + [self decorationForEvent:event
|
| + inRect:[controlView bounds]
|
| + ofView:controlView];
|
| + // Only ButtonDecorations need a delayed focus handling.
|
| + if (decoration && decoration->AsButtonDecoration()) {
|
| + focusEvent_.reset([event retain]);
|
| + return;
|
| + }
|
| + }
|
| +
|
| + // Handle event immediately.
|
| + [self focusNotificationFor:event ofView:controlView];
|
| +}
|
| +
|
| @end
|
|
|