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

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

Issue 2845593002: Updates Zoom bubble layout and adds +/- buttons (Closed)
Patch Set: Updates Zoom bubble layout and adds +/- buttons (vector images) 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/auto_reset.h"
7 #include "base/i18n/number_formatting.h" 8 #include "base/i18n/number_formatting.h"
8 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
9 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "chrome/app/vector_icons/vector_icons.h"
10 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/platform_util.h" 13 #include "chrome/browser/platform_util.h"
12 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_finder.h" 15 #include "chrome/browser/ui/browser_finder.h"
14 #include "chrome/browser/ui/browser_tabstrip.h" 16 #include "chrome/browser/ui/browser_tabstrip.h"
15 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
16 #include "chrome/browser/ui/views/frame/browser_view.h" 18 #include "chrome/browser/ui/views/frame/browser_view.h"
17 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 19 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
18 #include "chrome/browser/ui/views/location_bar/zoom_view.h" 20 #include "chrome/browser/ui/views/location_bar/zoom_view.h"
19 #include "chrome/common/extensions/api/extension_action/action_info.h" 21 #include "chrome/common/extensions/api/extension_action/action_info.h"
20 #include "chrome/grit/generated_resources.h" 22 #include "chrome/grit/generated_resources.h"
21 #include "chrome/grit/theme_resources.h" 23 #include "chrome/grit/theme_resources.h"
22 #include "components/zoom/page_zoom.h" 24 #include "components/zoom/page_zoom.h"
23 #include "components/zoom/zoom_controller.h" 25 #include "components/zoom/zoom_controller.h"
24 #include "content/public/browser/notification_source.h" 26 #include "content/public/browser/notification_source.h"
25 #include "extensions/browser/extension_zoom_request_client.h" 27 #include "extensions/browser/extension_zoom_request_client.h"
26 #include "extensions/common/manifest_handlers/icons_handler.h" 28 #include "extensions/common/manifest_handlers/icons_handler.h"
27 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/material_design/material_design_controller.h" 30 #include "ui/base/material_design/material_design_controller.h"
29 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/base/ui_features.h" 32 #include "ui/base/ui_features.h"
31 #include "ui/gfx/favicon_size.h" 33 #include "ui/gfx/favicon_size.h"
34 #include "ui/native_theme/native_theme.h"
32 #include "ui/views/controls/button/image_button.h" 35 #include "ui/views/controls/button/image_button.h"
36 #include "ui/views/controls/button/image_button_factory.h"
33 #include "ui/views/controls/button/md_text_button.h" 37 #include "ui/views/controls/button/md_text_button.h"
34 #include "ui/views/controls/separator.h" 38 #include "ui/views/controls/separator.h"
35 #include "ui/views/layout/grid_layout.h" 39 #include "ui/views/layout/grid_layout.h"
36 #include "ui/views/layout/layout_constants.h" 40 #include "ui/views/layout/layout_constants.h"
37 #include "ui/views/widget/widget.h" 41 #include "ui/views/widget/widget.h"
38 42
43 namespace {
44
45 constexpr int kVerticalInset = 2;
Evan Stade 2017/04/27 17:29:39 I would prefer these be defined where they are use
varkha 2017/04/28 02:06:14 Done.
46 constexpr int kLeftInset = 0;
47 constexpr int kRightInset = 10;
48 constexpr int kResetButtonPadding = 10;
Evan Stade 2017/04/27 17:29:39 ditto
varkha 2017/04/28 02:06:13 Done.
49
50 } // namespace
51
39 // static 52 // static
40 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = nullptr; 53 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = nullptr;
41 54
42 // static 55 // static
43 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents, 56 void ZoomBubbleView::ShowBubble(content::WebContents* web_contents,
44 const gfx::Point& anchor_point, 57 const gfx::Point& anchor_point,
45 DisplayReason reason) { 58 DisplayReason reason) {
46 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 59 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
47 DCHECK(browser && browser->window() && 60 DCHECK(browser && browser->window() &&
48 browser->exclusive_access_manager()->fullscreen_controller()); 61 browser->exclusive_access_manager()->fullscreen_controller());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 139
127 // static 140 // static
128 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() { 141 ZoomBubbleView* ZoomBubbleView::GetZoomBubble() {
129 return zoom_bubble_; 142 return zoom_bubble_;
130 } 143 }
131 144
132 void ZoomBubbleView::Refresh() { 145 void ZoomBubbleView::Refresh() {
133 zoom::ZoomController* zoom_controller = 146 zoom::ZoomController* zoom_controller =
134 zoom::ZoomController::FromWebContents(web_contents_); 147 zoom::ZoomController::FromWebContents(web_contents_);
135 int zoom_percent = zoom_controller->GetZoomPercent(); 148 int zoom_percent = zoom_controller->GetZoomPercent();
136 label_->SetText(l10n_util::GetStringFUTF16( 149 const base::string16 label_text =
137 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent))); 150 ui::MaterialDesignController::IsSecondaryUiMaterial()
151 ? base::FormatPercent(zoom_percent)
152 : l10n_util::GetStringFUTF16(IDS_TOOLTIP_ZOOM,
153 base::FormatPercent(zoom_percent));
154 label_->SetText(label_text);
varkha 2017/04/27 11:42:39 Self review: carve out utility UpdateZoomPercent()
varkha 2017/04/28 02:06:13 Done.
138 StartTimerIfNecessary(); 155 StartTimerIfNecessary();
139 } 156 }
140 157
141 ZoomBubbleView::ZoomBubbleView( 158 ZoomBubbleView::ZoomBubbleView(
142 views::View* anchor_view, 159 views::View* anchor_view,
143 const gfx::Point& anchor_point, 160 const gfx::Point& anchor_point,
144 content::WebContents* web_contents, 161 content::WebContents* web_contents,
145 DisplayReason reason, 162 DisplayReason reason,
146 ImmersiveModeController* immersive_mode_controller) 163 ImmersiveModeController* immersive_mode_controller)
147 : LocationBarBubbleDelegateView(anchor_view, anchor_point, web_contents), 164 : LocationBarBubbleDelegateView(anchor_view, anchor_point, web_contents),
148 image_button_(nullptr), 165 image_button_(nullptr),
149 label_(nullptr), 166 label_(nullptr),
167 zoom_out_button_(nullptr),
168 zoom_in_button_(nullptr),
169 reset_button_(nullptr),
150 web_contents_(web_contents), 170 web_contents_(web_contents),
151 auto_close_(reason == AUTOMATIC), 171 auto_close_(reason == AUTOMATIC),
172 ignore_close_bubble_(false),
152 immersive_mode_controller_(immersive_mode_controller) { 173 immersive_mode_controller_(immersive_mode_controller) {
153 set_notify_enter_exit_on_child(true); 174 set_notify_enter_exit_on_child(true);
154 if (immersive_mode_controller_) 175 if (immersive_mode_controller_)
155 immersive_mode_controller_->AddObserver(this); 176 immersive_mode_controller_->AddObserver(this);
156 UseCompactMargins(); 177 UseCompactMargins();
157 } 178 }
158 179
159 ZoomBubbleView::~ZoomBubbleView() { 180 ZoomBubbleView::~ZoomBubbleView() {
160 if (immersive_mode_controller_) 181 if (immersive_mode_controller_)
161 immersive_mode_controller_->RemoveObserver(this); 182 immersive_mode_controller_->RemoveObserver(this);
(...skipping 24 matching lines...) Expand all
186 views::GridLayout* grid_layout = new views::GridLayout(this); 207 views::GridLayout* grid_layout = new views::GridLayout(this);
187 SetLayoutManager(grid_layout); 208 SetLayoutManager(grid_layout);
188 views::ColumnSet* columns = grid_layout->AddColumnSet(0); 209 views::ColumnSet* columns = grid_layout->AddColumnSet(0);
189 // First row. 210 // First row.
190 if (extension_info_.icon_image) { 211 if (extension_info_.icon_image) {
191 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 2, 212 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, 2,
192 views::GridLayout::USE_PREF, 0, 0); 213 views::GridLayout::USE_PREF, 0, 0);
193 } 214 }
194 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 215 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
195 views::GridLayout::USE_PREF, 0, 0); 216 views::GridLayout::USE_PREF, 0, 0);
217 const bool material = ui::MaterialDesignController::IsSecondaryUiMaterial();
218 if (material) {
219 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
220 views::GridLayout::USE_PREF, 0, 0);
221 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
222 views::GridLayout::USE_PREF, 0, 0);
223 columns->AddPaddingColumn(0, kResetButtonPadding);
224 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 0,
225 views::GridLayout::USE_PREF, 0, 0);
226 grid_layout->SetInsets(kVerticalInset, kLeftInset, kVerticalInset,
227 kRightInset);
228 }
196 grid_layout->StartRow(0, 0); 229 grid_layout->StartRow(0, 0);
197 230
198 // If this zoom change was initiated by an extension, that extension will be 231 // If this zoom change was initiated by an extension, that extension will be
199 // attributed by showing its icon in the zoom bubble. 232 // attributed by showing its icon in the zoom bubble.
200 if (extension_info_.icon_image) { 233 if (extension_info_.icon_image) {
201 image_button_ = new views::ImageButton(this); 234 image_button_ = new views::ImageButton(this);
202 image_button_->SetTooltipText( 235 image_button_->SetTooltipText(
203 l10n_util::GetStringFUTF16(IDS_TOOLTIP_ZOOM_EXTENSION_ICON, 236 l10n_util::GetStringFUTF16(IDS_TOOLTIP_ZOOM_EXTENSION_ICON,
204 base::UTF8ToUTF16(extension_info_.name))); 237 base::UTF8ToUTF16(extension_info_.name)));
205 image_button_->SetImage(views::Button::STATE_NORMAL, 238 image_button_->SetImage(views::Button::STATE_NORMAL,
206 &extension_info_.icon_image->image_skia()); 239 &extension_info_.icon_image->image_skia());
207 grid_layout->AddView(image_button_); 240 grid_layout->AddView(image_button_);
208 } 241 }
209 242
210 // Add zoom label with the new zoom percent. 243 // Add zoom label with the new zoom percent.
211 zoom::ZoomController* zoom_controller = 244 zoom::ZoomController* zoom_controller =
212 zoom::ZoomController::FromWebContents(web_contents_); 245 zoom::ZoomController::FromWebContents(web_contents_);
213 int zoom_percent = zoom_controller->GetZoomPercent(); 246 int zoom_percent = zoom_controller->GetZoomPercent();
214 label_ = new views::Label(l10n_util::GetStringFUTF16( 247 const base::string16 label_text =
215 IDS_TOOLTIP_ZOOM, base::FormatPercent(zoom_percent))); 248 material ? base::FormatPercent(zoom_percent)
216 label_->SetFontList(GetTitleFontList()); 249 : l10n_util::GetStringFUTF16(IDS_TOOLTIP_ZOOM,
250 base::FormatPercent(zoom_percent));
251 label_ = new views::Label(label_text);
252 if (material) {
253 zoom_out_button_ = views::CreateVectorImageButton(this);
254 views::SetImageFromVectorIcon(zoom_out_button_, kMinusIcon);
255 zoom_out_button_->SetFocusForPlatform();
256 zoom_out_button_->SetTooltipText(
257 l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM_MINUS2));
varkha 2017/04/27 11:42:39 Self review: carve out utility ImageButton* Create
varkha 2017/04/28 02:06:13 Done.
258 grid_layout->AddView(zoom_out_button_);
259
260 label_->SetEnabledColor(GetNativeTheme()->GetSystemColor(
261 ui::NativeTheme::kColorId_ButtonEnabledColor));
262 } else {
263 label_->SetFontList(GetTitleFontList());
264 }
217 grid_layout->AddView(label_); 265 grid_layout->AddView(label_);
218 266
219 // Second row. 267 if (material) {
220 grid_layout->AddPaddingRow(0, 8); 268 zoom_in_button_ = views::CreateVectorImageButton(this);
221 columns = grid_layout->AddColumnSet(1); 269 views::SetImageFromVectorIcon(zoom_in_button_, kPlusIcon);
222 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, 270 zoom_in_button_->SetFocusForPlatform();
223 views::GridLayout::USE_PREF, 0, 0); 271 zoom_in_button_->SetTooltipText(
224 grid_layout->StartRow(0, 1); 272 l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM_PLUS2));
273 grid_layout->AddView(zoom_in_button_);
274 } else {
275 // Second row.
276 grid_layout->AddPaddingRow(0, 8);
277 columns = grid_layout->AddColumnSet(1);
278 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
279 views::GridLayout::USE_PREF, 0, 0);
280 grid_layout->StartRow(0, 1);
281 }
225 282
226 // Add "Reset to Default" button. 283 // Add "Reset to Default" button.
227 grid_layout->AddView( 284 reset_button_ = views::MdTextButton::CreateSecondaryUiButton(
228 views::MdTextButton::CreateSecondaryUiButton( 285 this, l10n_util::GetStringUTF16(material ? IDS_ZOOM_SET_DEFAULT_SHORT
229 this, l10n_util::GetStringUTF16(IDS_ZOOM_SET_DEFAULT))); 286 : IDS_ZOOM_SET_DEFAULT));
287 if (material) {
288 reset_button_->SetTooltipText(
289 l10n_util::GetStringUTF16(IDS_ZOOM_SET_DEFAULT));
Evan Stade 2017/04/27 17:29:39 so it's normally "Reset" with a tooltip of "Reset
varkha 2017/04/28 02:06:13 Acknowledged. I've added a todo to change that whe
290 }
varkha 2017/04/27 11:42:39 nit: no newline.
varkha 2017/04/28 02:06:13 Done.
291
292 grid_layout->AddView(reset_button_);
230 293
231 StartTimerIfNecessary(); 294 StartTimerIfNecessary();
232 } 295 }
233 296
234 void ZoomBubbleView::WindowClosing() { 297 void ZoomBubbleView::WindowClosing() {
235 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't 298 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't
236 // call this right away). Only set to nullptr when it's this bubble. 299 // call this right away). Only set to nullptr when it's this bubble.
237 if (zoom_bubble_ == this) 300 if (zoom_bubble_ == this)
238 zoom_bubble_ = nullptr; 301 zoom_bubble_ = nullptr;
239 } 302 }
240 303
241 void ZoomBubbleView::CloseBubble() { 304 void ZoomBubbleView::CloseBubble() {
305 if (ignore_close_bubble_)
306 return;
307
242 // Widget's Close() is async, but we don't want to use zoom_bubble_ after 308 // Widget's Close() is async, but we don't want to use zoom_bubble_ after
243 // this. Additionally web_contents_ may have been destroyed. 309 // this. Additionally web_contents_ may have been destroyed.
244 zoom_bubble_ = nullptr; 310 zoom_bubble_ = nullptr;
245 web_contents_ = nullptr; 311 web_contents_ = nullptr;
246 LocationBarBubbleDelegateView::CloseBubble(); 312 LocationBarBubbleDelegateView::CloseBubble();
247 } 313 }
248 314
249 void ZoomBubbleView::ButtonPressed(views::Button* sender, 315 void ZoomBubbleView::ButtonPressed(views::Button* sender,
250 const ui::Event& event) { 316 const ui::Event& event) {
317 base::AutoReset<bool> auto_ignore_close_bubble(&ignore_close_bubble_, true);
318 auto_close_ = false;
319 StopTimer();
251 if (sender == image_button_) { 320 if (sender == image_button_) {
252 DCHECK(extension_info_.icon_image) << "Invalid button press."; 321 DCHECK(extension_info_.icon_image) << "Invalid button press.";
253 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_); 322 Browser* browser = chrome::FindBrowserWithWebContents(web_contents_);
254 chrome::AddSelectedTabWithURL( 323 chrome::AddSelectedTabWithURL(
255 browser, GURL(base::StringPrintf("chrome://extensions?id=%s", 324 browser, GURL(base::StringPrintf("chrome://extensions?id=%s",
256 extension_info_.id.c_str())), 325 extension_info_.id.c_str())),
257 ui::PAGE_TRANSITION_FROM_API); 326 ui::PAGE_TRANSITION_FROM_API);
327 } else if (sender == zoom_out_button_) {
328 zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_OUT);
329 } else if (sender == zoom_in_button_) {
330 zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_IN);
331 } else if (sender == reset_button_) {
332 zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_RESET);
258 } else { 333 } else {
259 zoom::PageZoom::Zoom(web_contents_, content::PAGE_ZOOM_RESET); 334 NOTREACHED();
260 } 335 }
261 } 336 }
262 337
263 void ZoomBubbleView::OnImmersiveRevealStarted() { 338 void ZoomBubbleView::OnImmersiveRevealStarted() {
264 CloseBubble(); 339 CloseBubble();
265 } 340 }
266 341
267 void ZoomBubbleView::OnImmersiveModeControllerDestroyed() { 342 void ZoomBubbleView::OnImmersiveModeControllerDestroyed() {
268 immersive_mode_controller_ = nullptr; 343 immersive_mode_controller_ = nullptr;
269 } 344 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 } 410 }
336 } 411 }
337 412
338 void ZoomBubbleView::StopTimer() { 413 void ZoomBubbleView::StopTimer() {
339 timer_.Stop(); 414 timer_.Stop();
340 } 415 }
341 416
342 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} 417 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {}
343 418
344 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} 419 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698