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

Unified Diff: chrome/browser/cocoa/autocomplete_text_field.mm

Issue 173194: [Mac] Omnibox keyword, keyword hint, and search hint support.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 4 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
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field.h ('k') | chrome/browser/cocoa/autocomplete_text_field_cell.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/autocomplete_text_field.mm
===================================================================
--- chrome/browser/cocoa/autocomplete_text_field.mm (revision 23951)
+++ chrome/browser/cocoa/autocomplete_text_field.mm (working copy)
@@ -33,4 +33,71 @@
[super flagsChanged:theEvent];
}
+- (AutocompleteTextFieldCell*)autocompleteTextFieldCell {
+ DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]);
+ return static_cast<AutocompleteTextFieldCell*>([self cell]);
+}
+
+// TODO(shess): An alternate implementation of this would be to pick
+// out the field's subview (which may be a clip view around the field
+// editor) and manually resize it to the textFrame returned from the
+// cell's -splitFrame:*. That doesn't mess with the editing state of
+// the field editor system, but does make other assumptions about how
+// field editors are placed.
+- (void)resetFieldEditorFrameIfNeeded {
+ AutocompleteTextFieldCell* cell = [self cell];
+ if ([cell fieldEditorNeedsReset]) {
+ NSTextView* editor = (id)[self currentEditor];
+ if (editor) {
+ // Clear the delegate so that it doesn't see
+ // -control:textShouldEndEditing: (closes autocomplete popup).
+ id delegate = [self delegate];
+ [self setDelegate:nil];
+
+ // -makeFirstResponder: will select-all, restore selection.
+ NSRange sel = [editor selectedRange];
+ [[self window] makeFirstResponder:self];
+ [editor setSelectedRange:sel];
+
+ [self setDelegate:delegate];
+
+ // Now provoke call to delegate's -controlTextDidBeginEditing:.
+ // This is necessary to make sure that we'll send the
+ // appropriate -control:textShouldEndEditing: call when we lose
+ // focus.
+ // TODO(shess): Would be better to only restore this state if
+ // -controlTextDidBeginEditing: had already been sent.
+ // Unfortunately, that's hard to detect. Could either check
+ // popup IsOpen() or model has_focus()?
+ [editor shouldChangeTextInRange:sel replacementString:@""];
+ }
+ [cell setFieldEditorNeedsReset:NO];
+ }
+}
+
+// Clicks in the frame outside the field editor will attempt to make
+// us first-responder, which will select-all. So decline
+// first-responder when the field editor is active.
+- (BOOL)acceptsFirstResponder {
+ if ([self currentEditor]) {
+ return NO;
+ }
+ return [super acceptsFirstResponder];
+}
+
+// Reroute events for the decoration area to the field editor. This
+// will cause the cursor to be moved as close to the edge where the
+// event was seen as possible.
+//
+// TODO(shess) Check this in light of the -acceptsFirstResponder
+// change. It may no longer be needed.
+- (void)mouseDown:(NSEvent *)theEvent {
+ NSText* editor = [self currentEditor];
+ if (editor) {
+ [editor mouseDown:theEvent];
+ } else {
+ [super mouseDown:theEvent];
+ }
+}
+
@end
Property changes on: chrome/browser/cocoa/autocomplete_text_field.mm
___________________________________________________________________
Name: svn:eol-style
+ LF
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field.h ('k') | chrome/browser/cocoa/autocomplete_text_field_cell.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698