diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-17 21:24:30 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-10-17 21:24:30 +0000 |
commit | 7724ed6a158a82c1e7e6f016a9ed02d31bbcaa99 (patch) | |
tree | 9b0ddde36cbf464f3d80ded3ca6e1fee02678dd6 /chrome | |
parent | fa4dd291cc96e2953e6c83217c27e2c2596a0254 (diff) | |
download | chromium_src-7724ed6a158a82c1e7e6f016a9ed02d31bbcaa99.zip chromium_src-7724ed6a158a82c1e7e6f016a9ed02d31bbcaa99.tar.gz chromium_src-7724ed6a158a82c1e7e6f016a9ed02d31bbcaa99.tar.bz2 |
views: Implementation of the new fullscreen bubble.
Due to the base class changing, this also touches the GTK UI, but the GTK
changes should be mostly no-ops.
Based on a patch by Yuzhu Shen <yzshen@chromium.org>
BUG=95136, 100266
TEST=none
Review URL: http://codereview.chromium.org/8321016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@105922 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/ui/fullscreen_exit_bubble.cc | 44 | ||||
-rw-r--r-- | chrome/browser/ui/fullscreen_exit_bubble.h | 30 | ||||
-rw-r--r-- | chrome/browser/ui/fullscreen_exit_bubble_type.cc | 13 | ||||
-rw-r--r-- | chrome/browser/ui/fullscreen_exit_bubble_type.h | 5 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.cc | 20 | ||||
-rw-r--r-- | chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.h | 1 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_view.cc | 21 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_view.h | 10 | ||||
-rw-r--r-- | chrome/browser/ui/views/fullscreen_exit_bubble_views.cc | 169 | ||||
-rw-r--r-- | chrome/browser/ui/views/fullscreen_exit_bubble_views.h | 9 |
10 files changed, 210 insertions, 112 deletions
diff --git a/chrome/browser/ui/fullscreen_exit_bubble.cc b/chrome/browser/ui/fullscreen_exit_bubble.cc index 8bca0a9..111189e 100644 --- a/chrome/browser/ui/fullscreen_exit_bubble.cc +++ b/chrome/browser/ui/fullscreen_exit_bubble.cc @@ -4,8 +4,11 @@ #include "chrome/browser/ui/fullscreen_exit_bubble.h" +#include "base/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/ui/browser.h" +#include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util.h" #include "ui/gfx/rect.h" const int FullscreenExitBubble::kPaddingPx = 8; @@ -17,8 +20,13 @@ const int FullscreenExitBubble::kSlideInDurationMs = 350; const int FullscreenExitBubble::kSlideOutDurationMs = 700; const int FullscreenExitBubble::kPopupTopPx = 15; -FullscreenExitBubble::FullscreenExitBubble(Browser* browser) - : browser_(browser) { +FullscreenExitBubble::FullscreenExitBubble(Browser* browser, + const GURL& url, + FullscreenExitBubbleType bubble_type) + : browser_(browser), + url_(url), + bubble_type_(bubble_type) { + DCHECK_NE(FEB_TYPE_NONE, bubble_type_); } FullscreenExitBubble::~FullscreenExitBubble() { @@ -36,6 +44,12 @@ void FullscreenExitBubble::StartWatchingMouse() { &FullscreenExitBubble::CheckMousePosition); } +void FullscreenExitBubble::StopWatchingMouse() { + initial_delay_.Stop(); + idle_timeout_.Stop(); + mouse_position_checker_.Stop(); +} + void FullscreenExitBubble::CheckMousePosition() { // Desired behavior: // @@ -89,10 +103,30 @@ void FullscreenExitBubble::ToggleFullscreen() { browser_->ExecuteCommand(IDC_FULLSCREEN); } -void FullscreenExitBubble::AcceptFullscreen(const GURL& url) { - browser_->OnAcceptFullscreenPermission(url); +void FullscreenExitBubble::Accept() { + // TODO(yzshen): Pass bubble_type_ to OnAcceptFullscreenPermission() once it + // accepts it. + browser_->OnAcceptFullscreenPermission(url_); } -void FullscreenExitBubble::CancelFullscreen() { +void FullscreenExitBubble::Cancel() { + // TODO(yzshen): Pass bubble_type_ to OnDenyFullscreenPermission() once it + // accepts it. browser_->OnDenyFullscreenPermission(); } + +string16 FullscreenExitBubble::GetCurrentMessageText() const { + return fullscreen_bubble::GetLabelTextForType(bubble_type_, url_); +} + +string16 FullscreenExitBubble::GetCurrentDenyButtonText() const { + return fullscreen_bubble::GetDenyButtonTextForType(bubble_type_); +} + +string16 FullscreenExitBubble::GetAllowButtonText() const { + return l10n_util::GetStringUTF16(IDS_FULLSCREEN_ALLOW); +} + +string16 FullscreenExitBubble::GetInstructionText() const { + return l10n_util::GetStringUTF16(IDS_FULLSCREEN_PRESS_ESC_TO_EXIT); +} diff --git a/chrome/browser/ui/fullscreen_exit_bubble.h b/chrome/browser/ui/fullscreen_exit_bubble.h index ab4ddb8..50eb675 100644 --- a/chrome/browser/ui/fullscreen_exit_bubble.h +++ b/chrome/browser/ui/fullscreen_exit_bubble.h @@ -9,6 +9,7 @@ #include "base/memory/scoped_ptr.h" #include "base/timer.h" #include "chrome/browser/command_updater.h" +#include "chrome/browser/ui/fullscreen_exit_bubble_type.h" #include "googleurl/src/gurl.h" #include "ui/base/animation/animation_delegate.h" #include "ui/gfx/point.h" @@ -25,7 +26,9 @@ class Rect; class FullscreenExitBubble : public ui::AnimationDelegate { public: - explicit FullscreenExitBubble(Browser* browser); + explicit FullscreenExitBubble(Browser* browser, + const GURL& url, + FullscreenExitBubbleType bubble_type); virtual ~FullscreenExitBubble(); protected: @@ -33,8 +36,9 @@ class FullscreenExitBubble : public ui::AnimationDelegate { static const int kInitialDelayMs; // Initial time bubble remains onscreen static const int kIdleTimeMs; // Time before mouse idle triggers hide static const int kPositionCheckHz; // How fast to check the mouse position - static const int kSlideInRegionHeightPx; // Height of region triggering - // slide-in + static const int kSlideInRegionHeightPx; + // Height of region triggering + // slide-in static const int kPopupTopPx; // Space between the popup and the top // of the screen. static const int kSlideInDurationMs; // Duration of slide-in animation @@ -64,10 +68,19 @@ class FullscreenExitBubble : public ui::AnimationDelegate { void CheckMousePosition(); void StartWatchingMouse(); + void StopWatchingMouse(); void ToggleFullscreen(); - void AcceptFullscreen(const GURL& url); - void CancelFullscreen(); + void Accept(); + void Cancel(); + + // The following strings may change according to the content type and URL. + string16 GetCurrentMessageText() const; + string16 GetCurrentDenyButtonText() const; + + // The following strings never change. + string16 GetAllowButtonText() const; + string16 GetInstructionText() const; // The browser this bubble is in. Browser* browser_; @@ -89,6 +102,13 @@ class FullscreenExitBubble : public ui::AnimationDelegate { // The most recently seen mouse position, in screen coordinates. Used to see // if the mouse has moved since our last check. gfx::Point last_mouse_pos_; + + protected: + // The host the bubble is for, can be empty. + GURL url_; + + // The type of the bubble; controls e.g. which buttons to show. + FullscreenExitBubbleType bubble_type_; }; #endif // CHROME_BROWSER_UI_FULLSCREEN_EXIT_BUBBLE_H_ diff --git a/chrome/browser/ui/fullscreen_exit_bubble_type.cc b/chrome/browser/ui/fullscreen_exit_bubble_type.cc index d346dcb..6d0c76f 100644 --- a/chrome/browser/ui/fullscreen_exit_bubble_type.cc +++ b/chrome/browser/ui/fullscreen_exit_bubble_type.cc @@ -92,4 +92,17 @@ bool ShowButtonsForType(FullscreenExitBubbleType type) { type == FEB_TYPE_MOUSELOCK_BUTTONS; } +void PermissionRequestedByType(FullscreenExitBubbleType type, + bool* tab_fullscreen, + bool* mouse_lock) { + if (tab_fullscreen) { + *tab_fullscreen = type == FEB_TYPE_FULLSCREEN_BUTTONS || + type == FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS; + } + if (mouse_lock) { + *mouse_lock = type == FEB_TYPE_FULLSCREEN_MOUSELOCK_BUTTONS || + type == FEB_TYPE_MOUSELOCK_BUTTONS; + } +} + } // namespace diff --git a/chrome/browser/ui/fullscreen_exit_bubble_type.h b/chrome/browser/ui/fullscreen_exit_bubble_type.h index bf77bd7..4d2507a 100644 --- a/chrome/browser/ui/fullscreen_exit_bubble_type.h +++ b/chrome/browser/ui/fullscreen_exit_bubble_type.h @@ -35,7 +35,10 @@ string16 GetLabelTextForType( FullscreenExitBubbleType type, const GURL& url); string16 GetDenyButtonTextForType(FullscreenExitBubbleType type); bool ShowButtonsForType(FullscreenExitBubbleType type); +void PermissionRequestedByType(FullscreenExitBubbleType type, + bool* tab_fullscreen, + bool* mouse_lock); -} // namespace fullscreen +} // namespace fullscreen_bubble #endif // CHROME_BROWSER_UI_FULLSCREEN_EXIT_BUBBLE_TYPE_H_ diff --git a/chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.cc b/chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.cc index c140e73..43b4eda 100644 --- a/chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.cc +++ b/chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.cc @@ -25,9 +25,11 @@ FullscreenExitBubbleGtk::FullscreenExitBubbleGtk( Browser* browser, const GURL& url, bool ask_permission) - : FullscreenExitBubble(browser), + : FullscreenExitBubble( + browser, url, + ask_permission ? FEB_TYPE_FULLSCREEN_BUTTONS : + FEB_TYPE_FULLSCREEN_EXIT_INSTRUCTION), container_(container), - url_(url), show_buttons_(ask_permission) { InitWidgets(); } @@ -53,9 +55,9 @@ void FullscreenExitBubbleGtk::InitWidgets() { GtkWidget* button_link_hbox = gtk_hbox_new(false, ui::kControlSpacing); allow_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_FULLSCREEN_INFOBAR_ALLOW).c_str()); + l10n_util::GetStringUTF8(IDS_FULLSCREEN_ALLOW).c_str()); deny_button_ = gtk_button_new_with_label( - l10n_util::GetStringUTF8(IDS_FULLSCREEN_INFOBAR_DENY).c_str()); + 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); @@ -119,11 +121,11 @@ void FullscreenExitBubbleGtk::InitWidgets() { std::string FullscreenExitBubbleGtk::GetMessage(const GURL& url) { if (url.is_empty()) { return l10n_util::GetStringUTF8( - IDS_FULLSCREEN_INFOBAR_USER_ENTERED_FULLSCREEN); + IDS_FULLSCREEN_USER_ENTERED_FULLSCREEN); } if (url.SchemeIsFile()) - return l10n_util::GetStringUTF8(IDS_FULLSCREEN_INFOBAR_FILE_PAGE_NAME); - return l10n_util::GetStringFUTF8(IDS_FULLSCREEN_INFOBAR_REQUEST_PERMISSION, + return l10n_util::GetStringUTF8(IDS_FULLSCREEN_ENTERED_FULLSCREEN); + return l10n_util::GetStringFUTF8(IDS_FULLSCREEN_SITE_ENTERED_FULLSCREEN, UTF8ToUTF16(url.host())); } @@ -210,9 +212,9 @@ void FullscreenExitBubbleGtk::HideButtons() { } void FullscreenExitBubbleGtk::OnAllowClicked(GtkWidget* button) { - AcceptFullscreen(url_); + Accept(); HideButtons(); } void FullscreenExitBubbleGtk::OnDenyClicked(GtkWidget* button) { - CancelFullscreen(); + Cancel(); } diff --git a/chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.h b/chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.h index 8528315..c23a129 100644 --- a/chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.h +++ b/chrome/browser/ui/gtk/fullscreen_exit_bubble_gtk.h @@ -68,7 +68,6 @@ class FullscreenExitBubbleGtk : public FullscreenExitBubble { ui::GtkSignalRegistrar signals_; - const GURL url_; bool show_buttons_; }; diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 38ac79f..1ecd895 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -767,12 +767,12 @@ bool BrowserView::IsMinimized() const { } void BrowserView::EnterFullscreen( - const GURL& url, FullscreenExitBubbleType type) { + const GURL& url, FullscreenExitBubbleType bubble_type) { if (IsFullscreen()) return; // Nothing to do. #if defined(OS_WIN) - ProcessFullscreen(true, url, type == FEB_TYPE_FULLSCREEN_BUTTONS); + ProcessFullscreen(true, url, bubble_type); #else // On Linux changing fullscreen is async. Ask the window to change it's // fullscreen state, and when done invoke ProcessFullscreen. @@ -785,7 +785,7 @@ void BrowserView::ExitFullscreen() { return; // Nothing to do. #if defined(OS_WIN) - ProcessFullscreen(false, GURL(), false); + ProcessFullscreen(false, GURL(), FEB_TYPE_NONE); #else // On Linux changing fullscreen is async. Ask the window to change it's // fullscreen state, and when done invoke ProcessFullscreen. @@ -794,9 +794,10 @@ void BrowserView::ExitFullscreen() { } void BrowserView::UpdateFullscreenExitBubbleContent( - const GURL& url, - FullscreenExitBubbleType bubble_type) { - NOTIMPLEMENTED(); + const GURL& url, + FullscreenExitBubbleType bubble_type) { + if (fullscreen_bubble_.get()) + fullscreen_bubble_->UpdateContent(url, bubble_type); } bool BrowserView::IsFullscreen() const { @@ -808,7 +809,9 @@ bool BrowserView::IsFullscreenBubbleVisible() const { } void BrowserView::FullScreenStateChanged() { - ProcessFullscreen(IsFullscreen(), GURL(), false); + bool is_fullscreen = IsFullscreen(); + ProcessFullscreen(is_fullscreen, GURL(), is_fullscreen ? + FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION : FEB_TYPE_NONE); } void BrowserView::RestoreFocus() { @@ -2200,7 +2203,7 @@ bool BrowserView::UpdateChildViewAndLayout(views::View* new_view, void BrowserView::ProcessFullscreen(bool fullscreen, const GURL& url, - bool ask_permission) { + FullscreenExitBubbleType bubble_type) { // Reduce jankiness during the following position changes by: // * Hiding the window until it's in the final position // * Ignoring all intervening Layout() calls, which resize the webpage and @@ -2250,7 +2253,7 @@ void BrowserView::ProcessFullscreen(bool fullscreen, CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode); if (!is_kiosk) { fullscreen_bubble_.reset(new FullscreenExitBubbleViews( - GetWidget(), browser_.get(), url, ask_permission)); + GetWidget(), browser_.get(), url, bubble_type)); } } else { #if defined(OS_WIN) && !defined(USE_AURA) diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index c099543c..f0e844f 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -259,7 +259,7 @@ class BrowserView : public BrowserBubbleHost, virtual bool IsMaximized() const OVERRIDE; virtual bool IsMinimized() const OVERRIDE; virtual void EnterFullscreen( - const GURL& url, FullscreenExitBubbleType type) OVERRIDE; + const GURL& url, FullscreenExitBubbleType bubble_type) OVERRIDE; virtual void ExitFullscreen() OVERRIDE; virtual void UpdateFullscreenExitBubbleContent( const GURL& url, @@ -509,9 +509,11 @@ class BrowserView : public BrowserBubbleHost, // notification that it succeeded this method is invoked. // If |url| is not empty, it is the URL of the page that requested fullscreen // (via the fullscreen JS API). - // |ask_permission| determines whether the user should be asked to allow the - // site to remain fullscreen. - void ProcessFullscreen(bool fullscreen, const GURL& url, bool ask_permission); + // |bubble_type| determines what should be shown in the fullscreen exit + // bubble. + void ProcessFullscreen(bool fullscreen, + const GURL& url, + FullscreenExitBubbleType bubble_type); // Copy the accelerator table from the app resources into something we can // use. diff --git a/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc b/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc index ceebc768..0c27d24 100644 --- a/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc +++ b/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc @@ -38,7 +38,7 @@ class FullscreenExitBubbleViews::FullscreenExitView FullscreenExitView(FullscreenExitBubbleViews* bubble, const string16& accelerator, const GURL& url, - bool ask_permission); + FullscreenExitBubbleType bubble_type); virtual ~FullscreenExitView(); // views::View @@ -47,35 +47,31 @@ class FullscreenExitBubbleViews::FullscreenExitView // views::ButtonListener virtual void ButtonPressed(views::Button* sender, const views::Event& event); - // Hide the accept and deny buttons, exposing the exit link. - void HideButtons(); + void UpdateContent(const GURL& url, FullscreenExitBubbleType bubble_type); private: - string16 GetMessage(const GURL& url); - // views::View virtual void Layout(); FullscreenExitBubbleViews* bubble_; - // Clickable hint text to show in the bubble. + // Clickable hint text for exiting browser fullscreen mode. views::Link link_; + // Instruction for exiting tab fullscreen mode. + views::Label instruction_label_; views::Label message_label_; views::NativeTextButton* accept_button_; views::NativeTextButton* deny_button_; - - bool show_buttons_; }; FullscreenExitBubbleViews::FullscreenExitView::FullscreenExitView( FullscreenExitBubbleViews* bubble, const string16& accelerator, const GURL& url, - bool ask_permission) + FullscreenExitBubbleType bubble_type) : bubble_(bubble), accept_button_(NULL), - deny_button_(NULL), - show_buttons_(ask_permission) { + deny_button_(NULL) { views::BubbleBorder* bubble_border = new views::BubbleBorder(views::BubbleBorder::NONE); bubble_border->set_background_color(Bubble::kBackgroundColor); @@ -84,10 +80,14 @@ FullscreenExitBubbleViews::FullscreenExitView::FullscreenExitView( set_focusable(false); message_label_.set_parent_owned(false); - message_label_.SetText(GetMessage(url)); message_label_.SetFont(ResourceBundle::GetSharedInstance().GetFont( ResourceBundle::MediumFont)); + instruction_label_.set_parent_owned(false); + instruction_label_.SetText(bubble_->GetInstructionText()); + instruction_label_.SetFont(ResourceBundle::GetSharedInstance().GetFont( + ResourceBundle::MediumFont)); + link_.set_parent_owned(false); link_.set_collapse_when_hidden(false); link_.set_focusable(false); @@ -107,33 +107,21 @@ FullscreenExitBubbleViews::FullscreenExitView::FullscreenExitView( link_.SetBackgroundColor(background()->get_color()); message_label_.SetBackgroundColor(background()->get_color()); + instruction_label_.SetBackgroundColor(background()->get_color()); AddChildView(&message_label_); + AddChildView(&instruction_label_); AddChildView(&link_); accept_button_ = new views::NativeTextButton(this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_FULLSCREEN_INFOBAR_ALLOW))); + UTF16ToWideHack(bubble->GetAllowButtonText())); accept_button_->set_focusable(false); AddChildView(accept_button_); - deny_button_ = new views::NativeTextButton(this, - UTF16ToWide(l10n_util::GetStringUTF16(IDS_FULLSCREEN_INFOBAR_DENY))); + deny_button_ = new views::NativeTextButton(this); deny_button_->set_focusable(false); AddChildView(deny_button_); - if (!show_buttons_) - HideButtons(); -} - -string16 FullscreenExitBubbleViews::FullscreenExitView::GetMessage( - const GURL& url) { - if (url.is_empty()) { - return l10n_util::GetStringUTF16( - IDS_FULLSCREEN_INFOBAR_USER_ENTERED_FULLSCREEN); - } - if (url.SchemeIsFile()) - return l10n_util::GetStringUTF16(IDS_FULLSCREEN_INFOBAR_FILE_PAGE_NAME); - return l10n_util::GetStringFUTF16(IDS_FULLSCREEN_INFOBAR_REQUEST_PERMISSION, - UTF8ToUTF16(url.host())); + UpdateContent(url, bubble_type); } FullscreenExitBubbleViews::FullscreenExitView::~FullscreenExitView() { @@ -142,43 +130,64 @@ FullscreenExitBubbleViews::FullscreenExitView::~FullscreenExitView() { void FullscreenExitBubbleViews::FullscreenExitView::ButtonPressed( views::Button* sender, const views::Event& event) { if (sender == accept_button_) - bubble_->OnAcceptFullscreen(); + bubble_->Accept(); else - bubble_->OnCancelFullscreen(); -} - -void FullscreenExitBubbleViews::FullscreenExitView::HideButtons() { - show_buttons_ = false; - accept_button_->SetVisible(false); - deny_button_->SetVisible(false); - link_.SetVisible(true); + bubble_->Cancel(); } gfx::Size FullscreenExitBubbleViews::FullscreenExitView::GetPreferredSize() { - gfx::Size link_size(link_.GetPreferredSize()); - gfx::Size message_label_size(message_label_.GetPreferredSize()); - gfx::Size accept_size(accept_button_->GetPreferredSize()); - gfx::Size deny_size(deny_button_->GetPreferredSize()); - gfx::Insets insets(GetInsets()); + gfx::Size message_size(message_label_.GetPreferredSize()); - int buttons_width = accept_size.width() + kPaddingPx + - deny_size.width(); - int button_box_width = std::max(buttons_width, link_size.width()); - int width = kPaddingPx + message_label_size.width() + kMiddlePaddingPx + - button_box_width + kPaddingPx; + gfx::Size button_instruction_area; + if (instruction_label_.IsVisible()) { + button_instruction_area = instruction_label_.GetPreferredSize(); + } else if (link_.IsVisible()) { + button_instruction_area = link_.GetPreferredSize(); + } else { + gfx::Size accept_size(accept_button_->GetPreferredSize()); + gfx::Size deny_size(deny_button_->GetPreferredSize()); + button_instruction_area.set_height(accept_size.height()); + button_instruction_area.set_width( + accept_size.width() + kPaddingPx + deny_size.width()); + } - gfx::Size result(width + insets.width(), - kPaddingPx * 2 + accept_size.height() + insets.height()); + gfx::Insets insets(GetInsets()); + gfx::Size result( + message_size.width() + kMiddlePaddingPx + button_instruction_area.width(), + std::max(message_size.height(), button_instruction_area.height())); + result.Enlarge(insets.width() + 2 * kPaddingPx, + insets.height() + 2 * kPaddingPx); return result; } +void FullscreenExitBubbleViews::FullscreenExitView::UpdateContent( + const GURL& url, + FullscreenExitBubbleType bubble_type) { + DCHECK_NE(FEB_TYPE_NONE, bubble_type); + + message_label_.SetText(bubble_->GetCurrentMessageText()); + if (fullscreen_bubble::ShowButtonsForType(bubble_type)) { + link_.SetVisible(false); + instruction_label_.SetVisible(false); + accept_button_->SetVisible(true); + deny_button_->SetText(UTF16ToWideHack(bubble_->GetCurrentDenyButtonText())); + deny_button_->SetVisible(true); + deny_button_->ClearMaxTextSize(); + } else { + bool link_visible = + bubble_type == FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION; + link_.SetVisible(link_visible); + instruction_label_.SetVisible(!link_visible); + accept_button_->SetVisible(false); + deny_button_->SetVisible(false); + } +} + void FullscreenExitBubbleViews::FullscreenExitView::Layout() { - gfx::Size link_size(link_.GetPreferredSize()); - gfx::Size message_label_size(message_label_.GetPreferredSize()); - gfx::Size accept_size(accept_button_->GetPreferredSize()); - gfx::Size deny_size(deny_button_->GetPreferredSize()); + // TODO(thakis): Use a LayoutManager instead of doing manual layout. + gfx::Size message_size(message_label_.GetPreferredSize()); gfx::Insets insets(GetInsets()); - + int x = insets.left() + kPaddingPx; int inner_height = height() - insets.height(); int button_box_x = insets.left() + kPaddingPx + message_label_size.width() + kMiddlePaddingPx; @@ -210,23 +219,23 @@ void FullscreenExitBubbleViews::FullscreenExitView::Layout() { // FullscreenExitBubbleViews --------------------------------------------------- -FullscreenExitBubbleViews::FullscreenExitBubbleViews(views::Widget* frame, - Browser* browser, - const GURL& url, - bool ask_permission) - : FullscreenExitBubble(browser), +FullscreenExitBubbleViews::FullscreenExitBubbleViews( + views::Widget* frame, + Browser* browser, + const GURL& url, + FullscreenExitBubbleType bubble_type) + : FullscreenExitBubble(browser, url, bubble_type), root_view_(frame->GetRootView()), popup_(NULL), - size_animation_(new ui::SlideAnimation(this)), - url_(url) { + size_animation_(new ui::SlideAnimation(this)) { size_animation_->Reset(1); // Create the contents view. views::Accelerator accelerator(ui::VKEY_UNKNOWN, false, false, false); bool got_accelerator = frame->GetAccelerator(IDC_FULLSCREEN, &accelerator); DCHECK(got_accelerator); - view_ = new FullscreenExitView(this, - accelerator.GetShortcutText(), url, ask_permission); + view_ = new FullscreenExitView( + this, accelerator.GetShortcutText(), url, bubble_type_); // Initialize the popup. popup_ = new views::Widget; @@ -247,8 +256,7 @@ FullscreenExitBubbleViews::FullscreenExitBubbleViews(views::Widget* frame, view_->SetBounds(0, 0, size.width(), size.height()); popup_->Show(); // This does not activate the popup. - if (!ask_permission) - StartWatchingMouse(); + StartWatchingMouseIfNecessary(); } FullscreenExitBubbleViews::~FullscreenExitBubbleViews() { @@ -270,14 +278,24 @@ void FullscreenExitBubbleViews::LinkClicked( ToggleFullscreen(); } -void FullscreenExitBubbleViews::OnAcceptFullscreen() { - AcceptFullscreen(url_); - view_->HideButtons(); - StartWatchingMouse(); -} +void FullscreenExitBubbleViews::UpdateContent( + const GURL& url, + FullscreenExitBubbleType bubble_type) { + DCHECK_NE(FEB_TYPE_NONE, bubble_type); + if (bubble_type_ == bubble_type && url_ == url) + return; + + url_ = url; + bubble_type_ = bubble_type; + view_->UpdateContent(url_, bubble_type_); + + gfx::Size size = GetPopupRect(true).size(); + view_->SetSize(size); + popup_->SetBounds(GetPopupRect(false)); + Show(); -void FullscreenExitBubbleViews::OnCancelFullscreen() { - CancelFullscreen(); + StopWatchingMouse(); + StartWatchingMouseIfNecessary(); } void FullscreenExitBubbleViews::AnimationProgressed( @@ -346,3 +364,8 @@ gfx::Rect FullscreenExitBubbleViews::GetPopupRect( } return gfx::Rect(origin, size); } + +void FullscreenExitBubbleViews::StartWatchingMouseIfNecessary() { + if (!fullscreen_bubble::ShowButtonsForType(bubble_type_)) + StartWatchingMouse(); +} diff --git a/chrome/browser/ui/views/fullscreen_exit_bubble_views.h b/chrome/browser/ui/views/fullscreen_exit_bubble_views.h index 161f2ca..d5df1c5 100644 --- a/chrome/browser/ui/views/fullscreen_exit_bubble_views.h +++ b/chrome/browser/ui/views/fullscreen_exit_bubble_views.h @@ -26,11 +26,10 @@ class FullscreenExitBubbleViews : public views::LinkListener, FullscreenExitBubbleViews(views::Widget* frame, Browser* browser, const GURL& url, - bool ask_permission); + FullscreenExitBubbleType bubble_type); virtual ~FullscreenExitBubbleViews(); - void OnAcceptFullscreen(); - void OnCancelFullscreen(); + void UpdateContent(const GURL& url, FullscreenExitBubbleType bubble_type); protected: // FullScreenExitBubble @@ -45,6 +44,8 @@ class FullscreenExitBubbleViews : public views::LinkListener, private: class FullscreenExitView; + void StartWatchingMouseIfNecessary(); + // views::LinkListener: virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; @@ -63,8 +64,6 @@ class FullscreenExitBubbleViews : public views::LinkListener, // The contents of the popup. FullscreenExitView* view_; - const GURL url_; - DISALLOW_COPY_AND_ASSIGN(FullscreenExitBubbleViews); }; |