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