ellyjones | 9412ffff | 2016-05-17 22:41:11 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "ui/gfx/scoped_canvas.h" |
| 6 | |
| 7 | #include "base/i18n/rtl.h" |
| 8 | #include "ui/gfx/geometry/rect.h" |
| 9 | |
| 10 | namespace gfx { |
| 11 | |
Peter Kasting | 838fdda | 2019-06-25 21:41:14 | [diff] [blame] | 12 | ScopedCanvas::ScopedCanvas(gfx::Canvas* canvas) : canvas_(canvas) { |
| 13 | if (canvas_) |
| 14 | canvas_->Save(); |
| 15 | } |
| 16 | |
| 17 | ScopedCanvas::~ScopedCanvas() { |
| 18 | if (canvas_) |
| 19 | canvas_->Restore(); |
| 20 | } |
| 21 | |
| 22 | void ScopedCanvas::FlipIfRTL(int width) { |
| 23 | if (base::i18n::IsRTL()) { |
| 24 | canvas_->Translate(gfx::Vector2d(width, 0)); |
| 25 | canvas_->Scale(-1, 1); |
ellyjones | 9412ffff | 2016-05-17 22:41:11 | [diff] [blame] | 26 | } |
| 27 | } |
| 28 | |
| 29 | } // namespace gfx |