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/template_url_service_factory.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/chrome_pages.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "components/search_engines/util.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/views/controls/label.h"
16 #include "ui/views/controls/link.h"
17 #include "ui/views/layout/grid_layout.h"
18 #include "ui/views/layout/layout_constants.h"
19 #include "ui/views/widget/widget.h"
22 const int kAnchorVerticalInset
= 5;
23 const int kTopInset
= 1;
24 const int kLeftInset
= 2;
25 const int kBottomInset
= 7;
26 const int kRightInset
= 2;
30 FirstRunBubble
* FirstRunBubble::ShowBubble(Browser
* browser
,
31 views::View
* anchor_view
) {
32 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_SHOWN
);
34 FirstRunBubble
* delegate
= new FirstRunBubble(browser
, anchor_view
);
35 views::BubbleDelegateView::CreateBubble(delegate
)->Show();
39 void FirstRunBubble::Init() {
40 ui::ResourceBundle
& rb
= ui::ResourceBundle::GetSharedInstance();
41 const gfx::FontList
& original_font_list
=
42 rb
.GetFontList(ui::ResourceBundle::MediumFont
);
44 const base::string16 search_engine_name
= browser_
?
45 GetDefaultSearchEngineName(
46 TemplateURLServiceFactory::GetForProfile(browser_
->profile())) :
48 views::Label
* title
= new views::Label(
49 l10n_util::GetStringFUTF16(IDS_FR_BUBBLE_TITLE
, search_engine_name
),
50 original_font_list
.Derive(2, gfx::Font::BOLD
));
53 new views::Link(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_CHANGE
));
54 change
->SetFontList(original_font_list
);
55 change
->set_listener(this);
57 views::Label
* subtext
=
58 new views::Label(l10n_util::GetStringUTF16(IDS_FR_BUBBLE_SUBTEXT
),
61 views::GridLayout
* layout
= views::GridLayout::CreatePanel(this);
62 SetLayoutManager(layout
);
63 layout
->SetInsets(kTopInset
, kLeftInset
, kBottomInset
, kRightInset
);
65 views::ColumnSet
* columns
= layout
->AddColumnSet(0);
66 columns
->AddColumn(views::GridLayout::LEADING
, views::GridLayout::LEADING
, 0,
67 views::GridLayout::USE_PREF
, 0, 0);
68 columns
->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing
);
69 columns
->AddColumn(views::GridLayout::LEADING
, views::GridLayout::LEADING
, 0,
70 views::GridLayout::USE_PREF
, 0, 0);
71 columns
->AddPaddingColumn(1, 0);
73 layout
->StartRow(0, 0);
74 layout
->AddView(title
);
75 layout
->AddView(change
);
76 layout
->StartRowWithPadding(0, 0, 0,
77 views::kRelatedControlSmallVerticalSpacing
);
78 layout
->AddView(subtext
, columns
->num_columns(), 1);
81 FirstRunBubble::FirstRunBubble(Browser
* browser
, views::View
* anchor_view
)
82 : views::BubbleDelegateView(anchor_view
, views::BubbleBorder::TOP_LEFT
),
84 // Compensate for built-in vertical padding in the anchor view's image.
85 set_anchor_view_insets(
86 gfx::Insets(kAnchorVerticalInset
, 0, kAnchorVerticalInset
, 0));
89 FirstRunBubble::~FirstRunBubble() {
92 void FirstRunBubble::LinkClicked(views::Link
* source
, int event_flags
) {
93 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_CHANGE_INVOKED
);
97 chrome::ShowSearchEngineSettings(browser_
);