nsDateTimeControlFrame.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. /**
  6. * This frame type is used for input type=date, time, month, week, and
  7. * datetime-local.
  8. *
  9. * NOTE: some of the above-mentioned input types are still to-be-implemented.
  10. * See nsCSSFrameConstructor::FindInputData, as well as bug 1286182 (date),
  11. * bug 1306215 (month), bug 1306216 (week) and bug 1306217 (datetime-local).
  12. */
  13. #ifndef nsDateTimeControlFrame_h__
  14. #define nsDateTimeControlFrame_h__
  15. #include "mozilla/Attributes.h"
  16. #include "nsContainerFrame.h"
  17. #include "nsIAnonymousContentCreator.h"
  18. #include "nsCOMPtr.h"
  19. namespace mozilla {
  20. namespace dom {
  21. struct DateTimeValue;
  22. } // namespace dom
  23. } // namespace mozilla
  24. class nsDateTimeControlFrame final : public nsContainerFrame,
  25. public nsIAnonymousContentCreator
  26. {
  27. typedef mozilla::dom::DateTimeValue DateTimeValue;
  28. explicit nsDateTimeControlFrame(nsStyleContext* aContext);
  29. public:
  30. friend nsIFrame* NS_NewDateTimeControlFrame(nsIPresShell* aPresShell,
  31. nsStyleContext* aContext);
  32. void ContentStatesChanged(mozilla::EventStates aStates) override;
  33. void DestroyFrom(nsIFrame* aDestructRoot) override;
  34. NS_DECL_QUERYFRAME_TARGET(nsDateTimeControlFrame)
  35. NS_DECL_QUERYFRAME
  36. NS_DECL_FRAMEARENA_HELPERS
  37. #ifdef DEBUG_FRAME_DUMP
  38. nsresult GetFrameName(nsAString& aResult) const override {
  39. return MakeFrameName(NS_LITERAL_STRING("DateTimeControl"), aResult);
  40. }
  41. #endif
  42. nsIAtom* GetType() const override;
  43. bool IsFrameOfType(uint32_t aFlags) const override
  44. {
  45. return nsContainerFrame::IsFrameOfType(aFlags &
  46. ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
  47. }
  48. // Reflow
  49. nscoord GetMinISize(nsRenderingContext* aRenderingContext) override;
  50. nscoord GetPrefISize(nsRenderingContext* aRenderingContext) override;
  51. void Reflow(nsPresContext* aPresContext,
  52. ReflowOutput& aDesiredSize,
  53. const ReflowInput& aReflowState,
  54. nsReflowStatus& aStatus) override;
  55. // nsIAnonymousContentCreator
  56. nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
  57. void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
  58. uint32_t aFilter) override;
  59. nsresult AttributeChanged(int32_t aNameSpaceID, nsIAtom* aAttribute,
  60. int32_t aModType) override;
  61. void UpdateInputBoxValue();
  62. void SetValueFromPicker(const DateTimeValue& aValue);
  63. void HandleFocusEvent();
  64. void HandleBlurEvent();
  65. void SetPickerState(bool aOpen);
  66. private:
  67. class SyncDisabledStateEvent;
  68. friend class SyncDisabledStateEvent;
  69. class SyncDisabledStateEvent : public mozilla::Runnable
  70. {
  71. public:
  72. explicit SyncDisabledStateEvent(nsDateTimeControlFrame* aFrame)
  73. : mFrame(aFrame)
  74. {}
  75. NS_IMETHOD Run() override
  76. {
  77. nsDateTimeControlFrame* frame =
  78. static_cast<nsDateTimeControlFrame*>(mFrame.GetFrame());
  79. NS_ENSURE_STATE(frame);
  80. frame->SyncDisabledState();
  81. return NS_OK;
  82. }
  83. private:
  84. nsWeakFrame mFrame;
  85. };
  86. /**
  87. * Sync the disabled state of the anonymous children up with our content's.
  88. */
  89. void SyncDisabledState();
  90. // Anonymous child which is bound via XBL to an element that wraps the input
  91. // area and reset button.
  92. nsCOMPtr<nsIContent> mInputAreaContent;
  93. };
  94. #endif // nsDateTimeControlFrame_h__