| 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 class Rect; | |
| 15 | |
| 16 // 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. |
| 17 class GFX_EXPORT ScopedCanvas { | 15 class GFX_EXPORT ScopedCanvas { |
| 18 public: | 16 public: |
| 19 explicit ScopedCanvas(gfx::Canvas* canvas) : canvas_(canvas) { | 17 explicit ScopedCanvas(gfx::Canvas* canvas) : canvas_(canvas) { |
| 20 if (canvas_) | 18 if (canvas_) |
| 21 canvas_->Save(); | 19 canvas_->Save(); |
| 22 } | 20 } |
| 23 ~ScopedCanvas() { | 21 ~ScopedCanvas() { |
| 24 if (canvas_) | 22 if (canvas_) |
| 25 canvas_->Restore(); | 23 canvas_->Restore(); |
| 26 } | 24 } |
| 27 | 25 |
| 28 private: | 26 private: |
| 29 gfx::Canvas* canvas_; | 27 gfx::Canvas* canvas_; |
| 30 | 28 |
| 31 DISALLOW_COPY_AND_ASSIGN(ScopedCanvas); | 29 DISALLOW_COPY_AND_ASSIGN(ScopedCanvas); |
| 32 }; | 30 }; |
| 33 | 31 |
| 34 // Saves the drawing state, and applies an RTL transform for the supplied rect | 32 // Saves the drawing state. If |flip| is true, and the UI is in RTL layout, |
| 35 // if the UI is in RTL layout. The resulting transform is such that anything | 33 // applies a transform such that anything drawn inside the supplied width will |
| 36 // drawn inside the supplied rect will be flipped horizontally. | 34 // be flipped horizontally. |
| 37 class GFX_EXPORT ScopedRTLFlipCanvas { | 35 class GFX_EXPORT ScopedRTLFlipCanvas { |
| 38 public: | 36 public: |
| 39 ScopedRTLFlipCanvas(gfx::Canvas* canvas, const gfx::Rect& rect); | 37 ScopedRTLFlipCanvas(gfx::Canvas* canvas, int width, bool flip = true); |
| 40 ~ScopedRTLFlipCanvas() {} | 38 ~ScopedRTLFlipCanvas() {} |
| 41 | 39 |
| 42 private: | 40 private: |
| 43 ScopedCanvas canvas_; | 41 ScopedCanvas canvas_; |
| 44 | 42 |
| 45 DISALLOW_COPY_AND_ASSIGN(ScopedRTLFlipCanvas); | 43 DISALLOW_COPY_AND_ASSIGN(ScopedRTLFlipCanvas); |
| 46 }; | 44 }; |
| 47 | 45 |
| 48 } // namespace gfx | 46 } // namespace gfx |
| 49 | 47 |
| 50 #endif // UI_GFX_SCOPED_CANVAS_H_ | 48 #endif // UI_GFX_SCOPED_CANVAS_H_ |
| OLD | NEW |