Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef UI_GFX_SCOPED_CANVAS_H_ | 5 #ifndef UI_GFX_SCOPED_CANVAS_H_ |
| 6 #define UI_GFX_SCOPED_CANVAS_H_ | 6 #define UI_GFX_SCOPED_CANVAS_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/gfx/gfx_export.h" | 10 #include "ui/gfx/gfx_export.h" |
| 11 | 11 |
| 12 namespace gfx { | 12 namespace gfx { |
| 13 | 13 |
| 14 // Saves the drawing state, and restores the state when going out of scope. | 14 // Saves the drawing state, and restores the state when going out of scope. |
| 15 class GFX_EXPORT ScopedCanvas { | 15 class GFX_EXPORT ScopedCanvas { |
| 16 public: | 16 public: |
| 17 explicit ScopedCanvas(gfx::Canvas* canvas) : canvas_(canvas) { | 17 explicit ScopedCanvas(gfx::Canvas* canvas) : canvas_(canvas) { |
| 18 if (canvas_) | 18 if (canvas_) |
| 19 canvas_->Save(); | 19 canvas_->Save(); |
| 20 } | 20 } |
| 21 ~ScopedCanvas() { | 21 ~ScopedCanvas() { |
| 22 if (canvas_) | 22 if (canvas_) |
| 23 canvas_->Restore(); | 23 canvas_->Restore(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 ScopedCanvas(ScopedCanvas&& o) { | |
|
Peter Kasting
2017/04/06 00:52:11
Nit: Per Google style guide constructors and assig
danakj
2017/04/06 17:05:28
I didn't realize this, thanks. https://google.gith
| |
| 27 canvas_ = o.canvas_; | |
| 28 o.canvas_ = nullptr; | |
| 29 } | |
| 30 ScopedCanvas& operator=(ScopedCanvas&& o) { | |
| 31 if (canvas_) | |
| 32 canvas_->Restore(); | |
| 33 canvas_ = o.canvas_; | |
| 34 o.canvas_ = nullptr; | |
| 35 return *this; | |
| 36 } | |
| 37 | |
| 26 private: | 38 private: |
| 27 gfx::Canvas* canvas_; | 39 gfx::Canvas* canvas_; |
| 28 | 40 |
| 29 DISALLOW_COPY_AND_ASSIGN(ScopedCanvas); | 41 DISALLOW_COPY_AND_ASSIGN(ScopedCanvas); |
| 30 }; | 42 }; |
| 31 | 43 |
| 32 // Saves the drawing state. If |flip| is true, and the UI is in RTL layout, | 44 // Saves the drawing state. If |flip| is true, and the UI is in RTL layout, |
| 33 // applies a transform such that anything drawn inside the supplied width will | 45 // applies a transform such that anything drawn inside the supplied width will |
| 34 // be flipped horizontally. | 46 // be flipped horizontally. |
| 35 class GFX_EXPORT ScopedRTLFlipCanvas { | 47 class GFX_EXPORT ScopedRTLFlipCanvas { |
| 36 public: | 48 public: |
| 37 ScopedRTLFlipCanvas(gfx::Canvas* canvas, int width, bool flip = true); | 49 ScopedRTLFlipCanvas(gfx::Canvas* canvas, int width, bool flip = true); |
| 38 ~ScopedRTLFlipCanvas() {} | 50 ~ScopedRTLFlipCanvas() {} |
| 39 | 51 |
| 40 private: | 52 private: |
| 41 ScopedCanvas canvas_; | 53 ScopedCanvas canvas_; |
| 42 | 54 |
| 43 DISALLOW_COPY_AND_ASSIGN(ScopedRTLFlipCanvas); | 55 DISALLOW_COPY_AND_ASSIGN(ScopedRTLFlipCanvas); |
| 44 }; | 56 }; |
| 45 | 57 |
| 46 } // namespace gfx | 58 } // namespace gfx |
| 47 | 59 |
| 48 #endif // UI_GFX_SCOPED_CANVAS_H_ | 60 #endif // UI_GFX_SCOPED_CANVAS_H_ |
| OLD | NEW |