Changeset 259559 in webkit
- Timestamp:
- Apr 5, 2020 5:28:50 PM (4 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r259557 r259559 1 2020-04-05 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Address review comments after r259550 4 https://bugs.webkit.org/show_bug.cgi?id=208472 5 6 Reviewed by Darin Adler. 7 8 * platform/ios/ValidationBubbleIOS.mm: 9 10 Change a few named constants to be `constexpr` instead, and add comments describing their purpose. 11 12 (label): 13 (updateLabelFrame): 14 15 Rename these helper functions and move them up the file. Turn what was previously named 16 `WebValidationBubbleViewController_labelFrame` into `updateLabelFrame`, and have it additionally update the 17 view controller's label's frame to avoid repeating this logic in the subclassed method implementations below. 18 19 (callSuper): 20 (WebValidationBubbleViewController_viewDidLoad): 21 (WebValidationBubbleViewController_viewWillLayoutSubviews): 22 (WebValidationBubbleViewController_viewSafeAreaInsetsDidChange): 23 (allocWebValidationBubbleViewControllerInstance): 24 25 Instead of using `-valueForKey`, use `objc_getAssociatedObject` and `objc_setAssociatedObject`, with 26 `OBJC_ASSOCIATION_RETAIN_NONATOMIC`. 27 28 (WebCore::ValidationBubble::ValidationBubble): 29 (invokeUIViewControllerSelector): Deleted. 30 (WebValidationBubbleViewController_dealloc): Deleted. 31 32 Remove the -dealloc override. We don't need this anymore, since we're now using associated objects with 33 `OBJC_ASSOCIATION_RETAIN_NONATOMIC` to hold on to and keep track of our label. 34 35 (WebValidationBubbleViewController_labelFrame): Deleted. 36 (WebValidationBubbleViewController_label): Deleted. 37 1 38 2020-04-05 Simon Fraser <simon.fraser@apple.com> 2 39 -
trunk/Source/WebCore/platform/ios/ValidationBubbleIOS.mm
r259550 r259559 32 32 #import <UIKit/UIGeometry.h> 33 33 #import <objc/message.h> 34 #import <objc/runtime.h>35 34 #import <pal/ios/UIKitSoftLink.h> 36 35 #import <pal/spi/ios/UIKitSPI.h> … … 39 38 #import <wtf/text/WTFString.h> 40 39 41 static const CGFloat validationBubbleHorizontalPadding = 17; 42 static const CGFloat validationBubbleVerticalPadding = 9; 43 static const CGFloat validationBubbleMaxLabelWidth = 300; 40 // Add a bit of vertical and horizontal padding between the 41 // label and its parent view, to avoid laying out the label 42 // against the edges of the popover view. 43 constexpr CGFloat validationBubbleHorizontalPadding = 17; 44 constexpr CGFloat validationBubbleVerticalPadding = 9; 45 46 // Avoid making the validation bubble too wide by enforcing a 47 // maximum width on the content size of the validation bubble 48 // view controller. 49 constexpr CGFloat validationBubbleMaxLabelWidth = 300; 50 51 // Avoid making the validation bubble too tall by truncating 52 // the label to a maximum of 4 lines. 53 constexpr NSInteger validationBubbleMaxNumberOfLines = 4; 44 54 45 55 @interface WebValidationBubbleViewController : UIViewController 46 @property (nonatomic, readonly) UILabel *label; 47 @property (nonatomic, readonly) CGRect labelFrame; 48 @end 49 50 static void invokeUIViewControllerSelector(id instance, SEL selector) 51 { 52 objc_super superClass { instance, PAL::getUIViewControllerClass() }; 53 auto superclassFunction = reinterpret_cast<void(*)(objc_super*, SEL)>(objc_msgSendSuper); 54 superclassFunction(&superClass, selector); 55 } 56 57 static void WebValidationBubbleViewController_dealloc(WebValidationBubbleViewController *instance, SEL) 58 { 59 [instance.label release]; 60 [instance setValue:nil forKey:@"_label"]; 61 62 invokeUIViewControllerSelector(instance, @selector(dealloc)); 56 @end 57 58 static const void* const validationBubbleViewControllerLabelKey = &validationBubbleViewControllerLabelKey; 59 60 static UILabel *label(WebValidationBubbleViewController *controller) 61 { 62 return objc_getAssociatedObject(controller, validationBubbleViewControllerLabelKey); 63 } 64 65 static void updateLabelFrame(WebValidationBubbleViewController *controller) 66 { 67 auto frameWithPadding = UIEdgeInsetsInsetRect(controller.view.bounds, controller.view.safeAreaInsets); 68 label(controller).frame = UIEdgeInsetsInsetRect(frameWithPadding, UIEdgeInsetsMake(validationBubbleVerticalPadding, validationBubbleHorizontalPadding, validationBubbleVerticalPadding, validationBubbleHorizontalPadding)); 69 } 70 71 static void callSuper(WebValidationBubbleViewController *instance, SEL selector) 72 { 73 objc_super superStructure { instance, PAL::getUIViewControllerClass() }; 74 auto msgSendSuper = reinterpret_cast<void(*)(objc_super*, SEL)>(objc_msgSendSuper); 75 msgSendSuper(&superStructure, selector); 63 76 } 64 77 65 78 static void WebValidationBubbleViewController_viewDidLoad(WebValidationBubbleViewController *instance, SEL) 66 79 { 67 invokeUIViewControllerSelector(instance, @selector(viewDidLoad));68 69 UILabel *label = [PAL::allocUILabelInstance() init];70 label.font = [PAL::getUIFontClass() preferredFontForTextStyle:PAL::get_UIKit_UIFontTextStyleCallout()];71 label.lineBreakMode = NSLineBreakByTruncatingTail;72 label.numberOfLines = 4;73 [instance.view addSubview:label ];74 [instance setValue:label forKey:@"_label"];80 callSuper(instance, @selector(viewDidLoad)); 81 82 auto label = adoptNS([PAL::allocUILabelInstance() init]); 83 [label setFont:[PAL::getUIFontClass() preferredFontForTextStyle:PAL::get_UIKit_UIFontTextStyleCallout()]]; 84 [label setLineBreakMode:NSLineBreakByTruncatingTail]; 85 [label setNumberOfLines:validationBubbleMaxNumberOfLines]; 86 [instance.view addSubview:label.get()]; 87 objc_setAssociatedObject(instance, validationBubbleViewControllerLabelKey, label.get(), OBJC_ASSOCIATION_RETAIN_NONATOMIC); 75 88 } 76 89 77 90 static void WebValidationBubbleViewController_viewWillLayoutSubviews(WebValidationBubbleViewController *instance, SEL) 78 91 { 79 invokeUIViewControllerSelector(instance, @selector(viewWillLayoutSubviews)); 80 81 instance.label.frame = instance.labelFrame; 92 callSuper(instance, @selector(viewWillLayoutSubviews)); 93 updateLabelFrame(instance); 82 94 } 83 95 84 96 static void WebValidationBubbleViewController_viewSafeAreaInsetsDidChange(WebValidationBubbleViewController *instance, SEL) 85 97 { 86 invokeUIViewControllerSelector(instance, @selector(viewSafeAreaInsetsDidChange)); 87 88 instance.label.frame = instance.labelFrame; 89 } 90 91 static CGRect WebValidationBubbleViewController_labelFrame(WebValidationBubbleViewController *instance, SEL) 92 { 93 auto frameWithPadding = UIEdgeInsetsInsetRect(instance.view.bounds, instance.view.safeAreaInsets); 94 return UIEdgeInsetsInsetRect(frameWithPadding, UIEdgeInsetsMake(validationBubbleVerticalPadding, validationBubbleHorizontalPadding, validationBubbleVerticalPadding, validationBubbleHorizontalPadding)); 95 } 96 97 static UILabel *WebValidationBubbleViewController_label(WebValidationBubbleViewController *instance, SEL) 98 { 99 return [instance valueForKey:@"_label"]; 98 callSuper(instance, @selector(viewSafeAreaInsetsDidChange)); 99 updateLabelFrame(instance); 100 100 } 101 101 … … 106 106 dispatch_once(&onceToken, ^{ 107 107 theClass = objc_allocateClassPair(PAL::getUIViewControllerClass(), "WebValidationBubbleViewController", 0); 108 class_addMethod(theClass, @selector(dealloc), (IMP)WebValidationBubbleViewController_dealloc, "v@:");109 108 class_addMethod(theClass, @selector(viewDidLoad), (IMP)WebValidationBubbleViewController_viewDidLoad, "v@:"); 110 109 class_addMethod(theClass, @selector(viewWillLayoutSubviews), (IMP)WebValidationBubbleViewController_viewWillLayoutSubviews, "v@:"); 111 110 class_addMethod(theClass, @selector(viewSafeAreaInsetsDidChange), (IMP)WebValidationBubbleViewController_viewSafeAreaInsetsDidChange, "v@:"); 112 class_addMethod(theClass, @selector(label), (IMP)WebValidationBubbleViewController_label, "v@:");113 class_addMethod(theClass, @selector(labelFrame), (IMP)WebValidationBubbleViewController_labelFrame, "v@:");114 class_addIvar(theClass, "_label", sizeof(UILabel *), log2(sizeof(UILabel *)), "@");115 111 objc_registerClassPair(theClass); 116 112 }); … … 178 174 m_tapRecognizer = adoptNS([[WebValidationBubbleTapRecognizer alloc] initWithPopoverController:m_popoverController.get()]); 179 175 180 UILabel * label = [m_popoverController label];181 label.text = message;182 m_fontSize = label.font.pointSize;183 CGSize labelSize = [ label sizeThatFits:CGSizeMake(validationBubbleMaxLabelWidth, CGFLOAT_MAX)];176 UILabel *validationLabel = label(m_popoverController.get()); 177 validationLabel.text = message; 178 m_fontSize = validationLabel.font.pointSize; 179 CGSize labelSize = [validationLabel sizeThatFits:CGSizeMake(validationBubbleMaxLabelWidth, CGFLOAT_MAX)]; 184 180 [m_popoverController setPreferredContentSize:CGSizeMake(labelSize.width + validationBubbleHorizontalPadding * 2, labelSize.height + validationBubbleVerticalPadding * 2)]; 185 181 }
Note: See TracChangeset
for help on using the changeset viewer.