| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/styled_text_field_cell.h" | 5 #import "chrome/browser/ui/cocoa/styled_text_field_cell.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/themes/theme_properties.h" | 8 #include "chrome/browser/themes/theme_properties.h" |
| 9 #include "chrome/browser/themes/theme_service.h" | 9 #include "chrome/browser/themes/theme_service.h" |
| 10 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 10 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
| 11 #import "chrome/browser/ui/cocoa/themed_window.h" | 11 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 12 #include "grit/theme_resources.h" | 12 #include "grit/theme_resources.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/gfx/font.h" | 14 #include "ui/gfx/font.h" |
| 15 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 15 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 16 | 16 |
| 17 @implementation StyledTextFieldCell | 17 @implementation StyledTextFieldCell |
| 18 | 18 |
| 19 - (CGFloat)baselineAdjust { | 19 - (CGFloat)topTextFrameOffset { |
| 20 return 0.0; | 20 return 0.0; |
| 21 } | 21 } |
| 22 | 22 |
| 23 - (CGFloat)bottomTextFrameOffset { |
| 24 return 0.0; |
| 25 } |
| 26 |
| 23 - (CGFloat)cornerRadius { | 27 - (CGFloat)cornerRadius { |
| 24 return 0.0; | 28 return 0.0; |
| 25 } | 29 } |
| 26 | 30 |
| 27 - (rect_path_utils::RoundedCornerFlags)roundedCornerFlags { | 31 - (rect_path_utils::RoundedCornerFlags)roundedCornerFlags { |
| 28 return rect_path_utils::RoundedCornerAll; | 32 return rect_path_utils::RoundedCornerAll; |
| 29 } | 33 } |
| 30 | 34 |
| 31 - (BOOL)shouldDrawBezel { | 35 - (BOOL)shouldDrawBezel { |
| 32 return NO; | 36 return NO; |
| 33 } | 37 } |
| 34 | 38 |
| 39 - (NSRect)textFrameForFrameInternal:(NSRect)cellFrame { |
| 40 CGFloat topOffset = [self topTextFrameOffset]; |
| 41 NSRect textFrame = cellFrame; |
| 42 textFrame.origin.y += topOffset; |
| 43 textFrame.size.height -= topOffset + [self bottomTextFrameOffset]; |
| 44 return textFrame; |
| 45 } |
| 46 |
| 35 // Returns the same value as textCursorFrameForFrame, but does not call it | 47 // Returns the same value as textCursorFrameForFrame, but does not call it |
| 36 // directly to avoid potential infinite loops. | 48 // directly to avoid potential infinite loops. |
| 37 - (NSRect)textFrameForFrame:(NSRect)cellFrame { | 49 - (NSRect)textFrameForFrame:(NSRect)cellFrame { |
| 38 return NSInsetRect(cellFrame, 0, [self baselineAdjust]); | 50 return [self textFrameForFrameInternal:cellFrame]; |
| 39 } | 51 } |
| 40 | 52 |
| 41 // Returns the same value as textFrameForFrame, but does not call it directly to | 53 // Returns the same value as textFrameForFrame, but does not call it directly to |
| 42 // avoid potential infinite loops. | 54 // avoid potential infinite loops. |
| 43 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { | 55 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { |
| 44 return NSInsetRect(cellFrame, 0, [self baselineAdjust]); | 56 return [self textFrameForFrameInternal:cellFrame]; |
| 45 } | 57 } |
| 46 | 58 |
| 47 // Override to show the I-beam cursor only in the area given by | 59 // Override to show the I-beam cursor only in the area given by |
| 48 // |textCursorFrameForFrame:|. | 60 // |textCursorFrameForFrame:|. |
| 49 - (void)resetCursorRect:(NSRect)cellFrame inView:(NSView *)controlView { | 61 - (void)resetCursorRect:(NSRect)cellFrame inView:(NSView *)controlView { |
| 50 [super resetCursorRect:[self textCursorFrameForFrame:cellFrame] | 62 [super resetCursorRect:[self textCursorFrameForFrame:cellFrame] |
| 51 inView:controlView]; | 63 inView:controlView]; |
| 52 } | 64 } |
| 53 | 65 |
| 54 // For NSTextFieldCell this is the area within the borders. For our | 66 // For NSTextFieldCell this is the area within the borders. For our |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // Draw the focus ring if needed. | 163 // Draw the focus ring if needed. |
| 152 if ([self showsFirstResponder]) { | 164 if ([self showsFirstResponder]) { |
| 153 NSColor* color = [[NSColor keyboardFocusIndicatorColor] | 165 NSColor* color = [[NSColor keyboardFocusIndicatorColor] |
| 154 colorWithAlphaComponent:0.5 / lineWidth]; | 166 colorWithAlphaComponent:0.5 / lineWidth]; |
| 155 rect_path_utils::FrameRectWithInset(roundedCornerFlags, frame, 0.0, 0.0, | 167 rect_path_utils::FrameRectWithInset(roundedCornerFlags, frame, 0.0, 0.0, |
| 156 radius, lineWidth * 2, color); | 168 radius, lineWidth * 2, color); |
| 157 } | 169 } |
| 158 } | 170 } |
| 159 | 171 |
| 160 @end | 172 @end |
| OLD | NEW |