Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(166)

Side by Side Diff: third_party/WebKit/Source/core/style/ComputedStyle.cpp

Issue 2187493004: Add a generated ComputedStyleBase class that ComputedStyle extends (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@_make_visibility_enum_class_rebase
Patch Set: Rebase onto fast path patches Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org) 2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
4 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. 4 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 struct SameSizeAsBorderValue { 61 struct SameSizeAsBorderValue {
62 RGBA32 m_color; 62 RGBA32 m_color;
63 unsigned m_width; 63 unsigned m_width;
64 }; 64 };
65 65
66 static_assert(sizeof(BorderValue) == sizeof(SameSizeAsBorderValue), "BorderValue should stay small"); 66 static_assert(sizeof(BorderValue) == sizeof(SameSizeAsBorderValue), "BorderValue should stay small");
67 67
68 // Since different compilers/architectures pack ComputedStyle differently, 68 // Since different compilers/architectures pack ComputedStyle differently,
69 // re-create the same structure for an accurate size comparison. 69 // re-create the same structure for an accurate size comparison.
70 struct SameSizeAsComputedStyle : public RefCounted<SameSizeAsComputedStyle> { 70 struct SameSizeAsComputedStyle : public RefCounted<SameSizeAsComputedStyle> {
71 // The size of ComputedStyle increases by 1 pointer since we are now
72 // inheriting from the generated parent class. This change is temporary and
73 // will go away once ComputedStyleBase becomes ComputedStyle.
74 void* parentClass[1];
71 void* dataRefs[7]; 75 void* dataRefs[7];
72 void* ownPtrs[1]; 76 void* ownPtrs[1];
73 void* dataRefSvgStyle; 77 void* dataRefSvgStyle;
74 78
75 struct InheritedData { 79 struct InheritedData {
76 unsigned m_bitfields[2]; 80 unsigned m_bitfields[2];
77 } m_inheritedData; 81 } m_inheritedData;
78 82
79 struct NonInheritedData { 83 struct NonInheritedData {
80 unsigned m_bitfields[3]; 84 unsigned m_bitfields[3];
(...skipping 25 matching lines...) Expand all
106 newStyle->setDisplay(display); 110 newStyle->setDisplay(display);
107 return newStyle; 111 return newStyle;
108 } 112 }
109 113
110 PassRefPtr<ComputedStyle> ComputedStyle::clone(const ComputedStyle& other) 114 PassRefPtr<ComputedStyle> ComputedStyle::clone(const ComputedStyle& other)
111 { 115 {
112 return adoptRef(new ComputedStyle(other)); 116 return adoptRef(new ComputedStyle(other));
113 } 117 }
114 118
115 ALWAYS_INLINE ComputedStyle::ComputedStyle() 119 ALWAYS_INLINE ComputedStyle::ComputedStyle()
116 : m_box(initialStyle().m_box) 120 : ComputedStyleBase()
121 , m_box(initialStyle().m_box)
117 , m_visual(initialStyle().m_visual) 122 , m_visual(initialStyle().m_visual)
118 , m_background(initialStyle().m_background) 123 , m_background(initialStyle().m_background)
119 , m_surround(initialStyle().m_surround) 124 , m_surround(initialStyle().m_surround)
120 , m_rareNonInheritedData(initialStyle().m_rareNonInheritedData) 125 , m_rareNonInheritedData(initialStyle().m_rareNonInheritedData)
121 , m_rareInheritedData(initialStyle().m_rareInheritedData) 126 , m_rareInheritedData(initialStyle().m_rareInheritedData)
122 , m_styleInheritedData(initialStyle().m_styleInheritedData) 127 , m_styleInheritedData(initialStyle().m_styleInheritedData)
123 , m_svgStyle(initialStyle().m_svgStyle) 128 , m_svgStyle(initialStyle().m_svgStyle)
124 { 129 {
125 setBitDefaults(); // Would it be faster to copy this from the default style? 130 setBitDefaults(); // Would it be faster to copy this from the default style?
126 static_assert((sizeof(InheritedData) <= 8), "InheritedData should not grow") ; 131 static_assert((sizeof(InheritedData) <= 8), "InheritedData should not grow") ;
127 static_assert((sizeof(NonInheritedData) <= 12), "NonInheritedData should not grow"); 132 static_assert((sizeof(NonInheritedData) <= 12), "NonInheritedData should not grow");
128 } 133 }
129 134
130 ALWAYS_INLINE ComputedStyle::ComputedStyle(InitialStyleTag) 135 ALWAYS_INLINE ComputedStyle::ComputedStyle(InitialStyleTag)
136 : ComputedStyleBase()
131 { 137 {
132 setBitDefaults(); 138 setBitDefaults();
133 139
134 m_box.init(); 140 m_box.init();
135 m_visual.init(); 141 m_visual.init();
136 m_background.init(); 142 m_background.init();
137 m_surround.init(); 143 m_surround.init();
138 m_rareNonInheritedData.init(); 144 m_rareNonInheritedData.init();
139 m_rareNonInheritedData.access()->m_deprecatedFlexibleBox.init(); 145 m_rareNonInheritedData.access()->m_deprecatedFlexibleBox.init();
140 m_rareNonInheritedData.access()->m_flexibleBox.init(); 146 m_rareNonInheritedData.access()->m_flexibleBox.init();
141 m_rareNonInheritedData.access()->m_multiCol.init(); 147 m_rareNonInheritedData.access()->m_multiCol.init();
142 m_rareNonInheritedData.access()->m_transform.init(); 148 m_rareNonInheritedData.access()->m_transform.init();
143 m_rareNonInheritedData.access()->m_willChange.init(); 149 m_rareNonInheritedData.access()->m_willChange.init();
144 m_rareNonInheritedData.access()->m_filter.init(); 150 m_rareNonInheritedData.access()->m_filter.init();
145 m_rareNonInheritedData.access()->m_backdropFilter.init(); 151 m_rareNonInheritedData.access()->m_backdropFilter.init();
146 m_rareNonInheritedData.access()->m_grid.init(); 152 m_rareNonInheritedData.access()->m_grid.init();
147 m_rareNonInheritedData.access()->m_gridItem.init(); 153 m_rareNonInheritedData.access()->m_gridItem.init();
148 m_rareNonInheritedData.access()->m_scrollSnap.init(); 154 m_rareNonInheritedData.access()->m_scrollSnap.init();
149 m_rareInheritedData.init(); 155 m_rareInheritedData.init();
150 m_styleInheritedData.init(); 156 m_styleInheritedData.init();
151 m_svgStyle.init(); 157 m_svgStyle.init();
152 } 158 }
153 159
154 ALWAYS_INLINE ComputedStyle::ComputedStyle(const ComputedStyle& o) 160 ALWAYS_INLINE ComputedStyle::ComputedStyle(const ComputedStyle& o)
155 : RefCounted<ComputedStyle>() 161 : ComputedStyleBase(o)
156 , m_box(o.m_box) 162 , m_box(o.m_box)
157 , m_visual(o.m_visual) 163 , m_visual(o.m_visual)
158 , m_background(o.m_background) 164 , m_background(o.m_background)
159 , m_surround(o.m_surround) 165 , m_surround(o.m_surround)
160 , m_rareNonInheritedData(o.m_rareNonInheritedData) 166 , m_rareNonInheritedData(o.m_rareNonInheritedData)
161 , m_rareInheritedData(o.m_rareInheritedData) 167 , m_rareInheritedData(o.m_rareInheritedData)
162 , m_styleInheritedData(o.m_styleInheritedData) 168 , m_styleInheritedData(o.m_styleInheritedData)
163 , m_svgStyle(o.m_svgStyle) 169 , m_svgStyle(o.m_svgStyle)
164 , m_inheritedData(o.m_inheritedData) 170 , m_inheritedData(o.m_inheritedData)
165 , m_nonInheritedData(o.m_nonInheritedData) 171 , m_nonInheritedData(o.m_nonInheritedData)
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 return resolvedContentAlignmentPosition(alignContent(), normalValueBehavior) ; 305 return resolvedContentAlignmentPosition(alignContent(), normalValueBehavior) ;
300 } 306 }
301 307
302 ContentDistributionType ComputedStyle::resolvedAlignContentDistribution(const St yleContentAlignmentData& normalValueBehavior) const 308 ContentDistributionType ComputedStyle::resolvedAlignContentDistribution(const St yleContentAlignmentData& normalValueBehavior) const
303 { 309 {
304 return resolvedContentAlignmentDistribution(alignContent(), normalValueBehav ior); 310 return resolvedContentAlignmentDistribution(alignContent(), normalValueBehav ior);
305 } 311 }
306 312
307 void ComputedStyle::inheritFrom(const ComputedStyle& inheritParent, IsAtShadowBo undary isAtShadowBoundary) 313 void ComputedStyle::inheritFrom(const ComputedStyle& inheritParent, IsAtShadowBo undary isAtShadowBoundary)
308 { 314 {
315 ComputedStyleBase::inheritFrom(inheritParent, isAtShadowBoundary);
309 if (isAtShadowBoundary == AtShadowBoundary) { 316 if (isAtShadowBoundary == AtShadowBoundary) {
310 // Even if surrounding content is user-editable, shadow DOM should act a s a single unit, and not necessarily be editable 317 // Even if surrounding content is user-editable, shadow DOM should act a s a single unit, and not necessarily be editable
311 EUserModify currentUserModify = userModify(); 318 EUserModify currentUserModify = userModify();
312 m_rareInheritedData = inheritParent.m_rareInheritedData; 319 m_rareInheritedData = inheritParent.m_rareInheritedData;
313 setUserModify(currentUserModify); 320 setUserModify(currentUserModify);
314 } else { 321 } else {
315 m_rareInheritedData = inheritParent.m_rareInheritedData; 322 m_rareInheritedData = inheritParent.m_rareInheritedData;
316 } 323 }
317 m_styleInheritedData = inheritParent.m_styleInheritedData; 324 m_styleInheritedData = inheritParent.m_styleInheritedData;
318 m_inheritedData = inheritParent.m_inheritedData; 325 m_inheritedData = inheritParent.m_inheritedData;
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 } 470 }
464 471
465 bool ComputedStyle::inheritedEqual(const ComputedStyle& other) const 472 bool ComputedStyle::inheritedEqual(const ComputedStyle& other) const
466 { 473 {
467 return independentInheritedEqual(other) 474 return independentInheritedEqual(other)
468 && nonIndependentInheritedEqual(other); 475 && nonIndependentInheritedEqual(other);
469 } 476 }
470 477
471 bool ComputedStyle::independentInheritedEqual(const ComputedStyle& other) const 478 bool ComputedStyle::independentInheritedEqual(const ComputedStyle& other) const
472 { 479 {
473 return m_inheritedData.compareEqualIndependent(other.m_inheritedData); 480 return ComputedStyleBase::independentInheritedEqual(other)
481 && m_inheritedData.compareEqualIndependent(other.m_inheritedData);
474 } 482 }
475 483
476 bool ComputedStyle::nonIndependentInheritedEqual(const ComputedStyle& other) con st 484 bool ComputedStyle::nonIndependentInheritedEqual(const ComputedStyle& other) con st
477 { 485 {
478 return m_inheritedData.compareEqualNonIndependent(other.m_inheritedData) 486 return ComputedStyleBase::nonIndependentInheritedEqual(other)
487 && m_inheritedData.compareEqualNonIndependent(other.m_inheritedData)
479 && m_styleInheritedData == other.m_styleInheritedData 488 && m_styleInheritedData == other.m_styleInheritedData
480 && m_svgStyle->inheritedEqual(*other.m_svgStyle) 489 && m_svgStyle->inheritedEqual(*other.m_svgStyle)
481 && m_rareInheritedData == other.m_rareInheritedData; 490 && m_rareInheritedData == other.m_rareInheritedData;
482 } 491 }
483 492
484 bool ComputedStyle::loadingCustomFontsEqual(const ComputedStyle& other) const 493 bool ComputedStyle::loadingCustomFontsEqual(const ComputedStyle& other) const
485 { 494 {
486 return font().loadingCustomFonts() == other.font().loadingCustomFonts(); 495 return font().loadingCustomFonts() == other.font().loadingCustomFonts();
487 } 496 }
488 497
489 bool ComputedStyle::nonInheritedEqual(const ComputedStyle& other) const 498 bool ComputedStyle::nonInheritedEqual(const ComputedStyle& other) const
490 { 499 {
491 // compare everything except the pseudoStyle pointer 500 // compare everything except the pseudoStyle pointer
492 return m_nonInheritedData == other.m_nonInheritedData 501 return m_nonInheritedData == other.m_nonInheritedData
493 && m_box == other.m_box 502 && m_box == other.m_box
494 && m_visual == other.m_visual 503 && m_visual == other.m_visual
495 && m_background == other.m_background 504 && m_background == other.m_background
496 && m_surround == other.m_surround 505 && m_surround == other.m_surround
497 && m_rareNonInheritedData == other.m_rareNonInheritedData 506 && m_rareNonInheritedData == other.m_rareNonInheritedData
498 && m_svgStyle->nonInheritedEqual(*other.m_svgStyle); 507 && m_svgStyle->nonInheritedEqual(*other.m_svgStyle);
499 } 508 }
500 509
501 bool ComputedStyle::inheritedDataShared(const ComputedStyle& other) const 510 bool ComputedStyle::inheritedDataShared(const ComputedStyle& other) const
502 { 511 {
503 // This is a fast check that only looks if the data structures are shared. 512 // This is a fast check that only looks if the data structures are shared.
504 return m_inheritedData == other.m_inheritedData 513 // TODO(sashab): Should ComputedStyleBase have an inheritedDataShared method ?
514 return ComputedStyleBase::inheritedEqual(other)
515 && m_inheritedData == other.m_inheritedData
505 && m_styleInheritedData.get() == other.m_styleInheritedData.get() 516 && m_styleInheritedData.get() == other.m_styleInheritedData.get()
506 && m_svgStyle.get() == other.m_svgStyle.get() 517 && m_svgStyle.get() == other.m_svgStyle.get()
507 && m_rareInheritedData.get() == other.m_rareInheritedData.get(); 518 && m_rareInheritedData.get() == other.m_rareInheritedData.get();
508 } 519 }
509 520
510 static bool dependenceOnContentHeightHasChanged(const ComputedStyle& a, const Co mputedStyle& b) 521 static bool dependenceOnContentHeightHasChanged(const ComputedStyle& a, const Co mputedStyle& b)
511 { 522 {
512 // If top or bottom become auto/non-auto then it means we either have to sol ve height based 523 // If top or bottom become auto/non-auto then it means we either have to sol ve height based
513 // on the content or stop doing so (http://www.w3.org/TR/CSS2/visudet.html#a bs-non-replaced-height) 524 // on the content or stop doing so (http://www.w3.org/TR/CSS2/visudet.html#a bs-non-replaced-height)
514 // - either way requires a layout. 525 // - either way requires a layout.
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 } 814 }
804 815
805 return false; 816 return false;
806 } 817 }
807 818
808 bool ComputedStyle::diffNeedsPaintInvalidationObject(const ComputedStyle& other) const 819 bool ComputedStyle::diffNeedsPaintInvalidationObject(const ComputedStyle& other) const
809 { 820 {
810 if (!m_background->outline().visuallyEqual(other.m_background->outline())) 821 if (!m_background->outline().visuallyEqual(other.m_background->outline()))
811 return true; 822 return true;
812 823
813 if (m_inheritedData.m_visibility != other.m_inheritedData.m_visibility 824 if (visibility() != other.visibility()
814 || m_inheritedData.m_printColorAdjust != other.m_inheritedData.m_printCo lorAdjust 825 || m_inheritedData.m_printColorAdjust != other.m_inheritedData.m_printCo lorAdjust
815 || m_inheritedData.m_insideLink != other.m_inheritedData.m_insideLink 826 || m_inheritedData.m_insideLink != other.m_inheritedData.m_insideLink
816 || !m_surround->border.visuallyEqual(other.m_surround->border) 827 || !m_surround->border.visuallyEqual(other.m_surround->border)
817 || !m_background->visuallyEqual(*other.m_background)) 828 || !m_background->visuallyEqual(*other.m_background))
818 return true; 829 return true;
819 830
820 if (m_rareInheritedData.get() != other.m_rareInheritedData.get()) { 831 if (m_rareInheritedData.get() != other.m_rareInheritedData.get()) {
821 if (m_rareInheritedData->userModify != other.m_rareInheritedData->userMo dify 832 if (m_rareInheritedData->userModify != other.m_rareInheritedData->userMo dify
822 || m_rareInheritedData->userSelect != other.m_rareInheritedData->use rSelect 833 || m_rareInheritedData->userSelect != other.m_rareInheritedData->use rSelect
823 || m_rareInheritedData->m_imageRendering != other.m_rareInheritedDat a->m_imageRendering) 834 || m_rareInheritedData->m_imageRendering != other.m_rareInheritedDat a->m_imageRendering)
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 if (value < 0) 2056 if (value < 0)
2046 fvalue -= 0.5f; 2057 fvalue -= 0.5f;
2047 else 2058 else
2048 fvalue += 0.5f; 2059 fvalue += 0.5f;
2049 } 2060 }
2050 2061
2051 return roundForImpreciseConversion<int>(fvalue / zoomFactor); 2062 return roundForImpreciseConversion<int>(fvalue / zoomFactor);
2052 } 2063 }
2053 2064
2054 } // namespace blink 2065 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698