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/web/web_state/crw_web_view_proxy_impl.h" | 5 #import "ios/web/web_state/crw_web_view_proxy_impl.h" |
6 | 6 |
7 #include "base/ios/ios_util.h" | 7 #include "base/ios/ios_util.h" |
8 #include "base/ios/weak_nsobject.h" | |
9 #include "base/mac/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
10 #import "ios/web/public/web_state/crw_web_view_scroll_view_proxy.h" | 9 #import "ios/web/public/web_state/crw_web_view_scroll_view_proxy.h" |
11 #import "ios/web/public/web_state/ui/crw_content_view.h" | 10 #import "ios/web/public/web_state/ui/crw_content_view.h" |
12 #import "ios/web/web_state/ui/crw_web_controller.h" | 11 #import "ios/web/web_state/ui/crw_web_controller.h" |
13 | 12 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." |
| 15 #endif |
| 16 |
14 namespace { | 17 namespace { |
15 | 18 |
16 // Returns the first responder in the subviews of |view|, or nil if no view in | 19 // Returns the first responder in the subviews of |view|, or nil if no view in |
17 // the subtree is the first responder. | 20 // the subtree is the first responder. |
18 UIView* GetFirstResponderSubview(UIView* view) { | 21 UIView* GetFirstResponderSubview(UIView* view) { |
19 if ([view isFirstResponder]) | 22 if ([view isFirstResponder]) |
20 return view; | 23 return view; |
21 | 24 |
22 for (UIView* subview in [view subviews]) { | 25 for (UIView* subview in [view subviews]) { |
23 UIView* firstResponder = GetFirstResponderSubview(subview); | 26 UIView* firstResponder = GetFirstResponderSubview(subview); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 negativeInsets.top = -insets.top; | 62 negativeInsets.top = -insets.top; |
60 negativeInsets.left = -insets.left; | 63 negativeInsets.left = -insets.left; |
61 negativeInsets.bottom = -insets.bottom; | 64 negativeInsets.bottom = -insets.bottom; |
62 negativeInsets.right = -insets.right; | 65 negativeInsets.right = -insets.right; |
63 [self cr_addInsets:negativeInsets]; | 66 [self cr_addInsets:negativeInsets]; |
64 } | 67 } |
65 | 68 |
66 @end | 69 @end |
67 | 70 |
68 @implementation CRWWebViewProxyImpl { | 71 @implementation CRWWebViewProxyImpl { |
69 base::WeakNSObject<CRWContentView> _contentView; | 72 __weak CRWWebController* _webController; |
70 base::WeakNSObject<CRWWebController> _webController; | |
71 base::scoped_nsobject<NSMutableDictionary> _registeredInsets; | 73 base::scoped_nsobject<NSMutableDictionary> _registeredInsets; |
72 // The WebViewScrollViewProxy is a wrapper around the web view's | 74 // The WebViewScrollViewProxy is a wrapper around the web view's |
73 // UIScrollView to give components access in a limited and controlled manner. | 75 // UIScrollView to give components access in a limited and controlled manner. |
74 base::scoped_nsobject<CRWWebViewScrollViewProxy> _contentViewScrollViewProxy; | 76 base::scoped_nsobject<CRWWebViewScrollViewProxy> _contentViewScrollViewProxy; |
75 } | 77 } |
| 78 @synthesize contentView = _contentView; |
76 | 79 |
77 - (instancetype)initWithWebController:(CRWWebController*)webController { | 80 - (instancetype)initWithWebController:(CRWWebController*)webController { |
78 self = [super init]; | 81 self = [super init]; |
79 if (self) { | 82 if (self) { |
80 DCHECK(webController); | 83 DCHECK(webController); |
81 _registeredInsets.reset([[NSMutableDictionary alloc] init]); | 84 _registeredInsets.reset([[NSMutableDictionary alloc] init]); |
82 _webController.reset(webController); | 85 _webController = webController; |
83 _contentViewScrollViewProxy.reset([[CRWWebViewScrollViewProxy alloc] init]); | 86 _contentViewScrollViewProxy.reset([[CRWWebViewScrollViewProxy alloc] init]); |
84 } | 87 } |
85 return self; | 88 return self; |
86 } | 89 } |
87 | 90 |
88 - (CRWWebViewScrollViewProxy*)scrollViewProxy { | 91 - (CRWWebViewScrollViewProxy*)scrollViewProxy { |
89 return _contentViewScrollViewProxy.get(); | 92 return _contentViewScrollViewProxy.get(); |
90 } | 93 } |
91 | 94 |
92 - (CGRect)bounds { | 95 - (CGRect)bounds { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 forKey:callerValue]; | 142 forKey:callerValue]; |
140 } | 143 } |
141 | 144 |
142 - (void)unregisterInsetsForCaller:(id)caller { | 145 - (void)unregisterInsetsForCaller:(id)caller { |
143 NSValue* callerValue = [NSValue valueWithNonretainedObject:caller]; | 146 NSValue* callerValue = [NSValue valueWithNonretainedObject:caller]; |
144 NSValue* insetsValue = [_registeredInsets objectForKey:callerValue]; | 147 NSValue* insetsValue = [_registeredInsets objectForKey:callerValue]; |
145 [self.scrollViewProxy cr_removeInsets:[insetsValue UIEdgeInsetsValue]]; | 148 [self.scrollViewProxy cr_removeInsets:[insetsValue UIEdgeInsetsValue]]; |
146 [_registeredInsets removeObjectForKey:callerValue]; | 149 [_registeredInsets removeObjectForKey:callerValue]; |
147 } | 150 } |
148 | 151 |
149 - (CRWContentView*)contentView { | |
150 return _contentView.get(); | |
151 } | |
152 | |
153 - (void)setContentView:(CRWContentView*)contentView { | 152 - (void)setContentView:(CRWContentView*)contentView { |
154 _contentView.reset(contentView); | 153 _contentView = contentView; |
155 [_contentViewScrollViewProxy setScrollView:contentView.scrollView]; | 154 [_contentViewScrollViewProxy setScrollView:contentView.scrollView]; |
156 } | 155 } |
157 | 156 |
158 - (void)addSubview:(UIView*)view { | 157 - (void)addSubview:(UIView*)view { |
159 return [_contentView addSubview:view]; | 158 return [_contentView addSubview:view]; |
160 } | 159 } |
161 | 160 |
162 - (BOOL)hasSearchableTextContent { | 161 - (BOOL)hasSearchableTextContent { |
163 return _contentView != nil && [_webController contentIsHTML]; | 162 return _contentView != nil && [_webController contentIsHTML]; |
164 } | 163 } |
(...skipping 14 matching lines...) Expand all Loading... |
179 UIView* firstResponder = GetFirstResponderSubview(_contentView); | 178 UIView* firstResponder = GetFirstResponderSubview(_contentView); |
180 return firstResponder.inputAssistantItem; | 179 return firstResponder.inputAssistantItem; |
181 } | 180 } |
182 #endif | 181 #endif |
183 | 182 |
184 - (BOOL)becomeFirstResponder { | 183 - (BOOL)becomeFirstResponder { |
185 return [_contentView becomeFirstResponder]; | 184 return [_contentView becomeFirstResponder]; |
186 } | 185 } |
187 | 186 |
188 @end | 187 @end |
OLD | NEW |