OLD | NEW |
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 #import "ios/chrome/browser/ui/side_swipe/side_swipe_controller.h" | 5 #import "ios/chrome/browser/ui/side_swipe/side_swipe_controller.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #import "base/ios/weak_nsobject.h" | |
10 #include "components/reading_list/core/reading_list_model.h" | 9 #include "components/reading_list/core/reading_list_model.h" |
11 #import "ios/chrome/browser/browser_state/chrome_browser_state.h" | 10 #import "ios/chrome/browser/browser_state/chrome_browser_state.h" |
12 #import "ios/chrome/browser/infobars/infobar_container_view.h" | 11 #import "ios/chrome/browser/infobars/infobar_container_view.h" |
13 #import "ios/chrome/browser/reading_list/reading_list_model_factory.h" | 12 #import "ios/chrome/browser/reading_list/reading_list_model_factory.h" |
14 #import "ios/chrome/browser/snapshots/snapshot_cache.h" | 13 #import "ios/chrome/browser/snapshots/snapshot_cache.h" |
15 #import "ios/chrome/browser/tabs/tab.h" | 14 #import "ios/chrome/browser/tabs/tab.h" |
16 #import "ios/chrome/browser/tabs/tab_model_observer.h" | 15 #import "ios/chrome/browser/tabs/tab_model_observer.h" |
17 #import "ios/chrome/browser/ui/reading_list/reading_list_side_swipe_provider.h" | 16 #import "ios/chrome/browser/ui/reading_list/reading_list_side_swipe_provider.h" |
18 #import "ios/chrome/browser/ui/side_swipe/card_side_swipe_view.h" | 17 #import "ios/chrome/browser/ui/side_swipe/card_side_swipe_view.h" |
19 #import "ios/chrome/browser/ui/side_swipe/history_side_swipe_provider.h" | 18 #import "ios/chrome/browser/ui/side_swipe/history_side_swipe_provider.h" |
20 #import "ios/chrome/browser/ui/side_swipe/side_swipe_navigation_view.h" | 19 #import "ios/chrome/browser/ui/side_swipe/side_swipe_navigation_view.h" |
21 #import "ios/chrome/browser/ui/side_swipe/side_swipe_util.h" | 20 #import "ios/chrome/browser/ui/side_swipe/side_swipe_util.h" |
22 #import "ios/chrome/browser/ui/side_swipe_gesture_recognizer.h" | 21 #import "ios/chrome/browser/ui/side_swipe_gesture_recognizer.h" |
23 #include "ios/chrome/browser/ui/ui_util.h" | 22 #include "ios/chrome/browser/ui/ui_util.h" |
24 #import "ios/web/public/web_state/web_state_observer_bridge.h" | 23 #import "ios/web/public/web_state/web_state_observer_bridge.h" |
25 #import "ios/web/web_state/ui/crw_web_controller.h" | 24 #import "ios/web/web_state/ui/crw_web_controller.h" |
26 | 25 |
| 26 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 27 #error "This file requires ARC support." |
| 28 #endif |
| 29 |
27 namespace ios_internal { | 30 namespace ios_internal { |
28 NSString* const kSideSwipeWillStartNotification = | 31 NSString* const kSideSwipeWillStartNotification = |
29 @"kSideSwipeWillStartNotification"; | 32 @"kSideSwipeWillStartNotification"; |
30 NSString* const kSideSwipeDidStopNotification = | 33 NSString* const kSideSwipeDidStopNotification = |
31 @"kSideSwipeDidStopNotification"; | 34 @"kSideSwipeDidStopNotification"; |
32 } // namespace ios_internal | 35 } // namespace ios_internal |
33 | 36 |
34 namespace { | 37 namespace { |
35 | 38 |
36 enum class SwipeType { NONE, CHANGE_TAB, CHANGE_PAGE }; | 39 enum class SwipeType { NONE, CHANGE_TAB, CHANGE_PAGE }; |
37 | 40 |
38 // Swipe starting distance from edge. | 41 // Swipe starting distance from edge. |
39 const CGFloat kSwipeEdge = 20; | 42 const CGFloat kSwipeEdge = 20; |
40 | 43 |
41 // Distance between sections of iPad side swipe. | 44 // Distance between sections of iPad side swipe. |
42 const CGFloat kIpadTabSwipeDistance = 100; | 45 const CGFloat kIpadTabSwipeDistance = 100; |
43 | 46 |
44 // Number of tabs to keep in the grey image cache. | 47 // Number of tabs to keep in the grey image cache. |
45 const NSUInteger kIpadGreySwipeTabCount = 8; | 48 const NSUInteger kIpadGreySwipeTabCount = 8; |
46 } | 49 } |
47 | 50 |
48 @interface SideSwipeController ()<CRWWebStateObserver, | 51 @interface SideSwipeController ()<CRWWebStateObserver, |
49 TabModelObserver, | 52 TabModelObserver, |
50 UIGestureRecognizerDelegate> { | 53 UIGestureRecognizerDelegate> { |
51 @private | 54 @private |
52 | 55 |
53 base::WeakNSObject<TabModel> model_; | 56 __weak TabModel* model_; |
54 | 57 |
55 // Side swipe view for tab navigation. | 58 // Side swipe view for tab navigation. |
56 base::scoped_nsobject<CardSideSwipeView> tabSideSwipeView_; | 59 CardSideSwipeView* tabSideSwipeView_; |
57 | 60 |
58 // Side swipe view for page navigation. | 61 // Side swipe view for page navigation. |
59 base::scoped_nsobject<SideSwipeNavigationView> pageSideSwipeView_; | 62 SideSwipeNavigationView* pageSideSwipeView_; |
60 | 63 |
61 // YES if the user is currently swiping. | 64 // YES if the user is currently swiping. |
62 BOOL inSwipe_; | 65 BOOL inSwipe_; |
63 | 66 |
64 // Swipe gesture recognizer. | 67 // Swipe gesture recognizer. |
65 base::scoped_nsobject<SideSwipeGestureRecognizer> swipeGestureRecognizer_; | 68 SideSwipeGestureRecognizer* swipeGestureRecognizer_; |
66 | 69 |
67 base::scoped_nsobject<SideSwipeGestureRecognizer> panGestureRecognizer_; | 70 SideSwipeGestureRecognizer* panGestureRecognizer_; |
68 | 71 |
69 // Used in iPad side swipe gesture, tracks the starting tab index. | 72 // Used in iPad side swipe gesture, tracks the starting tab index. |
70 NSUInteger startingTabIndex_; | 73 NSUInteger startingTabIndex_; |
71 | 74 |
72 // If the swipe is for a page change or a tab change. | 75 // If the swipe is for a page change or a tab change. |
73 SwipeType swipeType_; | 76 SwipeType swipeType_; |
74 | 77 |
75 // Bridge to observe the web state from Objective-C. | 78 // Bridge to observe the web state from Objective-C. |
76 std::unique_ptr<web::WebStateObserverBridge> webStateObserverBridge_; | 79 std::unique_ptr<web::WebStateObserverBridge> webStateObserverBridge_; |
77 | 80 |
78 // Curtain over web view while waiting for it to load. | 81 // Curtain over web view while waiting for it to load. |
79 base::scoped_nsobject<UIView> curtain_; | 82 UIView* curtain_; |
80 | 83 |
81 // Provides forward/back action for history entries. | 84 // Provides forward/back action for history entries. |
82 base::scoped_nsobject<HistorySideSwipeProvider> historySideSwipeProvider_; | 85 HistorySideSwipeProvider* historySideSwipeProvider_; |
83 | 86 |
84 // Provides forward action for reading list. | 87 // Provides forward action for reading list. |
85 base::scoped_nsobject<ReadingListSideSwipeProvider> | 88 ReadingListSideSwipeProvider* readingListSideSwipeProvider_; |
86 readingListSideSwipeProvider_; | |
87 | 89 |
88 base::WeakNSProtocol<id<SideSwipeContentProvider>> currentContentProvider_; | 90 __weak id<SideSwipeContentProvider> currentContentProvider_; |
89 } | 91 } |
90 | 92 |
91 // Load grey snapshots for the next |kIpadGreySwipeTabCount| tabs in | 93 // Load grey snapshots for the next |kIpadGreySwipeTabCount| tabs in |
92 // |direction|. | 94 // |direction|. |
93 - (void)createGreyCache:(UISwipeGestureRecognizerDirection)direction; | 95 - (void)createGreyCache:(UISwipeGestureRecognizerDirection)direction; |
94 // Tell snapshot cache to clear grey cache. | 96 // Tell snapshot cache to clear grey cache. |
95 - (void)deleteGreyCache; | 97 - (void)deleteGreyCache; |
96 // Handle tab side swipe for iPad. Change tabs according to swipe distance. | 98 // Handle tab side swipe for iPad. Change tabs according to swipe distance. |
97 - (void)handleiPadTabSwipe:(SideSwipeGestureRecognizer*)gesture; | 99 - (void)handleiPadTabSwipe:(SideSwipeGestureRecognizer*)gesture; |
98 // Handle tab side swipe for iPhone. Introduces a CardSideSwipeView to convey | 100 // Handle tab side swipe for iPhone. Introduces a CardSideSwipeView to convey |
(...skipping 11 matching lines...) Expand all Loading... |
110 | 112 |
111 @synthesize inSwipe = inSwipe_; | 113 @synthesize inSwipe = inSwipe_; |
112 @synthesize swipeDelegate = swipeDelegate_; | 114 @synthesize swipeDelegate = swipeDelegate_; |
113 @synthesize snapshotDelegate = snapshotDelegate_; | 115 @synthesize snapshotDelegate = snapshotDelegate_; |
114 | 116 |
115 - (id)initWithTabModel:(TabModel*)model | 117 - (id)initWithTabModel:(TabModel*)model |
116 browserState:(ios::ChromeBrowserState*)browserState { | 118 browserState:(ios::ChromeBrowserState*)browserState { |
117 DCHECK(model); | 119 DCHECK(model); |
118 self = [super init]; | 120 self = [super init]; |
119 if (self) { | 121 if (self) { |
120 model_.reset(model); | 122 model_ = model; |
121 [model_ addObserver:self]; | 123 [model_ addObserver:self]; |
122 historySideSwipeProvider_.reset( | 124 historySideSwipeProvider_ = |
123 [[HistorySideSwipeProvider alloc] initWithTabModel:model_]); | 125 [[HistorySideSwipeProvider alloc] initWithTabModel:model_]; |
124 | 126 |
125 readingListSideSwipeProvider_.reset([[ReadingListSideSwipeProvider alloc] | 127 readingListSideSwipeProvider_ = [[ReadingListSideSwipeProvider alloc] |
126 initWithReadingList:ReadingListModelFactory::GetForBrowserState( | 128 initWithReadingList:ReadingListModelFactory::GetForBrowserState( |
127 browserState)]); | 129 browserState)]; |
128 } | 130 } |
129 return self; | 131 return self; |
130 } | 132 } |
131 | 133 |
132 - (void)dealloc { | 134 - (void)dealloc { |
133 [model_ removeObserver:self]; | 135 [model_ removeObserver:self]; |
134 [super dealloc]; | |
135 } | 136 } |
136 | 137 |
137 - (void)addHorizontalGesturesToView:(UIView*)view { | 138 - (void)addHorizontalGesturesToView:(UIView*)view { |
138 swipeGestureRecognizer_.reset([[SideSwipeGestureRecognizer alloc] | 139 swipeGestureRecognizer_ = [[SideSwipeGestureRecognizer alloc] |
139 initWithTarget:self | 140 initWithTarget:self |
140 action:@selector(handleSwipe:)]); | 141 action:@selector(handleSwipe:)]; |
141 [swipeGestureRecognizer_ setMaximumNumberOfTouches:1]; | 142 [swipeGestureRecognizer_ setMaximumNumberOfTouches:1]; |
142 [swipeGestureRecognizer_ setDelegate:self]; | 143 [swipeGestureRecognizer_ setDelegate:self]; |
143 [swipeGestureRecognizer_ setSwipeEdge:kSwipeEdge]; | 144 [swipeGestureRecognizer_ setSwipeEdge:kSwipeEdge]; |
144 [view addGestureRecognizer:swipeGestureRecognizer_]; | 145 [view addGestureRecognizer:swipeGestureRecognizer_]; |
145 | 146 |
146 // Add a second gesture recognizer to handle swiping on the toolbar to change | 147 // Add a second gesture recognizer to handle swiping on the toolbar to change |
147 // tabs. | 148 // tabs. |
148 panGestureRecognizer_.reset([[SideSwipeGestureRecognizer alloc] | 149 panGestureRecognizer_ = |
149 initWithTarget:self | 150 [[SideSwipeGestureRecognizer alloc] initWithTarget:self |
150 action:@selector(handlePan:)]); | 151 action:@selector(handlePan:)]; |
151 [panGestureRecognizer_ setMaximumNumberOfTouches:1]; | 152 [panGestureRecognizer_ setMaximumNumberOfTouches:1]; |
152 [panGestureRecognizer_ setSwipeThreshold:48]; | 153 [panGestureRecognizer_ setSwipeThreshold:48]; |
153 [panGestureRecognizer_ setDelegate:self]; | 154 [panGestureRecognizer_ setDelegate:self]; |
154 [view addGestureRecognizer:panGestureRecognizer_]; | 155 [view addGestureRecognizer:panGestureRecognizer_]; |
155 } | 156 } |
156 | 157 |
157 - (NSSet*)swipeRecognizers { | 158 - (NSSet*)swipeRecognizers { |
158 return [NSSet setWithObjects:swipeGestureRecognizer_.get(), nil]; | 159 return [NSSet setWithObjects:swipeGestureRecognizer_, nil]; |
159 } | 160 } |
160 | 161 |
161 - (void)setEnabled:(BOOL)enabled { | 162 - (void)setEnabled:(BOOL)enabled { |
162 [swipeGestureRecognizer_ setEnabled:enabled]; | 163 [swipeGestureRecognizer_ setEnabled:enabled]; |
163 } | 164 } |
164 | 165 |
165 - (BOOL)shouldAutorotate { | 166 - (BOOL)shouldAutorotate { |
166 return !([tabSideSwipeView_ window] || inSwipe_); | 167 return !([tabSideSwipeView_ window] || inSwipe_); |
167 } | 168 } |
168 | 169 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 if (index == (NSInteger)startingTabIndex_) | 246 if (index == (NSInteger)startingTabIndex_) |
246 break; | 247 break; |
247 | 248 |
248 Tab* tab = [model_ tabAtIndex:index]; | 249 Tab* tab = [model_ tabAtIndex:index]; |
249 if (tab && tab.webController.usePlaceholderOverlay) { | 250 if (tab && tab.webController.usePlaceholderOverlay) { |
250 [sessionIDs addObject:tab.tabId]; | 251 [sessionIDs addObject:tab.tabId]; |
251 } | 252 } |
252 index = index + dx; | 253 index = index + dx; |
253 } | 254 } |
254 [[SnapshotCache sharedInstance] createGreyCache:sessionIDs]; | 255 [[SnapshotCache sharedInstance] createGreyCache:sessionIDs]; |
255 for (Tab* tab in model_.get()) { | 256 for (Tab* tab in model_) { |
256 tab.useGreyImageCache = YES; | 257 tab.useGreyImageCache = YES; |
257 } | 258 } |
258 } | 259 } |
259 | 260 |
260 - (void)deleteGreyCache { | 261 - (void)deleteGreyCache { |
261 [[SnapshotCache sharedInstance] removeGreyCache]; | 262 [[SnapshotCache sharedInstance] removeGreyCache]; |
262 for (Tab* tab in model_.get()) { | 263 for (Tab* tab in model_) { |
263 tab.useGreyImageCache = NO; | 264 tab.useGreyImageCache = NO; |
264 } | 265 } |
265 } | 266 } |
266 | 267 |
267 - (void)handlePan:(SideSwipeGestureRecognizer*)gesture { | 268 - (void)handlePan:(SideSwipeGestureRecognizer*)gesture { |
268 if (!IsIPadIdiom()) { | 269 if (!IsIPadIdiom()) { |
269 return [self handleiPhoneTabSwipe:gesture]; | 270 return [self handleiPhoneTabSwipe:gesture]; |
270 } else { | 271 } else { |
271 return [self handleiPadTabSwipe:gesture]; | 272 return [self handleiPadTabSwipe:gesture]; |
272 } | 273 } |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 // Show swipe to navigate. | 379 // Show swipe to navigate. |
379 - (void)handleSwipeToNavigate:(SideSwipeGestureRecognizer*)gesture { | 380 - (void)handleSwipeToNavigate:(SideSwipeGestureRecognizer*)gesture { |
380 if (gesture.state == UIGestureRecognizerStateBegan) { | 381 if (gesture.state == UIGestureRecognizerStateBegan) { |
381 // If the toolbar is hidden, move it to visible. | 382 // If the toolbar is hidden, move it to visible. |
382 [[model_ currentTab] updateFullscreenWithToolbarVisible:YES]; | 383 [[model_ currentTab] updateFullscreenWithToolbarVisible:YES]; |
383 | 384 |
384 inSwipe_ = YES; | 385 inSwipe_ = YES; |
385 [swipeDelegate_ updateAccessoryViewsForSideSwipeWithVisibility:NO]; | 386 [swipeDelegate_ updateAccessoryViewsForSideSwipeWithVisibility:NO]; |
386 BOOL goBack = IsSwipingBack(gesture.direction); | 387 BOOL goBack = IsSwipingBack(gesture.direction); |
387 | 388 |
388 currentContentProvider_.reset([self contentProviderForGesture:goBack]); | 389 currentContentProvider_ = [self contentProviderForGesture:goBack]; |
389 BOOL canNavigate = currentContentProvider_ != nil; | 390 BOOL canNavigate = currentContentProvider_ != nil; |
390 | 391 |
391 CGRect gestureBounds = gesture.view.bounds; | 392 CGRect gestureBounds = gesture.view.bounds; |
392 CGFloat headerHeight = [swipeDelegate_ headerHeight]; | 393 CGFloat headerHeight = [swipeDelegate_ headerHeight]; |
393 CGRect navigationFrame = | 394 CGRect navigationFrame = |
394 CGRectMake(CGRectGetMinX(gestureBounds), | 395 CGRectMake(CGRectGetMinX(gestureBounds), |
395 CGRectGetMinY(gestureBounds) + headerHeight, | 396 CGRectGetMinY(gestureBounds) + headerHeight, |
396 CGRectGetWidth(gestureBounds), | 397 CGRectGetWidth(gestureBounds), |
397 CGRectGetHeight(gestureBounds) - headerHeight); | 398 CGRectGetHeight(gestureBounds) - headerHeight); |
398 | 399 |
399 pageSideSwipeView_.reset([[SideSwipeNavigationView alloc] | 400 pageSideSwipeView_ = [[SideSwipeNavigationView alloc] |
400 initWithFrame:navigationFrame | 401 initWithFrame:navigationFrame |
401 withDirection:gesture.direction | 402 withDirection:gesture.direction |
402 canNavigate:canNavigate | 403 canNavigate:canNavigate |
403 image:[currentContentProvider_ paneIcon] | 404 image:[currentContentProvider_ paneIcon] |
404 rotateForward:[currentContentProvider_ rotateForwardIcon]]); | 405 rotateForward:[currentContentProvider_ rotateForwardIcon]]; |
405 [pageSideSwipeView_ setTargetView:[swipeDelegate_ contentView]]; | 406 [pageSideSwipeView_ setTargetView:[swipeDelegate_ contentView]]; |
406 | 407 |
407 [gesture.view insertSubview:pageSideSwipeView_ | 408 [gesture.view insertSubview:pageSideSwipeView_ |
408 belowSubview:[[swipeDelegate_ toolbarController] view]]; | 409 belowSubview:[[swipeDelegate_ toolbarController] view]]; |
409 } | 410 } |
410 | 411 |
411 base::WeakNSObject<Tab> weakCurrentTab([model_ currentTab]); | 412 __weak Tab* weakCurrentTab = [model_ currentTab]; |
412 [pageSideSwipeView_ handleHorizontalPan:gesture | 413 [pageSideSwipeView_ handleHorizontalPan:gesture |
413 onOverThresholdCompletion:^{ | 414 onOverThresholdCompletion:^{ |
414 BOOL wantsBack = IsSwipingBack(gesture.direction); | 415 BOOL wantsBack = IsSwipingBack(gesture.direction); |
415 web::WebState* webState = [weakCurrentTab webState]; | 416 web::WebState* webState = [weakCurrentTab webState]; |
416 if (wantsBack) { | 417 if (wantsBack) { |
417 [currentContentProvider_ goBack:webState]; | 418 [currentContentProvider_ goBack:webState]; |
418 } else { | 419 } else { |
419 [currentContentProvider_ goForward:webState]; | 420 [currentContentProvider_ goForward:webState]; |
420 } | 421 } |
421 | 422 |
(...skipping 25 matching lines...) Expand all Loading... |
447 CGRect frame = [[swipeDelegate_ contentView] frame]; | 448 CGRect frame = [[swipeDelegate_ contentView] frame]; |
448 | 449 |
449 // Add horizontal stack view controller. | 450 // Add horizontal stack view controller. |
450 CGFloat headerHeight = | 451 CGFloat headerHeight = |
451 [self.snapshotDelegate snapshotContentAreaForTab:[model_ currentTab]] | 452 [self.snapshotDelegate snapshotContentAreaForTab:[model_ currentTab]] |
452 .origin.y; | 453 .origin.y; |
453 if (tabSideSwipeView_) { | 454 if (tabSideSwipeView_) { |
454 [tabSideSwipeView_ setFrame:frame]; | 455 [tabSideSwipeView_ setFrame:frame]; |
455 [tabSideSwipeView_ setTopMargin:headerHeight]; | 456 [tabSideSwipeView_ setTopMargin:headerHeight]; |
456 } else { | 457 } else { |
457 tabSideSwipeView_.reset([[CardSideSwipeView alloc] | 458 tabSideSwipeView_ = [[CardSideSwipeView alloc] initWithFrame:frame |
458 initWithFrame:frame | 459 topMargin:headerHeight |
459 topMargin:headerHeight | 460 model:model_]; |
460 model:model_]); | |
461 [tabSideSwipeView_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | | 461 [tabSideSwipeView_ setAutoresizingMask:UIViewAutoresizingFlexibleWidth | |
462 UIViewAutoresizingFlexibleHeight]; | 462 UIViewAutoresizingFlexibleHeight]; |
463 [tabSideSwipeView_ setDelegate:swipeDelegate_]; | 463 [tabSideSwipeView_ setDelegate:swipeDelegate_]; |
464 [tabSideSwipeView_ setBackgroundColor:[UIColor blackColor]]; | 464 [tabSideSwipeView_ setBackgroundColor:[UIColor blackColor]]; |
465 } | 465 } |
466 | 466 |
467 // Ensure that there's an up-to-date snapshot of the current tab. | 467 // Ensure that there's an up-to-date snapshot of the current tab. |
468 [[model_ currentTab] updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; | 468 [[model_ currentTab] updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; |
469 // Hide the infobar after snapshot has been updated (see the previous line) | 469 // Hide the infobar after snapshot has been updated (see the previous line) |
470 // to avoid it obscuring the cards in the side swipe view. | 470 // to avoid it obscuring the cards in the side swipe view. |
(...skipping 12 matching lines...) Expand all Loading... |
483 | 483 |
484 // Remove content area so it doesn't receive any pan events. | 484 // Remove content area so it doesn't receive any pan events. |
485 [[swipeDelegate_ contentView] removeFromSuperview]; | 485 [[swipeDelegate_ contentView] removeFromSuperview]; |
486 } | 486 } |
487 | 487 |
488 [tabSideSwipeView_ handleHorizontalPan:gesture]; | 488 [tabSideSwipeView_ handleHorizontalPan:gesture]; |
489 } | 489 } |
490 | 490 |
491 - (void)addCurtainWithCompletionHandler:(ProceduralBlock)completionHandler { | 491 - (void)addCurtainWithCompletionHandler:(ProceduralBlock)completionHandler { |
492 if (!curtain_) { | 492 if (!curtain_) { |
493 curtain_.reset( | 493 curtain_ = |
494 [[UIView alloc] initWithFrame:[swipeDelegate_ contentView].bounds]); | 494 [[UIView alloc] initWithFrame:[swipeDelegate_ contentView].bounds]; |
495 [curtain_ setBackgroundColor:[UIColor whiteColor]]; | 495 [curtain_ setBackgroundColor:[UIColor whiteColor]]; |
496 } | 496 } |
497 [[swipeDelegate_ contentView] addSubview:curtain_]; | 497 [[swipeDelegate_ contentView] addSubview:curtain_]; |
498 | 498 |
499 // Fallback in case load takes a while. 3 seconds is a balance between how | 499 // Fallback in case load takes a while. 3 seconds is a balance between how |
500 // long it can take a web view to clear the previous page image, and what | 500 // long it can take a web view to clear the previous page image, and what |
501 // feels like to 'too long' to see the curtain. | 501 // feels like to 'too long' to see the curtain. |
502 [self performSelector:@selector(dismissCurtainWithCompletionHandler:) | 502 [self performSelector:@selector(dismissCurtainWithCompletionHandler:) |
503 withObject:[[completionHandler copy] autorelease] | 503 withObject:[completionHandler copy] |
504 afterDelay:3]; | 504 afterDelay:3]; |
505 } | 505 } |
506 | 506 |
507 - (void)resetContentView { | 507 - (void)resetContentView { |
508 CGRect frame = [swipeDelegate_ contentView].frame; | 508 CGRect frame = [swipeDelegate_ contentView].frame; |
509 frame.origin.x = 0; | 509 frame.origin.x = 0; |
510 [swipeDelegate_ contentView].frame = frame; | 510 [swipeDelegate_ contentView].frame = frame; |
511 } | 511 } |
512 | 512 |
513 - (void)dismissCurtainWithCompletionHandler:(ProceduralBlock)completionHandler { | 513 - (void)dismissCurtainWithCompletionHandler:(ProceduralBlock)completionHandler { |
514 [NSObject cancelPreviousPerformRequestsWithTarget:self]; | 514 [NSObject cancelPreviousPerformRequestsWithTarget:self]; |
515 webStateObserverBridge_.reset(); | 515 webStateObserverBridge_.reset(); |
516 [curtain_ removeFromSuperview]; | 516 [curtain_ removeFromSuperview]; |
517 curtain_.reset(); | 517 curtain_ = nil; |
518 completionHandler(); | 518 completionHandler(); |
519 } | 519 } |
520 | 520 |
521 #pragma mark - CRWWebStateObserver Methods | 521 #pragma mark - CRWWebStateObserver Methods |
522 | 522 |
523 - (void)webStateDidStopLoading:(web::WebState*)webState { | 523 - (void)webStateDidStopLoading:(web::WebState*)webState { |
524 [self dismissCurtainWithCompletionHandler:^{ | 524 [self dismissCurtainWithCompletionHandler:^{ |
525 inSwipe_ = NO; | 525 inSwipe_ = NO; |
526 }]; | 526 }]; |
527 } | 527 } |
528 | 528 |
529 #pragma mark - TabModelObserver Methods | 529 #pragma mark - TabModelObserver Methods |
530 | 530 |
531 - (void)tabModel:(TabModel*)model | 531 - (void)tabModel:(TabModel*)model |
532 didChangeActiveTab:(Tab*)newTab | 532 didChangeActiveTab:(Tab*)newTab |
533 previousTab:(Tab*)previousTab | 533 previousTab:(Tab*)previousTab |
534 atIndex:(NSUInteger)index { | 534 atIndex:(NSUInteger)index { |
535 // Toggling the gesture's enabled state off and on will effectively cancel | 535 // Toggling the gesture's enabled state off and on will effectively cancel |
536 // the gesture recognizer. | 536 // the gesture recognizer. |
537 [swipeGestureRecognizer_ setEnabled:NO]; | 537 [swipeGestureRecognizer_ setEnabled:NO]; |
538 [swipeGestureRecognizer_ setEnabled:YES]; | 538 [swipeGestureRecognizer_ setEnabled:YES]; |
539 } | 539 } |
540 | 540 |
541 @end | 541 @end |
OLD | NEW |