From 34c1558fedad7b65b8595d9e452e3190efa3ed12 Mon Sep 17 00:00:00 2001 From: Hidehiko Abe Date: Thu, 12 Apr 2018 17:02:44 +0900 Subject: Migrate libmojo repository into libchrome, part 1. This CL moves following files. - base/* except base/android/* - devices/* - ui/* except ui/gfx/**/mojom/* - ui/gfx/range/range_mac(_unittest)?.mm are just deleted. Bug: 73606903, 73270448 Test: Built locally. libchrome_test locally. Run update_libchrome.py and made sure no diff is made. Change-Id: I7f47337aa190f901c9c1d41758f312a2b95adc1b --- ui/gfx/geometry/size.cc | 115 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 ui/gfx/geometry/size.cc (limited to 'ui/gfx/geometry/size.cc') diff --git a/ui/gfx/geometry/size.cc b/ui/gfx/geometry/size.cc new file mode 100644 index 0000000000..69486723a1 --- /dev/null +++ b/ui/gfx/geometry/size.cc @@ -0,0 +1,115 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ui/gfx/geometry/size.h" + +#if defined(OS_WIN) +#include +#elif defined(OS_IOS) +#include +#elif defined(OS_MACOSX) +#include +#endif + +#include "base/numerics/safe_math.h" +#include "base/numerics/saturated_arithmetic.h" +#include "base/strings/stringprintf.h" +#include "build/build_config.h" +#include "ui/gfx/geometry/safe_integer_conversions.h" +#include "ui/gfx/geometry/size_conversions.h" + +namespace gfx { + +#if defined(OS_MACOSX) +Size::Size(const CGSize& s) + : width_(s.width < 0 ? 0 : s.width), + height_(s.height < 0 ? 0 : s.height) { +} + +Size& Size::operator=(const CGSize& s) { + set_width(s.width); + set_height(s.height); + return *this; +} +#endif + +#if defined(OS_WIN) +SIZE Size::ToSIZE() const { + SIZE s; + s.cx = width(); + s.cy = height(); + return s; +} +#elif defined(OS_MACOSX) +CGSize Size::ToCGSize() const { + return CGSizeMake(width(), height()); +} +#endif + +int Size::GetArea() const { + return GetCheckedArea().ValueOrDie(); +} + +base::CheckedNumeric Size::GetCheckedArea() const { + base::CheckedNumeric checked_area = width(); + checked_area *= height(); + return checked_area; +} + +void Size::Enlarge(int grow_width, int grow_height) { + SetSize(base::SaturatedAddition(width(), grow_width), + base::SaturatedAddition(height(), grow_height)); +} + +void Size::SetToMin(const Size& other) { + width_ = width() <= other.width() ? width() : other.width(); + height_ = height() <= other.height() ? height() : other.height(); +} + +void Size::SetToMax(const Size& other) { + width_ = width() >= other.width() ? width() : other.width(); + height_ = height() >= other.height() ? height() : other.height(); +} + +std::string Size::ToString() const { + return base::StringPrintf("%dx%d", width(), height()); +} + +Size ScaleToCeiledSize(const Size& size, float x_scale, float y_scale) { + if (x_scale == 1.f && y_scale == 1.f) + return size; + return ToCeiledSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale)); +} + +Size ScaleToCeiledSize(const Size& size, float scale) { + if (scale == 1.f) + return size; + return ToCeiledSize(ScaleSize(gfx::SizeF(size), scale, scale)); +} + +Size ScaleToFlooredSize(const Size& size, float x_scale, float y_scale) { + if (x_scale == 1.f && y_scale == 1.f) + return size; + return ToFlooredSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale)); +} + +Size ScaleToFlooredSize(const Size& size, float scale) { + if (scale == 1.f) + return size; + return ToFlooredSize(ScaleSize(gfx::SizeF(size), scale, scale)); +} + +Size ScaleToRoundedSize(const Size& size, float x_scale, float y_scale) { + if (x_scale == 1.f && y_scale == 1.f) + return size; + return ToRoundedSize(ScaleSize(gfx::SizeF(size), x_scale, y_scale)); +} + +Size ScaleToRoundedSize(const Size& size, float scale) { + if (scale == 1.f) + return size; + return ToRoundedSize(ScaleSize(gfx::SizeF(size), scale, scale)); +} + +} // namespace gfx -- cgit v1.2.3