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

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

Issue 2476923002: [RFC] Move StyleTransformData to ComputedStyle top-level (Closed)
Patch Set: Add export for StyleTransformData Created 4 years 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 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
4 * reserved. 4 * reserved.
5 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. 5 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 RGBA32 m_color; 65 RGBA32 m_color;
66 unsigned m_width; 66 unsigned m_width;
67 }; 67 };
68 68
69 ASSERT_SIZE(BorderValue, SameSizeAsBorderValue); 69 ASSERT_SIZE(BorderValue, SameSizeAsBorderValue);
70 70
71 // Since different compilers/architectures pack ComputedStyle differently, 71 // Since different compilers/architectures pack ComputedStyle differently,
72 // re-create the same structure for an accurate size comparison. 72 // re-create the same structure for an accurate size comparison.
73 struct SameSizeAsComputedStyle : public ComputedStyleBase, 73 struct SameSizeAsComputedStyle : public ComputedStyleBase,
74 public RefCounted<ComputedStyle> { 74 public RefCounted<ComputedStyle> {
75 void* dataRefs[7]; 75 void* dataRefs[8];
76 void* ownPtrs[1]; 76 void* ownPtrs[1];
77 void* dataRefSvgStyle; 77 void* dataRefSvgStyle;
78 78
79 struct InheritedData { 79 struct InheritedData {
80 unsigned m_bitfields[2]; 80 unsigned m_bitfields[2];
81 } m_inheritedData; 81 } m_inheritedData;
82 82
83 struct NonInheritedData { 83 struct NonInheritedData {
84 unsigned m_bitfields[3]; 84 unsigned m_bitfields[3];
85 } m_nonInheritedData; 85 } m_nonInheritedData;
(...skipping 27 matching lines...) Expand all
113 return adoptRef(new ComputedStyle(other)); 113 return adoptRef(new ComputedStyle(other));
114 } 114 }
115 115
116 ALWAYS_INLINE ComputedStyle::ComputedStyle() 116 ALWAYS_INLINE ComputedStyle::ComputedStyle()
117 : ComputedStyleBase(), 117 : ComputedStyleBase(),
118 RefCounted<ComputedStyle>(), 118 RefCounted<ComputedStyle>(),
119 m_box(initialStyle().m_box), 119 m_box(initialStyle().m_box),
120 m_visual(initialStyle().m_visual), 120 m_visual(initialStyle().m_visual),
121 m_background(initialStyle().m_background), 121 m_background(initialStyle().m_background),
122 m_surround(initialStyle().m_surround), 122 m_surround(initialStyle().m_surround),
123 m_transform(initialStyle().m_transform),
123 m_rareNonInheritedData(initialStyle().m_rareNonInheritedData), 124 m_rareNonInheritedData(initialStyle().m_rareNonInheritedData),
124 m_rareInheritedData(initialStyle().m_rareInheritedData), 125 m_rareInheritedData(initialStyle().m_rareInheritedData),
125 m_styleInheritedData(initialStyle().m_styleInheritedData), 126 m_styleInheritedData(initialStyle().m_styleInheritedData),
126 m_svgStyle(initialStyle().m_svgStyle) { 127 m_svgStyle(initialStyle().m_svgStyle) {
127 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?
128 static_assert((sizeof(InheritedData) <= 8), "InheritedData should not grow"); 129 static_assert((sizeof(InheritedData) <= 8), "InheritedData should not grow");
129 static_assert((sizeof(NonInheritedData) <= 12), 130 static_assert((sizeof(NonInheritedData) <= 12),
130 "NonInheritedData should not grow"); 131 "NonInheritedData should not grow");
131 } 132 }
132 133
133 ALWAYS_INLINE ComputedStyle::ComputedStyle(InitialStyleTag) 134 ALWAYS_INLINE ComputedStyle::ComputedStyle(InitialStyleTag)
134 : ComputedStyleBase(), RefCounted<ComputedStyle>() { 135 : ComputedStyleBase(), RefCounted<ComputedStyle>() {
135 setBitDefaults(); 136 setBitDefaults();
136 137
137 m_box.init(); 138 m_box.init();
138 m_visual.init(); 139 m_visual.init();
139 m_background.init(); 140 m_background.init();
140 m_surround.init(); 141 m_surround.init();
142 m_transform.init();
141 m_rareNonInheritedData.init(); 143 m_rareNonInheritedData.init();
142 m_rareNonInheritedData.access()->m_deprecatedFlexibleBox.init(); 144 m_rareNonInheritedData.access()->m_deprecatedFlexibleBox.init();
143 m_rareNonInheritedData.access()->m_flexibleBox.init(); 145 m_rareNonInheritedData.access()->m_flexibleBox.init();
144 m_rareNonInheritedData.access()->m_multiCol.init(); 146 m_rareNonInheritedData.access()->m_multiCol.init();
145 m_rareNonInheritedData.access()->m_transform.init();
146 m_rareNonInheritedData.access()->m_willChange.init(); 147 m_rareNonInheritedData.access()->m_willChange.init();
147 m_rareNonInheritedData.access()->m_filter.init(); 148 m_rareNonInheritedData.access()->m_filter.init();
148 m_rareNonInheritedData.access()->m_backdropFilter.init(); 149 m_rareNonInheritedData.access()->m_backdropFilter.init();
149 m_rareNonInheritedData.access()->m_grid.init(); 150 m_rareNonInheritedData.access()->m_grid.init();
150 m_rareNonInheritedData.access()->m_gridItem.init(); 151 m_rareNonInheritedData.access()->m_gridItem.init();
151 m_rareNonInheritedData.access()->m_scrollSnap.init(); 152 m_rareNonInheritedData.access()->m_scrollSnap.init();
152 m_rareInheritedData.init(); 153 m_rareInheritedData.init();
153 m_styleInheritedData.init(); 154 m_styleInheritedData.init();
154 m_svgStyle.init(); 155 m_svgStyle.init();
155 } 156 }
156 157
157 ALWAYS_INLINE ComputedStyle::ComputedStyle(const ComputedStyle& o) 158 ALWAYS_INLINE ComputedStyle::ComputedStyle(const ComputedStyle& o)
158 : ComputedStyleBase(o), 159 : ComputedStyleBase(o),
159 RefCounted<ComputedStyle>(), 160 RefCounted<ComputedStyle>(),
160 m_box(o.m_box), 161 m_box(o.m_box),
161 m_visual(o.m_visual), 162 m_visual(o.m_visual),
162 m_background(o.m_background), 163 m_background(o.m_background),
163 m_surround(o.m_surround), 164 m_surround(o.m_surround),
165 m_transform(o.m_transform),
164 m_rareNonInheritedData(o.m_rareNonInheritedData), 166 m_rareNonInheritedData(o.m_rareNonInheritedData),
165 m_rareInheritedData(o.m_rareInheritedData), 167 m_rareInheritedData(o.m_rareInheritedData),
166 m_styleInheritedData(o.m_styleInheritedData), 168 m_styleInheritedData(o.m_styleInheritedData),
167 m_svgStyle(o.m_svgStyle), 169 m_svgStyle(o.m_svgStyle),
168 m_inheritedData(o.m_inheritedData), 170 m_inheritedData(o.m_inheritedData),
169 m_nonInheritedData(o.m_nonInheritedData) {} 171 m_nonInheritedData(o.m_nonInheritedData) {}
170 172
171 static StyleRecalcChange diffPseudoStyles(const ComputedStyle& oldStyle, 173 static StyleRecalcChange diffPseudoStyles(const ComputedStyle& oldStyle,
172 const ComputedStyle& newStyle) { 174 const ComputedStyle& newStyle) {
173 // If the pseudoStyles have changed, ensure layoutObject triggers setStyle. 175 // If the pseudoStyles have changed, ensure layoutObject triggers setStyle.
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 if (m_svgStyle != inheritParent.m_svgStyle) 359 if (m_svgStyle != inheritParent.m_svgStyle)
358 m_svgStyle.access()->inheritFrom(inheritParent.m_svgStyle.get()); 360 m_svgStyle.access()->inheritFrom(inheritParent.m_svgStyle.get());
359 } 361 }
360 362
361 void ComputedStyle::copyNonInheritedFromCached(const ComputedStyle& other) { 363 void ComputedStyle::copyNonInheritedFromCached(const ComputedStyle& other) {
362 ComputedStyleBase::copyNonInheritedFromCached(other); 364 ComputedStyleBase::copyNonInheritedFromCached(other);
363 m_box = other.m_box; 365 m_box = other.m_box;
364 m_visual = other.m_visual; 366 m_visual = other.m_visual;
365 m_background = other.m_background; 367 m_background = other.m_background;
366 m_surround = other.m_surround; 368 m_surround = other.m_surround;
369 m_transform = other.m_transform;
367 m_rareNonInheritedData = other.m_rareNonInheritedData; 370 m_rareNonInheritedData = other.m_rareNonInheritedData;
368 371
369 // The flags are copied one-by-one because m_nonInheritedData.m_contains a 372 // The flags are copied one-by-one because m_nonInheritedData.m_contains a
370 // bunch of stuff other than real style data. 373 // bunch of stuff other than real style data.
371 // See comments for each skipped flag below. 374 // See comments for each skipped flag below.
372 m_nonInheritedData.m_effectiveDisplay = 375 m_nonInheritedData.m_effectiveDisplay =
373 other.m_nonInheritedData.m_effectiveDisplay; 376 other.m_nonInheritedData.m_effectiveDisplay;
374 m_nonInheritedData.m_originalDisplay = 377 m_nonInheritedData.m_originalDisplay =
375 other.m_nonInheritedData.m_originalDisplay; 378 other.m_nonInheritedData.m_originalDisplay;
376 m_nonInheritedData.m_overflowAnchor = 379 m_nonInheritedData.m_overflowAnchor =
377 other.m_nonInheritedData.m_overflowAnchor; 380 other.m_nonInheritedData.m_overflowAnchor;
378 m_nonInheritedData.m_overflowX = other.m_nonInheritedData.m_overflowX; 381 m_nonInheritedData.m_overflowX = other.m_nonInheritedData.m_overflowX;
379 m_nonInheritedData.m_overflowY = other.m_nonInheritedData.m_overflowY; 382 m_nonInheritedData.m_overflowY = other.m_nonInheritedData.m_overflowY;
380 m_nonInheritedData.m_verticalAlign = other.m_nonInheritedData.m_verticalAlign; 383 m_nonInheritedData.m_verticalAlign = other.m_nonInheritedData.m_verticalAlign;
381 m_nonInheritedData.m_clear = other.m_nonInheritedData.m_clear; 384 m_nonInheritedData.m_clear = other.m_nonInheritedData.m_clear;
382 m_nonInheritedData.m_position = other.m_nonInheritedData.m_position; 385 m_nonInheritedData.m_position = other.m_nonInheritedData.m_position;
383 m_nonInheritedData.m_tableLayout = other.m_nonInheritedData.m_tableLayout; 386 m_nonInheritedData.m_tableLayout = other.m_nonInheritedData.m_tableLayout;
384 m_nonInheritedData.m_unicodeBidi = other.m_nonInheritedData.m_unicodeBidi; 387 m_nonInheritedData.m_unicodeBidi = other.m_nonInheritedData.m_unicodeBidi;
385 m_nonInheritedData.m_hasViewportUnits = 388 m_nonInheritedData.m_hasViewportUnits =
386 other.m_nonInheritedData.m_hasViewportUnits; 389 other.m_nonInheritedData.m_hasViewportUnits;
387 m_nonInheritedData.m_breakBefore = other.m_nonInheritedData.m_breakBefore; 390 m_nonInheritedData.m_breakBefore = other.m_nonInheritedData.m_breakBefore;
388 m_nonInheritedData.m_breakAfter = other.m_nonInheritedData.m_breakAfter; 391 m_nonInheritedData.m_breakAfter = other.m_nonInheritedData.m_breakAfter;
389 m_nonInheritedData.m_breakInside = other.m_nonInheritedData.m_breakInside; 392 m_nonInheritedData.m_breakInside = other.m_nonInheritedData.m_breakInside;
390 m_nonInheritedData.m_hasRemUnits = other.m_nonInheritedData.m_hasRemUnits; 393 m_nonInheritedData.m_hasRemUnits = other.m_nonInheritedData.m_hasRemUnits;
394 m_nonInheritedData.m_isStackingContext =
395 other.m_nonInheritedData.m_isStackingContext;
391 396
392 // Correctly set during selector matching: 397 // Correctly set during selector matching:
393 // m_nonInheritedData.m_styleType 398 // m_nonInheritedData.m_styleType
394 // m_nonInheritedData.m_pseudoBits 399 // m_nonInheritedData.m_pseudoBits
395 400
396 // Set correctly while computing style for children: 401 // Set correctly while computing style for children:
397 // m_nonInheritedData.m_explicitInheritance 402 // m_nonInheritedData.m_explicitInheritance
398 403
399 // unique() styles are not cacheable. 404 // unique() styles are not cacheable.
400 DCHECK(!other.m_nonInheritedData.m_unique); 405 DCHECK(!other.m_nonInheritedData.m_unique);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 bool ComputedStyle::loadingCustomFontsEqual(const ComputedStyle& other) const { 530 bool ComputedStyle::loadingCustomFontsEqual(const ComputedStyle& other) const {
526 return font().loadingCustomFonts() == other.font().loadingCustomFonts(); 531 return font().loadingCustomFonts() == other.font().loadingCustomFonts();
527 } 532 }
528 533
529 bool ComputedStyle::nonInheritedEqual(const ComputedStyle& other) const { 534 bool ComputedStyle::nonInheritedEqual(const ComputedStyle& other) const {
530 // compare everything except the pseudoStyle pointer 535 // compare everything except the pseudoStyle pointer
531 return ComputedStyleBase::nonInheritedEqual(other) && 536 return ComputedStyleBase::nonInheritedEqual(other) &&
532 m_nonInheritedData == other.m_nonInheritedData && 537 m_nonInheritedData == other.m_nonInheritedData &&
533 m_box == other.m_box && m_visual == other.m_visual && 538 m_box == other.m_box && m_visual == other.m_visual &&
534 m_background == other.m_background && m_surround == other.m_surround && 539 m_background == other.m_background && m_surround == other.m_surround &&
540 m_transform == other.m_transform &&
535 m_rareNonInheritedData == other.m_rareNonInheritedData && 541 m_rareNonInheritedData == other.m_rareNonInheritedData &&
536 m_svgStyle->nonInheritedEqual(*other.m_svgStyle); 542 m_svgStyle->nonInheritedEqual(*other.m_svgStyle);
537 } 543 }
538 544
539 bool ComputedStyle::inheritedDataShared(const ComputedStyle& other) const { 545 bool ComputedStyle::inheritedDataShared(const ComputedStyle& other) const {
540 // This is a fast check that only looks if the data structures are shared. 546 // This is a fast check that only looks if the data structures are shared.
541 // TODO(sashab): Should ComputedStyleBase have an inheritedDataShared method? 547 // TODO(sashab): Should ComputedStyleBase have an inheritedDataShared method?
542 return ComputedStyleBase::inheritedEqual(other) && 548 return ComputedStyleBase::inheritedEqual(other) &&
543 m_inheritedData == other.m_inheritedData && 549 m_inheritedData == other.m_inheritedData &&
544 m_styleInheritedData.get() == other.m_styleInheritedData.get() && 550 m_styleInheritedData.get() == other.m_styleInheritedData.get() &&
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 return false; 1064 return false;
1059 } 1065 }
1060 1066
1061 void ComputedStyle::updatePropertySpecificDifferences( 1067 void ComputedStyle::updatePropertySpecificDifferences(
1062 const ComputedStyle& other, 1068 const ComputedStyle& other,
1063 StyleDifference& diff) const { 1069 StyleDifference& diff) const {
1064 if (m_box->zIndex() != other.m_box->zIndex() || 1070 if (m_box->zIndex() != other.m_box->zIndex() ||
1065 isStackingContext() != other.isStackingContext()) 1071 isStackingContext() != other.isStackingContext())
1066 diff.setZIndexChanged(); 1072 diff.setZIndexChanged();
1067 1073
1074 if (!transformDataEquivalent(other))
1075 diff.setTransformChanged();
1076
1068 if (m_rareNonInheritedData.get() != other.m_rareNonInheritedData.get()) { 1077 if (m_rareNonInheritedData.get() != other.m_rareNonInheritedData.get()) {
1069 if (!transformDataEquivalent(other))
1070 diff.setTransformChanged();
1071
1072 if (m_rareNonInheritedData->opacity != 1078 if (m_rareNonInheritedData->opacity !=
1073 other.m_rareNonInheritedData->opacity) 1079 other.m_rareNonInheritedData->opacity)
1074 diff.setOpacityChanged(); 1080 diff.setOpacityChanged();
1075 1081
1076 if (m_rareNonInheritedData->m_filter != 1082 if (m_rareNonInheritedData->m_filter !=
1077 other.m_rareNonInheritedData->m_filter) 1083 other.m_rareNonInheritedData->m_filter)
1078 diff.setFilterChanged(); 1084 diff.setFilterChanged();
1079 1085
1080 if (!m_rareNonInheritedData->shadowDataEquivalent( 1086 if (!m_rareNonInheritedData->shadowDataEquivalent(
1081 *other.m_rareNonInheritedData.get())) 1087 *other.m_rareNonInheritedData.get()))
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 if (applyTransformOrigin) { 1378 if (applyTransformOrigin) {
1373 result.translate3d(-originX, -originY, -originZ); 1379 result.translate3d(-originX, -originY, -originZ);
1374 } 1380 }
1375 } 1381 }
1376 1382
1377 void ComputedStyle::applyMotionPathTransform( 1383 void ComputedStyle::applyMotionPathTransform(
1378 float originX, 1384 float originX,
1379 float originY, 1385 float originY,
1380 const FloatRect& boundingBox, 1386 const FloatRect& boundingBox,
1381 TransformationMatrix& transform) const { 1387 TransformationMatrix& transform) const {
1382 const StyleMotionData& motionData = 1388 const StyleMotionData& motionData = m_transform->m_motion;
1383 m_rareNonInheritedData->m_transform->m_motion;
1384 // TODO(ericwilligers): crbug.com/638055 Apply offset-position. 1389 // TODO(ericwilligers): crbug.com/638055 Apply offset-position.
1385 if (!motionData.m_path) { 1390 if (!motionData.m_path) {
1386 return; 1391 return;
1387 } 1392 }
1388 const StylePath& motionPath = *motionData.m_path; 1393 const StylePath& motionPath = *motionData.m_path;
1389 float pathLength = motionPath.length(); 1394 float pathLength = motionPath.length();
1390 float distance = floatValueForLength(motionData.m_distance, pathLength); 1395 float distance = floatValueForLength(motionData.m_distance, pathLength);
1391 float computedDistance; 1396 float computedDistance;
1392 if (motionPath.isClosed() && pathLength > 0) { 1397 if (motionPath.isClosed() && pathLength > 0) {
1393 computedDistance = fmod(distance, pathLength); 1398 computedDistance = fmod(distance, pathLength);
(...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after
2281 setMarginLeft(margin); 2286 setMarginLeft(margin);
2282 } else { 2287 } else {
2283 if (isLeftToRightDirection()) 2288 if (isLeftToRightDirection())
2284 setMarginBottom(margin); 2289 setMarginBottom(margin);
2285 else 2290 else
2286 setMarginTop(margin); 2291 setMarginTop(margin);
2287 } 2292 }
2288 } 2293 }
2289 2294
2290 void ComputedStyle::setOffsetPath(PassRefPtr<StylePath> path) { 2295 void ComputedStyle::setOffsetPath(PassRefPtr<StylePath> path) {
2291 m_rareNonInheritedData.access()->m_transform.access()->m_motion.m_path = path; 2296 m_transform.access()->m_motion.m_path = path;
2292 } 2297 }
2293 2298
2294 int ComputedStyle::outlineOutsetExtent() const { 2299 int ComputedStyle::outlineOutsetExtent() const {
2295 if (!hasOutline()) 2300 if (!hasOutline())
2296 return 0; 2301 return 0;
2297 if (outlineStyleIsAuto()) { 2302 if (outlineStyleIsAuto()) {
2298 return GraphicsContext::focusRingOutsetExtent( 2303 return GraphicsContext::focusRingOutsetExtent(
2299 outlineOffset(), std::ceil(getOutlineStrokeWidthForFocusRing())); 2304 outlineOffset(), std::ceil(getOutlineStrokeWidthForFocusRing()));
2300 } 2305 }
2301 return std::max(0, SaturatedAddition(outlineWidth(), outlineOffset())); 2306 return std::max(0, SaturatedAddition(outlineWidth(), outlineOffset()));
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2471 if (value < 0) 2476 if (value < 0)
2472 fvalue -= 0.5f; 2477 fvalue -= 0.5f;
2473 else 2478 else
2474 fvalue += 0.5f; 2479 fvalue += 0.5f;
2475 } 2480 }
2476 2481
2477 return roundForImpreciseConversion<int>(fvalue / zoomFactor); 2482 return roundForImpreciseConversion<int>(fvalue / zoomFactor);
2478 } 2483 }
2479 2484
2480 } // namespace blink 2485 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/style/ComputedStyle.h ('k') | third_party/WebKit/Source/core/style/StylePath.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698