| 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/autocomplete_text_field_cell.h" | 5 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" |
| 6 | 6 |
| 7 #import "base/logging.h" | 7 #import "base/logging.h" |
| 8 #import "third_party/GTM/AppKit/GTMTheme.h" | 8 #import "third_party/GTM/AppKit/GTMTheme.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 184 |
| 185 if ([self showsFirstResponder]) { | 185 if ([self showsFirstResponder]) { |
| 186 [[[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.5] set]; | 186 [[[NSColor keyboardFocusIndicatorColor] colorWithAlphaComponent:0.5] set]; |
| 187 NSFrameRectWithWidthUsingOperation(NSInsetRect(frame, 0, 0), 2, | 187 NSFrameRectWithWidthUsingOperation(NSInsetRect(frame, 0, 0), 2, |
| 188 NSCompositeSourceOver); | 188 NSCompositeSourceOver); |
| 189 } | 189 } |
| 190 | 190 |
| 191 [self drawInteriorWithFrame:cellFrame inView:controlView]; | 191 [self drawInteriorWithFrame:cellFrame inView:controlView]; |
| 192 } | 192 } |
| 193 | 193 |
| 194 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { |
| 195 return NSInsetRect(cellFrame, 0, kBaselineAdjust); |
| 196 } |
| 197 |
| 194 - (NSRect)textFrameForFrame:(NSRect)cellFrame { | 198 - (NSRect)textFrameForFrame:(NSRect)cellFrame { |
| 195 NSRect textFrame(cellFrame); | 199 NSRect textFrame([self textCursorFrameForFrame:cellFrame]); |
| 196 | 200 |
| 197 if (hintString_) { | 201 if (hintString_) { |
| 198 DCHECK(!keywordString_); | 202 DCHECK(!keywordString_); |
| 199 const CGFloat hintWidth = kHintXOffset + ceil([hintString_ size].width); | 203 const CGFloat hintWidth = kHintXOffset + ceil([hintString_ size].width); |
| 200 | 204 |
| 201 // TODO(shess): This could be better. Show the hint until the | 205 // TODO(shess): This could be better. Show the hint until the |
| 202 // non-hint text bumps against it? | 206 // non-hint text bumps against it? |
| 203 if (hintWidth < NSWidth(cellFrame)) { | 207 if (hintWidth < NSWidth(cellFrame)) { |
| 204 textFrame.size.width -= hintWidth; | 208 textFrame.size.width -= hintWidth; |
| 205 } | 209 } |
| 206 } else if (keywordString_) { | 210 } else if (keywordString_) { |
| 207 DCHECK(!hintString_); | 211 DCHECK(!hintString_); |
| 208 const CGFloat keywordWidth = kKeywordXOffset + | 212 const CGFloat keywordWidth = kKeywordXOffset + |
| 209 ceil([keywordString_ size].width) + 2 * kKeywordTokenInset; | 213 ceil([keywordString_ size].width) + 2 * kKeywordTokenInset; |
| 210 | 214 |
| 211 // TODO(shess): This could be better. There's support for a | 215 // TODO(shess): This could be better. There's support for a |
| 212 // "short" version of the keyword string, work that in in a | 216 // "short" version of the keyword string, work that in in a |
| 213 // follow-on pass. | 217 // follow-on pass. |
| 214 if (keywordWidth < NSWidth(cellFrame)) { | 218 if (keywordWidth < NSWidth(cellFrame)) { |
| 215 textFrame.origin.x += keywordWidth; | 219 textFrame.origin.x += keywordWidth; |
| 216 textFrame.size.width = NSMaxX(cellFrame) - NSMinX(textFrame); | 220 textFrame.size.width = NSMaxX(cellFrame) - NSMinX(textFrame); |
| 217 } | 221 } |
| 218 } | 222 } |
| 219 | 223 |
| 220 return NSInsetRect(textFrame, 0, kBaselineAdjust); | 224 return textFrame; |
| 221 } | 225 } |
| 222 | 226 |
| 223 - (void)drawHintWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 227 - (void)drawHintWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 224 DCHECK(hintString_); | 228 DCHECK(hintString_); |
| 225 | 229 |
| 226 NSRect textFrame = [self textFrameForFrame:cellFrame]; | 230 NSRect textFrame = [self textFrameForFrame:cellFrame]; |
| 227 NSRect infoFrame(NSMakeRect(NSMaxX(textFrame), | 231 NSRect infoFrame(NSMakeRect(NSMaxX(textFrame), |
| 228 cellFrame.origin.y + kHintYOffset, | 232 cellFrame.origin.y + kHintYOffset, |
| 229 ceil([hintString_ size].width), | 233 ceil([hintString_ size].width), |
| 230 cellFrame.size.height - kHintYOffset)); | 234 cellFrame.size.height - kHintYOffset)); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 delegate:(id)anObject | 297 delegate:(id)anObject |
| 294 start:(NSInteger)selStart | 298 start:(NSInteger)selStart |
| 295 length:(NSInteger)selLength { | 299 length:(NSInteger)selLength { |
| 296 [super selectWithFrame:[self textFrameForFrame:cellFrame] | 300 [super selectWithFrame:[self textFrameForFrame:cellFrame] |
| 297 inView:controlView editor:textObj | 301 inView:controlView editor:textObj |
| 298 delegate:anObject | 302 delegate:anObject |
| 299 start:selStart | 303 start:selStart |
| 300 length:selLength]; | 304 length:selLength]; |
| 301 } | 305 } |
| 302 | 306 |
| 307 - (void)resetCursorRect:(NSRect)cellFrame inView:(NSView *)controlView { |
| 308 [super resetCursorRect:[self textCursorFrameForFrame:cellFrame] |
| 309 inView:controlView]; |
| 310 } |
| 311 |
| 303 @end | 312 @end |
| OLD | NEW |