layout/generic/nsLeafFrame.cpp

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:8960b69f0699
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/. */
5
6 /* base class for rendering objects that do not have child lists */
7
8 #include "nsLeafFrame.h"
9 #include "nsPresContext.h"
10
11 nsLeafFrame::~nsLeafFrame()
12 {
13 }
14
15 NS_IMPL_FRAMEARENA_HELPERS(nsLeafFrame)
16
17 /* virtual */ nscoord
18 nsLeafFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
19 {
20 nscoord result;
21 DISPLAY_MIN_WIDTH(this, result);
22
23 result = GetIntrinsicWidth();
24 return result;
25 }
26
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 }
35
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 }
44
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()));
55
56 NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow");
57
58 DoReflow(aPresContext, aMetrics, aReflowState, aStatus);
59
60 FinishAndStoreOverflow(&aMetrics);
61 return NS_OK;
62 }
63
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");
76
77 aMetrics.Width() = aReflowState.ComputedWidth();
78 aMetrics.Height() = aReflowState.ComputedHeight();
79
80 AddBordersAndPadding(aReflowState, aMetrics);
81 aStatus = NS_FRAME_COMPLETE;
82
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);
87
88 aMetrics.SetOverflowAreasToDesiredBounds();
89
90 return NS_OK;
91 }
92
93 nscoord
94 nsLeafFrame::GetIntrinsicHeight()
95 {
96 NS_NOTREACHED("Someone didn't override Reflow or ComputeAutoSize");
97 return 0;
98 }
99
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 }
109
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 }

mercurial