Chromium Code Reviews| 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 "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
| 8 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 9 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
| 9 #include "chrome/browser/ui/gtk/gtk_util.h" | 10 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 10 #include "chrome/browser/ui/gtk/rounded_window.h" | 11 #include "chrome/browser/ui/gtk/rounded_window.h" |
| 11 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
| 12 #include "grit/ui_strings.h" | 13 #include "grit/ui_strings.h" |
| 13 #include "ui/base/gtk/gtk_floating_container.h" | 14 #include "ui/base/gtk/gtk_floating_container.h" |
| 14 #include "ui/base/gtk/gtk_hig_constants.h" | 15 #include "ui/base/gtk/gtk_hig_constants.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 16 | 17 |
| 18 namespace { | |
| 19 const GdkColor kFrameColor = GDK_COLOR_RGB(0x63, 0x63, 0x63); | |
| 20 const int kMiddlePaddingPx = 30; | |
| 21 } // namespace | |
|
tony
2011/10/14 17:56:05
Nit: 2 spaces before //. Why didn't the presubmit
jeremya
2011/10/15 01:44:55
Done. Not sure why the presubmit didn't pick up on
| |
| 22 | |
| 17 FullscreenExitBubbleGtk::FullscreenExitBubbleGtk( | 23 FullscreenExitBubbleGtk::FullscreenExitBubbleGtk( |
| 18 GtkFloatingContainer* container, | 24 GtkFloatingContainer* container, |
| 19 Browser* browser, | 25 Browser* browser, |
| 20 const GURL& url, | 26 const GURL& url, |
| 21 bool ask_permission) | 27 bool ask_permission) |
| 22 : FullscreenExitBubble(browser), | 28 : FullscreenExitBubble(browser), |
| 23 container_(container), | 29 container_(container), |
| 24 url_(url), | 30 url_(url), |
| 25 show_buttons_(ask_permission) { | 31 show_buttons_(ask_permission) { |
| 26 InitWidgets(); | 32 InitWidgets(); |
| 27 StartWatchingMouse(); | |
| 28 } | 33 } |
| 29 | 34 |
| 30 FullscreenExitBubbleGtk::~FullscreenExitBubbleGtk() { | 35 FullscreenExitBubbleGtk::~FullscreenExitBubbleGtk() { |
| 31 } | 36 } |
| 32 | 37 |
| 33 void FullscreenExitBubbleGtk::InitWidgets() { | 38 void FullscreenExitBubbleGtk::InitWidgets() { |
| 34 // The exit bubble is a gtk_chrome_link_button inside a gtk event box and gtk | 39 // The exit bubble is a gtk_chrome_link_button inside a gtk event box and gtk |
| 35 // alignment (these provide the background color). This is then made rounded | 40 // alignment (these provide the background color). This is then made rounded |
| 36 // and put into a slide widget. | 41 // and put into a slide widget. |
| 37 | 42 |
| 38 // The Windows code actually looks up the accelerator key in the accelerator | 43 // The Windows code actually looks up the accelerator key in the accelerator |
| 39 // table and then converts the key to a string (in a switch statement). This | 44 // table and then converts the key to a string (in a switch statement). This |
| 40 // doesn't seem to be implemented for Gtk, so we just use F11 directly. | 45 // doesn't seem to be implemented for Gtk, so we just use F11 directly. |
| 41 std::string exit_text_utf8("<span color=\"white\" size=\"large\">"); | 46 std::string exit_text_utf8(l10n_util::GetStringFUTF8( |
| 42 exit_text_utf8.append(l10n_util::GetStringFUTF8( | |
| 43 IDS_EXIT_FULLSCREEN_MODE, l10n_util::GetStringUTF16(IDS_APP_F11_KEY))); | 47 IDS_EXIT_FULLSCREEN_MODE, l10n_util::GetStringUTF16(IDS_APP_F11_KEY))); |
| 44 exit_text_utf8.append("</span>"); | 48 link_ = gtk_chrome_link_button_new(exit_text_utf8.c_str()); |
|
tony
2011/10/14 17:56:05
Do you have a screenshot of what this looks like a
jeremya
2011/10/15 01:44:55
The mock (http://www.corp.google.com/~glen/chrome/
| |
| 45 GtkWidget* link = gtk_chrome_link_button_new_with_markup( | 49 gtk_chrome_link_button_set_use_gtk_theme(GTK_CHROME_LINK_BUTTON(link_), |
| 46 exit_text_utf8.c_str()); | |
| 47 gtk_chrome_link_button_set_use_gtk_theme(GTK_CHROME_LINK_BUTTON(link), | |
| 48 FALSE); | 50 FALSE); |
| 49 signals_.Connect(link, "clicked", G_CALLBACK(OnLinkClickedThunk), this); | |
| 50 | 51 |
| 52 GtkWidget* hbox = gtk_hbox_new(false, 0); | |
| 51 | 53 |
| 52 link_container_.Own(gtk_util::CreateGtkBorderBin( | 54 // The widget needs to not change size when the allow/deny buttons are |
| 53 link, &ui::kGdkBlack, | 55 // replaced by the exit link, so we wrap the buttons and the link in their |
| 54 kPaddingPx, kPaddingPx, kPaddingPx, kPaddingPx)); | 56 // own HBox, and force its size to be the max of the two sizes. |
| 55 GdkColor green = GDK_COLOR_RGB(0x00, 0xff, 0x00); | 57 GtkWidget* button_link_hbox = gtk_hbox_new(false, ui::kControlSpacing); |
| 56 gtk_util::ActAsRoundedWindow(link_container_.get(), green, kPaddingPx, | 58 allow_button_ = gtk_button_new_with_label( |
| 57 gtk_util::ROUNDED_BOTTOM_LEFT | gtk_util::ROUNDED_BOTTOM_RIGHT, | 59 l10n_util::GetStringUTF8(IDS_FULLSCREEN_INFOBAR_ALLOW).c_str()); |
| 58 gtk_util::BORDER_NONE); | 60 deny_button_ = gtk_button_new_with_label( |
| 61 l10n_util::GetStringUTF8(IDS_FULLSCREEN_INFOBAR_DENY).c_str()); | |
| 62 gtk_box_pack_end(GTK_BOX(button_link_hbox), deny_button_, FALSE, FALSE, 0); | |
| 63 gtk_box_pack_end(GTK_BOX(button_link_hbox), allow_button_, FALSE, FALSE, 0); | |
| 64 gtk_box_pack_end(GTK_BOX(button_link_hbox), link_, FALSE, FALSE, 0); | |
| 59 | 65 |
| 60 slide_widget_.reset(new SlideAnimatorGtk(link_container_.get(), | 66 GtkWidget* message_label = gtk_label_new(GetMessage(url_).c_str()); |
| 67 | |
| 68 gtk_box_pack_start(GTK_BOX(hbox), message_label, FALSE, FALSE, 0); | |
| 69 gtk_box_pack_end(GTK_BOX(hbox), button_link_hbox, FALSE, FALSE, 0); | |
| 70 | |
| 71 GtkWidget* bubble = gtk_util::CreateGtkBorderBin( | |
| 72 hbox, &ui::kGdkWhite, | |
| 73 kPaddingPx, kPaddingPx, kPaddingPx, kPaddingPx); | |
| 74 gtk_util::ActAsRoundedWindow(bubble, kFrameColor, 3, | |
|
tony
2011/10/14 17:56:05
Is this supposed to be a fixed frame color or shou
jeremya
2011/10/15 01:44:55
BubbleGtk seems to use a fixed frame color.
| |
| 75 gtk_util::ROUNDED_ALL, gtk_util::BORDER_ALL); | |
| 76 GtkWidget* alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); | |
| 77 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 5, 0, 0, 0); | |
| 78 gtk_container_add(GTK_CONTAINER(alignment), bubble); | |
| 79 ui_container_.Own(alignment); | |
| 80 | |
| 81 slide_widget_.reset(new SlideAnimatorGtk(ui_container_.get(), | |
| 61 SlideAnimatorGtk::DOWN, kSlideOutDurationMs, false, false, NULL)); | 82 SlideAnimatorGtk::DOWN, kSlideOutDurationMs, false, false, NULL)); |
| 62 gtk_widget_set_name(widget(), "exit-fullscreen-bubble"); | 83 gtk_widget_set_name(widget(), "exit-fullscreen-bubble"); |
| 63 gtk_widget_show_all(link_container_.get()); | 84 gtk_widget_show_all(ui_container_.get()); |
| 64 gtk_widget_show(widget()); | 85 gtk_widget_show(widget()); |
| 65 slide_widget_->OpenWithoutAnimation(); | 86 slide_widget_->OpenWithoutAnimation(); |
| 66 | 87 |
| 67 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(container_), | 88 gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(container_), |
| 68 widget()); | 89 widget()); |
| 90 | |
| 91 GtkRequisition req; | |
|
tony
2011/10/14 17:56:05
I would move the size comment on lines 54-56 here.
jeremya
2011/10/15 01:44:55
Done.
| |
| 92 int button_width = 0; | |
| 93 gtk_widget_size_request(allow_button_, &req); | |
| 94 button_width += req.width; | |
| 95 gtk_widget_size_request(deny_button_, &req); | |
| 96 button_width += req.width; | |
| 97 button_width += ui::kControlSpacing; | |
| 98 int height = req.height; | |
| 99 gtk_widget_size_request(link_, &req); | |
| 100 int width = std::max(button_width, req.width); | |
| 101 gtk_widget_set_size_request(button_link_hbox, width, height); | |
|
tony
2011/10/14 17:56:05
Should the contents of the hbox be horizontally ce
jeremya
2011/10/15 01:44:55
You mean vertically..?
| |
| 102 | |
| 103 gtk_widget_size_request(message_label, &req); | |
| 104 gtk_widget_set_size_request(hbox, req.width + width + kMiddlePaddingPx, -1); | |
| 105 | |
| 69 signals_.Connect(container_, "set-floating-position", | 106 signals_.Connect(container_, "set-floating-position", |
| 70 G_CALLBACK(OnSetFloatingPositionThunk), this); | 107 G_CALLBACK(OnSetFloatingPositionThunk), this); |
| 108 signals_.Connect(link_, "clicked", G_CALLBACK(OnLinkClickedThunk), this); | |
| 109 signals_.Connect(allow_button_, "clicked", | |
| 110 G_CALLBACK(&OnAllowClickedThunk), this); | |
| 111 signals_.Connect(deny_button_, "clicked", | |
| 112 G_CALLBACK(&OnDenyClickedThunk), this); | |
| 113 gtk_widget_hide(link_); | |
| 114 if (!show_buttons_) { | |
| 115 HideButtons(); | |
| 116 } | |
| 117 } | |
| 118 | |
| 119 std::string FullscreenExitBubbleGtk::GetMessage(const GURL& url) { | |
| 120 if (url.is_empty()) { | |
| 121 return l10n_util::GetStringUTF8( | |
| 122 IDS_FULLSCREEN_INFOBAR_USER_ENTERED_FULLSCREEN); | |
| 123 } | |
| 124 if (url.SchemeIsFile()) | |
| 125 return l10n_util::GetStringUTF8(IDS_FULLSCREEN_INFOBAR_FILE_PAGE_NAME); | |
| 126 return l10n_util::GetStringFUTF8(IDS_FULLSCREEN_INFOBAR_REQUEST_PERMISSION, | |
| 127 UTF8ToUTF16(url.host())); | |
| 71 } | 128 } |
| 72 | 129 |
| 73 gfx::Rect FullscreenExitBubbleGtk::GetPopupRect( | 130 gfx::Rect FullscreenExitBubbleGtk::GetPopupRect( |
| 74 bool ignore_animation_state) const { | 131 bool ignore_animation_state) const { |
| 75 GtkRequisition bubble_size; | 132 GtkRequisition bubble_size; |
| 76 if (ignore_animation_state) { | 133 if (ignore_animation_state) { |
| 77 gtk_widget_size_request(link_container_.get(), &bubble_size); | 134 gtk_widget_size_request(ui_container_.get(), &bubble_size); |
| 78 } else { | 135 } else { |
| 79 gtk_widget_size_request(widget(), &bubble_size); | 136 gtk_widget_size_request(widget(), &bubble_size); |
| 80 } | 137 } |
| 81 return gfx::Rect(bubble_size.width, bubble_size.height); | 138 return gfx::Rect(bubble_size.width, bubble_size.height); |
| 82 } | 139 } |
| 83 | 140 |
| 84 gfx::Point FullscreenExitBubbleGtk::GetCursorScreenPoint() { | 141 gfx::Point FullscreenExitBubbleGtk::GetCursorScreenPoint() { |
| 85 GdkDisplay* display = gtk_widget_get_display(widget()); | 142 GdkDisplay* display = gtk_widget_get_display(widget()); |
| 86 | 143 |
| 87 // Get cursor position. | 144 // Get cursor position. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 | 194 |
| 138 g_value_set_int(&value, 0); | 195 g_value_set_int(&value, 0); |
| 139 gtk_container_child_set_property(GTK_CONTAINER(floating_container), | 196 gtk_container_child_set_property(GTK_CONTAINER(floating_container), |
| 140 widget(), "y", &value); | 197 widget(), "y", &value); |
| 141 g_value_unset(&value); | 198 g_value_unset(&value); |
| 142 } | 199 } |
| 143 | 200 |
| 144 void FullscreenExitBubbleGtk::OnLinkClicked(GtkWidget* link) { | 201 void FullscreenExitBubbleGtk::OnLinkClicked(GtkWidget* link) { |
| 145 ToggleFullscreen(); | 202 ToggleFullscreen(); |
| 146 } | 203 } |
| 204 | |
| 205 void FullscreenExitBubbleGtk::HideButtons() { | |
| 206 gtk_widget_hide(allow_button_); | |
| 207 gtk_widget_hide(deny_button_); | |
| 208 gtk_widget_show(link_); | |
| 209 StartWatchingMouse(); | |
| 210 } | |
| 211 | |
| 212 void FullscreenExitBubbleGtk::OnAllowClicked(GtkWidget* button) { | |
| 213 AcceptFullscreen(url_); | |
| 214 HideButtons(); | |
| 215 } | |
| 216 void FullscreenExitBubbleGtk::OnDenyClicked(GtkWidget* button) { | |
| 217 CancelFullscreen(); | |
| 218 } | |
| OLD | NEW |