Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3992)

Unified Diff: chrome/browser/ui/views/location_bar/zoom_bubble_view.cc

Issue 10792020: Implements the "Set to default" button on the zoom bubble. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Removed .gitmodules, oops Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 d59327d3e157fb54fa293e7c9c31fd7886d815b9..7a42e151b3d2f5883ceb653b3e4fb2cc3705ed08 100644
--- a/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc
+++ b/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc
@@ -6,16 +6,33 @@
#include "base/bind.h"
#include "base/message_loop.h"
+#include "chrome/browser/chrome_page_zoom.h"
+#include "chrome/browser/prefs/pref_service.h"
Peter Kasting 2012/08/03 19:24:23 Nit: I think this is no longer necessary, maybe a
Kyle Horimoto 2012/08/03 22:20:44 Done.
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/tab_contents/tab_contents.h"
+#include "chrome/browser/ui/zoom/zoom_controller.h"
+#include "chrome/common/pref_names.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/render_view_host.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 +41,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 +49,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 +57,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 +75,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 +115,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;
« no previous file with comments | « chrome/browser/ui/views/location_bar/zoom_bubble_view.h ('k') | chrome/browser/ui/views/location_bar/zoom_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698