| 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 | |
| 450 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 408 - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 451 if (hintString_) { | 409 if (hintString_) { |
| 452 [self drawHintWithFrame:cellFrame inView:controlView]; | 410 [self drawHintWithFrame:cellFrame inView:controlView]; |
| 453 } else if (keywordString_) { | 411 } else if (keywordString_) { |
| 454 [self drawKeywordWithFrame:cellFrame inView:controlView]; | 412 [self drawKeywordWithFrame:cellFrame inView:controlView]; |
| 455 } else { | 413 } else { |
| 456 if (security_image_view_ && security_image_view_->IsVisible()) { | 414 if (security_image_view_ && security_image_view_->IsVisible()) { |
| 457 [self drawImageView:security_image_view_ | 415 [self drawImageView:security_image_view_ |
| 458 inFrame:[self securityImageFrameForFrame:cellFrame] | 416 inFrame:[self securityImageFrameForFrame:cellFrame] |
| 459 inView:controlView]; | 417 inView:controlView]; |
| 460 } | 418 } |
| 461 | 419 |
| 462 const size_t pageActionCount = [self pageActionCount]; | 420 const size_t pageActionCount = [self pageActionCount]; |
| 463 for (size_t i = 0; i < pageActionCount; ++i) { | 421 for (size_t i = 0; i < pageActionCount; ++i) { |
| 464 LocationBarViewMac::PageActionImageView* view = | 422 LocationBarViewMac::PageActionImageView* view = |
| 465 page_action_views_->ViewAt(i); | 423 page_action_views_->ViewAt(i); |
| 466 if (view && view->IsVisible()) { | 424 if (view && view->IsVisible()) { |
| 467 [self drawImageView:view | 425 [self drawImageView:view |
| 468 inFrame:[self pageActionFrameForIndex:i inFrame:cellFrame] | 426 inFrame:[self pageActionFrameForIndex:i inFrame:cellFrame] |
| 469 inView:controlView]; | 427 inView:controlView]; |
| 470 } | 428 } |
| 471 } | 429 } |
| 472 } | 430 } |
| 473 | 431 |
| 474 [super drawInteriorWithFrame:cellFrame inView:controlView]; | 432 [super drawInteriorWithFrame:cellFrame inView:controlView]; |
| 475 } | 433 } |
| 476 | 434 |
| 477 @end | 435 @end |
| OLD | NEW |