Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / autofill / down_arrow_popup_menu_cell.mm
blob0c8b46b2af141a89e12f9e842f4e5ff39c8713c4
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.
5 #include "chrome/browser/ui/cocoa/autofill/down_arrow_popup_menu_cell.h"
7 #include <algorithm>
9 #include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h"
11 const int kSidePadding = 2.0;
13 @implementation DownArrowPopupMenuCell
15 - (NSSize)imageSize {
16   image_button_cell::ButtonState state = image_button_cell::kDefaultState;
17   NSView* controlView = [self controlView];
18   NSImage* image = [self imageForState:state view:controlView];
19   return [image size];
22 - (NSSize)cellSize {
23   NSSize imageSize = [self imageSize];
25   NSAttributedString* title = [self attributedTitle];
26   NSSize size = [title size];
27   size.height = std::max(size.height, imageSize.height);
28   size.width += 2 * kSidePadding + autofill::kButtonGap + imageSize.width;
30   return size;
33 - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView*)controlView {
34   NSRect imageRect, titleRect;
35   NSRect contentRect = NSInsetRect(cellFrame, kSidePadding, 0);
36   NSDivideRect(
37       contentRect, &imageRect, &titleRect, [self imageSize].width, NSMaxXEdge);
38   [super drawImageWithFrame:imageRect inView:controlView];
40   NSAttributedString* title = [self attributedTitle];
41   if ([title length])
42     [self drawTitle:title withFrame:titleRect inView:controlView];
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];
50 @end