Implements the "Set to default" button on the zoom bubble.

BUG=128816
TEST=


Review URL: https://chromiumcodereview.appspot.com/10792020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149965 0039d316-1c4b-4281-b951-d872f2087c98
parent 36c01347
......@@ -275,7 +275,7 @@ void LocationBarView::Init(views::View* popup_parent_view) {
content_blocked_view->SetVisible(false);
}
zoom_view_ = new ZoomView(model_);
zoom_view_ = new ZoomView(model_, delegate_);
AddChildView(zoom_view_);
if (extensions::switch_utils::IsActionBoxEnabled()) {
......@@ -533,7 +533,7 @@ void LocationBarView::SetZoomIconState(
}
void LocationBarView::ShowZoomBubble(int zoom_percent) {
ZoomBubbleView::ShowBubble(zoom_view_, zoom_percent, true);
ZoomBubbleView::ShowBubble(zoom_view_, GetTabContents(), true);
}
void LocationBarView::ShowChromeToMobileBubble() {
......@@ -1304,7 +1304,7 @@ void LocationBarView::WriteDragDataForView(views::View* sender,
DCHECK_NE(GetDragOperationsForView(sender, press_pt),
ui::DragDropTypes::DRAG_NONE);
TabContents* tab_contents = delegate_->GetTabContents();
TabContents* tab_contents = GetTabContents();
DCHECK(tab_contents);
gfx::ImageSkia favicon =
tab_contents->favicon_tab_helper()->GetFavicon().AsImageSkia();
......
......@@ -4,18 +4,28 @@
#include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
#include "base/bind.h"
#include "base/message_loop.h"
#include "chrome/browser/chrome_page_zoom.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "chrome/browser/ui/zoom/zoom_controller.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/controls/separator.h"
#include "ui/views/layout/box_layout.h"
#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 for if it
// will automatically close.
const int kBubbleCloseDelay = 400;
// The number of milliseconds the bubble should stay on the screen if it will
// close automatically.
const int kBubbleCloseDelay = 1500;
// The number of pixels between the separator and the button.
const int kSeparatorButtonSpacing = 2;
// How many pixels larger the percentage label font should be, compared to the
// default font.
const int kPercentageFontIncrease = 5;
} // namespace
......@@ -24,7 +34,7 @@ ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL;
// static
void ZoomBubbleView::ShowBubble(views::View* anchor_view,
int zoom_percent,
TabContents* tab_contents,
bool auto_close) {
// If the bubble is already showing in this window and its |auto_close_| value
// is equal to |auto_close|, the bubble can be reused and only the label text
......@@ -32,15 +42,7 @@ void ZoomBubbleView::ShowBubble(views::View* anchor_view,
if (zoom_bubble_ &&
zoom_bubble_->anchor_view() == anchor_view &&
zoom_bubble_->auto_close_ == auto_close) {
zoom_bubble_->label_->SetText(
l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent));
if (auto_close) {
// If the bubble should be closed automatically, reset the timer so that
// it will show for the full amount of time instead of only what remained
// from the previous time.
zoom_bubble_->timer_.Reset();
}
zoom_bubble_->Refresh();
} else {
// If the bubble is already showing but its |auto_close_| value is not equal
// to |auto_close|, the bubble's focus properties must change, so the
......@@ -48,7 +50,7 @@ void ZoomBubbleView::ShowBubble(views::View* anchor_view,
if (zoom_bubble_)
zoom_bubble_->Close();
zoom_bubble_ = new ZoomBubbleView(anchor_view, zoom_percent, auto_close);
zoom_bubble_ = new ZoomBubbleView(anchor_view, tab_contents, auto_close);
views::BubbleDelegateView::CreateBubble(zoom_bubble_);
zoom_bubble_->Show();
}
......@@ -66,28 +68,37 @@ bool ZoomBubbleView::IsShowing() {
}
ZoomBubbleView::ZoomBubbleView(views::View* anchor_view,
int zoom_percent,
TabContents* tab_contents,
bool auto_close)
: BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
label_(NULL),
zoom_percent_(zoom_percent),
tab_contents_(tab_contents),
auto_close_(auto_close) {
set_use_focusless(auto_close);
set_notify_enter_exit_on_child(true);
}
ZoomBubbleView::~ZoomBubbleView() {
}
void ZoomBubbleView::Refresh() {
int zoom_percent = tab_contents_->zoom_controller()->zoom_percent();
label_->SetText(
l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent));
if (auto_close_) {
// If the bubble should be closed automatically, reset the timer so that
// it will show for the full amount of time instead of only what remained
// from the previous time.
timer_.Reset();
}
}
void ZoomBubbleView::Close() {
GetWidget()->Close();
}
void ZoomBubbleView::Init() {
SetLayoutManager(new views::FillLayout());
label_ = new views::Label(
l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent_));
AddChildView(label_);
void ZoomBubbleView::StartTimerIfNecessary() {
if (auto_close_) {
timer_.Start(
FROM_HERE,
......@@ -97,6 +108,52 @@ void ZoomBubbleView::Init() {
}
}
void ZoomBubbleView::StopTimer() {
timer_.Stop();
}
void ZoomBubbleView::OnMouseEntered(const views::MouseEvent& event) {
StopTimer();
}
void ZoomBubbleView::OnMouseExited(const views::MouseEvent& event) {
StartTimerIfNecessary();
}
void ZoomBubbleView::ButtonPressed(views::Button* sender,
const views::Event& event) {
chrome_page_zoom::Zoom(tab_contents_->web_contents(),
content::PAGE_ZOOM_RESET);
}
void ZoomBubbleView::Init() {
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical,
0, 0, views::kRelatedControlVerticalSpacing));
int zoom_percent = tab_contents_->zoom_controller()->zoom_percent();
label_ = new views::Label(
l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent));
gfx::Font font = label_->font().DeriveFont(kPercentageFontIncrease);
label_->SetFont(font);
AddChildView(label_);
AddChildView(new views::Separator());
views::TextButton* set_default_button = new views::TextButton(
this, l10n_util::GetStringUTF16(IDS_ZOOM_SET_DEFAULT));
set_default_button->set_alignment(views::TextButtonBase::ALIGN_CENTER);
AddChildView(set_default_button);
StartTimerIfNecessary();
}
gfx::Rect ZoomBubbleView::GetAnchorRect() {
// Compensate for some built-in padding in the zoom image.
gfx::Rect rect(BubbleDelegateView::GetAnchorRect());
rect.Inset(0, anchor_view() ? 5 : 0);
return rect;
}
void ZoomBubbleView::WindowClosing() {
DCHECK(zoom_bubble_ == this);
zoom_bubble_ = NULL;
......
......@@ -9,31 +9,53 @@
#include "base/timer.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/text_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/events/event.h"
class TabContents;
// View used to display the zoom percentage when it has changed.
class ZoomBubbleView : public views::BubbleDelegateView {
class ZoomBubbleView : public views::BubbleDelegateView,
public views::ButtonListener {
public:
// Shows the bubble and automatically closes it after a short time period if
// |auto_close| is true.
static void ShowBubble(views::View* anchor_view,
int zoom_percent,
TabContents* tab_contents,
bool auto_close);
static void CloseBubble();
static bool IsShowing();
private:
ZoomBubbleView(views::View* anchor_view,
int zoom_percent,
TabContents* tab_contents,
bool auto_close);
virtual ~ZoomBubbleView();
// Refreshes the bubble by changing the zoom percentage appropriately and
// resetting the timer if necessary.
void Refresh();
void Close();
// Starts a timer which will close the bubble if |auto_close_| is true.
void StartTimerIfNecessary();
// Stops the auto-close timer.
void StopTimer();
// views::View method.
virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE;
// views::ButtonListener method.
virtual void ButtonPressed(views::Button* sender,
const views::Event& event) OVERRIDE;
// views::BubbleDelegateView method.
virtual void Init() OVERRIDE;
// views::BubbleDelegateView:
virtual gfx::Rect GetAnchorRect() OVERRIDE;
virtual void WindowClosing() OVERRIDE;
// Singleton instance of the zoom bubble. The zoom bubble can only be shown on
......@@ -47,8 +69,8 @@ class ZoomBubbleView : public views::BubbleDelegateView {
// Label displaying the zoom percentage.
views::Label* label_;
// The zoom percentage to show in the bubble.
int zoom_percent_;
// The TabContents for the page whose zoom has changed.
TabContents* tab_contents_;
// Whether the currently displayed bubble will automatically close.
bool auto_close_;
......
......@@ -14,8 +14,10 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/size.h"
ZoomView::ZoomView(ToolbarModel* toolbar_model)
ZoomView::ZoomView(ToolbarModel* toolbar_model,
LocationBarView::Delegate* location_bar_delegate)
: toolbar_model_(toolbar_model),
location_bar_delegate_(location_bar_delegate),
zoom_icon_state_(ZoomController::NONE),
zoom_percent_(100) {
set_accessibility_focusable(true);
......@@ -71,8 +73,10 @@ bool ZoomView::OnMousePressed(const views::MouseEvent& event) {
}
void ZoomView::OnMouseReleased(const views::MouseEvent& event) {
if (event.IsOnlyLeftMouseButton() && HitTest(event.location()))
ZoomBubbleView::ShowBubble(this, zoom_percent_, false);
if (event.IsOnlyLeftMouseButton() && HitTest(event.location())) {
ZoomBubbleView::ShowBubble(
this, location_bar_delegate_->GetTabContents(), false);
}
}
bool ZoomView::OnKeyPressed(const views::KeyEvent& event) {
......@@ -80,6 +84,7 @@ bool ZoomView::OnKeyPressed(const views::KeyEvent& event) {
event.key_code() != ui::VKEY_RETURN)
return false;
ZoomBubbleView::ShowBubble(this, zoom_percent_, false);
ZoomBubbleView::ShowBubble(
this, location_bar_delegate_->GetTabContents(), false);
return true;
}
......@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "chrome/browser/ui/toolbar/toolbar_model.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/zoom/zoom_controller.h"
#include "ui/views/controls/image_view.h"
......@@ -18,7 +19,13 @@ class MouseEvent;
// View for the zoom icon in the Omnibox.
class ZoomView : public views::ImageView {
public:
explicit ZoomView(ToolbarModel* toolbar_model);
// Constructor for ZoomView. Clicking on the ZoomView shows a ZoomBubbleView,
// which requires the current TabContents. Because the current TabContents
// changes as the user switches tabs, it cannot be provided in the
// constructor. Instead, a LocationBarView::Delegate is passed here so that
// it can be queried for the current TabContents as needed.
ZoomView(ToolbarModel* toolbar_model,
LocationBarView::Delegate* location_bar_delegate);
virtual ~ZoomView();
void SetZoomIconState(ZoomController::ZoomIconState zoom_icon_state);
......@@ -40,6 +47,9 @@ class ZoomView : public views::ImageView {
// Toolbar model used to test whether location bar input is in progress.
ToolbarModel* toolbar_model_;
// The delegate used to get the currently visible TabContents.
LocationBarView::Delegate* location_bar_delegate_;
// The current icon state.
ZoomController::ZoomIconState zoom_icon_state_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment