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

Side by Side Diff: chrome/browser/ui/views/location_bar/zoom_bubble_view.cc

Issue 1402363013: Update location bar bubble/icon behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 1 month 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/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 19 matching lines...) Expand all
30 #include "ui/views/controls/separator.h" 30 #include "ui/views/controls/separator.h"
31 #include "ui/views/layout/grid_layout.h" 31 #include "ui/views/layout/grid_layout.h"
32 #include "ui/views/layout/layout_constants.h" 32 #include "ui/views/layout/layout_constants.h"
33 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
34 34
35 // static 35 // static
36 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL; 36 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL;
37 37
38 // static 38 // static
39 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents, 39 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents,
40 bool auto_close) { 40 DisplayReason reason) {
41 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 41 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
42 DCHECK(browser && browser->window() && 42 DCHECK(browser && browser->window() &&
43 browser->exclusive_access_manager()->fullscreen_controller()); 43 browser->exclusive_access_manager()->fullscreen_controller());
44 44
45 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 45 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
46 bool is_fullscreen = browser_view->IsFullscreen(); 46 bool is_fullscreen = browser_view->IsFullscreen();
47 bool anchor_to_view = !is_fullscreen || 47 bool anchor_to_view = !is_fullscreen ||
48 browser_view->immersive_mode_controller()->IsRevealed(); 48 browser_view->immersive_mode_controller()->IsRevealed();
49 views::View* anchor_view = anchor_to_view ? 49 views::View* anchor_view = anchor_to_view ?
50 browser_view->GetLocationBarView()->zoom_view() : NULL; 50 browser_view->GetLocationBarView()->zoom_view() : NULL;
51 51
52 // Find the extension that initiated the zoom change, if any. 52 // Find the extension that initiated the zoom change, if any.
53 ui_zoom::ZoomController* zoom_controller = 53 ui_zoom::ZoomController* zoom_controller =
54 ui_zoom::ZoomController::FromWebContents(web_contents); 54 ui_zoom::ZoomController::FromWebContents(web_contents);
55 const ui_zoom::ZoomRequestClient* client = zoom_controller->last_client(); 55 const ui_zoom::ZoomRequestClient* client = zoom_controller->last_client();
56 56
57 // If the bubble is already showing in this window and the zoom change was not 57 // If the bubble is already showing in this window and the zoom change was not
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 CloseBubble();
69 69
70 zoom_bubble_ = new ZoomBubbleView(anchor_view, web_contents, auto_close, 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::BubbleDelegateView::CreateBubble(zoom_bubble_); 85 views::BubbleDelegateView::CreateBubble(zoom_bubble_);
86 86
87 // Adjust for fullscreen after creation as it relies on the content size. 87 // Adjust for fullscreen after creation as it relies on the content size.
88 if (is_fullscreen) 88 if (is_fullscreen)
89 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); 89 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen());
90 90
91 if (auto_close) 91 zoom_bubble_->ShowForReason(reason);
92 zoom_bubble_->GetWidget()->ShowInactive();
93 else
94 zoom_bubble_->GetWidget()->Show();
95 } 92 }
96 93
97 // static 94 // static
98 void ZoomBubbleView::CloseBubble() { 95 void ZoomBubbleView::CloseBubble() {
99 if (zoom_bubble_) 96 if (zoom_bubble_)
100 zoom_bubble_->Close(); 97 zoom_bubble_->Close();
101 } 98 }
102 99
103 // static 100 // static
104 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() { 101 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() {
105 return zoom_bubble_; 102 return zoom_bubble_;
106 } 103 }
107 104
108 ZoomBubbleView::ZoomBubbleView( 105 ZoomBubbleView::ZoomBubbleView(
109 views::View* anchor_view, 106 views::View* anchor_view,
110 content::WebContents* web_contents, 107 content::WebContents* web_contents,
111 bool auto_close, 108 DisplayReason reason,
112 ImmersiveModeController* immersive_mode_controller) 109 ImmersiveModeController* immersive_mode_controller)
113 : LocationBarBubbleDelegateView(anchor_view, web_contents), 110 : LocationBarBubbleDelegateView(anchor_view, web_contents),
114 image_button_(NULL), 111 image_button_(NULL),
115 label_(NULL), 112 label_(NULL),
116 web_contents_(web_contents), 113 web_contents_(web_contents),
117 auto_close_(auto_close), 114 auto_close_(reason == AUTOMATIC),
118 immersive_mode_controller_(immersive_mode_controller) { 115 immersive_mode_controller_(immersive_mode_controller) {
119 // Compensate for built-in vertical padding in the anchor view's image. 116 // Compensate for built-in vertical padding in the anchor view's image.
120 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); 117 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
121 set_notify_enter_exit_on_child(true); 118 set_notify_enter_exit_on_child(true);
122 immersive_mode_controller_->AddObserver(this); 119 immersive_mode_controller_->AddObserver(this);
123 } 120 }
124 121
125 ZoomBubbleView::~ZoomBubbleView() { 122 ZoomBubbleView::~ZoomBubbleView() {
126 if (immersive_mode_controller_) 123 if (immersive_mode_controller_)
127 immersive_mode_controller_->RemoveObserver(this); 124 immersive_mode_controller_->RemoveObserver(this);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 extension_info_.icon_image.reset( 288 extension_info_.icon_image.reset(
292 new extensions::IconImage(web_contents_->GetBrowserContext(), 289 new extensions::IconImage(web_contents_->GetBrowserContext(),
293 extension, 290 extension,
294 browser_action->default_icon, 291 browser_action->default_icon,
295 icon_size, 292 icon_size,
296 default_extension_icon_image, 293 default_extension_icon_image,
297 this)); 294 this));
298 } 295 }
299 296
300 void ZoomBubbleView::StartTimerIfNecessary() { 297 void ZoomBubbleView::StartTimerIfNecessary() {
301 if (auto_close_) { 298 if (!auto_close_)
302 if (timer_.IsRunning()) { 299 return;
303 timer_.Reset(); 300
304 } else { 301 if (timer_.IsRunning()) {
305 // The number of milliseconds the bubble should stay on the screen if it 302 timer_.Reset();
306 // will close automatically. 303 } else {
307 const int kBubbleCloseDelay = 1500; 304 // The number of milliseconds the bubble should stay on the screen if it
308 timer_.Start( 305 // will close automatically.
309 FROM_HERE, 306 const int kBubbleCloseDelay = 1500;
310 base::TimeDelta::FromMilliseconds(kBubbleCloseDelay), 307 timer_.Start(
311 this, 308 FROM_HERE,
312 &ZoomBubbleView::Close); 309 base::TimeDelta::FromMilliseconds(kBubbleCloseDelay),
313 } 310 this,
311 &ZoomBubbleView::Close);
314 } 312 }
315 } 313 }
316 314
317 void ZoomBubbleView::StopTimer() { 315 void ZoomBubbleView::StopTimer() {
318 timer_.Stop(); 316 timer_.Stop();
319 } 317 }
320 318
321 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} 319 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {}
322 320
323 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} 321 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698