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 /* rendering object for CSS "::backdrop" */
8 
9 #include "nsBackdropFrame.h"
10 
11 #include "nsDisplayList.h"
12 
13 using namespace mozilla;
14 
NS_IMPL_FRAMEARENA_HELPERS(nsBackdropFrame)15 NS_IMPL_FRAMEARENA_HELPERS(nsBackdropFrame)
16 
17 #ifdef DEBUG_FRAME_DUMP
18 nsresult nsBackdropFrame::GetFrameName(nsAString& aResult) const {
19   return MakeFrameName(NS_LITERAL_STRING("Backdrop"), aResult);
20 }
21 #endif
22 
23 /* virtual */
GetParentComputedStyle(nsIFrame ** aProviderFrame) const24 ComputedStyle* nsBackdropFrame::GetParentComputedStyle(
25     nsIFrame** aProviderFrame) const {
26   // Style context of backdrop pseudo-element does not inherit from
27   // any element, per the Fullscreen API spec.
28   *aProviderFrame = nullptr;
29   return nullptr;
30 }
31 
32 /* virtual */
BuildDisplayList(nsDisplayListBuilder * aBuilder,const nsDisplayListSet & aLists)33 void nsBackdropFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
34                                        const nsDisplayListSet& aLists) {
35   DO_GLOBAL_REFLOW_COUNT_DSP("nsBackdropFrame");
36   // We want this frame to always be there even if its display value is
37   // none or contents so that we can respond to style change on it. To
38   // support those values, we skip painting ourselves in those cases.
39   auto display = StyleDisplay()->mDisplay;
40   if (display == mozilla::StyleDisplay::None ||
41       display == mozilla::StyleDisplay::Contents) {
42     return;
43   }
44 
45   DisplayBorderBackgroundOutline(aBuilder, aLists);
46 }
47 
48 /* virtual */
ComputeAutoSize(gfxContext * aRenderingContext,WritingMode aWM,const LogicalSize & aCBSize,nscoord aAvailableISize,const LogicalSize & aMargin,const LogicalSize & aBorder,const LogicalSize & aPadding,ComputeSizeFlags aFlags)49 LogicalSize nsBackdropFrame::ComputeAutoSize(
50     gfxContext* aRenderingContext, WritingMode aWM, const LogicalSize& aCBSize,
51     nscoord aAvailableISize, const LogicalSize& aMargin,
52     const LogicalSize& aBorder, const LogicalSize& aPadding,
53     ComputeSizeFlags aFlags) {
54   // Note that this frame is a child of the viewport frame.
55   LogicalSize result(aWM, 0xdeadbeef, NS_UNCONSTRAINEDSIZE);
56   if (aFlags & ComputeSizeFlags::eShrinkWrap) {
57     result.ISize(aWM) = 0;
58   } else {
59     result.ISize(aWM) = aAvailableISize - aMargin.ISize(aWM) -
60                         aBorder.ISize(aWM) - aPadding.ISize(aWM);
61   }
62   return result;
63 }
64 
65 /* virtual */
Reflow(nsPresContext * aPresContext,ReflowOutput & aDesiredSize,const ReflowInput & aReflowInput,nsReflowStatus & aStatus)66 void nsBackdropFrame::Reflow(nsPresContext* aPresContext,
67                              ReflowOutput& aDesiredSize,
68                              const ReflowInput& aReflowInput,
69                              nsReflowStatus& aStatus) {
70   MarkInReflow();
71   DO_GLOBAL_REFLOW_COUNT("nsBackdropFrame");
72   DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
73   MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
74 
75   // Note that this frame is a child of the viewport frame.
76   WritingMode wm = aReflowInput.GetWritingMode();
77   LogicalMargin borderPadding = aReflowInput.ComputedLogicalBorderPadding();
78   nscoord isize = aReflowInput.ComputedISize() + borderPadding.IStartEnd(wm);
79   nscoord bsize = aReflowInput.ComputedBSize() + borderPadding.BStartEnd(wm);
80   aDesiredSize.SetSize(wm, LogicalSize(wm, isize, bsize));
81 }
82