| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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/gtk/fullscreen_exit_bubble_gtk.h" |
| 6 |
| 7 #include "app/gfx/gtk_util.h" |
| 8 #include "app/l10n_util.h" |
| 9 #include "chrome/browser/gtk/gtk_chrome_link_button.h" |
| 10 #include "chrome/browser/gtk/gtk_floating_container.h" |
| 11 #include "chrome/common/gtk_util.h" |
| 12 #include "grit/app_strings.h" |
| 13 #include "grit/generated_resources.h" |
| 14 |
| 15 namespace { |
| 16 |
| 17 // Padding around the link text. |
| 18 const int kPaddingPixels = 8; |
| 19 |
| 20 // Time before the link disappears or slides away. |
| 21 const int kInitialDelayMs = 3000; |
| 22 |
| 23 } |
| 24 |
| 25 FullscreenExitBubbleGtk::FullscreenExitBubbleGtk( |
| 26 GtkFloatingContainer* container) |
| 27 : container_(container) { |
| 28 InitWidgets(); |
| 29 } |
| 30 |
| 31 FullscreenExitBubbleGtk::~FullscreenExitBubbleGtk() { |
| 32 // If the user exits the browser while in fullscreen mode, we may already |
| 33 // have been removed from the widget hierarchy. |
| 34 GtkWidget* parent = gtk_widget_get_parent(alignment_.get()); |
| 35 if (parent) { |
| 36 g_signal_handlers_disconnect_by_func(parent, |
| 37 reinterpret_cast<gpointer>(OnSetFloatingPosition), this); |
| 38 gtk_container_remove(GTK_CONTAINER(parent), alignment_.get()); |
| 39 } |
| 40 alignment_.Destroy(); |
| 41 } |
| 42 |
| 43 void FullscreenExitBubbleGtk::InitWidgets() { |
| 44 // The exit bubble is a gtk_chrome_link_button inside a gtk event box and gtk |
| 45 // alignment. |
| 46 |
| 47 // The Windows code actually looks up the accelerator key in the accelerator |
| 48 // table and then converts the key to a string (in a switch statement). |
| 49 std::string exit_text_utf8("<span color=\"white\" size=\"large\">"); |
| 50 exit_text_utf8.append(l10n_util::GetStringFUTF8( |
| 51 IDS_EXIT_FULLSCREEN_MODE, l10n_util::GetStringUTF16(IDS_APP_F11_KEY))); |
| 52 exit_text_utf8.append("</span>"); |
| 53 GtkWidget* link = gtk_chrome_link_button_new_with_markup( |
| 54 exit_text_utf8.c_str()); |
| 55 gtk_chrome_link_button_set_use_gtk_theme(GTK_CHROME_LINK_BUTTON(link), |
| 56 FALSE); |
| 57 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkClicked), this); |
| 58 |
| 59 alignment_.Own(gtk_util::CreateGtkBorderBin(link, &gfx::kGdkBlack, |
| 60 kPaddingPixels, kPaddingPixels, kPaddingPixels, kPaddingPixels)); |
| 61 gtk_widget_set_name(alignment_.get(), "exit-fullscreen-bubble"); |
| 62 gtk_widget_show_all(alignment_.get()); |
| 63 |
| 64 // TODO(tc): Implement the more complex logic in the windows version for |
| 65 // when to show/hide the exit bubble. |
| 66 initial_delay_.Start(base::TimeDelta::FromMilliseconds(kInitialDelayMs), this, |
| 67 &FullscreenExitBubbleGtk::Hide); |
| 68 |
| 69 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(container_), |
| 70 alignment_.get()); |
| 71 g_signal_connect(container_, "set-floating-position", |
| 72 G_CALLBACK(OnSetFloatingPosition), this); |
| 73 } |
| 74 |
| 75 void FullscreenExitBubbleGtk::Hide() { |
| 76 // TODO(tc): Slide out animation. |
| 77 gtk_widget_hide(alignment_.get()); |
| 78 } |
| 79 |
| 80 // static |
| 81 void FullscreenExitBubbleGtk::OnSetFloatingPosition( |
| 82 GtkFloatingContainer* floating_container, GtkAllocation* allocation, |
| 83 FullscreenExitBubbleGtk* bubble) { |
| 84 GtkRequisition bubble_size; |
| 85 gtk_widget_size_request(bubble->alignment_.get(), &bubble_size); |
| 86 |
| 87 // Position the bubble at the top center of the screen. |
| 88 GValue value = { 0, }; |
| 89 g_value_init(&value, G_TYPE_INT); |
| 90 g_value_set_int(&value, (allocation->width - bubble_size.width) / 2); |
| 91 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 92 bubble->alignment_.get(), "x", &value); |
| 93 |
| 94 g_value_set_int(&value, 0); |
| 95 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 96 bubble->alignment_.get(), "y", &value); |
| 97 g_value_unset(&value); |
| 98 } |
| 99 |
| 100 // static |
| 101 void FullscreenExitBubbleGtk::OnLinkClicked(GtkWidget* link, |
| 102 FullscreenExitBubbleGtk* bubble) { |
| 103 GtkWindow* window = GTK_WINDOW(gtk_widget_get_toplevel( |
| 104 bubble->alignment_.get())); |
| 105 gtk_window_unfullscreen(window); |
| 106 } |
| OLD | NEW |