Home | History | Annotate | Download | only in dom
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  * Copyright (C) 2000 Frederik Holljen (frederik.holljen (at) hig.no)
      4  * Copyright (C) 2001 Peter Kelly (pmk (at) post.com)
      5  * Copyright (C) 2006 Samuel Weinig (sam.weinig (at) gmail.com)
      6  * Copyright (C) 2004, 2008, 2009 Apple Inc. All rights reserved.
      7  *
      8  * This library is free software; you can redistribute it and/or
      9  * modify it under the terms of the GNU Library General Public
     10  * License as published by the Free Software Foundation; either
     11  * version 2 of the License, or (at your option) any later version.
     12  *
     13  * This library is distributed in the hope that it will be useful,
     14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     16  * Library General Public License for more details.
     17  *
     18  * You should have received a copy of the GNU Library General Public License
     19  * along with this library; see the file COPYING.LIB.  If not, write to
     20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     21  * Boston, MA 02110-1301, USA.
     22  *
     23  */
     24 
     25 #ifndef NodeFilter_h
     26 #define NodeFilter_h
     27 
     28 #include "DOMWrapperWorld.h"
     29 #include "NodeFilterCondition.h"
     30 #include <wtf/RefPtr.h>
     31 
     32 namespace WebCore {
     33 
     34     class NodeFilter : public RefCounted<NodeFilter> {
     35     public:
     36         /**
     37          * The following constants are returned by the acceptNode()
     38          * method:
     39          */
     40         enum {
     41             FILTER_ACCEPT = 1,
     42             FILTER_REJECT = 2,
     43             FILTER_SKIP   = 3
     44         };
     45 
     46         /**
     47          * These are the available values for the whatToShow parameter.
     48          * They are the same as the set of possible types for Node, and
     49          * their values are derived by using a bit position corresponding
     50          * to the value of NodeType for the equivalent node type.
     51          */
     52         enum {
     53             SHOW_ALL                       = 0xFFFFFFFF,
     54             SHOW_ELEMENT                   = 0x00000001,
     55             SHOW_ATTRIBUTE                 = 0x00000002,
     56             SHOW_TEXT                      = 0x00000004,
     57             SHOW_CDATA_SECTION             = 0x00000008,
     58             SHOW_ENTITY_REFERENCE          = 0x00000010,
     59             SHOW_ENTITY                    = 0x00000020,
     60             SHOW_PROCESSING_INSTRUCTION    = 0x00000040,
     61             SHOW_COMMENT                   = 0x00000080,
     62             SHOW_DOCUMENT                  = 0x00000100,
     63             SHOW_DOCUMENT_TYPE             = 0x00000200,
     64             SHOW_DOCUMENT_FRAGMENT         = 0x00000400,
     65             SHOW_NOTATION                  = 0x00000800
     66         };
     67 
     68         static PassRefPtr<NodeFilter> create(PassRefPtr<NodeFilterCondition> condition)
     69         {
     70             return adoptRef(new NodeFilter(condition));
     71         }
     72 
     73         static PassRefPtr<NodeFilter> create()
     74         {
     75             return adoptRef(new NodeFilter());
     76         }
     77 
     78         short acceptNode(ScriptState*, Node*) const;
     79 
     80         // Do not call these functions. They are just scaffolding to support the Objective-C bindings.
     81         // They operate in the main thread normal world, and they swallow JS exceptions.
     82         short acceptNode(Node* node) const { return acceptNode(scriptStateFromNode(mainThreadNormalWorld(), node), node); }
     83 
     84         void setCondition(PassRefPtr<NodeFilterCondition> condition) { ASSERT(!m_condition); m_condition = condition; }
     85 
     86     private:
     87         NodeFilter(PassRefPtr<NodeFilterCondition> condition) : m_condition(condition) { }
     88         NodeFilter() {}
     89 
     90         RefPtr<NodeFilterCondition> m_condition;
     91     };
     92 
     93 } // namespace WebCore
     94 
     95 #endif // NodeFilter_h
     96