Backout a74bd5095902, Bug 959405 - Please update the Buri Moz-central, 1.3, 1.2 with...
[gecko.git] / layout / forms / nsFieldSetFrame.cpp
blobeeb582ce0ac8b4157115f9db7002d896bee2ee4d
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 #include "nsCSSAnonBoxes.h"
7 #include "nsContainerFrame.h"
8 #include "nsLegendFrame.h"
9 #include "nsCSSRendering.h"
10 #include <algorithm>
11 #include "nsIFrame.h"
12 #include "nsPresContext.h"
13 #include "RestyleManager.h"
14 #include "nsGkAtoms.h"
15 #include "nsStyleConsts.h"
16 #include "nsDisplayList.h"
17 #include "nsRenderingContext.h"
18 #include "nsIScrollableFrame.h"
19 #include "mozilla/Likely.h"
20 #include "mozilla/Maybe.h"
22 using namespace mozilla;
23 using namespace mozilla::layout;
25 class nsFieldSetFrame MOZ_FINAL : public nsContainerFrame {
26 public:
27 NS_DECL_FRAMEARENA_HELPERS
29 nsFieldSetFrame(nsStyleContext* aContext);
31 NS_HIDDEN_(nscoord)
32 GetIntrinsicWidth(nsRenderingContext* aRenderingContext,
33 nsLayoutUtils::IntrinsicWidthType);
34 virtual nscoord GetMinWidth(nsRenderingContext* aRenderingContext);
35 virtual nscoord GetPrefWidth(nsRenderingContext* aRenderingContext);
36 virtual nsSize ComputeSize(nsRenderingContext *aRenderingContext,
37 nsSize aCBSize, nscoord aAvailableWidth,
38 nsSize aMargin, nsSize aBorder, nsSize aPadding,
39 uint32_t aFlags) MOZ_OVERRIDE;
40 virtual nscoord GetBaseline() const;
42 /**
43 * The area to paint box-shadows around. It's the border rect except
44 * when there's a <legend> we offset the y-position to the center of it.
46 virtual nsRect VisualBorderRectRelativeToSelf() const MOZ_OVERRIDE {
47 nscoord topBorder = StyleBorder()->GetComputedBorderWidth(NS_SIDE_TOP);
48 nsRect r(nsPoint(0,0), GetSize());
49 if (topBorder < mLegendRect.height) {
50 nscoord yoff = (mLegendRect.height - topBorder) / 2;
51 r.y += yoff;
52 r.height -= yoff;
54 return r;
57 NS_IMETHOD Reflow(nsPresContext* aPresContext,
58 nsHTMLReflowMetrics& aDesiredSize,
59 const nsHTMLReflowState& aReflowState,
60 nsReflowStatus& aStatus);
62 virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
63 const nsRect& aDirtyRect,
64 const nsDisplayListSet& aLists) MOZ_OVERRIDE;
66 void PaintBorderBackground(nsRenderingContext& aRenderingContext,
67 nsPoint aPt, const nsRect& aDirtyRect, uint32_t aBGFlags);
69 NS_IMETHOD AppendFrames(ChildListID aListID,
70 nsFrameList& aFrameList);
71 NS_IMETHOD InsertFrames(ChildListID aListID,
72 nsIFrame* aPrevFrame,
73 nsFrameList& aFrameList);
74 NS_IMETHOD RemoveFrame(ChildListID aListID,
75 nsIFrame* aOldFrame);
77 virtual nsIAtom* GetType() const;
78 virtual bool IsFrameOfType(uint32_t aFlags) const
80 return nsContainerFrame::IsFrameOfType(aFlags &
81 ~nsIFrame::eCanContainOverflowContainers);
83 virtual nsIScrollableFrame* GetScrollTargetFrame() MOZ_OVERRIDE
85 return do_QueryFrame(GetInner());
88 #ifdef ACCESSIBILITY
89 virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
90 #endif
92 #ifdef DEBUG
93 NS_IMETHOD SetInitialChildList(ChildListID aListID,
94 nsFrameList& aChildList);
95 #endif
97 #ifdef DEBUG_FRAME_DUMP
98 NS_IMETHOD GetFrameName(nsAString& aResult) const {
99 return MakeFrameName(NS_LITERAL_STRING("FieldSet"), aResult);
101 #endif
103 protected:
106 * Return the anonymous frame that contains all descendants except
107 * the legend frame. This is currently always a block frame with
108 * pseudo nsCSSAnonBoxes::fieldsetContent -- this may change in the
109 * future when we add support for CSS overflow for <fieldset>.
111 nsIFrame* GetInner() const
113 nsIFrame* last = mFrames.LastChild();
114 if (last &&
115 last->StyleContext()->GetPseudo() == nsCSSAnonBoxes::fieldsetContent) {
116 return last;
118 MOZ_ASSERT(mFrames.LastChild() == mFrames.FirstChild());
119 return nullptr;
123 * Return the frame that represents the legend if any. This may be
124 * a nsLegendFrame or a nsHTMLScrollFrame with the nsLegendFrame as the
125 * scrolled frame (aka content insertion frame).
127 nsIFrame* GetLegend() const
129 if (mFrames.FirstChild() == GetInner()) {
130 MOZ_ASSERT(mFrames.LastChild() == mFrames.FirstChild());
131 return nullptr;
133 MOZ_ASSERT(mFrames.FirstChild() &&
134 mFrames.FirstChild()->GetContentInsertionFrame()->GetType() ==
135 nsGkAtoms::legendFrame);
136 return mFrames.FirstChild();
139 nsRect mLegendRect;
140 nscoord mLegendSpace;
143 nsIFrame*
144 NS_NewFieldSetFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
146 return new (aPresShell) nsFieldSetFrame(aContext);
149 NS_IMPL_FRAMEARENA_HELPERS(nsFieldSetFrame)
151 nsFieldSetFrame::nsFieldSetFrame(nsStyleContext* aContext)
152 : nsContainerFrame(aContext)
154 mLegendSpace = 0;
157 nsIAtom*
158 nsFieldSetFrame::GetType() const
160 return nsGkAtoms::fieldSetFrame;
163 #ifdef DEBUG
164 NS_IMETHODIMP
165 nsFieldSetFrame::SetInitialChildList(ChildListID aListID,
166 nsFrameList& aChildList)
168 nsresult rv = nsContainerFrame::SetInitialChildList(kPrincipalList, aChildList);
169 MOZ_ASSERT(GetInner());
170 return rv;
172 #endif
174 class nsDisplayFieldSetBorderBackground : public nsDisplayItem {
175 public:
176 nsDisplayFieldSetBorderBackground(nsDisplayListBuilder* aBuilder,
177 nsFieldSetFrame* aFrame)
178 : nsDisplayItem(aBuilder, aFrame) {
179 MOZ_COUNT_CTOR(nsDisplayFieldSetBorderBackground);
181 #ifdef NS_BUILD_REFCNT_LOGGING
182 virtual ~nsDisplayFieldSetBorderBackground() {
183 MOZ_COUNT_DTOR(nsDisplayFieldSetBorderBackground);
185 #endif
187 virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
188 HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames);
189 virtual void Paint(nsDisplayListBuilder* aBuilder,
190 nsRenderingContext* aCtx);
191 virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
192 const nsDisplayItemGeometry* aGeometry,
193 nsRegion *aInvalidRegion) MOZ_OVERRIDE;
194 NS_DISPLAY_DECL_NAME("FieldSetBorderBackground", TYPE_FIELDSET_BORDER_BACKGROUND)
197 void nsDisplayFieldSetBorderBackground::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
198 HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
200 // aPt is guaranteed to be in this item's bounds. We do the hit test based on the
201 // frame bounds even though our background doesn't cover the whole frame.
202 // It's not clear whether this is correct.
203 aOutFrames->AppendElement(mFrame);
206 void
207 nsDisplayFieldSetBorderBackground::Paint(nsDisplayListBuilder* aBuilder,
208 nsRenderingContext* aCtx)
210 static_cast<nsFieldSetFrame*>(mFrame)->
211 PaintBorderBackground(*aCtx, ToReferenceFrame(),
212 mVisibleRect, aBuilder->GetBackgroundPaintFlags());
215 void
216 nsDisplayFieldSetBorderBackground::ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
217 const nsDisplayItemGeometry* aGeometry,
218 nsRegion *aInvalidRegion)
220 AddInvalidRegionForSyncDecodeBackgroundImages(aBuilder, aGeometry, aInvalidRegion);
222 nsDisplayItem::ComputeInvalidationRegion(aBuilder, aGeometry, aInvalidRegion);
225 void
226 nsFieldSetFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
227 const nsRect& aDirtyRect,
228 const nsDisplayListSet& aLists) {
229 // Paint our background and border in a special way.
230 // REVIEW: We don't really need to check frame emptiness here; if it's empty,
231 // the background/border display item won't do anything, and if it isn't empty,
232 // we need to paint the outline
233 if (!(GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER) &&
234 IsVisibleForPainting(aBuilder)) {
235 if (StyleBorder()->mBoxShadow) {
236 aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
237 nsDisplayBoxShadowOuter(aBuilder, this));
240 // don't bother checking to see if we really have a border or background.
241 // we usually will have a border.
242 aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
243 nsDisplayFieldSetBorderBackground(aBuilder, this));
245 DisplayOutlineUnconditional(aBuilder, aLists);
247 DO_GLOBAL_REFLOW_COUNT_DSP("nsFieldSetFrame");
250 if (GetPrevInFlow()) {
251 DisplayOverflowContainers(aBuilder, aDirtyRect, aLists);
254 nsDisplayListCollection contentDisplayItems;
255 if (nsIFrame* inner = GetInner()) {
256 // Collect the inner frame's display items into their own collection.
257 // We need to be calling BuildDisplayList on it before the legend in
258 // case it contains out-of-flow frames whose placeholders are in the
259 // legend. However, we want the inner frame's display items to be
260 // after the legend's display items in z-order, so we need to save them
261 // and append them later.
262 BuildDisplayListForChild(aBuilder, inner, aDirtyRect, contentDisplayItems);
264 if (nsIFrame* legend = GetLegend()) {
265 // The legend's background goes on our BlockBorderBackgrounds list because
266 // it's a block child.
267 nsDisplayListSet set(aLists, aLists.BlockBorderBackgrounds());
268 BuildDisplayListForChild(aBuilder, legend, aDirtyRect, set);
270 // Put the inner frame's display items on the master list. Note that this
271 // moves its border/background display items to our BorderBackground() list,
272 // which isn't really correct, but it's OK because the inner frame is
273 // anonymous and can't have its own border and background.
274 contentDisplayItems.MoveTo(aLists);
277 void
278 nsFieldSetFrame::PaintBorderBackground(nsRenderingContext& aRenderingContext,
279 nsPoint aPt, const nsRect& aDirtyRect, uint32_t aBGFlags)
281 // if the border is smaller than the legend. Move the border down
282 // to be centered on the legend.
283 // FIXME: This means border-radius clamping is incorrect; we should
284 // override nsIFrame::GetBorderRadii.
285 nsRect rect = VisualBorderRectRelativeToSelf();
286 nscoord yoff = rect.y;
287 rect += aPt;
288 nsPresContext* presContext = PresContext();
290 nsCSSRendering::PaintBackground(presContext, aRenderingContext, this,
291 aDirtyRect, rect, aBGFlags);
293 nsCSSRendering::PaintBoxShadowInner(presContext, aRenderingContext,
294 this, rect, aDirtyRect);
296 if (nsIFrame* legend = GetLegend()) {
297 nscoord topBorder = StyleBorder()->GetComputedBorderWidth(NS_SIDE_TOP);
299 // Use the rect of the legend frame, not mLegendRect, so we draw our
300 // border under the legend's left and right margins.
301 nsRect legendRect = legend->GetRect() + aPt;
303 // we should probably use PaintBorderEdges to do this but for now just use clipping
304 // to achieve the same effect.
306 // draw left side
307 nsRect clipRect(rect);
308 clipRect.width = legendRect.x - rect.x;
309 clipRect.height = topBorder;
311 aRenderingContext.PushState();
312 aRenderingContext.IntersectClip(clipRect);
313 nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
314 aDirtyRect, rect, mStyleContext);
316 aRenderingContext.PopState();
319 // draw right side
320 clipRect = rect;
321 clipRect.x = legendRect.XMost();
322 clipRect.width = rect.XMost() - legendRect.XMost();
323 clipRect.height = topBorder;
325 aRenderingContext.PushState();
326 aRenderingContext.IntersectClip(clipRect);
327 nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
328 aDirtyRect, rect, mStyleContext);
330 aRenderingContext.PopState();
333 // draw bottom
334 clipRect = rect;
335 clipRect.y += topBorder;
336 clipRect.height = mRect.height - (yoff + topBorder);
338 aRenderingContext.PushState();
339 aRenderingContext.IntersectClip(clipRect);
340 nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
341 aDirtyRect, rect, mStyleContext);
343 aRenderingContext.PopState();
344 } else {
346 nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
347 aDirtyRect,
348 nsRect(aPt, mRect.Size()),
349 mStyleContext);
353 nscoord
354 nsFieldSetFrame::GetIntrinsicWidth(nsRenderingContext* aRenderingContext,
355 nsLayoutUtils::IntrinsicWidthType aType)
357 nscoord legendWidth = 0;
358 nscoord contentWidth = 0;
359 if (nsIFrame* legend = GetLegend()) {
360 legendWidth =
361 nsLayoutUtils::IntrinsicForContainer(aRenderingContext, legend, aType);
364 if (nsIFrame* inner = GetInner()) {
365 // Ignore padding on the inner, since the padding will be applied to the
366 // outer instead, and the padding computed for the inner is wrong
367 // for percentage padding.
368 contentWidth =
369 nsLayoutUtils::IntrinsicForContainer(aRenderingContext, inner, aType,
370 nsLayoutUtils::IGNORE_PADDING);
373 return std::max(legendWidth, contentWidth);
377 nscoord
378 nsFieldSetFrame::GetMinWidth(nsRenderingContext* aRenderingContext)
380 nscoord result = 0;
381 DISPLAY_MIN_WIDTH(this, result);
383 result = GetIntrinsicWidth(aRenderingContext, nsLayoutUtils::MIN_WIDTH);
384 return result;
387 nscoord
388 nsFieldSetFrame::GetPrefWidth(nsRenderingContext* aRenderingContext)
390 nscoord result = 0;
391 DISPLAY_PREF_WIDTH(this, result);
393 result = GetIntrinsicWidth(aRenderingContext, nsLayoutUtils::PREF_WIDTH);
394 return result;
397 /* virtual */ nsSize
398 nsFieldSetFrame::ComputeSize(nsRenderingContext *aRenderingContext,
399 nsSize aCBSize, nscoord aAvailableWidth,
400 nsSize aMargin, nsSize aBorder, nsSize aPadding,
401 uint32_t aFlags)
403 nsSize result =
404 nsContainerFrame::ComputeSize(aRenderingContext, aCBSize, aAvailableWidth,
405 aMargin, aBorder, aPadding, aFlags);
407 // Fieldsets never shrink below their min width.
409 // If we're a container for font size inflation, then shrink
410 // wrapping inside of us should not apply font size inflation.
411 AutoMaybeDisableFontInflation an(this);
413 nscoord minWidth = GetMinWidth(aRenderingContext);
414 if (minWidth > result.width)
415 result.width = minWidth;
417 return result;
420 NS_IMETHODIMP
421 nsFieldSetFrame::Reflow(nsPresContext* aPresContext,
422 nsHTMLReflowMetrics& aDesiredSize,
423 const nsHTMLReflowState& aReflowState,
424 nsReflowStatus& aStatus)
426 DO_GLOBAL_REFLOW_COUNT("nsFieldSetFrame");
427 DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
429 NS_PRECONDITION(aReflowState.ComputedWidth() != NS_INTRINSICSIZE,
430 "Should have a precomputed width!");
432 // Initialize OUT parameter
433 aStatus = NS_FRAME_COMPLETE;
435 nsOverflowAreas ocBounds;
436 nsReflowStatus ocStatus = NS_FRAME_COMPLETE;
437 if (GetPrevInFlow()) {
438 ReflowOverflowContainerChildren(aPresContext, aReflowState, ocBounds, 0,
439 ocStatus);
442 //------------ Handle Incremental Reflow -----------------
443 bool reflowInner;
444 bool reflowLegend;
445 nsIFrame* legend = GetLegend();
446 nsIFrame* inner = GetInner();
447 if (aReflowState.ShouldReflowAllKids()) {
448 reflowInner = inner != nullptr;
449 reflowLegend = legend != nullptr;
450 } else {
451 reflowInner = inner && NS_SUBTREE_DIRTY(inner);
452 reflowLegend = legend && NS_SUBTREE_DIRTY(legend);
455 // We don't allow fieldsets to break vertically. If we did, we'd
456 // need logic here to push and pull overflow frames.
457 // Since we're not applying our padding in this frame, we need to add it here
458 // to compute the available width for our children.
459 nsSize availSize(aReflowState.ComputedWidth() + aReflowState.ComputedPhysicalPadding().LeftRight(),
460 NS_UNCONSTRAINEDSIZE);
461 NS_ASSERTION(!inner ||
462 nsLayoutUtils::IntrinsicForContainer(aReflowState.rendContext,
463 inner,
464 nsLayoutUtils::MIN_WIDTH) <=
465 availSize.width,
466 "Bogus availSize.width; should be bigger");
467 NS_ASSERTION(!legend ||
468 nsLayoutUtils::IntrinsicForContainer(aReflowState.rendContext,
469 legend,
470 nsLayoutUtils::MIN_WIDTH) <=
471 availSize.width,
472 "Bogus availSize.width; should be bigger");
474 // get our border and padding
475 nsMargin border = aReflowState.ComputedPhysicalBorderPadding() - aReflowState.ComputedPhysicalPadding();
477 // Figure out how big the legend is if there is one.
478 // get the legend's margin
479 nsMargin legendMargin(0,0,0,0);
480 // reflow the legend only if needed
481 Maybe<nsHTMLReflowState> legendReflowState;
482 if (legend) {
483 legendReflowState.construct(aPresContext, aReflowState, legend, availSize);
485 if (reflowLegend) {
486 nsHTMLReflowMetrics legendDesiredSize(aReflowState.GetWritingMode());
488 ReflowChild(legend, aPresContext, legendDesiredSize, legendReflowState.ref(),
489 0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);
490 #ifdef NOISY_REFLOW
491 printf(" returned (%d, %d)\n", legendDesiredSize.Width(), legendDesiredSize.Height());
492 #endif
493 // figure out the legend's rectangle
494 legendMargin = legend->GetUsedMargin();
495 mLegendRect.width = legendDesiredSize.Width() + legendMargin.left + legendMargin.right;
496 mLegendRect.height = legendDesiredSize.Height() + legendMargin.top + legendMargin.bottom;
497 mLegendRect.x = 0;
498 mLegendRect.y = 0;
500 nscoord oldSpace = mLegendSpace;
501 mLegendSpace = 0;
502 if (mLegendRect.height > border.top) {
503 // center the border on the legend
504 mLegendSpace = mLegendRect.height - border.top;
505 } else {
506 mLegendRect.y = (border.top - mLegendRect.height)/2;
509 // if the legend space changes then we need to reflow the
510 // content area as well.
511 if (mLegendSpace != oldSpace && inner) {
512 reflowInner = true;
515 FinishReflowChild(legend, aPresContext, &legendReflowState.ref(),
516 legendDesiredSize, 0, 0, NS_FRAME_NO_MOVE_FRAME);
517 } else if (!legend) {
518 mLegendRect.SetEmpty();
519 mLegendSpace = 0;
520 } else {
521 // mLegendSpace and mLegendRect haven't changed, but we need
522 // the used margin when placing the legend.
523 legendMargin = legend->GetUsedMargin();
526 // reflow the content frame only if needed
527 if (reflowInner) {
528 nsHTMLReflowState kidReflowState(aPresContext, aReflowState, inner,
529 availSize, -1, -1, nsHTMLReflowState::CALLER_WILL_INIT);
530 // Override computed padding, in case it's percentage padding
531 kidReflowState.Init(aPresContext, -1, -1, nullptr,
532 &aReflowState.ComputedPhysicalPadding());
533 // Our child is "height:100%" but we actually want its height to be reduced
534 // by the amount of content-height the legend is eating up, unless our
535 // height is unconstrained (in which case the child's will be too).
536 if (aReflowState.ComputedHeight() != NS_UNCONSTRAINEDSIZE) {
537 kidReflowState.SetComputedHeight(
538 std::max(0, aReflowState.ComputedHeight() - mLegendSpace));
541 if (aReflowState.ComputedMinHeight() > 0) {
542 kidReflowState.ComputedMinHeight() =
543 std::max(0, aReflowState.ComputedMinHeight() - mLegendSpace);
546 if (aReflowState.ComputedMaxHeight() != NS_UNCONSTRAINEDSIZE) {
547 kidReflowState.ComputedMaxHeight() =
548 std::max(0, aReflowState.ComputedMaxHeight() - mLegendSpace);
551 nsHTMLReflowMetrics kidDesiredSize(kidReflowState.GetWritingMode(),
552 aDesiredSize.mFlags);
553 // Reflow the frame
554 NS_ASSERTION(kidReflowState.ComputedPhysicalMargin() == nsMargin(0,0,0,0),
555 "Margins on anonymous fieldset child not supported!");
556 nsPoint pt(border.left, border.top + mLegendSpace);
557 ReflowChild(inner, aPresContext, kidDesiredSize, kidReflowState,
558 pt.x, pt.y, 0, aStatus);
560 FinishReflowChild(inner, aPresContext, &kidReflowState,
561 kidDesiredSize, pt.x, pt.y, 0);
562 NS_FRAME_TRACE_REFLOW_OUT("FieldSet::Reflow", aStatus);
565 nsRect contentRect;
566 if (inner) {
567 // We don't support margins on inner, so our content rect is just the
568 // inner's border-box.
569 contentRect = inner->GetRect();
572 // Our content rect must fill up the available width
573 if (availSize.width > contentRect.width) {
574 contentRect.width = availSize.width;
577 if (legend) {
578 // the legend is postioned horizontally within the inner's content rect
579 // (so that padding on the fieldset affects the legend position).
580 nsRect innerContentRect = contentRect;
581 innerContentRect.Deflate(aReflowState.ComputedPhysicalPadding());
582 // if the inner content rect is larger than the legend, we can align the legend
583 if (innerContentRect.width > mLegendRect.width) {
584 int32_t align = static_cast<nsLegendFrame*>
585 (legend->GetContentInsertionFrame())->GetAlign();
587 switch (align) {
588 case NS_STYLE_TEXT_ALIGN_RIGHT:
589 mLegendRect.x = innerContentRect.XMost() - mLegendRect.width;
590 break;
591 case NS_STYLE_TEXT_ALIGN_CENTER:
592 // Note: rounding removed; there doesn't seem to be any need
593 mLegendRect.x = innerContentRect.width / 2 - mLegendRect.width / 2 + innerContentRect.x;
594 break;
595 default:
596 mLegendRect.x = innerContentRect.x;
597 break;
599 } else {
600 // otherwise make place for the legend
601 mLegendRect.x = innerContentRect.x;
602 innerContentRect.width = mLegendRect.width;
603 contentRect.width = mLegendRect.width + aReflowState.ComputedPhysicalPadding().LeftRight();
606 // place the legend
607 nsRect actualLegendRect(mLegendRect);
608 actualLegendRect.Deflate(legendMargin);
609 nsPoint actualLegendPos(actualLegendRect.TopLeft());
610 legendReflowState.ref().ApplyRelativePositioning(&actualLegendPos);
611 legend->SetPosition(actualLegendPos);
612 nsContainerFrame::PositionFrameView(legend);
613 nsContainerFrame::PositionChildViews(legend);
616 // Return our size and our result
617 if (aReflowState.ComputedHeight() == NS_INTRINSICSIZE) {
618 aDesiredSize.Height() = mLegendSpace +
619 border.TopBottom() +
620 (inner ? inner->GetRect().height : 0);
621 } else {
622 nscoord min = border.TopBottom() + mLegendRect.height;
623 aDesiredSize.Height() =
624 aReflowState.ComputedHeight() + aReflowState.ComputedPhysicalBorderPadding().TopBottom();
625 if (aDesiredSize.Height() < min)
626 aDesiredSize.Height() = min;
628 aDesiredSize.Width() = contentRect.width + border.LeftRight();
629 aDesiredSize.SetOverflowAreasToDesiredBounds();
630 if (legend)
631 ConsiderChildOverflow(aDesiredSize.mOverflowAreas, legend);
632 if (inner)
633 ConsiderChildOverflow(aDesiredSize.mOverflowAreas, inner);
635 // Merge overflow container bounds and status.
636 aDesiredSize.mOverflowAreas.UnionWith(ocBounds);
637 NS_MergeReflowStatusInto(&aStatus, ocStatus);
639 FinishReflowWithAbsoluteFrames(aPresContext, aDesiredSize, aReflowState, aStatus);
641 InvalidateFrame();
643 NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
644 return NS_OK;
647 NS_IMETHODIMP
648 nsFieldSetFrame::AppendFrames(ChildListID aListID,
649 nsFrameList& aFrameList)
651 MOZ_CRASH("nsFieldSetFrame::AppendFrames not supported");
652 return NS_ERROR_NOT_IMPLEMENTED;
655 NS_IMETHODIMP
656 nsFieldSetFrame::InsertFrames(ChildListID aListID,
657 nsIFrame* aPrevFrame,
658 nsFrameList& aFrameList)
660 MOZ_CRASH("nsFieldSetFrame::InsertFrames not supported");
661 return NS_ERROR_NOT_IMPLEMENTED;
664 NS_IMETHODIMP
665 nsFieldSetFrame::RemoveFrame(ChildListID aListID,
666 nsIFrame* aOldFrame)
668 MOZ_CRASH("nsFieldSetFrame::RemoveFrame not supported");
669 return NS_ERROR_NOT_IMPLEMENTED;
672 #ifdef ACCESSIBILITY
673 a11y::AccType
674 nsFieldSetFrame::AccessibleType()
676 return a11y::eHTMLGroupboxType;
678 #endif
680 nscoord
681 nsFieldSetFrame::GetBaseline() const
683 nsIFrame* inner = GetInner();
684 return inner->GetPosition().y + inner->GetBaseline();