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

Side by Side 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: Addressed tfarina's comments Created 8 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" 5 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "chrome/common/pref_names.h"
10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/tab_contents/tab_contents.h"
13 #include "chrome/browser/ui/zoom/zoom_controller.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/render_view_host.h"
9 #include "grit/generated_resources.h" 16 #include "grit/generated_resources.h"
10 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/views/layout/fill_layout.h" 18 #include "ui/views/controls/button/text_button.h"
19 #include "ui/views/controls/separator.h"
20 #include "ui/views/layout/box_layout.h"
12 21
13 namespace { 22 namespace {
14 23
15 // The number of milliseconds the bubble should stay on the screen for if it 24 // The number of milliseconds the bubble should stay on the screen for if it
16 // will automatically close. 25 // will automatically close.
17 const int kBubbleCloseDelay = 400; 26 const int kBubbleCloseDelay = 400;
18 27
28 // The number of pixels between the percentage label and the separator.
29 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.
30
31 // The number of pixels between the separator and the button.
32 const int kSeparatorButtonSpacing = 2;
33
34 // The font size of the percentage label.
35 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.
36
19 } 37 }
20 38
21 // static 39 // static
22 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL; 40 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL;
23 41
24 // static 42 // static
25 void ZoomBubbleView::ShowBubble(views::View* anchor_view, 43 void ZoomBubbleView::ShowBubble(views::View* anchor_view,
26 int zoom_percent, 44 TabContents* tab_contents,
27 bool auto_close) { 45 bool auto_close) {
28 // If the bubble is already showing in this window and its |auto_close_| value 46 // If the bubble is already showing in this window and its |auto_close_| value
29 // is equal to |auto_close|, the bubble can be reused and only the label text 47 // is equal to |auto_close|, the bubble can be reused and only the label text
30 // needs to be updated. 48 // needs to be updated.
31 if (zoom_bubble_ && 49 if (zoom_bubble_ &&
32 zoom_bubble_->anchor_view() == anchor_view && 50 zoom_bubble_->anchor_view() == anchor_view &&
33 zoom_bubble_->auto_close_ == auto_close) { 51 zoom_bubble_->auto_close_ == auto_close) {
34 zoom_bubble_->label_->SetText( 52 zoom_bubble_->Refresh();
35 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent));
36
37 if (auto_close) {
38 // If the bubble should be closed automatically, reset the timer so that
39 // it will show for the full amount of time instead of only what remained
40 // from the previous time.
41 zoom_bubble_->timer_.Reset();
42 }
43 } else { 53 } else {
44 // If the bubble is already showing but its |auto_close_| value is not equal 54 // If the bubble is already showing but its |auto_close_| value is not equal
45 // to |auto_close|, the bubble's focus properties must change, so the 55 // to |auto_close|, the bubble's focus properties must change, so the
46 // current bubble must be closed and a new one created. 56 // current bubble must be closed and a new one created.
47 if (zoom_bubble_) 57 if (zoom_bubble_)
48 zoom_bubble_->Close(); 58 zoom_bubble_->Close();
49 59
50 zoom_bubble_ = new ZoomBubbleView(anchor_view, zoom_percent, auto_close); 60 zoom_bubble_ = new ZoomBubbleView(anchor_view, tab_contents, auto_close);
51 views::BubbleDelegateView::CreateBubble(zoom_bubble_); 61 views::BubbleDelegateView::CreateBubble(zoom_bubble_);
52 zoom_bubble_->Show(); 62 zoom_bubble_->Show();
53 } 63 }
54 } 64 }
55 65
56 // static 66 // static
57 void ZoomBubbleView::CloseBubble() { 67 void ZoomBubbleView::CloseBubble() {
58 if (zoom_bubble_) 68 if (zoom_bubble_)
59 zoom_bubble_->Close(); 69 zoom_bubble_->Close();
60 } 70 }
61 71
62 // static 72 // static
63 bool ZoomBubbleView::IsShowing() { 73 bool ZoomBubbleView::IsShowing() {
64 return zoom_bubble_ != NULL; 74 return zoom_bubble_ != NULL;
65 } 75 }
66 76
67 ZoomBubbleView::ZoomBubbleView(views::View* anchor_view, 77 ZoomBubbleView::ZoomBubbleView(views::View* anchor_view,
68 int zoom_percent, 78 TabContents* tab_contents,
69 bool auto_close) 79 bool auto_close)
70 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), 80 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
71 label_(NULL), 81 label_(NULL),
72 zoom_percent_(zoom_percent), 82 tab_contents_(tab_contents),
73 auto_close_(auto_close) { 83 auto_close_(auto_close) {
74 set_use_focusless(auto_close); 84 set_use_focusless(auto_close);
75 } 85 }
76 86
77 ZoomBubbleView::~ZoomBubbleView() { 87 ZoomBubbleView::~ZoomBubbleView() {
78 } 88 }
79 89
90 void ZoomBubbleView::Refresh() {
91 int zoom_percent = tab_contents_->zoom_controller()->zoom_percent();
92 label_->SetText(
93 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent));
94
95 if (auto_close_) {
96 // If the bubble should be closed automatically, reset the timer so that
97 // it will show for the full amount of time instead of only what remained
98 // from the previous time.
99 timer_.Reset();
100 }
101 }
102
80 void ZoomBubbleView::Close() { 103 void ZoomBubbleView::Close() {
81 GetWidget()->Close(); 104 GetWidget()->Close();
82 } 105 }
83 106
107 void ZoomBubbleView::ButtonPressed(views::Button* sender,
108 const views::Event& event) {
109 double default_zoom_level = Profile::FromBrowserContext(
110 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.
111 GetPrefs()->GetDouble(prefs::kDefaultZoomLevel);
112 tab_contents_->web_contents()->GetRenderViewHost()->
113 SetZoomLevel(default_zoom_level);
114 }
115
84 void ZoomBubbleView::Init() { 116 void ZoomBubbleView::Init() {
85 SetLayoutManager(new views::FillLayout()); 117 SetLayoutManager(new views::BoxLayout(
118 views::BoxLayout::kVertical, 0, 0, kPercentageSeparatorSpacing));
119
120 int zoom_percent = tab_contents_->zoom_controller()->zoom_percent();
86 label_ = new views::Label( 121 label_ = new views::Label(
87 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent_)); 122 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent));
123 gfx::Font font(label_->font().GetFontName(), kPercentageFontSize);
124 label_->SetFont(font);
88 AddChildView(label_); 125 AddChildView(label_);
89 126
90 if (auto_close_) { 127 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.
91 timer_.Start( 128 timer_.Start(
92 FROM_HERE, 129 FROM_HERE,
93 base::TimeDelta::FromMilliseconds(kBubbleCloseDelay), 130 base::TimeDelta::FromMilliseconds(kBubbleCloseDelay),
94 this, 131 this,
95 &ZoomBubbleView::Close); 132 &ZoomBubbleView::Close);
133 } else {
134 views::View* container = new views::View();
135 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
136 views::BoxLayout::kVertical, 0, 0, kSeparatorButtonSpacing));
137 container->AddChildView(new views::Separator());
138 container->AddChildView(new views::TextButton(
139 this, l10n_util::GetStringUTF16(IDS_ZOOM_SET_DEFAULT)));
140
141 AddChildView(container);
96 } 142 }
97 } 143 }
98 144
99 void ZoomBubbleView::WindowClosing() { 145 void ZoomBubbleView::WindowClosing() {
100 DCHECK(zoom_bubble_ == this); 146 DCHECK(zoom_bubble_ == this);
101 zoom_bubble_ = NULL; 147 zoom_bubble_ = NULL;
102 } 148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698