| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/cocoa/autofill/down_arrow_popup_menu_cell.h" | 5 #include "chrome/browser/ui/cocoa/autofill/down_arrow_popup_menu_cell.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" | 9 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h" |
| 10 | 10 |
| 11 const int kSidePadding = 2.0; |
| 12 |
| 11 @implementation DownArrowPopupMenuCell | 13 @implementation DownArrowPopupMenuCell |
| 12 | 14 |
| 13 - (NSSize)imageSize { | 15 - (NSSize)imageSize { |
| 14 image_button_cell::ButtonState state = image_button_cell::kDefaultState; | 16 image_button_cell::ButtonState state = image_button_cell::kDefaultState; |
| 15 NSView* controlView = [self controlView]; | 17 NSView* controlView = [self controlView]; |
| 16 NSImage* image = [self imageForState:state view:controlView]; | 18 NSImage* image = [self imageForState:state view:controlView]; |
| 17 return [image size]; | 19 return [image size]; |
| 18 } | 20 } |
| 19 | 21 |
| 20 - (NSSize)cellSize { | 22 - (NSSize)cellSize { |
| 21 NSSize imageSize = [self imageSize]; | 23 NSSize imageSize = [self imageSize]; |
| 22 | 24 |
| 23 NSAttributedString* title = [self attributedTitle]; | 25 NSAttributedString* title = [self attributedTitle]; |
| 24 NSSize size = [title size]; | 26 NSSize size = [title size]; |
| 25 size.height = std::max(size.height, imageSize.height); | 27 size.height = std::max(size.height, imageSize.height); |
| 26 size.width += autofill::kButtonGap + imageSize.width; | 28 size.width += 2 * kSidePadding + autofill::kButtonGap + imageSize.width; |
| 27 | 29 |
| 28 return size; | 30 return size; |
| 29 } | 31 } |
| 30 | 32 |
| 31 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { | 33 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { |
| 32 NSRect imageRect, titleRect; | 34 NSRect imageRect, titleRect; |
| 35 NSRect contentRect = NSInsetRect(cellFrame, kSidePadding, 0); |
| 33 NSDivideRect( | 36 NSDivideRect( |
| 34 cellFrame, &imageRect, &titleRect, [self imageSize].width, NSMaxXEdge); | 37 contentRect, &imageRect, &titleRect, [self imageSize].width, NSMaxXEdge); |
| 35 [super drawWithFrame:imageRect inView:controlView]; | 38 [super drawImageWithFrame:imageRect inView:controlView]; |
| 36 | 39 |
| 37 NSAttributedString* title = [self attributedTitle]; | 40 NSAttributedString* title = [self attributedTitle]; |
| 38 if ([title length]) | 41 if ([title length]) |
| 39 [self drawTitle:title withFrame:titleRect inView:controlView]; | 42 [self drawTitle:title withFrame:titleRect inView:controlView]; |
| 43 |
| 44 // Only draw custom focus ring if the 10.7 focus ring APIs are not available. |
| 45 // TODO(groby): Remove once we build against the 10.7 SDK. |
| 46 if (![self respondsToSelector:@selector(drawFocusRingMaskWithFrame:inView:)]) |
| 47 [super drawFocusRingWithFrame:cellFrame inView:controlView]; |
| 40 } | 48 } |
| 41 | 49 |
| 42 @end | 50 @end |
| 43 | 51 |
| OLD | NEW |