1/*
2 * Copyright (C) 2011 Google Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 */
25
26#pragma once
27
28#include "GridArea.h"
29#include "GridTrackSize.h"
30#include "RenderStyleConstants.h"
31#include <wtf/Ref.h>
32#include <wtf/RefCounted.h>
33#include <wtf/Vector.h>
34#include <wtf/text/WTFString.h>
35
36namespace WebCore {
37
38typedef HashMap<String, Vector<unsigned>> NamedGridLinesMap;
39typedef HashMap<unsigned, Vector<String>, WTF::IntHash<unsigned>, WTF::UnsignedWithZeroKeyHashTraits<unsigned>> OrderedNamedGridLinesMap;
40
41class StyleGridData : public RefCounted<StyleGridData> {
42public:
43 static Ref<StyleGridData> create() { return adoptRef(*new StyleGridData); }
44 Ref<StyleGridData> copy() const;
45
46 bool operator==(const StyleGridData& o) const
47 {
48 // FIXME: comparing two hashes doesn't look great for performance. Something to keep in mind going forward.
49 return gridColumns == o.gridColumns && gridRows == o.gridRows
50 && gridAutoFlow == o.gridAutoFlow && gridAutoRows == o.gridAutoRows && gridAutoColumns == o.gridAutoColumns
51 && namedGridColumnLines == o.namedGridColumnLines && namedGridRowLines == o.namedGridRowLines
52 && autoRepeatNamedGridColumnLines == o.autoRepeatNamedGridColumnLines && autoRepeatNamedGridRowLines == o.autoRepeatNamedGridRowLines
53 && autoRepeatOrderedNamedGridColumnLines == o.autoRepeatOrderedNamedGridColumnLines && autoRepeatOrderedNamedGridRowLines == o.autoRepeatOrderedNamedGridRowLines
54 && namedGridArea == o.namedGridArea && namedGridArea == o.namedGridArea
55 && namedGridAreaRowCount == o.namedGridAreaRowCount && namedGridAreaColumnCount == o.namedGridAreaColumnCount
56 && orderedNamedGridRowLines == o.orderedNamedGridRowLines && orderedNamedGridColumnLines == o.orderedNamedGridColumnLines
57 && gridAutoRepeatColumns == o.gridAutoRepeatColumns && gridAutoRepeatRows == o.gridAutoRepeatRows
58 && autoRepeatColumnsInsertionPoint == o.autoRepeatColumnsInsertionPoint && autoRepeatRowsInsertionPoint == o.autoRepeatRowsInsertionPoint
59 && autoRepeatColumnsType == o.autoRepeatColumnsType && autoRepeatRowsType == o.autoRepeatRowsType;
60 }
61
62 bool operator!=(const StyleGridData& o) const
63 {
64 return !(*this == o);
65 }
66
67 Vector<GridTrackSize> gridColumns;
68 Vector<GridTrackSize> gridRows;
69
70 NamedGridLinesMap namedGridColumnLines;
71 NamedGridLinesMap namedGridRowLines;
72
73 OrderedNamedGridLinesMap orderedNamedGridColumnLines;
74 OrderedNamedGridLinesMap orderedNamedGridRowLines;
75
76 NamedGridLinesMap autoRepeatNamedGridColumnLines;
77 NamedGridLinesMap autoRepeatNamedGridRowLines;
78 OrderedNamedGridLinesMap autoRepeatOrderedNamedGridColumnLines;
79 OrderedNamedGridLinesMap autoRepeatOrderedNamedGridRowLines;
80
81 unsigned gridAutoFlow : GridAutoFlowBits;
82
83 Vector<GridTrackSize> gridAutoRows;
84 Vector<GridTrackSize> gridAutoColumns;
85
86 NamedGridAreaMap namedGridArea;
87 // Because namedGridArea doesn't store the unnamed grid areas, we need to keep track
88 // of the explicit grid size defined by both named and unnamed grid areas.
89 unsigned namedGridAreaRowCount;
90 unsigned namedGridAreaColumnCount;
91
92 Vector<GridTrackSize> gridAutoRepeatColumns;
93 Vector<GridTrackSize> gridAutoRepeatRows;
94
95 unsigned autoRepeatColumnsInsertionPoint;
96 unsigned autoRepeatRowsInsertionPoint;
97
98 AutoRepeatType autoRepeatColumnsType;
99 AutoRepeatType autoRepeatRowsType;
100
101private:
102 StyleGridData();
103 StyleGridData(const StyleGridData&);
104};
105
106} // namespace WebCore
107