diff options
author | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 00:57:40 +0000 |
---|---|---|
committer | rohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-06 00:57:40 +0000 |
commit | de1509c9e4b7322ef13b754acd4f500916b2e0f7 (patch) | |
tree | f35e47690f4ce382a18fa2e47493dfce8a6c0870 /chrome/browser/cocoa/styled_text_field_cell.mm | |
parent | 189cf275c82afe58c656066cc4137ce9e95ece48 (diff) | |
download | chromium_src-de1509c9e4b7322ef13b754acd4f500916b2e0f7.zip chromium_src-de1509c9e4b7322ef13b754acd4f500916b2e0f7.tar.gz chromium_src-de1509c9e4b7322ef13b754acd4f500916b2e0f7.tar.bz2 |
[Mac] Draw the results label correctly in the findbar.
Adds common base classes (StyledTextField and StyledTextFieldCell) for both the find bar and omnibox text fields.
BUG=http://crbug.com/19550
TEST=Findbar results label should not be overdrawn by find text.
TEST=Autocomplete drawing (keyword, hint, lock icon) should not be affected.
Review URL: http://codereview.chromium.org/319005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31186 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/styled_text_field_cell.mm')
-rw-r--r-- | chrome/browser/cocoa/styled_text_field_cell.mm | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/styled_text_field_cell.mm b/chrome/browser/cocoa/styled_text_field_cell.mm new file mode 100644 index 0000000..79b1adf --- /dev/null +++ b/chrome/browser/cocoa/styled_text_field_cell.mm @@ -0,0 +1,83 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "chrome/browser/cocoa/styled_text_field_cell.h" + +#include "app/gfx/font.h" +#include "app/resource_bundle.h" +#include "base/logging.h" +#import "third_party/GTM/AppKit/GTMTheme.h" + +@implementation StyledTextFieldCell + +- (CGFloat)baselineAdjust { + return 0.0; +} + +// Returns the same value as textCursorFrameForFrame, but does not call it +// directly to avoid potential infinite loops. +- (NSRect)textFrameForFrame:(NSRect)cellFrame { + return NSInsetRect(cellFrame, 0, [self baselineAdjust]); +} + +// Returns the same value as textFrameForFrame, but does not call it directly to +// avoid potential infinite loops. +- (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { + return NSInsetRect(cellFrame, 0, [self baselineAdjust]); +} + +// Override to show the I-beam cursor only in the area given by +// |textCursorFrameForFrame:|. +- (void)resetCursorRect:(NSRect)cellFrame inView:(NSView *)controlView { + [super resetCursorRect:[self textCursorFrameForFrame:cellFrame] + inView:controlView]; +} + +// For NSTextFieldCell this is the area within the borders. For our +// purposes, we count the info decorations as being part of the +// border. +- (NSRect)drawingRectForBounds:(NSRect)theRect { + return [super drawingRectForBounds:[self textFrameForFrame:theRect]]; +} + +// TODO(shess): This code is manually drawing the cell's border area, +// but otherwise the cell assumes -setBordered:YES for purposes of +// calculating things like the editing area. This is probably +// incorrect. I know that this affects -drawingRectForBounds:. +- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { + DCHECK([controlView isFlipped]); + [[NSColor colorWithCalibratedWhite:1.0 alpha:0.25] set]; + NSFrameRectWithWidthUsingOperation(cellFrame, 1, NSCompositeSourceOver); + + // TODO(shess): This inset is also reflected in ToolbarController + // -autocompletePopupPosition. + NSRect frame = NSInsetRect(cellFrame, 0, 1); + [[self backgroundColor] setFill]; + NSRect innerFrame = NSInsetRect(frame, 1, 1); + NSRectFill(innerFrame); + + NSRect shadowFrame, restFrame; + NSDivideRect(innerFrame, &shadowFrame, &restFrame, 1, NSMinYEdge); + + BOOL isMainWindow = [[controlView window] isMainWindow]; + GTMTheme *theme = [controlView gtm_theme]; + NSColor* stroke = [theme strokeColorForStyle:GTMThemeStyleToolBarButton + state:isMainWindow]; + [stroke set]; + NSFrameRectWithWidthUsingOperation(frame, 1.0, NSCompositeSourceOver); + + // Draw the shadow. + [[NSColor colorWithCalibratedWhite:0.0 alpha:0.05] setFill]; + NSRectFillUsingOperation(shadowFrame, NSCompositeSourceOver); + + if ([self showsFirstResponder]) { + [[[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.5] set]; + NSFrameRectWithWidthUsingOperation(NSInsetRect(frame, 0, 0), 2, + NSCompositeSourceOver); + } + + [self drawInteriorWithFrame:cellFrame inView:controlView]; +} + +@end |