1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
4 * Copyright (C) 2012 Google Inc. 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#ifndef CSSToStyleMap_h
23#define CSSToStyleMap_h
24
25#include "CSSPropertyNames.h"
26#include "core/css/resolver/ElementStyleResources.h"
27#include "core/platform/LengthBox.h"
28#include "wtf/Noncopyable.h"
29
30namespace WebCore {
31
32class FillLayer;
33class CSSValue;
34class CSSAnimationData;
35class RenderStyle;
36class StyleImage;
37class StyleResolverState;
38class NinePieceImage;
39
40// CSSToStyleMap is a short-lived helper object which
41// given the current StyleResolverState can map
42// CSSValue objects into their RenderStyle equivalents.
43
44class CSSToStyleMap {
45    WTF_MAKE_NONCOPYABLE(CSSToStyleMap);
46public:
47    CSSToStyleMap(const StyleResolverState& state, ElementStyleResources& elementStyleResources) : m_state(state), m_elementStyleResources(elementStyleResources) { }
48
49    void mapFillAttachment(CSSPropertyID, FillLayer*, CSSValue*) const;
50    void mapFillClip(CSSPropertyID, FillLayer*, CSSValue*) const;
51    void mapFillComposite(CSSPropertyID, FillLayer*, CSSValue*) const;
52    void mapFillBlendMode(CSSPropertyID, FillLayer*, CSSValue*) const;
53    void mapFillOrigin(CSSPropertyID, FillLayer*, CSSValue*) const;
54    void mapFillImage(CSSPropertyID, FillLayer*, CSSValue*);
55    void mapFillRepeatX(CSSPropertyID, FillLayer*, CSSValue*) const;
56    void mapFillRepeatY(CSSPropertyID, FillLayer*, CSSValue*) const;
57    void mapFillSize(CSSPropertyID, FillLayer*, CSSValue*) const;
58    void mapFillXPosition(CSSPropertyID, FillLayer*, CSSValue*) const;
59    void mapFillYPosition(CSSPropertyID, FillLayer*, CSSValue*) const;
60
61    void mapAnimationDelay(CSSAnimationData*, CSSValue*) const;
62    void mapAnimationDirection(CSSAnimationData*, CSSValue*) const;
63    void mapAnimationDuration(CSSAnimationData*, CSSValue*) const;
64    void mapAnimationFillMode(CSSAnimationData*, CSSValue*) const;
65    void mapAnimationIterationCount(CSSAnimationData*, CSSValue*) const;
66    void mapAnimationName(CSSAnimationData*, CSSValue*) const;
67    void mapAnimationPlayState(CSSAnimationData*, CSSValue*) const;
68    void mapAnimationProperty(CSSAnimationData*, CSSValue*) const;
69    void mapAnimationTimingFunction(CSSAnimationData*, CSSValue*) const;
70
71    void mapNinePieceImage(RenderStyle* mutableStyle, CSSPropertyID, CSSValue*, NinePieceImage&);
72    void mapNinePieceImageSlice(CSSValue*, NinePieceImage&) const;
73    LengthBox mapNinePieceImageQuad(CSSValue*) const;
74    void mapNinePieceImageRepeat(CSSValue*, NinePieceImage&) const;
75
76private:
77    const RenderStyle* style() const;
78    const RenderStyle* rootElementStyle() const;
79    bool useSVGZoomRules() const;
80
81    PassRefPtr<StyleImage> styleImage(CSSPropertyID, CSSValue*);
82
83    // FIXME: Consider passing a StyleResolverState (or ElementResolveState)
84    // as an argument instead of caching it on this object.
85    const StyleResolverState& m_state;
86    ElementStyleResources& m_elementStyleResources;
87};
88
89}
90
91#endif
92