OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" | 5 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" |
6 | 6 |
7 #include "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 observer->OnCopy(); | 40 observer->OnCopy(); |
41 } | 41 } |
42 | 42 |
43 - (void)cut:(id)sender { | 43 - (void)cut:(id)sender { |
44 [self copy:sender]; | 44 [self copy:sender]; |
45 [self delete:nil]; | 45 [self delete:nil]; |
46 } | 46 } |
47 | 47 |
48 // This class assumes that the delegate is an AutocompleteTextField. | 48 // This class assumes that the delegate is an AutocompleteTextField. |
49 // Enforce that assumption. | 49 // Enforce that assumption. |
50 - (void)setDelegate:(id)anObject { | 50 - (AutocompleteTextField*)delegate { |
51 DCHECK(anObject == nil || | 51 AutocompleteTextField* delegate = |
52 [anObject isKindOfClass:[AutocompleteTextField class]]); | 52 static_cast<AutocompleteTextField*>([super delegate]); |
53 [super setDelegate:anObject]; | 53 DCHECK(delegate == nil || |
| 54 [delegate isKindOfClass:[AutocompleteTextField class]]); |
| 55 return delegate; |
| 56 } |
| 57 |
| 58 - (void)setDelegate:(AutocompleteTextField*)delegate { |
| 59 DCHECK(delegate == nil || |
| 60 [delegate isKindOfClass:[AutocompleteTextField class]]); |
| 61 [super setDelegate:delegate]; |
54 } | 62 } |
55 | 63 |
56 // Convenience method for retrieving the observer from the delegate. | 64 // Convenience method for retrieving the observer from the delegate. |
57 - (AutocompleteTextFieldObserver*)observer { | 65 - (AutocompleteTextFieldObserver*)observer { |
58 DCHECK([[self delegate] isKindOfClass:[AutocompleteTextField class]]); | 66 return [[self delegate] observer]; |
59 return [static_cast<AutocompleteTextField*>([self delegate]) observer]; | |
60 } | 67 } |
61 | 68 |
62 - (void)paste:(id)sender { | 69 - (void)paste:(id)sender { |
63 AutocompleteTextFieldObserver* observer = [self observer]; | 70 AutocompleteTextFieldObserver* observer = [self observer]; |
64 DCHECK(observer); | 71 DCHECK(observer); |
65 if (observer) { | 72 if (observer) { |
66 observer->OnPaste(); | 73 observer->OnPaste(); |
67 } | 74 } |
68 } | 75 } |
69 | 76 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 [item setTag:IDC_EDIT_SEARCH_ENGINES]; | 145 [item setTag:IDC_EDIT_SEARCH_ENGINES]; |
139 } | 146 } |
140 } | 147 } |
141 | 148 |
142 return menu; | 149 return menu; |
143 } | 150 } |
144 | 151 |
145 // (Overridden from NSResponder) | 152 // (Overridden from NSResponder) |
146 - (BOOL)becomeFirstResponder { | 153 - (BOOL)becomeFirstResponder { |
147 BOOL doAccept = [super becomeFirstResponder]; | 154 BOOL doAccept = [super becomeFirstResponder]; |
148 AutocompleteTextField* field = (AutocompleteTextField*)[self delegate]; | 155 AutocompleteTextField* field = [self delegate]; |
149 // Only lock visibility if we've been set up with a delegate (the text field). | 156 // Only lock visibility if we've been set up with a delegate (the text field). |
150 if (doAccept && field) { | 157 if (doAccept && field) { |
151 DCHECK([field isKindOfClass:[AutocompleteTextField class]]); | |
152 // Give the text field ownership of the visibility lock. (The first | 158 // Give the text field ownership of the visibility lock. (The first |
153 // responder dance between the field and the field editor is a little | 159 // responder dance between the field and the field editor is a little |
154 // weird.) | 160 // weird.) |
155 [[BrowserWindowController browserWindowControllerForView:field] | 161 [[BrowserWindowController browserWindowControllerForView:field] |
156 lockBarVisibilityForOwner:field withAnimation:YES delay:NO]; | 162 lockBarVisibilityForOwner:field withAnimation:YES delay:NO]; |
157 } | 163 } |
158 return doAccept; | 164 return doAccept; |
159 } | 165 } |
160 | 166 |
161 // (Overridden from NSResponder) | 167 // (Overridden from NSResponder) |
162 - (BOOL)resignFirstResponder { | 168 - (BOOL)resignFirstResponder { |
163 BOOL doResign = [super resignFirstResponder]; | 169 BOOL doResign = [super resignFirstResponder]; |
164 AutocompleteTextField* field = (AutocompleteTextField*)[self delegate]; | 170 AutocompleteTextField* field = [self delegate]; |
165 // Only lock visibility if we've been set up with a delegate (the text field). | 171 // Only lock visibility if we've been set up with a delegate (the text field). |
166 if (doResign && field) { | 172 if (doResign && field) { |
167 DCHECK([field isKindOfClass:[AutocompleteTextField class]]); | |
168 // Give the text field ownership of the visibility lock. | 173 // Give the text field ownership of the visibility lock. |
169 [[BrowserWindowController browserWindowControllerForView:field] | 174 [[BrowserWindowController browserWindowControllerForView:field] |
170 releaseBarVisibilityForOwner:field withAnimation:YES delay:YES]; | 175 releaseBarVisibilityForOwner:field withAnimation:YES delay:YES]; |
171 } | 176 } |
172 return doResign; | 177 return doResign; |
173 } | 178 } |
174 | 179 |
175 // (URLDropTarget protocol) | 180 // (URLDropTarget protocol) |
176 - (id<URLDropTargetController>)urlDropController { | 181 - (id<URLDropTargetController>)urlDropController { |
177 BrowserWindowController* windowController = | 182 BrowserWindowController* windowController = |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 | 231 |
227 // TODO(shess): Beep on empty? I hate beeps, though. | 232 // TODO(shess): Beep on empty? I hate beeps, though. |
228 // NOTE: If |aString| is empty, this intentionally replaces the | 233 // NOTE: If |aString| is empty, this intentionally replaces the |
229 // selection with empty. This seems consistent with the case where | 234 // selection with empty. This seems consistent with the case where |
230 // the input contained a mixture of characters and the string ended | 235 // the input contained a mixture of characters and the string ended |
231 // up not empty. | 236 // up not empty. |
232 [super insertText:aString]; | 237 [super insertText:aString]; |
233 } | 238 } |
234 | 239 |
235 @end | 240 @end |
OLD | NEW |