Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /* base class for rendering objects that do not have child lists */
8 #include "nsLeafFrame.h"
9 #include "nsPresContext.h"
11 nsLeafFrame::~nsLeafFrame()
12 {
13 }
15 NS_IMPL_FRAMEARENA_HELPERS(nsLeafFrame)
17 /* virtual */ nscoord
18 nsLeafFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
19 {
20 nscoord result;
21 DISPLAY_MIN_WIDTH(this, result);
23 result = GetIntrinsicWidth();
24 return result;
25 }
27 /* virtual */ nscoord
28 nsLeafFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
29 {
30 nscoord result;
31 DISPLAY_PREF_WIDTH(this, result);
32 result = GetIntrinsicWidth();
33 return result;
34 }
36 /* virtual */ nsSize
37 nsLeafFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
38 nsSize aCBSize, nscoord aAvailableWidth,
39 nsSize aMargin, nsSize aBorder,
40 nsSize aPadding, bool aShrinkWrap)
41 {
42 return nsSize(GetIntrinsicWidth(), GetIntrinsicHeight());
43 }
45 nsresult
46 nsLeafFrame::Reflow(nsPresContext* aPresContext,
47 nsHTMLReflowMetrics& aMetrics,
48 const nsHTMLReflowState& aReflowState,
49 nsReflowStatus& aStatus)
50 {
51 DO_GLOBAL_REFLOW_COUNT("nsLeafFrame");
52 NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
53 ("enter nsLeafFrame::Reflow: aMaxSize=%d,%d",
54 aReflowState.AvailableWidth(), aReflowState.AvailableHeight()));
56 NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
58 DoReflow(aPresContext, aMetrics, aReflowState, aStatus);
60 FinishAndStoreOverflow(&aMetrics);
61 return NS_OK;
62 }
64 nsresult
65 nsLeafFrame::DoReflow(nsPresContext* aPresContext,
66 nsHTMLReflowMetrics& aMetrics,
67 const nsHTMLReflowState& aReflowState,
68 nsReflowStatus& aStatus)
69 {
70 NS_ASSERTION(aReflowState.ComputedWidth() != NS_UNCONSTRAINEDSIZE,
71 "Shouldn't have unconstrained stuff here "
72 "Thanks to the rules of reflow");
73 NS_ASSERTION(NS_INTRINSICSIZE != aReflowState.ComputedHeight(),
74 "Shouldn't have unconstrained stuff here "
75 "thanks to ComputeAutoSize");
77 aMetrics.Width() = aReflowState.ComputedWidth();
78 aMetrics.Height() = aReflowState.ComputedHeight();
80 AddBordersAndPadding(aReflowState, aMetrics);
81 aStatus = NS_FRAME_COMPLETE;
83 NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
84 ("exit nsLeafFrame::DoReflow: size=%d,%d",
85 aMetrics.Width(), aMetrics.Height()));
86 NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
88 aMetrics.SetOverflowAreasToDesiredBounds();
90 return NS_OK;
91 }
93 nscoord
94 nsLeafFrame::GetIntrinsicHeight()
95 {
96 NS_NOTREACHED("Someone didn't override Reflow or ComputeAutoSize");
97 return 0;
98 }
100 // XXX how should border&padding effect baseline alignment?
101 // => descent = borderPadding.bottom for example
102 void
103 nsLeafFrame::AddBordersAndPadding(const nsHTMLReflowState& aReflowState,
104 nsHTMLReflowMetrics& aMetrics)
105 {
106 aMetrics.Width() += aReflowState.ComputedPhysicalBorderPadding().LeftRight();
107 aMetrics.Height() += aReflowState.ComputedPhysicalBorderPadding().TopBottom();
108 }
110 void
111 nsLeafFrame::SizeToAvailSize(const nsHTMLReflowState& aReflowState,
112 nsHTMLReflowMetrics& aDesiredSize)
113 {
114 aDesiredSize.Width() = aReflowState.AvailableWidth(); // FRAME
115 aDesiredSize.Height() = aReflowState.AvailableHeight();
116 aDesiredSize.SetOverflowAreasToDesiredBounds();
117 FinishAndStoreOverflow(&aDesiredSize);
118 }