summaryrefslogtreecommitdiffstats
path: root/ios
diff options
context:
space:
mode:
authorjbbegue <jbbegue@chromium.org>2015-08-07 03:15:47 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-07 10:16:30 +0000
commit18831714d344d489908705d374cf8c416afa603d (patch)
tree5d746b841072cf73535599715ca84a5df8c6e860 /ios
parent8b581d8b638951f98c0fb0c0116ac18b355b825e (diff)
downloadchromium_src-18831714d344d489908705d374cf8c416afa603d.zip
chromium_src-18831714d344d489908705d374cf8c416afa603d.tar.gz
chromium_src-18831714d344d489908705d374cf8c416afa603d.tar.bz2
Upstreaming browser/ui/uikit_ui_util from iOS.
Added AddSameCenterXConstraint which add constraints to a parent view to horizontally align two subviews. Added BOOL IsRTLUILayout() which take into account RTL pseudo language. This will be removed once base::i18n::IsRTL() supports it. BUG=None Review URL: https://codereview.chromium.org/1280913003 Cr-Commit-Position: refs/heads/master@{#342328}
Diffstat (limited to 'ios')
-rw-r--r--ios/chrome/browser/ui/uikit_ui_util.h13
-rw-r--r--ios/chrome/browser/ui/uikit_ui_util.mm34
2 files changed, 47 insertions, 0 deletions
diff --git a/ios/chrome/browser/ui/uikit_ui_util.h b/ios/chrome/browser/ui/uikit_ui_util.h
index 56bad29..5bffe39 100644
--- a/ios/chrome/browser/ui/uikit_ui_util.h
+++ b/ios/chrome/browser/ui/uikit_ui_util.h
@@ -142,6 +142,12 @@ void ApplyVisualConstraintsWithMetrics(NSArray* constraints,
// |subview| must be a subview of |parentView|.
void AddSameCenterXConstraint(UIView* parentView, UIView* subview);
+// Adds a constraint that |subview1| and |subview2| are center aligned
+// horizontally on |parentView|.
+// |subview1| and |subview2| must be subview of |parentView|.
+void AddSameCenterXConstraint(UIView *parentView, UIView *subview1,
+ UIView *subview2);
+
// Adds a constraint that |subview| is center aligned vertically in
// |parentView|.
// |subview| must be a subview of |parentView|.
@@ -153,6 +159,13 @@ void AddSameCenterYConstraint(UIView* parentView, UIView* subview);
void AddSameCenterYConstraint(UIView* parentView,
UIView* subview1,
UIView* subview2);
+// Whether the UI is configured for right to left layout.
+// The implementation will use the local in order to get the UI layout direction
+// for version of iOS under 9.
+// TODO(jbbegue): Use base::i18n::IsRTL() instead when it will support RTL
+// pseudo language. Remove that method once base::i18n::IsRTL() is fixed.
+// crbug/514625.
+BOOL IsRTLUILayout();
// Returns true if the main application window's rootViewController is a compact
// iPad horizontal size class.
diff --git a/ios/chrome/browser/ui/uikit_ui_util.mm b/ios/chrome/browser/ui/uikit_ui_util.mm
index 3f8d5b7..9b9d8f5 100644
--- a/ios/chrome/browser/ui/uikit_ui_util.mm
+++ b/ios/chrome/browser/ui/uikit_ui_util.mm
@@ -457,6 +457,21 @@ void AddSameCenterXConstraint(UIView* parentView, UIView* subview) {
constant:0]];
}
+void AddSameCenterXConstraint(UIView *parentView, UIView *subview1,
+ UIView *subview2) {
+ DCHECK_EQ(parentView, [subview1 superview]);
+ DCHECK_EQ(parentView, [subview2 superview]);
+ DCHECK_NE(subview1, subview2);
+ [parentView addConstraint:[NSLayoutConstraint
+ constraintWithItem:subview1
+ attribute:NSLayoutAttributeCenterX
+ relatedBy:NSLayoutRelationEqual
+ toItem:subview2
+ attribute:NSLayoutAttributeCenterX
+ multiplier:1
+ constant:0]];
+}
+
void AddSameCenterYConstraint(UIView* parentView, UIView* subview) {
DCHECK_EQ(parentView, [subview superview]);
[parentView addConstraint:[NSLayoutConstraint
@@ -499,3 +514,22 @@ bool IsCompactTablet() {
bool IsCompactTabletSizeClass(UIUserInterfaceSizeClass sizeClass) {
return IsIPadIdiom() && sizeClass == UIUserInterfaceSizeClassCompact;
}
+
+BOOL IsRTLUILayout() {
+ if (base::ios::IsRunningOnIOS9OrLater()) {
+#if __IPHONE_9_0
+ // Calling this method is better than using the locale on iOS9 since it will
+ // work with the right to left pseudolanguage.
+ return [UIView userInterfaceLayoutDirectionForSemanticContentAttribute:
+ UISemanticContentAttributeUnspecified] ==
+ UIUserInterfaceLayoutDirectionRightToLeft;
+#endif
+ }
+ // Using NSLocale instead of base::i18n::IsRTL() in order to take into account
+ // right to left pseudolanguage correctly (which base::i18n::IsRTL() doesn't).
+ return
+ [NSLocale
+ characterDirectionForLanguage:
+ [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]] ==
+ NSLocaleLanguageDirectionRightToLeft;
+}