| 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.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" |    9 #import "chrome/browser/cocoa/browser_window_controller.h" | 
|   10 #import "chrome/browser/cocoa/toolbar_controller.h" |   10 #import "chrome/browser/cocoa/toolbar_controller.h" | 
|   11 #import "chrome/browser/cocoa/url_drop_target.h" |   11 #import "chrome/browser/cocoa/url_drop_target.h" | 
|   12  |   12  | 
|   13 @implementation AutocompleteTextField |   13 @implementation AutocompleteTextField | 
|   14  |   14  | 
|   15 @synthesize observer = observer_; |   15 @synthesize observer = observer_; | 
|   16  |   16  | 
|   17 + (Class)cellClass { |   17 + (Class)cellClass { | 
|   18   return [AutocompleteTextFieldCell class]; |   18   return [AutocompleteTextFieldCell class]; | 
|   19 } |   19 } | 
|   20  |   20  | 
|   21 - (void)dealloc { |   21 - (void)dealloc { | 
|   22   [[NSNotificationCenter defaultCenter] removeObserver:self]; |   22   [[NSNotificationCenter defaultCenter] removeObserver:self]; | 
|   23   [super dealloc]; |   23   [super dealloc]; | 
|   24 } |   24 } | 
|   25  |   25  | 
|   26 - (void)awakeFromNib { |   26 - (void)awakeFromNib { | 
|   27   DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]); |   27   DCHECK([[self cell] isKindOfClass:[AutocompleteTextFieldCell class]]); | 
|   28   dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]); |  | 
|   29   currentToolTips_.reset([[NSMutableArray alloc] init]); |   28   currentToolTips_.reset([[NSMutableArray alloc] init]); | 
|   30 } |   29 } | 
|   31  |   30  | 
|   32 - (void)flagsChanged:(NSEvent*)theEvent { |   31 - (void)flagsChanged:(NSEvent*)theEvent { | 
|   33   if (observer_) { |   32   if (observer_) { | 
|   34     const bool controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; |   33     const bool controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; | 
|   35     observer_->OnControlKeyChanged(controlFlag); |   34     observer_->OnControlKeyChanged(controlFlag); | 
|   36   } |   35   } | 
|   37 } |   36 } | 
|   38  |   37  | 
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  297   } |  296   } | 
|  298 } |  297 } | 
|  299  |  298  | 
|  300 - (void)viewDidMoveToWindow { |  299 - (void)viewDidMoveToWindow { | 
|  301   if ([self window]) { |  300   if ([self window]) { | 
|  302     NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; |  301     NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; | 
|  303     [nc addObserver:self |  302     [nc addObserver:self | 
|  304            selector:@selector(windowDidResignKey:) |  303            selector:@selector(windowDidResignKey:) | 
|  305                name:NSWindowDidResignKeyNotification |  304                name:NSWindowDidResignKeyNotification | 
|  306              object:[self window]]; |  305              object:[self window]]; | 
 |  306     // Only register for drops if not in a popup window. Lazily create the | 
 |  307     // drop handler when the type of window is known. | 
 |  308     BrowserWindowController* windowController = | 
 |  309         [BrowserWindowController browserWindowControllerForView:self]; | 
 |  310     if ([windowController isNormalWindow]) | 
 |  311       dropHandler_.reset([[URLDropTargetHandler alloc] initWithView:self]); | 
|  307   } |  312   } | 
|  308 } |  313 } | 
|  309  |  314  | 
|  310 // (Overridden from NSResponder) |  315 // (Overridden from NSResponder) | 
|  311 - (BOOL)becomeFirstResponder { |  316 - (BOOL)becomeFirstResponder { | 
|  312   BOOL doAccept = [super becomeFirstResponder]; |  317   BOOL doAccept = [super becomeFirstResponder]; | 
|  313   if (doAccept) { |  318   if (doAccept) { | 
|  314     [[BrowserWindowController browserWindowControllerForView:self] |  319     [[BrowserWindowController browserWindowControllerForView:self] | 
|  315         lockBarVisibilityForOwner:self withAnimation:YES delay:NO]; |  320         lockBarVisibilityForOwner:self withAnimation:YES delay:NO]; | 
|  316   } |  321   } | 
|  317   return doAccept; |  322   return doAccept; | 
|  318 } |  323 } | 
|  319  |  324  | 
|  320 // (Overridden from NSResponder) |  325 // (Overridden from NSResponder) | 
|  321 - (BOOL)resignFirstResponder { |  326 - (BOOL)resignFirstResponder { | 
|  322   BOOL doResign = [super resignFirstResponder]; |  327   BOOL doResign = [super resignFirstResponder]; | 
|  323   if (doResign) { |  328   if (doResign) { | 
|  324     [[BrowserWindowController browserWindowControllerForView:self] |  329     [[BrowserWindowController browserWindowControllerForView:self] | 
|  325         releaseBarVisibilityForOwner:self withAnimation:YES delay:YES]; |  330         releaseBarVisibilityForOwner:self withAnimation:YES delay:YES]; | 
|  326   } |  331   } | 
|  327   return doResign; |  332   return doResign; | 
|  328 } |  333 } | 
|  329  |  334  | 
|  330 // (URLDropTarget protocol) |  335 // (URLDropTarget protocol) | 
|  331 - (id<URLDropTargetController>)urlDropController { |  336 - (id<URLDropTargetController>)urlDropController { | 
|  332   BrowserWindowController* windowController = [[self window] windowController]; |  337   BrowserWindowController* windowController = | 
|  333   DCHECK([windowController isKindOfClass:[BrowserWindowController class]]); |  338       [BrowserWindowController browserWindowControllerForView:self]; | 
|  334   return [windowController toolbarController]; |  339   return [windowController toolbarController]; | 
|  335 } |  340 } | 
|  336  |  341  | 
|  337 // (URLDropTarget protocol) |  342 // (URLDropTarget protocol) | 
|  338 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { |  343 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender { | 
|  339   // Make ourself the first responder, which will select the text to indicate |  344   // Make ourself the first responder, which will select the text to indicate | 
|  340   // that our contents would be replaced by a drop. |  345   // that our contents would be replaced by a drop. | 
|  341   // TODO(viettrungluu): crbug.com/30809 -- this is a hack since it steals focus |  346   // TODO(viettrungluu): crbug.com/30809 -- this is a hack since it steals focus | 
|  342   // and doesn't return it. |  347   // and doesn't return it. | 
|  343   [[self window] makeFirstResponder:self]; |  348   [[self window] makeFirstResponder:self]; | 
|  344   return [dropHandler_ draggingEntered:sender]; |  349   return [dropHandler_ draggingEntered:sender]; | 
|  345 } |  350 } | 
|  346  |  351  | 
|  347 // (URLDropTarget protocol) |  352 // (URLDropTarget protocol) | 
|  348 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender { |  353 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender { | 
|  349   return [dropHandler_ draggingUpdated:sender]; |  354   return [dropHandler_ draggingUpdated:sender]; | 
|  350 } |  355 } | 
|  351  |  356  | 
|  352 // (URLDropTarget protocol) |  357 // (URLDropTarget protocol) | 
|  353 - (void)draggingExited:(id<NSDraggingInfo>)sender { |  358 - (void)draggingExited:(id<NSDraggingInfo>)sender { | 
|  354   return [dropHandler_ draggingExited:sender]; |  359   return [dropHandler_ draggingExited:sender]; | 
|  355 } |  360 } | 
|  356  |  361  | 
|  357 // (URLDropTarget protocol) |  362 // (URLDropTarget protocol) | 
|  358 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { |  363 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { | 
|  359   return [dropHandler_ performDragOperation:sender]; |  364   return [dropHandler_ performDragOperation:sender]; | 
|  360 } |  365 } | 
|  361  |  366  | 
|  362 @end |  367 @end | 
| OLD | NEW |