nsFormControlFrame.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #ifndef nsFormControlFrame_h___
  6. #define nsFormControlFrame_h___
  7. #include "mozilla/Attributes.h"
  8. #include "nsIFormControlFrame.h"
  9. #include "nsAtomicContainerFrame.h"
  10. #include "nsDisplayList.h"
  11. /**
  12. * nsFormControlFrame is the base class for radio buttons and
  13. * checkboxes. It also has two static methods (RegUnRegAccessKey and
  14. * GetScreenHeight) that are used by other form controls.
  15. */
  16. class nsFormControlFrame : public nsAtomicContainerFrame,
  17. public nsIFormControlFrame
  18. {
  19. public:
  20. /**
  21. * Main constructor
  22. * @param aContent the content representing this frame
  23. * @param aParentFrame the parent frame
  24. */
  25. explicit nsFormControlFrame(nsStyleContext*);
  26. virtual nsIAtom* GetType() const override;
  27. virtual bool IsFrameOfType(uint32_t aFlags) const override
  28. {
  29. return nsAtomicContainerFrame::IsFrameOfType(aFlags &
  30. ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
  31. }
  32. NS_DECL_QUERYFRAME
  33. NS_DECL_ABSTRACT_FRAME(nsFormControlFrame)
  34. // nsIFrame replacements
  35. virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
  36. const nsDisplayListSet& aLists) override {
  37. DO_GLOBAL_REFLOW_COUNT_DSP("nsFormControlFrame");
  38. DisplayBorderBackgroundOutline(aBuilder, aLists);
  39. }
  40. /**
  41. * Both GetMinISize and GetPrefISize will return whatever GetIntrinsicISize
  42. * returns.
  43. */
  44. virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) override;
  45. virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) override;
  46. /**
  47. * Our auto size is just intrinsic width and intrinsic height.
  48. */
  49. virtual mozilla::LogicalSize
  50. ComputeAutoSize(nsRenderingContext* aRenderingContext,
  51. mozilla::WritingMode aWM,
  52. const mozilla::LogicalSize& aCBSize,
  53. nscoord aAvailableISize,
  54. const mozilla::LogicalSize& aMargin,
  55. const mozilla::LogicalSize& aBorder,
  56. const mozilla::LogicalSize& aPadding,
  57. ComputeSizeFlags aFlags) override;
  58. /**
  59. * Respond to a gui event
  60. * @see nsIFrame::HandleEvent
  61. */
  62. virtual nsresult HandleEvent(nsPresContext* aPresContext,
  63. mozilla::WidgetGUIEvent* aEvent,
  64. nsEventStatus* aEventStatus) override;
  65. virtual nscoord GetLogicalBaseline(mozilla::WritingMode aWritingMode)
  66. const override;
  67. /**
  68. * Respond to the request to resize and/or reflow
  69. * @see nsIFrame::Reflow
  70. */
  71. virtual void Reflow(nsPresContext* aCX,
  72. ReflowOutput& aDesiredSize,
  73. const ReflowInput& aReflowInput,
  74. nsReflowStatus& aStatus) override;
  75. virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
  76. // new behavior
  77. virtual void SetFocus(bool aOn = true, bool aRepaint = false) override;
  78. // nsIFormControlFrame
  79. virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue) override;
  80. // AccessKey Helper function
  81. static nsresult RegUnRegAccessKey(nsIFrame * aFrame, bool aDoReg);
  82. /**
  83. * Returns the usable screen rect in app units, eg the rect where we can
  84. * draw dropdowns.
  85. */
  86. static nsRect GetUsableScreenRect(nsPresContext* aPresContext);
  87. protected:
  88. virtual ~nsFormControlFrame();
  89. nscoord GetIntrinsicISize();
  90. nscoord GetIntrinsicBSize();
  91. //
  92. //-------------------------------------------------------------------------------------
  93. // Utility methods for managing checkboxes and radiobuttons
  94. //-------------------------------------------------------------------------------------
  95. //
  96. /**
  97. * Get the state of the checked attribute.
  98. * @param aState set to true if the checked attribute is set,
  99. * false if the checked attribute has been removed
  100. */
  101. void GetCurrentCheckState(bool* aState);
  102. };
  103. #endif