Commit 84567cea authored by wjmaclean's avatar wjmaclean Committed by Commit bot

[OSX] Allow one zoom bubble to override another.

At present, if a user changes zoom on OSX while the zoom bubble is
already being shown, the new zoom bubble (with the most up to date
information) is not shown. This CL changes this behaviour by allowing
a new zoom bubble to be created, and replace the existing one.

Example: load a PDF and repeatedly click the zoom +/- controls in the
lower-right corner of the viewer.

BUG=444995

Review URL: https://codereview.chromium.org/886883002

Cr-Commit-Position: refs/heads/master@{#314147}
parent fd6e39a0
......@@ -48,6 +48,8 @@ class ZoomBubbleControllerDelegate {
ui::ScopedCrTrackingArea trackingArea_;
}
@property(nonatomic) ZoomBubbleControllerDelegate* delegate;
// Creates the bubble for a parent window but does not show it.
- (id)initWithParentWindow:(NSWindow*)parentWindow
delegate:(ZoomBubbleControllerDelegate*)delegate;
......
......@@ -75,6 +75,8 @@ void SetZoomBubbleAutoCloseDelayForTesting(NSTimeInterval time_interval) {
@implementation ZoomBubbleController
@synthesize delegate = delegate_;
- (id)initWithParentWindow:(NSWindow*)parentWindow
delegate:(ZoomBubbleControllerDelegate*)delegate {
base::scoped_nsobject<InfoBubbleWindow> window(
......@@ -126,6 +128,10 @@ void SetZoomBubbleAutoCloseDelayForTesting(NSTimeInterval time_interval) {
}
- (void)onZoomChanged {
// |delegate_| may be set null by this object's owner.
if (!delegate_)
return;
// TODO(shess): It may be appropriate to close the window if
// |contents| or |zoomController| are NULL. But they can be NULL in
// tests.
......@@ -169,8 +175,11 @@ void SetZoomBubbleAutoCloseDelayForTesting(NSTimeInterval time_interval) {
}
- (void)windowWillClose:(NSNotification*)notification {
delegate_->OnClose();
delegate_ = NULL;
// |delegate_| may be set null by this object's owner.
if (delegate_) {
delegate_->OnClose();
delegate_ = NULL;
}
[NSObject cancelPreviousPerformRequestsWithTarget:self
selector:@selector(autoCloseBubble)
object:nil];
......
......@@ -33,6 +33,7 @@ class ZoomDecoration : public ImageDecoration,
// Shows the zoom bubble for this decoration. If |auto_close| is YES, then
// the bubble will automatically close after a fixed period of time.
// If a bubble is already showing, the |auto_close| timer is reset.
void ShowBubble(BOOL auto_close);
// Closes the zoom bubble.
......
......@@ -23,6 +23,7 @@ ZoomDecoration::ZoomDecoration(LocationBarViewMac* owner)
ZoomDecoration::~ZoomDecoration() {
[bubble_ closeWithoutAnimation];
bubble_.delegate = nil;
}
bool ZoomDecoration::UpdateIfNecessary(
......@@ -48,8 +49,11 @@ bool ZoomDecoration::UpdateIfNecessary(
}
void ZoomDecoration::ShowBubble(BOOL auto_close) {
if (bubble_)
return;
if (bubble_) {
bubble_.delegate = nil;
[bubble_.window orderOut:nil];
[bubble_ closeWithoutAnimation];
}
content::WebContents* web_contents = owner_->GetWebContents();
if (!web_contents)
......@@ -138,6 +142,7 @@ content::WebContents* ZoomDecoration::GetWebContents() {
}
void ZoomDecoration::OnClose() {
bubble_.delegate = nil;
bubble_ = nil;
// If the page is at default zoom then hiding the zoom decoration
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment