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/gtk/first_run_bubble.h"
9 #include "base/i18n/rtl.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/first_run/first_run.h"
12 #include "chrome/browser/search_engines/util.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_finder.h"
15 #include "chrome/browser/ui/chrome_pages.h"
16 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
17 #include "grit/generated_resources.h"
18 #include "ui/base/gtk/gtk_hig_constants.h"
19 #include "ui/base/l10n/l10n_util.h"
23 // Markup for the text of the Omnibox search label
24 const char kSearchLabelMarkup
[] = "<big><b>%s</b></big>";
29 void FirstRunBubble::Show(Browser
* browser
,
31 const gfx::Rect
& rect
) {
32 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_SHOWN
);
34 new FirstRunBubble(browser
, anchor
, rect
);
37 void FirstRunBubble::BubbleClosing(BubbleGtk
* bubble
, bool closed_by_escape
) {
38 // TODO(port): Enable parent window
41 FirstRunBubble::FirstRunBubble(Browser
* browser
,
43 const gfx::Rect
& rect
)
46 GtkThemeService
* theme_service
= GtkThemeService::GetFrom(browser
->profile());
47 GtkWidget
* title
= theme_service
->BuildLabel(std::string(), ui::kGdkBlack
);
48 char* markup
= g_markup_printf_escaped(
50 l10n_util::GetStringFUTF8(IDS_FR_BUBBLE_TITLE
,
51 GetDefaultSearchEngineName(browser
->profile()))
53 gtk_label_set_markup(GTK_LABEL(title
), markup
);
56 GtkWidget
* change
= theme_service
->BuildChromeLinkButton(
57 l10n_util::GetStringUTF8(IDS_FR_BUBBLE_CHANGE
));
58 g_signal_connect(change
, "clicked", G_CALLBACK(&HandleChangeLinkThunk
), this);
60 GtkWidget
* subtext
= theme_service
->BuildLabel(
61 l10n_util::GetStringUTF8(IDS_FR_BUBBLE_SUBTEXT
), ui::kGdkBlack
);
63 GtkWidget
* top_line
= gtk_hbox_new(FALSE
, ui::kControlSpacing
);
64 gtk_box_pack_start(GTK_BOX(top_line
), title
, FALSE
, FALSE
, 0);
65 gtk_box_pack_start(GTK_BOX(top_line
), change
, FALSE
, FALSE
, 0);
67 GtkWidget
* content
= gtk_vbox_new(FALSE
, ui::kControlSpacing
);
68 gtk_container_set_border_width(GTK_CONTAINER(content
),
69 ui::kContentAreaBorder
);
70 g_signal_connect(content
, "destroy", G_CALLBACK(&HandleDestroyThunk
), this);
71 gtk_box_pack_start(GTK_BOX(content
), top_line
, FALSE
, FALSE
, 0);
72 gtk_box_pack_start(GTK_BOX(content
), subtext
, FALSE
, FALSE
, 0);
74 bubble_
= BubbleGtk::Show(anchor
,
77 BubbleGtk::ANCHOR_TOP_LEFT
,
78 BubbleGtk::MATCH_SYSTEM_THEME
|
79 BubbleGtk::POPUP_WINDOW
|
80 BubbleGtk::GRAB_INPUT
,
86 FirstRunBubble::~FirstRunBubble() {
89 void FirstRunBubble::HandleDestroy(GtkWidget
* sender
) {
93 void FirstRunBubble::HandleChangeLink(GtkWidget
* sender
) {
94 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_CHANGE_INVOKED
);
96 // Cache browser_ before closing the bubble, which deletes |this|.
97 Browser
* browser
= browser_
;
100 chrome::ShowSearchEngineSettings(browser
);