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