Give names to all utility processes.
[chromium-blink-merge.git] / ios / chrome / browser / ui / uikit_ui_util.h
blob37aa0d3931f91313e85068de9e0dd5c502ec7c3f
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_UIKIT_UI_UTIL_H_
6 #define IOS_CHROME_BROWSER_UI_UIKIT_UI_UTIL_H_
8 #include <CoreGraphics/CoreGraphics.h>
9 #import <Foundation/Foundation.h>
10 #import <UIKit/UIKit.h>
12 #import "ios/chrome/browser/ui/ui_util.h"
14 // UI Util containing functions that require UIKit.
16 enum { FONT_HELVETICA, FONT_HELVETICA_NEUE, FONT_HELVETICA_NEUE_LIGHT };
18 // Utility function to set the |element|'s accessibility label to the localized
19 // message corresponding to |idsAccessibilityLabel| and its accessibility
20 // identifier to |englishUiAutomationName|.
21 // Call SetA11yLabelAndUiAutomationName() if |element| is accessible and its
22 // a11y label should be localized.
23 // By convention |englishUiAutomationName| must be equal to the English
24 // localized string corresponding to |idsAccessibilityLabel|.
25 // |englishUiAutomationName| is the name used in JavaScript UI Automation test
26 // scripts to identify the |element|.
27 void SetA11yLabelAndUiAutomationName(UIView* element,
28 int idsAccessibilityLabel,
29 NSString* englishUiAutomationName);
31 // Sets the given |button|'s width to exactly fit its image and text. Does not
32 // modify the button's height.
33 void GetSizeButtonWidthToFit(UIButton* button);
35 // Translates the given |view|'s frame. Sets a new frame instead of applying a
36 // transform to the existing frame.
37 void TranslateFrame(UIView* view, UIOffset offset);
39 // Returns a UIFont. |fontFace| is one of the defined enumerated values
40 // to avoid spelling mistakes.
41 UIFont* GetUIFont(int fontFace, bool isBold, CGFloat fontSize);
43 // Adds a border shadow around |view|.
44 void AddBorderShadow(UIView* view, CGFloat offset, UIColor* color);
46 // Adds a rounded-rectangle border shadow around a view.
47 void AddRoundedBorderShadow(UIView* view, CGFloat radius, UIColor* color);
49 // Captures and returns an autoreleased rendering of the |view|.
50 // The |view| is assumed to be opaque and the returned image does
51 // not have an alpha channel. The scale parameter is used as a scale factor
52 // for the rendering context. Using 0.0 as scale will result in the device's
53 // main screen scale to be used.
54 UIImage* CaptureView(UIView* view, CGFloat scale);
56 // Converts input image and returns a grey scaled version.
57 UIImage* GreyImage(UIImage* image);
59 // Returns the color that should be used for the background of all Settings
60 // pages.
61 UIColor* GetSettingsBackgroundColor();
63 // Returns the color used as the main color for primary action buttons.
64 UIColor* GetPrimaryActionButtonColor();
66 // Returns an UIColor with |rgb| and |alpha|. The caller should pass the RGB
67 // value in hexadecimal as this is the typical way they are provided by UX.
68 // For example a call to |UIColorFromRGB(0xFF7D40, 1.0)| returns an orange
69 // UIColor object.
70 inline UIColor* UIColorFromRGB(int rgb, CGFloat alpha = 1.0) {
71 return [UIColor colorWithRed:((CGFloat)((rgb & 0xFF0000) >> 16)) / 255.0
72 green:((CGFloat)((rgb & 0x00FF00) >> 8)) / 255.0
73 blue:((CGFloat)(rgb & 0x0000FF)) / 255.0
74 alpha:alpha];
77 // Returns an image resized to |targetSize|. It first calculate the projection
78 // by calling CalculateProjection() and then create a new image of the desired
79 // size and project the correct subset of the originla image onto it.
81 // Image interpolation level for resizing is set to kCGInterpolationDefault.
83 // The resize always preserves the scale of the original image.
84 UIImage* ResizeImage(UIImage* image,
85 CGSize targetSize,
86 ProjectionMode projectionMode);
88 // Returns a slightly blurred image darkened enough to provide contrast for
89 // white text to be readable.
90 UIImage* DarkenImage(UIImage* image);
92 // Applies various effects to an image. This method can apply a blur over a
93 // |radius|, superimpose a |tintColor| (an alpha of 0.6 on the color is a good
94 // approximation to look like iOS tint colors) or saturate the image colors by
95 // applying a |saturationDeltaFactor| (negative to desaturate, positive to
96 // saturate). The optional |maskImage| is used to limit the effect of the blur
97 // and/or saturation to a portion of the image.
98 UIImage* BlurImage(UIImage* image,
99 CGFloat blurRadius,
100 UIColor* tintColor,
101 CGFloat saturationDeltaFactor,
102 UIImage* maskImage);
104 // Returns the interface orientation of the app.
105 UIInterfaceOrientation GetInterfaceOrientation();
107 // Returns the height of the keyboard in the current orientation.
108 CGFloat CurrentKeyboardHeight(NSValue* keyboardFrameValue);
110 // Create 1x1px image from |color|.
111 UIImage* ImageWithColor(UIColor* color);
113 // Returns a circular image of width |width| based on |image| scaled up or
114 // down. If the source image is not square, the image is first cropped.
115 UIImage* CircularImageFromImage(UIImage* image, CGFloat width);
117 // Returns the linear interpolated color from |firstColor| to |secondColor| by
118 // the given |fraction|. Requires that both colors are in RGB or monochrome
119 // color space. |fraction| is a decimal value between 0.0 and 1.0.
120 UIColor* InterpolateFromColorToColor(UIColor* firstColor,
121 UIColor* secondColor,
122 CGFloat fraction);
124 // Applies all |constraints| to all views in |subviewsDictionary| in the
125 // superview |parentView|.
126 void ApplyVisualConstraints(NSArray* constraints,
127 NSDictionary* subviewsDictionary,
128 UIView* parentView);
130 // Adds a constraint that |subview| is center aligned horizontally in
131 // |parentView|.
132 // |subview| must be a subiew of |parentView|.
133 void AddSameCenterXConstraint(UIView* parentView, UIView* subview);
135 // Adds a constraint that |subview1| and |subview2| are center aligned
136 // vertically on |parentView|.
137 // |subview1| and |subview2| must be subiews of |parentView|.
138 void AddSameCenterYConstraint(UIView* parentView,
139 UIView* subview1,
140 UIView* subview2);
142 #endif // IOS_CHROME_BROWSER_UI_UIKIT_UI_UTIL_H_