UIWebView体系结构(四)UIWebBrowserView

UIWebBrowserView的声明如下:(代码好长,点此跳过)

[cpp]  view plain copy
  1. @interface UIWebBrowserView : UIWebDocumentView <UIWebFormAccessoryDelegate, UIBrowserDocumentController, _UIWebRotationDelegate>  
  2. {  
  3.     UIWebFormAccessory *_accessory;  
  4.     NSObject<UIFormPeripheral> *_input;  
  5.     DOMNode *_currentAssistedNode;  
  6.     DOMNode *_assistedNodeStartingFocusRedirects;  
  7.     struct CGRect _inputViewBounds;  
  8.     struct CGRect _addressViewBounds;  
  9.     float _lastAdjustmentForScroller;  
  10.     unsigned int _audioSessionCategoryOverride;  
  11.     unsigned int _accessoryEnabled:1;  
  12.     unsigned int _forceInputView:1;  
  13.     unsigned int _formIsAutoFilling:1;  
  14.     unsigned int _inputViewObeysDOMFocus:1;  
  15.     unsigned int _allowDOMFocusRedirects:1;  
  16.     unsigned int _hasEditedTextField:1;  
  17.     unsigned int _alwaysDispatchesScrollEvents:1;  
  18.     UIWebTouchEventsGestureRecognizer *_webTouchEventsGestureRecognizer;  
  19.     UIWebFormDelegate *_formDelegate;  
  20.     UIResponder *_editingDelegateForEverythingExceptForms;  
  21.     unsigned int _dispatchedTouchEvents;  
  22.     NSMutableArray *_deferredTouchEvents;  
  23.     struct {  
  24.         NSMutableArray *all;  
  25.         NSMutableArray *html;  
  26.         NSMutableArray *javascript;  
  27.         NSMutableArray *css;  
  28.         NSMutableArray *error;  
  29.         NSMutableArray *warning;  
  30.         NSMutableArray *tip;  
  31.         NSMutableArray *log;  
  32.     } _messages;  
  33.     CDStruct_d58a15aa _pdf;  
  34. }  
  35.   
  36. + (id)_PDFPageNumberLabel:(BOOL)arg1;  
  37. + (BOOL)isAutoFillAllowed;  
  38. + (id)getUIWebBrowserViewForWebFrame:(id)arg1;  
  39. + (float)preferredScrollDecelerationFactor;  
  40. @property(readonly, nonatomic) BOOL hasEditedTextField; // @synthesize hasEditedTextField=_hasEditedTextField;  
  41. @property(nonatomic) BOOL allowDOMFocusRedirects; // @synthesize allowDOMFocusRedirects=_allowDOMFocusRedirects;  
  42. @property(nonatomic) BOOL inputViewObeysDOMFocus; // @synthesize inputViewObeysDOMFocus=_inputViewObeysDOMFocus;  
  43. @property(nonatomic, getter=isAccessoryEnabled) BOOL accessoryEnabled; // @synthesize accessoryEnabled=_accessoryEnabled;  
  44. @property(nonatomic) UIResponder *_editingDelegateForEverythingExceptForms; // @synthesize _editingDelegateForEverythingExceptForms;  
  45. @property(retain, nonatomic) DOMNode *_currentAssistedNode; // @synthesize _currentAssistedNode;  
  46. @property(retain, nonatomic) NSObject<UIFormPeripheral> *_input; // @synthesize _input;  
  47. @property(retain, nonatomic) UIWebFormAccessory *_accessory; // @synthesize _accessory;  
  48. - (BOOL)considerHeightOfRectOfInterestForRotation;  
  49. - (struct CGSize)contentSizeForScrollView:(id)arg1;  
  50. - (float)scaleForProposedNewScale:(float)arg1 andOldScale:(float)arg2;  
  51. - (struct CGRect)activeRectForRectOfInterest:(struct CGRect)arg1;  
  52. - (float)heightToKeepVisible;  
  53. - (float)minimumVerticalContentOffset;  
  54. - (struct CGRect)rectOfInterestForRotation;  
  55. - (void)updateBoundariesOfScrollView:(id)arg1 withScales:(CDStruct_869f9c67)arg2;  
  56. - (CDStruct_869f9c67)scalesForContainerSize:(struct CGSize)arg1;  
  57. @property(nonatomic) BOOL alwaysDispatchesScrollEvents;  
  58. - (void)webView:(id)arg1 didFirstVisuallyNonEmptyLayoutInFrame:(id)arg2;  
  59. - (id)_absoluteUrlRelativeToDocumentURL:(id)arg1;  
  60. - (void)_startURLificationIfNeededCoalesce:(BOOL)arg1;  
  61. - (void)_setSelectedDOMRangeAndUpdateUI:(id)arg1;  
  62. - (void)_clearSelectionAndUI;  
  63. - (BOOL)_dumpWebArchiveAtPath:(id)arg1;  
  64. - (void)_updatePDFPageNumberLabelWithUserScrolling:(BOOL)arg1 animated:(BOOL)arg2;  
  65. - (struct CGPoint)_originForPDFPageLabelInSuperview:(id)arg1;  
  66. - (unsigned int)_firstVisiblePDFPageNumber;  
  67. - (void)_clearAllConsoleMessages;  
  68. - (void)clearMessagesMatchingMask:(int)arg1;  
  69. - (id)messagesMatchingMask:(int)arg1;  
  70. - (void)webView:(id)arg1 addMessageToConsole:(id)arg2 withSource:(id)arg3;  
  71. - (void)_setAddressViewFrame:(struct CGRect)arg1;  
  72. - (void)rotateEnclosingScrollViewToFrame:(struct CGRect)arg1;  
  73. - (struct CGSize)_defaultScrollViewContentSize;  
  74. - (void)_zoomToRect:(struct CGRect)arg1 withScale:(float)arg2;  
  75. - (void)_zoomToRect:(struct CGRect)arg1 ensuringVisibilityOfRect:(struct CGRect)arg2 withScale:(float)arg3 forceScroll:(BOOL)arg4 formAssistantFrame:(struct CGRect)arg5 animationDuration:(double)arg6;  
  76. - (void)_zoomToRect:(struct CGRect)arg1 ensuringVisibilityOfRect:(struct CGRect)arg2 withScale:(float)arg3 forceScroll:(BOOL)arg4;  
  77. - (void)_zoomToNode:(id)arg1 forceScroll:(BOOL)arg2;  
  78. - (void)_centerRect:(struct CGRect)arg1 forSizeChange:(BOOL)arg2 withVisibleHeight:(float)arg3 pinningEdge:(int)arg4;  
  79. - (void)_centerRect:(struct CGRect)arg1 forSizeChange:(BOOL)arg2 withVisibleHeight:(float)arg3 pinningEdge:(int)arg4 toValue:(float)arg5;  
  80. - (struct CGRect)_activeRectForRectToCenter:(struct CGRect)arg1;  
  81. - (void)webViewDidPreventDefaultForEvent:(id)arg1;  
  82. - (struct CGPoint)_convertWindowPointToViewport:(struct CGPoint)arg1;  
  83. @property(readonly, nonatomic) BOOL isDispatchingTouchEvents;  
  84. - (void)_webTouchEventsRecognized:(id)arg1;  
  85. - (void)_handleDeferredEvents;  
  86. - (void)_deferWebEvent:(id)arg1;  
  87. - (void)_endDeferringEvents;  
  88. - (void)_startDeferringEvents;  
  89. - (void)_dispatchWebEvent:(id)arg1;  
  90. - (BOOL)_shouldDeferEvents;  
  91. - (void)webView:(id)arg1 elementDidBlurNode:(id)arg2;  
  92. - (void)webView:(id)arg1 elementDidFocusNode:(id)arg2;  
  93. - (void)webViewFormEditedStatusHasChanged:(id)arg1;  
  94. - (BOOL)isAutoFilling;  
  95. - (BOOL)isAutoFillMode;  
  96. - (void)autoFillWithElementValue;  
  97. - (void)acceptedAutoFillWord:(id)arg1;  
  98. - (void)webView:(id)arg1 didFirstLayoutInFrame:(id)arg2;  
  99. - (void)webView:(id)arg1 didFailLoadWithError:(id)arg2 forFrame:(id)arg3;  
  100. - (void)webView:(id)arg1 didFinishLoadForFrame:(id)arg2;  
  101. - (void)webView:(id)arg1 didStartProvisionalLoadForFrame:(id)arg2;  
  102. - (void)webView:(id)arg1 willCloseFrame:(id)arg2;  
  103. - (void)_autoFillFrame:(id)arg1;  
  104. - (void)_resetFormDataForFrame:(id)arg1;  
  105. - (id)textFormElement;  
  106. - (id)formElement;  
  107. - (BOOL)canAutoFill;  
  108. - (void)formDelegateHandleTextChangeWithAutoFillSuggestions:(BOOL)arg1;  
  109. - (void)_scrollCaretToVisible:(id)arg1;  
  110. - (void)accessoryClear;  
  111. - (void)accessoryAutoFill;  
  112. - (void)accessoryTab:(BOOL)arg1;  
  113. - (void)accessoryDone;  
  114. @property(nonatomic) unsigned int audioSessionCategoryOverride;  
  115. @property(nonatomic) BOOL mediaPlaybackRequiresUserAction;  
  116. @property(nonatomic) BOOL allowsInlineMediaPlayback;  
  117. - (void)assistFormNode:(id)arg1;  
  118. - (void)_endAllowingFocusRedirects;  
  119. - (void)_beginAllowingFocusRedirects;  
  120. - (void)_updateAccessory;  
  121. - (void)_displayFormNodeInputView;  
  122. - (void)_stopAssistingFormNode;  
  123. - (void)setBounds:(struct CGRect)arg1;  
  124. - (void)setFrame:(struct CGRect)arg1;  
  125. - (void)_didScroll;  
  126. - (void)_updateScrollerViewForInputView:(id)arg1;  
  127. - (void)_updateFixedPositioningObjectsLayoutSoon;  
  128. - (void)_updateFixedPositionContent;  
  129. - (void)_updateFixedPositioningObjectsLayoutAfterVisibleGeometryChange;  
  130. - (void)_updateFixedPositioningObjectsLayoutAfterScroll;  
  131. - (void)_keyboardWillHide:(id)arg1;  
  132. - (void)_keyboardWillShow:(id)arg1;  
  133. - (void)_keyboardDidChangeFrame:(id)arg1;  
  134. - (void)_keyboardWillChangeFrame:(id)arg1;  
  135. - (void)_setInputViewBoundsForAutomaticKeyboardInfo:(id)arg1 adjustScrollView:(BOOL)arg2;  
  136. - (void)_stopAssistingNode:(id)arg1;  
  137. - (void)_startAssistingNode:(id)arg1;  
  138. - (void)_stopAssistingKeyboard;  
  139. - (void)_startAssistingKeyboard;  
  140. - (void)_promptForReplace:(id)arg1;  
  141. - (BOOL)playsNicelyWithGestures;  
  142. - (id)_editingDelegate;  
  143. - (void)copy:(id)arg1;  
  144. - (BOOL)canPerformAction:(SEL)arg1 withSender:(id)arg2;  
  145. - (id)inputView;  
  146. - (id)inputAccessoryView;  
  147. - (void)_handleKeyEvent:(struct __GSEvent *)arg1;  
  148. - (BOOL)resignFirstResponder;  
  149. - (id)textDocument;  
  150. - (id)_keyboardResponder;  
  151. - (BOOL)_requiresKeyboardResetOnReload;  
  152. - (BOOL)_requiresKeyboardWhenFirstResponder;  
  153. - (BOOL)_keepKeyboardVisibleDuringFocusRedirects;  
  154. - (BOOL)isEditable;  
  155. - (void)installGestureRecognizers;  
  156. - (void)dealloc;  
  157. - (id)initWithFrame:(struct CGRect)arg1;  
  158. - (id)initWithWebView:(id)arg1 frame:(struct CGRect)arg2;  
  159.   
  160. @end  

UIWebBrowserView并不算复杂,主要负责这些工作:

  • form的自动填充
  • fixed元素的位置调整
  • JavaScript的手势识别,参见《iOS私有API(三) UIWebView下的手势识别器gestureRecognizer》
  • 键盘弹出时的视图滚动处理,防止遮挡
  • 各种信息的中转,见_messages变量
  • 提供接口让UIWebView获取信息
  • 为显示PDF时添加页号标签

下面想探讨一下UIWebBrowserView->UIWebDocumentView->UIWebTiledView这样的设计。

从已掌握的信息看,他们的成员变量都是使用private继承,即子类无法直接访问父类的成员变量。他们之间的关系是子类操控父类,基类的职责不会牵涉和考虑到子类,分工非常明确。由于UIWebDocumentView直接管理WebView,它的职责是有部分属于Controller的行为,例如手势事件。但是UIWebBrowserView的JavaScript手势却完全不干涉UIWebDocumentView的手势,通过别的途径来获取更高优先级的处理权。

总之,通过继承来拆分一个大类,必须做到这样才是可行的,值得借鉴。要拆分大类通常会用组合,但这里就是不用组合的优秀例子。当然,这也要求继承链里不能有分支,即基类不会有多个子类。

你可能感兴趣的:(UIWebView体系结构(四)UIWebBrowserView)