// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef IOS_CHROME_COMMON_UI_UTIL_UI_UTIL_H_
#define IOS_CHROME_COMMON_UI_UTIL_UI_UTIL_H_

#include <UIKit/UIKit.h>

// UI Util containing functions that do not require Objective-C.


// Returns the width of the screen in the current orientation.
CGFloat CurrentScreenWidth();

// Returns the closest pixel-aligned value less than `value`, taking the scale
// factor into account. At a scale of 1, equivalent to floor().
CGFloat AlignValueToLowerPixel(CGFloat value);

// Returns the closest pixel-aligned value higher than `value`, taking the scale
// factor into account. At a scale of 1, equivalent to ceil().
CGFloat AlignValueToUpperPixel(CGFloat value);

// Returns the point resulting from applying AlignValueToLowerPixel() to both
// components.
CGPoint AlignPointToLowerPixel(CGPoint point);

// Returns the point resulting from applying AlignValueToUpperPixel() to both
// components.
CGPoint AlignPointToUpperPixel(CGPoint point);

// Returns the rectangle resulting from applying AlignPointToLowerPixel() to the
// origin.
CGRect AlignRectToPixel(CGRect rect);

// Returns the size resulting from applying AlignValueToUpperPixel() to both
// components.
CGSize AlignSizeToUpperPixel(CGSize size);

// Returns the rectangle resulting from applying AlignPointToLowerPixel() to the
// origin, and AlignSizeToUpperPixel() to the size.
CGRect AlignRectOriginAndSizeToPixels(CGRect rect);

// Returns a square CGRect centered at `x`, `y` with a width of `width`.
// Both the position and the size of the CGRect will be aligned to points.
CGRect CGRectMakeAlignedAndCenteredAt(CGFloat x, CGFloat y, CGFloat width);

// Returns a rectangle of size `rectSize` centered inside `frameSize`.
CGRect CGRectMakeCenteredRectInFrame(CGSize frameSize, CGSize rectSize);

// Returns whether `a` and `b` are within CGFloat's epsilon value.
bool AreCGFloatsEqual(CGFloat a, CGFloat b);

// Whether the `environment` has a regular vertical and regular horizontal
// size class.
bool IsRegularXRegularSizeClass(id<UITraitEnvironment> environment);

// Whether the `traitCollection` has a regular vertical and regular horizontal
// size class.
bool IsRegularXRegularSizeClass(UITraitCollection* traitCollection);

// Returns a color which is a blend of `color_1` and `color_2`, depending on
// the value of `fraction`. `fraction` is a value between 0 and 1. If it is
// closer to 0, the output will be closer to `color_1`, and if it is closer to
// 1 the output will be closer to `color_2`.
UIColor* BlendColors(UIColor* color_1, UIColor* color_2, CGFloat fraction);

#endif  // IOS_CHROME_COMMON_UI_UTIL_UI_UTIL_H_
