- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / cocoa / find_bar / find_bar_text_field.mm
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
3 // found in the LICENSE file.
4
5 #import "chrome/browser/ui/cocoa/find_bar/find_bar_text_field.h"
6
7 #include "base/logging.h"
8 #include "base/mac/foundation_util.h"
9 #import "chrome/browser/ui/cocoa/find_bar/find_bar_text_field_cell.h"
10 #import "chrome/browser/ui/cocoa/view_id_util.h"
11
12 @implementation FindBarTextField
13
14 + (Class)cellClass {
15   return [FindBarTextFieldCell class];
16 }
17
18 - (void)awakeFromNib {
19   DCHECK([[self cell] isKindOfClass:[FindBarTextFieldCell class]]);
20
21   [self registerForDraggedTypes:
22           [NSArray arrayWithObjects:NSStringPboardType, nil]];
23 }
24
25 - (FindBarTextFieldCell*)findBarTextFieldCell {
26   DCHECK([[self cell] isKindOfClass:[FindBarTextFieldCell class]]);
27   return static_cast<FindBarTextFieldCell*>([self cell]);
28 }
29
30 - (ViewID)viewID {
31   return VIEW_ID_FIND_IN_PAGE_TEXT_FIELD;
32 }
33
34 - (NSDragOperation)draggingEntered:(id<NSDraggingInfo>)info {
35   // When a drag enters the text field, focus the field.  This will swap in the
36   // field editor, which will then handle the drag itself.
37   [[self window] makeFirstResponder:self];
38   return NSDragOperationNone;
39 }
40
41 // Disable default automated replacements, see <http://crbug.com/173405>.
42 - (void)textDidBeginEditing:(NSNotification*)aNotification {
43   // NSTextDidBeginEditingNotification is from NSText, but this only
44   // applies to NSTextView instances.
45   NSTextView* textView =
46       base::mac::ObjCCast<NSTextView>([aNotification object]);
47   NSTextCheckingTypes checkingTypes = [textView enabledTextCheckingTypes];
48   checkingTypes &= ~NSTextCheckingTypeReplacement;
49   checkingTypes &= ~NSTextCheckingTypeCorrection;
50   [textView setEnabledTextCheckingTypes:checkingTypes];
51 }
52
53 @end