diff options
author | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-05 17:19:11 +0000 |
---|---|---|
committer | yzshen@chromium.org <yzshen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-05 17:19:11 +0000 |
commit | 56c39f543883334c854502dd92f769de7c85d5bc (patch) | |
tree | 2fb8939b6ed76db292d21b62c9f5422806201040 /ui/gfx | |
parent | 54ccbd1473f09f07a8fd49a58aec05ab10eed465 (diff) | |
download | chromium_src-56c39f543883334c854502dd92f769de7c85d5bc.zip chromium_src-56c39f543883334c854502dd92f769de7c85d5bc.tar.gz chromium_src-56c39f543883334c854502dd92f769de7c85d5bc.tar.bz2 |
Revert 95611 - Always call the class methods to save/restore contexts.
If the current context was ever nil, sending a "restore" message would be a no-op and would likely leave an out-of-scope context as current.
BUG=90140
TEST=repeatedly select items in an open file dialog in column mode; no crash
Review URL: http://codereview.chromium.org/7572031
TBR=avi@chromium.org
Review URL: http://codereview.chromium.org/7541043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@95631 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r-- | ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h | 14 | ||||
-rw-r--r-- | ui/gfx/scoped_ns_graphics_context_save_gstate_mac.mm | 15 |
2 files changed, 12 insertions, 17 deletions
diff --git a/ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h b/ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h index 4826bcc..05bf5f6 100644 --- a/ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h +++ b/ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h @@ -4,27 +4,23 @@ #ifndef UI_GFX_SCOPED_NS_GRAPHICS_CONTEXT_SAVE_GSTATE_MAC_H_ #define UI_GFX_SCOPED_NS_GRAPHICS_CONTEXT_SAVE_GSTATE_MAC_H_ -#pragma once -#include "base/basictypes.h" #include "ui/ui_api.h" +#include "base/basictypes.h" +#include "base/memory/scoped_nsobject.h" -#if defined(__OBJC__) @class NSGraphicsContext; -#else -class NSGraphicsContext; -#endif namespace gfx { -// A class to save/restore the state of the current context. class UI_API ScopedNSGraphicsContextSaveGState { public: - ScopedNSGraphicsContextSaveGState(); + // If |context| is nil, it will use the |+currentContext|. + explicit ScopedNSGraphicsContextSaveGState(NSGraphicsContext* context = nil); ~ScopedNSGraphicsContextSaveGState(); private: - NSGraphicsContext* context_; // weak + scoped_nsobject<NSGraphicsContext> context_; DISALLOW_COPY_AND_ASSIGN(ScopedNSGraphicsContextSaveGState); }; diff --git a/ui/gfx/scoped_ns_graphics_context_save_gstate_mac.mm b/ui/gfx/scoped_ns_graphics_context_save_gstate_mac.mm index 6b19d8c..f3992ea 100644 --- a/ui/gfx/scoped_ns_graphics_context_save_gstate_mac.mm +++ b/ui/gfx/scoped_ns_graphics_context_save_gstate_mac.mm @@ -4,20 +4,19 @@ #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" -#import <AppKit/AppKit.h> - -#include "base/logging.h" +#include <AppKit/AppKit.h> namespace gfx { -ScopedNSGraphicsContextSaveGState::ScopedNSGraphicsContextSaveGState() - : context_([NSGraphicsContext currentContext]) { - [NSGraphicsContext saveGraphicsState]; +ScopedNSGraphicsContextSaveGState::ScopedNSGraphicsContextSaveGState( + NSGraphicsContext* context) : context_([context retain]) { + if (!context_) + context_.reset([[NSGraphicsContext currentContext] retain]); + [context_ saveGraphicsState]; } ScopedNSGraphicsContextSaveGState::~ScopedNSGraphicsContextSaveGState() { - [NSGraphicsContext restoreGraphicsState]; - DCHECK_EQ(context_, [NSGraphicsContext currentContext]); + [context_ restoreGraphicsState]; } } // namespace gfx |