1 /*
2  * Copyright (C) 2006 Apple Computer, Inc.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_SVG_LAYOUT_SVG_BLOCK_H_
21 #define THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_SVG_LAYOUT_SVG_BLOCK_H_
22 
23 #include "third_party/blink/renderer/core/layout/layout_block_flow.h"
24 
25 namespace blink {
26 
27 class SVGElement;
28 
29 // A common class of SVG objects that delegate layout, paint, etc. tasks to
30 // LayoutBlockFlow. It has two coordinate spaces:
31 // - local SVG coordinate space: similar to LayoutSVGModelObject, the space
32 //   that localSVGTransform() applies.
33 // - local HTML coordinate space: defined by frameRect() as if the local SVG
34 //   coordinate space created a containing block. Like other LayoutBlockFlow
35 //   objects, LayoutSVGBlock's frameRect() is also in physical coordinates with
36 //   flipped blocks direction in the "containing block".
37 class LayoutSVGBlock : public LayoutBlockFlow {
38  public:
39   explicit LayoutSVGBlock(SVGElement*);
40 
41   // These mapping functions map coordinates in HTML spaces.
42   void MapLocalToAncestor(const LayoutBoxModelObject* ancestor,
43                           TransformState&,
44                           MapCoordinatesFlags) const final;
45   void MapAncestorToLocal(const LayoutBoxModelObject* ancestor,
46                           TransformState&,
47                           MapCoordinatesFlags) const final;
48   const LayoutObject* PushMappingToContainer(
49       const LayoutBoxModelObject* ancestor_to_stop_at,
50       LayoutGeometryMap&) const final;
51 
LocalSVGTransform()52   AffineTransform LocalSVGTransform() const final { return local_transform_; }
53 
LayerTypeRequired()54   PaintLayerType LayerTypeRequired() const override { return kNoPaintLayer; }
55 
56   SVGElement* GetElement() const;
57 
58  protected:
59   void WillBeDestroyed() override;
60   bool MapToVisualRectInAncestorSpaceInternal(
61       const LayoutBoxModelObject* ancestor,
62       TransformState&,
63       VisualRectFlags = kDefaultVisualRectFlags) const final;
64 
65   AffineTransform local_transform_;
66 
IsOfType(LayoutObjectType type)67   bool IsOfType(LayoutObjectType type) const override {
68     return type == kLayoutObjectSVG || LayoutBlockFlow::IsOfType(type);
69   }
70 
71   void StyleDidChange(StyleDifference, const ComputedStyle* old_style) override;
72 
73  private:
74   // LayoutSVGBlock subclasses should use GetElement() instead.
75   void GetNode() const = delete;
76 
77   PhysicalRect VisualRectInDocument(VisualRectFlags) const final;
78 
79   void UpdateFromStyle() final;
80 
81   bool NodeAtPoint(HitTestResult&,
82                    const HitTestLocation&,
83                    const PhysicalOffset& accumulated_offset,
84                    HitTestAction) override;
85 };
86 
87 }  // namespace blink
88 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_LAYOUT_SVG_LAYOUT_SVG_BLOCK_H_
89