[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / ui / views / first_run_bubble.cc
blobe1541290fa813e011f0e138499e3f1554bb75185
1 // Copyright (c) 2012 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/views/first_run_bubble.h"
7 #include "chrome/browser/first_run/first_run.h"
8 #include "chrome/browser/search_engines/util.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/chrome_pages.h"
11 #include "grit/generated_resources.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/views/controls/label.h"
15 #include "ui/views/controls/link.h"
16 #include "ui/views/layout/grid_layout.h"
17 #include "ui/views/layout/layout_constants.h"
18 #include "ui/views/widget/widget.h"
20 namespace {
21 const int kAnchorVerticalInset = 5;
22 const int kTopInset = 1;
23 const int kLeftInset = 2;
24 const int kBottomInset = 7;
25 const int kRightInset = 2;
26 } // namespace
28 // static
29 FirstRunBubble* FirstRunBubble::ShowBubble(Browser* browser,
30 views::View* anchor_view) {
31 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_SHOWN);
33 FirstRunBubble* delegate = new FirstRunBubble(browser, anchor_view);
34 views::BubbleDelegateView::CreateBubble(delegate)->Show();
35 return delegate;
38 void FirstRunBubble::Init() {
39 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
40 const gfx::FontList& original_font_list =
41 rb.GetFontList(ui::ResourceBundle::MediumFont);
43 views::Label* title = new views::Label(
44 l10n_util::GetStringFUTF16(
45 IDS_FR_BUBBLE_TITLE,
46 browser_ ? GetDefaultSearchEngineName(browser_->profile())
47 : base::string16()),
48 original_font_list.Derive(2, gfx::Font::BOLD));
50 views::Link* change =
51 new views::Link(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_CHANGE));
52 change->SetFontList(original_font_list);
53 change->set_listener(this);
55 views::Label* subtext =
56 new views::Label(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT),
57 original_font_list);
59 views::GridLayout* layout = views::GridLayout::CreatePanel(this);
60 SetLayoutManager(layout);
61 layout->SetInsets(kTopInset, kLeftInset, kBottomInset, kRightInset);
63 views::ColumnSet* columns = layout->AddColumnSet(0);
64 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0,
65 views::GridLayout::USE_PREF, 0, 0);
66 columns->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
67 columns->AddColumn(views::GridLayout::LEADING, views::GridLayout::LEADING, 0,
68 views::GridLayout::USE_PREF, 0, 0);
69 columns->AddPaddingColumn(1, 0);
71 layout->StartRow(0, 0);
72 layout->AddView(title);
73 layout->AddView(change);
74 layout->StartRowWithPadding(0, 0, 0,
75 views::kRelatedControlSmallVerticalSpacing);
76 layout->AddView(subtext, columns->num_columns(), 1);
79 FirstRunBubble::FirstRunBubble(Browser* browser, views::View* anchor_view)
80 : views::BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
81 browser_(browser) {
82 // Compensate for built-in vertical padding in the anchor view's image.
83 set_anchor_view_insets(
84 gfx::Insets(kAnchorVerticalInset, 0, kAnchorVerticalInset, 0));
87 FirstRunBubble::~FirstRunBubble() {
90 void FirstRunBubble::LinkClicked(views::Link* source, int event_flags) {
91 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_CHANGE_INVOKED);
93 GetWidget()->Close();
94 if (browser_)
95 chrome::ShowSearchEngineSettings(browser_);