Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/TransformPaintPropertyNode.h

Issue 2137173002: [SPv2] Respect transform-style in the Blink and cc property trees. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix perspective Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef TransformPaintPropertyNode_h 5 #ifndef TransformPaintPropertyNode_h
6 #define TransformPaintPropertyNode_h 6 #define TransformPaintPropertyNode_h
7 7
8 #include "platform/PlatformExport.h" 8 #include "platform/PlatformExport.h"
9 #include "platform/geometry/FloatPoint3D.h" 9 #include "platform/geometry/FloatPoint3D.h"
10 #include "platform/transforms/TransformationMatrix.h" 10 #include "platform/transforms/TransformationMatrix.h"
11 #include "wtf/PassRefPtr.h" 11 #include "wtf/PassRefPtr.h"
12 #include "wtf/RefCounted.h" 12 #include "wtf/RefCounted.h"
13 #include "wtf/RefPtr.h" 13 #include "wtf/RefPtr.h"
14 14
15 #include <iosfwd> 15 #include <iosfwd>
16 16
17 namespace blink { 17 namespace blink {
18 18
19 // A transform created by a css property such as "transform" or "perspective" 19 // A transform created by a css property such as "transform" or "perspective"
20 // along with a reference to the parent TransformPaintPropertyNode, or nullptr 20 // along with a reference to the parent TransformPaintPropertyNode, or nullptr
21 // for the root. 21 // for the root.
22 class PLATFORM_EXPORT TransformPaintPropertyNode : public RefCounted<TransformPa intPropertyNode> { 22 class PLATFORM_EXPORT TransformPaintPropertyNode : public RefCounted<TransformPa intPropertyNode> {
23 public: 23 public:
24 static PassRefPtr<TransformPaintPropertyNode> create(const TransformationMat rix& matrix, const FloatPoint3D& origin, PassRefPtr<TransformPaintPropertyNode> parent = nullptr) 24 enum TransformStyle { FlattenTransform, Preserve3D };
25 enum RenderingContextBehavior {
trchen 2016/07/13 04:39:44 I don't think this belong here. This is a CSS conc
jbroman 2016/07/13 21:47:13 Because the |this| pointer doesn't exist yet there
trchen 2016/07/13 22:31:42 Why do we need to TransformPaintPropertyNode* as s
jbroman 2016/07/14 20:34:58 It doesn't need to be; it just was (it's convenien
26 // The node should participate in the context provided, if any, but not
27 // establish a new one.
28 DontEstablishNewRenderingContext,
29
30 // The node should establish a new 3D rendering context.
31 // No existing rendering context root should be provided.
32 EstablishNewRenderingContext
33 };
34
35 // Creates a transform node, allowing full specification of the rendering
36 // context and transform style. If renderingContextBehavior is
37 // EstablishNewRenderingContext, then the renderingContextRoot provided must
38 // be null.
39 static PassRefPtr<TransformPaintPropertyNode> create(
40 const TransformationMatrix& matrix,
41 const FloatPoint3D& origin,
42 PassRefPtr<TransformPaintPropertyNode> parent,
43 RenderingContextBehavior renderingContextBehavior,
44 const TransformPaintPropertyNode* renderingContextRoot,
45 TransformStyle transformStyle)
25 { 46 {
26 return adoptRef(new TransformPaintPropertyNode(matrix, origin, parent)); 47 return adoptRef(new TransformPaintPropertyNode(matrix, origin, parent, r enderingContextBehavior, renderingContextRoot, transformStyle));
48 }
49
50 // As above, but inherits the rendering context and transform style from the
51 // parent transform node. Never establishes a new rendering context.
52 static PassRefPtr<TransformPaintPropertyNode> create(
53 const TransformationMatrix& matrix,
54 const FloatPoint3D& origin,
55 PassRefPtr<TransformPaintPropertyNode> parent = nullptr)
56 {
57 if (!parent)
58 return create(matrix, origin, nullptr, DontEstablishNewRenderingCont ext, nullptr, FlattenTransform);
59
60 // Have to copy the data out of parent before we pass the reference
61 // (and null out the local pointer).
62 const TransformPaintPropertyNode* renderingContextRoot = parent->renderi ngContextRoot();
63 TransformStyle transformStyle = parent->transformStyle();
64 return create(matrix, origin, parent, DontEstablishNewRenderingContext, renderingContextRoot, transformStyle);
27 } 65 }
28 66
29 const TransformationMatrix& matrix() const { return m_matrix; } 67 const TransformationMatrix& matrix() const { return m_matrix; }
30 const FloatPoint3D& origin() const { return m_origin; } 68 const FloatPoint3D& origin() const { return m_origin; }
31 69
32 // Parent transform that this transform is relative to, or nullptr if this 70 // Parent transform that this transform is relative to, or nullptr if this
33 // is the root transform. 71 // is the root transform.
34 TransformPaintPropertyNode* parent() const { return m_parent.get(); } 72 TransformPaintPropertyNode* parent() const { return m_parent.get(); }
35 73
74 // Content whose transform nodes have a common rendering context root is 3D
75 // sorted. If this is nullptr, content will not be 3D sorted.
76 const TransformPaintPropertyNode* renderingContextRoot() const { return m_re nderingContextRoot; }
77 bool hasRenderingContext() const { return renderingContextRoot(); }
78
79 // If a transform node flattens transform, then content within it is
80 // flattened into the plane of the transform space (including this node's
81 // matrix). If it preserves 3D, then no such flattening occurs.
82 //
83 // This corresponds fairly closely to CSS transform-style semantics, and in
84 // CSS is fairly tightly connected with the rendering context root.
85 TransformStyle transformStyle() const { return m_transformStyle; }
86 bool flattensTransform() const { return transformStyle() == FlattenTransform ; }
87 bool preserves3D() const { return transformStyle() == Preserve3D; }
trchen 2016/07/13 04:39:44 Ditto. It is a leak of CSS concept. I think flatte
chrishtr 2016/07/13 20:30:50 I don't understand this comment, could you rephras
jbroman 2016/07/13 21:47:13 This isn't the CSS concept, because it is not inte
trchen 2016/07/13 22:31:42 In that case, why not name it "flattensLocalToScre
trchen 2016/07/13 22:31:42 For example: <div style="transform-style:preserve
jbroman 2016/07/14 20:34:58 We can, and now this CL does. It does require some
88
36 private: 89 private:
90 TransformPaintPropertyNode(
91 const TransformationMatrix& matrix,
92 const FloatPoint3D& origin,
93 PassRefPtr<TransformPaintPropertyNode> parent,
94 RenderingContextBehavior renderingContextBehavior,
95 const TransformPaintPropertyNode* renderingContextRoot,
96 TransformStyle transformStyle)
97 : m_matrix(matrix)
98 , m_origin(origin)
99 , m_parent(parent)
100 , m_transformStyle(transformStyle)
101 {
102 switch (renderingContextBehavior) {
103 case DontEstablishNewRenderingContext:
104 m_renderingContextRoot = renderingContextRoot;
105 break;
106 case EstablishNewRenderingContext:
107 DCHECK(!renderingContextRoot);
108 m_renderingContextRoot = this;
109 break;
110 }
37 111
38 TransformPaintPropertyNode(const TransformationMatrix& matrix, const FloatPo int3D& origin, PassRefPtr<TransformPaintPropertyNode> parent) 112 // Every rendering context root must preserve 3D.
39 : m_matrix(matrix), m_origin(origin), m_parent(parent) { } 113 DCHECK(!m_renderingContextRoot || m_renderingContextRoot->preserves3D()) ;
114 }
40 115
41 const TransformationMatrix m_matrix; 116 const TransformationMatrix m_matrix;
42 const FloatPoint3D m_origin; 117 const FloatPoint3D m_origin;
43 RefPtr<TransformPaintPropertyNode> m_parent; 118 RefPtr<TransformPaintPropertyNode> m_parent;
119 const TransformPaintPropertyNode* m_renderingContextRoot;
120 const TransformStyle m_transformStyle;
44 }; 121 };
45 122
46 // Redeclared here to avoid ODR issues. 123 // Redeclared here to avoid ODR issues.
47 // See platform/testing/PaintPrinters.h. 124 // See platform/testing/PaintPrinters.h.
48 void PrintTo(const TransformPaintPropertyNode&, std::ostream*); 125 void PrintTo(const TransformPaintPropertyNode&, std::ostream*);
49 126
50 } // namespace blink 127 } // namespace blink
51 128
52 #endif // TransformPaintPropertyNode_h 129 #endif // TransformPaintPropertyNode_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698