1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsCSSAnonBoxes.h"
#include "nsContainerFrame.h"
#include "nsLegendFrame.h"
#include "nsIDOMNode.h"
#include "nsIDOMHTMLFieldSetElement.h"
#include "nsIDOMHTMLLegendElement.h"
#include "nsCSSRendering.h"
#include <algorithm>
#include "nsIContent.h"
#include "nsIFrame.h"
#include "nsISupports.h"
#include "nsIAtom.h"
#include "nsPresContext.h"
#include "nsFrameManager.h"
#include "nsHTMLParts.h"
#include "nsGkAtoms.h"
#include "nsStyleConsts.h"
#include "nsFont.h"
#include "nsCOMPtr.h"
#include "nsIServiceManager.h"
#include "nsDisplayList.h"
#include "nsRenderingContext.h"
#include "mozilla/Likely.h"
using namespace mozilla;
using namespace mozilla::layout;
class nsLegendFrame;
class nsFieldSetFrame MOZ_FINAL : public nsContainerFrame {
public:
NS_DECL_FRAMEARENA_HELPERS
nsFieldSetFrame(nsStyleContext* aContext);
NS_HIDDEN_(nscoord)
GetIntrinsicWidth(nsRenderingContext* aRenderingContext,
nsLayoutUtils::IntrinsicWidthType);
virtual nscoord GetMinWidth(nsRenderingContext* aRenderingContext);
virtual nscoord GetPrefWidth(nsRenderingContext* aRenderingContext);
virtual nsSize ComputeSize(nsRenderingContext *aRenderingContext,
nsSize aCBSize, nscoord aAvailableWidth,
nsSize aMargin, nsSize aBorder, nsSize aPadding,
uint32_t aFlags) MOZ_OVERRIDE;
virtual nscoord GetBaseline() const;
/**
* The area to paint box-shadows around. It's the border rect except
* when there's a <legend> we offset the y-position to the center of it.
*/
virtual nsRect VisualBorderRectRelativeToSelf() const MOZ_OVERRIDE {
nscoord topBorder = StyleBorder()->GetComputedBorderWidth(NS_SIDE_TOP);
nsRect r(nsPoint(0,0), GetSize());
if (topBorder < mLegendRect.height) {
nscoord yoff = (mLegendRect.height - topBorder) / 2;
r.y += yoff;
r.height -= yoff;
}
return r;
}
NS_IMETHOD Reflow(nsPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus);
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists) MOZ_OVERRIDE;
void PaintBorderBackground(nsRenderingContext& aRenderingContext,
nsPoint aPt, const nsRect& aDirtyRect, uint32_t aBGFlags);
NS_IMETHOD AppendFrames(ChildListID aListID,
nsFrameList& aFrameList);
NS_IMETHOD InsertFrames(ChildListID aListID,
nsIFrame* aPrevFrame,
nsFrameList& aFrameList);
NS_IMETHOD RemoveFrame(ChildListID aListID,
nsIFrame* aOldFrame);
virtual nsIAtom* GetType() const;
virtual bool IsFrameOfType(uint32_t aFlags) const
{
return nsContainerFrame::IsFrameOfType(aFlags &
~nsIFrame::eCanContainOverflowContainers);
}
#ifdef ACCESSIBILITY
virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
#endif
#ifdef DEBUG
NS_IMETHOD SetInitialChildList(ChildListID aListID,
nsFrameList& aChildList);
NS_IMETHOD GetFrameName(nsAString& aResult) const {
return MakeFrameName(NS_LITERAL_STRING("FieldSet"), aResult);
}
#endif
protected:
void ReparentFrameList(const nsFrameList& aFrameList);
/**
* Return the anonymous frame that contains all descendants except
* the legend frame. This is currently always a block frame with
* pseudo nsCSSAnonBoxes::fieldsetContent -- this may change in the
* future when we add support for CSS overflow for <fieldset>.
*/
nsIFrame* GetInner() const
{
nsIFrame* last = mFrames.LastChild();
if (last &&
last->StyleContext()->GetPseudo() == nsCSSAnonBoxes::fieldsetContent) {
return last;
}
MOZ_ASSERT(mFrames.LastChild() == mFrames.FirstChild());
return nullptr;
}
/**
* Return the frame that represents the legend if any. This may be
* a nsLegendFrame or a nsHTMLScrollFrame with the nsLegendFrame as the
* scrolled frame (aka content insertion frame).
*/
nsIFrame* GetLegend() const
{
if (mFrames.FirstChild() == GetInner()) {
MOZ_ASSERT(mFrames.LastChild() == mFrames.FirstChild());
return nullptr;
}
MOZ_ASSERT(mFrames.FirstChild() &&
mFrames.FirstChild()->GetContentInsertionFrame()->GetType() ==
nsGkAtoms::legendFrame);
return mFrames.FirstChild();
}
nsRect mLegendRect;
nscoord mLegendSpace;
};
nsIFrame*
NS_NewFieldSetFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
{
return new (aPresShell) nsFieldSetFrame(aContext);
}
NS_IMPL_FRAMEARENA_HELPERS(nsFieldSetFrame)
nsFieldSetFrame::nsFieldSetFrame(nsStyleContext* aContext)
: nsContainerFrame(aContext)
{
mLegendSpace = 0;
}
nsIAtom*
nsFieldSetFrame::GetType() const
{
return nsGkAtoms::fieldSetFrame;
}
#ifdef DEBUG
NS_IMETHODIMP
nsFieldSetFrame::SetInitialChildList(ChildListID aListID,
nsFrameList& aChildList)
{
nsresult rv = nsContainerFrame::SetInitialChildList(kPrincipalList, aChildList);
MOZ_ASSERT(GetInner());
return rv;
}
#endif
class nsDisplayFieldSetBorderBackground : public nsDisplayItem {
public:
nsDisplayFieldSetBorderBackground(nsDisplayListBuilder* aBuilder,
nsFieldSetFrame* aFrame)
: nsDisplayItem(aBuilder, aFrame) {
MOZ_COUNT_CTOR(nsDisplayFieldSetBorderBackground);
}
#ifdef NS_BUILD_REFCNT_LOGGING
virtual ~nsDisplayFieldSetBorderBackground() {
MOZ_COUNT_DTOR(nsDisplayFieldSetBorderBackground);
}
#endif
virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames);
virtual void Paint(nsDisplayListBuilder* aBuilder,
nsRenderingContext* aCtx);
NS_DISPLAY_DECL_NAME("FieldSetBorderBackground", TYPE_FIELDSET_BORDER_BACKGROUND)
};
void nsDisplayFieldSetBorderBackground::HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
{
// aPt is guaranteed to be in this item's bounds. We do the hit test based on the
// frame bounds even though our background doesn't cover the whole frame.
// It's not clear whether this is correct.
aOutFrames->AppendElement(mFrame);
}
void
nsDisplayFieldSetBorderBackground::Paint(nsDisplayListBuilder* aBuilder,
nsRenderingContext* aCtx)
{
static_cast<nsFieldSetFrame*>(mFrame)->
PaintBorderBackground(*aCtx, ToReferenceFrame(),
mVisibleRect, aBuilder->GetBackgroundPaintFlags());
}
void
nsFieldSetFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
const nsRect& aDirtyRect,
const nsDisplayListSet& aLists) {
// Paint our background and border in a special way.
// REVIEW: We don't really need to check frame emptiness here; if it's empty,
// the background/border display item won't do anything, and if it isn't empty,
// we need to paint the outline
if (!(GetStateBits() & NS_FRAME_IS_OVERFLOW_CONTAINER) &&
IsVisibleForPainting(aBuilder)) {
if (StyleBorder()->mBoxShadow) {
aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
nsDisplayBoxShadowOuter(aBuilder, this));
}
// don't bother checking to see if we really have a border or background.
// we usually will have a border.
aLists.BorderBackground()->AppendNewToTop(new (aBuilder)
nsDisplayFieldSetBorderBackground(aBuilder, this));
DisplayOutlineUnconditional(aBuilder, aLists);
DO_GLOBAL_REFLOW_COUNT_DSP("nsFieldSetFrame");
}
if (GetPrevInFlow()) {
DisplayOverflowContainers(aBuilder, aDirtyRect, aLists);
}
nsDisplayListCollection contentDisplayItems;
if (nsIFrame* inner = GetInner()) {
// Collect the inner frame's display items into their own collection.
// We need to be calling BuildDisplayList on it before the legend in
// case it contains out-of-flow frames whose placeholders are in the
// legend. However, we want the inner frame's display items to be
// after the legend's display items in z-order, so we need to save them
// and append them later.
BuildDisplayListForChild(aBuilder, inner, aDirtyRect, contentDisplayItems);
}
if (nsIFrame* legend = GetLegend()) {
// The legend's background goes on our BlockBorderBackgrounds list because
// it's a block child.
nsDisplayListSet set(aLists, aLists.BlockBorderBackgrounds());
BuildDisplayListForChild(aBuilder, legend, aDirtyRect, set);
}
// Put the inner frame's display items on the master list. Note that this
// moves its border/background display items to our BorderBackground() list,
// which isn't really correct, but it's OK because the inner frame is
// anonymous and can't have its own border and background.
contentDisplayItems.MoveTo(aLists);
}
void
nsFieldSetFrame::PaintBorderBackground(nsRenderingContext& aRenderingContext,
nsPoint aPt, const nsRect& aDirtyRect, uint32_t aBGFlags)
{
// if the border is smaller than the legend. Move the border down
// to be centered on the legend.
// FIXME: This means border-radius clamping is incorrect; we should
// override nsIFrame::GetBorderRadii.
nsRect rect = VisualBorderRectRelativeToSelf();
nscoord yoff = rect.y;
rect += aPt;
nsPresContext* presContext = PresContext();
nsCSSRendering::PaintBackground(presContext, aRenderingContext, this,
aDirtyRect, rect, aBGFlags);
nsCSSRendering::PaintBoxShadowInner(presContext, aRenderingContext,
this, rect, aDirtyRect);
if (nsIFrame* legend = GetLegend()) {
nscoord topBorder = StyleBorder()->GetComputedBorderWidth(NS_SIDE_TOP);
// Use the rect of the legend frame, not mLegendRect, so we draw our
// border under the legend's left and right margins.
nsRect legendRect = legend->GetRect() + aPt;
// we should probably use PaintBorderEdges to do this but for now just use clipping
// to achieve the same effect.
// draw left side
nsRect clipRect(rect);
clipRect.width = legendRect.x - rect.x;
clipRect.height = topBorder;
aRenderingContext.PushState();
aRenderingContext.IntersectClip(clipRect);
nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
aDirtyRect, rect, mStyleContext);
aRenderingContext.PopState();
// draw right side
clipRect = rect;
clipRect.x = legendRect.XMost();
clipRect.width = rect.XMost() - legendRect.XMost();
clipRect.height = topBorder;
aRenderingContext.PushState();
aRenderingContext.IntersectClip(clipRect);
nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
aDirtyRect, rect, mStyleContext);
aRenderingContext.PopState();
// draw bottom
clipRect = rect;
clipRect.y += topBorder;
clipRect.height = mRect.height - (yoff + topBorder);
aRenderingContext.PushState();
aRenderingContext.IntersectClip(clipRect);
nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
aDirtyRect, rect, mStyleContext);
aRenderingContext.PopState();
} else {
nsCSSRendering::PaintBorder(presContext, aRenderingContext, this,
aDirtyRect,
nsRect(aPt, mRect.Size()),
mStyleContext);
}
}
nscoord
nsFieldSetFrame::GetIntrinsicWidth(nsRenderingContext* aRenderingContext,
nsLayoutUtils::IntrinsicWidthType aType)
{
nscoord legendWidth = 0;
nscoord contentWidth = 0;
if (nsIFrame* legend = GetLegend()) {
legendWidth =
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, legend, aType);
}
if (nsIFrame* inner = GetInner()) {
contentWidth =
nsLayoutUtils::IntrinsicForContainer(aRenderingContext, inner, aType);
}
return std::max(legendWidth, contentWidth);
}
nscoord
nsFieldSetFrame::GetMinWidth(nsRenderingContext* aRenderingContext)
{
nscoord result = 0;
DISPLAY_MIN_WIDTH(this, result);
result = GetIntrinsicWidth(aRenderingContext, nsLayoutUtils::MIN_WIDTH);
return result;
}
nscoord
nsFieldSetFrame::GetPrefWidth(nsRenderingContext* aRenderingContext)
{
nscoord result = 0;
DISPLAY_PREF_WIDTH(this, result);
result = GetIntrinsicWidth(aRenderingContext, nsLayoutUtils::PREF_WIDTH);
return result;
}
/* virtual */ nsSize
nsFieldSetFrame::ComputeSize(nsRenderingContext *aRenderingContext,
nsSize aCBSize, nscoord aAvailableWidth,
nsSize aMargin, nsSize aBorder, nsSize aPadding,
uint32_t aFlags)
{
nsSize result =
nsContainerFrame::ComputeSize(aRenderingContext, aCBSize, aAvailableWidth,
aMargin, aBorder, aPadding, aFlags);
// Fieldsets never shrink below their min width.
// If we're a container for font size inflation, then shrink
// wrapping inside of us should not apply font size inflation.
AutoMaybeDisableFontInflation an(this);
nscoord minWidth = GetMinWidth(aRenderingContext);
if (minWidth > result.width)
result.width = minWidth;
return result;
}
NS_IMETHODIMP
nsFieldSetFrame::Reflow(nsPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
DO_GLOBAL_REFLOW_COUNT("nsFieldSetFrame");
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
NS_PRECONDITION(aReflowState.ComputedWidth() != NS_INTRINSICSIZE,
"Should have a precomputed width!");
// Initialize OUT parameter
aStatus = NS_FRAME_COMPLETE;
nsOverflowAreas ocBounds;
nsReflowStatus ocStatus = NS_FRAME_COMPLETE;
if (GetPrevInFlow()) {
ReflowOverflowContainerChildren(aPresContext, aReflowState, ocBounds, 0,
ocStatus);
}
//------------ Handle Incremental Reflow -----------------
bool reflowInner;
bool reflowLegend;
nsIFrame* legend = GetLegend();
nsIFrame* inner = GetInner();
if (aReflowState.ShouldReflowAllKids()) {
reflowInner = inner != nullptr;
reflowLegend = legend != nullptr;
} else {
reflowInner = inner && NS_SUBTREE_DIRTY(inner);
reflowLegend = legend && NS_SUBTREE_DIRTY(legend);
}
// We don't allow fieldsets to break vertically. If we did, we'd
// need logic here to push and pull overflow frames.
nsSize availSize(aReflowState.ComputedWidth(), NS_UNCONSTRAINEDSIZE);
NS_ASSERTION(!inner ||
nsLayoutUtils::IntrinsicForContainer(aReflowState.rendContext,
inner,
nsLayoutUtils::MIN_WIDTH) <=
availSize.width,
"Bogus availSize.width; should be bigger");
NS_ASSERTION(!legend ||
nsLayoutUtils::IntrinsicForContainer(aReflowState.rendContext,
legend,
nsLayoutUtils::MIN_WIDTH) <=
availSize.width,
"Bogus availSize.width; should be bigger");
// get our border and padding
const nsMargin &borderPadding = aReflowState.mComputedBorderPadding;
nsMargin border = borderPadding - aReflowState.mComputedPadding;
// Figure out how big the legend is if there is one.
// get the legend's margin
nsMargin legendMargin(0,0,0,0);
// reflow the legend only if needed
if (reflowLegend) {
nsHTMLReflowState legendReflowState(aPresContext, aReflowState,
legend, availSize);
nsHTMLReflowMetrics legendDesiredSize;
ReflowChild(legend, aPresContext, legendDesiredSize, legendReflowState,
0, 0, NS_FRAME_NO_MOVE_FRAME, aStatus);
#ifdef NOISY_REFLOW
printf(" returned (%d, %d)\n", legendDesiredSize.width, legendDesiredSize.height);
#endif
// figure out the legend's rectangle
legendMargin = legend->GetUsedMargin();
mLegendRect.width = legendDesiredSize.width + legendMargin.left + legendMargin.right;
mLegendRect.height = legendDesiredSize.height + legendMargin.top + legendMargin.bottom;
mLegendRect.x = borderPadding.left;
mLegendRect.y = 0;
nscoord oldSpace = mLegendSpace;
mLegendSpace = 0;
if (mLegendRect.height > border.top) {
// center the border on the legend
mLegendSpace = mLegendRect.height - border.top;
} else {
mLegendRect.y = (border.top - mLegendRect.height)/2;
}
// if the legend space changes then we need to reflow the
// content area as well.
if (mLegendSpace != oldSpace && inner) {
reflowInner = true;
}
FinishReflowChild(legend, aPresContext, &legendReflowState,
legendDesiredSize, 0, 0, NS_FRAME_NO_MOVE_FRAME);
} else if (!legend) {
mLegendRect.SetEmpty();
mLegendSpace = 0;
} else {
// mLegendSpace and mLegendRect haven't changed, but we need
// the used margin when placing the legend.
legendMargin = legend->GetUsedMargin();
}
// reflow the content frame only if needed
if (reflowInner) {
nsHTMLReflowState kidReflowState(aPresContext, aReflowState, inner,
availSize);
// Our child is "height:100%" but we actually want its height to be reduced
// by the amount of content-height the legend is eating up, unless our
// height is unconstrained (in which case the child's will be too).
if (aReflowState.ComputedHeight() != NS_UNCONSTRAINEDSIZE) {
kidReflowState.SetComputedHeight(std::max(0, aReflowState.ComputedHeight() - mLegendSpace));
}
kidReflowState.mComputedMinHeight =
std::max(0, aReflowState.mComputedMinHeight - mLegendSpace);
if (aReflowState.mComputedMaxHeight != NS_UNCONSTRAINEDSIZE) {
kidReflowState.mComputedMaxHeight =
std::max(0, aReflowState.mComputedMaxHeight - mLegendSpace);
}
nsHTMLReflowMetrics kidDesiredSize(aDesiredSize.mFlags);
// Reflow the frame
NS_ASSERTION(kidReflowState.mComputedMargin == nsMargin(0,0,0,0),
"Margins on anonymous fieldset child not supported!");
nsPoint pt(borderPadding.left, borderPadding.top + mLegendSpace);
ReflowChild(inner, aPresContext, kidDesiredSize, kidReflowState,
pt.x, pt.y, 0, aStatus);
FinishReflowChild(inner, aPresContext, &kidReflowState,
kidDesiredSize, pt.x, pt.y, 0);
NS_FRAME_TRACE_REFLOW_OUT("FieldSet::Reflow", aStatus);
}
nsRect contentRect(0,0,0,0);
if (inner) {
// We don't support margins on inner, so our "content rect" is just
// its rect.
contentRect = inner->GetRect();
}
// use the computed width if the inner content does not fill it
if (aReflowState.ComputedWidth() > contentRect.width) {
contentRect.width = aReflowState.ComputedWidth();
}
if (legend) {
// if the content rect is larger then the legend we can align the legend
if (contentRect.width > mLegendRect.width) {
int32_t align = static_cast<nsLegendFrame*>
(legend->GetContentInsertionFrame())->GetAlign();
switch(align) {
case NS_STYLE_TEXT_ALIGN_RIGHT:
mLegendRect.x = contentRect.width - mLegendRect.width + borderPadding.left;
break;
case NS_STYLE_TEXT_ALIGN_CENTER:
// Note: rounding removed; there doesn't seem to be any need
mLegendRect.x = contentRect.width / 2 - mLegendRect.width / 2 + borderPadding.left;
break;
}
} else {
// otherwise make place for the legend
contentRect.width = mLegendRect.width;
}
// place the legend
nsRect actualLegendRect(mLegendRect);
actualLegendRect.Deflate(legendMargin);
nsPoint curOrigin = legend->GetPosition();
// only if the origin changed
if ((curOrigin.x != actualLegendRect.x) || (curOrigin.y != actualLegendRect.y)) {
legend->SetPosition(nsPoint(actualLegendRect.x , actualLegendRect.y));
nsContainerFrame::PositionFrameView(legend);
// We need to recursively process the legend frame's
// children since we're moving the frame after Reflow.
nsContainerFrame::PositionChildViews(legend);
}
}
// Return our size and our result
if (aReflowState.ComputedHeight() == NS_INTRINSICSIZE) {
aDesiredSize.height = mLegendSpace +
borderPadding.TopBottom() +
contentRect.height;
} else {
nscoord min = borderPadding.TopBottom() + mLegendRect.height;
aDesiredSize.height =
aReflowState.ComputedHeight() + borderPadding.TopBottom();
if (aDesiredSize.height < min)
aDesiredSize.height = min;
}
aDesiredSize.width = contentRect.width + borderPadding.LeftRight();
aDesiredSize.SetOverflowAreasToDesiredBounds();
if (legend)
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, legend);
if (inner)
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, inner);
// Merge overflow container bounds and status.
aDesiredSize.mOverflowAreas.UnionWith(ocBounds);
NS_MergeReflowStatusInto(&aStatus, ocStatus);
FinishReflowWithAbsoluteFrames(aPresContext, aDesiredSize, aReflowState, aStatus);
InvalidateFrame();
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
return NS_OK;
}
NS_IMETHODIMP
nsFieldSetFrame::AppendFrames(ChildListID aListID,
nsFrameList& aFrameList)
{
// aFrameList is not allowed to contain "the legend" for this fieldset
ReparentFrameList(aFrameList);
return GetInner()->AppendFrames(aListID, aFrameList);
}
NS_IMETHODIMP
nsFieldSetFrame::InsertFrames(ChildListID aListID,
nsIFrame* aPrevFrame,
nsFrameList& aFrameList)
{
NS_ASSERTION(!aPrevFrame || aPrevFrame->GetParent() == this ||
aPrevFrame->GetParent() == GetInner(),
"inserting after sibling frame with different parent");
// aFrameList is not allowed to contain "the legend" for this fieldset
ReparentFrameList(aFrameList);
if (MOZ_UNLIKELY(aPrevFrame == GetLegend())) {
aPrevFrame = nullptr;
}
return GetInner()->InsertFrames(aListID, aPrevFrame, aFrameList);
}
NS_IMETHODIMP
nsFieldSetFrame::RemoveFrame(ChildListID aListID,
nsIFrame* aOldFrame)
{
// For reference, see bug 70648, bug 276104 and bug 236071.
NS_ASSERTION(aOldFrame != GetLegend(), "Cannot remove legend here");
return GetInner()->RemoveFrame(aListID, aOldFrame);
}
#ifdef ACCESSIBILITY
a11y::AccType
nsFieldSetFrame::AccessibleType()
{
return a11y::eHTMLGroupboxType;
}
#endif
void
nsFieldSetFrame::ReparentFrameList(const nsFrameList& aFrameList)
{
nsFrameManager* frameManager = PresContext()->FrameManager();
nsIFrame* inner = GetInner();
for (nsFrameList::Enumerator e(aFrameList); !e.AtEnd(); e.Next()) {
NS_ASSERTION(GetLegend() || e.get()->GetType() != nsGkAtoms::legendFrame,
"The fieldset's legend is not allowed in this list");
e.get()->SetParent(inner);
frameManager->ReparentStyleContext(e.get());
}
}
nscoord
nsFieldSetFrame::GetBaseline() const
{
// We know inner is a block, so calling GetBaseline() on it will do
// the right thing (that being to return the baseline of the last line).
nsIFrame* inner = GetInner();
NS_ASSERTION(nsLayoutUtils::GetAsBlock(inner), "Unexpected inner");
return inner->GetPosition().y + inner->GetBaseline();
}
|