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 #include "app/gfx/font.h" | 7 #include "app/gfx/font.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #import "third_party/GTM/AppKit/GTMTheme.h" | 10 #import "third_party/GTM/AppKit/GTMTheme.h" |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 NSRect imageRect = NSZeroRect; | 398 NSRect imageRect = NSZeroRect; |
399 NSImage* image = imageView->GetImage(); | 399 NSImage* image = imageView->GetImage(); |
400 image.size = [image size]; | 400 image.size = [image size]; |
401 [image setFlipped:[controlView isFlipped]]; | 401 [image setFlipped:[controlView isFlipped]]; |
402 [image drawInRect:imageFrame | 402 [image drawInRect:imageFrame |
403 fromRect:imageRect | 403 fromRect:imageRect |
404 operation:NSCompositeSourceOver | 404 operation:NSCompositeSourceOver |
405 fraction:1.0]; | 405 fraction:1.0]; |
406 } | 406 } |
407 | 407 |
| 408 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 409 [NSGraphicsContext saveGraphicsState]; |
| 410 |
| 411 GTMTheme* theme = [controlView gtm_theme]; |
| 412 |
| 413 NSRect drawFrame = NSInsetRect(cellFrame, 0.5, 1.5); |
| 414 // TODO(viettrungluu): It's hard to do pixel-perfect drawing in Cocoa 'cause |
| 415 // rounding kills you (obviously, the constants below should be 0.5, but then |
| 416 // it doesn't draw correctly). |
| 417 NSRect innerFrame = NSInsetRect(drawFrame, 0.5001, 0.5001); |
| 418 NSBezierPath* innerPath = [NSBezierPath bezierPathWithRect:drawFrame]; |
| 419 |
| 420 // Paint button background image if there is one (otherwise the border won't |
| 421 // look right). |
| 422 NSImage* backgroundImage = |
| 423 [theme backgroundImageForStyle:GTMThemeStyleToolBarButton state:YES]; |
| 424 if (backgroundImage) { |
| 425 NSColor* patternColor = [NSColor colorWithPatternImage:backgroundImage]; |
| 426 [patternColor set]; |
| 427 // Set the phase to match window. |
| 428 NSRect trueRect = [controlView convertRectToBase:cellFrame]; |
| 429 [[NSGraphicsContext currentContext] |
| 430 setPatternPhase:NSMakePoint(NSMinX(trueRect), NSMaxY(trueRect))]; |
| 431 [innerPath fill]; |
| 432 } |
| 433 |
| 434 // Draw the outer stroke (over the background). |
| 435 [[theme strokeColorForStyle:GTMThemeStyleToolBarButton state:YES] setStroke]; |
| 436 [innerPath setLineWidth:1]; |
| 437 [innerPath stroke]; |
| 438 |
| 439 // Fill the inside if we're told to. |
| 440 if ([self drawsBackground]) { |
| 441 [[self backgroundColor] setFill]; |
| 442 [NSBezierPath fillRect:innerFrame]; |
| 443 } |
| 444 |
| 445 [NSGraphicsContext restoreGraphicsState]; |
| 446 |
| 447 [self drawInteriorWithFrame:cellFrame inView:controlView]; |
| 448 } |
| 449 |
408 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 450 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
409 if (hintString_) { | 451 if (hintString_) { |
410 [self drawHintWithFrame:cellFrame inView:controlView]; | 452 [self drawHintWithFrame:cellFrame inView:controlView]; |
411 } else if (keywordString_) { | 453 } else if (keywordString_) { |
412 [self drawKeywordWithFrame:cellFrame inView:controlView]; | 454 [self drawKeywordWithFrame:cellFrame inView:controlView]; |
413 } else { | 455 } else { |
414 if (security_image_view_ && security_image_view_->IsVisible()) { | 456 if (security_image_view_ && security_image_view_->IsVisible()) { |
415 [self drawImageView:security_image_view_ | 457 [self drawImageView:security_image_view_ |
416 inFrame:[self securityImageFrameForFrame:cellFrame] | 458 inFrame:[self securityImageFrameForFrame:cellFrame] |
417 inView:controlView]; | 459 inView:controlView]; |
418 } | 460 } |
419 | 461 |
420 const size_t pageActionCount = [self pageActionCount]; | 462 const size_t pageActionCount = [self pageActionCount]; |
421 for (size_t i = 0; i < pageActionCount; ++i) { | 463 for (size_t i = 0; i < pageActionCount; ++i) { |
422 LocationBarViewMac::PageActionImageView* view = | 464 LocationBarViewMac::PageActionImageView* view = |
423 page_action_views_->ViewAt(i); | 465 page_action_views_->ViewAt(i); |
424 if (view && view->IsVisible()) { | 466 if (view && view->IsVisible()) { |
425 [self drawImageView:view | 467 [self drawImageView:view |
426 inFrame:[self pageActionFrameForIndex:i inFrame:cellFrame] | 468 inFrame:[self pageActionFrameForIndex:i inFrame:cellFrame] |
427 inView:controlView]; | 469 inView:controlView]; |
428 } | 470 } |
429 } | 471 } |
430 } | 472 } |
431 | 473 |
432 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 474 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
433 } | 475 } |
434 | 476 |
435 @end | 477 @end |
OLD | NEW |