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

Side by Side Diff: chrome/browser/cocoa/autocomplete_text_field.mm

Issue 211030: [Mac] Expose AutocompleteEditViewMac to Cocoa code. (Closed)
Patch Set: Rohit's comments Created 11 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/cocoa/autocomplete_text_field.h" 5 #include "chrome/browser/cocoa/autocomplete_text_field.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/cocoa/autocomplete_text_field_cell.h" 8 #include "chrome/browser/cocoa/autocomplete_text_field_cell.h"
9 9
10 @implementation AutocompleteTextField 10 @implementation AutocompleteTextField
11 11
12 @synthesize observer = observer_;
13
12 + (Class)cellClass { 14 + (Class)cellClass {
13 return [AutocompleteTextFieldCell class]; 15 return [AutocompleteTextFieldCell class];
14 } 16 }
15 17
16 - (void)awakeFromNib { 18 - (void)awakeFromNib {
17 DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]); 19 DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]);
18 } 20 }
19 21
20 - (BOOL)textShouldPaste:(NSText*)fieldEditor {
21 id delegate = [self delegate];
22 if ([delegate respondsToSelector:@selector(control:textShouldPaste:)]) {
23 return [delegate control:self textShouldPaste:fieldEditor];
24 }
25 return YES;
26 }
27
28 - (NSString*)textPasteActionString:(NSText*)fieldEditor { 22 - (NSString*)textPasteActionString:(NSText*)fieldEditor {
29 id delegate = [self delegate]; 23 id delegate = [self delegate];
30 if ([delegate respondsToSelector:@selector(control:textPasteActionString:)]) { 24 if ([delegate respondsToSelector:@selector(control:textPasteActionString:)]) {
31 return [delegate control:self textPasteActionString:fieldEditor]; 25 return [delegate control:self textPasteActionString:fieldEditor];
32 } 26 }
33 return nil; 27 return nil;
34 } 28 }
35 29
36 - (void)textDidPasteAndGo:(NSText*)fieldEditor { 30 - (void)textDidPasteAndGo:(NSText*)fieldEditor {
37 id delegate = [self delegate]; 31 id delegate = [self delegate];
38 if ([delegate respondsToSelector:@selector(control:textDidPasteAndGo:)]) { 32 if ([delegate respondsToSelector:@selector(control:textDidPasteAndGo:)]) {
39 [delegate control:self textDidPasteAndGo:fieldEditor]; 33 [delegate control:self textDidPasteAndGo:fieldEditor];
40 } 34 }
41 } 35 }
42 36
43 - (void)flagsChanged:(NSEvent*)theEvent { 37 - (void)flagsChanged:(NSEvent*)theEvent {
44 id delegate = [self delegate]; 38 bool controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0;
45 if ([delegate respondsToSelector:@selector(control:flagsChanged:)]) { 39 observer_->OnControlKeyChanged(controlFlag);
46 [delegate control:self flagsChanged:theEvent];
47 }
48 [super flagsChanged:theEvent];
49 } 40 }
50 41
51 - (AutocompleteTextFieldCell*)autocompleteTextFieldCell { 42 - (AutocompleteTextFieldCell*)autocompleteTextFieldCell {
52 DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]); 43 DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]);
53 return static_cast<AutocompleteTextFieldCell*>([self cell]); 44 return static_cast<AutocompleteTextFieldCell*>([self cell]);
54 } 45 }
55 46
56 // TODO(shess): An alternate implementation of this would be to pick 47 // TODO(shess): An alternate implementation of this would be to pick
57 // out the field's subview (which may be a clip view around the field 48 // out the field's subview (which may be a clip view around the field
58 // editor) and manually resize it to the textFrame returned from the 49 // editor) and manually resize it to the textFrame returned from the
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // field editor to the end of the content so that the selection 151 // field editor to the end of the content so that the selection
161 // doesn't initiate from somewhere in the middle of the text. 152 // doesn't initiate from somewhere in the middle of the text.
162 if (location.x > NSMaxX(textFrame)) { 153 if (location.x > NSMaxX(textFrame)) {
163 [editor scrollRangeToVisible:NSMakeRange([[self stringValue] length], 0)]; 154 [editor scrollRangeToVisible:NSMakeRange([[self stringValue] length], 0)];
164 } 155 }
165 156
166 [editor mouseDown:theEvent]; 157 [editor mouseDown:theEvent];
167 } 158 }
168 159
169 @end 160 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/autocomplete_text_field.h ('k') | chrome/browser/cocoa/autocomplete_text_field_editor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698