summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/svg/svg_text_positioning_element.cc
blob: caeca5c57bbf5030839c3950bfc77937c99fb904 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "third_party/blink/renderer/core/svg/svg_text_positioning_element.h"

#include "third_party/blink/renderer/core/layout/svg/layout_svg_text.h"
#include "third_party/blink/renderer/core/svg/svg_length_list.h"
#include "third_party/blink/renderer/core/svg/svg_number_list.h"
#include "third_party/blink/renderer/core/svg_names.h"
#include "third_party/blink/renderer/platform/heap/heap.h"

namespace blink {

SVGTextPositioningElement::SVGTextPositioningElement(
    const QualifiedName& tag_name,
    Document& document)
    : SVGTextContentElement(tag_name, document),
      x_(MakeGarbageCollected<SVGAnimatedLengthList>(
          this,
          svg_names::kXAttr,
          MakeGarbageCollected<SVGLengthList>(SVGLengthMode::kWidth))),
      y_(MakeGarbageCollected<SVGAnimatedLengthList>(
          this,
          svg_names::kYAttr,
          MakeGarbageCollected<SVGLengthList>(SVGLengthMode::kHeight))),
      dx_(MakeGarbageCollected<SVGAnimatedLengthList>(
          this,
          svg_names::kDxAttr,
          MakeGarbageCollected<SVGLengthList>(SVGLengthMode::kWidth))),
      dy_(MakeGarbageCollected<SVGAnimatedLengthList>(
          this,
          svg_names::kDyAttr,
          MakeGarbageCollected<SVGLengthList>(SVGLengthMode::kHeight))),
      rotate_(
          MakeGarbageCollected<SVGAnimatedNumberList>(this,
                                                      svg_names::kRotateAttr)) {
  AddToPropertyMap(x_);
  AddToPropertyMap(y_);
  AddToPropertyMap(dx_);
  AddToPropertyMap(dy_);
  AddToPropertyMap(rotate_);
}

void SVGTextPositioningElement::Trace(Visitor* visitor) const {
  visitor->Trace(x_);
  visitor->Trace(y_);
  visitor->Trace(dx_);
  visitor->Trace(dy_);
  visitor->Trace(rotate_);
  SVGTextContentElement::Trace(visitor);
}

void SVGTextPositioningElement::SvgAttributeChanged(
    const QualifiedName& attr_name) {
  bool update_relative_lengths =
      attr_name == svg_names::kXAttr || attr_name == svg_names::kYAttr ||
      attr_name == svg_names::kDxAttr || attr_name == svg_names::kDyAttr;

  if (update_relative_lengths)
    UpdateRelativeLengthsInformation();

  if (update_relative_lengths || attr_name == svg_names::kRotateAttr) {
    SVGElement::InvalidationGuard invalidation_guard(this);

    LayoutObject* layout_object = GetLayoutObject();
    if (!layout_object)
      return;

    if (LayoutSVGText* text_layout_object =
            LayoutSVGText::LocateLayoutSVGTextAncestor(layout_object))
      text_layout_object->SetNeedsPositioningValuesUpdate();
    MarkForLayoutAndParentResourceInvalidation(*layout_object);
    return;
  }

  SVGTextContentElement::SvgAttributeChanged(attr_name);
}

}  // namespace blink