tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

HTMLFrameSetElement.h (4597B)


      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/Span.h"
     12 #include "nsGenericHTMLElement.h"
     13 #include "nsTArray.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::dom {
     43 
     44 class OnBeforeUnloadEventHandlerNonNull;
     45 
     46 class HTMLFrameSetElement final : public nsGenericHTMLElement {
     47 public:
     48  explicit HTMLFrameSetElement(
     49      already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
     50      : nsGenericHTMLElement(std::move(aNodeInfo)),
     51        mCurrentRowColHint(NS_STYLE_HINT_REFLOW) {
     52    SetHasWeirdParserInsertionMode();
     53  }
     54 
     55  NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLFrameSetElement, frameset)
     56 
     57  // nsISupports
     58  NS_INLINE_DECL_REFCOUNTING_INHERITED(HTMLFrameSetElement,
     59                                       nsGenericHTMLElement)
     60 
     61  void GetCols(DOMString& aCols) { GetHTMLAttr(nsGkAtoms::cols, aCols); }
     62  void SetCols(const nsAString& aCols, ErrorResult& aError) {
     63    SetHTMLAttr(nsGkAtoms::cols, aCols, aError);
     64  }
     65  void GetRows(DOMString& aRows) { GetHTMLAttr(nsGkAtoms::rows, aRows); }
     66  void SetRows(const nsAString& aRows, ErrorResult& aError) {
     67    SetHTMLAttr(nsGkAtoms::rows, aRows, aError);
     68  }
     69 
     70  bool IsEventAttributeNameInternal(nsAtom* aName) override;
     71 
     72  // Event listener stuff; we need to declare only the ones we need to
     73  // forward to window that don't come from nsIDOMHTMLFrameSetElement.
     74 #define EVENT(name_, id_, type_, \
     75              struct_) /* nothing; handled by the superclass */
     76 #define WINDOW_EVENT_HELPER(name_, type_) \
     77  type_* GetOn##name_();                  \
     78  void SetOn##name_(type_* handler);
     79 #define WINDOW_EVENT(name_, id_, type_, struct_) \
     80  WINDOW_EVENT_HELPER(name_, EventHandlerNonNull)
     81 #define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
     82  WINDOW_EVENT_HELPER(name_, OnBeforeUnloadEventHandlerNonNull)
     83 #include "mozilla/EventNameList.h"  // IWYU pragma: keep
     84 #undef BEFOREUNLOAD_EVENT
     85 #undef WINDOW_EVENT
     86 #undef WINDOW_EVENT_HELPER
     87 #undef EVENT
     88 
     89  /**
     90   * GetRowSpec is used to get the "rows" spec.
     91   * @return The span of size specifications, owned by the
     92   *        nsFrameSetElement implementation.
     93   */
     94  Span<const nsFramesetSpec> GetRowSpec() MOZ_LIFETIME_BOUND;
     95  /**
     96   * GetColSpec is used to get the "cols" spec.
     97   * @return The span of size specifications, owned by the
     98   *        nsFrameSetElement implementation.
     99   */
    100  Span<const nsFramesetSpec> GetColSpec() MOZ_LIFETIME_BOUND;
    101 
    102  bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
    103                      const nsAString& aValue,
    104                      nsIPrincipal* aMaybeScriptedPrincipal,
    105                      nsAttrValue& aResult) override;
    106  nsChangeHint GetAttributeChangeHint(const nsAtom* aAttribute,
    107                                      AttrModType aModType) const override;
    108 
    109  nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
    110 
    111 protected:
    112  virtual ~HTMLFrameSetElement();
    113 
    114  JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
    115 
    116  void BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName,
    117                     const nsAttrValue* aValue, bool aNotify) override;
    118 
    119 private:
    120  nsresult ParseRowCol(const nsAttrValue& aValue,
    121                       nsTArray<nsFramesetSpec>& aSpecs);
    122 
    123  /**
    124   * The style hint to return for the rows/cols attrs in
    125   * GetAttributeChangeHint
    126   */
    127  nsChangeHint mCurrentRowColHint;
    128  /**
    129   * The parsed representation of the "rows" attribute
    130   */
    131  nsTArray<nsFramesetSpec> mRowSpecs;  // parsed, non-computed dimensions
    132  /**
    133   * The parsed representation of the "cols" attribute
    134   */
    135  nsTArray<nsFramesetSpec> mColSpecs;  // parsed, non-computed dimensions
    136 };
    137 
    138 }  // namespace mozilla::dom
    139 
    140 #endif  // HTMLFrameSetElement_h