OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "chrome/browser/ui/cocoa/autofill/autofill_pop_up_button.h" |
| 6 |
| 7 #include <ApplicationServices/ApplicationServices.h> |
| 8 |
| 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 11 |
| 12 @implementation AutofillPopUpButton |
| 13 |
| 14 + (Class)cellClass { |
| 15 return [AutofillPopUpCell class]; |
| 16 } |
| 17 |
| 18 - (BOOL)invalid { |
| 19 return [[self cell] invalid]; |
| 20 } |
| 21 |
| 22 - (void)setInvalid:(BOOL)invalid { |
| 23 [[self cell] setInvalid:invalid]; |
| 24 } |
| 25 |
| 26 - (NSString*)fieldValue { |
| 27 return [[self cell] fieldValue]; |
| 28 } |
| 29 |
| 30 - (void)setFieldValue:(NSString*)fieldValue { |
| 31 [[self cell] setFieldValue:fieldValue]; |
| 32 } |
| 33 |
| 34 @end |
| 35 |
| 36 |
| 37 @implementation AutofillPopUpCell |
| 38 |
| 39 @synthesize invalid = invalid_; |
| 40 |
| 41 // Draw a bezel that's highlighted. |
| 42 - (void)drawBezelWithFrame:(NSRect)frame inView:(NSView*)controlView { |
| 43 if (invalid_) { |
| 44 CGContextRef context = static_cast<CGContextRef>( |
| 45 [[NSGraphicsContext currentContext] graphicsPort]); |
| 46 |
| 47 // Create a highlight-shaded bezel in a transparency layer. |
| 48 CGContextBeginTransparencyLayerWithRect(context, NSRectToCGRect(frame), 0); |
| 49 // 1. Draw bezel. |
| 50 [super drawBezelWithFrame:frame inView:controlView]; |
| 51 |
| 52 // 2. Use that as stencil against solid color rect. |
| 53 [[NSColor redColor] set]; |
| 54 NSRectFillUsingOperation(frame, NSCompositeSourceAtop); |
| 55 |
| 56 // 3. Composite the solid color bezel and the actual bezel. |
| 57 CGContextSetBlendMode(context, kCGBlendModePlusDarker); |
| 58 [super drawBezelWithFrame:frame inView:controlView]; |
| 59 CGContextEndTransparencyLayer(context); |
| 60 } else { |
| 61 [super drawBezelWithFrame:frame inView:controlView]; |
| 62 } |
| 63 } |
| 64 |
| 65 - (NSString*)fieldValue { |
| 66 return [self titleOfSelectedItem]; |
| 67 } |
| 68 |
| 69 - (void)setFieldValue:(NSString*)fieldValue { |
| 70 [self selectItemWithTitle:fieldValue]; |
| 71 } |
| 72 |
| 73 @end |
OLD | NEW |