| 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 "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // initiated by an extension, then the bubble can be reused and only the label | 58 // initiated by an extension, then the bubble can be reused and only the label |
| 59 // text needs to be updated. | 59 // text needs to be updated. |
| 60 if (zoom_bubble_ && zoom_bubble_->GetAnchorView() == anchor_view && !client) { | 60 if (zoom_bubble_ && zoom_bubble_->GetAnchorView() == anchor_view && !client) { |
| 61 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_); | 61 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_); |
| 62 zoom_bubble_->Refresh(); | 62 zoom_bubble_->Refresh(); |
| 63 return; | 63 return; |
| 64 } | 64 } |
| 65 | 65 |
| 66 // If the bubble is already showing but in a different tab, the current | 66 // If the bubble is already showing but in a different tab, the current |
| 67 // bubble must be closed and a new one created. | 67 // bubble must be closed and a new one created. |
| 68 CloseBubble(); | 68 CloseCurrentBubble(); |
| 69 | 69 |
| 70 zoom_bubble_ = new ZoomBubbleView(anchor_view, web_contents, reason, | 70 zoom_bubble_ = new ZoomBubbleView(anchor_view, web_contents, reason, |
| 71 browser_view->immersive_mode_controller()); | 71 browser_view->immersive_mode_controller()); |
| 72 | 72 |
| 73 // If the zoom change was initiated by an extension, capture the relevent | 73 // If the zoom change was initiated by an extension, capture the relevent |
| 74 // information from it. | 74 // information from it. |
| 75 if (client) { | 75 if (client) { |
| 76 zoom_bubble_->SetExtensionInfo( | 76 zoom_bubble_->SetExtensionInfo( |
| 77 static_cast<const extensions::ExtensionZoomRequestClient*>(client) | 77 static_cast<const extensions::ExtensionZoomRequestClient*>(client) |
| 78 ->extension()); | 78 ->extension()); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // If we do not have an anchor view, parent the bubble to the content area. | 81 // If we do not have an anchor view, parent the bubble to the content area. |
| 82 if (!anchor_to_view) | 82 if (!anchor_to_view) |
| 83 zoom_bubble_->set_parent_window(web_contents->GetNativeView()); | 83 zoom_bubble_->set_parent_window(web_contents->GetNativeView()); |
| 84 | 84 |
| 85 views::Widget* zoom_bubble_widget = | 85 views::Widget* zoom_bubble_widget = |
| 86 views::BubbleDelegateView::CreateBubble(zoom_bubble_); | 86 views::BubbleDialogDelegateView::CreateBubble(zoom_bubble_); |
| 87 if (anchor_view) | 87 if (anchor_view) |
| 88 zoom_bubble_widget->AddObserver(anchor_view); | 88 zoom_bubble_widget->AddObserver(anchor_view); |
| 89 | 89 |
| 90 // Adjust for fullscreen after creation as it relies on the content size. | 90 // Adjust for fullscreen after creation as it relies on the content size. |
| 91 if (is_fullscreen) | 91 if (is_fullscreen) |
| 92 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); | 92 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); |
| 93 | 93 |
| 94 zoom_bubble_->ShowForReason(reason); | 94 zoom_bubble_->ShowForReason(reason); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // static | 97 // static |
| 98 void ZoomBubbleView::CloseBubble() { | 98 void ZoomBubbleView::CloseCurrentBubble() { |
| 99 if (zoom_bubble_) | 99 if (zoom_bubble_) |
| 100 zoom_bubble_->Close(); | 100 zoom_bubble_->CloseBubble(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // static | 103 // static |
| 104 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() { | 104 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() { |
| 105 return zoom_bubble_; | 105 return zoom_bubble_; |
| 106 } | 106 } |
| 107 | 107 |
| 108 ZoomBubbleView::ZoomBubbleView( | 108 ZoomBubbleView::ZoomBubbleView( |
| 109 views::View* anchor_view, | 109 views::View* anchor_view, |
| 110 content::WebContents* web_contents, | 110 content::WebContents* web_contents, |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 StartTimerIfNecessary(); | 200 StartTimerIfNecessary(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 void ZoomBubbleView::WindowClosing() { | 203 void ZoomBubbleView::WindowClosing() { |
| 204 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't | 204 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't |
| 205 // call this right away). Only set to NULL when it's this bubble. | 205 // call this right away). Only set to NULL when it's this bubble. |
| 206 if (zoom_bubble_ == this) | 206 if (zoom_bubble_ == this) |
| 207 zoom_bubble_ = NULL; | 207 zoom_bubble_ = NULL; |
| 208 } | 208 } |
| 209 | 209 |
| 210 void ZoomBubbleView::Close() { | 210 void ZoomBubbleView::CloseBubble() { |
| 211 // Widget's Close() is async, but we don't want to use zoom_bubble_ after | 211 // Widget's Close() is async, but we don't want to use zoom_bubble_ after |
| 212 // this. Additionally web_contents_ may have been destroyed. | 212 // this. Additionally web_contents_ may have been destroyed. |
| 213 zoom_bubble_ = NULL; | 213 zoom_bubble_ = NULL; |
| 214 web_contents_ = NULL; | 214 web_contents_ = NULL; |
| 215 LocationBarBubbleDelegateView::Close(); | 215 LocationBarBubbleDelegateView::CloseBubble(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void ZoomBubbleView::ButtonPressed(views::Button* sender, | 218 void ZoomBubbleView::ButtonPressed(views::Button* sender, |
| 219 const ui::Event& event) { | 219 const ui::Event& event) { |
| 220 if (sender == image_button_) { | 220 if (sender == image_button_) { |
| 221 DCHECK(extension_info_.icon_image) << "Invalid button press."; | 221 DCHECK(extension_info_.icon_image) << "Invalid button press."; |
| 222 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 222 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
| 223 chrome::AddSelectedTabWithURL( | 223 chrome::AddSelectedTabWithURL( |
| 224 browser, GURL(base::StringPrintf("chrome://extensions?id=%s", | 224 browser, GURL(base::StringPrintf("chrome://extensions?id=%s", |
| 225 extension_info_.id.c_str())), | 225 extension_info_.id.c_str())), |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 void ZoomBubbleView::StartTimerIfNecessary() { | 300 void ZoomBubbleView::StartTimerIfNecessary() { |
| 301 if (!auto_close_) | 301 if (!auto_close_) |
| 302 return; | 302 return; |
| 303 | 303 |
| 304 if (timer_.IsRunning()) { | 304 if (timer_.IsRunning()) { |
| 305 timer_.Reset(); | 305 timer_.Reset(); |
| 306 } else { | 306 } else { |
| 307 // The number of milliseconds the bubble should stay on the screen if it | 307 // The number of milliseconds the bubble should stay on the screen if it |
| 308 // will close automatically. | 308 // will close automatically. |
| 309 const int kBubbleCloseDelay = 1500; | 309 const int kBubbleCloseDelay = 1500; |
| 310 timer_.Start( | 310 timer_.Start(FROM_HERE, |
| 311 FROM_HERE, | 311 base::TimeDelta::FromMilliseconds(kBubbleCloseDelay), this, |
| 312 base::TimeDelta::FromMilliseconds(kBubbleCloseDelay), | 312 &ZoomBubbleView::CloseBubble); |
| 313 this, | |
| 314 &ZoomBubbleView::Close); | |
| 315 } | 313 } |
| 316 } | 314 } |
| 317 | 315 |
| 318 void ZoomBubbleView::StopTimer() { | 316 void ZoomBubbleView::StopTimer() { |
| 319 timer_.Stop(); | 317 timer_.Stop(); |
| 320 } | 318 } |
| 321 | 319 |
| 322 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} | 320 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} |
| 323 | 321 |
| 324 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} | 322 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} |
| OLD | NEW |