summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa/bubble_combobox.mm
blob: b093fcccded631f96a2f1e003c9273261ec0fe9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#import "chrome/browser/ui/cocoa/bubble_combobox.h"

#include "base/strings/sys_string_conversions.h"
#include "ui/base/models/combobox_model.h"

@implementation BubbleCombobox

- (id)initWithFrame:(NSRect)frame
          pullsDown:(BOOL)pullsDown
              model:(ui::ComboboxModel*)model {
  if ((self = [super initWithFrame:frame pullsDown:pullsDown])) {
    [self setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
    [self setBordered:YES];
    [[self cell] setControlSize:NSSmallControlSize];

    for (int i = 0; i < model->GetItemCount(); ++i) {
      if (model->IsItemSeparatorAt(i))
        [[self menu] addItem:[NSMenuItem separatorItem]];
      else
        [self addItemWithTitle:base::SysUTF16ToNSString(model->GetItemAt(i))];
    }

    [self selectItemAtIndex:model->GetDefaultIndex()];
  }
  return self;
}

@end