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