OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" |
| 6 #import "third_party/GTM/AppKit/GTMTheme.h" |
| 7 |
| 8 const NSInteger kBaselineOffset = 2; |
| 9 |
| 10 @implementation AutocompleteTextFieldCell |
| 11 |
| 12 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 13 [[NSColor colorWithCalibratedWhite:1.0 alpha:0.25] set]; |
| 14 NSFrameRectWithWidthUsingOperation(cellFrame, 1, NSCompositeSourceOver); |
| 15 |
| 16 NSRect frame = NSInsetRect(cellFrame, 0, 1); |
| 17 [[NSColor whiteColor] setFill]; |
| 18 NSRect innerFrame = NSInsetRect(frame, 1, 1); |
| 19 NSRectFill(innerFrame); |
| 20 |
| 21 NSRect shadowFrame, restFrame; |
| 22 NSDivideRect(innerFrame, &shadowFrame, &restFrame, 1, NSMinYEdge); |
| 23 |
| 24 BOOL isMainWindow = [[controlView window] isMainWindow]; |
| 25 GTMTheme *theme = [controlView gtm_theme]; |
| 26 NSColor* stroke = [theme strokeColorForStyle:GTMThemeStyleToolBarButton |
| 27 state:isMainWindow]; |
| 28 [stroke set]; |
| 29 NSFrameRectWithWidthUsingOperation(frame, 1.0, NSCompositeSourceOver); |
| 30 |
| 31 // Draw the shadow. |
| 32 [[NSColor colorWithCalibratedWhite:0.0 alpha:0.05] setFill]; |
| 33 NSRectFillUsingOperation(shadowFrame, NSCompositeSourceOver); |
| 34 |
| 35 if ([self showsFirstResponder]) { |
| 36 [[[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.5] set]; |
| 37 NSFrameRectWithWidthUsingOperation(NSInsetRect(frame, 0, 0), 2, |
| 38 NSCompositeSourceOver); |
| 39 } |
| 40 |
| 41 [self drawInteriorWithFrame:cellFrame |
| 42 inView:controlView]; |
| 43 |
| 44 } |
| 45 |
| 46 - (void)drawInteriorWithFrame:(NSRect)cellFrame |
| 47 inView:(NSView*)controlView { |
| 48 [super drawInteriorWithFrame:NSInsetRect(cellFrame, 0, kBaselineOffset) |
| 49 inView:controlView]; |
| 50 } |
| 51 |
| 52 // Override these methods so that the field editor shows up in the right place |
| 53 - (void)editWithFrame:(NSRect)cellFrame |
| 54 inView:(NSView*)controlView |
| 55 editor:(NSText*)textObj |
| 56 delegate:(id)anObject |
| 57 event:(NSEvent*)theEvent { |
| 58 [super editWithFrame:NSInsetRect(cellFrame, 0, kBaselineOffset) |
| 59 inView:controlView |
| 60 editor:textObj |
| 61 delegate:anObject |
| 62 event:theEvent]; |
| 63 } |
| 64 |
| 65 |
| 66 // Override these methods so that the field editor shows up in the right place |
| 67 - (void)selectWithFrame:(NSRect)cellFrame |
| 68 inView:(NSView*)controlView |
| 69 editor:(NSText*)textObj |
| 70 delegate:(id)anObject |
| 71 start:(NSInteger)selStart |
| 72 length:(NSInteger)selLength { |
| 73 [super selectWithFrame:NSInsetRect(cellFrame, 0, kBaselineOffset) |
| 74 inView:controlView editor:textObj |
| 75 delegate:anObject |
| 76 start:selStart |
| 77 length:selLength]; |
| 78 } |
| 79 |
| 80 @end |
OLD | NEW |