标签:
下载了一份很久以前泄漏的IE5.0的源代码,虽然已经是很古远的版本了。但是通过调试现有版本浏览器与查看源代码,发现关键部分的差距并不是很大,代码很有参考意义。这里把重要的函数、数据结构摘抄出来以备参考。
1 class NOVTABLE CTreeNode : public CVoid 2 { 3 friend class CTreePos; 4 5 DECLARE_CLASS_TYPES(CTreeNode, CVoid) 6 7 public: 8 DECLARE_MEMCLEAR_NEW_DELETE(); 9 10 CTreeNode(CTreeNode* pParent, CElement* pElement=NULL); 11 12 // Use this to get an interface to the element/node 13 HRESULT GetElementInterface(REFIID riid, void** ppUnk); 14 15 // NOTE: these functions may look like IUnknown functions 16 // but don‘t make that mistake. They are here to 17 // manage creation of the tearoff to handle all 18 // external references. 19 // These functions should not be called! 20 NV_DECLARE_TEAROFF_METHOD(GetInterface, getinterface, (REFIID riid, LPVOID* ppv)); 21 NV_DECLARE_TEAROFF_METHOD_(ULONG, PutRef, putref, ()); 22 NV_DECLARE_TEAROFF_METHOD_(ULONG, RemoveRef, removeref, ()); 23 24 // These functions are to be used to keep a node/element 25 // combination alive while it may leave the tree. 26 // BEWARE: this may cause the creation of a tearoff. 27 ULONG NodeAddRef(); 28 ULONG NodeRelease(); 29 30 // These functions manage the _fInMarkup bit 31 void PrivateEnterTree(); 32 void PrivateExitTree(); 33 void PrivateMakeDead(); 34 void PrivateMarkupRelease(); 35 36 void SetElement(CElement* pElement); 37 void SetParent(CTreeNode* pNodeParent); 38 39 // Element access and structure methods 40 CElement* Element() { return _pElement; } 41 CElement* SafeElement() { return this?_pElement:NULL; } 42 43 CTreePos* GetBeginPos() { return &_tpBegin; } 44 CTreePos* GetEndPos() { return &_tpEnd; } 45 46 // Context chain access 47 BOOL IsFirstBranch() { return _tpBegin.IsEdgeScope(); } 48 BOOL IsLastBranch() { return _tpEnd.IsEdgeScope(); } 49 CTreeNode* NextBranch(); 50 CTreeNode* PreviousBranch(); 51 52 CDocument* Doc(); 53 54 BOOL IsInMarkup() { return _fInMarkup; } 55 BOOL IsDead() { return ! _fInMarkup; } 56 CRootElement* IsRoot(); 57 CMarkup* GetMarkup(); 58 CRootElement* MarkupRoot(); 59 60 // Does the element that this node points to have currency? 61 BOOL HasCurrency(); 62 63 BOOL IsContainer(); 64 CTreeNode* GetContainerBranch(); 65 CElement* GetContainer() { return GetContainerBranch()->SafeElement(); } 66 67 BOOL SupportsHtml(); 68 69 CTreeNode* Parent() { return _pNodeParent; } 70 71 CTreeNode* Ancestor(ELEMENT_TAG etag); 72 CTreeNode* Ancestor(ELEMENT_TAG* arytag); 73 74 CElement* ZParent() { return ZParentBranch()->SafeElement(); } 75 CTreeNode* ZParentBranch(); 76 77 CElement* RenderParent() { return RenderParentBranch()->SafeElement(); } 78 CTreeNode* RenderParentBranch(); 79 80 CElement* ClipParent() { return ClipParentBranch()->SafeElement(); } 81 CTreeNode* ClipParentBranch(); 82 83 CElement* ScrollingParent() { return ScrollingParentBranch()->SafeElement(); } 84 CTreeNode* ScrollingParentBranch(); 85 86 inline ELEMENT_TAG Tag() { return (ELEMENT_TAG)_etag; } 87 88 ELEMENT_TAG TagType() 89 { 90 switch(_etag) 91 { 92 case ETAG_GENERIC_LITERAL: 93 case ETAG_GENERIC_BUILTIN: 94 return ETAG_GENERIC; 95 default: 96 return (ELEMENT_TAG)_etag; 97 } 98 } 99 100 CTreeNode* GetFirstCommonAncestor(CTreeNode* pNode, CElement* pEltStop); 101 CTreeNode* GetFirstCommonBlockOrLayoutAncestor(CTreeNode* pNodeTwo, CElement* pEltStop); 102 CTreeNode* GetFirstCommonAncestorNode(CTreeNode* pNodeTwo, CElement* pEltStop); 103 104 CTreeNode* SearchBranchForPureBlockElement(CFlowLayout*); 105 CTreeNode* SearchBranchToFlowLayoutForTag(ELEMENT_TAG etag); 106 CTreeNode* SearchBranchToRootForTag(ELEMENT_TAG etag); 107 CTreeNode* SearchBranchToRootForScope(CElement* pElementFindMe); 108 BOOL SearchBranchToRootForNode(CTreeNode* pNodeFindMe); 109 110 CTreeNode* GetCurrentRelativeNode(CElement* pElementFL); 111 112 // The layout attached to the current element may not be accurate, when a 113 // property changes, current element can gain/lose layoutness. When an 114 // element gains/loses layoutness, its layout is created/destroyed lazily. 115 // 116 // So, for the following functions "cur" means return the layout currently 117 // associated with the layout which may not be accurate. "Updated" means 118 // compute the state and return the accurate information. 119 // 120 // Note: Calling "Updated" function may cause the formats to be computed. 121 // 122 // If there is any confusion please talk to (srinib/lylec/brendand) 123 inline CLayout* GetCurLayout(); 124 inline BOOL HasLayout(); 125 126 CLayout* GetCurNearestLayout(); 127 CTreeNode* GetCurNearestLayoutNode(); 128 CElement* GetCurNearestLayoutElement(); 129 130 CLayout* GetCurParentLayout(); 131 CTreeNode* GetCurParentLayoutNode(); 132 CElement* GetCurParentLayoutElement(); 133 134 // the following get functions may create the layout if it is not 135 // created yet. 136 inline CLayout* GetUpdatedLayout(); // checks for NeedsLayout() 137 inline CLayout* GetUpdatedLayoutPtr(); // Call this if NeedsLayout() is already called 138 inline BOOL NeedsLayout(); 139 140 CLayout* GetUpdatedNearestLayout(); 141 CTreeNode* GetUpdatedNearestLayoutNode(); 142 CElement* GetUpdatedNearestLayoutElement(); 143 144 CLayout* GetUpdatedParentLayout(); 145 CTreeNode* GetUpdatedParentLayoutNode(); 146 CElement* GetUpdatedParentLayoutElement(); 147 148 // BUGBUG - these functions should go, we should not need 149 // to know if the element has flowlayout. 150 CFlowLayout* GetFlowLayout(); 151 CTreeNode* GetFlowLayoutNode(); 152 CElement* GetFlowLayoutElement(); 153 CFlowLayout* HasFlowLayout(); 154 155 // Helper methods 156 htmlBlockAlign GetParagraphAlign(BOOL fOuter); 157 htmlControlAlign GetSiteAlign(); 158 159 BOOL IsInlinedElement(); 160 161 BOOL IsPositionStatic(void); 162 BOOL IsPositioned(void); 163 BOOL IsAbsolute(stylePosition st); 164 BOOL IsAbsolute(void); 165 166 BOOL IsAligned(); 167 168 // IsRelative() tells you if the specific element has had a CSS position 169 // property set on it ( by examining _fRelative and _bPositionType on the 170 // FF). It will NOT tell you if something is relative because one of its 171 // ancestors is relative; that information is stored in the CF, and can be 172 // had via IsInheritingRelativeness() 173 BOOL IsRelative(stylePosition st); 174 BOOL IsRelative(void); 175 BOOL IsInheritingRelativeness(void); 176 177 BOOL IsScrollingParent(void); 178 BOOL IsClipParent(void); 179 BOOL IsZParent(void); 180 BOOL IsDisplayNone(void); 181 BOOL IsVisibilityHidden(void); 182 183 // Depth is defined to be 1 plus the count of parents above this element 184 int Depth() const; 185 186 // Format info functions 187 HRESULT CacheNewFormats(CFormatInfo* pCFI); 188 189 void EnsureFormats(); 190 BOOL IsCharFormatValid() { return _iCF>=0; } 191 BOOL IsParaFormatValid() { return _iPF>=0; } 192 BOOL IsFancyFormatValid() { return _iFF>=0; } 193 const CCharFormat* GetCharFormat() { return (_iCF>=0 ? ::GetCharFormatEx(_iCF) : GetCharFormatHelper()); } 194 const CParaFormat* GetParaFormat() { return (_iPF>=0 ? ::GetParaFormatEx(_iPF) : GetParaFormatHelper()); } 195 const CFancyFormat* GetFancyFormat() { return (_iFF>=0 ? ::GetFancyFormatEx(_iFF) : GetFancyFormatHelper()); } 196 const CCharFormat* GetCharFormatHelper(); 197 const CParaFormat* GetParaFormatHelper(); 198 const CFancyFormat* GetFancyFormatHelper(); 199 long GetCharFormatIndex() { return (_iCF>=0 ? _iCF : GetCharFormatIndexHelper()); } 200 long GetParaFormatIndex() { return (_iPF>=0 ? _iPF : GetParaFormatIndexHelper()); } 201 long GetFancyFormatIndex() { return (_iFF>=0 ? _iFF : GetFancyFormatIndexHelper()); } 202 long GetCharFormatIndexHelper(); 203 long GetParaFormatIndexHelper(); 204 long GetFancyFormatIndexHelper(); 205 206 long GetFontHeightInTwips(CUnitValue* pCuv); 207 void GetRelTopLeft(CElement* pElementFL, CParentInfo* ppi, long* pxOffset, long* pyOffset); 208 209 // These GetCascaded methods are taken from style.hdl where they were 210 // originally generated by the PDL parser. 211 CColorValue GetCascadedbackgroundColor(); 212 CColorValue GetCascadedcolor(); 213 CUnitValue GetCascadedletterSpacing(); 214 styleTextTransform GetCascadedtextTransform(); 215 CUnitValue GetCascadedpaddingTop(); 216 CUnitValue GetCascadedpaddingRight(); 217 CUnitValue GetCascadedpaddingBottom(); 218 CUnitValue GetCascadedpaddingLeft(); 219 CColorValue GetCascadedborderTopColor(); 220 CColorValue GetCascadedborderRightColor(); 221 CColorValue GetCascadedborderBottomColor(); 222 CColorValue GetCascadedborderLeftColor(); 223 styleBorderStyle GetCascadedborderTopStyle(); 224 styleBorderStyle GetCascadedborderRightStyle(); 225 styleBorderStyle GetCascadedborderBottomStyle(); 226 styleBorderStyle GetCascadedborderLeftStyle(); 227 CUnitValue GetCascadedborderTopWidth(); 228 CUnitValue GetCascadedborderRightWidth(); 229 CUnitValue GetCascadedborderBottomWidth(); 230 CUnitValue GetCascadedborderLeftWidth(); 231 CUnitValue GetCascadedwidth(); 232 CUnitValue GetCascadedheight(); 233 CUnitValue GetCascadedtop(); 234 CUnitValue GetCascadedbottom(); 235 CUnitValue GetCascadedleft(); 236 CUnitValue GetCascadedright(); 237 styleOverflow GetCascadedoverflowX(); 238 styleOverflow GetCascadedoverflowY(); 239 styleOverflow GetCascadedoverflow(); 240 styleStyleFloat GetCascadedfloat(); 241 stylePosition GetCascadedposition(); 242 long GetCascadedzIndex(); 243 CUnitValue GetCascadedclipTop(); 244 CUnitValue GetCascadedclipLeft(); 245 CUnitValue GetCascadedclipRight(); 246 CUnitValue GetCascadedclipBottom(); 247 BOOL GetCascadedtableLayout(); // fixed - 1, auto - 0 248 BOOL GetCascadedborderCollapse(); // collapse - 1, separate - 0 249 BOOL GetCascadedborderOverride(); 250 WORD GetCascadedfontWeight(); 251 WORD GetCascadedfontHeight(); 252 CUnitValue GetCascadedbackgroundPositionX(); 253 CUnitValue GetCascadedbackgroundPositionY(); 254 BOOL GetCascadedbackgroundRepeatX(); 255 BOOL GetCascadedbackgroundRepeatY(); 256 htmlBlockAlign GetCascadedblockAlign(); 257 styleVisibility GetCascadedvisibility(); 258 styleDisplay GetCascadeddisplay(); 259 BOOL GetCascadedunderline(); 260 styleAccelerator GetCascadedaccelerator(); 261 BOOL GetCascadedoverline(); 262 BOOL GetCascadedstrikeOut(); 263 CUnitValue GetCascadedlineHeight(); 264 CUnitValue GetCascadedtextIndent(); 265 BOOL GetCascadedsubscript(); 266 BOOL GetCascadedsuperscript(); 267 BOOL GetCascadedbackgroundAttachmentFixed(); 268 styleListStyleType GetCascadedlistStyleType(); 269 styleListStylePosition GetCascadedlistStylePosition(); 270 long GetCascadedlistImageCookie(); 271 const TCHAR* GetCascadedfontFaceName(); 272 const TCHAR* GetCascadedfontFamilyName(); 273 BOOL GetCascadedfontItalic(); 274 long GetCascadedbackgroundImageCookie(); 275 BOOL GetCascadedclearLeft(); 276 BOOL GetCascadedclearRight(); 277 styleCursor GetCascadedcursor(); 278 styleTableLayout GetCascadedtableLayoutEnum(); 279 styleBorderCollapse GetCascadedborderCollapseEnum(); 280 styleDir GetCascadedBlockDirection(); 281 styleDir GetCascadeddirection(); 282 styleBidi GetCascadedunicodeBidi(); 283 styleLayoutGridMode GetCascadedlayoutGridMode(); 284 styleLayoutGridType GetCascadedlayoutGridType(); 285 CUnitValue GetCascadedlayoutGridLine(); 286 CUnitValue GetCascadedlayoutGridChar(); 287 LONG GetCascadedtextAutospace(); 288 styleWordBreak GetCascadedwordBreak(); 289 styleLineBreak GetCascadedlineBreak(); 290 styleTextJustify GetCascadedtextJustify(); 291 styleTextJustifyTrim GetCascadedtextJustifyTrim(); 292 CUnitValue GetCascadedmarginTop(); 293 CUnitValue GetCascadedmarginRight(); 294 CUnitValue GetCascadedmarginBottom(); 295 CUnitValue GetCascadedmarginLeft(); 296 CUnitValue GetCascadedtextKashida(); 297 298 // Ref helpers 299 // Right now these just drop right through to the element 300 static void ReplacePtr (CTreeNode** ppNodelhs, CTreeNode* pNoderhs); 301 static void SetPtr (CTreeNode** ppNodelhs, CTreeNode* pNoderhs); 302 static void ClearPtr (CTreeNode** ppNodelhs); 303 static void StealPtrSet (CTreeNode** ppNodelhs, CTreeNode* pNoderhs); 304 static void StealPtrReplace (CTreeNode** ppNodelhs, CTreeNode* pNoderhs); 305 static void ReleasePtr (CTreeNode* pNode); 306 307 // Other helpers 308 void VoidCachedInfo(); 309 void VoidCachedNodeInfo(); 310 void VoidFancyFormat(); 311 312 // Helpers for contained CTreePos‘s 313 CTreePos* InitBeginPos(BOOL fEdge) 314 { 315 _tpBegin.SetFlags( 316 (_tpBegin.GetFlags()&~(CTreePos::TPF_ETYPE_MASK|CTreePos::TPF_DATA_POS|CTreePos::TPF_EDGE)) 317 | CTreePos::NodeBeg 318 | BOOLFLAG(fEdge, CTreePos::TPF_EDGE)); 319 return &_tpBegin; 320 } 321 322 CTreePos* InitEndPos(BOOL fEdge) 323 { 324 _tpEnd.SetFlags( 325 (_tpEnd.GetFlags()&~(CTreePos::TPF_ETYPE_MASK|CTreePos::TPF_DATA_POS|CTreePos::TPF_EDGE)) 326 | CTreePos::NodeEnd 327 | BOOLFLAG(fEdge, CTreePos::TPF_EDGE)); 328 return &_tpEnd; 329 } 330 331 //+----------------------------------------------------------------------- 332 // 333 // CTreeNode::CLock 334 // 335 //------------------------------------------------------------------------ 336 class CLock 337 { 338 public: 339 DECLARE_MEMALLOC_NEW_DELETE() 340 CLock(CTreeNode* pNode); 341 ~CLock(); 342 343 private: 344 CTreeNode* _pNode; 345 }; 346 347 // Lookaside pointers 348 enum 349 { 350 LOOKASIDE_PRIMARYTEAROFF = 0, 351 LOOKASIDE_CURRENTSTYLE = 1, 352 LOOKASIDE_NODE_NUMBER = 2 353 // *** There are only 2 bits reserved in the node. 354 // *** if you add more lookasides you have to make sure 355 // *** that you make room for those bits. 356 }; 357 358 BOOL HasLookasidePtr(int iPtr) { return (_fHasLookasidePtr&(1<<iPtr)); } 359 void* GetLookasidePtr(int iPtr); 360 HRESULT SetLookasidePtr(int iPtr, void* pv); 361 void* DelLookasidePtr(int iPtr); 362 363 // Primary Tearoff pointer management 364 BOOL HasPrimaryTearoff() { return (HasLookasidePtr(LOOKASIDE_PRIMARYTEAROFF)); } 365 IUnknown* GetPrimaryTearoff() { return ((IUnknown*)GetLookasidePtr(LOOKASIDE_PRIMARYTEAROFF)); } 366 HRESULT SetPrimaryTearoff(IUnknown* pTearoff) { return (SetLookasidePtr(LOOKASIDE_PRIMARYTEAROFF, pTearoff)); } 367 IUnknown* DelPrimaryTearoff() { return ((IUnknown*)DelLookasidePtr(LOOKASIDE_PRIMARYTEAROFF)); } 368 369 // Class Data 370 CElement* _pElement; // The element for this node 371 CTreeNode* _pNodeParent; // The parent in the CTreeNode tree 372 373 // DWORD 1 374 BYTE _etag; // 0-7: element tag 375 BYTE _fFirstCommonAncestorNode : 1; // 8: for finding common ancestor 376 BYTE _fInMarkup : 1; // 9: this node is in a markup and shouldn‘t die 377 BYTE _fInMarkupDestruction : 1; // 10: Used by CMarkup::DestroySplayTree 378 BYTE _fHasLookasidePtr : 2; // 11-12 Lookaside flags 379 BYTE _fBlockNess : 1; // 13: Cached from format -- valid if _iFF != -1 380 BYTE _fHasLayout : 1; // 14: Cached from format -- valid if _iFF != -1 381 BYTE _fUnused : 1; // 15: Unused 382 383 SHORT _iPF; // 16-31: Paragraph Format 384 385 // DWORD 2 386 SHORT _iCF; // 0-15: Char Format 387 SHORT _iFF; // 16-31: Fancy Format 388 389 protected: 390 // Use GetBeginPos() or GetEndPos() to get at these members 391 CTreePos _tpBegin; // The begin CTreePos for this node 392 CTreePos _tpEnd; // The end CTreePos for this node 393 394 public: 395 // STATIC MEMBERS 396 DECLARE_TEAROFF_TABLE_NAMED(s_apfnNodeVTable) 397 398 private: 399 NO_COPY(CTreeNode); 400 };
1 void CMarkup::FreeTreePos(CTreePos* ptp) 2 { 3 Assert(ptp); 4 5 // set a sentinel to make the traversal terminate 6 ptp->MarkFirst(); 7 ptp->SetNext(NULL); 8 9 // release the subtree, adding its nodes to the free list 10 while(ptp) 11 { 12 if (ptp->FirstChild()) 13 { 14 ptp = ptp->FirstChild(); 15 } 16 else 17 { 18 CTreePos* ptpNext; 19 BOOL fRelease = TRUE; 20 while(fRelease) 21 { 22 fRelease = ptp->IsLastChild(); 23 ptpNext = ptp->Next(); 24 ReleaseTreePos(ptp); 25 ptp = ptpNext; 26 } 27 } 28 } 29 }
标签:
原文地址:http://www.cnblogs.com/Ox9A82/p/5808552.html