OLD | NEW |
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 <cmath> |
| 8 |
| 9 #include "base/auto_reset.h" |
7 #include "base/i18n/number_formatting.h" | 10 #include "base/i18n/number_formatting.h" |
8 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
9 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "chrome/app/vector_icons/vector_icons.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/platform_util.h" | 15 #include "chrome/browser/platform_util.h" |
12 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_dialogs.h" | 17 #include "chrome/browser/ui/browser_dialogs.h" |
14 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
15 #include "chrome/browser/ui/browser_tabstrip.h" | 19 #include "chrome/browser/ui/browser_tabstrip.h" |
16 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
17 #include "chrome/browser/ui/views/frame/browser_view.h" | 21 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 22 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" |
18 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 23 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
19 #include "chrome/browser/ui/views/location_bar/zoom_view.h" | 24 #include "chrome/browser/ui/views/location_bar/zoom_view.h" |
20 #include "chrome/common/extensions/api/extension_action/action_info.h" | 25 #include "chrome/common/extensions/api/extension_action/action_info.h" |
21 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
22 #include "chrome/grit/theme_resources.h" | 27 #include "chrome/grit/theme_resources.h" |
23 #include "components/zoom/page_zoom.h" | 28 #include "components/zoom/page_zoom.h" |
24 #include "components/zoom/zoom_controller.h" | 29 #include "components/zoom/zoom_controller.h" |
25 #include "content/public/browser/notification_source.h" | 30 #include "content/public/browser/notification_source.h" |
26 #include "extensions/browser/extension_zoom_request_client.h" | 31 #include "extensions/browser/extension_zoom_request_client.h" |
27 #include "extensions/common/manifest_handlers/icons_handler.h" | 32 #include "extensions/common/manifest_handlers/icons_handler.h" |
28 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
29 #include "ui/base/material_design/material_design_controller.h" | 34 #include "ui/base/material_design/material_design_controller.h" |
30 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
31 #include "ui/base/ui_features.h" | 36 #include "ui/base/ui_features.h" |
32 #include "ui/gfx/favicon_size.h" | 37 #include "ui/gfx/favicon_size.h" |
| 38 #include "ui/gfx/text_utils.h" |
| 39 #include "ui/gfx/vector_icon_types.h" |
| 40 #include "ui/native_theme/native_theme.h" |
33 #include "ui/views/controls/button/image_button.h" | 41 #include "ui/views/controls/button/image_button.h" |
| 42 #include "ui/views/controls/button/image_button_factory.h" |
34 #include "ui/views/controls/button/md_text_button.h" | 43 #include "ui/views/controls/button/md_text_button.h" |
35 #include "ui/views/controls/separator.h" | 44 #include "ui/views/controls/separator.h" |
36 #include "ui/views/layout/grid_layout.h" | 45 #include "ui/views/layout/box_layout.h" |
| 46 #include "ui/views/layout/fill_layout.h" |
37 #include "ui/views/layout/layout_constants.h" | 47 #include "ui/views/layout/layout_constants.h" |
38 #include "ui/views/widget/widget.h" | 48 #include "ui/views/widget/widget.h" |
39 | 49 |
| 50 namespace { |
| 51 |
| 52 // The default time that the bubble should stay on the screen if it will close |
| 53 // automatically. |
| 54 constexpr base::TimeDelta kBubbleCloseDelayDefault = |
| 55 base::TimeDelta::FromMilliseconds(1500); |
| 56 |
| 57 // A longer timeout used for how long the bubble should stay on the screen |
| 58 // before it will close automatically after + or - buttons have been used. |
| 59 constexpr base::TimeDelta kBubbleCloseDelayLong = |
| 60 base::TimeDelta::FromMilliseconds(5000); |
| 61 |
| 62 // Creates an ImageButton using vector |icon|, sets a tooltip with |tooltip_id|. |
| 63 // Returns the button. |
| 64 std::unique_ptr<views::Button> CreateZoomButton(views::ButtonListener* listener, |
| 65 const gfx::VectorIcon& icon, |
| 66 int tooltip_id) { |
| 67 std::unique_ptr<views::ImageButton> button( |
| 68 views::CreateVectorImageButton(listener)); |
| 69 views::SetImageFromVectorIcon(button.get(), icon); |
| 70 button->SetFocusForPlatform(); |
| 71 button->SetTooltipText(l10n_util::GetStringUTF16(tooltip_id)); |
| 72 return std::move(button); |
| 73 } |
| 74 |
| 75 class ZoomValue : public views::Label { |
| 76 public: |
| 77 explicit ZoomValue(const content::WebContents* web_contents) |
| 78 : Label(base::string16(), |
| 79 views::style::CONTEXT_LABEL, |
| 80 views::style::STYLE_PRIMARY), |
| 81 max_width_(GetLabelMaxWidth(web_contents)) {} |
| 82 ~ZoomValue() override {} |
| 83 |
| 84 // views::Label: |
| 85 gfx::Size GetPreferredSize() const override { |
| 86 return gfx::Size(max_width_, GetHeightForWidth(max_width_)); |
| 87 } |
| 88 |
| 89 private: |
| 90 int GetLabelMaxWidth(const content::WebContents* web_contents) const { |
| 91 int border_width = border() ? border()->GetInsets().width() : 0; |
| 92 int max_w = 0; |
| 93 auto* zoom_controller = zoom::ZoomController::FromWebContents(web_contents); |
| 94 DCHECK(zoom_controller); |
| 95 // Enumerate all zoom factors that can be used in PageZoom::Zoom. |
| 96 std::vector<double> zoom_factors = |
| 97 zoom::PageZoom::PresetZoomFactors(zoom_controller->GetZoomPercent()); |
| 98 for (auto zoom : zoom_factors) { |
| 99 int w = gfx::GetStringWidth( |
| 100 base::FormatPercent(static_cast<int>(std::round(zoom * 100))), |
| 101 font_list()); |
| 102 max_w = std::max(w, max_w); |
| 103 } |
| 104 return max_w + border_width; |
| 105 } |
| 106 |
| 107 const int max_width_; |
| 108 |
| 109 DISALLOW_COPY_AND_ASSIGN(ZoomValue); |
| 110 }; |
| 111 |
| 112 } // namespace |
| 113 |
40 // static | 114 // static |
41 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = nullptr; | 115 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = nullptr; |
42 | 116 |
43 // static | 117 // static |
44 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents, | 118 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents, |
45 const gfx::Point& anchor_point, | 119 const gfx::Point& anchor_point, |
46 DisplayReason reason) { | 120 DisplayReason reason) { |
47 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 121 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
48 DCHECK(browser && browser->window() && | 122 DCHECK(browser && browser->window() && |
49 browser->exclusive_access_manager()->fullscreen_controller()); | 123 browser->exclusive_access_manager()->fullscreen_controller()); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 zoom_bubble_->set_arrow(views::BubbleBorder::TOP_RIGHT); | 184 zoom_bubble_->set_arrow(views::BubbleBorder::TOP_RIGHT); |
111 zoom_bubble_->set_parent_window(parent); | 185 zoom_bubble_->set_parent_window(parent); |
112 views::BubbleDialogDelegateView::CreateBubble(zoom_bubble_); | 186 views::BubbleDialogDelegateView::CreateBubble(zoom_bubble_); |
113 #endif | 187 #endif |
114 | 188 |
115 // Adjust for fullscreen after creation as it relies on the content size. | 189 // Adjust for fullscreen after creation as it relies on the content size. |
116 if (is_fullscreen) | 190 if (is_fullscreen) |
117 zoom_bubble_->AdjustForFullscreen(browser->window()->GetBounds()); | 191 zoom_bubble_->AdjustForFullscreen(browser->window()->GetBounds()); |
118 | 192 |
119 zoom_bubble_->ShowForReason(reason); | 193 zoom_bubble_->ShowForReason(reason); |
| 194 zoom_bubble_->UpdateZoomIconVisibility(); |
120 } | 195 } |
121 | 196 |
122 // static | 197 // static |
123 void ZoomBubbleView::CloseCurrentBubble() { | 198 void ZoomBubbleView::CloseCurrentBubble() { |
124 if (zoom_bubble_) | 199 if (zoom_bubble_) |
125 zoom_bubble_->CloseBubble(); | 200 zoom_bubble_->CloseBubble(); |
126 } | 201 } |
127 | 202 |
128 // static | 203 // static |
129 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() { | 204 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() { |
130 return zoom_bubble_; | 205 return zoom_bubble_; |
131 } | 206 } |
132 | 207 |
133 void ZoomBubbleView::Refresh() { | 208 void ZoomBubbleView::Refresh() { |
134 zoom::ZoomController* zoom_controller = | 209 UpdateZoomPercent(); |
135 zoom::ZoomController::FromWebContents(web_contents_); | |
136 int zoom_percent = zoom_controller->GetZoomPercent(); | |
137 label_->SetText(l10n_util::GetStringFUTF16( | |
138 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent))); | |
139 StartTimerIfNecessary(); | 210 StartTimerIfNecessary(); |
140 } | 211 } |
141 | 212 |
142 ZoomBubbleView::ZoomBubbleView( | 213 ZoomBubbleView::ZoomBubbleView( |
143 views::View* anchor_view, | 214 views::View* anchor_view, |
144 const gfx::Point& anchor_point, | 215 const gfx::Point& anchor_point, |
145 content::WebContents* web_contents, | 216 content::WebContents* web_contents, |
146 DisplayReason reason, | 217 DisplayReason reason, |
147 ImmersiveModeController* immersive_mode_controller) | 218 ImmersiveModeController* immersive_mode_controller) |
148 : LocationBarBubbleDelegateView(anchor_view, anchor_point, web_contents), | 219 : LocationBarBubbleDelegateView(anchor_view, anchor_point, web_contents), |
| 220 auto_close_duration_(kBubbleCloseDelayDefault), |
149 image_button_(nullptr), | 221 image_button_(nullptr), |
150 label_(nullptr), | 222 label_(nullptr), |
| 223 zoom_out_button_(nullptr), |
| 224 zoom_in_button_(nullptr), |
| 225 reset_button_(nullptr), |
151 web_contents_(web_contents), | 226 web_contents_(web_contents), |
152 auto_close_(reason == AUTOMATIC), | 227 auto_close_(reason == AUTOMATIC), |
| 228 ignore_close_bubble_(false), |
153 immersive_mode_controller_(immersive_mode_controller) { | 229 immersive_mode_controller_(immersive_mode_controller) { |
154 set_notify_enter_exit_on_child(true); | 230 set_notify_enter_exit_on_child(true); |
155 if (immersive_mode_controller_) | 231 if (immersive_mode_controller_) |
156 immersive_mode_controller_->AddObserver(this); | 232 immersive_mode_controller_->AddObserver(this); |
157 UseCompactMargins(); | 233 UseCompactMargins(); |
158 chrome::RecordDialogCreation(chrome::DialogIdentifier::ZOOM); | 234 chrome::RecordDialogCreation(chrome::DialogIdentifier::ZOOM); |
159 } | 235 } |
160 | 236 |
161 ZoomBubbleView::~ZoomBubbleView() { | 237 ZoomBubbleView::~ZoomBubbleView() { |
162 if (immersive_mode_controller_) | 238 if (immersive_mode_controller_) |
(...skipping 13 matching lines...) Expand all Loading... |
176 | 252 |
177 void ZoomBubbleView::OnMouseEntered(const ui::MouseEvent& event) { | 253 void ZoomBubbleView::OnMouseEntered(const ui::MouseEvent& event) { |
178 StopTimer(); | 254 StopTimer(); |
179 } | 255 } |
180 | 256 |
181 void ZoomBubbleView::OnMouseExited(const ui::MouseEvent& event) { | 257 void ZoomBubbleView::OnMouseExited(const ui::MouseEvent& event) { |
182 StartTimerIfNecessary(); | 258 StartTimerIfNecessary(); |
183 } | 259 } |
184 | 260 |
185 void ZoomBubbleView::Init() { | 261 void ZoomBubbleView::Init() { |
186 // Set up the layout of the zoom bubble. A grid layout is used because | 262 // Set up the layout of the zoom bubble. |
187 // sometimes an extension icon is shown next to the zoom label. | 263 ChromeLayoutProvider* provider = ChromeLayoutProvider::Get(); |
188 views::GridLayout* grid_layout = new views::GridLayout(this); | 264 const int margin = |
189 SetLayoutManager(grid_layout); | 265 provider->GetDistanceMetric(views::DISTANCE_RELATED_BUTTON_HORIZONTAL); |
190 views::ColumnSet* columns = grid_layout->AddColumnSet(0); | 266 views::BoxLayout* box_layout = |
191 // First row. | 267 new views::BoxLayout(views::BoxLayout::kHorizontal, margin, 0, margin); |
192 if (extension_info_.icon_image) { | 268 |
193 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 2, | 269 box_layout->set_main_axis_alignment( |
194 views::GridLayout::USE_PREF, 0, 0); | 270 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
195 } | 271 box_layout->set_cross_axis_alignment( |
196 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 272 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
197 views::GridLayout::USE_PREF, 0, 0); | 273 SetLayoutManager(box_layout); |
198 grid_layout->StartRow(0, 0); | |
199 | 274 |
200 // If this zoom change was initiated by an extension, that extension will be | 275 // If this zoom change was initiated by an extension, that extension will be |
201 // attributed by showing its icon in the zoom bubble. | 276 // attributed by showing its icon in the zoom bubble. |
202 if (extension_info_.icon_image) { | 277 if (extension_info_.icon_image) { |
203 image_button_ = new views::ImageButton(this); | 278 image_button_ = new views::ImageButton(this); |
204 image_button_->SetTooltipText( | 279 image_button_->SetTooltipText( |
205 l10n_util::GetStringFUTF16(IDS_TOOLTIP_ZOOM_EXTENSION_ICON, | 280 l10n_util::GetStringFUTF16(IDS_TOOLTIP_ZOOM_EXTENSION_ICON, |
206 base::UTF8ToUTF16(extension_info_.name))); | 281 base::UTF8ToUTF16(extension_info_.name))); |
207 image_button_->SetImage(views::Button::STATE_NORMAL, | 282 image_button_->SetImage(views::Button::STATE_NORMAL, |
208 &extension_info_.icon_image->image_skia()); | 283 &extension_info_.icon_image->image_skia()); |
209 grid_layout->AddView(image_button_); | 284 AddChildView(image_button_); |
210 } | 285 } |
211 | 286 |
| 287 // Add Zoom Out ("-") button. |
| 288 std::unique_ptr<views::Button> zoom_out_button = |
| 289 CreateZoomButton(this, kRemoveIcon, IDS_ACCNAME_ZOOM_MINUS2); |
| 290 zoom_out_button_ = zoom_out_button.get(); |
| 291 AddChildView(zoom_out_button.release()); |
| 292 |
212 // Add zoom label with the new zoom percent. | 293 // Add zoom label with the new zoom percent. |
213 zoom::ZoomController* zoom_controller = | 294 label_ = new ZoomValue(web_contents_); |
214 zoom::ZoomController::FromWebContents(web_contents_); | 295 UpdateZoomPercent(); |
215 int zoom_percent = zoom_controller->GetZoomPercent(); | 296 AddChildView(label_); |
216 label_ = new views::Label(l10n_util::GetStringFUTF16( | |
217 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent))); | |
218 label_->SetFontList(GetTitleFontList()); | |
219 grid_layout->AddView(label_); | |
220 | 297 |
221 // Second row. | 298 // Add Zoom In ("+") button. |
222 grid_layout->AddPaddingRow(0, 8); | 299 std::unique_ptr<views::Button> zoom_in_button = |
223 columns = grid_layout->AddColumnSet(1); | 300 CreateZoomButton(this, kAddIcon, IDS_ACCNAME_ZOOM_PLUS2); |
224 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 301 zoom_in_button_ = zoom_in_button.get(); |
225 views::GridLayout::USE_PREF, 0, 0); | 302 AddChildView(zoom_in_button.release()); |
226 grid_layout->StartRow(0, 1); | |
227 | 303 |
228 // Add "Reset to Default" button. | 304 // Add "Reset" button. |
229 grid_layout->AddView( | 305 reset_button_ = views::MdTextButton::CreateSecondaryUiButton( |
230 views::MdTextButton::CreateSecondaryUiButton( | 306 this, l10n_util::GetStringUTF16(IDS_ZOOM_SET_DEFAULT)); |
231 this, l10n_util::GetStringUTF16(IDS_ZOOM_SET_DEFAULT))); | 307 reset_button_->SetTooltipText( |
| 308 l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM_SET_DEFAULT)); |
| 309 AddChildView(reset_button_); |
232 | 310 |
233 StartTimerIfNecessary(); | 311 StartTimerIfNecessary(); |
234 } | 312 } |
235 | 313 |
236 void ZoomBubbleView::WindowClosing() { | 314 void ZoomBubbleView::WindowClosing() { |
237 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't | 315 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't |
238 // call this right away). Only set to nullptr when it's this bubble. | 316 // call this right away). Only set to nullptr when it's this bubble. |
239 if (zoom_bubble_ == this) | 317 bool this_bubble = zoom_bubble_ == this; |
| 318 if (this_bubble) |
240 zoom_bubble_ = nullptr; | 319 zoom_bubble_ = nullptr; |
| 320 UpdateZoomIconVisibility(); |
| 321 if (this_bubble) |
| 322 web_contents_ = nullptr; |
241 } | 323 } |
242 | 324 |
243 void ZoomBubbleView::CloseBubble() { | 325 void ZoomBubbleView::CloseBubble() { |
| 326 if (ignore_close_bubble_) |
| 327 return; |
| 328 |
244 // Widget's Close() is async, but we don't want to use zoom_bubble_ after | 329 // Widget's Close() is async, but we don't want to use zoom_bubble_ after |
245 // this. Additionally web_contents_ may have been destroyed. | 330 // this. Additionally web_contents_ may have been destroyed. |
246 zoom_bubble_ = nullptr; | 331 zoom_bubble_ = nullptr; |
247 web_contents_ = nullptr; | |
248 LocationBarBubbleDelegateView::CloseBubble(); | 332 LocationBarBubbleDelegateView::CloseBubble(); |
249 } | 333 } |
250 | 334 |
251 void ZoomBubbleView::ButtonPressed(views::Button* sender, | 335 void ZoomBubbleView::ButtonPressed(views::Button* sender, |
252 const ui::Event& event) { | 336 const ui::Event& event) { |
| 337 // No button presses in this dialog should cause the dialog to close, |
| 338 // including when the zoom level is set to 100% as a result of a button press. |
| 339 base::AutoReset<bool> auto_ignore_close_bubble(&ignore_close_bubble_, true); |
| 340 |
| 341 // Extend the timer to give a user more time after any button is pressed. |
| 342 auto_close_duration_ = kBubbleCloseDelayLong; |
| 343 StartTimerIfNecessary(); |
| 344 |
253 if (sender == image_button_) { | 345 if (sender == image_button_) { |
254 DCHECK(extension_info_.icon_image) << "Invalid button press."; | 346 DCHECK(extension_info_.icon_image) << "Invalid button press."; |
255 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 347 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
256 chrome::AddSelectedTabWithURL( | 348 chrome::AddSelectedTabWithURL( |
257 browser, GURL(base::StringPrintf("chrome://extensions?id=%s", | 349 browser, GURL(base::StringPrintf("chrome://extensions?id=%s", |
258 extension_info_.id.c_str())), | 350 extension_info_.id.c_str())), |
259 ui::PAGE_TRANSITION_FROM_API); | 351 ui::PAGE_TRANSITION_FROM_API); |
| 352 } else if (sender == zoom_out_button_) { |
| 353 zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_OUT); |
| 354 } else if (sender == zoom_in_button_) { |
| 355 zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_IN); |
| 356 } else if (sender == reset_button_) { |
| 357 zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_RESET); |
260 } else { | 358 } else { |
261 zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_RESET); | 359 NOTREACHED(); |
262 } | 360 } |
263 } | 361 } |
264 | 362 |
265 void ZoomBubbleView::OnImmersiveRevealStarted() { | 363 void ZoomBubbleView::OnImmersiveRevealStarted() { |
266 CloseBubble(); | 364 CloseBubble(); |
267 } | 365 } |
268 | 366 |
269 void ZoomBubbleView::OnImmersiveModeControllerDestroyed() { | 367 void ZoomBubbleView::OnImmersiveModeControllerDestroyed() { |
270 immersive_mode_controller_ = nullptr; | 368 immersive_mode_controller_ = nullptr; |
271 } | 369 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 icon_size = browser_action->default_icon.map().begin()->first; | 412 icon_size = browser_action->default_icon.map().begin()->first; |
315 extension_info_.icon_image.reset( | 413 extension_info_.icon_image.reset( |
316 new extensions::IconImage(web_contents_->GetBrowserContext(), | 414 new extensions::IconImage(web_contents_->GetBrowserContext(), |
317 extension, | 415 extension, |
318 browser_action->default_icon, | 416 browser_action->default_icon, |
319 icon_size, | 417 icon_size, |
320 default_extension_icon_image, | 418 default_extension_icon_image, |
321 this)); | 419 this)); |
322 } | 420 } |
323 | 421 |
| 422 void ZoomBubbleView::UpdateZoomPercent() { |
| 423 label_->SetText(base::FormatPercent( |
| 424 zoom::ZoomController::FromWebContents(web_contents_)->GetZoomPercent())); |
| 425 } |
| 426 |
| 427 void ZoomBubbleView::UpdateZoomIconVisibility() { |
| 428 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
| 429 if (browser && browser->window() && browser->window()->GetLocationBar()) |
| 430 browser->window()->GetLocationBar()->UpdateZoomViewVisibility(); |
| 431 } |
| 432 |
324 void ZoomBubbleView::StartTimerIfNecessary() { | 433 void ZoomBubbleView::StartTimerIfNecessary() { |
325 if (!auto_close_) | 434 if (!auto_close_) |
326 return; | 435 return; |
327 | 436 |
328 if (timer_.IsRunning()) { | 437 timer_.Start(FROM_HERE, auto_close_duration_, this, |
329 timer_.Reset(); | 438 &ZoomBubbleView::CloseBubble); |
330 } else { | |
331 // The number of milliseconds the bubble should stay on the screen if it | |
332 // will close automatically. | |
333 const int kBubbleCloseDelay = 1500; | |
334 timer_.Start(FROM_HERE, | |
335 base::TimeDelta::FromMilliseconds(kBubbleCloseDelay), this, | |
336 &ZoomBubbleView::CloseBubble); | |
337 } | |
338 } | 439 } |
339 | 440 |
340 void ZoomBubbleView::StopTimer() { | 441 void ZoomBubbleView::StopTimer() { |
341 timer_.Stop(); | 442 timer_.Stop(); |
342 } | 443 } |
343 | 444 |
344 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} | 445 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} |
345 | 446 |
346 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} | 447 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} |
OLD | NEW |