OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/fullscreen_controller.h" | 5 #import "ios/chrome/browser/ui/fullscreen_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/mac/objc_property_releaser.h" | 10 |
11 #import "ios/chrome/browser/ui/browser_view_controller.h" | 11 #import "ios/chrome/browser/ui/browser_view_controller.h" |
12 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.
h" | 12 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.
h" |
13 #import "ios/chrome/browser/ui/tabs/tab_strip_controller.h" | 13 #import "ios/chrome/browser/ui/tabs/tab_strip_controller.h" |
14 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" | 14 #import "ios/chrome/browser/ui/toolbar/toolbar_controller.h" |
15 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" | 15 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" |
16 #import "ios/chrome/browser/ui/voice/voice_search_notification_names.h" | 16 #import "ios/chrome/browser/ui/voice/voice_search_notification_names.h" |
17 #include "ios/web/public/navigation_item.h" | 17 #include "ios/web/public/navigation_item.h" |
18 #import "ios/web/public/navigation_manager.h" | 18 #import "ios/web/public/navigation_manager.h" |
19 #include "ios/web/public/ssl_status.h" | 19 #include "ios/web/public/ssl_status.h" |
20 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h" | 20 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h" |
21 #import "ios/web/web_state/ui/crw_web_controller.h" | 21 #import "ios/web/web_state/ui/crw_web_controller.h" |
22 | 22 |
| 23 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 24 #error "This file requires ARC support." |
| 25 #endif |
| 26 |
23 NSString* const kSetupForTestingWillCloseAllTabsNotification = | 27 NSString* const kSetupForTestingWillCloseAllTabsNotification = |
24 @"kSetupForTestingWillCloseAllTabsNotification"; | 28 @"kSetupForTestingWillCloseAllTabsNotification"; |
25 | 29 |
26 using web::NavigationManager; | 30 using web::NavigationManager; |
27 | 31 |
28 namespace { | 32 namespace { |
29 | 33 |
30 class ScopedIncrementer { | 34 class ScopedIncrementer { |
31 public: | 35 public: |
32 explicit ScopedIncrementer(int* value) : value_(value) { ++(*value_); } | 36 explicit ScopedIncrementer(int* value) : value_(value) { ++(*value_); } |
(...skipping 27 matching lines...) Expand all Loading... |
60 // Used to detect if the keyboard is visible. | 64 // Used to detect if the keyboard is visible. |
61 BOOL keyboardIsVisible_; | 65 BOOL keyboardIsVisible_; |
62 // Used to detect that the OverscrollActionsController is displaying its UI. | 66 // Used to detect that the OverscrollActionsController is displaying its UI. |
63 // The FullScreenController is disabled when the OverscrollActionsController's | 67 // The FullScreenController is disabled when the OverscrollActionsController's |
64 // UI is displayed. | 68 // UI is displayed. |
65 BOOL overscrollActionsInProgress_; | 69 BOOL overscrollActionsInProgress_; |
66 // Counter used to keep track of the number of actions currently disabling | 70 // Counter used to keep track of the number of actions currently disabling |
67 // full screen. | 71 // full screen. |
68 uint fullScreenLock_; | 72 uint fullScreenLock_; |
69 // CRWWebViewProxy object allows web view manipulations. | 73 // CRWWebViewProxy object allows web view manipulations. |
70 base::scoped_nsprotocol<id<CRWWebViewProxy>> webViewProxy_; | 74 id<CRWWebViewProxy> webViewProxy_; |
71 base::mac::ObjCPropertyReleaser propertyReleaser_FullScreenController_; | |
72 } | 75 } |
73 | 76 |
74 // Access to the UIWebView's UIScrollView. | 77 // Access to the UIWebView's UIScrollView. |
75 @property(nonatomic, readonly) CRWWebViewScrollViewProxy* scrollViewProxy; | 78 @property(weak, nonatomic, readonly) CRWWebViewScrollViewProxy* scrollViewProxy; |
76 // The navigation controller of the page. | 79 // The navigation controller of the page. |
77 @property(nonatomic, readonly, assign) NavigationManager* navigationManager; | 80 @property(nonatomic, readonly, assign) NavigationManager* navigationManager; |
78 // The gesture recognizer set on the scrollview to detect tap. Must be readwrite | 81 // The gesture recognizer set on the scrollview to detect tap. Must be readwrite |
79 // for property releaser to work. | 82 // for property releaser to work. |
80 @property(nonatomic, readwrite, retain) | 83 @property(nonatomic, readwrite, strong) |
81 UITapGestureRecognizer* userInteractionGestureRecognizer; | 84 UITapGestureRecognizer* userInteractionGestureRecognizer; |
82 // The delegate responsible for providing the header height and moving the | 85 // The delegate responsible for providing the header height and moving the |
83 // header. | 86 // header. |
84 @property(nonatomic, readonly) id<FullScreenControllerDelegate> delegate; | 87 @property(weak, nonatomic, readonly) id<FullScreenControllerDelegate> delegate; |
85 // Current height of the header, in points. This is a pass-through method that | 88 // Current height of the header, in points. This is a pass-through method that |
86 // fetches the header height from the FullScreenControllerDelegate. | 89 // fetches the header height from the FullScreenControllerDelegate. |
87 @property(nonatomic, readonly) CGFloat headerHeight; | 90 @property(nonatomic, readonly) CGFloat headerHeight; |
88 // |top| field of UIScrollView.contentInset value caused by header. | 91 // |top| field of UIScrollView.contentInset value caused by header. |
89 // Always 0 for WKWebView, as it does not support contentInset. | 92 // Always 0 for WKWebView, as it does not support contentInset. |
90 @property(nonatomic, readonly) CGFloat topContentInsetCausedByHeader; | 93 @property(nonatomic, readonly) CGFloat topContentInsetCausedByHeader; |
91 // Last known y offset of the content in the scroll view during a scroll. Used | 94 // Last known y offset of the content in the scroll view during a scroll. Used |
92 // to infer the direction of the current scroll. | 95 // to infer the direction of the current scroll. |
93 @property(nonatomic, assign) CGFloat previousContentOffset; | 96 @property(nonatomic, assign) CGFloat previousContentOffset; |
94 // Last known y offset requested on the scroll view. In general the same value | 97 // Last known y offset requested on the scroll view. In general the same value |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 @synthesize isFullScreenDisabledForLoading = isFullScreenDisabledForLoading_; | 186 @synthesize isFullScreenDisabledForLoading = isFullScreenDisabledForLoading_; |
184 @synthesize skipNextScrollOffsetForHeader = skipNextScrollOffsetForHeader_; | 187 @synthesize skipNextScrollOffsetForHeader = skipNextScrollOffsetForHeader_; |
185 @synthesize delayedHideHeaderCount = delayedHideHeaderCount_; | 188 @synthesize delayedHideHeaderCount = delayedHideHeaderCount_; |
186 @synthesize sessionID = sessionID_; | 189 @synthesize sessionID = sessionID_; |
187 @synthesize userInteractionGestureRecognizer = | 190 @synthesize userInteractionGestureRecognizer = |
188 userInteractionGestureRecognizer_; | 191 userInteractionGestureRecognizer_; |
189 | 192 |
190 - (id)initWithDelegate:(id<FullScreenControllerDelegate>)delegate | 193 - (id)initWithDelegate:(id<FullScreenControllerDelegate>)delegate |
191 navigationManager:(NavigationManager*)navigationManager | 194 navigationManager:(NavigationManager*)navigationManager |
192 sessionID:(NSString*)sessionID { | 195 sessionID:(NSString*)sessionID { |
193 if (!gEnabledForTests) { | 196 if (!gEnabledForTests) |
194 propertyReleaser_FullScreenController_.Init(self, | |
195 [FullScreenController class]); | |
196 [self release]; | |
197 return nil; | 197 return nil; |
198 } | |
199 if ((self = [super init])) { | 198 if ((self = [super init])) { |
200 propertyReleaser_FullScreenController_.Init(self, | |
201 [FullScreenController class]); | |
202 DCHECK(sessionID); | 199 DCHECK(sessionID); |
203 DCHECK(delegate); | 200 DCHECK(delegate); |
204 delegate_ = delegate; | 201 delegate_ = delegate; |
205 sessionID_ = [sessionID copy]; | 202 sessionID_ = [sessionID copy]; |
206 navigationManager_ = navigationManager; | 203 navigationManager_ = navigationManager; |
207 | 204 |
208 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 205 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
209 [center addObserver:self | 206 [center addObserver:self |
210 selector:@selector(keyboardStart:) | 207 selector:@selector(keyboardStart:) |
211 name:UIKeyboardWillShowNotification | 208 name:UIKeyboardWillShowNotification |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 306 |
310 - (void)invalidate { | 307 - (void)invalidate { |
311 delegate_ = nil; | 308 delegate_ = nil; |
312 navigationManager_ = NULL; | 309 navigationManager_ = NULL; |
313 [self.scrollViewProxy removeObserver:self]; | 310 [self.scrollViewProxy removeObserver:self]; |
314 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 311 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
315 } | 312 } |
316 | 313 |
317 - (void)dealloc { | 314 - (void)dealloc { |
318 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 315 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
319 [super dealloc]; | |
320 } | 316 } |
321 | 317 |
322 - (CRWWebViewScrollViewProxy*)scrollViewProxy { | 318 - (CRWWebViewScrollViewProxy*)scrollViewProxy { |
323 return [webViewProxy_ scrollViewProxy]; | 319 return [webViewProxy_ scrollViewProxy]; |
324 } | 320 } |
325 | 321 |
326 - (CGFloat)headerHeight { | 322 - (CGFloat)headerHeight { |
327 return [self.delegate headerHeight]; | 323 return [self.delegate headerHeight]; |
328 } | 324 } |
329 | 325 |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 | 689 |
694 [self setContentViewTopContentPadding:topInset]; | 690 [self setContentViewTopContentPadding:topInset]; |
695 } | 691 } |
696 | 692 |
697 #pragma mark - | 693 #pragma mark - |
698 #pragma mark CRWWebControllerObserver methods | 694 #pragma mark CRWWebControllerObserver methods |
699 | 695 |
700 - (void)setWebViewProxy:(id<CRWWebViewProxy>)webViewProxy | 696 - (void)setWebViewProxy:(id<CRWWebViewProxy>)webViewProxy |
701 controller:(CRWWebController*)webController { | 697 controller:(CRWWebController*)webController { |
702 DCHECK([webViewProxy scrollViewProxy]); | 698 DCHECK([webViewProxy scrollViewProxy]); |
703 webViewProxy_.reset([webViewProxy retain]); | 699 webViewProxy_ = webViewProxy; |
704 [[webViewProxy scrollViewProxy] addObserver:self]; | 700 [[webViewProxy scrollViewProxy] addObserver:self]; |
705 } | 701 } |
706 | 702 |
707 - (void)pageLoaded:(CRWWebController*)webController { | 703 - (void)pageLoaded:(CRWWebController*)webController { |
708 [self enableFullScreen]; | 704 [self enableFullScreen]; |
709 web::WebState* webState = webController.webState; | 705 web::WebState* webState = webController.webState; |
710 if (webState) { | 706 if (webState) { |
711 BOOL MIMETypeIsPDF = webState->GetContentsMimeType() == "application/pdf"; | 707 BOOL MIMETypeIsPDF = webState->GetContentsMimeType() == "application/pdf"; |
712 [webViewProxy_ setShouldUseInsetForTopPadding:MIMETypeIsPDF]; | 708 [webViewProxy_ setShouldUseInsetForTopPadding:MIMETypeIsPDF]; |
713 } | 709 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 overscrollActionsInProgress_ = NO; | 809 overscrollActionsInProgress_ = NO; |
814 } | 810 } |
815 | 811 |
816 #pragma mark - Used for testing | 812 #pragma mark - Used for testing |
817 | 813 |
818 + (void)setEnabledForTests:(BOOL)enabled { | 814 + (void)setEnabledForTests:(BOOL)enabled { |
819 gEnabledForTests = enabled; | 815 gEnabledForTests = enabled; |
820 } | 816 } |
821 | 817 |
822 @end | 818 @end |
OLD | NEW |