scoped_canvas.cc 635 B

1234567891011121314151617181920212223242526272829
  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. #include "ui/gfx/scoped_canvas.h"
  5. #include "base/i18n/rtl.h"
  6. #include "ui/gfx/geometry/rect.h"
  7. namespace gfx {
  8. ScopedCanvas::ScopedCanvas(gfx::Canvas* canvas) : canvas_(canvas) {
  9. if (canvas_)
  10. canvas_->Save();
  11. }
  12. ScopedCanvas::~ScopedCanvas() {
  13. if (canvas_)
  14. canvas_->Restore();
  15. }
  16. void ScopedCanvas::FlipIfRTL(int width) {
  17. if (base::i18n::IsRTL()) {
  18. canvas_->Translate(gfx::Vector2d(width, 0));
  19. canvas_->Scale(-1, 1);
  20. }
  21. }
  22. } // namespace gfx