| OLD | NEW |
| 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 #import "chrome/browser/cocoa/autocomplete_text_field.h" | 5 #import "chrome/browser/cocoa/autocomplete_text_field.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" | 8 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" |
| 9 #import "chrome/browser/cocoa/browser_window_controller.h" |
| 10 #import "chrome/browser/cocoa/toolbar_controller.h" |
| 11 #import "chrome/browser/cocoa/url_drop_target.h" |
| 9 | 12 |
| 10 @implementation AutocompleteTextField | 13 @implementation AutocompleteTextField |
| 11 | 14 |
| 12 @synthesize observer = observer_; | 15 @synthesize observer = observer_; |
| 13 | 16 |
| 14 + (Class)cellClass { | 17 + (Class)cellClass { |
| 15 return [AutocompleteTextFieldCell class]; | 18 return [AutocompleteTextFieldCell class]; |
| 16 } | 19 } |
| 17 | 20 |
| 18 - (void)dealloc { | 21 - (void)dealloc { |
| 19 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 22 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 20 [super dealloc]; | 23 [super dealloc]; |
| 21 } | 24 } |
| 22 | 25 |
| 23 - (void)awakeFromNib { | 26 - (void)awakeFromNib { |
| 24 DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]); | 27 DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]); |
| 28 dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]); |
| 25 } | 29 } |
| 26 | 30 |
| 27 - (void)flagsChanged:(NSEvent*)theEvent { | 31 - (void)flagsChanged:(NSEvent*)theEvent { |
| 28 if (observer_) { | 32 if (observer_) { |
| 29 const bool controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; | 33 const bool controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; |
| 30 observer_->OnControlKeyChanged(controlFlag); | 34 observer_->OnControlKeyChanged(controlFlag); |
| 31 } | 35 } |
| 32 } | 36 } |
| 33 | 37 |
| 34 - (AutocompleteTextFieldCell*)autocompleteTextFieldCell { | 38 - (AutocompleteTextFieldCell*)autocompleteTextFieldCell { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 - (void)viewDidMoveToWindow { | 247 - (void)viewDidMoveToWindow { |
| 244 if ([self window]) { | 248 if ([self window]) { |
| 245 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | 249 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; |
| 246 [nc addObserver:self | 250 [nc addObserver:self |
| 247 selector:@selector(windowDidResignKey:) | 251 selector:@selector(windowDidResignKey:) |
| 248 name:NSWindowDidResignKeyNotification | 252 name:NSWindowDidResignKeyNotification |
| 249 object:[self window]]; | 253 object:[self window]]; |
| 250 } | 254 } |
| 251 } | 255 } |
| 252 | 256 |
| 257 // (URLDropTarget protocol) |
| 258 - (id<URLDropTargetController>)urlDropController { |
| 259 BrowserWindowController* windowController = [[self window] windowController]; |
| 260 DCHECK([windowController isKindOfClass:[BrowserWindowController class]]); |
| 261 return [windowController toolbarController]; |
| 262 } |
| 263 |
| 264 // (URLDropTarget protocol) |
| 265 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { |
| 266 // Make ourself the first responder, which will select the text to indicate |
| 267 // that our contents would be replaced by a drop. |
| 268 // TODO(viettrungluu): crbug.com/30809 -- this is a hack since it steals focus |
| 269 // and doesn't return it. |
| 270 [[self window] makeFirstResponder:self]; |
| 271 return [dropHandler_ draggingEntered:sender]; |
| 272 } |
| 273 |
| 274 // (URLDropTarget protocol) |
| 275 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender { |
| 276 return [dropHandler_ draggingUpdated:sender]; |
| 277 } |
| 278 |
| 279 // (URLDropTarget protocol) |
| 280 - (void)draggingExited:(id<NSDraggingInfo>)sender { |
| 281 return [dropHandler_ draggingExited:sender]; |
| 282 } |
| 283 |
| 284 // (URLDropTarget protocol) |
| 285 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { |
| 286 return [dropHandler_ performDragOperation:sender]; |
| 287 } |
| 288 |
| 253 @end | 289 @end |
| OLD | NEW |