nsLegendFrame.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #include "nsLegendFrame.h"
  6. #include "nsIContent.h"
  7. #include "nsGenericHTMLElement.h"
  8. #include "nsAttrValueInlines.h"
  9. #include "nsHTMLParts.h"
  10. #include "nsGkAtoms.h"
  11. #include "nsStyleConsts.h"
  12. #include "nsFormControlFrame.h"
  13. using namespace mozilla;
  14. nsIFrame*
  15. NS_NewLegendFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
  16. {
  17. #ifdef DEBUG
  18. const nsStyleDisplay* disp = aContext->StyleDisplay();
  19. NS_ASSERTION(!disp->IsAbsolutelyPositionedStyle() && !disp->IsFloatingStyle(),
  20. "Legends should not be positioned and should not float");
  21. #endif
  22. nsIFrame* f = new (aPresShell) nsLegendFrame(aContext);
  23. f->AddStateBits(NS_BLOCK_FORMATTING_CONTEXT_STATE_BITS);
  24. return f;
  25. }
  26. NS_IMPL_FRAMEARENA_HELPERS(nsLegendFrame)
  27. nsIAtom*
  28. nsLegendFrame::GetType() const
  29. {
  30. return nsGkAtoms::legendFrame;
  31. }
  32. void
  33. nsLegendFrame::DestroyFrom(nsIFrame* aDestructRoot)
  34. {
  35. nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
  36. nsBlockFrame::DestroyFrom(aDestructRoot);
  37. }
  38. NS_QUERYFRAME_HEAD(nsLegendFrame)
  39. NS_QUERYFRAME_ENTRY(nsLegendFrame)
  40. NS_QUERYFRAME_TAIL_INHERITING(nsBlockFrame)
  41. void
  42. nsLegendFrame::Reflow(nsPresContext* aPresContext,
  43. ReflowOutput& aDesiredSize,
  44. const ReflowInput& aReflowInput,
  45. nsReflowStatus& aStatus)
  46. {
  47. DO_GLOBAL_REFLOW_COUNT("nsLegendFrame");
  48. DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
  49. if (mState & NS_FRAME_FIRST_REFLOW) {
  50. nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), true);
  51. }
  52. return nsBlockFrame::Reflow(aPresContext, aDesiredSize, aReflowInput, aStatus);
  53. }
  54. int32_t
  55. nsLegendFrame::GetLogicalAlign(WritingMode aCBWM)
  56. {
  57. int32_t intValue = NS_STYLE_TEXT_ALIGN_START;
  58. nsGenericHTMLElement* content = nsGenericHTMLElement::FromContent(mContent);
  59. if (content) {
  60. const nsAttrValue* attr = content->GetParsedAttr(nsGkAtoms::align);
  61. if (attr && attr->Type() == nsAttrValue::eEnum) {
  62. intValue = attr->GetEnumValue();
  63. switch (intValue) {
  64. case NS_STYLE_TEXT_ALIGN_LEFT:
  65. intValue = aCBWM.IsBidiLTR() ? NS_STYLE_TEXT_ALIGN_START
  66. : NS_STYLE_TEXT_ALIGN_END;
  67. break;
  68. case NS_STYLE_TEXT_ALIGN_RIGHT:
  69. intValue = aCBWM.IsBidiLTR() ? NS_STYLE_TEXT_ALIGN_END
  70. : NS_STYLE_TEXT_ALIGN_START;
  71. break;
  72. }
  73. }
  74. }
  75. return intValue;
  76. }
  77. #ifdef DEBUG_FRAME_DUMP
  78. nsresult
  79. nsLegendFrame::GetFrameName(nsAString& aResult) const
  80. {
  81. return MakeFrameName(NS_LITERAL_STRING("Legend"), aResult);
  82. }
  83. #endif