Restrict SVG filters to accessible security origins
[WebKit-https.git] / Source / WebCore / rendering / PaintInfo.h
1 /*
2  * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3  *           (C) 2000 Antti Koivisto (koivisto@kde.org)
4  *           (C) 2000 Dirk Mueller (mueller@kde.org)
5  *           (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com)
6  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7  * Copyright (C) 2009 Google Inc. All rights reserved.
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public License
20  * along with this library; see the file COPYING.LIB.  If not, write to
21  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  *
24  */
25
26 #pragma once
27
28 #include "AffineTransform.h"
29 #include "GraphicsContext.h"
30 #include "IntRect.h"
31 #include "LayoutRect.h"
32 #include "PaintPhase.h"
33 #include <limits>
34 #include <wtf/HashMap.h>
35 #include <wtf/ListHashSet.h>
36
37 namespace WebCore {
38
39 class OverlapTestRequestClient;
40 class RenderInline;
41 class RenderLayerModelObject;
42 class RenderObject;
43
44 typedef HashMap<OverlapTestRequestClient*, IntRect> OverlapTestRequestMap;
45
46 /*
47  * Paint the object and its children, clipped by (x|y|w|h).
48  * (tx|ty) is the calculated position of the parent
49  */
50 struct PaintInfo {
51     PaintInfo(GraphicsContext& newContext, const LayoutRect& newRect, PaintPhase newPhase, PaintBehavior newPaintBehavior,
52         RenderObject* newSubtreePaintRoot = nullptr, ListHashSet<RenderInline*>* newOutlineObjects = nullptr,
53         OverlapTestRequestMap* overlapTestRequests = nullptr, const RenderLayerModelObject* newPaintContainer = nullptr,
54         bool newRequireSecurityOriginAccessForWidgets = false)
55             : rect(newRect)
56             , phase(newPhase)
57             , paintBehavior(newPaintBehavior)
58             , subtreePaintRoot(newSubtreePaintRoot)
59             , outlineObjects(newOutlineObjects)
60             , overlapTestRequests(overlapTestRequests)
61             , paintContainer(newPaintContainer)
62             , requireSecurityOriginAccessForWidgets(newRequireSecurityOriginAccessForWidgets)
63             , m_context(&newContext)
64     {
65     }
66
67     GraphicsContext& context() const
68     {
69         ASSERT(m_context);
70         return *m_context;
71     }
72
73     void setContext(GraphicsContext& context)
74     {
75         m_context = &context;
76     }
77
78     void updateSubtreePaintRootForChildren(const RenderObject* renderer)
79     {
80         if (!subtreePaintRoot)
81             return;
82
83         // If we're the painting root, kids draw normally, and see root of nullptr.
84         if (subtreePaintRoot == renderer) {
85             subtreePaintRoot = nullptr;
86             return;
87         }
88     }
89
90     bool shouldPaintWithinRoot(const RenderObject& renderer) const
91     {
92         return !subtreePaintRoot || subtreePaintRoot == &renderer;
93     }
94
95     bool forceTextColor() const { return forceBlackText() || forceWhiteText(); }
96     bool forceBlackText() const { return paintBehavior & PaintBehaviorForceBlackText; }
97     bool forceWhiteText() const { return paintBehavior & PaintBehaviorForceWhiteText; }
98     Color forcedTextColor() const { return (forceBlackText()) ? Color::black : Color::white; }
99
100     bool skipRootBackground() const { return paintBehavior & PaintBehaviorSkipRootBackground; }
101     bool paintRootBackgroundOnly() const { return paintBehavior & PaintBehaviorRootBackgroundOnly; }
102
103     void applyTransform(const AffineTransform& localToAncestorTransform)
104     {
105         if (localToAncestorTransform.isIdentity())
106             return;
107
108         context().concatCTM(localToAncestorTransform);
109
110         if (rect.isInfinite())
111             return;
112
113         FloatRect tranformedRect(localToAncestorTransform.inverse().value_or(AffineTransform()).mapRect(rect));
114         rect.setLocation(LayoutPoint(tranformedRect.location()));
115         rect.setSize(LayoutSize(tranformedRect.size()));
116     }
117
118     LayoutRect rect;
119     PaintPhase phase;
120     PaintBehavior paintBehavior;
121     RenderObject* subtreePaintRoot; // used to draw just one element and its visual children
122     ListHashSet<RenderInline*>* outlineObjects; // used to list outlines that should be painted by a block with inline children
123     OverlapTestRequestMap* overlapTestRequests;
124     const RenderLayerModelObject* paintContainer; // the layer object that originates the current painting
125     bool requireSecurityOriginAccessForWidgets { false };
126
127 private:
128     GraphicsContext* m_context;
129 };
130
131 } // namespace WebCore