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

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

Issue 2834493007: MacViews: Allows the toolkit-views Zoom Dialog to be used (Closed)
Patch Set: MacViews: Allows the toolkit-views Zoom Dialog to be used (keep anchoring) Created 3 years, 7 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/platform_util.h"
11 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h" 13 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_tabstrip.h" 14 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/browser/ui/browser_window.h" 15 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/views/frame/browser_view.h" 16 #include "chrome/browser/ui/views/frame/browser_view.h"
16 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 17 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
17 #include "chrome/browser/ui/views/location_bar/zoom_view.h" 18 #include "chrome/browser/ui/views/location_bar/zoom_view.h"
18 #include "chrome/common/extensions/api/extension_action/action_info.h" 19 #include "chrome/common/extensions/api/extension_action/action_info.h"
19 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
20 #include "chrome/grit/theme_resources.h" 21 #include "chrome/grit/theme_resources.h"
21 #include "components/zoom/page_zoom.h" 22 #include "components/zoom/page_zoom.h"
22 #include "components/zoom/zoom_controller.h" 23 #include "components/zoom/zoom_controller.h"
23 #include "content/public/browser/notification_source.h" 24 #include "content/public/browser/notification_source.h"
24 #include "extensions/browser/extension_zoom_request_client.h" 25 #include "extensions/browser/extension_zoom_request_client.h"
25 #include "extensions/common/manifest_handlers/icons_handler.h" 26 #include "extensions/common/manifest_handlers/icons_handler.h"
26 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/material_design/material_design_controller.h" 28 #include "ui/base/material_design/material_design_controller.h"
28 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/base/ui_features.h"
29 #include "ui/gfx/favicon_size.h" 31 #include "ui/gfx/favicon_size.h"
30 #include "ui/views/controls/button/image_button.h" 32 #include "ui/views/controls/button/image_button.h"
31 #include "ui/views/controls/button/md_text_button.h" 33 #include "ui/views/controls/button/md_text_button.h"
32 #include "ui/views/controls/separator.h" 34 #include "ui/views/controls/separator.h"
33 #include "ui/views/layout/grid_layout.h" 35 #include "ui/views/layout/grid_layout.h"
34 #include "ui/views/layout/layout_constants.h" 36 #include "ui/views/layout/layout_constants.h"
35 #include "ui/views/widget/widget.h" 37 #include "ui/views/widget/widget.h"
36 38
37 // static 39 // static
38 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = nullptr; 40 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = nullptr;
39 41
40 // static 42 // static
41 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents, 43 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents,
44 const gfx::Point& anchor_point,
42 DisplayReason reason) { 45 DisplayReason reason) {
43 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 46 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
44 DCHECK(browser && browser->window() && 47 DCHECK(browser && browser->window() &&
45 browser->exclusive_access_manager()->fullscreen_controller()); 48 browser->exclusive_access_manager()->fullscreen_controller());
46 49
50 views::View* anchor_view = nullptr;
51 ImmersiveModeController* immersive_mode_controller = nullptr;
52 bool is_fullscreen = browser->window()->IsFullscreen();
53 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
47 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 54 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
48 bool is_fullscreen = browser_view->IsFullscreen();
49 views::View* anchor_view = nullptr;
50 if (!is_fullscreen || 55 if (!is_fullscreen ||
51 browser_view->immersive_mode_controller()->IsRevealed()) { 56 browser_view->immersive_mode_controller()->IsRevealed()) {
52 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) 57 if (ui::MaterialDesignController::IsSecondaryUiMaterial())
53 anchor_view = browser_view->GetLocationBarView(); 58 anchor_view = browser_view->GetLocationBarView();
54 else 59 else
55 anchor_view = browser_view->GetLocationBarView()->zoom_view(); 60 anchor_view = browser_view->GetLocationBarView()->zoom_view();
56 } 61 }
62 immersive_mode_controller = browser_view->immersive_mode_controller();
63 #endif
57 64
58 // Find the extension that initiated the zoom change, if any. 65 // Find the extension that initiated the zoom change, if any.
59 zoom::ZoomController* zoom_controller = 66 zoom::ZoomController* zoom_controller =
60 zoom::ZoomController::FromWebContents(web_contents); 67 zoom::ZoomController::FromWebContents(web_contents);
61 const zoom::ZoomRequestClient* client = zoom_controller->last_client(); 68 const zoom::ZoomRequestClient* client = zoom_controller->last_client();
62 69
63 // If the bubble is already showing in this window and the zoom change was not 70 // If the bubble is already showing in this window and the zoom change was not
64 // initiated by an extension, then the bubble can be reused and only the label 71 // initiated by an extension, then the bubble can be reused and only the label
65 // text needs to be updated. 72 // text needs to be updated.
66 if (zoom_bubble_ && zoom_bubble_->GetAnchorView() == anchor_view && !client) { 73 if (zoom_bubble_ && zoom_bubble_->GetAnchorView() == anchor_view && !client) {
67 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_); 74 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_);
68 zoom_bubble_->Refresh(); 75 zoom_bubble_->Refresh();
69 return; 76 return;
70 } 77 }
71 78
72 // If the bubble is already showing but in a different tab, the current 79 // If the bubble is already showing but in a different tab, the current
73 // bubble must be closed and a new one created. 80 // bubble must be closed and a new one created.
74 CloseCurrentBubble(); 81 CloseCurrentBubble();
75 82
76 zoom_bubble_ = new ZoomBubbleView(anchor_view, web_contents, reason, 83 zoom_bubble_ = new ZoomBubbleView(anchor_view, anchor_point, web_contents,
77 browser_view->immersive_mode_controller()); 84 reason, immersive_mode_controller);
78 85
79 // 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
80 // information from it. 87 // information from it.
81 if (client) { 88 if (client) {
82 zoom_bubble_->SetExtensionInfo( 89 zoom_bubble_->SetExtensionInfo(
83 static_cast<const extensions::ExtensionZoomRequestClient*>(client) 90 static_cast<const extensions::ExtensionZoomRequestClient*>(client)
84 ->extension()); 91 ->extension());
85 } 92 }
86 93
94 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
87 // If we do not have an anchor view, parent the bubble to the content area. 95 // If we do not have an anchor view, parent the bubble to the content area.
88 if (!anchor_view) 96 if (!anchor_view)
89 zoom_bubble_->set_parent_window(web_contents->GetNativeView()); 97 zoom_bubble_->set_parent_window(web_contents->GetNativeView());
90 98
91 views::Widget* zoom_bubble_widget = 99 views::Widget* zoom_bubble_widget =
92 views::BubbleDialogDelegateView::CreateBubble(zoom_bubble_); 100 views::BubbleDialogDelegateView::CreateBubble(zoom_bubble_);
93 if (anchor_view) { 101 if (anchor_view) {
94 zoom_bubble_widget->AddObserver( 102 zoom_bubble_widget->AddObserver(
95 browser_view->GetLocationBarView()->zoom_view()); 103 browser_view->GetLocationBarView()->zoom_view());
96 } 104 }
105 #else
106 gfx::NativeView parent =
107 platform_util::GetViewForWindow(browser->window()->GetNativeWindow());
108 DCHECK(parent);
109 zoom_bubble_->set_arrow(views::BubbleBorder::TOP_RIGHT);
110 zoom_bubble_->set_parent_window(parent);
111 views::BubbleDialogDelegateView::CreateBubble(zoom_bubble_);
112 #endif
97 113
98 // Adjust for fullscreen after creation as it relies on the content size. 114 // Adjust for fullscreen after creation as it relies on the content size.
99 if (is_fullscreen) 115 if (is_fullscreen)
100 zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen()); 116 zoom_bubble_->AdjustForFullscreen(browser->window()->GetBounds());
101 117
102 zoom_bubble_->ShowForReason(reason); 118 zoom_bubble_->ShowForReason(reason);
103 } 119 }
104 120
105 // static 121 // static
106 void ZoomBubbleView::CloseCurrentBubble() { 122 void ZoomBubbleView::CloseCurrentBubble() {
107 if (zoom_bubble_) 123 if (zoom_bubble_)
108 zoom_bubble_->CloseBubble(); 124 zoom_bubble_->CloseBubble();
109 } 125 }
110 126
111 // static 127 // static
112 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() { 128 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() {
113 return zoom_bubble_; 129 return zoom_bubble_;
114 } 130 }
115 131
132 void ZoomBubbleView::Refresh() {
133 zoom::ZoomController* zoom_controller =
134 zoom::ZoomController::FromWebContents(web_contents_);
135 int zoom_percent = zoom_controller->GetZoomPercent();
136 label_->SetText(l10n_util::GetStringFUTF16(
137 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent)));
138 StartTimerIfNecessary();
139 }
140
116 ZoomBubbleView::ZoomBubbleView( 141 ZoomBubbleView::ZoomBubbleView(
117 views::View* anchor_view, 142 views::View* anchor_view,
143 const gfx::Point& anchor_point,
118 content::WebContents* web_contents, 144 content::WebContents* web_contents,
119 DisplayReason reason, 145 DisplayReason reason,
120 ImmersiveModeController* immersive_mode_controller) 146 ImmersiveModeController* immersive_mode_controller)
121 : LocationBarBubbleDelegateView(anchor_view, web_contents), 147 : LocationBarBubbleDelegateView(anchor_view, anchor_point, web_contents),
122 image_button_(nullptr), 148 image_button_(nullptr),
123 label_(nullptr), 149 label_(nullptr),
124 web_contents_(web_contents), 150 web_contents_(web_contents),
125 auto_close_(reason == AUTOMATIC), 151 auto_close_(reason == AUTOMATIC),
126 immersive_mode_controller_(immersive_mode_controller) { 152 immersive_mode_controller_(immersive_mode_controller) {
127 set_notify_enter_exit_on_child(true); 153 set_notify_enter_exit_on_child(true);
128 immersive_mode_controller_->AddObserver(this); 154 if (immersive_mode_controller_)
155 immersive_mode_controller_->AddObserver(this);
129 UseCompactMargins(); 156 UseCompactMargins();
130 } 157 }
131 158
132 ZoomBubbleView::~ZoomBubbleView() { 159 ZoomBubbleView::~ZoomBubbleView() {
133 if (immersive_mode_controller_) 160 if (immersive_mode_controller_)
134 immersive_mode_controller_->RemoveObserver(this); 161 immersive_mode_controller_->RemoveObserver(this);
135 } 162 }
136 163
137 void ZoomBubbleView::OnGestureEvent(ui::GestureEvent* event) { 164 void ZoomBubbleView::OnGestureEvent(ui::GestureEvent* event) {
138 if (!zoom_bubble_ || !zoom_bubble_->auto_close_ || 165 if (!zoom_bubble_ || !zoom_bubble_->auto_close_ ||
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 &extension_info_.icon_image->image_skia()); 206 &extension_info_.icon_image->image_skia());
180 grid_layout->AddView(image_button_); 207 grid_layout->AddView(image_button_);
181 } 208 }
182 209
183 // Add zoom label with the new zoom percent. 210 // Add zoom label with the new zoom percent.
184 zoom::ZoomController* zoom_controller = 211 zoom::ZoomController* zoom_controller =
185 zoom::ZoomController::FromWebContents(web_contents_); 212 zoom::ZoomController::FromWebContents(web_contents_);
186 int zoom_percent = zoom_controller->GetZoomPercent(); 213 int zoom_percent = zoom_controller->GetZoomPercent();
187 label_ = new views::Label(l10n_util::GetStringFUTF16( 214 label_ = new views::Label(l10n_util::GetStringFUTF16(
188 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent))); 215 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent)));
189 label_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( 216 label_->SetFontList(GetTitleFontList());
190 ui::ResourceBundle::MediumFont));
191 grid_layout->AddView(label_); 217 grid_layout->AddView(label_);
192 218
193 // Second row. 219 // Second row.
194 grid_layout->AddPaddingRow(0, 8); 220 grid_layout->AddPaddingRow(0, 8);
195 columns = grid_layout->AddColumnSet(1); 221 columns = grid_layout->AddColumnSet(1);
196 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 222 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
197 views::GridLayout::USE_PREF, 0, 0); 223 views::GridLayout::USE_PREF, 0, 0);
198 grid_layout->StartRow(0, 1); 224 grid_layout->StartRow(0, 1);
199 225
200 // Add "Reset to Default" button. 226 // Add "Reset to Default" button.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 immersive_mode_controller_ = nullptr; 268 immersive_mode_controller_ = nullptr;
243 } 269 }
244 270
245 void ZoomBubbleView::OnExtensionIconImageChanged( 271 void ZoomBubbleView::OnExtensionIconImageChanged(
246 extensions::IconImage* /* image */) { 272 extensions::IconImage* /* image */) {
247 image_button_->SetImage(views::Button::STATE_NORMAL, 273 image_button_->SetImage(views::Button::STATE_NORMAL,
248 &extension_info_.icon_image->image_skia()); 274 &extension_info_.icon_image->image_skia());
249 image_button_->SchedulePaint(); 275 image_button_->SchedulePaint();
250 } 276 }
251 277
252 void ZoomBubbleView::Refresh() {
253 zoom::ZoomController* zoom_controller =
254 zoom::ZoomController::FromWebContents(web_contents_);
255 int zoom_percent = zoom_controller->GetZoomPercent();
256 label_->SetText(l10n_util::GetStringFUTF16(
257 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent)));
258 StartTimerIfNecessary();
259 }
260
261 void ZoomBubbleView::SetExtensionInfo(const extensions::Extension* extension) { 278 void ZoomBubbleView::SetExtensionInfo(const extensions::Extension* extension) {
262 DCHECK(extension); 279 DCHECK(extension);
263 extension_info_.id = extension->id(); 280 extension_info_.id = extension->id();
264 extension_info_.name = extension->name(); 281 extension_info_.name = extension->name();
265 282
266 ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 283 ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
267 const gfx::ImageSkia& default_extension_icon_image = 284 const gfx::ImageSkia& default_extension_icon_image =
268 *rb.GetImageSkiaNamed(IDR_EXTENSIONS_FAVICON); 285 *rb.GetImageSkiaNamed(IDR_EXTENSIONS_FAVICON);
269 int icon_size = gfx::kFaviconSize; 286 int icon_size = gfx::kFaviconSize;
270 287
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 } 335 }
319 } 336 }
320 337
321 void ZoomBubbleView::StopTimer() { 338 void ZoomBubbleView::StopTimer() {
322 timer_.Stop(); 339 timer_.Stop();
323 } 340 }
324 341
325 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} 342 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {}
326 343
327 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} 344 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698