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

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

Issue 163913011: [OSX, OmniTheatre] Handle OriginChip click properly. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Account for becomeFirstResponder without corresponding event. Created 6 years, 10 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
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

Powered by Google App Engine
This is Rietveld 408576698