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