blob: 84d46b624b03a4f1916631b5957bf01eb7830d52 [file] [log] [blame]
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +00001/*
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
commit-queue@webkit.org46c0f522016-11-13 10:05:43 +000026#pragma once
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +000027
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +000028#include "AffineTransform.h"
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +000029#include "GraphicsContext.h"
30#include "IntRect.h"
eae@chromium.org9717cd82012-11-07 18:33:44 +000031#include "LayoutRect.h"
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +000032#include "PaintPhase.h"
leviw@chromium.org848025e2012-05-03 21:07:32 +000033#include <limits>
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +000034#include <wtf/HashMap.h>
35#include <wtf/ListHashSet.h>
36
37namespace WebCore {
38
39class OverlapTestRequestClient;
40class RenderInline;
wangxianzhu@chromium.org64f38292013-02-28 20:38:23 +000041class RenderLayerModelObject;
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +000042class RenderObject;
43
44typedef 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 */
50struct PaintInfo {
mmaxfield@apple.coma93d7ef2015-08-29 06:15:28 +000051 PaintInfo(GraphicsContext& newContext, const LayoutRect& newRect, PaintPhase newPhase, PaintBehavior newPaintBehavior,
abucur@adobe.com7f9668a2014-05-16 13:22:00 +000052 RenderObject* newSubtreePaintRoot = nullptr, ListHashSet<RenderInline*>* newOutlineObjects = nullptr,
darin@apple.com8cdf7122013-09-30 02:40:50 +000053 OverlapTestRequestMap* overlapTestRequests = nullptr, const RenderLayerModelObject* newPaintContainer = nullptr)
mmaxfield@apple.coma93d7ef2015-08-29 06:15:28 +000054 : rect(newRect)
stavila@adobe.comf1ddee62014-02-21 15:29:49 +000055 , phase(newPhase)
56 , paintBehavior(newPaintBehavior)
57 , subtreePaintRoot(newSubtreePaintRoot)
stavila@adobe.comf1ddee62014-02-21 15:29:49 +000058 , outlineObjects(newOutlineObjects)
59 , overlapTestRequests(overlapTestRequests)
60 , paintContainer(newPaintContainer)
mmaxfield@apple.coma93d7ef2015-08-29 06:15:28 +000061 , m_context(&newContext)
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +000062 {
63 }
64
mmaxfield@apple.coma93d7ef2015-08-29 06:15:28 +000065 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
simon.fraser@apple.come7b410b2013-05-19 22:52:34 +000076 void updateSubtreePaintRootForChildren(const RenderObject* renderer)
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +000077 {
simon.fraser@apple.come7b410b2013-05-19 22:52:34 +000078 if (!subtreePaintRoot)
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +000079 return;
80
darin@apple.com8cdf7122013-09-30 02:40:50 +000081 // If we're the painting root, kids draw normally, and see root of nullptr.
simon.fraser@apple.come7b410b2013-05-19 22:52:34 +000082 if (subtreePaintRoot == renderer) {
darin@apple.com8cdf7122013-09-30 02:40:50 +000083 subtreePaintRoot = nullptr;
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +000084 return;
85 }
86 }
87
antti@apple.com6fa2c9f2013-10-06 22:55:54 +000088 bool shouldPaintWithinRoot(const RenderObject& renderer) const
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +000089 {
antti@apple.com6fa2c9f2013-10-06 22:55:54 +000090 return !subtreePaintRoot || subtreePaintRoot == &renderer;
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +000091 }
92
commit-queue@webkit.orgbaadf5f2014-08-05 23:40:24 +000093 bool forceTextColor() const { return forceBlackText() || forceWhiteText(); }
simon.fraser@apple.com2bedf6f2013-01-16 20:00:52 +000094 bool forceBlackText() const { return paintBehavior & PaintBehaviorForceBlackText; }
commit-queue@webkit.orgbaadf5f2014-08-05 23:40:24 +000095 bool forceWhiteText() const { return paintBehavior & PaintBehaviorForceWhiteText; }
96 Color forcedTextColor() const { return (forceBlackText()) ? Color::black : Color::white; }
simon.fraser@apple.com2bedf6f2013-01-16 20:00:52 +000097
simon.fraser@apple.comee9213c2013-01-18 00:10:53 +000098 bool skipRootBackground() const { return paintBehavior & PaintBehaviorSkipRootBackground; }
99 bool paintRootBackgroundOnly() const { return paintBehavior & PaintBehaviorRootBackgroundOnly; }
100
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +0000101 void applyTransform(const AffineTransform& localToAncestorTransform)
102 {
103 if (localToAncestorTransform.isIdentity())
104 return;
105
mmaxfield@apple.coma93d7ef2015-08-29 06:15:28 +0000106 context().concatCTM(localToAncestorTransform);
zimmermann@webkit.org0cfc11b2010-08-19 12:41:23 +0000107
zalan@apple.comccc2ae32015-01-16 00:11:27 +0000108 if (rect.isInfinite())
zimmermann@webkit.org0cfc11b2010-08-19 12:41:23 +0000109 return;
110
utatane.tea@gmail.com43926962016-11-27 06:08:16 +0000111 FloatRect tranformedRect(localToAncestorTransform.inverse().value_or(AffineTransform()).mapRect(rect));
zalan@apple.com5f08e992014-01-24 23:35:07 +0000112 rect.setLocation(LayoutPoint(tranformedRect.location()));
113 rect.setSize(LayoutSize(tranformedRect.size()));
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +0000114 }
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +0000115
zalan@apple.com5f08e992014-01-24 23:35:07 +0000116 LayoutRect rect;
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +0000117 PaintPhase phase;
simon.fraser@apple.com2bedf6f2013-01-16 20:00:52 +0000118 PaintBehavior paintBehavior;
simon.fraser@apple.come7b410b2013-05-19 22:52:34 +0000119 RenderObject* subtreePaintRoot; // used to draw just one element and its visual children
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +0000120 ListHashSet<RenderInline*>* outlineObjects; // used to list outlines that should be painted by a block with inline children
121 OverlapTestRequestMap* overlapTestRequests;
wangxianzhu@chromium.org64f38292013-02-28 20:38:23 +0000122 const RenderLayerModelObject* paintContainer; // the layer object that originates the current painting
mmaxfield@apple.coma93d7ef2015-08-29 06:15:28 +0000123
124private:
125 GraphicsContext* m_context;
zimmermann@webkit.org427c02f2010-06-29 12:14:53 +0000126};
127
128} // namespace WebCore