[WTF] Import std::optional reference implementation as WTF::Optional
[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             : rect(newRect)
55             , phase(newPhase)
56             , paintBehavior(newPaintBehavior)
57             , subtreePaintRoot(newSubtreePaintRoot)
58             , outlineObjects(newOutlineObjects)
59             , overlapTestRequests(overlapTestRequests)
60             , paintContainer(newPaintContainer)
61             , m_context(&newContext)
62     {
63     }
64
65     GraphicsContext& context() const
66     {
67         ASSERT(m_context);
68         return *m_context;
69     }
70
71     void setContext(GraphicsContext& context)
72     {
73         m_context = &context;
74     }
75
76     void updateSubtreePaintRootForChildren(const RenderObject* renderer)
77     {
78         if (!subtreePaintRoot)
79             return;
80
81         // If we're the painting root, kids draw normally, and see root of nullptr.
82         if (subtreePaintRoot == renderer) {
83             subtreePaintRoot = nullptr;
84             return;
85         }
86     }
87
88     bool shouldPaintWithinRoot(const RenderObject& renderer) const
89     {
90         return !subtreePaintRoot || subtreePaintRoot == &renderer;
91     }
92
93     bool forceTextColor() const { return forceBlackText() || forceWhiteText(); }
94     bool forceBlackText() const { return paintBehavior & PaintBehaviorForceBlackText; }
95     bool forceWhiteText() const { return paintBehavior & PaintBehaviorForceWhiteText; }
96     Color forcedTextColor() const { return (forceBlackText()) ? Color::black : Color::white; }
97
98     bool skipRootBackground() const { return paintBehavior & PaintBehaviorSkipRootBackground; }
99     bool paintRootBackgroundOnly() const { return paintBehavior & PaintBehaviorRootBackgroundOnly; }
100
101     void applyTransform(const AffineTransform& localToAncestorTransform)
102     {
103         if (localToAncestorTransform.isIdentity())
104             return;
105
106         context().concatCTM(localToAncestorTransform);
107
108         if (rect.isInfinite())
109             return;
110
111         FloatRect tranformedRect(localToAncestorTransform.inverse().value_or(AffineTransform()).mapRect(rect));
112         rect.setLocation(LayoutPoint(tranformedRect.location()));
113         rect.setSize(LayoutSize(tranformedRect.size()));
114     }
115
116     LayoutRect rect;
117     PaintPhase phase;
118     PaintBehavior paintBehavior;
119     RenderObject* subtreePaintRoot; // used to draw just one element and its visual children
120     ListHashSet<RenderInline*>* outlineObjects; // used to list outlines that should be painted by a block with inline children
121     OverlapTestRequestMap* overlapTestRequests;
122     const RenderLayerModelObject* paintContainer; // the layer object that originates the current painting
123
124 private:
125     GraphicsContext* m_context;
126 };
127
128 } // namespace WebCore