40b611dccee057e94234be19b0bc67ac256c5597
[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 RenderLayer;
42 class RenderLayerModelObject;
43 class RenderObject;
44
45 typedef HashMap<OverlapTestRequestClient*, IntRect> OverlapTestRequestMap;
46
47 /*
48  * Paint the object and its children, clipped by (x|y|w|h).
49  * (tx|ty) is the calculated position of the parent
50  */
51 struct PaintInfo {
52     PaintInfo(GraphicsContext& newContext, const LayoutRect& newRect, PaintPhase newPhase, PaintBehavior newPaintBehavior,
53         RenderObject* newSubtreePaintRoot = nullptr, ListHashSet<RenderInline*>* newOutlineObjects = nullptr,
54         OverlapTestRequestMap* overlapTestRequests = nullptr, const RenderLayerModelObject* newPaintContainer = nullptr,
55         const RenderLayer* enclosingSelfPaintingLayer = nullptr, bool newRequireSecurityOriginAccessForWidgets = false)
56             : rect(newRect)
57             , phase(newPhase)
58             , paintBehavior(newPaintBehavior)
59             , subtreePaintRoot(newSubtreePaintRoot)
60             , outlineObjects(newOutlineObjects)
61             , overlapTestRequests(overlapTestRequests)
62             , paintContainer(newPaintContainer)
63             , requireSecurityOriginAccessForWidgets(newRequireSecurityOriginAccessForWidgets)
64             , m_enclosingSelfPaintingLayer(enclosingSelfPaintingLayer)
65             , m_context(&newContext)
66     {
67     }
68
69     GraphicsContext& context() const
70     {
71         ASSERT(m_context);
72         return *m_context;
73     }
74
75     void setContext(GraphicsContext& context)
76     {
77         m_context = &context;
78     }
79
80     void updateSubtreePaintRootForChildren(const RenderObject* renderer)
81     {
82         if (!subtreePaintRoot)
83             return;
84
85         // If we're the painting root, kids draw normally, and see root of nullptr.
86         if (subtreePaintRoot == renderer) {
87             subtreePaintRoot = nullptr;
88             return;
89         }
90     }
91
92     bool shouldPaintWithinRoot(const RenderObject& renderer) const
93     {
94         return !subtreePaintRoot || subtreePaintRoot == &renderer;
95     }
96
97     bool forceTextColor() const { return forceBlackText() || forceWhiteText(); }
98     bool forceBlackText() const { return paintBehavior & PaintBehaviorForceBlackText; }
99     bool forceWhiteText() const { return paintBehavior & PaintBehaviorForceWhiteText; }
100     Color forcedTextColor() const { return (forceBlackText()) ? Color::black : Color::white; }
101
102     bool skipRootBackground() const { return paintBehavior & PaintBehaviorSkipRootBackground; }
103     bool paintRootBackgroundOnly() const { return paintBehavior & PaintBehaviorRootBackgroundOnly; }
104
105     const RenderLayer* enclosingSelfPaintingLayer() const { return m_enclosingSelfPaintingLayer; }
106
107     void applyTransform(const AffineTransform& localToAncestorTransform)
108     {
109         if (localToAncestorTransform.isIdentity())
110             return;
111
112         context().concatCTM(localToAncestorTransform);
113
114         if (rect.isInfinite())
115             return;
116
117         FloatRect tranformedRect(localToAncestorTransform.inverse().value_or(AffineTransform()).mapRect(rect));
118         rect.setLocation(LayoutPoint(tranformedRect.location()));
119         rect.setSize(LayoutSize(tranformedRect.size()));
120     }
121
122     LayoutRect rect;
123     PaintPhase phase;
124     PaintBehavior paintBehavior;
125     RenderObject* subtreePaintRoot; // used to draw just one element and its visual children
126     ListHashSet<RenderInline*>* outlineObjects; // used to list outlines that should be painted by a block with inline children
127     OverlapTestRequestMap* overlapTestRequests;
128     const RenderLayerModelObject* paintContainer; // the layer object that originates the current painting
129     bool requireSecurityOriginAccessForWidgets { false };
130     const RenderLayer* m_enclosingSelfPaintingLayer { nullptr };
131
132 private:
133     GraphicsContext* m_context;
134 };
135
136 } // namespace WebCore