summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-30 16:11:50 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-30 16:11:50 +0000
commitcb9763b66b2829349280c08549ee519bf1ae58db (patch)
tree0a6335d823aecc7e38282f5e7d020ca557443934 /chrome
parentcabf8f557789815b5f093aa741127a73b1a6618d (diff)
downloadchromium_src-cb9763b66b2829349280c08549ee519bf1ae58db.zip
chromium_src-cb9763b66b2829349280c08549ee519bf1ae58db.tar.gz
chromium_src-cb9763b66b2829349280c08549ee519bf1ae58db.tar.bz2
-[AutocompleteTextFieldEditor delegate] cleanup.
AutocompleteTextFieldEditor* requires its delegate to be an AutocompleteTextField*. Override the return type of -delegate and the parameter type of -setDelegate:. This is safe because NSTextView, AutocompleteTextFieldEditor's superclass, uses id<NSTextViewDelegate> as the delegate type (as of the 10.6 SDK, and just id prior), and AutocompleteTextField* implements NSTextViewDelegate (and of course is descended from id). This change allows some casts and scattered type checks in this file to be removed in favor of the cast and type check in one central location. It also fixes another 10.6 SDK build error caused because -delegate is more specific than just id in that SDK. It provides future-proofing against further errors of this sort. BUG=none TEST=10.6 SDK build Review URL: http://codereview.chromium.org/1550002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43083 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_editor.h6
-rw-r--r--chrome/browser/cocoa/autocomplete_text_field_editor.mm25
2 files changed, 21 insertions, 10 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_editor.h b/chrome/browser/cocoa/autocomplete_text_field_editor.h
index aee4e6a..1c3ce5a 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_editor.h
+++ b/chrome/browser/cocoa/autocomplete_text_field_editor.h
@@ -7,6 +7,7 @@
#include "base/scoped_nsobject.h"
#import "chrome/browser/cocoa/url_drop_target.h"
+@class AutocompleteTextField;
class AutocompleteTextFieldObserver;
class Profile;
@@ -33,6 +34,11 @@ class Profile;
@property(nonatomic) Profile* profile;
+// The delegate is always an AutocompleteTextField*. Override the superclass
+// implementations to allow for proper typing.
+- (AutocompleteTextField*)delegate;
+- (void)setDelegate:(AutocompleteTextField*)delegate;
+
@end
@interface AutocompleteTextFieldEditor(PrivateTestMethods)
diff --git a/chrome/browser/cocoa/autocomplete_text_field_editor.mm b/chrome/browser/cocoa/autocomplete_text_field_editor.mm
index 5608e3f..70aa5cd 100644
--- a/chrome/browser/cocoa/autocomplete_text_field_editor.mm
+++ b/chrome/browser/cocoa/autocomplete_text_field_editor.mm
@@ -47,16 +47,23 @@ class Extension;
// This class assumes that the delegate is an AutocompleteTextField.
// Enforce that assumption.
-- (void)setDelegate:(id)anObject {
- DCHECK(anObject == nil ||
- [anObject isKindOfClass:[AutocompleteTextField class]]);
- [super setDelegate:anObject];
+- (AutocompleteTextField*)delegate {
+ AutocompleteTextField* delegate =
+ static_cast<AutocompleteTextField*>([super delegate]);
+ DCHECK(delegate == nil ||
+ [delegate isKindOfClass:[AutocompleteTextField class]]);
+ return delegate;
+}
+
+- (void)setDelegate:(AutocompleteTextField*)delegate {
+ DCHECK(delegate == nil ||
+ [delegate isKindOfClass:[AutocompleteTextField class]]);
+ [super setDelegate:delegate];
}
// Convenience method for retrieving the observer from the delegate.
- (AutocompleteTextFieldObserver*)observer {
- DCHECK([[self delegate] isKindOfClass:[AutocompleteTextField class]]);
- return [static_cast<AutocompleteTextField*>([self delegate]) observer];
+ return [[self delegate] observer];
}
- (void)paste:(id)sender {
@@ -145,10 +152,9 @@ class Extension;
// (Overridden from NSResponder)
- (BOOL)becomeFirstResponder {
BOOL doAccept = [super becomeFirstResponder];
- AutocompleteTextField* field = (AutocompleteTextField*)[self delegate];
+ AutocompleteTextField* field = [self delegate];
// Only lock visibility if we've been set up with a delegate (the text field).
if (doAccept && field) {
- DCHECK([field isKindOfClass:[AutocompleteTextField class]]);
// Give the text field ownership of the visibility lock. (The first
// responder dance between the field and the field editor is a little
// weird.)
@@ -161,10 +167,9 @@ class Extension;
// (Overridden from NSResponder)
- (BOOL)resignFirstResponder {
BOOL doResign = [super resignFirstResponder];
- AutocompleteTextField* field = (AutocompleteTextField*)[self delegate];
+ AutocompleteTextField* field = [self delegate];
// Only lock visibility if we've been set up with a delegate (the text field).
if (doResign && field) {
- DCHECK([field isKindOfClass:[AutocompleteTextField class]]);
// Give the text field ownership of the visibility lock.
[[BrowserWindowController browserWindowControllerForView:field]
releaseBarVisibilityForOwner:field withAnimation:YES delay:YES];