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#include "chrome/browser/ui/cocoa/autofill/down_arrow_popup_menu_cell.h"
6
7#include <algorithm>
8
9#include "chrome/browser/ui/cocoa/autofill/autofill_dialog_constants.h"
10
11const int kSidePadding = 2.0;
12
13@implementation DownArrowPopupMenuCell
14
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];
20}
21
22- (NSSize)cellSize {
23  NSSize imageSize = [self imageSize];
24
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;
29
30  return size;
31}
32
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];
39
40  NSAttributedString* title = [self attributedTitle];
41  if ([title length])
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];
48}
49
50@end
51
52