nsFileControlFrame.h (3944B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef nsFileControlFrame_h___ 8 #define nsFileControlFrame_h___ 9 10 #include "mozilla/Attributes.h" 11 #include "nsBlockFrame.h" 12 #include "nsIAnonymousContentCreator.h" 13 #include "nsIDOMEventListener.h" 14 15 namespace mozilla::dom { 16 class FileList; 17 class BlobImpl; 18 class DataTransfer; 19 } // namespace mozilla::dom 20 21 class nsFileControlFrame final : public nsBlockFrame, 22 public nsIAnonymousContentCreator { 23 using Element = mozilla::dom::Element; 24 25 public: 26 NS_DECL_QUERYFRAME 27 NS_DECL_FRAMEARENA_HELPERS(nsFileControlFrame) 28 29 explicit nsFileControlFrame(ComputedStyle* aStyle, 30 nsPresContext* aPresContext); 31 32 void Init(nsIContent* aContent, nsContainerFrame* aParent, 33 nsIFrame* aPrevInFlow) override; 34 35 void Reflow(nsPresContext* aPresContext, ReflowOutput& aReflowOutput, 36 const ReflowInput& aReflowInput, 37 nsReflowStatus& aStatus) override; 38 39 void SelectedFilesUpdated(); 40 41 void Destroy(DestroyContext&) override; 42 43 #ifdef DEBUG_FRAME_DUMP 44 nsresult GetFrameName(nsAString& aResult) const override; 45 #endif 46 47 void ElementStateChanged(mozilla::dom::ElementState aStates) override; 48 49 // nsIAnonymousContentCreator 50 nsresult CreateAnonymousContent(nsTArray<ContentInfo>&) override; 51 void AppendAnonymousContentTo(nsTArray<nsIContent*>&, 52 uint32_t aFilter) override; 53 54 #ifdef ACCESSIBILITY 55 mozilla::a11y::AccType AccessibleType() override; 56 #endif 57 58 protected: 59 class MouseListener; 60 friend class MouseListener; 61 class MouseListener : public nsIDOMEventListener { 62 public: 63 NS_DECL_ISUPPORTS 64 65 explicit MouseListener(nsFileControlFrame* aFrame) : mFrame(aFrame) {} 66 67 void ForgetFrame() { mFrame = nullptr; } 68 69 protected: 70 virtual ~MouseListener() = default; 71 72 nsFileControlFrame* mFrame; 73 }; 74 75 class SyncDisabledStateEvent; 76 friend class SyncDisabledStateEvent; 77 class SyncDisabledStateEvent : public mozilla::Runnable { 78 public: 79 explicit SyncDisabledStateEvent(nsFileControlFrame* aFrame) 80 : mozilla::Runnable("nsFileControlFrame::SyncDisabledStateEvent"), 81 mFrame(aFrame) {} 82 83 NS_IMETHOD Run() override { 84 nsFileControlFrame* frame = 85 static_cast<nsFileControlFrame*>(mFrame.GetFrame()); 86 NS_ENSURE_STATE(frame); 87 88 frame->SyncDisabledState(); 89 return NS_OK; 90 } 91 92 private: 93 WeakFrame mFrame; 94 }; 95 96 class DnDListener : public MouseListener { 97 public: 98 explicit DnDListener(nsFileControlFrame* aFrame) : MouseListener(aFrame) {} 99 100 // nsIDOMEventListener 101 MOZ_CAN_RUN_SCRIPT_BOUNDARY 102 NS_IMETHOD HandleEvent(mozilla::dom::Event* aEvent) override; 103 104 nsresult GetBlobImplForWebkitDirectory(mozilla::dom::FileList* aFileList, 105 mozilla::dom::BlobImpl** aBlobImpl); 106 107 bool IsValidDropData(mozilla::dom::DataTransfer* aDataTransfer); 108 bool CanDropTheseFiles(mozilla::dom::DataTransfer* aDataTransfer, 109 bool aSupportsMultiple); 110 }; 111 112 /** 113 * The text box input. 114 * @see nsFileControlFrame::CreateAnonymousContent 115 */ 116 RefPtr<Element> mTextContent; 117 /** 118 * The button to open a file or directory picker. 119 * @see nsFileControlFrame::CreateAnonymousContent 120 */ 121 RefPtr<Element> mBrowseFilesOrDirs; 122 123 /** 124 * Drag and drop mouse listener. 125 * This makes sure we don't get used after destruction. 126 */ 127 RefPtr<DnDListener> mMouseListener; 128 129 protected: 130 /** 131 * Sync the disabled state of the content with anonymous children. 132 */ 133 void SyncDisabledState(); 134 }; 135 136 #endif // nsFileControlFrame_h___