Chromium Code Reviews| 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/chrome_page_zoom.h" | 10 #include "chrome/browser/chrome_page_zoom.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 bool anchor_to_view = !is_fullscreen || | 56 bool anchor_to_view = !is_fullscreen || |
| 57 browser_view->immersive_mode_controller()->IsRevealed(); | 57 browser_view->immersive_mode_controller()->IsRevealed(); |
| 58 views::View* anchor_view = anchor_to_view ? | 58 views::View* anchor_view = anchor_to_view ? |
| 59 browser_view->GetLocationBarView()->zoom_view() : NULL; | 59 browser_view->GetLocationBarView()->zoom_view() : NULL; |
| 60 | 60 |
| 61 // Find the extension that initiated the zoom change, if any. | 61 // Find the extension that initiated the zoom change, if any. |
| 62 ZoomController* zoom_controller = | 62 ZoomController* zoom_controller = |
| 63 ZoomController::FromWebContents(web_contents); | 63 ZoomController::FromWebContents(web_contents); |
| 64 const extensions::Extension* extension = zoom_controller->last_extension(); | 64 const extensions::Extension* extension = zoom_controller->last_extension(); |
| 65 | 65 |
| 66 // If the bubble is already showing in this window, its |auto_close_| value | 66 // If the bubble is already showing in this window and the zoom change was not |
| 67 // is equal to |auto_close|, and the zoom change was not initiated by an | 67 // initiated by an extension, then the bubble can be reused and only the label |
| 68 // extension, then the bubble can be reused and only the label text needs to | 68 // text needs to be updated. |
| 69 // be updated. | |
| 70 if (zoom_bubble_ && | 69 if (zoom_bubble_ && |
| 71 zoom_bubble_->GetAnchorView() == anchor_view && | 70 zoom_bubble_->GetAnchorView() == anchor_view && |
| 72 zoom_bubble_->auto_close_ == auto_close && | |
| 73 !extension) { | 71 !extension) { |
| 74 zoom_bubble_->Refresh(); | 72 zoom_bubble_->Refresh(); |
| 75 return; | 73 return; |
| 76 } | 74 } |
| 77 | 75 |
| 78 // If the bubble is already showing but its |auto_close_| value is not equal | 76 // If the bubble is already showing but in the different tab, the current |
|
msw
2014/07/25 15:38:38
nit: "in a different"
vasilii
2014/07/25 15:48:20
Done.
| |
| 79 // to |auto_close|, the bubble's focus properties must change, so the | 77 // bubble must be closed and a new one created. |
| 80 // current bubble must be closed and a new one created. | |
| 81 CloseBubble(); | 78 CloseBubble(); |
| 82 | 79 |
| 83 zoom_bubble_ = new ZoomBubbleView(anchor_view, | 80 zoom_bubble_ = new ZoomBubbleView(anchor_view, |
| 84 web_contents, | 81 web_contents, |
| 85 auto_close, | 82 auto_close, |
| 86 browser_view->immersive_mode_controller(), | 83 browser_view->immersive_mode_controller(), |
| 87 browser->fullscreen_controller()); | 84 browser->fullscreen_controller()); |
| 88 | 85 |
| 89 // If the zoom change was initiated by an extension, capture the relevent | 86 // If the zoom change was initiated by an extension, capture the relevent |
| 90 // information from it. | 87 // information from it. |
| 91 if (extension) | 88 if (extension) |
| 92 zoom_bubble_->SetExtensionInfo(extension); | 89 zoom_bubble_->SetExtensionInfo(extension); |
| 93 | 90 |
| 94 // If we do not have an anchor view, parent the bubble to the content area. | 91 // If we do not have an anchor view, parent the bubble to the content area. |
| 95 if (!anchor_to_view) | 92 if (!anchor_to_view) |
| 96 zoom_bubble_->set_parent_window(web_contents->GetTopLevelNativeWindow()); | 93 zoom_bubble_->set_parent_window(web_contents->GetTopLevelNativeWindow()); |
| 97 | 94 |
| 98 views::BubbleDelegateView::CreateBubble(zoom_bubble_); | 95 views::BubbleDelegateView::CreateBubble(zoom_bubble_); |
| 99 | 96 |
| 100 // Adjust for fullscreen after creation as it relies on the content size. | 97 // Adjust for fullscreen after creation as it relies on the content size. |
| 101 if (is_fullscreen) | 98 if (is_fullscreen) |
| 102 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); | 99 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); |
| 103 | 100 |
| 104 if (zoom_bubble_->use_focusless()) | 101 if (auto_close) |
| 105 zoom_bubble_->GetWidget()->ShowInactive(); | 102 zoom_bubble_->GetWidget()->ShowInactive(); |
| 106 else | 103 else |
| 107 zoom_bubble_->GetWidget()->Show(); | 104 zoom_bubble_->GetWidget()->Show(); |
| 108 } | 105 } |
| 109 | 106 |
| 110 // static | 107 // static |
| 111 void ZoomBubbleView::CloseBubble() { | 108 void ZoomBubbleView::CloseBubble() { |
| 112 if (zoom_bubble_) | 109 if (zoom_bubble_) |
| 113 zoom_bubble_->Close(); | 110 zoom_bubble_->Close(); |
| 114 } | 111 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 132 FullscreenController* fullscreen_controller) | 129 FullscreenController* fullscreen_controller) |
| 133 : BubbleDelegateView(anchor_view, anchor_view ? | 130 : BubbleDelegateView(anchor_view, anchor_view ? |
| 134 views::BubbleBorder::TOP_RIGHT : views::BubbleBorder::NONE), | 131 views::BubbleBorder::TOP_RIGHT : views::BubbleBorder::NONE), |
| 135 image_button_(NULL), | 132 image_button_(NULL), |
| 136 label_(NULL), | 133 label_(NULL), |
| 137 web_contents_(web_contents), | 134 web_contents_(web_contents), |
| 138 auto_close_(auto_close), | 135 auto_close_(auto_close), |
| 139 immersive_mode_controller_(immersive_mode_controller) { | 136 immersive_mode_controller_(immersive_mode_controller) { |
| 140 // Compensate for built-in vertical padding in the anchor view's image. | 137 // Compensate for built-in vertical padding in the anchor view's image. |
| 141 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 138 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
| 142 set_use_focusless(auto_close); | |
| 143 set_notify_enter_exit_on_child(true); | 139 set_notify_enter_exit_on_child(true); |
| 144 | 140 |
| 145 // Add observers to close the bubble if the fullscreen state or immersive | 141 // Add observers to close the bubble if the fullscreen state or immersive |
| 146 // fullscreen revealed state changes. | 142 // fullscreen revealed state changes. |
| 147 registrar_.Add(this, | 143 registrar_.Add(this, |
| 148 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | 144 chrome::NOTIFICATION_FULLSCREEN_CHANGED, |
| 149 content::Source<FullscreenController>(fullscreen_controller)); | 145 content::Source<FullscreenController>(fullscreen_controller)); |
| 150 immersive_mode_controller_->AddObserver(this); | 146 immersive_mode_controller_->AddObserver(this); |
| 151 } | 147 } |
| 152 | 148 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 } | 239 } |
| 244 | 240 |
| 245 void ZoomBubbleView::OnExtensionIconImageChanged( | 241 void ZoomBubbleView::OnExtensionIconImageChanged( |
| 246 extensions::IconImage* /* image */) { | 242 extensions::IconImage* /* image */) { |
| 247 image_button_->SetImage(views::Button::STATE_NORMAL, | 243 image_button_->SetImage(views::Button::STATE_NORMAL, |
| 248 &extension_info_.icon_image->image_skia()); | 244 &extension_info_.icon_image->image_skia()); |
| 249 image_button_->SchedulePaint(); | 245 image_button_->SchedulePaint(); |
| 250 } | 246 } |
| 251 | 247 |
| 252 void ZoomBubbleView::OnMouseEntered(const ui::MouseEvent& event) { | 248 void ZoomBubbleView::OnMouseEntered(const ui::MouseEvent& event) { |
| 253 set_use_focusless(false); | |
| 254 StopTimer(); | 249 StopTimer(); |
| 255 } | 250 } |
| 256 | 251 |
| 257 void ZoomBubbleView::OnMouseExited(const ui::MouseEvent& event) { | 252 void ZoomBubbleView::OnMouseExited(const ui::MouseEvent& event) { |
| 258 set_use_focusless(auto_close_); | |
| 259 StartTimerIfNecessary(); | 253 StartTimerIfNecessary(); |
| 260 } | 254 } |
| 261 | 255 |
| 262 void ZoomBubbleView::OnGestureEvent(ui::GestureEvent* event) { | 256 void ZoomBubbleView::OnGestureEvent(ui::GestureEvent* event) { |
| 263 if (!zoom_bubble_ || !zoom_bubble_->auto_close_ || | 257 if (!zoom_bubble_ || !zoom_bubble_->auto_close_ || |
| 264 event->type() != ui::ET_GESTURE_TAP) { | 258 event->type() != ui::ET_GESTURE_TAP) { |
| 265 return; | 259 return; |
| 266 } | 260 } |
| 267 | 261 |
| 268 // If an auto-closing bubble was tapped, show a non-auto-closing bubble in | 262 auto_close_ = false; |
| 269 // its place. | 263 StopTimer(); |
| 270 ShowBubble(zoom_bubble_->web_contents_, false); | |
| 271 event->SetHandled(); | 264 event->SetHandled(); |
| 272 } | 265 } |
| 273 | 266 |
| 274 void ZoomBubbleView::ButtonPressed(views::Button* sender, | 267 void ZoomBubbleView::ButtonPressed(views::Button* sender, |
| 275 const ui::Event& event) { | 268 const ui::Event& event) { |
| 276 if (sender == image_button_) { | 269 if (sender == image_button_) { |
| 277 DCHECK(extension_info_.icon_image) << "Invalid button press."; | 270 DCHECK(extension_info_.icon_image) << "Invalid button press."; |
| 278 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); | 271 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); |
| 279 chrome::AddSelectedTabWithURL( | 272 chrome::AddSelectedTabWithURL( |
| 280 browser, | 273 browser, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 359 void ZoomBubbleView::WindowClosing() { | 352 void ZoomBubbleView::WindowClosing() { |
| 360 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't | 353 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't |
| 361 // call this right away). Only set to NULL when it's this bubble. | 354 // call this right away). Only set to NULL when it's this bubble. |
| 362 if (zoom_bubble_ == this) | 355 if (zoom_bubble_ == this) |
| 363 zoom_bubble_ = NULL; | 356 zoom_bubble_ = NULL; |
| 364 } | 357 } |
| 365 | 358 |
| 366 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} | 359 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} |
| 367 | 360 |
| 368 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} | 361 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} |
| OLD | NEW |