root/trunk/WebCore/rendering/RenderTable.h

Revision 32406, 6.5 kB (checked in by hyatt@apple.com, 3 months ago)

WebCore:

2008-04-22 David Hyatt <hyatt@apple.com>

Fix for <rdar://5589634>.

Implement CSS alpha masks. The syntax is very similar to that used for backgrounds. Multiple mask images
can be specified, and each one can be tiled, positioned, etc. The following new properties have been
added (all of which are analogous to their background-* counterparts).

mask, mask-image, mask-clip, mask-origin, mask-repeat, mask-attachment, mask-position

The alpha values in the final composite image are used to determine how the mask applies (alpha of 1 = show,
alpha of 0 = don't show).

SVG images and CSS gradients can also be used as masks.

Reviewed by Dan

Added fast/backgrounds/repeat/mask-negative-offset-repeat.html, fast/backgrounds/svg-as-mask.html

  • css/CSSMutableStyleDeclaration.cpp:
    (WebCore::CSSMutableStyleDeclaration::getPropertyValue):
    (WebCore::initShorthandMap):
  • css/CSSParser.cpp:
    (WebCore::CSSParser::parseFillProperty):
    (WebCore::CSSParser::parseTransformOrigin):
  • css/CSSStyleSelector.cpp:
    (WebCore::CSSStyleSelector::adjustRenderStyle):
    (WebCore::CSSStyleSelector::applyProperty):
  • rendering/InlineFlowBox.cpp:
    (WebCore::InlineFlowBox::paint):
    (WebCore::InlineFlowBox::paintFillLayers):
    (WebCore::InlineFlowBox::paintFillLayer):
    (WebCore::InlineFlowBox::paintBoxDecorations):
    (WebCore::InlineFlowBox::paintMask):
  • rendering/InlineFlowBox.h:
  • rendering/RenderBlock.cpp:
    (WebCore::RenderBlock::paint):
    (WebCore::RenderBlock::paintObject):
  • rendering/RenderBox.cpp:
    (WebCore::RenderBox::paintRootBoxDecorations):
    (WebCore::RenderBox::paintBoxDecorations):
    (WebCore::RenderBox::paintMask):
    (WebCore::RenderBox::paintFillLayers):
    (WebCore::RenderBox::paintFillLayer):
    (WebCore::RenderBox::paintFillLayerExtended):
  • rendering/RenderBox.h:
  • rendering/RenderFieldset.cpp:
    (WebCore::RenderFieldset::paintBoxDecorations):
    (WebCore::RenderFieldset::paintMask):
  • rendering/RenderFieldset.h:
  • rendering/RenderInline.cpp:
    (WebCore::RenderInline::requiresLayer):
  • rendering/RenderLayer.cpp:
    (WebCore::RenderLayer::isTransparent):
    (WebCore::RenderLayer::paintLayer):
  • rendering/RenderObject.cpp:
    (WebCore::RenderObject::requiresLayer):
    (WebCore::mustRepaintFillLayers):
    (WebCore::RenderObject::mustRepaintBackgroundOrBorder):
    (WebCore::RenderObject::setStyle):
    (WebCore::RenderObject::updateFillImages):
  • rendering/RenderObject.h:
    (WebCore::):
    (WebCore::RenderObject::hasMask):
    (WebCore::RenderObject::paintMask):
    (WebCore::RenderObject::paintFillExtended):
  • rendering/RenderReplaced.cpp:
    (WebCore::RenderReplaced::paint):
  • rendering/RenderStyle.cpp:
    (WebCore::FillLayer::FillLayer):
    (WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData):
  • rendering/RenderStyle.h:
    (WebCore::FillLayer::initialFillComposite):
    (WebCore::FillLayer::initialFillSize):
    (WebCore::FillLayer::FillLayer):
    (WebCore::RenderStyle::hasMask):
  • rendering/RenderTable.cpp:
    (WebCore::RenderTable::paint):
    (WebCore::RenderTable::paintBoxDecorations):
    (WebCore::RenderTable::paintMask):
  • rendering/RenderTable.h:
  • rendering/RenderTableCell.cpp:
    (WebCore::RenderTableCell::requiresLayer):
    (WebCore::RenderTableCell::paintBackgroundsBehindCell):
    (WebCore::RenderTableCell::paintMask):
  • rendering/RenderTableCell.h:
  • rendering/RenderWidget.cpp:
    (WebCore::RenderWidget::paint):
  • svg/graphics/SVGImage.cpp:
    (WebCore::SVGImage::draw):
    (WebCore::SVGImage::dataChanged):

LayoutTests:

2008-04-22 David Hyatt <hyatt@apple.com>

Add support for CSS alpha masks. Test cases.

Reviewed by Dan

  • fast/backgrounds/repeat/mask-negative-offset-repeat.html: Added.
  • fast/backgrounds/repeat/resources/white.gif: Added.
  • fast/backgrounds/svg-as-mask.html: Added.
  • Property svn:eol-style set to native
Line 
1 /*
2  * This file is part of the DOM implementation for KDE.
3  *
4  * Copyright (C) 1997 Martin Jones (mjones@kde.org)
5  *           (C) 1997 Torben Weis (weis@kde.org)
6  *           (C) 1998 Waldo Bastian (bastian@kde.org)
7  *           (C) 1999 Lars Knoll (knoll@kde.org)
8  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
9  * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc.
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Library General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Library General Public License for more details.
20  *
21  * You should have received a copy of the GNU Library General Public License
22  * along with this library; see the file COPYING.LIB.  If not, write to
23  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  * Boston, MA 02110-1301, USA.
25  */
26
27 #ifndef RenderTable_h
28 #define RenderTable_h
29
30 #include "RenderBlock.h"
31 #include <wtf/Vector.h>
32
33 namespace WebCore {
34
35 class RenderTableCol;
36 class RenderTableCell;
37 class RenderTableSection;
38 class TableLayout;
39
40 class RenderTable : public RenderBlock {
41 public:
42     enum Rules {
43         None    = 0x00,
44         RGroups = 0x01,
45         CGroups = 0x02,
46         Groups  = 0x03,
47         Rows    = 0x05,
48         Cols    = 0x0a,
49         All     = 0x0f
50     };
51     enum Frame {
52         Void   = 0x00,
53         Above  = 0x01,
54         Below  = 0x02,
55         Lhs    = 0x04,
56         Rhs    = 0x08,
57         Hsides = 0x03,
58         Vsides = 0x0c,
59         Box    = 0x0f
60     };
61
62     RenderTable(Node*);
63     ~RenderTable();
64
65     virtual const char* renderName() const { return "RenderTable"; }
66
67     virtual bool isTable() const { return true; }
68
69     virtual void setStyle(RenderStyle*);
70
71     virtual bool avoidsFloats() const { return true; }
72
73     int getColumnPos(int col) const { return m_columnPos[col]; }
74
75     int hBorderSpacing() const { return m_hSpacing; }
76     int vBorderSpacing() const { return m_vSpacing; }
77    
78     bool collapseBorders() const { return style()->borderCollapse(); }
79     int borderLeft() const { return m_borderLeft; }
80     int borderRight() const { return m_borderRight; }
81     int borderTop() const;
82     int borderBottom() const;
83    
84     Rules getRules() const { return static_cast<Rules>(m_rules); }
85
86     const Color& bgColor() const { return style()->backgroundColor(); }
87
88     int outerBorderTop() const;
89     int outerBorderBottom() const;
90     int outerBorderLeft() const;
91     int outerBorderRight() const;
92    
93     int calcBorderLeft() const;
94     int calcBorderRight() const;
95     void recalcHorizontalBorders();
96
97     // overrides
98     virtual void addChild(RenderObject* child, RenderObject* beforeChild = 0);
99     virtual void paint(PaintInfo&, int tx, int ty);
100     virtual void paintBoxDecorations(PaintInfo&, int tx, int ty);
101     virtual void paintMask(PaintInfo& paintInfo, int tx, int ty);
102     virtual void layout();
103     virtual void calcPrefWidths();
104
105     virtual RenderBlock* firstLineBlock() const;
106     virtual void updateFirstLetter();
107    
108     virtual void setCellWidths();
109
110     virtual void calcWidth();
111
112     struct ColumnStruct {
113         enum {
114             WidthUndefined = 0xffff
115         };
116
117         ColumnStruct()
118             : span(1)
119             , width(WidthUndefined)
120         {
121         }
122
123         unsigned short span;
124         unsigned width; // the calculated position of the column
125     };
126
127     Vector<ColumnStruct>& columns() { return m_columns; }
128     Vector<int>& columnPositions() { return m_columnPos; }
129     RenderTableSection* header() const { return m_head; }
130     RenderTableSection* footer() const { return m_foot; }
131     RenderTableSection* firstBody() const { return m_firstBody; }
132
133     void splitColumn(int pos, int firstSpan);
134     void appendColumn(int span);
135     int numEffCols() const { return m_columns.size(); }
136     int spanOfEffCol(int effCol) const { return m_columns[effCol].span; }
137    
138     int colToEffCol(int col) const
139     {
140         int i = 0;
141         int effCol = numEffCols();
142         for (int c = 0; c < col && i < effCol; ++i)
143             c += m_columns[i].span;
144         return i;
145     }
146    
147     int effColToCol(int effCol) const
148     {
149         int c = 0;
150         for (int i = 0; i < effCol; i++)
151             c += m_columns[i].span;
152         return c;
153     }
154
155     int bordersPaddingAndSpacing() const
156     {
157         return borderLeft() + borderRight() +
158                (collapseBorders() ? 0 : (paddingLeft() + paddingRight() + (numEffCols() + 1) * hBorderSpacing()));
159     }
160
161     RenderTableCol* colElement(int col, bool* startEdge = 0, bool* endEdge = 0) const;
162
163     bool needsSectionRecalc() const { return m_needsSectionRecalc; }
164     void setNeedsSectionRecalc()
165     {
166         if (documentBeingDestroyed())
167             return;
168         m_needsSectionRecalc = true;
169         setNeedsLayout(true);
170     }
171
172     virtual RenderObject* removeChildNode(RenderObject*, bool fullRemove = true);
173
174     RenderTableSection* sectionAbove(const RenderTableSection*, bool skipEmptySections = false) const;
175     RenderTableSection* sectionBelow(const RenderTableSection*, bool skipEmptySections = false) const;
176
177     RenderTableCell* cellAbove(const RenderTableCell*) const;
178     RenderTableCell* cellBelow(const RenderTableCell*) const;
179     RenderTableCell* cellBefore(const RenderTableCell*) const;
180     RenderTableCell* cellAfter(const RenderTableCell*) const;
181  
182     const CollapsedBorderValue* currentBorderStyle() const { return m_currentBorder; }
183    
184     bool hasSections() const { return m_head || m_foot || m_firstBody; }
185
186     virtual IntRect getOverflowClipRect(int tx, int ty);
187
188     void recalcSectionsIfNeeded() const
189     {
190         if (m_needsSectionRecalc)
191             recalcSections();
192     }
193
194 private:
195     void recalcSections() const;
196
197     mutable Vector<int> m_columnPos;
198     mutable Vector<ColumnStruct> m_columns;
199
200     mutable RenderBlock* m_caption;
201     mutable RenderTableSection* m_head;
202     mutable RenderTableSection* m_foot;
203     mutable RenderTableSection* m_firstBody;
204
205     TableLayout* m_tableLayout;
206
207     const CollapsedBorderValue* m_currentBorder;
208    
209     unsigned m_frame : 4; // Frame
210     unsigned m_rules : 4; // Rules
211
212     mutable bool m_hasColElements : 1;
213     mutable bool m_needsSectionRecalc : 1;
214    
215     short m_hSpacing;
216     short m_vSpacing;
217     int m_borderLeft;
218     int m_borderRight;
219 };
220
221 } // namespace WebCore
222
223 #endif // RenderTable_h
224
Note: See TracBrowser for help on using the browser.