cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ios / chrome / browser / ui / ui_util.h
blob1bef1f04e1b41d1bf6a5af1f91642d6d3624b556
1 // Copyright 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.
5 #ifndef IOS_CHROME_BROWSER_UI_UI_UTIL_H_
6 #define IOS_CHROME_BROWSER_UI_UI_UTIL_H_
8 #include <CoreGraphics/CoreGraphics.h>
10 // UI Util containing functions that do not require Objective-C.
12 // Running on an iPad?
13 bool IsIPadIdiom();
15 // Enum for arrays by UI idiom.
16 enum InterfaceIdiom { IPHONE_IDIOM, IPAD_IDIOM, INTERFACE_IDIOM_COUNT };
18 // Array of widths for device idioms in portrait orientation.
19 extern const CGFloat kPortraitWidth[INTERFACE_IDIOM_COUNT];
21 // Is the screen of the device a high resolution screen, i.e. Retina Display.
22 bool IsHighResScreen();
24 // Returns true if the device is in portrait orientation or if interface
25 // orientation is unknown.
26 bool IsPortrait();
28 // Returns true if the device is in landscape orientation.
29 bool IsLandscape();
31 // Returns the height of the screen in the current orientation.
32 CGFloat CurrentScreenHeight();
34 // Returns the width of the screen in the current orientation.
35 CGFloat CurrentScreenWidth();
37 // Returns the height of the status bar, accounting for orientation.
38 CGFloat StatusBarHeight();
40 // Returns the closest pixel-aligned value less than |value|, taking the scale
41 // factor into account. At a scale of 1, equivalent to floor().
42 CGFloat AlignValueToPixel(CGFloat value);
44 // Returns the point resulting from applying AlignValueToPixel() to both
45 // components.
46 CGPoint AlignPointToPixel(CGPoint point);
48 // Returns the rectangle resulting from applying AlignPointToPixel() to the
49 // origin.
50 CGRect AlignRectToPixel(CGRect rect);
52 // Returns the rectangle resulting from applying AlignPointToPixel() to the
53 // origin, and ui::AlignSizeToUpperPixel() to the size.
54 CGRect AlignRectOriginAndSizeToPixels(CGRect rect);
56 // Makes a copy of |rect| with a new origin specified by |x| and |y|.
57 CGRect CGRectCopyWithOrigin(CGRect rect, CGFloat x, CGFloat y);
59 // Returns a square CGRect centered at |x|, |y| with a width of |width|.
60 // Both the position and the size of the CGRect will be aligned to points.
61 CGRect CGRectMakeAlignedAndCenteredAt(CGFloat x, CGFloat y, CGFloat width);
63 // This function is used to figure out how to resize an image from an
64 // |originalSize| to a |targetSize|. It returns a |revisedTargetSize| of the
65 // resized image and |projectTo| that is used to describe the rectangle in the
66 // target that the image will be covering. Returned values are always floored to
67 // integral values.
69 // The ProjectionMode describes in which way the stretching will apply.
71 enum class ProjectionMode {
72 // Just stretches the source into the destination, not preserving aspect ratio
73 // at all.
74 // |projectTo| and |revisedTargetSize| will be set to |targetSize|
75 kFill,
77 // Scale to the target, maintaining aspect ratio, clipping the excess. Large
78 // original sizes are shrunk until they fit on one side, small original sizes
79 // are expanded.
80 // |projectTo| will be a subset of |originalSize|
81 // |revisedTargetSize| will be set to |targetSize|
82 kAspectFill,
84 // Fit the image in the target so it fits completely inside, preserving aspect
85 // ratio. This will leave bands with with no data in the target.
86 // |projectTo| will be set to |originalSize|
87 // |revisedTargetSize| will be a smaller in one direction from |targetSize|
88 kAspectFit,
90 // Scale to the target, maintaining aspect ratio and not clipping the excess.
91 // |projectTo| will be set to |originalSize|
92 // |revisedTargetSize| will be a larger in one direction from |targetSize|
93 kAspectFillNoClipping,
95 void CalculateProjection(CGSize originalSize,
96 CGSize targetSize,
97 ProjectionMode projectionMode,
98 CGSize& revisedTargetSize,
99 CGRect& projectTo);
101 #endif // IOS_CHROME_BROWSER_UI_UI_UTIL_H_