1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/generic/nsLeafFrame.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,118 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* base class for rendering objects that do not have child lists */ 1.10 + 1.11 +#include "nsLeafFrame.h" 1.12 +#include "nsPresContext.h" 1.13 + 1.14 +nsLeafFrame::~nsLeafFrame() 1.15 +{ 1.16 +} 1.17 + 1.18 +NS_IMPL_FRAMEARENA_HELPERS(nsLeafFrame) 1.19 + 1.20 +/* virtual */ nscoord 1.21 +nsLeafFrame::GetMinWidth(nsRenderingContext *aRenderingContext) 1.22 +{ 1.23 + nscoord result; 1.24 + DISPLAY_MIN_WIDTH(this, result); 1.25 + 1.26 + result = GetIntrinsicWidth(); 1.27 + return result; 1.28 +} 1.29 + 1.30 +/* virtual */ nscoord 1.31 +nsLeafFrame::GetPrefWidth(nsRenderingContext *aRenderingContext) 1.32 +{ 1.33 + nscoord result; 1.34 + DISPLAY_PREF_WIDTH(this, result); 1.35 + result = GetIntrinsicWidth(); 1.36 + return result; 1.37 +} 1.38 + 1.39 +/* virtual */ nsSize 1.40 +nsLeafFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext, 1.41 + nsSize aCBSize, nscoord aAvailableWidth, 1.42 + nsSize aMargin, nsSize aBorder, 1.43 + nsSize aPadding, bool aShrinkWrap) 1.44 +{ 1.45 + return nsSize(GetIntrinsicWidth(), GetIntrinsicHeight()); 1.46 +} 1.47 + 1.48 +nsresult 1.49 +nsLeafFrame::Reflow(nsPresContext* aPresContext, 1.50 + nsHTMLReflowMetrics& aMetrics, 1.51 + const nsHTMLReflowState& aReflowState, 1.52 + nsReflowStatus& aStatus) 1.53 +{ 1.54 + DO_GLOBAL_REFLOW_COUNT("nsLeafFrame"); 1.55 + NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, 1.56 + ("enter nsLeafFrame::Reflow: aMaxSize=%d,%d", 1.57 + aReflowState.AvailableWidth(), aReflowState.AvailableHeight())); 1.58 + 1.59 + NS_PRECONDITION(mState & NS_FRAME_IN_REFLOW, "frame is not in reflow"); 1.60 + 1.61 + DoReflow(aPresContext, aMetrics, aReflowState, aStatus); 1.62 + 1.63 + FinishAndStoreOverflow(&aMetrics); 1.64 + return NS_OK; 1.65 +} 1.66 + 1.67 +nsresult 1.68 +nsLeafFrame::DoReflow(nsPresContext* aPresContext, 1.69 + nsHTMLReflowMetrics& aMetrics, 1.70 + const nsHTMLReflowState& aReflowState, 1.71 + nsReflowStatus& aStatus) 1.72 +{ 1.73 + NS_ASSERTION(aReflowState.ComputedWidth() != NS_UNCONSTRAINEDSIZE, 1.74 + "Shouldn't have unconstrained stuff here " 1.75 + "Thanks to the rules of reflow"); 1.76 + NS_ASSERTION(NS_INTRINSICSIZE != aReflowState.ComputedHeight(), 1.77 + "Shouldn't have unconstrained stuff here " 1.78 + "thanks to ComputeAutoSize"); 1.79 + 1.80 + aMetrics.Width() = aReflowState.ComputedWidth(); 1.81 + aMetrics.Height() = aReflowState.ComputedHeight(); 1.82 + 1.83 + AddBordersAndPadding(aReflowState, aMetrics); 1.84 + aStatus = NS_FRAME_COMPLETE; 1.85 + 1.86 + NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS, 1.87 + ("exit nsLeafFrame::DoReflow: size=%d,%d", 1.88 + aMetrics.Width(), aMetrics.Height())); 1.89 + NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics); 1.90 + 1.91 + aMetrics.SetOverflowAreasToDesiredBounds(); 1.92 + 1.93 + return NS_OK; 1.94 +} 1.95 + 1.96 +nscoord 1.97 +nsLeafFrame::GetIntrinsicHeight() 1.98 +{ 1.99 + NS_NOTREACHED("Someone didn't override Reflow or ComputeAutoSize"); 1.100 + return 0; 1.101 +} 1.102 + 1.103 +// XXX how should border&padding effect baseline alignment? 1.104 +// => descent = borderPadding.bottom for example 1.105 +void 1.106 +nsLeafFrame::AddBordersAndPadding(const nsHTMLReflowState& aReflowState, 1.107 + nsHTMLReflowMetrics& aMetrics) 1.108 +{ 1.109 + aMetrics.Width() += aReflowState.ComputedPhysicalBorderPadding().LeftRight(); 1.110 + aMetrics.Height() += aReflowState.ComputedPhysicalBorderPadding().TopBottom(); 1.111 +} 1.112 + 1.113 +void 1.114 +nsLeafFrame::SizeToAvailSize(const nsHTMLReflowState& aReflowState, 1.115 + nsHTMLReflowMetrics& aDesiredSize) 1.116 +{ 1.117 + aDesiredSize.Width() = aReflowState.AvailableWidth(); // FRAME 1.118 + aDesiredSize.Height() = aReflowState.AvailableHeight(); 1.119 + aDesiredSize.SetOverflowAreasToDesiredBounds(); 1.120 + FinishAndStoreOverflow(&aDesiredSize); 1.121 +}