| 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/styled_text_field_cell.h" | 5 #import "chrome/browser/cocoa/styled_text_field_cell.h" |
| 6 | 6 |
| 7 #include "app/gfx/font.h" | 7 #include "app/gfx/font.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #import "third_party/GTM/AppKit/GTMTheme.h" | 10 #import "third_party/GTM/AppKit/GTMTheme.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 - (NSRect)drawingRectForBounds:(NSRect)theRect { | 40 - (NSRect)drawingRectForBounds:(NSRect)theRect { |
| 41 return [super drawingRectForBounds:[self textFrameForFrame:theRect]]; | 41 return [super drawingRectForBounds:[self textFrameForFrame:theRect]]; |
| 42 } | 42 } |
| 43 | 43 |
| 44 // TODO(shess): This code is manually drawing the cell's border area, | 44 // TODO(shess): This code is manually drawing the cell's border area, |
| 45 // but otherwise the cell assumes -setBordered:YES for purposes of | 45 // but otherwise the cell assumes -setBordered:YES for purposes of |
| 46 // calculating things like the editing area. This is probably | 46 // calculating things like the editing area. This is probably |
| 47 // incorrect. I know that this affects -drawingRectForBounds:. | 47 // incorrect. I know that this affects -drawingRectForBounds:. |
| 48 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 48 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 49 DCHECK([controlView isFlipped]); | 49 DCHECK([controlView isFlipped]); |
| 50 [[NSColor colorWithCalibratedWhite:1.0 alpha:0.25] set]; | |
| 51 NSFrameRectWithWidthUsingOperation(cellFrame, 1, NSCompositeSourceOver); | |
| 52 | 50 |
| 53 // TODO(shess): This inset is also reflected in ToolbarController | 51 // TODO(shess): This inset is also reflected in ToolbarController |
| 54 // -autocompletePopupPosition. | 52 // -autocompletePopupPosition. |
| 55 NSRect frame = NSInsetRect(cellFrame, 0, 1); | 53 NSRect frame = NSInsetRect(cellFrame, 0, 1); |
| 54 NSRect midFrame = NSInsetRect(frame, 0.5, 0.5); |
| 55 NSRect innerFrame = NSInsetRect(frame, 1, 1); |
| 56 |
| 57 // Paint button background image if there is one (otherwise the border won't |
| 58 // look right). |
| 59 GTMTheme* theme = [controlView gtm_theme]; |
| 60 NSImage* backgroundImage = |
| 61 [theme backgroundImageForStyle:GTMThemeStyleToolBarButton state:YES]; |
| 62 if (backgroundImage) { |
| 63 NSColor* patternColor = [NSColor colorWithPatternImage:backgroundImage]; |
| 64 [patternColor set]; |
| 65 // Set the phase to match window. |
| 66 NSRect trueRect = [controlView convertRectToBase:cellFrame]; |
| 67 [[NSGraphicsContext currentContext] |
| 68 setPatternPhase:NSMakePoint(NSMinX(trueRect), NSMaxY(trueRect))]; |
| 69 NSRectFillUsingOperation(midFrame, NSCompositeCopy); |
| 70 } |
| 71 |
| 72 // Draw the outer stroke (over the background). |
| 73 BOOL active = [[controlView window] isMainWindow]; |
| 74 [[theme strokeColorForStyle:GTMThemeStyleToolBarButton state:active] set]; |
| 75 NSFrameRectWithWidthUsingOperation(frame, 1, NSCompositeSourceOver); |
| 76 |
| 77 // Draw the background for the interior. |
| 56 [[self backgroundColor] setFill]; | 78 [[self backgroundColor] setFill]; |
| 57 NSRect innerFrame = NSInsetRect(frame, 1, 1); | |
| 58 NSRectFill(innerFrame); | 79 NSRectFill(innerFrame); |
| 59 | 80 |
| 60 NSRect shadowFrame, restFrame; | 81 // Draw the shadow. |
| 61 NSDivideRect(innerFrame, &shadowFrame, &restFrame, 1, NSMinYEdge); | 82 NSRect topShadowFrame, leftShadowFrame, restFrame; |
| 83 NSDivideRect(innerFrame, &topShadowFrame, &restFrame, 1, NSMinYEdge); |
| 84 NSDivideRect(restFrame, &leftShadowFrame, &restFrame, 1, NSMinXEdge); |
| 85 [[NSColor colorWithCalibratedWhite:0.0 alpha:0.05] setFill]; |
| 86 NSRectFillUsingOperation(topShadowFrame, NSCompositeSourceOver); |
| 87 NSRectFillUsingOperation(leftShadowFrame, NSCompositeSourceOver); |
| 62 | 88 |
| 63 BOOL isMainWindow = [[controlView window] isMainWindow]; | 89 // Draw the focus ring if needed. |
| 64 GTMTheme *theme = [controlView gtm_theme]; | |
| 65 NSColor* stroke = [theme strokeColorForStyle:GTMThemeStyleToolBarButton | |
| 66 state:isMainWindow]; | |
| 67 [stroke set]; | |
| 68 NSFrameRectWithWidthUsingOperation(frame, 1.0, NSCompositeSourceOver); | |
| 69 | |
| 70 // Draw the shadow. | |
| 71 [[NSColor colorWithCalibratedWhite:0.0 alpha:0.05] setFill]; | |
| 72 NSRectFillUsingOperation(shadowFrame, NSCompositeSourceOver); | |
| 73 | |
| 74 if ([self showsFirstResponder]) { | 90 if ([self showsFirstResponder]) { |
| 75 [[[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.5] set]; | 91 [[[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.5] set]; |
| 76 NSFrameRectWithWidthUsingOperation(NSInsetRect(frame, 0, 0), 2, | 92 NSFrameRectWithWidthUsingOperation(NSInsetRect(frame, 0, 0), 2, |
| 77 NSCompositeSourceOver); | 93 NSCompositeSourceOver); |
| 78 } | 94 } |
| 79 | 95 |
| 80 [self drawInteriorWithFrame:cellFrame inView:controlView]; | 96 [self drawInteriorWithFrame:cellFrame inView:controlView]; |
| 81 } | 97 } |
| 82 | 98 |
| 83 @end | 99 @end |
| OLD | NEW |