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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
5 #import "ios/chrome/browser/ui/fancy_ui/bidi_container_view.h"
6
7 #include "base/i18n/rtl.h"
8 #include "base/logging.h"
9
10 @interface BidiContainerView ()
11 // Changes the autoresizing mask by mirroring it horizontally so that the RTL
12 // layout is bind to oposite sites than LRT one.
13 + (UIViewAutoresizing)mirrorAutoresizingMask:
14 (UIViewAutoresizing)autoresizingMask;
15 @end
16
17 @implementation BidiContainerView
18
19 + (UIViewAutoresizing)mirrorAutoresizingMask:
20 (UIViewAutoresizing)autoresizingMask {
21 UIViewAutoresizing mirroredAutoresizingMask = autoresizingMask;
22 mirroredAutoresizingMask &= ~(UIViewAutoresizingFlexibleRightMargin |
23 UIViewAutoresizingFlexibleLeftMargin);
24
25 if (autoresizingMask & UIViewAutoresizingFlexibleRightMargin)
26 mirroredAutoresizingMask |= UIViewAutoresizingFlexibleLeftMargin;
27 if (autoresizingMask & UIViewAutoresizingFlexibleLeftMargin)
28 mirroredAutoresizingMask |= UIViewAutoresizingFlexibleRightMargin;
29
30 return mirroredAutoresizingMask;
31 }
32
33 - (void)layoutSubviews {
34 [super layoutSubviews];
35 if (!base::i18n::IsRTL())
36 return;
37
38 NSArray* viewsToAdjust;
39 BOOL adjustAutoresizingMask;
40 switch (adjustSubviewsType_) {
41 case ios::rtl::ADJUST_FRAME_AND_AUTOROTATION_MASK_FOR_ALL_SUBVIEWS:
42 viewsToAdjust = self.subviews;
43 adjustAutoresizingMask = YES;
44 adjustSubviewsType_ = ios::rtl::ADJUST_FRAME_FOR_UPDATED_SUBVIEWS;
45 break;
46
47 case ios::rtl::ADJUST_FRAME_FOR_UPDATED_SUBVIEWS:
48 viewsToAdjust = [subviewsToBeAdjustedForRTL_ allObjects];
49 adjustAutoresizingMask = NO;
50 break;
51 }
52 if (![viewsToAdjust count])
53 return;
54
55 CGFloat frameWidth = self.frame.size.width;
56 for (UIView* subview in viewsToAdjust) {
57 CGRect subFrame = subview.frame;
58 subFrame.origin.x = frameWidth - subFrame.origin.x - subFrame.size.width;
59 subview.frame = subFrame;
60 if (adjustAutoresizingMask) {
61 UIViewAutoresizing mirroredAutoresizingMask =
62 [BidiContainerView mirrorAutoresizingMask:[subview autoresizingMask]];
63 [subview setAutoresizingMask:mirroredAutoresizingMask];
64 }
65 }
66 [subviewsToBeAdjustedForRTL_ removeAllObjects];
67 }
68
69 - (void)setSubviewNeedsAdjustmentForRTL:(UIView*)subview {
70 DCHECK([self.subviews containsObject:subview]);
71 if (!base::i18n::IsRTL())
72 return;
73 if (!subviewsToBeAdjustedForRTL_)
74 subviewsToBeAdjustedForRTL_.reset([[NSMutableSet alloc] init]);
75 [subviewsToBeAdjustedForRTL_ addObject:subview];
76 }
77
78 @end
OLDNEW
« 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