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

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: Re-ordered inheritance to match initializers 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "platform/fonts/Font.h" 46 #include "platform/fonts/Font.h"
47 #include "platform/fonts/FontSelector.h" 47 #include "platform/fonts/FontSelector.h"
48 #include "platform/geometry/FloatRoundedRect.h" 48 #include "platform/geometry/FloatRoundedRect.h"
49 #include "platform/graphics/GraphicsContext.h" 49 #include "platform/graphics/GraphicsContext.h"
50 #include "platform/transforms/RotateTransformOperation.h" 50 #include "platform/transforms/RotateTransformOperation.h"
51 #include "platform/transforms/ScaleTransformOperation.h" 51 #include "platform/transforms/ScaleTransformOperation.h"
52 #include "platform/transforms/TranslateTransformOperation.h" 52 #include "platform/transforms/TranslateTransformOperation.h"
53 #include "wtf/MathExtras.h" 53 #include "wtf/MathExtras.h"
54 #include "wtf/PtrUtil.h" 54 #include "wtf/PtrUtil.h"
55 #include "wtf/SaturatedArithmetic.h" 55 #include "wtf/SaturatedArithmetic.h"
56 #include "wtf/SizeAssertions.h"
56 #include <algorithm> 57 #include <algorithm>
57 #include <memory> 58 #include <memory>
58 59
59 namespace blink { 60 namespace blink {
60 61
61 struct SameSizeAsBorderValue { 62 struct SameSizeAsBorderValue {
62 RGBA32 m_color; 63 RGBA32 m_color;
63 unsigned m_width; 64 unsigned m_width;
64 }; 65 };
65 66
66 static_assert(sizeof(BorderValue) == sizeof(SameSizeAsBorderValue), "BorderValue should stay small"); 67 ASSERT_SIZE(BorderValue, SameSizeAsBorderValue);
67 68
68 // Since different compilers/architectures pack ComputedStyle differently, 69 // Since different compilers/architectures pack ComputedStyle differently,
69 // re-create the same structure for an accurate size comparison. 70 // re-create the same structure for an accurate size comparison.
70 struct SameSizeAsComputedStyle : public RefCounted<SameSizeAsComputedStyle> { 71 struct SameSizeAsComputedStyle : public ComputedStyleBase, public RefCounted<Com putedStyle> {
71 void* dataRefs[7]; 72 void* dataRefs[7];
72 void* ownPtrs[1]; 73 void* ownPtrs[1];
73 void* dataRefSvgStyle; 74 void* dataRefSvgStyle;
74 75
75 struct InheritedData { 76 struct InheritedData {
76 unsigned m_bitfields[2]; 77 unsigned m_bitfields[2];
77 } m_inheritedData; 78 } m_inheritedData;
78 79
79 struct NonInheritedData { 80 struct NonInheritedData {
80 unsigned m_bitfields[3]; 81 unsigned m_bitfields[3];
81 } m_nonInheritedData; 82 } m_nonInheritedData;
82 }; 83 };
83 84
84 static_assert(sizeof(ComputedStyle) == sizeof(SameSizeAsComputedStyle), "Compute dStyle should stay small"); 85 ASSERT_SIZE(ComputedStyle, SameSizeAsComputedStyle);
85 86
86 PassRefPtr<ComputedStyle> ComputedStyle::create() 87 PassRefPtr<ComputedStyle> ComputedStyle::create()
87 { 88 {
88 return adoptRef(new ComputedStyle()); 89 return adoptRef(new ComputedStyle());
89 } 90 }
90 91
91 PassRefPtr<ComputedStyle> ComputedStyle::createInitialStyle() 92 PassRefPtr<ComputedStyle> ComputedStyle::createInitialStyle()
92 { 93 {
93 return adoptRef(new ComputedStyle(InitialStyle)); 94 return adoptRef(new ComputedStyle(InitialStyle));
94 } 95 }
(...skipping 11 matching lines...) Expand all
106 newStyle->setDisplay(display); 107 newStyle->setDisplay(display);
107 return newStyle; 108 return newStyle;
108 } 109 }
109 110
110 PassRefPtr<ComputedStyle> ComputedStyle::clone(const ComputedStyle& other) 111 PassRefPtr<ComputedStyle> ComputedStyle::clone(const ComputedStyle& other)
111 { 112 {
112 return adoptRef(new ComputedStyle(other)); 113 return adoptRef(new ComputedStyle(other));
113 } 114 }
114 115
115 ALWAYS_INLINE ComputedStyle::ComputedStyle() 116 ALWAYS_INLINE ComputedStyle::ComputedStyle()
116 : m_box(initialStyle().m_box) 117 : ComputedStyleBase()
118 , RefCounted<ComputedStyle>()
119 , m_box(initialStyle().m_box)
117 , m_visual(initialStyle().m_visual) 120 , m_visual(initialStyle().m_visual)
118 , m_background(initialStyle().m_background) 121 , m_background(initialStyle().m_background)
119 , m_surround(initialStyle().m_surround) 122 , m_surround(initialStyle().m_surround)
120 , m_rareNonInheritedData(initialStyle().m_rareNonInheritedData) 123 , m_rareNonInheritedData(initialStyle().m_rareNonInheritedData)
121 , m_rareInheritedData(initialStyle().m_rareInheritedData) 124 , m_rareInheritedData(initialStyle().m_rareInheritedData)
122 , m_styleInheritedData(initialStyle().m_styleInheritedData) 125 , m_styleInheritedData(initialStyle().m_styleInheritedData)
123 , m_svgStyle(initialStyle().m_svgStyle) 126 , m_svgStyle(initialStyle().m_svgStyle)
124 { 127 {
125 setBitDefaults(); // Would it be faster to copy this from the default style? 128 setBitDefaults(); // Would it be faster to copy this from the default style?
126 static_assert((sizeof(InheritedData) <= 8), "InheritedData should not grow") ; 129 static_assert((sizeof(InheritedData) <= 8), "InheritedData should not grow") ;
127 static_assert((sizeof(NonInheritedData) <= 12), "NonInheritedData should not grow"); 130 static_assert((sizeof(NonInheritedData) <= 12), "NonInheritedData should not grow");
128 } 131 }
129 132
130 ALWAYS_INLINE ComputedStyle::ComputedStyle(InitialStyleTag) 133 ALWAYS_INLINE ComputedStyle::ComputedStyle(InitialStyleTag)
134 : ComputedStyleBase()
135 , RefCounted<ComputedStyle>()
131 { 136 {
132 setBitDefaults(); 137 setBitDefaults();
133 138
134 m_box.init(); 139 m_box.init();
135 m_visual.init(); 140 m_visual.init();
136 m_background.init(); 141 m_background.init();
137 m_surround.init(); 142 m_surround.init();
138 m_rareNonInheritedData.init(); 143 m_rareNonInheritedData.init();
139 m_rareNonInheritedData.access()->m_deprecatedFlexibleBox.init(); 144 m_rareNonInheritedData.access()->m_deprecatedFlexibleBox.init();
140 m_rareNonInheritedData.access()->m_flexibleBox.init(); 145 m_rareNonInheritedData.access()->m_flexibleBox.init();
141 m_rareNonInheritedData.access()->m_multiCol.init(); 146 m_rareNonInheritedData.access()->m_multiCol.init();
142 m_rareNonInheritedData.access()->m_transform.init(); 147 m_rareNonInheritedData.access()->m_transform.init();
143 m_rareNonInheritedData.access()->m_willChange.init(); 148 m_rareNonInheritedData.access()->m_willChange.init();
144 m_rareNonInheritedData.access()->m_filter.init(); 149 m_rareNonInheritedData.access()->m_filter.init();
145 m_rareNonInheritedData.access()->m_backdropFilter.init(); 150 m_rareNonInheritedData.access()->m_backdropFilter.init();
146 m_rareNonInheritedData.access()->m_grid.init(); 151 m_rareNonInheritedData.access()->m_grid.init();
147 m_rareNonInheritedData.access()->m_gridItem.init(); 152 m_rareNonInheritedData.access()->m_gridItem.init();
148 m_rareNonInheritedData.access()->m_scrollSnap.init(); 153 m_rareNonInheritedData.access()->m_scrollSnap.init();
149 m_rareInheritedData.init(); 154 m_rareInheritedData.init();
150 m_styleInheritedData.init(); 155 m_styleInheritedData.init();
151 m_svgStyle.init(); 156 m_svgStyle.init();
152 } 157 }
153 158
154 ALWAYS_INLINE ComputedStyle::ComputedStyle(const ComputedStyle& o) 159 ALWAYS_INLINE ComputedStyle::ComputedStyle(const ComputedStyle& o)
155 : RefCounted<ComputedStyle>() 160 : ComputedStyleBase(o)
161 , RefCounted<ComputedStyle>()
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 1218 matching lines...) Expand 10 before | Expand all | Expand 10 after
2042 if (value < 0) 2053 if (value < 0)
2043 fvalue -= 0.5f; 2054 fvalue -= 0.5f;
2044 else 2055 else
2045 fvalue += 0.5f; 2056 fvalue += 0.5f;
2046 } 2057 }
2047 2058
2048 return roundForImpreciseConversion<int>(fvalue / zoomFactor); 2059 return roundForImpreciseConversion<int>(fvalue / zoomFactor);
2049 } 2060 }
2050 2061
2051 } // namespace blink 2062 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/style/ComputedStyle.h ('k') | third_party/WebKit/Source/core/style/ComputedStyleConstants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698