OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 #ifndef IOS_CHROME_BROWSER_UI_UTIL_LABEL_LINK_CONTROLLER_H_ |
| 6 #define IOS_CHROME_BROWSER_UI_UTIL_LABEL_LINK_CONTROLLER_H_ |
| 7 |
| 8 #import <UIKit/UIKit.h> |
| 9 #include "ios/chrome/browser/procedural_block_types.h" |
| 10 |
| 11 class GURL; |
| 12 |
| 13 // A LabelLinkController manages a UILabel instance that is to have tappable |
| 14 // substrings ("links"). The controller handles styling the link areas (if |
| 15 // desired), and installs a gesture recognizer on the label that will trigger if |
| 16 // the specified regions are tapped. Multiple regions of the label may be |
| 17 // defined as links, and they may trigger different actions. |
| 18 // Each LabelLinkController calls a single action (a block that takes a GURL |
| 19 // parameter) for all taps; different links are defined by having different |
| 20 // URLs associated with them. |
| 21 // The LabelLinkController observes (via KVO) changes in the label's size, style |
| 22 // and text. If the label's bounds or style change, the controller recomputes |
| 23 // the link areas. If the text changes, all of the defined links for the label |
| 24 // are cleared (since they are presumed to be meaningless). |
| 25 // To prevent spurious recomputation of link areas, it is best to apply any |
| 26 // text manipulations and styling to the label before initializing a |
| 27 // LabelLinkController with it. |
| 28 @interface LabelLinkController : NSObject |
| 29 |
| 30 // If |showTapAreas| is true in a debug build, the tappable regions of the label |
| 31 // will have colored rectangles around them, with different colors for each URL, |
| 32 // and a darker outline around the exact text that the tappable region is for. |
| 33 // In non-debug builds, setting this property has no effect. |
| 34 @property(nonatomic, assign) BOOL showTapAreas; |
| 35 |
| 36 // Sets the link color for any defined links, updating the controlled label's |
| 37 // attributed text accordingly. |
| 38 @property(nonatomic, assign) UIColor* linkColor; |
| 39 |
| 40 // Sets the link underline style for any defined links, updating the controlled |
| 41 // label's attributed text accordingly. |
| 42 @property(nonatomic, assign) NSUnderlineStyle linkUnderlineStyle; |
| 43 |
| 44 // Sets the link font for any defined links, updating the controlled label's |
| 45 // attributed text accordingly. |
| 46 @property(nonatomic, retain) UIFont* linkFont; |
| 47 |
| 48 // Creates a new controller for |label|, whose lifetime is expected to exceed |
| 49 // that of the receiver. |action| is the block called for any tapped link. |
| 50 - (instancetype)initWithLabel:(UILabel*)label |
| 51 action:(ProceduralBlockWithURL)action; |
| 52 |
| 53 // Adds a link to the controlled label at |range| in the label's text, which |
| 54 // will call the receiver's action block when tapped, passing in |url|. |
| 55 - (void)addLinkWithRange:(NSRange)range url:(GURL)url; |
| 56 |
| 57 @end |
| 58 |
| 59 @interface LabelLinkController (Testing) |
| 60 |
| 61 // Testing interface for LabelLinkController. |
| 62 |
| 63 // This is the class that will be instantiated to do text mapping; by default |
| 64 // it is CoreTextMapper, but tests can assign to this property to do dependency |
| 65 // injection. |
| 66 @property(nonatomic, assign) Class textMapperClass; |
| 67 // Returns the tap rects generated by the controller that are associated with |
| 68 // |url|. |
| 69 - (NSArray*)tapRectsForURL:(GURL)url; |
| 70 // Simulates a tap in the controlled label at |point|. No touch events are |
| 71 // generated, but |action| should be invoked if |point| is inside a tap rect. |
| 72 - (void)tapLabelAtPoint:(CGPoint)point; |
| 73 |
| 74 @end |
| 75 |
| 76 #endif // IOS_CHROME_BROWSER_UI_UTIL_LABEL_LINK_CONTROLLER_H_ |
OLD | NEW |