nsFileControlFrame.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 nsFileControlFrame_h___
  6. #define nsFileControlFrame_h___
  7. #include "mozilla/Attributes.h"
  8. #include "nsBlockFrame.h"
  9. #include "nsIFormControlFrame.h"
  10. #include "nsIDOMEventListener.h"
  11. #include "nsIAnonymousContentCreator.h"
  12. #include "nsCOMPtr.h"
  13. class nsIDOMDataTransfer;
  14. class nsIDOMFileList;
  15. namespace mozilla {
  16. namespace dom {
  17. class BlobImpl;
  18. } // namespace dom
  19. } // namespace mozilla
  20. class nsFileControlFrame : public nsBlockFrame,
  21. public nsIFormControlFrame,
  22. public nsIAnonymousContentCreator
  23. {
  24. public:
  25. explicit nsFileControlFrame(nsStyleContext* aContext);
  26. virtual void Init(nsIContent* aContent,
  27. nsContainerFrame* aParent,
  28. nsIFrame* aPrevInFlow) override;
  29. virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
  30. const nsDisplayListSet& aLists) override;
  31. NS_DECL_QUERYFRAME
  32. NS_DECL_FRAMEARENA_HELPERS
  33. // nsIFormControlFrame
  34. virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue) override;
  35. virtual void SetFocus(bool aOn, bool aRepaint) override;
  36. virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) override;
  37. virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
  38. #ifdef DEBUG_FRAME_DUMP
  39. virtual nsresult GetFrameName(nsAString& aResult) const override;
  40. #endif
  41. virtual nsresult AttributeChanged(int32_t aNameSpaceID,
  42. nsIAtom* aAttribute,
  43. int32_t aModType) override;
  44. virtual void ContentStatesChanged(mozilla::EventStates aStates) override;
  45. virtual bool IsLeaf() const override
  46. {
  47. return true;
  48. }
  49. // nsIAnonymousContentCreator
  50. virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
  51. virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
  52. uint32_t aFilter) override;
  53. #ifdef ACCESSIBILITY
  54. virtual mozilla::a11y::AccType AccessibleType() override;
  55. #endif
  56. typedef bool (*AcceptAttrCallback)(const nsAString&, void*);
  57. protected:
  58. class MouseListener;
  59. friend class MouseListener;
  60. class MouseListener : public nsIDOMEventListener {
  61. public:
  62. NS_DECL_ISUPPORTS
  63. explicit MouseListener(nsFileControlFrame* aFrame)
  64. : mFrame(aFrame)
  65. {}
  66. void ForgetFrame() {
  67. mFrame = nullptr;
  68. }
  69. protected:
  70. virtual ~MouseListener() {}
  71. nsFileControlFrame* mFrame;
  72. };
  73. class SyncDisabledStateEvent;
  74. friend class SyncDisabledStateEvent;
  75. class SyncDisabledStateEvent : public mozilla::Runnable
  76. {
  77. public:
  78. explicit SyncDisabledStateEvent(nsFileControlFrame* aFrame)
  79. : mFrame(aFrame)
  80. {}
  81. NS_IMETHOD Run() override {
  82. nsFileControlFrame* frame = static_cast<nsFileControlFrame*>(mFrame.GetFrame());
  83. NS_ENSURE_STATE(frame);
  84. frame->SyncDisabledState();
  85. return NS_OK;
  86. }
  87. private:
  88. nsWeakFrame mFrame;
  89. };
  90. class DnDListener: public MouseListener {
  91. public:
  92. explicit DnDListener(nsFileControlFrame* aFrame)
  93. : MouseListener(aFrame)
  94. {}
  95. NS_DECL_NSIDOMEVENTLISTENER
  96. nsresult GetBlobImplForWebkitDirectory(nsIDOMFileList* aFileList,
  97. mozilla::dom::BlobImpl** aBlobImpl);
  98. bool IsValidDropData(nsIDOMDataTransfer* aDOMDataTransfer);
  99. bool CanDropTheseFiles(nsIDOMDataTransfer* aDOMDataTransfer, bool aSupportsMultiple);
  100. };
  101. virtual bool IsFrameOfType(uint32_t aFlags) const override
  102. {
  103. return nsBlockFrame::IsFrameOfType(aFlags &
  104. ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
  105. }
  106. /**
  107. * The text box input.
  108. * @see nsFileControlFrame::CreateAnonymousContent
  109. */
  110. nsCOMPtr<nsIContent> mTextContent;
  111. /**
  112. * The button to open a file or directory picker.
  113. * @see nsFileControlFrame::CreateAnonymousContent
  114. */
  115. nsCOMPtr<nsIContent> mBrowseFilesOrDirs;
  116. /**
  117. * Drag and drop mouse listener.
  118. * This makes sure we don't get used after destruction.
  119. */
  120. RefPtr<DnDListener> mMouseListener;
  121. protected:
  122. /**
  123. * Sync the disabled state of the content with anonymous children.
  124. */
  125. void SyncDisabledState();
  126. /**
  127. * Updates the displayed value by using aValue.
  128. */
  129. void UpdateDisplayedValue(const nsAString& aValue, bool aNotify);
  130. };
  131. #endif // nsFileControlFrame_h___