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

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

Issue 2394143004: Harmony - Update anchors for the rest of the location bar icons that (Closed)
Patch Set: Created 4 years, 2 months 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/number_formatting.h" 7 #include "base/i18n/number_formatting.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 16 matching lines...) Expand all
27 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/gfx/favicon_size.h" 28 #include "ui/gfx/favicon_size.h"
29 #include "ui/views/controls/button/image_button.h" 29 #include "ui/views/controls/button/image_button.h"
30 #include "ui/views/controls/button/md_text_button.h" 30 #include "ui/views/controls/button/md_text_button.h"
31 #include "ui/views/controls/separator.h" 31 #include "ui/views/controls/separator.h"
32 #include "ui/views/layout/grid_layout.h" 32 #include "ui/views/layout/grid_layout.h"
33 #include "ui/views/layout/layout_constants.h" 33 #include "ui/views/layout/layout_constants.h"
34 #include "ui/views/widget/widget.h" 34 #include "ui/views/widget/widget.h"
35 35
36 // static 36 // static
37 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL; 37 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = nullptr;
38 38
39 // static 39 // static
40 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents, 40 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents,
41 DisplayReason reason) { 41 DisplayReason reason) {
42 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 42 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
43 DCHECK(browser && browser->window() && 43 DCHECK(browser && browser->window() &&
44 browser->exclusive_access_manager()->fullscreen_controller()); 44 browser->exclusive_access_manager()->fullscreen_controller());
45 45
46 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 46 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
47 bool is_fullscreen = browser_view->IsFullscreen(); 47 bool is_fullscreen = browser_view->IsFullscreen();
48 bool anchor_to_view = !is_fullscreen || 48 bool anchor_to_view = !is_fullscreen ||
49 browser_view->immersive_mode_controller()->IsRevealed(); 49 browser_view->immersive_mode_controller()->IsRevealed();
50 ZoomView* anchor_view = anchor_to_view ? 50 views::View* anchor_view =
msw 2016/10/11 17:04:54 Should this still anchor to the zoom_view if not u
Evan Stade 2016/10/11 23:49:50 yes, thanks for catching.
51 browser_view->GetLocationBarView()->zoom_view() : NULL; 51 anchor_to_view ? browser_view->GetLocationBarView() : nullptr;
52 52
53 // Find the extension that initiated the zoom change, if any. 53 // Find the extension that initiated the zoom change, if any.
54 zoom::ZoomController* zoom_controller = 54 zoom::ZoomController* zoom_controller =
55 zoom::ZoomController::FromWebContents(web_contents); 55 zoom::ZoomController::FromWebContents(web_contents);
56 const zoom::ZoomRequestClient* client = zoom_controller->last_client(); 56 const zoom::ZoomRequestClient* client = zoom_controller->last_client();
57 57
58 // If the bubble is already showing in this window and the zoom change was not 58 // If the bubble is already showing in this window and the zoom change was not
59 // initiated by an extension, then the bubble can be reused and only the label 59 // initiated by an extension, then the bubble can be reused and only the label
60 // text needs to be updated. 60 // text needs to be updated.
61 if (zoom_bubble_ && zoom_bubble_->GetAnchorView() == anchor_view && !client) { 61 if (zoom_bubble_ && zoom_bubble_->GetAnchorView() == anchor_view && !client) {
(...skipping 16 matching lines...) Expand all
78 static_cast<const extensions::ExtensionZoomRequestClient*>(client) 78 static_cast<const extensions::ExtensionZoomRequestClient*>(client)
79 ->extension()); 79 ->extension());
80 } 80 }
81 81
82 // If we do not have an anchor view, parent the bubble to the content area. 82 // If we do not have an anchor view, parent the bubble to the content area.
83 if (!anchor_to_view) 83 if (!anchor_to_view)
84 zoom_bubble_->set_parent_window(web_contents->GetNativeView()); 84 zoom_bubble_->set_parent_window(web_contents->GetNativeView());
85 85
86 views::Widget* zoom_bubble_widget = 86 views::Widget* zoom_bubble_widget =
87 views::BubbleDialogDelegateView::CreateBubble(zoom_bubble_); 87 views::BubbleDialogDelegateView::CreateBubble(zoom_bubble_);
88 if (anchor_view) 88 if (anchor_to_view) {
89 zoom_bubble_widget->AddObserver(anchor_view); 89 zoom_bubble_widget->AddObserver(
90 browser_view->GetLocationBarView()->zoom_view());
91 }
90 92
91 // Adjust for fullscreen after creation as it relies on the content size. 93 // Adjust for fullscreen after creation as it relies on the content size.
92 if (is_fullscreen) 94 if (is_fullscreen)
93 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); 95 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen());
94 96
95 zoom_bubble_->ShowForReason(reason); 97 zoom_bubble_->ShowForReason(reason);
96 } 98 }
97 99
98 // static 100 // static
99 void ZoomBubbleView::CloseCurrentBubble() { 101 void ZoomBubbleView::CloseCurrentBubble() {
100 if (zoom_bubble_) 102 if (zoom_bubble_)
101 zoom_bubble_->CloseBubble(); 103 zoom_bubble_->CloseBubble();
102 } 104 }
103 105
104 // static 106 // static
105 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() { 107 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() {
106 return zoom_bubble_; 108 return zoom_bubble_;
107 } 109 }
108 110
109 ZoomBubbleView::ZoomBubbleView( 111 ZoomBubbleView::ZoomBubbleView(
110 views::View* anchor_view, 112 views::View* anchor_view,
111 content::WebContents* web_contents, 113 content::WebContents* web_contents,
112 DisplayReason reason, 114 DisplayReason reason,
113 ImmersiveModeController* immersive_mode_controller) 115 ImmersiveModeController* immersive_mode_controller)
114 : LocationBarBubbleDelegateView(anchor_view, web_contents), 116 : LocationBarBubbleDelegateView(anchor_view, web_contents),
115 image_button_(NULL), 117 image_button_(nullptr),
116 label_(NULL), 118 label_(nullptr),
117 web_contents_(web_contents), 119 web_contents_(web_contents),
118 auto_close_(reason == AUTOMATIC), 120 auto_close_(reason == AUTOMATIC),
119 immersive_mode_controller_(immersive_mode_controller) { 121 immersive_mode_controller_(immersive_mode_controller) {
120 set_notify_enter_exit_on_child(true); 122 set_notify_enter_exit_on_child(true);
121 immersive_mode_controller_->AddObserver(this); 123 immersive_mode_controller_->AddObserver(this);
122 UseCompactMargins(); 124 UseCompactMargins();
123 } 125 }
124 126
125 ZoomBubbleView::~ZoomBubbleView() { 127 ZoomBubbleView::~ZoomBubbleView() {
126 if (immersive_mode_controller_) 128 if (immersive_mode_controller_)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // Add "Reset to Default" button. 195 // Add "Reset to Default" button.
194 grid_layout->AddView( 196 grid_layout->AddView(
195 views::MdTextButton::CreateSecondaryUiButton( 197 views::MdTextButton::CreateSecondaryUiButton(
196 this, l10n_util::GetStringUTF16(IDS_ZOOM_SET_DEFAULT))); 198 this, l10n_util::GetStringUTF16(IDS_ZOOM_SET_DEFAULT)));
197 199
198 StartTimerIfNecessary(); 200 StartTimerIfNecessary();
199 } 201 }
200 202
201 void ZoomBubbleView::WindowClosing() { 203 void ZoomBubbleView::WindowClosing() {
202 // |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
203 // call this right away). Only set to NULL when it's this bubble. 205 // call this right away). Only set to nullptr when it's this bubble.
204 if (zoom_bubble_ == this) 206 if (zoom_bubble_ == this)
205 zoom_bubble_ = NULL; 207 zoom_bubble_ = nullptr;
206 } 208 }
207 209
208 void ZoomBubbleView::CloseBubble() { 210 void ZoomBubbleView::CloseBubble() {
209 // 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
210 // this. Additionally web_contents_ may have been destroyed. 212 // this. Additionally web_contents_ may have been destroyed.
211 zoom_bubble_ = NULL; 213 zoom_bubble_ = nullptr;
212 web_contents_ = NULL; 214 web_contents_ = nullptr;
213 LocationBarBubbleDelegateView::CloseBubble(); 215 LocationBarBubbleDelegateView::CloseBubble();
214 } 216 }
215 217
216 void ZoomBubbleView::ButtonPressed(views::Button* sender, 218 void ZoomBubbleView::ButtonPressed(views::Button* sender,
217 const ui::Event& event) { 219 const ui::Event& event) {
218 if (sender == image_button_) { 220 if (sender == image_button_) {
219 DCHECK(extension_info_.icon_image) << "Invalid button press."; 221 DCHECK(extension_info_.icon_image) << "Invalid button press.";
220 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); 222 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
221 chrome::AddSelectedTabWithURL( 223 chrome::AddSelectedTabWithURL(
222 browser, GURL(base::StringPrintf("chrome://extensions?id=%s", 224 browser, GURL(base::StringPrintf("chrome://extensions?id=%s",
223 extension_info_.id.c_str())), 225 extension_info_.id.c_str())),
224 ui::PAGE_TRANSITION_FROM_API); 226 ui::PAGE_TRANSITION_FROM_API);
225 } else { 227 } else {
226 zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_RESET); 228 zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_RESET);
227 } 229 }
228 } 230 }
229 231
230 void ZoomBubbleView::OnImmersiveRevealStarted() { 232 void ZoomBubbleView::OnImmersiveRevealStarted() {
231 CloseBubble(); 233 CloseBubble();
232 } 234 }
233 235
234 void ZoomBubbleView::OnImmersiveModeControllerDestroyed() { 236 void ZoomBubbleView::OnImmersiveModeControllerDestroyed() {
235 immersive_mode_controller_ = NULL; 237 immersive_mode_controller_ = nullptr;
236 } 238 }
237 239
238 void ZoomBubbleView::OnExtensionIconImageChanged( 240 void ZoomBubbleView::OnExtensionIconImageChanged(
239 extensions::IconImage* /* image */) { 241 extensions::IconImage* /* image */) {
240 image_button_->SetImage(views::Button::STATE_NORMAL, 242 image_button_->SetImage(views::Button::STATE_NORMAL,
241 &extension_info_.icon_image->image_skia()); 243 &extension_info_.icon_image->image_skia());
242 image_button_->SchedulePaint(); 244 image_button_->SchedulePaint();
243 } 245 }
244 246
245 void ZoomBubbleView::Refresh() { 247 void ZoomBubbleView::Refresh() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 313 }
312 } 314 }
313 315
314 void ZoomBubbleView::StopTimer() { 316 void ZoomBubbleView::StopTimer() {
315 timer_.Stop(); 317 timer_.Stop();
316 } 318 }
317 319
318 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} 320 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {}
319 321
320 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} 322 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698