diff options
author | scheib@chromium.org <scheib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 02:50:53 +0000 |
---|---|---|
committer | scheib@chromium.org <scheib@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-18 02:50:53 +0000 |
commit | 481817bc734f0ffb8babc6b3d4dab83696988770 (patch) | |
tree | 5cdd27e6e7735d5d28d74c454437e410bc7ae965 /chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.cc | |
parent | 1623acd2f8b2e20af8df3138f3df087a50b79a62 (diff) | |
download | chromium_src-481817bc734f0ffb8babc6b3d4dab83696988770.zip chromium_src-481817bc734f0ffb8babc6b3d4dab83696988770.tar.gz chromium_src-481817bc734f0ffb8babc6b3d4dab83696988770.tar.bz2 |
Linux Mouse Lock Bubble UI
Builds on http://codereview.chromium.org/8274022/
BUG=95136
TEST=none
Review URL: http://codereview.chromium.org/8315002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106010 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.cc')
-rw-r--r-- | chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.cc | 123 |
1 files changed, 75 insertions, 48 deletions
diff --git a/chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.cc b/chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.cc index 43b4eda..db74360 100644 --- a/chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.cc +++ b/chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.cc @@ -9,6 +9,8 @@ #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" #include "chrome/browser/ui/gtk/gtk_util.h" #include "chrome/browser/ui/gtk/rounded_window.h" +#include "content/browser/renderer_host/render_widget_host_view.h" +#include "content/browser/tab_contents/tab_contents.h" #include "grit/generated_resources.h" #include "grit/ui_strings.h" #include "ui/base/gtk/gtk_floating_container.h" @@ -24,19 +26,54 @@ FullscreenExitBubbleGtk::FullscreenExitBubbleGtk( GtkFloatingContainer* container, Browser* browser, const GURL& url, - bool ask_permission) - : FullscreenExitBubble( - browser, url, - ask_permission ? FEB_TYPE_FULLSCREEN_BUTTONS : - FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION), + FullscreenExitBubbleType bubble_type) + : FullscreenExitBubble(browser, url, bubble_type), container_(container), - show_buttons_(ask_permission) { + render_widget_host_view_widget_(browser->GetSelectedTabContents()-> + GetRenderWidgetHostView()->GetNativeView()) { InitWidgets(); } FullscreenExitBubbleGtk::~FullscreenExitBubbleGtk() { } +void FullscreenExitBubbleGtk::UpdateContent( + const GURL& url, + FullscreenExitBubbleType bubble_type) { + if (bubble_type == FEB_TYPE_NONE) { + NOTREACHED(); + bubble_type = FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; + } + + url_ = url; + bubble_type_ = bubble_type; + + gtk_label_set_text(GTK_LABEL(message_label_), + UTF16ToUTF8(GetCurrentMessageText()).c_str()); + if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { + gtk_widget_hide(link_); + gtk_widget_hide(instruction_label_); + gtk_widget_show(allow_button_); + gtk_button_set_label(GTK_BUTTON(deny_button_), + UTF16ToUTF8(GetCurrentDenyButtonText()).c_str()); + gtk_widget_show(deny_button_); + } else { + if (bubble_type == FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION) { + gtk_widget_show(link_); + gtk_widget_hide(instruction_label_); + } else { + gtk_widget_hide(link_); + gtk_widget_show(instruction_label_); + } + gtk_widget_hide(allow_button_); + gtk_widget_hide(deny_button_); + } + + Show(); + StopWatchingMouse(); + StartWatchingMouseIfNecessary(); +} + void FullscreenExitBubbleGtk::InitWidgets() { // The exit bubble is a gtk_chrome_link_button inside a gtk event box and gtk // alignment (these provide the background color). This is then made rounded @@ -47,28 +84,36 @@ void FullscreenExitBubbleGtk::InitWidgets() { // doesn't seem to be implemented for Gtk, so we just use F11 directly. std::string exit_text_utf8(l10n_util::GetStringFUTF8( IDS_EXIT_FULLSCREEN_MODE, l10n_util::GetStringUTF16(IDS_APP_F11_KEY))); - link_ = gtk_chrome_link_button_new(exit_text_utf8.c_str()); - gtk_chrome_link_button_set_use_gtk_theme(GTK_CHROME_LINK_BUTTON(link_), - FALSE); - GtkWidget* hbox = gtk_hbox_new(false, 0); + hbox_ = gtk_hbox_new(false, ui::kControlSpacing); + + message_label_ = gtk_label_new(GetMessage(url_).c_str()); + gtk_box_pack_start(GTK_BOX(hbox_), message_label_, FALSE, FALSE, 0); - GtkWidget* button_link_hbox = gtk_hbox_new(false, ui::kControlSpacing); allow_button_ = gtk_button_new_with_label( l10n_util::GetStringUTF8(IDS_FULLSCREEN_ALLOW).c_str()); + gtk_widget_set_no_show_all(allow_button_, FALSE); + gtk_box_pack_start(GTK_BOX(hbox_), allow_button_, FALSE, FALSE, 0); + deny_button_ = gtk_button_new_with_label( l10n_util::GetStringUTF8(IDS_FULLSCREEN_DENY).c_str()); - gtk_box_pack_end(GTK_BOX(button_link_hbox), deny_button_, FALSE, FALSE, 0); - gtk_box_pack_end(GTK_BOX(button_link_hbox), allow_button_, FALSE, FALSE, 0); - gtk_box_pack_end(GTK_BOX(button_link_hbox), link_, FALSE, FALSE, 0); + gtk_widget_set_no_show_all(deny_button_, FALSE); + gtk_box_pack_start(GTK_BOX(hbox_), deny_button_, FALSE, FALSE, 0); - GtkWidget* message_label = gtk_label_new(GetMessage(url_).c_str()); + link_ = gtk_chrome_link_button_new(exit_text_utf8.c_str()); + gtk_widget_set_no_show_all(link_, FALSE); + gtk_chrome_link_button_set_use_gtk_theme(GTK_CHROME_LINK_BUTTON(link_), + FALSE); + gtk_box_pack_start(GTK_BOX(hbox_), link_, FALSE, FALSE, 0); + + + instruction_label_ = gtk_label_new(UTF16ToUTF8(GetInstructionText()).c_str()); + gtk_widget_set_no_show_all(instruction_label_, FALSE); + gtk_box_pack_start(GTK_BOX(hbox_), instruction_label_, FALSE, FALSE, 0); - gtk_box_pack_start(GTK_BOX(hbox), message_label, FALSE, FALSE, 0); - gtk_box_pack_end(GTK_BOX(hbox), button_link_hbox, FALSE, FALSE, 0); GtkWidget* bubble = gtk_util::CreateGtkBorderBin( - hbox, &ui::kGdkWhite, + hbox_, &ui::kGdkWhite, kPaddingPx, kPaddingPx, kPaddingPx, kPaddingPx); gtk_util::ActAsRoundedWindow(bubble, kFrameColor, 3, gtk_util::ROUNDED_ALL, gtk_util::BORDER_ALL); @@ -87,24 +132,6 @@ void FullscreenExitBubbleGtk::InitWidgets() { gtk_floating_container_add_floating(GTK_FLOATING_CONTAINER(container_), widget()); - // The widget needs to not change size when the allow/deny buttons are - // replaced by the exit link, so we wrap the buttons and the link in their - // own HBox, and force its size to be the max of the two sizes. - GtkRequisition req; - int button_width = 0; - gtk_widget_size_request(allow_button_, &req); - button_width += req.width; - gtk_widget_size_request(deny_button_, &req); - button_width += req.width; - button_width += ui::kControlSpacing; - int height = req.height; - gtk_widget_size_request(link_, &req); - int width = std::max(button_width, req.width); - gtk_widget_set_size_request(button_link_hbox, width, height); - - gtk_widget_size_request(message_label, &req); - gtk_widget_set_size_request(hbox, req.width + width + kMiddlePaddingPx, -1); - signals_.Connect(container_, "set-floating-position", G_CALLBACK(OnSetFloatingPositionThunk), this); signals_.Connect(link_, "clicked", G_CALLBACK(OnLinkClickedThunk), this); @@ -112,10 +139,8 @@ void FullscreenExitBubbleGtk::InitWidgets() { G_CALLBACK(&OnAllowClickedThunk), this); signals_.Connect(deny_button_, "clicked", G_CALLBACK(&OnDenyClickedThunk), this); - gtk_widget_hide(link_); - if (!show_buttons_) { - HideButtons(); - } + + UpdateContent(url_, bubble_type_); } std::string FullscreenExitBubbleGtk::GetMessage(const GURL& url) { @@ -181,6 +206,11 @@ bool FullscreenExitBubbleGtk::IsAnimating() { return slide_widget_->IsAnimating(); } +void FullscreenExitBubbleGtk::StartWatchingMouseIfNecessary() { + if (!fullscreen_bubble::ShowButtonsForType(bubble_type_)) + StartWatchingMouse(); +} + void FullscreenExitBubbleGtk::OnSetFloatingPosition( GtkWidget* floating_container, GtkAllocation* allocation) { @@ -201,20 +231,17 @@ void FullscreenExitBubbleGtk::OnSetFloatingPosition( } void FullscreenExitBubbleGtk::OnLinkClicked(GtkWidget* link) { + gtk_widget_grab_focus(render_widget_host_view_widget_); ToggleFullscreen(); } -void FullscreenExitBubbleGtk::HideButtons() { - gtk_widget_hide(allow_button_); - gtk_widget_hide(deny_button_); - gtk_widget_show(link_); - StartWatchingMouse(); -} - void FullscreenExitBubbleGtk::OnAllowClicked(GtkWidget* button) { + gtk_widget_grab_focus(render_widget_host_view_widget_); Accept(); - HideButtons(); + UpdateContent(url_, bubble_type_); + StartWatchingMouse(); } void FullscreenExitBubbleGtk::OnDenyClicked(GtkWidget* button) { + gtk_widget_grab_focus(render_widget_host_view_widget_); Cancel(); } |