| 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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 return textFrame; | 247 return textFrame; |
| 248 } | 248 } |
| 249 | 249 |
| 250 // For NSTextFieldCell this is the area within the borders. For our | 250 // For NSTextFieldCell this is the area within the borders. For our |
| 251 // purposes, we count the info decorations as being part of the | 251 // purposes, we count the info decorations as being part of the |
| 252 // border. | 252 // border. |
| 253 - (NSRect)drawingRectForBounds:(NSRect)theRect { | 253 - (NSRect)drawingRectForBounds:(NSRect)theRect { |
| 254 return [super drawingRectForBounds:[self textFrameForFrame:theRect]]; | 254 return [super drawingRectForBounds:[self textFrameForFrame:theRect]]; |
| 255 } | 255 } |
| 256 | 256 |
| 257 - (NSRect)hintImageFrameForFrame:(NSRect)cellFrame { |
| 258 // We'll draw the entire image |
| 259 const NSSize imageRect([hintIcon_ size]); |
| 260 |
| 261 // Move the rect that we're drawing into to the far right |
| 262 cellFrame.origin.x += cellFrame.size.width - imageRect.width; |
| 263 // Add back the padding |
| 264 cellFrame.origin.x -= kHintIconHorizontalPad; |
| 265 |
| 266 // Center the image vertically in the frame |
| 267 cellFrame.origin.y += |
| 268 floor((cellFrame.size.height - imageRect.height) / 2); |
| 269 |
| 270 // Set the drawing size to the image size |
| 271 cellFrame.size = imageRect; |
| 272 |
| 273 return cellFrame; |
| 274 } |
| 275 |
| 257 - (void)drawHintWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 276 - (void)drawHintWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 258 DCHECK(hintString_); | 277 DCHECK(hintString_); |
| 259 | 278 |
| 260 NSRect textFrame = [self textFrameForFrame:cellFrame]; | 279 NSRect textFrame = [self textFrameForFrame:cellFrame]; |
| 261 NSRect infoFrame(NSMakeRect(NSMaxX(textFrame), | 280 NSRect infoFrame(NSMakeRect(NSMaxX(textFrame), |
| 262 cellFrame.origin.y + kHintYOffset, | 281 cellFrame.origin.y + kHintYOffset, |
| 263 ceil([hintString_ size].width), | 282 ceil([hintString_ size].width), |
| 264 cellFrame.size.height - kHintYOffset)); | 283 cellFrame.size.height - kHintYOffset)); |
| 265 [hintString_.get() drawInRect:infoFrame]; | 284 [hintString_.get() drawInRect:infoFrame]; |
| 266 } | 285 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 289 [path setLineWidth:1.0]; | 308 [path setLineWidth:1.0]; |
| 290 [path stroke]; | 309 [path stroke]; |
| 291 | 310 |
| 292 // Draw text w/in the rectangle. | 311 // Draw text w/in the rectangle. |
| 293 infoFrame.origin.x += 4.0; | 312 infoFrame.origin.x += 4.0; |
| 294 infoFrame.origin.y += 1.0; | 313 infoFrame.origin.y += 1.0; |
| 295 [keywordString_.get() drawInRect:infoFrame]; | 314 [keywordString_.get() drawInRect:infoFrame]; |
| 296 } | 315 } |
| 297 | 316 |
| 298 - (void)drawHintIconWithFrame:(NSRect)cellFrame | 317 - (void)drawHintIconWithFrame:(NSRect)cellFrame |
| 299 inView:(NSView*)controlView { | 318 inView:(NSView*)controlView { |
| 300 // We'll draw the entire image | 319 // We'll draw the entire image |
| 301 NSRect imageRect = NSZeroRect; | 320 NSRect imageRect = NSZeroRect; |
| 302 imageRect.size = [hintIcon_ size]; | 321 imageRect.size = [hintIcon_ size]; |
| 303 | 322 const NSRect hintFrame([self hintImageFrameForFrame:cellFrame]); |
| 304 // Move the rect that we're drawing into to the far right | |
| 305 cellFrame.origin.x += cellFrame.size.width - imageRect.size.width; | |
| 306 // Add back the padding | |
| 307 cellFrame.origin.x -= kHintIconHorizontalPad; | |
| 308 | |
| 309 // Center the image vertically in the frame | |
| 310 cellFrame.origin.y += | |
| 311 floor((cellFrame.size.height - imageRect.size.height) / 2); | |
| 312 | |
| 313 // Set the drawing size to the image size | |
| 314 cellFrame.size = imageRect.size; | |
| 315 | 323 |
| 316 [hintIcon_ setFlipped:[controlView isFlipped]]; | 324 [hintIcon_ setFlipped:[controlView isFlipped]]; |
| 317 [hintIcon_ drawInRect:cellFrame | 325 [hintIcon_ drawInRect:hintFrame |
| 318 fromRect:imageRect | 326 fromRect:imageRect |
| 319 operation:NSCompositeSourceOver | 327 operation:NSCompositeSourceOver |
| 320 fraction:1.0]; | 328 fraction:1.0]; |
| 321 } | 329 } |
| 322 | 330 |
| 323 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 331 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 324 if (hintString_) { | 332 if (hintString_) { |
| 325 [self drawHintWithFrame:cellFrame inView:controlView]; | 333 [self drawHintWithFrame:cellFrame inView:controlView]; |
| 326 } else if (keywordString_) { | 334 } else if (keywordString_) { |
| 327 [self drawKeywordWithFrame:cellFrame inView:controlView]; | 335 [self drawKeywordWithFrame:cellFrame inView:controlView]; |
| 328 } else if (hintIcon_) { | 336 } else if (hintIcon_) { |
| 329 [self drawHintIconWithFrame:cellFrame inView:controlView]; | 337 [self drawHintIconWithFrame:cellFrame inView:controlView]; |
| 330 } | 338 } |
| 331 | 339 |
| 332 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 340 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
| 333 } | 341 } |
| 334 | 342 |
| 335 - (void)resetCursorRect:(NSRect)cellFrame inView:(NSView *)controlView { | 343 - (void)resetCursorRect:(NSRect)cellFrame inView:(NSView *)controlView { |
| 336 [super resetCursorRect:[self textCursorFrameForFrame:cellFrame] | 344 [super resetCursorRect:[self textCursorFrameForFrame:cellFrame] |
| 337 inView:controlView]; | 345 inView:controlView]; |
| 338 } | 346 } |
| 339 | 347 |
| 340 @end | 348 @end |
| OLD | NEW |