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 HTMLFrameSetElement_h 8 #define HTMLFrameSetElement_h 9 10 #include "mozilla/Attributes.h" 11 #include "mozilla/UniquePtr.h" 12 #include "nsIDOMHTMLFrameSetElement.h" 13 #include "nsGenericHTMLElement.h" 14 15 /** 16 * The nsFramesetUnit enum is used to denote the type of each entry 17 * in the row or column spec. 18 */ 19 enum nsFramesetUnit { 20 eFramesetUnit_Fixed = 0, 21 eFramesetUnit_Percent, 22 eFramesetUnit_Relative 23 }; 24 25 /** 26 * The nsFramesetSpec struct is used to hold a single entry in the 27 * row or column spec. 28 */ 29 struct nsFramesetSpec { 30 nsFramesetUnit mUnit; 31 nscoord mValue; 32 }; 33 34 /** 35 * The maximum number of entries allowed in the frame set element row 36 * or column spec. 37 */ 38 #define NS_MAX_FRAMESET_SPEC_COUNT 16000 39 40 //---------------------------------------------------------------------- 41 42 namespace mozilla { 43 namespace dom { 44 45 class OnBeforeUnloadEventHandlerNonNull; 46 47 class HTMLFrameSetElement final : public nsGenericHTMLElement, 48 public nsIDOMHTMLFrameSetElement 49 { 50 public: HTMLFrameSetElement(already_AddRefed<mozilla::dom::NodeInfo> & aNodeInfo)51 explicit HTMLFrameSetElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo) 52 : nsGenericHTMLElement(aNodeInfo), 53 mNumRows(0), 54 mNumCols(0), 55 mCurrentRowColHint(NS_STYLE_HINT_REFLOW) 56 { 57 SetHasWeirdParserInsertionMode(); 58 } 59 NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLFrameSetElement,frameset)60 NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLFrameSetElement, frameset) 61 62 // nsISupports 63 NS_DECL_ISUPPORTS_INHERITED 64 65 // nsIDOMHTMLFrameSetElement 66 NS_DECL_NSIDOMHTMLFRAMESETELEMENT 67 68 void GetCols(DOMString& aCols) 69 { 70 GetHTMLAttr(nsGkAtoms::cols, aCols); 71 } SetCols(const nsAString & aCols,ErrorResult & aError)72 void SetCols(const nsAString& aCols, ErrorResult& aError) 73 { 74 SetHTMLAttr(nsGkAtoms::cols, aCols, aError); 75 } GetRows(DOMString & aRows)76 void GetRows(DOMString& aRows) 77 { 78 GetHTMLAttr(nsGkAtoms::rows, aRows); 79 } SetRows(const nsAString & aRows,ErrorResult & aError)80 void SetRows(const nsAString& aRows, ErrorResult& aError) 81 { 82 SetHTMLAttr(nsGkAtoms::rows, aRows, aError); 83 } 84 85 virtual bool IsEventAttributeName(nsIAtom *aName) override; 86 87 // Event listener stuff; we need to declare only the ones we need to 88 // forward to window that don't come from nsIDOMHTMLFrameSetElement. 89 #define EVENT(name_, id_, type_, struct_) /* nothing; handled by the superclass */ 90 #define WINDOW_EVENT_HELPER(name_, type_) \ 91 type_* GetOn##name_(); \ 92 void SetOn##name_(type_* handler); 93 #define WINDOW_EVENT(name_, id_, type_, struct_) \ 94 WINDOW_EVENT_HELPER(name_, EventHandlerNonNull) 95 #define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \ 96 WINDOW_EVENT_HELPER(name_, OnBeforeUnloadEventHandlerNonNull) 97 #include "mozilla/EventNameList.h" // IWYU pragma: keep 98 #undef BEFOREUNLOAD_EVENT 99 #undef WINDOW_EVENT 100 #undef WINDOW_EVENT_HELPER 101 #undef EVENT 102 103 // These override the SetAttr methods in nsGenericHTMLElement (need 104 // both here to silence compiler warnings). SetAttr(int32_t aNameSpaceID,nsIAtom * aName,const nsAString & aValue,bool aNotify)105 nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, 106 const nsAString& aValue, bool aNotify) 107 { 108 return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify); 109 } 110 virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, 111 nsIAtom* aPrefix, const nsAString& aValue, 112 bool aNotify) override; 113 114 /** 115 * GetRowSpec is used to get the "rows" spec. 116 * @param out int32_t aNumValues The number of row sizes specified. 117 * @param out nsFramesetSpec* aSpecs The array of size specifications. 118 This is _not_ owned by the caller, but by the nsFrameSetElement 119 implementation. DO NOT DELETE IT. 120 */ 121 nsresult GetRowSpec(int32_t *aNumValues, const nsFramesetSpec** aSpecs); 122 /** 123 * GetColSpec is used to get the "cols" spec 124 * @param out int32_t aNumValues The number of row sizes specified. 125 * @param out nsFramesetSpec* aSpecs The array of size specifications. 126 This is _not_ owned by the caller, but by the nsFrameSetElement 127 implementation. DO NOT DELETE IT. 128 */ 129 nsresult GetColSpec(int32_t *aNumValues, const nsFramesetSpec** aSpecs); 130 131 132 virtual bool ParseAttribute(int32_t aNamespaceID, 133 nsIAtom* aAttribute, 134 const nsAString& aValue, 135 nsAttrValue& aResult) override; 136 virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute, 137 int32_t aModType) const override; 138 139 virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override; 140 141 protected: 142 virtual ~HTMLFrameSetElement(); 143 144 virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override; 145 146 private: 147 nsresult ParseRowCol(const nsAString& aValue, 148 int32_t& aNumSpecs, 149 UniquePtr<nsFramesetSpec[]>* aSpecs); 150 151 /** 152 * The number of size specs in our "rows" attr 153 */ 154 int32_t mNumRows; 155 /** 156 * The number of size specs in our "cols" attr 157 */ 158 int32_t mNumCols; 159 /** 160 * The style hint to return for the rows/cols attrs in 161 * GetAttributeChangeHint 162 */ 163 nsChangeHint mCurrentRowColHint; 164 /** 165 * The parsed representation of the "rows" attribute 166 */ 167 UniquePtr<nsFramesetSpec[]> mRowSpecs; // parsed, non-computed dimensions 168 /** 169 * The parsed representation of the "cols" attribute 170 */ 171 UniquePtr<nsFramesetSpec[]> mColSpecs; // parsed, non-computed dimensions 172 }; 173 174 } // namespace dom 175 } // namespace mozilla 176 177 #endif // HTMLFrameSetElement_h 178