1 // Copyright (c) 2011 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/fullscreen_exit_bubble_gtk.h" 6 7 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" 8 #include "chrome/browser/ui/gtk/gtk_floating_container.h" 9 #include "chrome/browser/ui/gtk/gtk_util.h" 10 #include "chrome/browser/ui/gtk/rounded_window.h" 11 #include "grit/app_strings.h" 12 #include "grit/generated_resources.h" 13 #include "ui/base/l10n/l10n_util.h" 14 15 namespace { 16 17 // Padding around the link text. 18 const int kPaddingPixels = 8; 19 20 // Time before the link slides away. This is a bit longer than the Windows 21 // timeout because we don't yet support reshowing when the mouse moves to the 22 // of the screen. 23 const int kInitialDelayMs = 3000; 24 25 // How long the slide up animation takes when hiding the bubble. 26 const int kSlideOutDurationMs = 700; 27 28 } 29 30 FullscreenExitBubbleGtk::FullscreenExitBubbleGtk( 31 GtkFloatingContainer* container) 32 : container_(container) { 33 InitWidgets(); 34 } 35 36 FullscreenExitBubbleGtk::~FullscreenExitBubbleGtk() { 37 } 38 39 void FullscreenExitBubbleGtk::InitWidgets() { 40 // The exit bubble is a gtk_chrome_link_button inside a gtk event box and gtk 41 // alignment (these provide the background color). This is then made rounded 42 // and put into a slide widget. 43 44 // The Windows code actually looks up the accelerator key in the accelerator 45 // table and then converts the key to a string (in a switch statement). 46 std::string exit_text_utf8("<span color=\"white\" size=\"large\">"); 47 exit_text_utf8.append(l10n_util::GetStringFUTF8( 48 IDS_EXIT_FULLSCREEN_MODE, l10n_util::GetStringUTF16(IDS_APP_F11_KEY))); 49 exit_text_utf8.append("</span>"); 50 GtkWidget* link = gtk_chrome_link_button_new_with_markup( 51 exit_text_utf8.c_str()); 52 gtk_chrome_link_button_set_use_gtk_theme(GTK_CHROME_LINK_BUTTON(link), 53 FALSE); 54 signals_.Connect(link, "clicked", G_CALLBACK(OnLinkClickedThunk), this); 55 56 GtkWidget* container = gtk_util::CreateGtkBorderBin( 57 link, >k_util::kGdkBlack, 58 kPaddingPixels, kPaddingPixels, kPaddingPixels, kPaddingPixels); 59 gtk_util::ActAsRoundedWindow(container, gtk_util::kGdkGreen, kPaddingPixels, 60 gtk_util::ROUNDED_BOTTOM_LEFT | gtk_util::ROUNDED_BOTTOM_RIGHT, 61 gtk_util::BORDER_NONE); 62 63 slide_widget_.reset(new SlideAnimatorGtk(container, 64 SlideAnimatorGtk::DOWN, kSlideOutDurationMs, false, false, NULL)); 65 gtk_widget_set_name(widget(), "exit-fullscreen-bubble"); 66 gtk_widget_show_all(container); 67 gtk_widget_show(widget()); 68 slide_widget_->OpenWithoutAnimation(); 69 70 // TODO(tc): Implement the more complex logic in the windows version for 71 // when to show/hide the exit bubble. 72 initial_delay_.Start(base::TimeDelta::FromMilliseconds(kInitialDelayMs), this, 73 &FullscreenExitBubbleGtk::Hide); 74 75 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(container_), 76 widget()); 77 signals_.Connect(container_, "set-floating-position", 78 G_CALLBACK(OnSetFloatingPositionThunk), this); 79 } 80 81 void FullscreenExitBubbleGtk::Hide() { 82 slide_widget_->Close(); 83 } 84 85 void FullscreenExitBubbleGtk::OnSetFloatingPosition( 86 GtkWidget* floating_container, 87 GtkAllocation* allocation) { 88 GtkRequisition bubble_size; 89 gtk_widget_size_request(widget(), &bubble_size); 90 91 // Position the bubble at the top center of the screen. 92 GValue value = { 0, }; 93 g_value_init(&value, G_TYPE_INT); 94 g_value_set_int(&value, (allocation->width - bubble_size.width) / 2); 95 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 96 widget(), "x", &value); 97 98 g_value_set_int(&value, 0); 99 gtk_container_child_set_property(GTK_CONTAINER(floating_container), 100 widget(), "y", &value); 101 g_value_unset(&value); 102 } 103 104 void FullscreenExitBubbleGtk::OnLinkClicked(GtkWidget* link) { 105 GtkWindow* window = GTK_WINDOW(gtk_widget_get_toplevel(widget())); 106 gtk_window_unfullscreen(window); 107 } 108