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

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

Issue 712993004: Don't re-use a zoom bubble unless it has the same web-contents. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore WindowClosing(), improve comments. Created 6 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
« no previous file with comments | « no previous file | chrome/browser/ui/views/location_bar/zoom_bubble_view_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/chrome_page_zoom.h" 10 #include "chrome/browser/chrome_page_zoom.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 ZoomController* zoom_controller = 62 ZoomController* zoom_controller =
63 ZoomController::FromWebContents(web_contents); 63 ZoomController::FromWebContents(web_contents);
64 const extensions::Extension* extension = zoom_controller->last_extension(); 64 const extensions::Extension* extension = zoom_controller->last_extension();
65 65
66 // If the bubble is already showing in this window and the zoom change was not 66 // If the bubble is already showing in this window and the zoom change was not
67 // initiated by an extension, then the bubble can be reused and only the label 67 // initiated by an extension, then the bubble can be reused and only the label
68 // text needs to be updated. 68 // text needs to be updated.
69 if (zoom_bubble_ && 69 if (zoom_bubble_ &&
70 zoom_bubble_->GetAnchorView() == anchor_view && 70 zoom_bubble_->GetAnchorView() == anchor_view &&
71 !extension) { 71 !extension) {
72 DCHECK_EQ(web_contents, zoom_bubble_->web_contents_);
72 zoom_bubble_->Refresh(); 73 zoom_bubble_->Refresh();
73 return; 74 return;
74 } 75 }
75 76
76 // If the bubble is already showing but in a different tab, the current 77 // If the bubble is already showing but in a different tab, the current
77 // bubble must be closed and a new one created. 78 // bubble must be closed and a new one created.
78 CloseBubble(); 79 CloseBubble();
79 80
80 zoom_bubble_ = new ZoomBubbleView(anchor_view, 81 zoom_bubble_ = new ZoomBubbleView(anchor_view,
81 web_contents, 82 web_contents,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 void ZoomBubbleView::Refresh() { 168 void ZoomBubbleView::Refresh() {
168 ZoomController* zoom_controller = 169 ZoomController* zoom_controller =
169 ZoomController::FromWebContents(web_contents_); 170 ZoomController::FromWebContents(web_contents_);
170 int zoom_percent = zoom_controller->GetZoomPercent(); 171 int zoom_percent = zoom_controller->GetZoomPercent();
171 label_->SetText( 172 label_->SetText(
172 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent)); 173 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent));
173 StartTimerIfNecessary(); 174 StartTimerIfNecessary();
174 } 175 }
175 176
176 void ZoomBubbleView::Close() { 177 void ZoomBubbleView::Close() {
178 // Widget's Close() is async, but we don't want to use zoom_bubble_ after
179 // this. Additionally web_contents_ may have been destroyed.
180 zoom_bubble_ = NULL;
181 web_contents_ = NULL;
177 GetWidget()->Close(); 182 GetWidget()->Close();
178 } 183 }
179 184
180 void ZoomBubbleView::SetExtensionInfo(const extensions::Extension* extension) { 185 void ZoomBubbleView::SetExtensionInfo(const extensions::Extension* extension) {
181 DCHECK(extension); 186 DCHECK(extension);
182 extension_info_.id = extension->id(); 187 extension_info_.id = extension->id();
183 extension_info_.name = extension->name(); 188 extension_info_.name = extension->name();
184 189
185 ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 190 ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
186 const gfx::ImageSkia& default_extension_icon_image = 191 const gfx::ImageSkia& default_extension_icon_image =
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 void ZoomBubbleView::WindowClosing() { 358 void ZoomBubbleView::WindowClosing() {
354 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't 359 // |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't
355 // call this right away). Only set to NULL when it's this bubble. 360 // call this right away). Only set to NULL when it's this bubble.
356 if (zoom_bubble_ == this) 361 if (zoom_bubble_ == this)
357 zoom_bubble_ = NULL; 362 zoom_bubble_ = NULL;
358 } 363 }
359 364
360 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {} 365 ZoomBubbleView::ZoomBubbleExtensionInfo::ZoomBubbleExtensionInfo() {}
361 366
362 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {} 367 ZoomBubbleView::ZoomBubbleExtensionInfo::~ZoomBubbleExtensionInfo() {}
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/location_bar/zoom_bubble_view_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698