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

Side by Side Diff: ios/chrome/browser/ui/util/label_observer.h

Issue 2828743002: LabelObserver is no longer retained by the label (Closed)
Patch Set: Update comment Created 3 years, 8 months 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 #ifndef IOS_CHROME_BROWSER_UI_UTIL_LABEL_OBSERVER_H_ 5 #ifndef IOS_CHROME_BROWSER_UI_UTIL_LABEL_OBSERVER_H_
6 #define IOS_CHROME_BROWSER_UI_UTIL_LABEL_OBSERVER_H_ 6 #define IOS_CHROME_BROWSER_UI_UTIL_LABEL_OBSERVER_H_
7 7
8 #import <UIKit/UIKit.h> 8 #import <UIKit/UIKit.h>
9 9
10 // Class that observes changes to UILabel properties via KVO. This allows 10 // Class that observes changes to UILabel properties via KVO. This allows
11 // various classes that manage a UILabel's style via NSAttributedStrings to 11 // various classes that manage a UILabel's style via NSAttributedStrings to
12 // reapply their styling in response to property changes that would invalidate 12 // reapply their styling in response to property changes that would invalidate
13 // the attributed text. This class also synchronizes notifications of style 13 // the attributed text. This class also synchronizes notifications of style
14 // invalidation so that property changes that occur as the result of a 14 // invalidation so that property changes that occur as the result of a
15 // LabelObserverAction do not trigger other actions. 15 // LabelObserverAction do not trigger other actions.
16 @interface LabelObserver : NSObject 16 @interface LabelObserver : NSObject
17 17
18 // Returns the LabelObserver for |label|, laziliy instantiating one if 18 // Returns the LabelObserver for |label|, laziliy instantiating one if
19 // necessary. LabelObservers are associated with the label, and will be 19 // necessary. LabelObservers are associated with label but must be kept alive by
20 // deallocated upon |label|'s deallocation. 20 // the caller. |-startObserving| must be called before the |label| is observed.
21 + (instancetype)observerForLabel:(UILabel*)label; 21 + (instancetype)observerForLabel:(UILabel*)label;
marq (ping after 24h) 2017/04/19 15:25:19 Is this method still needed? It seems like any cal
gambard 2017/04/19 15:48:18 No, there is one use case in CRUILabel+AttributeUt
22 22
23 // LabelObservers should be created via |+observerForLabel:|. 23 // LabelObservers should be created via |+observerForLabel:|.
24 - (instancetype)init NS_UNAVAILABLE; 24 - (instancetype)init NS_UNAVAILABLE;
25 25
26 // Starts observing the label. For each call to this function, |-stopObserving|
27 // should be called before |label| is deallocated.
28 - (void)startObserving;
29
30 // Stops observing the label. The label stop being observed once the number of
31 // call to this function match the number of call to |-startObserving|.
32 - (void)stopObserving;
33
26 // Block type that takes a label. Blocks registered for a label will be called 34 // Block type that takes a label. Blocks registered for a label will be called
27 // when property values are updated. 35 // when property values are updated.
28 typedef void (^LabelObserverAction)(UILabel* label); 36 typedef void (^LabelObserverAction)(UILabel* label);
29 37
30 // Registers |action| to be called when stylistic properties on the observed 38 // Registers |action| to be called when stylistic properties on the observed
31 // label are changed. Style changes include changes to the label's font, 39 // label are changed. Style changes include changes to the label's font,
32 // textColor, textAlignment, lineBreakMode, shadowColor, or shadowOffset. 40 // textColor, textAlignment, lineBreakMode, shadowColor, or shadowOffset.
33 - (void)addStyleChangedAction:(LabelObserverAction)action; 41 - (void)addStyleChangedAction:(LabelObserverAction)action;
34 42
35 // Registers |action| to be called when the observed label's layout has changed. 43 // Registers |action| to be called when the observed label's layout has changed.
36 // Layout changes include changes to the label's bounds, frame, or superview, as 44 // Layout changes include changes to the label's bounds, frame, or superview, as
37 // well as changes to its center, which doesn't affect the label's layout 45 // well as changes to its center, which doesn't affect the label's layout
38 // internally but does affect its position in its superview. 46 // internally but does affect its position in its superview.
39 - (void)addLayoutChangedAction:(LabelObserverAction)action; 47 - (void)addLayoutChangedAction:(LabelObserverAction)action;
40 48
41 // Registers |action| to be called when the observed label's text has changed. 49 // Registers |action| to be called when the observed label's text has changed.
42 // Text changes include changes to the label's text or attributedText. 50 // Text changes include changes to the label's text or attributedText.
43 - (void)addTextChangedAction:(LabelObserverAction)action; 51 - (void)addTextChangedAction:(LabelObserverAction)action;
44 52
45 @end 53 @end
46 54
47 #endif // IOS_CHROME_BROWSER_UI_UTIL_LABEL_OBSERVER_H_ 55 #endif // IOS_CHROME_BROWSER_UI_UTIL_LABEL_OBSERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698