| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "chrome/browser/ui/gtk/first_run_bubble.h" | |
| 6 | |
| 7 #include <gtk/gtk.h> | |
| 8 | |
| 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" | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 // Markup for the text of the Omnibox search label | |
| 24 const char kSearchLabelMarkup[] = "<big><b>%s</b></big>"; | |
| 25 | |
| 26 } // namespace | |
| 27 | |
| 28 // static | |
| 29 void FirstRunBubble::Show(Browser* browser, | |
| 30 GtkWidget* anchor, | |
| 31 const gfx::Rect& rect) { | |
| 32 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_SHOWN); | |
| 33 | |
| 34 new FirstRunBubble(browser, anchor, rect); | |
| 35 } | |
| 36 | |
| 37 void FirstRunBubble::BubbleClosing(BubbleGtk* bubble, bool closed_by_escape) { | |
| 38 // TODO(port): Enable parent window | |
| 39 } | |
| 40 | |
| 41 FirstRunBubble::FirstRunBubble(Browser* browser, | |
| 42 GtkWidget* anchor, | |
| 43 const gfx::Rect& rect) | |
| 44 : browser_(browser), | |
| 45 bubble_(NULL) { | |
| 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( | |
| 49 kSearchLabelMarkup, | |
| 50 l10n_util::GetStringFUTF8(IDS_FR_BUBBLE_TITLE, | |
| 51 GetDefaultSearchEngineName(browser->profile())) | |
| 52 .c_str()); | |
| 53 gtk_label_set_markup(GTK_LABEL(title), markup); | |
| 54 g_free(markup); | |
| 55 | |
| 56 GtkWidget* change = theme_service->BuildChromeLinkButton( | |
| 57 l10n_util::GetStringUTF8(IDS_FR_BUBBLE_CHANGE)); | |
| 58 g_signal_connect(change, "clicked", G_CALLBACK(&HandleChangeLinkThunk), this); | |
| 59 | |
| 60 GtkWidget* subtext = theme_service->BuildLabel( | |
| 61 l10n_util::GetStringUTF8(IDS_FR_BUBBLE_SUBTEXT), ui::kGdkBlack); | |
| 62 | |
| 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); | |
| 66 | |
| 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); | |
| 73 | |
| 74 bubble_ = BubbleGtk::Show(anchor, | |
| 75 &rect, | |
| 76 content, | |
| 77 BubbleGtk::ANCHOR_TOP_LEFT, | |
| 78 BubbleGtk::MATCH_SYSTEM_THEME | | |
| 79 BubbleGtk::POPUP_WINDOW | | |
| 80 BubbleGtk::GRAB_INPUT, | |
| 81 theme_service, | |
| 82 this); | |
| 83 DCHECK(bubble_); | |
| 84 } | |
| 85 | |
| 86 FirstRunBubble::~FirstRunBubble() { | |
| 87 } | |
| 88 | |
| 89 void FirstRunBubble::HandleDestroy(GtkWidget* sender) { | |
| 90 delete this; | |
| 91 } | |
| 92 | |
| 93 void FirstRunBubble::HandleChangeLink(GtkWidget* sender) { | |
| 94 first_run::LogFirstRunMetric(first_run::FIRST_RUN_BUBBLE_CHANGE_INVOKED); | |
| 95 | |
| 96 // Cache browser_ before closing the bubble, which deletes |this|. | |
| 97 Browser* browser = browser_; | |
| 98 bubble_->Close(); | |
| 99 if (browser) | |
| 100 chrome::ShowSearchEngineSettings(browser); | |
| 101 } | |
| OLD | NEW |