Fix flickering window by deparenting before shutting bubble.
This cl revises https://codereview.chromium.org/886883002 in order to
fix the window-flickering issue by de-parenting the bubble window
prior to closing it.
BUG=444995
Review URL: https://codereview.chromium.org/887003006
(cherry picked from commit c9c22ca31db0aad109e7da30f84bbdc5284fe684)
Cr-Original-Commit-Position: refs/heads/master@{#315524}
Cr-Commit-Position: refs/branch-heads/2272@{#292}
Cr-Branched-From: 827a380cfdb31aa54c8d56e63ce2c3fd8c3ba4d4-refs/heads/master@{#310958}
diff --git a/chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h b/chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h
index cfcd3452..7293b4b 100644
--- a/chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h
+++ b/chrome/browser/ui/cocoa/browser/zoom_bubble_controller.h
@@ -48,6 +48,8 @@
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;
diff --git a/chrome/browser/ui/cocoa/browser/zoom_bubble_controller.mm b/chrome/browser/ui/cocoa/browser/zoom_bubble_controller.mm
index 60fbf5c2..74480a42 100644
--- a/chrome/browser/ui/cocoa/browser/zoom_bubble_controller.mm
+++ b/chrome/browser/ui/cocoa/browser/zoom_bubble_controller.mm
@@ -75,6 +75,8 @@
@implementation ZoomBubbleController
+@synthesize delegate = delegate_;
+
- (id)initWithParentWindow:(NSWindow*)parentWindow
delegate:(ZoomBubbleControllerDelegate*)delegate {
base::scoped_nsobject<InfoBubbleWindow> window(
@@ -126,6 +128,10 @@
}
- (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)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];
diff --git a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.h b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.h
index 90ef008..db09902 100644
--- a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.h
+++ b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.h
@@ -33,6 +33,7 @@
// 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.
diff --git a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm
index 7306dd1..c015e70 100644
--- a/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm
+++ b/chrome/browser/ui/cocoa/location_bar/zoom_decoration.mm
@@ -23,6 +23,7 @@
ZoomDecoration::~ZoomDecoration() {
[bubble_ closeWithoutAnimation];
+ bubble_.delegate = nil;
}
bool ZoomDecoration::UpdateIfNecessary(
@@ -48,8 +49,12 @@
}
void ZoomDecoration::ShowBubble(BOOL auto_close) {
- if (bubble_)
- return;
+ if (bubble_) {
+ bubble_.delegate = nil;
+ [[bubble_.window parentWindow] removeChildWindow:bubble_.window];
+ [bubble_.window orderOut:nil];
+ [bubble_ closeWithoutAnimation];
+ }
content::WebContents* web_contents = owner_->GetWebContents();
if (!web_contents)
@@ -138,6 +143,7 @@
}
void ZoomDecoration::OnClose() {
+ bubble_.delegate = nil;
bubble_ = nil;
// If the page is at default zoom then hiding the zoom decoration