Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/svg/SVGViewFrame.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
// Keep in (case-insensitive) order:
8
#include "nsFrame.h"
9
#include "nsGkAtoms.h"
10
#include "nsSVGOuterSVGFrame.h"
11
#include "mozilla/dom/SVGSVGElement.h"
12
#include "mozilla/dom/SVGViewElement.h"
13
14
using namespace mozilla::dom;
15
16
/**
17
 * While views are not directly rendered in SVG they can be linked to
18
 * and thereby override attributes of an <svg> element via a fragment
19
 * identifier. The SVGViewFrame class passes on any attribute changes
20
 * the view receives to the overridden <svg> element (if there is one).
21
 **/
22
class SVGViewFrame final : public nsFrame
23
{
24
  friend nsIFrame*
25
  NS_NewSVGViewFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle);
26
protected:
27
  explicit SVGViewFrame(ComputedStyle* aStyle)
28
    : nsFrame(aStyle, kClassID)
29
0
  {
30
0
    AddStateBits(NS_FRAME_IS_NONDISPLAY);
31
0
  }
32
33
public:
34
  NS_DECL_FRAMEARENA_HELPERS(SVGViewFrame)
35
36
#ifdef DEBUG
37
  virtual void Init(nsIContent*       aContent,
38
                    nsContainerFrame* aParent,
39
                    nsIFrame*         aPrevInFlow) override;
40
#endif
41
42
  virtual bool IsFrameOfType(uint32_t aFlags) const override
43
0
  {
44
0
    if (aFlags & eSupportsContainLayoutAndPaint) {
45
0
      return false;
46
0
    }
47
0
48
0
    return nsFrame::IsFrameOfType(aFlags & ~(nsIFrame::eSVG));
49
0
  }
50
51
#ifdef DEBUG_FRAME_DUMP
52
  virtual nsresult GetFrameName(nsAString& aResult) const override
53
  {
54
    return MakeFrameName(NS_LITERAL_STRING("SVGView"), aResult);
55
  }
56
#endif
57
58
  virtual nsresult AttributeChanged(int32_t  aNameSpaceID,
59
                                    nsAtom* aAttribute,
60
                                    int32_t  aModType) override;
61
62
0
  virtual bool ComputeCustomOverflow(nsOverflowAreas& aOverflowAreas) override {
63
0
    // We don't maintain a visual overflow rect
64
0
    return false;
65
0
  }
66
};
67
68
nsIFrame*
69
NS_NewSVGViewFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle)
70
0
{
71
0
  return new (aPresShell) SVGViewFrame(aStyle);
72
0
}
73
74
NS_IMPL_FRAMEARENA_HELPERS(SVGViewFrame)
75
76
#ifdef DEBUG
77
void
78
SVGViewFrame::Init(nsIContent*       aContent,
79
                   nsContainerFrame* aParent,
80
                   nsIFrame*         aPrevInFlow)
81
{
82
  NS_ASSERTION(aContent->IsSVGElement(nsGkAtoms::view),
83
               "Content is not an SVG view");
84
85
  nsFrame::Init(aContent, aParent, aPrevInFlow);
86
}
87
#endif /* DEBUG */
88
89
nsresult
90
SVGViewFrame::AttributeChanged(int32_t  aNameSpaceID,
91
                               nsAtom* aAttribute,
92
                               int32_t  aModType)
93
0
{
94
0
  // Ignore zoomAndPan as it does not cause the <svg> element to re-render
95
0
96
0
  if (aNameSpaceID == kNameSpaceID_None &&
97
0
      (aAttribute == nsGkAtoms::preserveAspectRatio ||
98
0
       aAttribute == nsGkAtoms::viewBox)) {
99
0
100
0
    nsSVGOuterSVGFrame *outerSVGFrame = nsSVGUtils::GetOuterSVGFrame(this);
101
0
    NS_ASSERTION(outerSVGFrame->GetContent()->IsSVGElement(nsGkAtoms::svg),
102
0
                 "Expecting an <svg> element");
103
0
104
0
    SVGSVGElement* svgElement =
105
0
      static_cast<SVGSVGElement*>(outerSVGFrame->GetContent());
106
0
107
0
    nsAutoString viewID;
108
0
    mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::id, viewID);
109
0
110
0
    if (svgElement->IsOverriddenBy(viewID)) {
111
0
      // We're the view that's providing overrides, so pretend that the frame
112
0
      // we're overriding was updated.
113
0
      outerSVGFrame->AttributeChanged(aNameSpaceID, aAttribute, aModType);
114
0
    }
115
0
  }
116
0
117
0
  return nsFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
118
0
}