size_f.cc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2012 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/geometry/size_f.h"
  5. #include "base/strings/stringprintf.h"
  6. #include "build/build_config.h"
  7. #if BUILDFLAG(IS_IOS)
  8. #include <CoreGraphics/CoreGraphics.h>
  9. #elif BUILDFLAG(IS_MAC)
  10. #include <ApplicationServices/ApplicationServices.h>
  11. #endif
  12. namespace gfx {
  13. #if BUILDFLAG(IS_APPLE)
  14. SizeF::SizeF(const CGSize& size) : SizeF(size.width, size.height) {}
  15. CGSize SizeF::ToCGSize() const {
  16. return CGSizeMake(width(), height());
  17. }
  18. #endif
  19. float SizeF::GetArea() const {
  20. return width() * height();
  21. }
  22. void SizeF::Enlarge(float grow_width, float grow_height) {
  23. SetSize(width() + grow_width, height() + grow_height);
  24. }
  25. void SizeF::SetToMin(const SizeF& other) {
  26. width_ = std::min(width_, other.width_);
  27. height_ = std::min(height_, other.height_);
  28. }
  29. void SizeF::SetToMax(const SizeF& other) {
  30. width_ = std::max(width_, other.width_);
  31. height_ = std::max(height_, other.height_);
  32. }
  33. std::string SizeF::ToString() const {
  34. return base::StringPrintf("%gx%g", width(), height());
  35. }
  36. SizeF ScaleSize(const SizeF& s, float x_scale, float y_scale) {
  37. SizeF scaled_s(s);
  38. scaled_s.Scale(x_scale, y_scale);
  39. return scaled_s;
  40. }
  41. } // namespace gfx