source: webkit/trunk/Source/WebCore/css/CSSProperty.h

Last change on this file was 291407, checked in by Oriol Brufau, 3 years ago

Clarify code for logical-to-physical mappings, and add physical-to-logical mappings
https://bugs.webkit.org/show_bug.cgi?id=237967

Reviewed by Darin Adler.

Source/WebCore:

The code for logical-to-physical mappings wasn't easy to understand, e.g.
mapLogicalSideToPhysicalSide used to cast a LogicalBoxSide enum into a
BoxSide enum, and then maybe casting it into an int and back to BoxSide.
So the code relied on the arbitrary order of the enum values, and it was
hard to grasp what was going on.

This patch makes these mappings much clearer, and also adds the inverse
physical-to-logical mappings. Being able to convert a physical property
into its logical equivalent will be needed for bug 236199.

No new tests because there is no change in behavior.

Tests in imported/w3c/web-platform-tests/css/css-logical/ ensure that
this patch doesn't break logical-to-physical mappings.
Some new API tests ensure that the physical-to-logical mappings
are the correct inverse.

Tests: WritingMode.LogicalBoxSide

WritingMode.BoxSide
WritingMode.LogicalBoxCorner
WritingMode.BoxCorner
WritingMode.LogicalBoxAxis
WritingMode.BoxAxis

  • css/CSSProperty.h:
  • css/makeprop.pl:
  • platform/text/WritingMode.h:

(WebCore::mapLogicalSideToPhysicalSide):
(WebCore::mapPhysicalSideToLogicalSide):
(WebCore::mapLogicalCornerToPhysicalCorner):
(WebCore::mapPhysicalCornerToLogicalCorner):
(WebCore::mapLogicalAxisToPhysicalAxis):
(WebCore::mapPhysicalAxisToLogicalAxis):
(WebCore::isHorizontalPhysicalSide): Deleted.
(WebCore::mirrorPhysicalSide): Deleted.
(WebCore::rotatePhysicalSide): Deleted.

Tools:

Add tests.

  • TestWebKitAPI/CMakeLists.txt:
  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebCore/WritingModeTests.cpp: Added.

(TestWebKitAPI::TEST):

  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1/*
2 * (C) 1999-2003 Lars Knoll ([email protected])
3 * Copyright (C) 2004, 2005, 2006 Apple Inc.
4 * Copyright (C) 2013 Intel Corporation. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#pragma once
23
24#include "CSSPropertyNames.h"
25#include "CSSValue.h"
26#include "WritingMode.h"
27#include <wtf/RefPtr.h>
28
29namespace WebCore {
30
31struct StylePropertyMetadata {
32 StylePropertyMetadata(CSSPropertyID propertyID, bool isSetFromShorthand, int indexInShorthandsVector, bool important, bool implicit, bool inherited)
33 : m_propertyID(propertyID)
34 , m_isSetFromShorthand(isSetFromShorthand)
35 , m_indexInShorthandsVector(indexInShorthandsVector)
36 , m_important(important)
37 , m_implicit(implicit)
38 , m_inherited(inherited)
39 {
40 }
41
42 CSSPropertyID shorthandID() const;
43
44 bool operator==(const StylePropertyMetadata& other) const
45 {
46 return m_propertyID == other.m_propertyID
47 && m_isSetFromShorthand == other.m_isSetFromShorthand
48 && m_indexInShorthandsVector == other.m_indexInShorthandsVector
49 && m_important == other.m_important
50 && m_implicit == other.m_implicit
51 && m_inherited == other.m_inherited;
52 }
53
54 uint16_t m_propertyID : 10;
55 uint16_t m_isSetFromShorthand : 1;
56 uint16_t m_indexInShorthandsVector : 2; // If this property was set as part of an ambiguous shorthand, gives the index in the shorthands vector.
57 uint16_t m_important : 1;
58 uint16_t m_implicit : 1; // Whether or not the property was set implicitly as the result of a shorthand.
59 uint16_t m_inherited : 1;
60};
61
62class CSSProperty {
63public:
64 CSSProperty(CSSPropertyID propertyID, RefPtr<CSSValue>&& value, bool important = false, bool isSetFromShorthand = false, int indexInShorthandsVector = 0, bool implicit = false)
65 : m_metadata(propertyID, isSetFromShorthand, indexInShorthandsVector, important, implicit, isInheritedProperty(propertyID))
66 , m_value(WTFMove(value))
67 {
68 }
69
70 CSSPropertyID id() const { return static_cast<CSSPropertyID>(m_metadata.m_propertyID); }
71 bool isSetFromShorthand() const { return m_metadata.m_isSetFromShorthand; };
72 CSSPropertyID shorthandID() const { return m_metadata.shorthandID(); };
73 bool isImportant() const { return m_metadata.m_important; }
74
75 CSSValue* value() const { return m_value.get(); }
76
77 void wrapValueInCommaSeparatedList();
78
79 static CSSPropertyID resolveDirectionAwareProperty(CSSPropertyID, TextDirection, WritingMode);
80 static CSSPropertyID unresolvePhysicalProperty(CSSPropertyID, TextDirection, WritingMode);
81 static bool isInheritedProperty(CSSPropertyID);
82 static Vector<String> aliasesForProperty(CSSPropertyID);
83 static bool isDirectionAwareProperty(CSSPropertyID);
84 static bool isInLogicalPropertyGroup(CSSPropertyID);
85 static bool areInSameLogicalPropertyGroupWithDifferentMappingLogic(CSSPropertyID, CSSPropertyID);
86 static bool isDescriptorOnly(CSSPropertyID);
87 static bool isColorProperty(CSSPropertyID);
88
89 const StylePropertyMetadata& metadata() const { return m_metadata; }
90
91 bool operator==(const CSSProperty& other) const
92 {
93 if (!(m_metadata == other.m_metadata))
94 return false;
95
96 if (!m_value && !other.m_value)
97 return true;
98
99 if (!m_value || !other.m_value)
100 return false;
101
102 return m_value->equals(*other.m_value);
103 }
104
105private:
106 StylePropertyMetadata m_metadata;
107 RefPtr<CSSValue> m_value;
108};
109
110typedef Vector<CSSProperty, 256> ParsedPropertyVector;
111
112} // namespace WebCore
113
114namespace WTF {
115template <> struct VectorTraits<WebCore::CSSProperty> : VectorTraitsBase<false, WebCore::CSSProperty> {
116 static const bool canInitializeWithMemset = true;
117 static const bool canMoveWithMemcpy = true;
118};
119}
Note: See TracBrowser for help on using the repository browser.