| Index: chrome/browser/ui/views/location_bar/zoom_bubble_view.cc
|
| diff --git a/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc b/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc
|
| index 354d3918d17442d49c7320a612471e86a1319395..49db0318af1ad98662f04ec6ab0398c4d4793906 100644
|
| --- a/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc
|
| +++ b/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc
|
| @@ -32,17 +32,6 @@
|
| #include "ui/views/layout/layout_constants.h"
|
| #include "ui/views/widget/widget.h"
|
|
|
| -namespace {
|
| -
|
| -// The number of milliseconds the bubble should stay on the screen if it will
|
| -// close automatically.
|
| -const int kBubbleCloseDelay = 1500;
|
| -
|
| -// The bubble's padding from the screen edge, used in fullscreen.
|
| -const int kFullscreenPaddingEnd = 20;
|
| -
|
| -} // namespace
|
| -
|
| // static
|
| ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL;
|
|
|
| @@ -131,8 +120,7 @@ ZoomBubbleView::ZoomBubbleView(
|
| bool auto_close,
|
| ImmersiveModeController* immersive_mode_controller,
|
| FullscreenController* fullscreen_controller)
|
| - : BubbleDelegateView(anchor_view, anchor_view ?
|
| - views::BubbleBorder::TOP_RIGHT : views::BubbleBorder::NONE),
|
| + : ManagedFullScreenBubbleDelegateView(anchor_view, web_contents),
|
| image_button_(NULL),
|
| label_(NULL),
|
| web_contents_(web_contents),
|
| @@ -141,12 +129,6 @@ ZoomBubbleView::ZoomBubbleView(
|
| // Compensate for built-in vertical padding in the anchor view's image.
|
| set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
|
| set_notify_enter_exit_on_child(true);
|
| -
|
| - // Add observers to close the bubble if the fullscreen state or immersive
|
| - // fullscreen revealed state changes.
|
| - registrar_.Add(this,
|
| - chrome::NOTIFICATION_FULLSCREEN_CHANGED,
|
| - content::Source<FullscreenController>(fullscreen_controller));
|
| immersive_mode_controller_->AddObserver(this);
|
| }
|
|
|
| @@ -155,33 +137,130 @@ ZoomBubbleView::~ZoomBubbleView() {
|
| immersive_mode_controller_->RemoveObserver(this);
|
| }
|
|
|
| -void ZoomBubbleView::AdjustForFullscreen(const gfx::Rect& screen_bounds) {
|
| - if (GetAnchorView())
|
| +void ZoomBubbleView::OnGestureEvent(ui::GestureEvent* event) {
|
| + if (!zoom_bubble_ || !zoom_bubble_->auto_close_ ||
|
| + event->type() != ui::ET_GESTURE_TAP) {
|
| return;
|
| + }
|
|
|
| - // TODO(dbeam): should RTL logic be done in views::BubbleDelegateView?
|
| - const size_t bubble_half_width = width() / 2;
|
| - const int x_pos = base::i18n::IsRTL() ?
|
| - screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd :
|
| - screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd;
|
| - SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0));
|
| + auto_close_ = false;
|
| + StopTimer();
|
| + event->SetHandled();
|
| }
|
|
|
| -void ZoomBubbleView::Refresh() {
|
| +void ZoomBubbleView::OnMouseEntered(const ui::MouseEvent& event) {
|
| + StopTimer();
|
| +}
|
| +
|
| +void ZoomBubbleView::OnMouseExited(const ui::MouseEvent& event) {
|
| + StartTimerIfNecessary();
|
| +}
|
| +
|
| +void ZoomBubbleView::Init() {
|
| + // Set up the layout of the zoom bubble. A grid layout is used because
|
| + // sometimes an extension icon is shown next to the zoom label.
|
| + views::GridLayout* grid_layout = new views::GridLayout(this);
|
| + SetLayoutManager(grid_layout);
|
| + views::ColumnSet* columns = grid_layout->AddColumnSet(0);
|
| + // First row.
|
| + if (extension_info_.icon_image) {
|
| + columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 2,
|
| + views::GridLayout::USE_PREF, 0, 0);
|
| + }
|
| + columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
|
| + views::GridLayout::USE_PREF, 0, 0);
|
| + grid_layout->StartRow(0, 0);
|
| +
|
| + // If this zoom change was initiated by an extension, that extension will be
|
| + // attributed by showing its icon in the zoom bubble.
|
| + if (extension_info_.icon_image) {
|
| + image_button_ = new views::ImageButton(this);
|
| + image_button_->SetTooltipText(
|
| + l10n_util::GetStringFUTF16(IDS_TOOLTIP_ZOOM_EXTENSION_ICON,
|
| + base::UTF8ToUTF16(extension_info_.name)));
|
| + image_button_->SetImage(views::Button::STATE_NORMAL,
|
| + &extension_info_.icon_image->image_skia());
|
| + grid_layout->AddView(image_button_);
|
| + }
|
| +
|
| + // Add zoom label with the new zoom percent.
|
| ui_zoom::ZoomController* zoom_controller =
|
| ui_zoom::ZoomController::FromWebContents(web_contents_);
|
| int zoom_percent = zoom_controller->GetZoomPercent();
|
| - label_->SetText(
|
| + label_ = new views::Label(
|
| l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent));
|
| + label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
|
| + ui::ResourceBundle::MediumFont));
|
| + grid_layout->AddView(label_);
|
| +
|
| + // Second row.
|
| + grid_layout->AddPaddingRow(0, 8);
|
| + columns = grid_layout->AddColumnSet(1);
|
| + columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
|
| + views::GridLayout::USE_PREF, 0, 0);
|
| + grid_layout->StartRow(0, 1);
|
| +
|
| + // Add "Reset to Default" button.
|
| + views::LabelButton* set_default_button = new views::LabelButton(
|
| + this, l10n_util::GetStringUTF16(IDS_ZOOM_SET_DEFAULT));
|
| + set_default_button->SetStyle(views::Button::STYLE_BUTTON);
|
| + set_default_button->SetHorizontalAlignment(gfx::ALIGN_CENTER);
|
| + grid_layout->AddView(set_default_button);
|
| +
|
| StartTimerIfNecessary();
|
| }
|
|
|
| +void ZoomBubbleView::WindowClosing() {
|
| + // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't
|
| + // call this right away). Only set to NULL when it's this bubble.
|
| + if (zoom_bubble_ == this)
|
| + zoom_bubble_ = NULL;
|
| +}
|
| +
|
| void ZoomBubbleView::Close() {
|
| // Widget's Close() is async, but we don't want to use zoom_bubble_ after
|
| // this. Additionally web_contents_ may have been destroyed.
|
| zoom_bubble_ = NULL;
|
| web_contents_ = NULL;
|
| - GetWidget()->Close();
|
| + ManagedFullScreenBubbleDelegateView::Close();
|
| +}
|
| +
|
| +void ZoomBubbleView::ButtonPressed(views::Button* sender,
|
| + const ui::Event& event) {
|
| + if (sender == image_button_) {
|
| + DCHECK(extension_info_.icon_image) << "Invalid button press.";
|
| + Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
|
| + chrome::AddSelectedTabWithURL(
|
| + browser, GURL(base::StringPrintf("chrome://extensions?id=%s",
|
| + extension_info_.id.c_str())),
|
| + ui::PAGE_TRANSITION_FROM_API);
|
| + } else {
|
| + chrome_page_zoom::Zoom(web_contents_, content::PAGE_ZOOM_RESET);
|
| + }
|
| +}
|
| +
|
| +void ZoomBubbleView::OnImmersiveRevealStarted() {
|
| + CloseBubble();
|
| +}
|
| +
|
| +void ZoomBubbleView::OnImmersiveModeControllerDestroyed() {
|
| + immersive_mode_controller_ = NULL;
|
| +}
|
| +
|
| +void ZoomBubbleView::OnExtensionIconImageChanged(
|
| + extensions::IconImage* /* image */) {
|
| + image_button_->SetImage(views::Button::STATE_NORMAL,
|
| + &extension_info_.icon_image->image_skia());
|
| + image_button_->SchedulePaint();
|
| +}
|
| +
|
| +void ZoomBubbleView::Refresh() {
|
| + ui_zoom::ZoomController* zoom_controller =
|
| + ui_zoom::ZoomController::FromWebContents(web_contents_);
|
| + int zoom_percent = zoom_controller->GetZoomPercent();
|
| + label_->SetText(
|
| + l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent));
|
| + StartTimerIfNecessary();
|
| }
|
|
|
| void ZoomBubbleView::SetExtensionInfo(const extensions::Extension* extension) {
|
| @@ -233,6 +312,9 @@ void ZoomBubbleView::StartTimerIfNecessary() {
|
| if (timer_.IsRunning()) {
|
| timer_.Reset();
|
| } else {
|
| + // The number of milliseconds the bubble should stay on the screen if it
|
| + // will close automatically.
|
| + const int kBubbleCloseDelay = 1500;
|
| timer_.Start(
|
| FROM_HERE,
|
| base::TimeDelta::FromMilliseconds(kBubbleCloseDelay),
|
| @@ -246,124 +328,6 @@ void ZoomBubbleView::StopTimer() {
|
| timer_.Stop();
|
| }
|
|
|
| -void ZoomBubbleView::OnExtensionIconImageChanged(
|
| - extensions::IconImage* /* image */) {
|
| - image_button_->SetImage(views::Button::STATE_NORMAL,
|
| - &extension_info_.icon_image->image_skia());
|
| - image_button_->SchedulePaint();
|
| -}
|
| -
|
| -void ZoomBubbleView::OnMouseEntered(const ui::MouseEvent& event) {
|
| - StopTimer();
|
| -}
|
| -
|
| -void ZoomBubbleView::OnMouseExited(const ui::MouseEvent& event) {
|
| - StartTimerIfNecessary();
|
| -}
|
| -
|
| -void ZoomBubbleView::OnGestureEvent(ui::GestureEvent* event) {
|
| - if (!zoom_bubble_ || !zoom_bubble_->auto_close_ ||
|
| - event->type() != ui::ET_GESTURE_TAP) {
|
| - return;
|
| - }
|
| -
|
| - auto_close_ = false;
|
| - StopTimer();
|
| - event->SetHandled();
|
| -}
|
| -
|
| -void ZoomBubbleView::ButtonPressed(views::Button* sender,
|
| - const ui::Event& event) {
|
| - if (sender == image_button_) {
|
| - DCHECK(extension_info_.icon_image) << "Invalid button press.";
|
| - Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
|
| - chrome::AddSelectedTabWithURL(
|
| - browser,
|
| - GURL(base::StringPrintf("chrome://extensions?id=%s",
|
| - extension_info_.id.c_str())),
|
| - ui::PAGE_TRANSITION_FROM_API);
|
| - } else {
|
| - chrome_page_zoom::Zoom(web_contents_, content::PAGE_ZOOM_RESET);
|
| - }
|
| -}
|
| -
|
| -void ZoomBubbleView::Init() {
|
| - // Set up the layout of the zoom bubble. A grid layout is used because
|
| - // sometimes an extension icon is shown next to the zoom label.
|
| - views::GridLayout* grid_layout = new views::GridLayout(this);
|
| - SetLayoutManager(grid_layout);
|
| - views::ColumnSet* columns = grid_layout->AddColumnSet(0);
|
| - // First row.
|
| - if (extension_info_.icon_image) {
|
| - columns->AddColumn(views::GridLayout::CENTER,views::GridLayout::CENTER, 2,
|
| - views::GridLayout::USE_PREF, 0, 0);
|
| - }
|
| - columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
|
| - views::GridLayout::USE_PREF, 0, 0);
|
| - grid_layout->StartRow(0, 0);
|
| -
|
| - // If this zoom change was initiated by an extension, that extension will be
|
| - // attributed by showing its icon in the zoom bubble.
|
| - if (extension_info_.icon_image) {
|
| - image_button_ = new views::ImageButton(this);
|
| - image_button_->SetTooltipText(l10n_util::GetStringFUTF16(
|
| - IDS_TOOLTIP_ZOOM_EXTENSION_ICON,
|
| - base::UTF8ToUTF16(extension_info_.name)));
|
| - image_button_->SetImage(views::Button::STATE_NORMAL,
|
| - &extension_info_.icon_image->image_skia());
|
| - grid_layout->AddView(image_button_);
|
| - }
|
| -
|
| - // Add zoom label with the new zoom percent.
|
| - ui_zoom::ZoomController* zoom_controller =
|
| - ui_zoom::ZoomController::FromWebContents(web_contents_);
|
| - int zoom_percent = zoom_controller->GetZoomPercent();
|
| - label_ = new views::Label(
|
| - l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent));
|
| - label_->SetFontList(
|
| - ui::ResourceBundle::GetSharedInstance().GetFontList(
|
| - ui::ResourceBundle::MediumFont));
|
| - grid_layout->AddView(label_);
|
| -
|
| - // Second row.
|
| - grid_layout->AddPaddingRow(0, 8);
|
| - columns = grid_layout->AddColumnSet(1);
|
| - columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
|
| - views::GridLayout::USE_PREF, 0, 0);
|
| - grid_layout->StartRow(0, 1);
|
| -
|
| - // Add "Reset to Default" button.
|
| - views::LabelButton* set_default_button = new views::LabelButton(
|
| - this, l10n_util::GetStringUTF16(IDS_ZOOM_SET_DEFAULT));
|
| - set_default_button->SetStyle(views::Button::STYLE_BUTTON);
|
| - set_default_button->SetHorizontalAlignment(gfx::ALIGN_CENTER);
|
| - grid_layout->AddView(set_default_button);
|
| -
|
| - StartTimerIfNecessary();
|
| -}
|
| -
|
| -void ZoomBubbleView::Observe(int type,
|
| - const content::NotificationSource& source,
|
| - const content::NotificationDetails& details) {
|
| - DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED);
|
| - CloseBubble();
|
| -}
|
| -
|
| -void ZoomBubbleView::OnImmersiveRevealStarted() {
|
| - CloseBubble();
|
| -}
|
| -
|
| -void ZoomBubbleView::OnImmersiveModeControllerDestroyed() {
|
| - immersive_mode_controller_ = NULL;
|
| -}
|
| -
|
| -void ZoomBubbleView::WindowClosing() {
|
| - // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't
|
| - // call this right away). Only set to NULL when it's this bubble.
|
| - if (zoom_bubble_ == this)
|
| - zoom_bubble_ = NULL;
|
| -}
|
| -
|
| ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {}
|
|
|
| ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {}
|
|
|