OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/ui/cocoa/autofill/autofill_textfield.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_textfield.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 9 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 const CGFloat kGap = 6.0; // gap between icon and text. | 13 const CGFloat kGap = 6.0; // gap between icon and text. |
14 | 14 |
15 } // namespace | 15 } // namespace |
16 | 16 |
17 @interface AutofillTextFieldCell (Internal) | 17 @interface AutofillTextFieldCell (Internal) |
18 | 18 |
19 - (NSRect)iconFrameForFrame:(NSRect)frame; | 19 - (NSRect)iconFrameForFrame:(NSRect)frame; |
20 - (NSRect)textFrameForFrame:(NSRect)frame; | 20 - (NSRect)textFrameForFrame:(NSRect)frame; |
21 | 21 |
22 @end | 22 @end |
23 | 23 |
24 @implementation AutofillTextField | 24 @implementation AutofillTextField |
25 | 25 |
26 + (Class)cellClass { | 26 + (Class)cellClass { |
27 return [AutofillTextFieldCell class]; | 27 return [AutofillTextFieldCell class]; |
28 } | 28 } |
29 | 29 |
| 30 - (BOOL)invalid { |
| 31 return [[self cell] invalid]; |
| 32 } |
| 33 |
| 34 - (void)setInvalid:(BOOL)invalid { |
| 35 [[self cell] setInvalid:invalid]; |
| 36 } |
| 37 |
| 38 - (NSString*)fieldValue { |
| 39 return [[self cell] fieldValue]; |
| 40 } |
| 41 |
| 42 - (void)setFieldValue:(NSString*)fieldValue { |
| 43 [[self cell] setFieldValue:fieldValue]; |
| 44 } |
| 45 |
30 @end | 46 @end |
31 | 47 |
32 @implementation AutofillTextFieldCell | 48 @implementation AutofillTextFieldCell |
33 | 49 |
34 @synthesize invalid = invalid_; | 50 @synthesize invalid = invalid_; |
35 | 51 |
36 - (NSImage*) icon{ | 52 - (NSImage*) icon{ |
37 return icon_; | 53 return icon_; |
38 } | 54 } |
39 | 55 |
40 - (void)setIcon:(NSImage*) icon { | 56 - (void)setIcon:(NSImage*) icon { |
41 icon_.reset([icon retain]); | 57 icon_.reset([icon retain]); |
42 } | 58 } |
43 | 59 |
| 60 - (NSString*)fieldValue { |
| 61 return [self stringValue]; |
| 62 } |
| 63 |
| 64 - (void)setFieldValue:(NSString*)fieldValue { |
| 65 [self setStringValue:fieldValue]; |
| 66 } |
| 67 |
44 - (NSRect)textFrameForFrame:(NSRect)frame { | 68 - (NSRect)textFrameForFrame:(NSRect)frame { |
45 if (icon_) { | 69 if (icon_) { |
46 NSRect textFrame, iconFrame; | 70 NSRect textFrame, iconFrame; |
47 NSDivideRect(frame, &iconFrame, &textFrame, | 71 NSDivideRect(frame, &iconFrame, &textFrame, |
48 kGap + [icon_ size].width, NSMaxXEdge); | 72 kGap + [icon_ size].width, NSMaxXEdge); |
49 return textFrame; | 73 return textFrame; |
50 } | 74 } |
51 return frame; | 75 return frame; |
52 } | 76 } |
53 | 77 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 NSPoint corner = NSMakePoint(NSMaxX(cellFrame), NSMinY(cellFrame)); | 156 NSPoint corner = NSMakePoint(NSMaxX(cellFrame), NSMinY(cellFrame)); |
133 [dog_ear moveToPoint:NSMakePoint(corner.x - kDogEarSize, corner.y)]; | 157 [dog_ear moveToPoint:NSMakePoint(corner.x - kDogEarSize, corner.y)]; |
134 [dog_ear lineToPoint:corner]; | 158 [dog_ear lineToPoint:corner]; |
135 [dog_ear lineToPoint:NSMakePoint(corner.x, corner.y + kDogEarSize)]; | 159 [dog_ear lineToPoint:NSMakePoint(corner.x, corner.y + kDogEarSize)]; |
136 [dog_ear closePath]; | 160 [dog_ear closePath]; |
137 [dog_ear fill]; | 161 [dog_ear fill]; |
138 } | 162 } |
139 } | 163 } |
140 | 164 |
141 @end | 165 @end |
OLD | NEW |