Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(578)

Unified Diff: ios/chrome/browser/ui/fancy_ui/bidi_container_view.mm

Issue 2588713002: Upstream Chrome on iOS source code [4/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/fancy_ui/bidi_container_view.mm
diff --git a/ios/chrome/browser/ui/fancy_ui/bidi_container_view.mm b/ios/chrome/browser/ui/fancy_ui/bidi_container_view.mm
new file mode 100644
index 0000000000000000000000000000000000000000..931176c059ef79668565ef03653e81cb471a9794
--- /dev/null
+++ b/ios/chrome/browser/ui/fancy_ui/bidi_container_view.mm
@@ -0,0 +1,78 @@
+// 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.
+
+#import "ios/chrome/browser/ui/fancy_ui/bidi_container_view.h"
+
+#include "base/i18n/rtl.h"
+#include "base/logging.h"
+
+@interface BidiContainerView ()
+// Changes the autoresizing mask by mirroring it horizontally so that the RTL
+// layout is bind to oposite sites than LRT one.
++ (UIViewAutoresizing)mirrorAutoresizingMask:
+ (UIViewAutoresizing)autoresizingMask;
+@end
+
+@implementation BidiContainerView
+
++ (UIViewAutoresizing)mirrorAutoresizingMask:
+ (UIViewAutoresizing)autoresizingMask {
+ UIViewAutoresizing mirroredAutoresizingMask = autoresizingMask;
+ mirroredAutoresizingMask &= ~(UIViewAutoresizingFlexibleRightMargin |
+ UIViewAutoresizingFlexibleLeftMargin);
+
+ if (autoresizingMask & UIViewAutoresizingFlexibleRightMargin)
+ mirroredAutoresizingMask |= UIViewAutoresizingFlexibleLeftMargin;
+ if (autoresizingMask & UIViewAutoresizingFlexibleLeftMargin)
+ mirroredAutoresizingMask |= UIViewAutoresizingFlexibleRightMargin;
+
+ return mirroredAutoresizingMask;
+}
+
+- (void)layoutSubviews {
+ [super layoutSubviews];
+ if (!base::i18n::IsRTL())
+ return;
+
+ NSArray* viewsToAdjust;
+ BOOL adjustAutoresizingMask;
+ switch (adjustSubviewsType_) {
+ case ios::rtl::ADJUST_FRAME_AND_AUTOROTATION_MASK_FOR_ALL_SUBVIEWS:
+ viewsToAdjust = self.subviews;
+ adjustAutoresizingMask = YES;
+ adjustSubviewsType_ = ios::rtl::ADJUST_FRAME_FOR_UPDATED_SUBVIEWS;
+ break;
+
+ case ios::rtl::ADJUST_FRAME_FOR_UPDATED_SUBVIEWS:
+ viewsToAdjust = [subviewsToBeAdjustedForRTL_ allObjects];
+ adjustAutoresizingMask = NO;
+ break;
+ }
+ if (![viewsToAdjust count])
+ return;
+
+ CGFloat frameWidth = self.frame.size.width;
+ for (UIView* subview in viewsToAdjust) {
+ CGRect subFrame = subview.frame;
+ subFrame.origin.x = frameWidth - subFrame.origin.x - subFrame.size.width;
+ subview.frame = subFrame;
+ if (adjustAutoresizingMask) {
+ UIViewAutoresizing mirroredAutoresizingMask =
+ [BidiContainerView mirrorAutoresizingMask:[subview autoresizingMask]];
+ [subview setAutoresizingMask:mirroredAutoresizingMask];
+ }
+ }
+ [subviewsToBeAdjustedForRTL_ removeAllObjects];
+}
+
+- (void)setSubviewNeedsAdjustmentForRTL:(UIView*)subview {
+ DCHECK([self.subviews containsObject:subview]);
+ if (!base::i18n::IsRTL())
+ return;
+ if (!subviewsToBeAdjustedForRTL_)
+ subviewsToBeAdjustedForRTL_.reset([[NSMutableSet alloc] init]);
+ [subviewsToBeAdjustedForRTL_ addObject:subview];
+}
+
+@end
« no previous file with comments | « ios/chrome/browser/ui/fancy_ui/bidi_container_view.h ('k') | ios/chrome/browser/ui/fancy_ui/bidi_container_view_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698