Index: chrome/browser/ui/views/fullscreen_exit_bubble_views.cc |
diff --git a/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc b/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc |
index 06051ddc64b496477d3b8aa3db608522b4013df8..1314fc85e2938659156edf20f4ed1981172f494e 100644 |
--- a/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc |
+++ b/chrome/browser/ui/views/fullscreen_exit_bubble_views.cc |
@@ -7,6 +7,7 @@ |
#include "base/message_loop.h" |
#include "base/utf_string_conversions.h" |
#include "chrome/app/chrome_command_ids.h" |
+#include "chrome/browser/ui/views/bubble/bubble.h" |
#include "grit/generated_resources.h" |
#include "ui/base/animation/slide_animation.h" |
#include "ui/base/keycodes/keyboard_codes.h" |
@@ -14,6 +15,8 @@ |
#include "ui/base/resource/resource_bundle.h" |
#include "ui/gfx/canvas_skia.h" |
#include "ui/gfx/screen.h" |
+#include "views/bubble/bubble_border.h" |
+#include "views/controls/button/text_button.h" |
#include "views/controls/link.h" |
#include "views/widget/widget.h" |
@@ -23,28 +26,53 @@ |
// FullscreenExitView ---------------------------------------------------------- |
-class FullscreenExitBubbleViews::FullscreenExitView : public views::View { |
+class FullscreenExitBubbleViews::FullscreenExitView : public views::View, |
+ public views::ButtonListener { |
public: |
FullscreenExitView(FullscreenExitBubbleViews* bubble, |
- const std::wstring& accelerator); |
+ const std::wstring& accelerator, |
+ const GURL& url, |
+ bool show_buttons); |
virtual ~FullscreenExitView(); |
// views::View |
virtual gfx::Size GetPreferredSize(); |
+ // views::ButtonListener |
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event); |
+ |
+ virtual void HideButtons(); |
+ |
private: |
+ // Space between the site info label and the buttons / link. |
+ static const int kMiddlePaddingPx = 30; |
// views::View |
virtual void Layout(); |
- virtual void OnPaint(gfx::Canvas* canvas); |
+ // virtual void OnPaint(gfx::Canvas* canvas); |
+ |
+ FullscreenExitBubbleViews* bubble_; |
// Clickable hint text to show in the bubble. |
views::Link link_; |
+ views::Label site_info_; |
+ views::NativeTextButton* accept_button_; |
+ views::NativeTextButton* deny_button_; |
+ |
+ bool show_buttons_; |
}; |
FullscreenExitBubbleViews::FullscreenExitView::FullscreenExitView( |
FullscreenExitBubbleViews* bubble, |
- const std::wstring& accelerator) { |
+ const std::wstring& accelerator, |
+ const GURL& url, |
+ bool show_buttons) |
+ : bubble_(bubble), |
+ accept_button_(NULL), |
+ deny_button_(NULL), |
+ show_buttons_(show_buttons) { |
link_.set_parent_owned(false); |
+ link_.set_collapse_when_hidden(false); |
+ link_.set_focusable(false); |
#if !defined(OS_CHROMEOS) |
link_.SetText( |
UTF16ToWide(l10n_util::GetStringFUTF16(IDS_EXIT_FULLSCREEN_MODE, |
@@ -55,59 +83,121 @@ FullscreenExitBubbleViews::FullscreenExitView::FullscreenExitView( |
#endif |
link_.set_listener(bubble); |
link_.SetFont(ResourceBundle::GetSharedInstance().GetFont( |
- ResourceBundle::LargeFont)); |
- link_.SetNormalColor(SK_ColorWHITE); |
- link_.SetHighlightedColor(SK_ColorWHITE); |
+ ResourceBundle::MediumFont)); |
+ link_.SetNormalColor(SK_ColorBLACK); |
+ link_.SetHighlightedColor(SK_ColorBLACK); |
+ |
+ site_info_.set_parent_owned(false); |
+ site_info_.SetText( |
+ UTF16ToWide(l10n_util::GetStringFUTF16(IDS_FULLSCREEN_INFOBAR_REQUEST_PERMISSION, |
+ UTF8ToUTF16(url.host())))); |
+ site_info_.SetFont(ResourceBundle::GetSharedInstance().GetFont( |
+ ResourceBundle::MediumFont)); |
+ AddChildView(&site_info_); |
AddChildView(&link_); |
+ |
+ views::BubbleBorder* bubble_border = new views::BubbleBorder(views::BubbleBorder::NONE); |
+ bubble_border->set_background_color(Bubble::kBackgroundColor); |
+ set_background(new views::BubbleBackground(bubble_border)); |
+ set_border(bubble_border); |
+ |
+ accept_button_ = new views::NativeTextButton(this, |
+ UTF16ToWide(l10n_util::GetStringUTF16(IDS_FULLSCREEN_INFOBAR_ALLOW))); |
+ AddChildView(accept_button_); |
+ |
+ deny_button_ = new views::NativeTextButton(this, |
+ UTF16ToWide(l10n_util::GetStringUTF16(IDS_FULLSCREEN_INFOBAR_DENY))); |
+ AddChildView(deny_button_); |
+ accept_button_->set_focusable(false); |
+ deny_button_->set_focusable(false); |
+ link_.SetVisible(false); |
+ if (!show_buttons_) { |
+ HideButtons(); |
+ } |
} |
FullscreenExitBubbleViews::FullscreenExitView::~FullscreenExitView() { |
} |
+void FullscreenExitBubbleViews::FullscreenExitView::ButtonPressed( |
+ views::Button* sender, const views::Event& event) { |
+ if (sender == accept_button_) |
+ bubble_->OnAcceptFullscreen(); |
+ else |
+ bubble_->OnCancelFullscreen(); |
+} |
+ |
+void FullscreenExitBubbleViews::FullscreenExitView::HideButtons() { |
+ show_buttons_ = false; |
+ accept_button_->SetVisible(false); |
+ deny_button_->SetVisible(false); |
+ link_.SetVisible(true); |
+} |
+ |
gfx::Size FullscreenExitBubbleViews::FullscreenExitView::GetPreferredSize() { |
- gfx::Size preferred_size(link_.GetPreferredSize()); |
- preferred_size.Enlarge(kPaddingPx * 2, kPaddingPx * 2); |
- return preferred_size; |
+ gfx::Size link_preferred_size(link_.GetPreferredSize()); |
+ gfx::Size site_info_preferred_size(site_info_.GetPreferredSize()); |
+ gfx::Size accept_preferred_size(accept_button_->GetPreferredSize()); |
+ gfx::Size deny_preferred_size(deny_button_->GetPreferredSize()); |
+ gfx::Insets insets(GetInsets()); |
+ |
+ int buttons_width = accept_preferred_size.width() + kPaddingPx + |
+ deny_preferred_size.width(); |
+ int button_box_width = std::max(buttons_width, link_preferred_size.width()); |
+ int width = kPaddingPx + site_info_preferred_size.width() + kMiddlePaddingPx + |
+ button_box_width + kPaddingPx; |
+ |
+ gfx::Size result(width + insets.width(), |
+ kPaddingPx * 2 + accept_preferred_size.height() + insets.height()); |
+ return result; |
} |
void FullscreenExitBubbleViews::FullscreenExitView::Layout() { |
gfx::Size link_preferred_size(link_.GetPreferredSize()); |
- link_.SetBounds(kPaddingPx, |
- height() - kPaddingPx - link_preferred_size.height(), |
- link_preferred_size.width(), link_preferred_size.height()); |
-} |
+ gfx::Size site_info_preferred_size(site_info_.GetPreferredSize()); |
+ gfx::Size accept_preferred_size(accept_button_->GetPreferredSize()); |
+ gfx::Size deny_preferred_size(deny_button_->GetPreferredSize()); |
+ gfx::Insets insets(GetInsets()); |
-void FullscreenExitBubbleViews::FullscreenExitView::OnPaint( |
- gfx::Canvas* canvas) { |
- // Create a round-bottomed rect to fill the whole View. |
- SkRect rect; |
- SkScalar padding = SkIntToScalar(kPaddingPx); |
- // The "-padding" top coordinate ensures that the rect is always tall enough |
- // to contain the complete rounded corner radius. If we set this to 0, as the |
- // popup slides offscreen (in reality, squishes to 0 height), the corners will |
- // flatten out as the height becomes less than the corner radius. |
- rect.set(0, -padding, SkIntToScalar(width()), SkIntToScalar(height())); |
- SkScalar rad[8] = { 0, 0, 0, 0, padding, padding, padding, padding }; |
- SkPath path; |
- path.addRoundRect(rect, rad, SkPath::kCW_Direction); |
- |
- // Fill it black. |
- SkPaint paint; |
- paint.setStyle(SkPaint::kFill_Style); |
- paint.setFlags(SkPaint::kAntiAlias_Flag); |
- paint.setColor(SK_ColorBLACK); |
- canvas->GetSkCanvas()->drawPath(path, paint); |
+ int inner_height = height() - insets.height(); |
+ int button_box_x = insets.left() + kPaddingPx + site_info_preferred_size.width() + |
+ kMiddlePaddingPx; |
+ int site_info_y = insets.top() + |
+ (inner_height - site_info_preferred_size.height()) / 2; |
+ int link_y = insets.top() + (inner_height - link_preferred_size.height()) / 2; |
+ |
+ site_info_.SetBounds(insets.left() + kPaddingPx, |
+ site_info_y, |
+ site_info_preferred_size.width(), |
+ site_info_preferred_size.height()); |
+ link_.SetBounds(width() - insets.right() - kPaddingPx - link_preferred_size.width(), |
+ link_y, |
+ link_preferred_size.width(), link_preferred_size.height()); |
+ if (show_buttons_) { |
+ accept_button_->SetBounds(button_box_x, |
+ insets.top() + kPaddingPx, |
+ accept_preferred_size.width(), |
+ accept_preferred_size.height()); |
+ deny_button_->SetBounds( |
+ button_box_x + accept_preferred_size.width() + kPaddingPx, |
+ insets.top() + kPaddingPx, |
+ deny_preferred_size.width(), |
+ deny_preferred_size.height()); |
+ } |
} |
// FullscreenExitBubbleViews --------------------------------------------------- |
FullscreenExitBubbleViews::FullscreenExitBubbleViews( |
views::Widget* frame, |
- CommandUpdater::CommandUpdaterDelegate* delegate) |
- : FullscreenExitBubble(delegate), |
+ Browser* browser, |
+ const GURL& url, |
+ bool show_buttons) |
+ : FullscreenExitBubble(browser), |
root_view_(frame->GetRootView()), |
popup_(NULL), |
- size_animation_(new ui::SlideAnimation(this)) { |
+ size_animation_(new ui::SlideAnimation(this)), |
+ url_(url) { |
size_animation_->Reset(1); |
// Create the contents view. |
@@ -115,7 +205,7 @@ FullscreenExitBubbleViews::FullscreenExitBubbleViews( |
bool got_accelerator = frame->GetAccelerator(IDC_FULLSCREEN, &accelerator); |
DCHECK(got_accelerator); |
view_ = new FullscreenExitView( |
- this, UTF16ToWideHack(accelerator.GetShortcutText())); |
+ this, UTF16ToWideHack(accelerator.GetShortcutText()), url, show_buttons); |
// Initialize the popup. |
popup_ = new views::Widget; |
@@ -126,11 +216,14 @@ FullscreenExitBubbleViews::FullscreenExitBubbleViews( |
params.parent = frame->GetNativeView(); |
params.bounds = GetPopupRect(false); |
popup_->Init(params); |
+ gfx::Size size = GetPopupRect(true).size(); |
popup_->SetContentsView(view_); |
- popup_->SetOpacity(static_cast<unsigned char>(0xff * kOpacity)); |
+ popup_->GetRootView()->SetLayoutManager(NULL); |
+ view_->SetBounds(0, 0, size.width(), size.height()); |
popup_->Show(); // This does not activate the popup. |
- StartWatchingMouse(); |
+ if (!show_buttons) |
+ StartWatchingMouse(); |
} |
FullscreenExitBubbleViews::~FullscreenExitBubbleViews() { |
@@ -152,6 +245,16 @@ void FullscreenExitBubbleViews::LinkClicked( |
ToggleFullscreen(); |
} |
+void FullscreenExitBubbleViews::OnAcceptFullscreen() { |
+ AcceptFullscreen(url_); |
+ view_->HideButtons(); |
+ StartWatchingMouse(); |
+} |
+ |
+void FullscreenExitBubbleViews::OnCancelFullscreen() { |
+ CancelFullscreen(); |
+} |
+ |
void FullscreenExitBubbleViews::AnimationProgressed( |
const ui::Animation* animation) { |
gfx::Rect popup_rect(GetPopupRect(false)); |
@@ -159,9 +262,11 @@ void FullscreenExitBubbleViews::AnimationProgressed( |
popup_->Hide(); |
} else { |
popup_->SetBounds(popup_rect); |
+ view_->SetY(popup_rect.height() - view_->height()); |
popup_->Show(); |
} |
} |
+ |
void FullscreenExitBubbleViews::AnimationEnded( |
const ui::Animation* animation) { |
AnimationProgressed(animation); |