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 | |
|
tapted
2016/04/27 03:25:11
nit: no blank line here
Elly Fong-Jones
2016/04/28 17:03:11
Done.
| |
| 9 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/gfx_export.h" | |
| 10 | 12 |
| 11 namespace gfx { | 13 namespace gfx { |
| 12 | 14 |
| 15 class Rect; | |
| 16 | |
| 13 // Saves the drawing state, and restores the state when going out of scope. | 17 // Saves the drawing state, and restores the state when going out of scope. |
| 14 class ScopedCanvas { | 18 class GFX_EXPORT ScopedCanvas { |
| 15 public: | 19 public: |
| 16 explicit ScopedCanvas(gfx::Canvas* canvas) : canvas_(canvas) { | 20 explicit ScopedCanvas(gfx::Canvas* canvas) : canvas_(canvas) { |
| 17 if (canvas_) | 21 if (canvas_) |
| 18 canvas_->Save(); | 22 canvas_->Save(); |
| 19 } | 23 } |
| 20 ~ScopedCanvas() { | 24 ~ScopedCanvas() { |
| 21 if (canvas_) | 25 if (canvas_) |
| 22 canvas_->Restore(); | 26 canvas_->Restore(); |
| 23 } | 27 } |
| 24 | 28 |
| 25 private: | 29 private: |
| 26 gfx::Canvas* canvas_; | 30 gfx::Canvas* canvas_; |
| 27 | 31 |
| 28 DISALLOW_COPY_AND_ASSIGN(ScopedCanvas); | 32 DISALLOW_COPY_AND_ASSIGN(ScopedCanvas); |
| 29 }; | 33 }; |
| 30 | 34 |
| 35 // Saves the drawing state, and applies an RTL transform for the supplied rect | |
| 36 // if the UI is in RTL layout. The resulting transform is such that anything | |
| 37 // drawn inside the supplied rect will be flipped horizontally. | |
| 38 class GFX_EXPORT ScopedRTLFlipCanvas { | |
| 39 public: | |
| 40 ScopedRTLFlipCanvas(gfx::Canvas* canvas, const gfx::Rect& rect); | |
| 41 ~ScopedRTLFlipCanvas() {} | |
| 42 | |
| 43 private: | |
| 44 ScopedCanvas canvas_; | |
| 45 | |
| 46 DISALLOW_COPY_AND_ASSIGN(ScopedRTLFlipCanvas); | |
| 47 }; | |
| 48 | |
| 31 } // namespace gfx | 49 } // namespace gfx |
| 32 | 50 |
| 33 #endif // UI_GFX_SCOPED_CANVAS_H_ | 51 #endif // UI_GFX_SCOPED_CANVAS_H_ |
| OLD | NEW |