OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/gtk/fullscreen_exit_bubble_gtk.h" | 5 #include "chrome/browser/gtk/fullscreen_exit_bubble_gtk.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "chrome/browser/gtk/gtk_chrome_link_button.h" | 8 #include "chrome/browser/gtk/gtk_chrome_link_button.h" |
9 #include "chrome/browser/gtk/gtk_floating_container.h" | 9 #include "chrome/browser/gtk/gtk_floating_container.h" |
10 #include "chrome/browser/gtk/gtk_util.h" | 10 #include "chrome/browser/gtk/gtk_util.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 } | 29 } |
30 | 30 |
31 FullscreenExitBubbleGtk::FullscreenExitBubbleGtk( | 31 FullscreenExitBubbleGtk::FullscreenExitBubbleGtk( |
32 GtkFloatingContainer* container) | 32 GtkFloatingContainer* container) |
33 : container_(container) { | 33 : container_(container) { |
34 InitWidgets(); | 34 InitWidgets(); |
35 } | 35 } |
36 | 36 |
37 FullscreenExitBubbleGtk::~FullscreenExitBubbleGtk() { | 37 FullscreenExitBubbleGtk::~FullscreenExitBubbleGtk() { |
38 // If the user exits the browser while in fullscreen mode, we may already | |
39 // have been removed from the widget hierarchy. | |
40 GtkWidget* parent = gtk_widget_get_parent(widget()); | |
41 if (parent) { | |
42 DCHECK_EQ(GTK_WIDGET(container_), parent); | |
43 g_signal_handlers_disconnect_by_func(parent, | |
44 reinterpret_cast<gpointer>(OnSetFloatingPosition), this); | |
45 gtk_container_remove(GTK_CONTAINER(parent), widget()); | |
46 } | |
47 } | 38 } |
48 | 39 |
49 void FullscreenExitBubbleGtk::InitWidgets() { | 40 void FullscreenExitBubbleGtk::InitWidgets() { |
50 // The exit bubble is a gtk_chrome_link_button inside a gtk event box and gtk | 41 // The exit bubble is a gtk_chrome_link_button inside a gtk event box and gtk |
51 // alignment (these provide the background color). This is then made rounded | 42 // alignment (these provide the background color). This is then made rounded |
52 // and put into a slide widget. | 43 // and put into a slide widget. |
53 | 44 |
54 // The Windows code actually looks up the accelerator key in the accelerator | 45 // The Windows code actually looks up the accelerator key in the accelerator |
55 // table and then converts the key to a string (in a switch statement). | 46 // table and then converts the key to a string (in a switch statement). |
56 std::string exit_text_utf8("<span color=\"white\" size=\"large\">"); | 47 std::string exit_text_utf8("<span color=\"white\" size=\"large\">"); |
57 exit_text_utf8.append(l10n_util::GetStringFUTF8( | 48 exit_text_utf8.append(l10n_util::GetStringFUTF8( |
58 IDS_EXIT_FULLSCREEN_MODE, l10n_util::GetStringUTF16(IDS_APP_F11_KEY))); | 49 IDS_EXIT_FULLSCREEN_MODE, l10n_util::GetStringUTF16(IDS_APP_F11_KEY))); |
59 exit_text_utf8.append("</span>"); | 50 exit_text_utf8.append("</span>"); |
60 GtkWidget* link = gtk_chrome_link_button_new_with_markup( | 51 GtkWidget* link = gtk_chrome_link_button_new_with_markup( |
61 exit_text_utf8.c_str()); | 52 exit_text_utf8.c_str()); |
62 gtk_chrome_link_button_set_use_gtk_theme(GTK_CHROME_LINK_BUTTON(link), | 53 gtk_chrome_link_button_set_use_gtk_theme(GTK_CHROME_LINK_BUTTON(link), |
63 FALSE); | 54 FALSE); |
64 g_signal_connect(link, "clicked", G_CALLBACK(OnLinkClicked), this); | 55 signals_.Connect(link, "clicked", G_CALLBACK(OnLinkClickedThunk), this); |
65 | 56 |
66 GtkWidget* container = gtk_util::CreateGtkBorderBin(link, &gfx::kGdkBlack, | 57 GtkWidget* container = gtk_util::CreateGtkBorderBin(link, &gfx::kGdkBlack, |
67 kPaddingPixels, kPaddingPixels, kPaddingPixels, kPaddingPixels); | 58 kPaddingPixels, kPaddingPixels, kPaddingPixels, kPaddingPixels); |
68 gtk_util::ActAsRoundedWindow(container, gfx::kGdkGreen, kPaddingPixels, | 59 gtk_util::ActAsRoundedWindow(container, gfx::kGdkGreen, kPaddingPixels, |
69 gtk_util::ROUNDED_BOTTOM_LEFT | gtk_util::ROUNDED_BOTTOM_RIGHT, | 60 gtk_util::ROUNDED_BOTTOM_LEFT | gtk_util::ROUNDED_BOTTOM_RIGHT, |
70 gtk_util::BORDER_NONE); | 61 gtk_util::BORDER_NONE); |
71 | 62 |
72 slide_widget_.reset(new SlideAnimatorGtk(container, | 63 slide_widget_.reset(new SlideAnimatorGtk(container, |
73 SlideAnimatorGtk::DOWN, kSlideOutDurationMs, false, false, NULL)); | 64 SlideAnimatorGtk::DOWN, kSlideOutDurationMs, false, false, NULL)); |
74 gtk_widget_set_name(widget(), "exit-fullscreen-bubble"); | 65 gtk_widget_set_name(widget(), "exit-fullscreen-bubble"); |
75 gtk_widget_show_all(container); | 66 gtk_widget_show_all(container); |
76 gtk_widget_show(widget()); | 67 gtk_widget_show(widget()); |
77 slide_widget_->OpenWithoutAnimation(); | 68 slide_widget_->OpenWithoutAnimation(); |
78 | 69 |
79 // TODO(tc): Implement the more complex logic in the windows version for | 70 // TODO(tc): Implement the more complex logic in the windows version for |
80 // when to show/hide the exit bubble. | 71 // when to show/hide the exit bubble. |
81 initial_delay_.Start(base::TimeDelta::FromMilliseconds(kInitialDelayMs), this, | 72 initial_delay_.Start(base::TimeDelta::FromMilliseconds(kInitialDelayMs), this, |
82 &FullscreenExitBubbleGtk::Hide); | 73 &FullscreenExitBubbleGtk::Hide); |
83 | 74 |
84 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(container_), | 75 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(container_), |
85 widget()); | 76 widget()); |
86 g_signal_connect(container_, "set-floating-position", | 77 signals_.Connect(container_, "set-floating-position", |
87 G_CALLBACK(OnSetFloatingPosition), this); | 78 G_CALLBACK(OnSetFloatingPositionThunk), this); |
88 } | 79 } |
89 | 80 |
90 void FullscreenExitBubbleGtk::Hide() { | 81 void FullscreenExitBubbleGtk::Hide() { |
91 slide_widget_->Close(); | 82 slide_widget_->Close(); |
92 } | 83 } |
93 | 84 |
94 // static | |
95 void FullscreenExitBubbleGtk::OnSetFloatingPosition( | 85 void FullscreenExitBubbleGtk::OnSetFloatingPosition( |
96 GtkFloatingContainer* floating_container, GtkAllocation* allocation, | 86 GtkWidget* floating_container, |
97 FullscreenExitBubbleGtk* bubble) { | 87 GtkAllocation* allocation) { |
98 GtkRequisition bubble_size; | 88 GtkRequisition bubble_size; |
99 gtk_widget_size_request(bubble->widget(), &bubble_size); | 89 gtk_widget_size_request(widget(), &bubble_size); |
100 | 90 |
101 // Position the bubble at the top center of the screen. | 91 // Position the bubble at the top center of the screen. |
102 GValue value = { 0, }; | 92 GValue value = { 0, }; |
103 g_value_init(&value, G_TYPE_INT); | 93 g_value_init(&value, G_TYPE_INT); |
104 g_value_set_int(&value, (allocation->width - bubble_size.width) / 2); | 94 g_value_set_int(&value, (allocation->width - bubble_size.width) / 2); |
105 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 95 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
106 bubble->widget(), "x", &value); | 96 widget(), "x", &value); |
107 | 97 |
108 g_value_set_int(&value, 0); | 98 g_value_set_int(&value, 0); |
109 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 99 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
110 bubble->widget(), "y", &value); | 100 widget(), "y", &value); |
111 g_value_unset(&value); | 101 g_value_unset(&value); |
112 } | 102 } |
113 | 103 |
114 // static | 104 void FullscreenExitBubbleGtk::OnLinkClicked(GtkWidget* link) { |
115 void FullscreenExitBubbleGtk::OnLinkClicked(GtkWidget* link, | 105 GtkWindow* window = GTK_WINDOW(gtk_widget_get_toplevel(widget())); |
116 FullscreenExitBubbleGtk* bubble) { | |
117 GtkWindow* window = GTK_WINDOW(gtk_widget_get_toplevel( | |
118 bubble->widget())); | |
119 gtk_window_unfullscreen(window); | 106 gtk_window_unfullscreen(window); |
120 } | 107 } |
OLD | NEW |