summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-09 17:39:34 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-09 17:39:34 +0000
commit9a556e3307dacc7e6d84517d3b78b86c6dbd84f1 (patch)
tree2468136819412b6be807049fbf6a3d5a02e4ab1c
parent2216683346b44b088820c64c5757bb66365acda3 (diff)
downloadchromium_src-9a556e3307dacc7e6d84517d3b78b86c6dbd84f1.zip
chromium_src-9a556e3307dacc7e6d84517d3b78b86c6dbd84f1.tar.gz
chromium_src-9a556e3307dacc7e6d84517d3b78b86c6dbd84f1.tar.bz2
Add a stack-based class for property disabling and re-enabling screen updating without epic fail. Fixes issues where we weren't re-enabling updates in many cases which caused both jank and resize issues.
BUG=13476 TEST=closing windows shouldn't have jank regardless of the # of tabs. Resizing a window shouldn't explode visually in the chrome. Review URL: http://codereview.chromium.org/119363 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17956 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/base.gyp1
-rw-r--r--base/scoped_nsdisable_screen_updates.h35
-rw-r--r--chrome/browser/cocoa/browser_window_controller.mm7
3 files changed, 39 insertions, 4 deletions
diff --git a/base/base.gyp b/base/base.gyp
index b26c68e..5d09098 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -247,6 +247,7 @@
'scoped_handle_win.h',
'scoped_nsautorelease_pool.h',
'scoped_nsautorelease_pool.mm',
+ 'scoped_nsdisable_screen_updates.h',
'scoped_nsobject.h',
'scoped_ptr.h',
'scoped_temp_dir.cc',
diff --git a/base/scoped_nsdisable_screen_updates.h b/base/scoped_nsdisable_screen_updates.h
new file mode 100644
index 0000000..3258fca
--- /dev/null
+++ b/base/scoped_nsdisable_screen_updates.h
@@ -0,0 +1,35 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_SCOPED_NSDISABLE_SCREEN_UPDATES_H_
+#define BASE_SCOPED_NSDISABLE_SCREEN_UPDATES_H_
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/basictypes.h"
+
+namespace base {
+
+// A stack-based class to disable Cocoa screen updates. When instantiated, it
+// disables screen updates and enables them when destroyed. Update disabling
+// can be nested, and there is a time-maximum (about 1 second) after which
+// Cocoa will automatically re-enable updating. This class doesn't attempt to
+// overrule that.
+
+class ScopedNSDisableScreenUpdates {
+ public:
+ ScopedNSDisableScreenUpdates() {
+ NSDisableScreenUpdates();
+ }
+ ~ScopedNSDisableScreenUpdates() {
+ NSEnableScreenUpdates();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ScopedNSDisableScreenUpdates);
+};
+
+} // namespace
+
+#endif
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm
index 9fa2ee0..f8342d0 100644
--- a/chrome/browser/cocoa/browser_window_controller.mm
+++ b/chrome/browser/cocoa/browser_window_controller.mm
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "base/mac_util.h"
+#include "base/scoped_nsdisable_screen_updates.h"
#include "base/sys_string_conversions.h"
#include "chrome/app/chrome_dll_resource.h" // IDC_*
#include "chrome/browser/browser.h"
@@ -193,7 +194,7 @@ willPositionSheet:(NSWindow *)sheet
// going away) will again call to close the window when it's finally ready.
- (BOOL)windowShouldClose:(id)sender {
// Disable updates while closing all tabs to avoid flickering.
- NSDisableScreenUpdates();
+ base::ScopedNSDisableScreenUpdates disabler;
// Give beforeunload handlers the chance to cancel the close before we hide
// the window below.
if (!browser_->ShouldCloseWindow())
@@ -212,7 +213,6 @@ willPositionSheet:(NSWindow *)sheet
browser_->OnWindowClosing();
return NO;
}
- NSEnableScreenUpdates();
// the tab strip is empty, it's ok to close the window
return YES;
@@ -462,7 +462,7 @@ willPositionSheet:(NSWindow *)sheet
- (TabWindowController*)detachTabToNewWindow:(TabView*)tabView {
// Disable screen updates so that this appears as a single visual change.
- NSDisableScreenUpdates();
+ base::ScopedNSDisableScreenUpdates disabler;
// Fetch the tab contents for the tab being dragged
int index = [tabStripController_ indexForTabView:tabView];
@@ -507,7 +507,6 @@ willPositionSheet:(NSWindow *)sheet
// And make sure we use the correct frame in the new view.
[[controller tabStripController] setFrameOfSelectedTab:tabRect];
- NSEnableScreenUpdates();
return controller;
}