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 01c1ad62c97d2e6d9182241edc814b16ffbaf061..c0dfc37e1c3b64df3f9db07241fd40480a0b1fe7 100644 |
--- a/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc |
+++ b/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc |
@@ -6,9 +6,18 @@ |
#include "base/bind.h" |
#include "base/message_loop.h" |
+#include "chrome/common/pref_names.h" |
+#include "chrome/browser/prefs/pref_service.h" |
+#include "chrome/browser/profiles/profile.h" |
+#include "chrome/browser/ui/tab_contents/tab_contents.h" |
+#include "chrome/browser/ui/zoom/zoom_controller.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/button/text_button.h" |
+#include "ui/views/controls/separator.h" |
+#include "ui/views/layout/box_layout.h" |
namespace { |
@@ -16,6 +25,15 @@ namespace { |
// will automatically close. |
const int kBubbleCloseDelay = 400; |
+// The number of pixels between the percentage label and the separator. |
+const int kPercentageSeparatorSpacing = 7; |
Peter Kasting
2012/07/18 03:26:30
These should be using standardized values from lay
Kyle Horimoto
2012/07/18 23:49:38
Done.
|
+ |
+// The number of pixels between the separator and the button. |
+const int kSeparatorButtonSpacing = 2; |
+ |
+// The font size of the percentage label. |
+const int kPercentageFontSize = 20; |
Peter Kasting
2012/07/18 03:26:30
This should not be hard-coded, because otherwise i
Kyle Horimoto
2012/07/18 23:49:38
Done.
|
+ |
} |
// static |
@@ -23,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 |
@@ -31,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 |
@@ -47,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(); |
} |
@@ -65,11 +75,11 @@ 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); |
} |
@@ -77,14 +87,41 @@ ZoomBubbleView::ZoomBubbleView(views::View* anchor_view, |
ZoomBubbleView::~ZoomBubbleView() { |
} |
+void ZoomBubbleView::Refresh() { |
+ int zoom_percent = tab_contents_->zoom_controller()->zoom_percent(); |
+ 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. |
+ timer_.Reset(); |
+ } |
+} |
+ |
void ZoomBubbleView::Close() { |
GetWidget()->Close(); |
} |
+void ZoomBubbleView::ButtonPressed(views::Button* sender, |
+ const views::Event& event) { |
+ double default_zoom_level = Profile::FromBrowserContext( |
+ tab_contents_->web_contents()->GetBrowserContext())-> |
Peter Kasting
2012/07/18 03:26:30
Nit: Just use tab_contents_->profile()
Kyle Horimoto
2012/07/18 23:49:38
Done.
|
+ GetPrefs()->GetDouble(prefs::kDefaultZoomLevel); |
+ tab_contents_->web_contents()->GetRenderViewHost()-> |
+ SetZoomLevel(default_zoom_level); |
+} |
+ |
void ZoomBubbleView::Init() { |
- SetLayoutManager(new views::FillLayout()); |
+ SetLayoutManager(new views::BoxLayout( |
+ views::BoxLayout::kVertical, 0, 0, kPercentageSeparatorSpacing)); |
+ |
+ int zoom_percent = tab_contents_->zoom_controller()->zoom_percent(); |
label_ = new views::Label( |
- l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent_)); |
+ l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent)); |
+ gfx::Font font(label_->font().GetFontName(), kPercentageFontSize); |
+ label_->SetFont(font); |
AddChildView(label_); |
if (auto_close_) { |
Peter Kasting
2012/07/18 03:26:30
Wait, so in the auto-close case, no button is avai
Kyle Horimoto
2012/07/18 23:49:38
Done.
|
@@ -93,6 +130,15 @@ void ZoomBubbleView::Init() { |
base::TimeDelta::FromMilliseconds(kBubbleCloseDelay), |
this, |
&ZoomBubbleView::Close); |
+ } else { |
+ views::View* container = new views::View(); |
+ container->SetLayoutManager(new views::BoxLayout( |
Peter Kasting
2012/07/18 03:26:31
Why do you need a child container with its own lay
Kyle Horimoto
2012/07/18 23:49:38
This was so that there could be a different spacin
|
+ views::BoxLayout::kVertical, 0, 0, kSeparatorButtonSpacing)); |
+ container->AddChildView(new views::Separator()); |
+ container->AddChildView(new views::TextButton( |
+ this, l10n_util::GetStringUTF16(IDS_ZOOM_SET_DEFAULT))); |
+ |
+ AddChildView(container); |
} |
} |