OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 5 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
6 | 6 |
7 #import <Accelerate/Accelerate.h> | 7 #import <Accelerate/Accelerate.h> |
8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
9 #import <QuartzCore/QuartzCore.h> | 9 #import <QuartzCore/QuartzCore.h> |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 NSDictionary* metrics, | 563 NSDictionary* metrics, |
564 UIView* unused_parentView) { | 564 UIView* unused_parentView) { |
565 ApplyVisualConstraintsWithMetrics(constraints, subviewsDictionary, metrics); | 565 ApplyVisualConstraintsWithMetrics(constraints, subviewsDictionary, metrics); |
566 } | 566 } |
567 | 567 |
568 void ApplyVisualConstraintsWithMetricsAndOptions( | 568 void ApplyVisualConstraintsWithMetricsAndOptions( |
569 NSArray* constraints, | 569 NSArray* constraints, |
570 NSDictionary* subviewsDictionary, | 570 NSDictionary* subviewsDictionary, |
571 NSDictionary* metrics, | 571 NSDictionary* metrics, |
572 NSLayoutFormatOptions options) { | 572 NSLayoutFormatOptions options) { |
573 NSMutableArray* layoutConstraints = | 573 NSArray* layoutConstraints = VisualConstraintsWithMetricsAndOptions( |
574 [NSMutableArray arrayWithCapacity:constraints.count * 3]; | 574 constraints, subviewsDictionary, metrics, options); |
575 for (NSString* constraint in constraints) { | |
576 DCHECK([constraint isKindOfClass:[NSString class]]); | |
577 [layoutConstraints addObjectsFromArray: | |
578 [NSLayoutConstraint | |
579 constraintsWithVisualFormat:constraint | |
580 options:options | |
581 metrics:metrics | |
582 views:subviewsDictionary]]; | |
583 } | |
584 [NSLayoutConstraint activateConstraints:layoutConstraints]; | 575 [NSLayoutConstraint activateConstraints:layoutConstraints]; |
585 } | 576 } |
586 | 577 |
587 void ApplyVisualConstraintsWithMetricsAndOptions( | 578 void ApplyVisualConstraintsWithMetricsAndOptions( |
588 NSArray* constraints, | 579 NSArray* constraints, |
589 NSDictionary* subviewsDictionary, | 580 NSDictionary* subviewsDictionary, |
590 NSDictionary* metrics, | 581 NSDictionary* metrics, |
591 NSLayoutFormatOptions options, | 582 NSLayoutFormatOptions options, |
592 UIView* unused_parentView) { | 583 UIView* unused_parentView) { |
593 ApplyVisualConstraintsWithMetricsAndOptions(constraints, subviewsDictionary, | 584 ApplyVisualConstraintsWithMetricsAndOptions(constraints, subviewsDictionary, |
594 metrics, options); | 585 metrics, options); |
595 } | 586 } |
596 | 587 |
588 NSArray* VisualConstraintsWithMetrics(NSArray* constraints, | |
589 NSDictionary* subviewsDictionary, | |
590 NSDictionary* metrics) { | |
591 return VisualConstraintsWithMetricsAndOptions(constraints, subviewsDictionary, | |
592 metrics, 0); | |
593 } | |
594 | |
595 NSArray* VisualConstraintsWithMetricsAndOptions( | |
596 NSArray* constraints, | |
597 NSDictionary* subviewsDictionary, | |
598 NSDictionary* metrics, | |
599 NSLayoutFormatOptions options) { | |
600 NSMutableArray* layoutConstraints = | |
601 [NSMutableArray arrayWithCapacity:constraints.count * 3]; | |
lpromero
2017/03/28 11:10:07
Question for marq: I don't understand the 3. Is it
marq (ping after 24h)
2017/03/28 12:15:13
No, it was an estimate. It should probably be docu
jlebel
2017/03/29 10:47:17
Removed as talk offline.
| |
602 for (NSString* constraint in constraints) { | |
603 DCHECK([constraint isKindOfClass:[NSString class]]); | |
604 [layoutConstraints addObjectsFromArray: | |
605 [NSLayoutConstraint | |
606 constraintsWithVisualFormat:constraint | |
607 options:options | |
608 metrics:metrics | |
609 views:subviewsDictionary]]; | |
610 } | |
611 return layoutConstraints; | |
marq (ping after 24h)
2017/03/28 12:15:13
Missed this: this should return [layoutConstrains
jlebel
2017/03/29 10:47:17
Done.
| |
612 } | |
613 | |
597 void AddSameCenterConstraints(UIView* view1, UIView* view2) { | 614 void AddSameCenterConstraints(UIView* view1, UIView* view2) { |
598 AddSameCenterXConstraint(view1, view2); | 615 AddSameCenterXConstraint(view1, view2); |
599 AddSameCenterYConstraint(view1, view2); | 616 AddSameCenterYConstraint(view1, view2); |
600 } | 617 } |
601 | 618 |
602 void AddSameCenterXConstraint(UIView* view1, UIView* view2) { | 619 void AddSameCenterXConstraint(UIView* view1, UIView* view2) { |
603 [view1.centerXAnchor constraintEqualToAnchor:view2.centerXAnchor].active = | 620 [view1.centerXAnchor constraintEqualToAnchor:view2.centerXAnchor].active = |
604 YES; | 621 YES; |
605 } | 622 } |
606 | 623 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 | 701 |
685 // On iOS10 and above, trigger a haptic vibration for a notification. | 702 // On iOS10 and above, trigger a haptic vibration for a notification. |
686 // This is a no-op for devices that do not support it. | 703 // This is a no-op for devices that do not support it. |
687 void TriggerHapticFeedbackForNotification(UINotificationFeedbackType type) { | 704 void TriggerHapticFeedbackForNotification(UINotificationFeedbackType type) { |
688 if (base::ios::IsRunningOnIOS10OrLater()) { | 705 if (base::ios::IsRunningOnIOS10OrLater()) { |
689 UINotificationFeedbackGenerator* generator = | 706 UINotificationFeedbackGenerator* generator = |
690 [[UINotificationFeedbackGenerator alloc] init]; | 707 [[UINotificationFeedbackGenerator alloc] init]; |
691 [generator notificationOccurred:type]; | 708 [generator notificationOccurred:type]; |
692 } | 709 } |
693 } | 710 } |
OLD | NEW |