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

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: actually fix 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"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h" 12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_tabstrip.h" 13 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/browser/ui/browser_window.h" 14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/views/frame/browser_view.h" 15 #include "chrome/browser/ui/views/frame/browser_view.h"
16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
17 #include "chrome/browser/ui/views/location_bar/zoom_view.h" 17 #include "chrome/browser/ui/views/location_bar/zoom_view.h"
18 #include "chrome/common/extensions/api/extension_action/action_info.h" 18 #include "chrome/common/extensions/api/extension_action/action_info.h"
19 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
20 #include "chrome/grit/theme_resources.h" 20 #include "chrome/grit/theme_resources.h"
21 #include "components/zoom/page_zoom.h" 21 #include "components/zoom/page_zoom.h"
22 #include "components/zoom/zoom_controller.h" 22 #include "components/zoom/zoom_controller.h"
23 #include "content/public/browser/notification_source.h" 23 #include "content/public/browser/notification_source.h"
24 #include "extensions/browser/extension_zoom_request_client.h" 24 #include "extensions/browser/extension_zoom_request_client.h"
25 #include "extensions/common/manifest_handlers/icons_handler.h" 25 #include "extensions/common/manifest_handlers/icons_handler.h"
26 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/material_design/material_design_controller.h"
27 #include "ui/base/resource/resource_bundle.h" 28 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/gfx/favicon_size.h" 29 #include "ui/gfx/favicon_size.h"
29 #include "ui/views/controls/button/image_button.h" 30 #include "ui/views/controls/button/image_button.h"
30 #include "ui/views/controls/button/md_text_button.h" 31 #include "ui/views/controls/button/md_text_button.h"
31 #include "ui/views/controls/separator.h" 32 #include "ui/views/controls/separator.h"
32 #include "ui/views/layout/grid_layout.h" 33 #include "ui/views/layout/grid_layout.h"
33 #include "ui/views/layout/layout_constants.h" 34 #include "ui/views/layout/layout_constants.h"
34 #include "ui/views/widget/widget.h" 35 #include "ui/views/widget/widget.h"
35 36
36 // static 37 // static
37 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL; 38 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = nullptr;
38 39
39 // static 40 // static
40 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents, 41 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents,
41 DisplayReason reason) { 42 DisplayReason reason) {
42 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 43 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
43 DCHECK(browser && browser->window() && 44 DCHECK(browser && browser->window() &&
44 browser->exclusive_access_manager()->fullscreen_controller()); 45 browser->exclusive_access_manager()->fullscreen_controller());
45 46
46 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 47 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
47 bool is_fullscreen = browser_view->IsFullscreen(); 48 bool is_fullscreen = browser_view->IsFullscreen();
48 bool anchor_to_view = !is_fullscreen || 49 views::View* anchor_view = nullptr;
49 browser_view->immersive_mode_controller()->IsRevealed(); 50 if (!is_fullscreen ||
50 ZoomView* anchor_view = anchor_to_view ? 51 browser_view->immersive_mode_controller()->IsRevealed()) {
51 browser_view->GetLocationBarView()->zoom_view() : NULL; 52 if (ui::MaterialDesignController::IsSecondaryUiMaterial())
53 anchor_view = browser_view->GetLocationBarView();
54 else
55 anchor_view = browser_view->GetLocationBarView()->zoom_view();
56 }
52 57
53 // Find the extension that initiated the zoom change, if any. 58 // Find the extension that initiated the zoom change, if any.
54 zoom::ZoomController* zoom_controller = 59 zoom::ZoomController* zoom_controller =
55 zoom::ZoomController::FromWebContents(web_contents); 60 zoom::ZoomController::FromWebContents(web_contents);
56 const zoom::ZoomRequestClient* client = zoom_controller->last_client(); 61 const zoom::ZoomRequestClient* client = zoom_controller->last_client();
57 62
58 // If the bubble is already showing in this window and the zoom change was not 63 // 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 64 // initiated by an extension, then the bubble can be reused and only the label
60 // text needs to be updated. 65 // text needs to be updated.
61 if (zoom_bubble_ && zoom_bubble_->GetAnchorView() == anchor_view && !client) { 66 if (zoom_bubble_ && zoom_bubble_->GetAnchorView() == anchor_view && !client) {
(...skipping 11 matching lines...) Expand all
73 78
74 // If the zoom change was initiated by an extension, capture the relevent 79 // If the zoom change was initiated by an extension, capture the relevent
75 // information from it. 80 // information from it.
76 if (client) { 81 if (client) {
77 zoom_bubble_->SetExtensionInfo( 82 zoom_bubble_->SetExtensionInfo(
78 static_cast<const extensions::ExtensionZoomRequestClient*>(client) 83 static_cast<const extensions::ExtensionZoomRequestClient*>(client)
79 ->extension()); 84 ->extension());
80 } 85 }
81 86
82 // If we do not have an anchor view, parent the bubble to the content area. 87 // If we do not have an anchor view, parent the bubble to the content area.
83 if (!anchor_to_view) 88 if (!anchor_view)
84 zoom_bubble_->set_parent_window(web_contents->GetNativeView()); 89 zoom_bubble_->set_parent_window(web_contents->GetNativeView());
85 90
86 views::Widget* zoom_bubble_widget = 91 views::Widget* zoom_bubble_widget =
87 views::BubbleDialogDelegateView::CreateBubble(zoom_bubble_); 92 views::BubbleDialogDelegateView::CreateBubble(zoom_bubble_);
88 if (anchor_view) 93 if (anchor_view) {
89 zoom_bubble_widget->AddObserver(anchor_view); 94 zoom_bubble_widget->AddObserver(
95 browser_view->GetLocationBarView()->zoom_view());
96 }
90 97
91 // Adjust for fullscreen after creation as it relies on the content size. 98 // Adjust for fullscreen after creation as it relies on the content size.
92 if (is_fullscreen) 99 if (is_fullscreen)
93 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); 100 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen());
94 101
95 zoom_bubble_->ShowForReason(reason); 102 zoom_bubble_->ShowForReason(reason);
96 } 103 }
97 104
98 // static 105 // static
99 void ZoomBubbleView::CloseCurrentBubble() { 106 void ZoomBubbleView::CloseCurrentBubble() {
100 if (zoom_bubble_) 107 if (zoom_bubble_)
101 zoom_bubble_->CloseBubble(); 108 zoom_bubble_->CloseBubble();
102 } 109 }
103 110
104 // static 111 // static
105 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() { 112 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() {
106 return zoom_bubble_; 113 return zoom_bubble_;
107 } 114 }
108 115
109 ZoomBubbleView::ZoomBubbleView( 116 ZoomBubbleView::ZoomBubbleView(
110 views::View* anchor_view, 117 views::View* anchor_view,
111 content::WebContents* web_contents, 118 content::WebContents* web_contents,
112 DisplayReason reason, 119 DisplayReason reason,
113 ImmersiveModeController* immersive_mode_controller) 120 ImmersiveModeController* immersive_mode_controller)
114 : LocationBarBubbleDelegateView(anchor_view, web_contents), 121 : LocationBarBubbleDelegateView(anchor_view, web_contents),
115 image_button_(NULL), 122 image_button_(nullptr),
116 label_(NULL), 123 label_(nullptr),
117 web_contents_(web_contents), 124 web_contents_(web_contents),
118 auto_close_(reason == AUTOMATIC), 125 auto_close_(reason == AUTOMATIC),
119 immersive_mode_controller_(immersive_mode_controller) { 126 immersive_mode_controller_(immersive_mode_controller) {
120 set_notify_enter_exit_on_child(true); 127 set_notify_enter_exit_on_child(true);
121 immersive_mode_controller_->AddObserver(this); 128 immersive_mode_controller_->AddObserver(this);
122 UseCompactMargins(); 129 UseCompactMargins();
123 } 130 }
124 131
125 ZoomBubbleView::~ZoomBubbleView() { 132 ZoomBubbleView::~ZoomBubbleView() {
126 if (immersive_mode_controller_) 133 if (immersive_mode_controller_)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 // Add "Reset to Default" button. 200 // Add "Reset to Default" button.
194 grid_layout->AddView( 201 grid_layout->AddView(
195 views::MdTextButton::CreateSecondaryUiButton( 202 views::MdTextButton::CreateSecondaryUiButton(
196 this, l10n_util::GetStringUTF16(IDS_ZOOM_SET_DEFAULT))); 203 this, l10n_util::GetStringUTF16(IDS_ZOOM_SET_DEFAULT)));
197 204
198 StartTimerIfNecessary(); 205 StartTimerIfNecessary();
199 } 206 }
200 207
201 void ZoomBubbleView::WindowClosing() { 208 void ZoomBubbleView::WindowClosing() {
202 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't 209 // |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. 210 // call this right away). Only set to nullptr when it's this bubble.
204 if (zoom_bubble_ == this) 211 if (zoom_bubble_ == this)
205 zoom_bubble_ = NULL; 212 zoom_bubble_ = nullptr;
206 } 213 }
207 214
208 void ZoomBubbleView::CloseBubble() { 215 void ZoomBubbleView::CloseBubble() {
209 // Widget's Close() is async, but we don't want to use zoom_bubble_ after 216 // Widget's Close() is async, but we don't want to use zoom_bubble_ after
210 // this. Additionally web_contents_ may have been destroyed. 217 // this. Additionally web_contents_ may have been destroyed.
211 zoom_bubble_ = NULL; 218 zoom_bubble_ = nullptr;
212 web_contents_ = NULL; 219 web_contents_ = nullptr;
213 LocationBarBubbleDelegateView::CloseBubble(); 220 LocationBarBubbleDelegateView::CloseBubble();
214 } 221 }
215 222
216 void ZoomBubbleView::ButtonPressed(views::Button* sender, 223 void ZoomBubbleView::ButtonPressed(views::Button* sender,
217 const ui::Event& event) { 224 const ui::Event& event) {
218 if (sender == image_button_) { 225 if (sender == image_button_) {
219 DCHECK(extension_info_.icon_image) << "Invalid button press."; 226 DCHECK(extension_info_.icon_image) << "Invalid button press.";
220 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); 227 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
221 chrome::AddSelectedTabWithURL( 228 chrome::AddSelectedTabWithURL(
222 browser, GURL(base::StringPrintf("chrome://extensions?id=%s", 229 browser, GURL(base::StringPrintf("chrome://extensions?id=%s",
223 extension_info_.id.c_str())), 230 extension_info_.id.c_str())),
224 ui::PAGE_TRANSITION_FROM_API); 231 ui::PAGE_TRANSITION_FROM_API);
225 } else { 232 } else {
226 zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_RESET); 233 zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_RESET);
227 } 234 }
228 } 235 }
229 236
230 void ZoomBubbleView::OnImmersiveRevealStarted() { 237 void ZoomBubbleView::OnImmersiveRevealStarted() {
231 CloseBubble(); 238 CloseBubble();
232 } 239 }
233 240
234 void ZoomBubbleView::OnImmersiveModeControllerDestroyed() { 241 void ZoomBubbleView::OnImmersiveModeControllerDestroyed() {
235 immersive_mode_controller_ = NULL; 242 immersive_mode_controller_ = nullptr;
236 } 243 }
237 244
238 void ZoomBubbleView::OnExtensionIconImageChanged( 245 void ZoomBubbleView::OnExtensionIconImageChanged(
239 extensions::IconImage* /* image */) { 246 extensions::IconImage* /* image */) {
240 image_button_->SetImage(views::Button::STATE_NORMAL, 247 image_button_->SetImage(views::Button::STATE_NORMAL,
241 &extension_info_.icon_image->image_skia()); 248 &extension_info_.icon_image->image_skia());
242 image_button_->SchedulePaint(); 249 image_button_->SchedulePaint();
243 } 250 }
244 251
245 void ZoomBubbleView::Refresh() { 252 void ZoomBubbleView::Refresh() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 318 }
312 } 319 }
313 320
314 void ZoomBubbleView::StopTimer() { 321 void ZoomBubbleView::StopTimer() {
315 timer_.Stop(); 322 timer_.Stop();
316 } 323 }
317 324
318 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} 325 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {}
319 326
320 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} 327 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698