File indexing completed on 2024-04-28 11:38:17

0001 /*
0002  * This file is part of the DOM implementation for KDE.
0003  *
0004  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
0005  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
0006  *
0007  * This library is free software; you can redistribute it and/or
0008  * modify it under the terms of the GNU Library General Public
0009  * License as published by the Free Software Foundation; either
0010  * version 2 of the License, or (at your option) any later version.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Library General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Library General Public License
0018  * along with this library; see the file COPYING.LIB.  If not, write to
0019  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020  * Boston, MA 02110-1301, USA.
0021  *
0022  */
0023 #ifndef HTML_MISCIMPL_H
0024 #define HTML_MISCIMPL_H
0025 
0026 #include "html_elementimpl.h"
0027 #include "xml/dom_nodelistimpl.h"
0028 #include "misc/shared.h"
0029 
0030 namespace DOM
0031 {
0032 
0033 class Node;
0034 class DOMString;
0035 class HTMLCollection;
0036 
0037 class HTMLBaseFontElementImpl : public HTMLElementImpl
0038 {
0039 public:
0040     HTMLBaseFontElementImpl(DocumentImpl *doc);
0041 
0042     ~HTMLBaseFontElementImpl();
0043 
0044     Id id() const override;
0045 };
0046 
0047 // -------------------------------------------------------------------------
0048 
0049 class HTMLCollectionImpl : public DynamicNodeListImpl
0050 {
0051     friend class DOM::HTMLCollection;
0052 public:
0053     enum Type {
0054         // from HTMLDocument
0055         DOC_IMAGES = LAST_NODE_LIST + 1, // all IMG elements in the document
0056         DOC_APPLETS,   // all OBJECT and APPLET elements
0057         DOC_FORMS,     // all FORMS
0058         DOC_LAYERS,    // all LAYERS
0059         DOC_LINKS,     // all A _and_ AREA elements with a value for href
0060         DOC_ANCHORS,      // all A elements with a value for name
0061         DOC_SCRIPTS,   // all SCRIPT elements
0062         // from HTMLTable, HTMLTableSection, HTMLTableRow
0063         TABLE_ROWS,    // all rows in this table
0064         TABLE_TBODIES, // all TBODY elements in this table
0065         TSECTION_ROWS, // all rows elements in this table section
0066         TR_CELLS,      // all CELLS in this row
0067         // from SELECT
0068         SELECT_OPTIONS,
0069         // from HTMLMap
0070         MAP_AREAS,
0071         FORMLESS_INPUT, // input elements that do not have form associated w/them
0072         DOC_ALL,        // "all" elements (IE)
0073         NODE_CHILDREN,   // first-level children (IE)
0074         FORM_ELEMENTS,   // input elements in a form
0075         WINDOW_NAMED_ITEMS,
0076         DOCUMENT_NAMED_ITEMS,
0077         LAST_TYPE
0078     };
0079 
0080     HTMLCollectionImpl(NodeImpl *_base, int _tagId);
0081 
0082     NodeImpl *item(unsigned long index) const override;
0083 
0084     // obsolete and not domtree changes save
0085     virtual NodeImpl *firstItem() const;
0086     virtual NodeImpl *nextItem() const;
0087 
0088     virtual NodeImpl *namedItem(const DOMString &name) const;
0089     // In case of multiple items named the same way
0090     virtual NodeImpl *nextNamedItem(const DOMString &name) const;
0091 
0092     QList<NodeImpl *> namedItems(const DOMString &name) const;
0093 
0094     int getType() const
0095     {
0096         return type;
0097     }
0098 
0099     NodeImpl *base()
0100     {
0101         return m_refNode;
0102     }
0103 protected:
0104     unsigned long calcLength(NodeImpl *start) const override;
0105 
0106     // The collection list the following elements
0107     int type: 8;
0108 
0109     // Reimplemented from DynamicNodeListImpl
0110     bool nodeMatches(NodeImpl *testNode, bool &doRecurse) const override;
0111 
0112     // Helper for name iteration: checks whether ID matches,
0113     // and inserts any name-matching things into namedItemsWithName
0114     bool checkForNameMatch(NodeImpl *node, const DOMString &name) const;
0115 };
0116 
0117 // this whole class is just a big hack to find form elements even in
0118 // malformed HTML elements
0119 // the famous <table><tr><form><td> problem
0120 class HTMLFormCollectionImpl : public HTMLCollectionImpl
0121 {
0122 public:
0123     // base must inherit HTMLGenericFormElementImpl or this won't work
0124     HTMLFormCollectionImpl(NodeImpl *_base);
0125     ~HTMLFormCollectionImpl() { }
0126 
0127     NodeImpl *item(unsigned long index) const override;
0128 
0129     NodeImpl *namedItem(const DOMString &name) const override;
0130     // In case of multiple items named the same way
0131     NodeImpl *nextNamedItem(const DOMString &name) const override;
0132 protected:
0133     unsigned long calcLength(NodeImpl *start) const override;
0134 
0135 private:
0136     mutable unsigned currentNamePos;
0137     mutable unsigned currentNameImgPos;
0138     mutable bool foundInput;
0139 };
0140 
0141 /*
0142  Special collection for items of given name/id under document. or window.; but using
0143  iteration interface
0144 */
0145 class HTMLMappedNameCollectionImpl : public HTMLCollectionImpl
0146 {
0147 public:
0148     HTMLMappedNameCollectionImpl(NodeImpl *_base, int type, const DOMString &name);
0149     bool nodeMatches(NodeImpl *testNode, bool &doRecurse) const override;
0150 
0151     static bool matchesName(ElementImpl *el, int type, const DOMString &name);
0152 private:
0153     DOMString name;
0154 };
0155 
0156 } //namespace
0157 
0158 #endif