| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/ui/gtk/fullscreen_exit_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 9 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
| 10 #include "chrome/browser/ui/gtk/gtk_util.h" | 10 #include "chrome/browser/ui/gtk/gtk_util.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 gtk_label_set_text(GTK_LABEL(message_label_), | 49 gtk_label_set_text(GTK_LABEL(message_label_), |
| 50 UTF16ToUTF8(GetCurrentMessageText()).c_str()); | 50 UTF16ToUTF8(GetCurrentMessageText()).c_str()); |
| 51 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { | 51 if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { |
| 52 gtk_widget_hide(link_); | 52 gtk_widget_hide(link_); |
| 53 gtk_widget_hide(instruction_label_); | 53 gtk_widget_hide(instruction_label_); |
| 54 gtk_widget_show(allow_button_); | 54 gtk_widget_show(allow_button_); |
| 55 gtk_button_set_label(GTK_BUTTON(deny_button_), | 55 gtk_button_set_label(GTK_BUTTON(deny_button_), |
| 56 UTF16ToUTF8(GetCurrentDenyButtonText()).c_str()); | 56 UTF16ToUTF8(GetCurrentDenyButtonText()).c_str()); |
| 57 gtk_widget_show(deny_button_); | 57 gtk_widget_show(deny_button_); |
| 58 } else { | 58 } else { |
| 59 bool link_visible = true; |
| 60 string16 accelerator; |
| 59 if (bubble_type == FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION) { | 61 if (bubble_type == FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION) { |
| 62 accelerator = l10n_util::GetStringUTF16(IDS_APP_F11_KEY); |
| 63 } else if (bubble_type == FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION) { |
| 64 accelerator = l10n_util::GetStringUTF16(IDS_APP_ESC_KEY); |
| 65 } else { |
| 66 link_visible = false; |
| 67 } |
| 68 if (link_visible) { |
| 69 std::string exit_link_text( |
| 70 l10n_util::GetStringUTF8(IDS_EXIT_FULLSCREEN_MODE) + " " + |
| 71 l10n_util::GetStringFUTF8(IDS_EXIT_FULLSCREEN_MODE_ACCELERATOR, |
| 72 accelerator)); |
| 73 gtk_chrome_link_button_set_label(GTK_CHROME_LINK_BUTTON(link_), |
| 74 exit_link_text.c_str()); |
| 60 gtk_widget_show(link_); | 75 gtk_widget_show(link_); |
| 61 gtk_widget_hide(instruction_label_); | 76 gtk_widget_hide(instruction_label_); |
| 62 } else { | 77 } else { |
| 63 gtk_widget_hide(link_); | 78 gtk_widget_hide(link_); |
| 64 gtk_widget_show(instruction_label_); | 79 gtk_widget_show(instruction_label_); |
| 65 } | 80 } |
| 66 gtk_widget_hide(allow_button_); | 81 gtk_widget_hide(allow_button_); |
| 67 gtk_widget_hide(deny_button_); | 82 gtk_widget_hide(deny_button_); |
| 68 } | 83 } |
| 69 | 84 |
| 70 Show(); | 85 Show(); |
| 71 StopWatchingMouse(); | 86 StopWatchingMouse(); |
| 72 StartWatchingMouseIfNecessary(); | 87 StartWatchingMouseIfNecessary(); |
| 73 } | 88 } |
| 74 | 89 |
| 75 void FullscreenExitBubbleGtk::InitWidgets() { | 90 void FullscreenExitBubbleGtk::InitWidgets() { |
| 76 // The exit bubble is a gtk_chrome_link_button inside a gtk event box and gtk | |
| 77 // alignment (these provide the background color). This is then made rounded | |
| 78 // and put into a slide widget. | |
| 79 | |
| 80 // The Windows code actually looks up the accelerator key in the accelerator | |
| 81 // table and then converts the key to a string (in a switch statement). This | |
| 82 // doesn't seem to be implemented for Gtk, so we just use F11 directly. | |
| 83 std::string exit_text_utf8(l10n_util::GetStringFUTF8( | |
| 84 IDS_EXIT_FULLSCREEN_MODE, l10n_util::GetStringUTF16(IDS_APP_F11_KEY))); | |
| 85 | |
| 86 hbox_ = gtk_hbox_new(false, ui::kControlSpacing); | 91 hbox_ = gtk_hbox_new(false, ui::kControlSpacing); |
| 87 | 92 |
| 88 message_label_ = gtk_label_new(GetMessage(url_).c_str()); | 93 message_label_ = gtk_label_new(GetMessage(url_).c_str()); |
| 89 gtk_box_pack_start(GTK_BOX(hbox_), message_label_, FALSE, FALSE, 0); | 94 gtk_box_pack_start(GTK_BOX(hbox_), message_label_, FALSE, FALSE, 0); |
| 90 | 95 |
| 91 allow_button_ = gtk_button_new_with_label( | 96 allow_button_ = gtk_button_new_with_label( |
| 92 l10n_util::GetStringUTF8(IDS_FULLSCREEN_ALLOW).c_str()); | 97 l10n_util::GetStringUTF8(IDS_FULLSCREEN_ALLOW).c_str()); |
| 93 gtk_widget_set_can_focus(allow_button_, FALSE); | 98 gtk_widget_set_can_focus(allow_button_, FALSE); |
| 94 gtk_widget_set_no_show_all(allow_button_, FALSE); | 99 gtk_widget_set_no_show_all(allow_button_, FALSE); |
| 95 gtk_box_pack_start(GTK_BOX(hbox_), allow_button_, FALSE, FALSE, 0); | 100 gtk_box_pack_start(GTK_BOX(hbox_), allow_button_, FALSE, FALSE, 0); |
| 96 | 101 |
| 97 deny_button_ = gtk_button_new_with_label( | 102 deny_button_ = gtk_button_new_with_label( |
| 98 l10n_util::GetStringUTF8(IDS_FULLSCREEN_DENY).c_str()); | 103 l10n_util::GetStringUTF8(IDS_FULLSCREEN_DENY).c_str()); |
| 99 gtk_widget_set_can_focus(deny_button_, FALSE); | 104 gtk_widget_set_can_focus(deny_button_, FALSE); |
| 100 gtk_widget_set_no_show_all(deny_button_, FALSE); | 105 gtk_widget_set_no_show_all(deny_button_, FALSE); |
| 101 gtk_box_pack_start(GTK_BOX(hbox_), deny_button_, FALSE, FALSE, 0); | 106 gtk_box_pack_start(GTK_BOX(hbox_), deny_button_, FALSE, FALSE, 0); |
| 102 | 107 |
| 103 link_ = gtk_chrome_link_button_new(exit_text_utf8.c_str()); | 108 link_ = gtk_chrome_link_button_new(""); |
| 104 gtk_widget_set_can_focus(link_, FALSE); | 109 gtk_widget_set_can_focus(link_, FALSE); |
| 105 gtk_widget_set_no_show_all(link_, FALSE); | 110 gtk_widget_set_no_show_all(link_, FALSE); |
| 106 gtk_chrome_link_button_set_use_gtk_theme(GTK_CHROME_LINK_BUTTON(link_), | 111 gtk_chrome_link_button_set_use_gtk_theme(GTK_CHROME_LINK_BUTTON(link_), |
| 107 FALSE); | 112 FALSE); |
| 108 gtk_box_pack_start(GTK_BOX(hbox_), link_, FALSE, FALSE, 0); | 113 gtk_box_pack_start(GTK_BOX(hbox_), link_, FALSE, FALSE, 0); |
| 109 | 114 |
| 110 instruction_label_ = gtk_chrome_link_button_new( | 115 instruction_label_ = gtk_label_new(UTF16ToUTF8(GetInstructionText()).c_str()); |
| 111 UTF16ToUTF8(GetInstructionText()).c_str()); | |
| 112 gtk_widget_set_no_show_all(instruction_label_, FALSE); | 116 gtk_widget_set_no_show_all(instruction_label_, FALSE); |
| 113 gtk_chrome_link_button_set_use_gtk_theme( | |
| 114 GTK_CHROME_LINK_BUTTON(instruction_label_), FALSE); | |
| 115 gtk_box_pack_start(GTK_BOX(hbox_), instruction_label_, FALSE, FALSE, 0); | 117 gtk_box_pack_start(GTK_BOX(hbox_), instruction_label_, FALSE, FALSE, 0); |
| 116 | 118 |
| 117 GtkWidget* bubble = gtk_util::CreateGtkBorderBin( | 119 GtkWidget* bubble = gtk_util::CreateGtkBorderBin( |
| 118 hbox_, &ui::kGdkWhite, | 120 hbox_, &ui::kGdkWhite, |
| 119 kPaddingPx, kPaddingPx, kPaddingPx, kPaddingPx); | 121 kPaddingPx, kPaddingPx, kPaddingPx, kPaddingPx); |
| 120 gtk_util::ActAsRoundedWindow(bubble, kFrameColor, 3, | 122 gtk_util::ActAsRoundedWindow(bubble, kFrameColor, 3, |
| 121 gtk_util::ROUNDED_ALL, gtk_util::BORDER_ALL); | 123 gtk_util::ROUNDED_ALL, gtk_util::BORDER_ALL); |
| 122 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); | 124 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); |
| 123 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 5, 0, 0, 0); | 125 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 5, 0, 0, 0); |
| 124 gtk_container_add(GTK_CONTAINER(alignment), bubble); | 126 gtk_container_add(GTK_CONTAINER(alignment), bubble); |
| 125 ui_container_.Own(alignment); | 127 ui_container_.Own(alignment); |
| 126 | 128 |
| 127 slide_widget_.reset(new SlideAnimatorGtk(ui_container_.get(), | 129 slide_widget_.reset(new SlideAnimatorGtk(ui_container_.get(), |
| 128 SlideAnimatorGtk::DOWN, kSlideOutDurationMs, false, false, NULL)); | 130 SlideAnimatorGtk::DOWN, kSlideOutDurationMs, false, false, NULL)); |
| 129 gtk_widget_set_name(widget(), "exit-fullscreen-bubble"); | 131 gtk_widget_set_name(widget(), "exit-fullscreen-bubble"); |
| 130 gtk_widget_show_all(ui_container_.get()); | 132 gtk_widget_show_all(ui_container_.get()); |
| 131 gtk_widget_show(widget()); | 133 gtk_widget_show(widget()); |
| 132 slide_widget_->OpenWithoutAnimation(); | 134 slide_widget_->OpenWithoutAnimation(); |
| 133 | 135 |
| 134 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(container_), | 136 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(container_), |
| 135 widget()); | 137 widget()); |
| 136 | 138 |
| 137 signals_.Connect(container_, "set-floating-position", | 139 signals_.Connect(container_, "set-floating-position", |
| 138 G_CALLBACK(OnSetFloatingPositionThunk), this); | 140 G_CALLBACK(OnSetFloatingPositionThunk), this); |
| 139 signals_.Connect(link_, "clicked", G_CALLBACK(OnLinkClickedThunk), this); | 141 signals_.Connect(link_, "clicked", G_CALLBACK(OnLinkClickedThunk), this); |
| 140 signals_.Connect(instruction_label_, "clicked", | |
| 141 G_CALLBACK(OnLinkClickedThunk), this); | |
| 142 signals_.Connect(allow_button_, "clicked", | 142 signals_.Connect(allow_button_, "clicked", |
| 143 G_CALLBACK(&OnAllowClickedThunk), this); | 143 G_CALLBACK(&OnAllowClickedThunk), this); |
| 144 signals_.Connect(deny_button_, "clicked", | 144 signals_.Connect(deny_button_, "clicked", |
| 145 G_CALLBACK(&OnDenyClickedThunk), this); | 145 G_CALLBACK(&OnDenyClickedThunk), this); |
| 146 | 146 |
| 147 UpdateContent(url_, bubble_type_); | 147 UpdateContent(url_, bubble_type_); |
| 148 } | 148 } |
| 149 | 149 |
| 150 std::string FullscreenExitBubbleGtk::GetMessage(const GURL& url) { | 150 std::string FullscreenExitBubbleGtk::GetMessage(const GURL& url) { |
| 151 if (url.is_empty()) { | 151 if (url.is_empty()) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 ToggleFullscreen(); | 238 ToggleFullscreen(); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void FullscreenExitBubbleGtk::OnAllowClicked(GtkWidget* button) { | 241 void FullscreenExitBubbleGtk::OnAllowClicked(GtkWidget* button) { |
| 242 Accept(); | 242 Accept(); |
| 243 UpdateContent(url_, bubble_type_); | 243 UpdateContent(url_, bubble_type_); |
| 244 } | 244 } |
| 245 void FullscreenExitBubbleGtk::OnDenyClicked(GtkWidget* button) { | 245 void FullscreenExitBubbleGtk::OnDenyClicked(GtkWidget* button) { |
| 246 Cancel(); | 246 Cancel(); |
| 247 } | 247 } |
| OLD | NEW |