Backed out changeset 2960ea3e50ca (bug 1881157) for causing crashtest assertion failu...
[gecko.git] / layout / svg / DisplaySVGItem.cpp
blobdfc77c674703e3a8500b9970ed1d41f25197a8ac
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/. */
7 // Main header first:
8 #include "DisplaySVGItem.h"
10 #include "mozilla/ISVGDisplayableFrame.h"
11 #include "mozilla/SVGUtils.h"
12 #include "nsLayoutUtils.h"
13 #include "nsPoint.h"
15 using namespace mozilla::gfx;
16 using namespace mozilla::image;
18 namespace mozilla {
20 void DisplaySVGItem::HitTest(nsDisplayListBuilder* aBuilder,
21 const nsRect& aRect, HitTestState* aState,
22 nsTArray<nsIFrame*>* aOutFrames) {
23 ISVGDisplayableFrame* svgFrame = do_QueryFrame(mFrame);
24 MOZ_ASSERT(svgFrame, "Unexpected frame type");
26 nsPoint pointRelativeToReferenceFrame = aRect.Center();
27 // ToReferenceFrame() includes mFrame->GetPosition(), our user
28 // space position.
29 nsPoint userSpacePtInAppUnits = pointRelativeToReferenceFrame -
30 (ToReferenceFrame() - mFrame->GetPosition());
31 gfxPoint userSpacePt =
32 gfxPoint(userSpacePtInAppUnits.x, userSpacePtInAppUnits.y) /
33 AppUnitsPerCSSPixel();
34 if (auto* target = svgFrame->GetFrameForPoint(userSpacePt)) {
35 aOutFrames->AppendElement(target);
39 void DisplaySVGItem::Paint(nsDisplayListBuilder* aBuilder, gfxContext* aCtx) {
40 ISVGDisplayableFrame* svgFrame = do_QueryFrame(mFrame);
41 MOZ_ASSERT(svgFrame, "Unexpected frame type");
42 int32_t appUnitsPerDevPixel = mFrame->PresContext()->AppUnitsPerDevPixel();
44 // ToReferenceFrame() includes our mRect offset, but painting takes
45 // account of that too. To avoid double counting, we subtract that
46 // here.
47 nsPoint offset = ToReferenceFrame() - mFrame->GetPosition();
49 gfxPoint devPixelOffset =
50 nsLayoutUtils::PointToGfxPoint(offset, appUnitsPerDevPixel);
52 gfxMatrix tm = SVGUtils::GetCSSPxToDevPxMatrix(mFrame) *
53 gfxMatrix::Translation(devPixelOffset);
54 imgDrawingParams imgParams(aBuilder->GetImageDecodeFlags());
55 svgFrame->PaintSVG(*aCtx, tm, imgParams);
58 } // namespace mozilla