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

Side by Side Diff: third_party/WebKit/Source/core/css/StylePropertySerializer.cpp

Issue 2368013002: [WIP] CSS Motion Path: offset shorthand ready for position and anchor
Patch Set: code review feedback Created 4 years, 2 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 * (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Inc. All r ights reserved.
4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved. 4 * Copyright (C) 2011 Research In Motion Limited. All rights reserved.
5 * Copyright (C) 2013 Intel Corporation. All rights reserved. 5 * Copyright (C) 2013 Intel Corporation. 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.
11 * 11 *
12 * This library is distributed in the hope that it will be useful, 12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details. 15 * Library General Public License for more details.
16 * 16 *
17 * You should have received a copy of the GNU Library General Public License 17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to 18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA. 20 * Boston, MA 02110-1301, USA.
21 */ 21 */
22 22
23 #include "core/css/StylePropertySerializer.h" 23 #include "core/css/StylePropertySerializer.h"
24 24
25 #include "core/CSSValueKeywords.h" 25 #include "core/CSSValueKeywords.h"
26 #include "core/StylePropertyShorthand.h" 26 #include "core/StylePropertyShorthand.h"
27 #include "core/css/CSSCustomPropertyDeclaration.h" 27 #include "core/css/CSSCustomPropertyDeclaration.h"
28 #include "core/css/CSSPendingSubstitutionValue.h" 28 #include "core/css/CSSPendingSubstitutionValue.h"
29 #include "core/css/CSSPropertyMetadata.h" 29 #include "core/css/CSSPropertyMetadata.h"
30 #include "core/css/CSSValuePair.h"
30 #include "core/css/CSSValuePool.h" 31 #include "core/css/CSSValuePool.h"
31 #include "wtf/StdLibExtras.h" 32 #include "wtf/StdLibExtras.h"
32 #include "wtf/text/StringBuilder.h" 33 #include "wtf/text/StringBuilder.h"
33 #include <bitset> 34 #include <bitset>
34 35
35 namespace blink { 36 namespace blink {
36 37
37 StylePropertySerializer::StylePropertySetForSerializer::StylePropertySetForSeria lizer(const StylePropertySet& properties) 38 StylePropertySerializer::StylePropertySetForSerializer::StylePropertySetForSeria lizer(const StylePropertySet& properties)
38 : m_propertySet(&properties) 39 : m_propertySet(&properties)
39 , m_allIndex(m_propertySet->findPropertyIndex(CSSPropertyAll)) 40 , m_allIndex(m_propertySet->findPropertyIndex(CSSPropertyAll))
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 return getShorthandValue(gridGapShorthand()); 451 return getShorthandValue(gridGapShorthand());
451 case CSSPropertyFont: 452 case CSSPropertyFont:
452 return fontValue(); 453 return fontValue();
453 case CSSPropertyFontVariant: 454 case CSSPropertyFontVariant:
454 return fontVariantValue(); 455 return fontVariantValue();
455 case CSSPropertyMargin: 456 case CSSPropertyMargin:
456 return get4Values(marginShorthand()); 457 return get4Values(marginShorthand());
457 case CSSPropertyMotion: 458 case CSSPropertyMotion:
458 return getShorthandValue(motionShorthand()); 459 return getShorthandValue(motionShorthand());
459 case CSSPropertyOffset: 460 case CSSPropertyOffset:
460 return getShorthandValue(offsetShorthand()); 461 return offsetValue();
461 case CSSPropertyWebkitMarginCollapse: 462 case CSSPropertyWebkitMarginCollapse:
462 return getShorthandValue(webkitMarginCollapseShorthand()); 463 return getShorthandValue(webkitMarginCollapseShorthand());
463 case CSSPropertyOverflow: 464 case CSSPropertyOverflow:
464 return getCommonValue(overflowShorthand()); 465 return getCommonValue(overflowShorthand());
465 case CSSPropertyPadding: 466 case CSSPropertyPadding:
466 return get4Values(paddingShorthand()); 467 return get4Values(paddingShorthand());
467 case CSSPropertyTransition: 468 case CSSPropertyTransition:
468 return getLayeredShorthandValue(transitionShorthand()); 469 return getLayeredShorthandValue(transitionShorthand());
469 case CSSPropertyListStyle: 470 case CSSPropertyListStyle:
470 return getShorthandValue(listStyleShorthand()); 471 return getShorthandValue(listStyleShorthand());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 && val->isPrimitiveValue() 540 && val->isPrimitiveValue()
540 && toCSSPrimitiveValue(val)->getValueID() == CSSValueNone) { 541 && toCSSPrimitiveValue(val)->getValueID() == CSSValueNone) {
541 value = "no-common-ligatures no-discretionary-ligatures no-historical-li gatures no-contextual"; 542 value = "no-common-ligatures no-discretionary-ligatures no-historical-li gatures no-contextual";
542 } else { 543 } else {
543 value = m_propertySet.propertyAt(foundPropertyIndex).value()->cssText(); 544 value = m_propertySet.propertyAt(foundPropertyIndex).value()->cssText();
544 } 545 }
545 546
546 result.append(value); 547 result.append(value);
547 } 548 }
548 549
550 String StylePropertySerializer::offsetValue() const
551 {
552 const CSSValue* offsetPathValue = m_propertySet.getPropertyCSSValue(CSSPrope rtyOffsetPath);
553 const CSSValue* offsetDistanceValue = m_propertySet.getPropertyCSSValue(CSSP ropertyOffsetDistance);
554 const CSSValue* offsetRotationValue = m_propertySet.getPropertyCSSValue(CSSP ropertyOffsetRotation);
555
556 const CSSValue* offsetPositionValue = nullptr;
557 const CSSValue* offsetAnchorValue = nullptr;
558 if (RuntimeEnabledFeatures::cssOffsetPositionAnchorEnabled()) {
559 offsetPositionValue = m_propertySet.getPropertyCSSValue(CSSPropertyOffse tPosition);
560 offsetAnchorValue = m_propertySet.getPropertyCSSValue(CSSPropertyOffsetA nchor);
561 }
562
563 StringBuilder result;
564 if (offsetPositionValue && offsetPositionValue->isValuePair()) {
565 result.append(offsetPositionValue->cssText());
566 result.append(' ');
567 }
568 result.append(offsetPathValue->cssText());
569 result.append(' ');
570 result.append(offsetDistanceValue->cssText());
571 result.append(' ');
572 result.append(offsetRotationValue->cssText());
573
574 bool anchorIsCentre = !offsetAnchorValue;
575 if (offsetAnchorValue && offsetAnchorValue->isValuePair()) {
576 const CSSValuePair* pair = toCSSValuePair(offsetAnchorValue);
577 const CSSPrimitiveValue& first = toCSSPrimitiveValue(pair->first());
578 const CSSPrimitiveValue& second = toCSSPrimitiveValue(pair->second());
579 anchorIsCentre = first.isPercentage() && first.getDoubleValue() == 50 && second.isPercentage() && second.getDoubleValue() == 50;
580 }
581 if (!anchorIsCentre) {
582 result.append('/');
583 result.append(offsetAnchorValue->cssText());
584 }
585 return result.toString();
586 }
587
549 String StylePropertySerializer::fontValue() const 588 String StylePropertySerializer::fontValue() const
550 { 589 {
551 int fontSizePropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFontS ize); 590 int fontSizePropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFontS ize);
552 int fontFamilyPropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFon tFamily); 591 int fontFamilyPropertyIndex = m_propertySet.findPropertyIndex(CSSPropertyFon tFamily);
553 int fontVariantCapsPropertyIndex = m_propertySet.findPropertyIndex(CSSProper tyFontVariantCaps); 592 int fontVariantCapsPropertyIndex = m_propertySet.findPropertyIndex(CSSProper tyFontVariantCaps);
554 int fontVariantLigaturesPropertyIndex = m_propertySet.findPropertyIndex(CSSP ropertyFontVariantLigatures); 593 int fontVariantLigaturesPropertyIndex = m_propertySet.findPropertyIndex(CSSP ropertyFontVariantLigatures);
555 int fontVariantNumericPropertyIndex = m_propertySet.findPropertyIndex(CSSPro pertyFontVariantNumeric); 594 int fontVariantNumericPropertyIndex = m_propertySet.findPropertyIndex(CSSPro pertyFontVariantNumeric);
556 DCHECK_NE(fontSizePropertyIndex, -1); 595 DCHECK_NE(fontSizePropertyIndex, -1);
557 DCHECK_NE(fontFamilyPropertyIndex, -1); 596 DCHECK_NE(fontFamilyPropertyIndex, -1);
558 DCHECK_NE(fontVariantCapsPropertyIndex, -1); 597 DCHECK_NE(fontVariantCapsPropertyIndex, -1);
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 builder.append(", "); 909 builder.append(", ");
871 910
872 const CSSValue& xValue = repeatXList ? repeatXList->item(i % repeatXList ->length()) : repeatX; 911 const CSSValue& xValue = repeatXList ? repeatXList->item(i % repeatXList ->length()) : repeatX;
873 const CSSValue& yValue = repeatYList ? repeatYList->item(i % repeatYList ->length()) : repeatY; 912 const CSSValue& yValue = repeatYList ? repeatYList->item(i % repeatYList ->length()) : repeatY;
874 appendBackgroundRepeatValue(builder, xValue, yValue); 913 appendBackgroundRepeatValue(builder, xValue, yValue);
875 } 914 }
876 return builder.toString(); 915 return builder.toString();
877 } 916 }
878 917
879 } // namespace blink 918 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698