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

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: Review fixes. 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..2b8e4479f688d7a03152db142830627d9706501d 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,12 @@ size_t CalculatePositionsInFrame(
- (BOOL)mouseDown:(NSEvent*)theEvent
inRect:(NSRect)cellFrame
ofView:(AutocompleteTextField*)controlView {
+ // 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_])
Scott Hess - ex-Googler 2014/02/27 21:09:36 focusEvent (no _), focusEvent_ is nil.
+ focusEvent.reset();
+
LocationBarDecoration* decoration =
[self decorationForEvent:theEvent inRect:cellFrame ofView:controlView];
if (!decoration || !decoration->AcceptsMousePress())
@@ -481,6 +493,9 @@ size_t CalculatePositionsInFrame(
ofView:controlView
untilMouseUp:YES];
+ // Post delayed focus notification, if necessary.
+ [self focusNotificationFor:focusEvent ofView:controlView];
Scott Hess - ex-Googler 2014/02/27 21:09:36 Yeah, I think so. Nothing has occurred to me abou
groby-ooo-7-16 2014/02/27 23:15:27 Well, we need to accept firstResponder for the top
+
// 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 +822,31 @@ static NSString* UnusedLegalNameForNewDropFile(NSURL* saveLocation,
return [super showsFirstResponder] && !hideFocusState_;
}
+- (void)focusNotificationFor:(NSEvent*)event
+ ofView:(AutocompleteTextField*)controlView {
+ if ([controlView observer] && event) {
+ const bool controlDown = ([event modifierFlags] & NSControlKeyMask) != 0;
+ [controlView observer]->OnSetFocus(controlDown);
+ }
+}
Scott Hess - ex-Googler 2014/02/27 21:09:36 I can't tell if the following is clearer or not, s
groby-ooo-7-16 2014/02/27 23:15:27 Except this is only called from button decorations
+
+- (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