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

Side by Side Diff: ios/chrome/browser/ui/stack_view/card_set.h

Issue 2587023002: Upstream Chrome on iOS source code [8/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 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 #ifndef IOS_CHROME_BROWSER_UI_STACK_VIEW_CARD_SET_H_
6 #define IOS_CHROME_BROWSER_UI_STACK_VIEW_CARD_SET_H_
7
8 #import <UIKit/UIKit.h>
9 #include <vector>
10
11 #import "ios/chrome/browser/tabs/tab_model_observer.h"
12 #import "ios/chrome/browser/ui/stack_view/card_view.h"
13 #import "ios/chrome/browser/ui/stack_view/stack_card.h"
14
15 @class CardSet;
16 @class CardStackLayoutManager;
17 struct LayoutRect;
18 @class TabModel;
19
20 // Observer delegate for clients interested in changes to cards in a CardSet.
21 @protocol CardSetObserver
22
23 // |newCard| has been added to |cardSet|.
24 - (void)cardSet:(CardSet*)cardSet didAddCard:(StackCard*)newCard;
25
26 // |cardBeingRemoved| will be removed from |cardSet|.
27 - (void)cardSet:(CardSet*)cardSet
28 willRemoveCard:(StackCard*)cardBeingRemoved
29 atIndex:(NSUInteger)index;
30
31 // |removedCard| has been removed from |cardSet|.
32 - (void)cardSet:(CardSet*)cardSet
33 didRemoveCard:(StackCard*)removedCard
34 atIndex:(NSUInteger)index;
35
36 // |card| has been made visible for the first time.
37 - (void)cardSet:(CardSet*)cardSet displayedCard:(StackCard*)card;
38
39 // |cardSet| completely rebuilt the cards; any cached reference to cards should
40 // be cleared, and any card setup done again for the whole card set.
41 // This is also called on initial creation of the card set.
42 - (void)cardSetRecreatedCards:(CardSet*)cardSet;
43
44 @end
45
46 // Manager for constructing a set of StackCards and displaying them in a view.
47 @interface CardSet : NSObject
48 // The layout manager for the set.
49 // TODO(stuartmorgan): See if this can reasonably be internalized.
50 @property(nonatomic, readonly) CardStackLayoutManager* stackModel;
51 // An array of StackCards in the same order as the tabs in the tab model.
52 @property(nonatomic, readonly) NSArray* cards;
53 // The card corresponding to the currently selected tab in the tab model.
54 // Setting this property will change the selection in the tab model.
55 @property(nonatomic, assign, readwrite) StackCard* currentCard;
56 // Set to the card that is currently animating closed, if any.
57 @property(nonatomic, assign, readwrite) StackCard* closingCard;
58 // The view that cards should be displayed in. Changing the display view will
59 // remove cards from the previous view, but they will not be re-displayed in the
60 // new view without a call to updateCardVisibilities.
61 @property(nonatomic, retain, readwrite) UIView* displayView;
62 // The side on which the close button should be displayed.
63 @property(nonatomic, readonly) CardCloseButtonSide closeButtonSide;
64 // The object to be notified about addition and removal of cards.
65 @property(nonatomic, assign, readwrite) id<CardSetObserver> observer;
66 // While YES, changes to the tab model will not affect the card stack. When
67 // this is changed back to NO, the card stack will be completely rebuilt, so
68 // this should be used very carefully.
69 @property(nonatomic, assign, readwrite) BOOL ignoresTabModelChanges;
70 // While set to YES, |updateCardVisibilities| will elide setting the views
71 // of covered cards to hidden. Setting to NO will trigger a call to
72 // |updateCardVisibilities| to hide any covered views. Can be set to YES
73 // during animations to ensure that cards being animated to not-visible
74 // positions remain visible throughout the animation; should be set back to
75 // NO on the completion of such animations. Default value is NO.
76 @property(nonatomic, assign, readwrite) BOOL defersCardHiding;
77 // The maximum amount that the first card is allowed to overextend toward the
78 // start or the end.
79 @property(nonatomic, assign) CGFloat maximumOverextensionAmount;
80 // If set to YES, a card view is released once the corresponding card becomes
81 // covered (it will be transparently reloaded if the card is uncovered), saving
82 // memory at the cost of potentially introducing jankiness. Default value is
83 // NO. Setting this property to YES causes views of covered cards to be
84 // immediately released.
85 @property(nonatomic, assign) BOOL keepOnlyVisibleCardViewsAlive;
86
87 // Initializes a card set backed by |model|. |model| is not retained, and must
88 // outlive the card set.
89 - (id)initWithModel:(TabModel*)model;
90
91 // The tab model backing the card set.
92 // TODO(stuartmorgan): See if this can reasonably be internalized.
93 - (TabModel*)tabModel;
94
95 // Sets the tab model backing the card set. This should only be called when the
96 // TabModel will be deleted and replaced by a new one. When called both the
97 // current tab model and the new tab model must be either nil, or contain no
98 // tabs.
99 - (void)setTabModel:(TabModel*)tabModel;
100
101 // Configures the stack fan out behavior based on the current display view
102 // size, card size, and layout direction. Sets the margin in the layout
103 // direction to |margin|.
104 - (void)configureLayoutParametersWithMargin:(CGFloat)margin;
105
106 // Updates the stack's visible size based on the current display view size,
107 // followed by recalculating the end stack. Should be called any time that the
108 // display view's size is changed.
109 - (void)displayViewSizeWasChanged;
110
111 // Sets the size of the cards in the set. Updates existing cards, and sets
112 // the size that will be used to make new cards in the future. Preserves card
113 // origins with the exception that cards are moved as necessary to satisfy
114 // placement constraints (e.g., that a card is not placed too far away from its
115 // preceding neighbor).
116 - (void)setCardSize:(CGSize)cardSize;
117
118 // Sets the layout axis position (i.e., the center of the cards in the
119 // non-layout direction) and layout direction of the card model. Sets the
120 // cards' positions along the new layout axis to their positions along the
121 // previous layout axis.
122 - (void)setLayoutAxisPosition:(CGFloat)position
123 isVertical:(BOOL)layoutIsVertical;
124
125 // Based on the cards' current positions, caps cards that should be in the
126 // start stack.
127 - (void)layOutStartStack;
128
129 // Fans out the cards starting at the first card and then gathers them in to
130 // the end limit of the visible stack.
131 - (void)fanOutCards;
132
133 // Fans out the cards and then gathers them in such that the first card not
134 // collapsed into the start stack is the card at |startIndex|.
135 - (void)fanOutCardsWithStartIndex:(NSUInteger)startIndex;
136
137 // Returns the current LayoutRects of the cards.
138 - (std::vector<LayoutRect>)cardLayouts;
139
140 // Scrolls the card at |index| by |delta| (and trailing cards by a maximum of
141 // |delta| depending on whether evening out after pinching needs to occur).
142 // Scrolls leading cards by delta if |scrollLeadingCards| is |YES|; otherwise,
143 // does not scroll leading cards. Allows a certain amount of overscrolling
144 // toward the start and end. If |decayOnOverscroll| is |YES|, the impact of the
145 // scroll decays once the stack is overscrolled. If |allowEarlyOverscroll|
146 // is |YES|, overscrolling is allowed to occur naturally on the scrolled card;
147 // otherwise, overscrolling is not allowed to occur until the stack is fully
148 // collapsed/fanned out.
149 - (void)scrollCardAtIndex:(NSUInteger)index
150 byDelta:(CGFloat)delta
151 allowEarlyOverscroll:(BOOL)allowEarlyOverscroll
152 decayOnOverscroll:(BOOL)decayOnOverscroll
153 scrollLeadingCards:(BOOL)scrollLeadingCards;
154
155 // Whether the stack is overextended.
156 - (BOOL)stackIsOverextended;
157 // Returns whether the card at |index| is overextended, defined as being
158 // overextended toward the start or end for the first card and overextended
159 // toward the start for any other card.
160 - (BOOL)overextensionOnCardAtIndex:(NSUInteger)index;
161 // Returns whether the card at |index| is overextended toward the start.
162 - (BOOL)overextensionTowardStartOnCardAtIndex:(NSUInteger)index;
163 // Moves the cards so that any overextension is eliminated, with the nature of
164 // the movement being dependent on whether a scroll or a pinch occurred last.
165 - (void)eliminateOverextension;
166
167 // Scrolls the card at |index| to be at the maximum separation from the
168 // neighboring card, followed by handling start and end capping. If |preceding|,
169 // the card at |index| is scrolled away from the previous card toward the end
170 // stack, otherwise it is scrolled away from the next card toward the start
171 // stack. Also scrolls the cards that the card at |index| is scrolled toward,
172 // but does not alter the positions of the cards it is being scrolled away from.
173 - (void)scrollCardAtIndex:(NSUInteger)index awayFromNeighbor:(BOOL)preceding;
174
175 // Updates the visibility of each card based on whether or not it is covered by
176 // other cards. Should be called any time the card layout changes.
177 - (void)updateCardVisibilities;
178
179 // Preloads (constructs the view and adds it to the view hierarchy, hidden) the
180 // next card, if there is one that still needs to be preloaded. Returns YES if
181 // a card was preloaded, NO if all cards were already loaded.
182 - (BOOL)preloadNextCard;
183
184 // Sets all of the cards' gesture recognizer targets/delegatesthat are equal to
185 // |object| to nil.
186 // TODO(stuartmorgan): This should probably move up out of CardSet.
187 - (void)clearGestureRecognizerTargetAndDelegateFromCards:(id)object;
188
189 // Removes the card at |index|. Does not modify the underlying TabModel.
190 // TODO(blundell): This public method is a hack only present to work around a
191 // crash. Do not add calls to it. b/8321162
192 - (void)removeCardAtIndex:(NSUInteger)index;
193
194 // The maximum length (without margins) that the stack could possibly grow to.
195 - (CGFloat)maximumStackLength;
196
197 // Returns whether |card| is collapsed behind its succeeding neighbor, defined
198 // as being separated by <= the separation distance between visible cards in the
199 // edge stacks.
200 - (BOOL)cardIsCollapsed:(StackCard*)card;
201
202 // Returns |YES| if all cards are scrolled into the start stack.
203 - (BOOL)stackIsFullyCollapsed;
204
205 // Returns |YES| if the stack is fully fanned out.
206 - (BOOL)stackIsFullyFannedOut;
207
208 // Returns |YES| if the stack is fully overextended toward the start or the
209 // end.
210 - (BOOL)stackIsFullyOverextended;
211
212 // The amount that the first card is currently overextended.
213 - (CGFloat)overextensionAmount;
214
215 // Returns whether |card| is collapsed into the start stagger region.
216 - (BOOL)isCardInStartStaggerRegion:(StackCard*)card;
217
218 // Returns whether |card| is collapsed into the end stagger region.
219 - (BOOL)isCardInEndStaggerRegion:(StackCard*)card;
220
221 // Updates the frame of the stack shadow to the card stack's current layout.
222 - (void)updateShadowLayout;
223
224 @end
225
226 @interface CardSet (Testing)
227 - (StackCard*)cardForTab:(Tab*)tab;
228 - (void)setStackModelForTesting:(CardStackLayoutManager*)stackModel;
229 @end
230
231 #endif // IOS_CHROME_BROWSER_UI_STACK_VIEW_CARD_SET_H_
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/side_swipe/side_swipe_util.mm ('k') | ios/chrome/browser/ui/stack_view/card_set.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698