layout/forms/nsLegendFrame.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/forms/nsLegendFrame.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     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 +#include "nsLegendFrame.h"
    1.10 +#include "nsIContent.h"
    1.11 +#include "nsGenericHTMLElement.h"
    1.12 +#include "nsAttrValueInlines.h"
    1.13 +#include "nsHTMLParts.h"
    1.14 +#include "nsGkAtoms.h"
    1.15 +#include "nsStyleConsts.h"
    1.16 +#include "nsFormControlFrame.h"
    1.17 +
    1.18 +nsIFrame*
    1.19 +NS_NewLegendFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
    1.20 +{
    1.21 +#ifdef DEBUG
    1.22 +  const nsStyleDisplay* disp = aContext->StyleDisplay();
    1.23 +  NS_ASSERTION(!disp->IsAbsolutelyPositionedStyle() && !disp->IsFloatingStyle(),
    1.24 +               "Legends should not be positioned and should not float");
    1.25 +#endif
    1.26 +
    1.27 +  nsIFrame* f = new (aPresShell) nsLegendFrame(aContext);
    1.28 +  if (f) {
    1.29 +    f->AddStateBits(NS_BLOCK_FLOAT_MGR | NS_BLOCK_MARGIN_ROOT);
    1.30 +  }
    1.31 +  return f;
    1.32 +}
    1.33 +
    1.34 +NS_IMPL_FRAMEARENA_HELPERS(nsLegendFrame)
    1.35 +
    1.36 +nsIAtom*
    1.37 +nsLegendFrame::GetType() const
    1.38 +{
    1.39 +  return nsGkAtoms::legendFrame; 
    1.40 +}
    1.41 +
    1.42 +void
    1.43 +nsLegendFrame::DestroyFrom(nsIFrame* aDestructRoot)
    1.44 +{
    1.45 +  nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
    1.46 +  nsBlockFrame::DestroyFrom(aDestructRoot);
    1.47 +}
    1.48 +
    1.49 +NS_QUERYFRAME_HEAD(nsLegendFrame)
    1.50 +  NS_QUERYFRAME_ENTRY(nsLegendFrame)
    1.51 +NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
    1.52 +
    1.53 +nsresult 
    1.54 +nsLegendFrame::Reflow(nsPresContext*          aPresContext,
    1.55 +                     nsHTMLReflowMetrics&     aDesiredSize,
    1.56 +                     const nsHTMLReflowState& aReflowState,
    1.57 +                     nsReflowStatus&          aStatus)
    1.58 +{
    1.59 +  DO_GLOBAL_REFLOW_COUNT("nsLegendFrame");
    1.60 +  DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
    1.61 +  if (mState & NS_FRAME_FIRST_REFLOW) {
    1.62 +    nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), true);
    1.63 +  }
    1.64 +  return nsBlockFrame::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus);
    1.65 +}
    1.66 +
    1.67 +// REVIEW: We don't need to override BuildDisplayList, nsBlockFrame will honour
    1.68 +// our visibility setting
    1.69 +int32_t nsLegendFrame::GetAlign()
    1.70 +{
    1.71 +  int32_t intValue = NS_STYLE_TEXT_ALIGN_LEFT;
    1.72 +  if (mParent && NS_STYLE_DIRECTION_RTL == mParent->StyleVisibility()->mDirection) {
    1.73 +    intValue = NS_STYLE_TEXT_ALIGN_RIGHT;
    1.74 +  }
    1.75 +
    1.76 +  nsGenericHTMLElement *content = nsGenericHTMLElement::FromContent(mContent);
    1.77 +
    1.78 +  if (content) {
    1.79 +    const nsAttrValue* attr = content->GetParsedAttr(nsGkAtoms::align);
    1.80 +    if (attr && attr->Type() == nsAttrValue::eEnum) {
    1.81 +      intValue = attr->GetEnumValue();
    1.82 +    }
    1.83 +  }
    1.84 +  return intValue;
    1.85 +}
    1.86 +
    1.87 +#ifdef DEBUG_FRAME_DUMP
    1.88 +nsresult
    1.89 +nsLegendFrame::GetFrameName(nsAString& aResult) const
    1.90 +{
    1.91 +  return MakeFrameName(NS_LITERAL_STRING("Legend"), aResult);
    1.92 +}
    1.93 +#endif

mercurial