| 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_service.h" | 8 #include "chrome/browser/themes/theme_service.h" |
| 9 #import "chrome/browser/ui/cocoa/nsview_additions.h" | 9 #import "chrome/browser/ui/cocoa/nsview_additions.h" |
| 10 #import "chrome/browser/ui/cocoa/themed_window.h" | 10 #import "chrome/browser/ui/cocoa/themed_window.h" |
| 11 #include "grit/theme_resources.h" | 11 #include "grit/theme_resources.h" |
| 12 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.h" | 12 #import "third_party/GTM/AppKit/GTMNSBezierPath+RoundRect.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_state_mac.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 NSBezierPath* RectPathWithInset(StyledTextFieldCellRoundedFlags roundedFlags, | 19 NSBezierPath* RectPathWithInset(StyledTextFieldCellRoundedFlags roundedFlags, |
| 19 const NSRect frame, | 20 const NSRect frame, |
| 20 const CGFloat inset, | 21 const CGFloat inset, |
| 21 const CGFloat outerRadius) { | 22 const CGFloat outerRadius) { |
| 22 NSRect insetFrame = NSInsetRect(frame, inset, inset); | 23 NSRect insetFrame = NSInsetRect(frame, inset, inset); |
| 23 | 24 |
| 24 if (outerRadius > 0.0) { | 25 if (outerRadius > 0.0) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 const CGFloat lineWidth, | 62 const CGFloat lineWidth, |
| 62 NSColor* color) { | 63 NSColor* color) { |
| 63 const CGFloat finalInset = inset + (lineWidth / 2.0); | 64 const CGFloat finalInset = inset + (lineWidth / 2.0); |
| 64 NSBezierPath* path = | 65 NSBezierPath* path = |
| 65 RectPathWithInset(roundedFlags, frame, finalInset, outerRadius); | 66 RectPathWithInset(roundedFlags, frame, finalInset, outerRadius); |
| 66 [color setStroke]; | 67 [color setStroke]; |
| 67 [path setLineWidth:lineWidth]; | 68 [path setLineWidth:lineWidth]; |
| 68 [path stroke]; | 69 [path stroke]; |
| 69 } | 70 } |
| 70 | 71 |
| 71 // TODO(shess): Maybe we need a |cocoa_util.h|? | |
| 72 class ScopedSaveGraphicsState { | |
| 73 public: | |
| 74 ScopedSaveGraphicsState() | |
| 75 : context_([NSGraphicsContext currentContext]) { | |
| 76 [context_ saveGraphicsState]; | |
| 77 } | |
| 78 explicit ScopedSaveGraphicsState(NSGraphicsContext* context) | |
| 79 : context_(context) { | |
| 80 [context_ saveGraphicsState]; | |
| 81 } | |
| 82 ~ScopedSaveGraphicsState() { | |
| 83 [context_ restoreGraphicsState]; | |
| 84 } | |
| 85 | |
| 86 private: | |
| 87 NSGraphicsContext* context_; | |
| 88 }; | |
| 89 | |
| 90 } // namespace | 72 } // namespace |
| 91 | 73 |
| 92 @implementation StyledTextFieldCell | 74 @implementation StyledTextFieldCell |
| 93 | 75 |
| 94 - (CGFloat)baselineAdjust { | 76 - (CGFloat)baselineAdjust { |
| 95 return 0.0; | 77 return 0.0; |
| 96 } | 78 } |
| 97 | 79 |
| 98 - (CGFloat)cornerRadius { | 80 - (CGFloat)cornerRadius { |
| 99 return 0.0; | 81 return 0.0; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 // Fill interior with background color. | 164 // Fill interior with background color. |
| 183 FillRectWithInset(roundedFlags, frame, lineWidth, radius, | 165 FillRectWithInset(roundedFlags, frame, lineWidth, radius, |
| 184 [self backgroundColor]); | 166 [self backgroundColor]); |
| 185 | 167 |
| 186 // Draw the shadow. For the rounded-rect case, the shadow needs to | 168 // Draw the shadow. For the rounded-rect case, the shadow needs to |
| 187 // slightly turn in at the corners. |shadowFrame| is at the same | 169 // slightly turn in at the corners. |shadowFrame| is at the same |
| 188 // midline as the inner border line on the top and left, but at the | 170 // midline as the inner border line on the top and left, but at the |
| 189 // outer border line on the bottom and right. The clipping change | 171 // outer border line on the bottom and right. The clipping change |
| 190 // will clip the bottom and right edges (and corner). | 172 // will clip the bottom and right edges (and corner). |
| 191 { | 173 { |
| 192 ScopedSaveGraphicsState state; | 174 gfx::ScopedNSGraphicsContextState state; |
| 193 [RectPathWithInset(roundedFlags, frame, lineWidth, radius) addClip]; | 175 [RectPathWithInset(roundedFlags, frame, lineWidth, radius) addClip]; |
| 194 const NSRect shadowFrame = | 176 const NSRect shadowFrame = |
| 195 NSOffsetRect(frame, halfLineWidth, halfLineWidth); | 177 NSOffsetRect(frame, halfLineWidth, halfLineWidth); |
| 196 NSColor* shadowShade = [NSColor colorWithCalibratedWhite:0.0 alpha:0.05]; | 178 NSColor* shadowShade = [NSColor colorWithCalibratedWhite:0.0 alpha:0.05]; |
| 197 FrameRectWithInset(roundedFlags, shadowFrame, halfLineWidth, | 179 FrameRectWithInset(roundedFlags, shadowFrame, halfLineWidth, |
| 198 radius - halfLineWidth, lineWidth, shadowShade); | 180 radius - halfLineWidth, lineWidth, shadowShade); |
| 199 } | 181 } |
| 200 | 182 |
| 201 // Draw optional bezel below bottom stroke. | 183 // Draw optional bezel below bottom stroke. |
| 202 if ([self shouldDrawBezel] && themeProvider && | 184 if ([self shouldDrawBezel] && themeProvider && |
| (...skipping 14 matching lines...) Expand all Loading... |
| 217 if ([self showsFirstResponder]) { | 199 if ([self showsFirstResponder]) { |
| 218 NSColor* color = | 200 NSColor* color = |
| 219 [[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.5]; | 201 [[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.5]; |
| 220 FrameRectWithInset(roundedFlags, frame, 0.0, radius, lineWidth * 2, color); | 202 FrameRectWithInset(roundedFlags, frame, 0.0, radius, lineWidth * 2, color); |
| 221 } | 203 } |
| 222 | 204 |
| 223 [self drawInteriorWithFrame:cellFrame inView:controlView]; | 205 [self drawInteriorWithFrame:cellFrame inView:controlView]; |
| 224 } | 206 } |
| 225 | 207 |
| 226 @end | 208 @end |
| OLD | NEW |