File indexing completed on 2024-04-28 15:23:15

0001 /*
0002  *  This file is part of the KDE libraries
0003  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
0004  *  Copyright (C) 2009 Maksim Orlovich (maksim@kde.org)
0005  *
0006  *  This library is free software; you can redistribute it and/or
0007  *  modify it under the terms of the GNU Library General Public
0008  *  License as published by the Free Software Foundation; either
0009  *  version 2 of the License, or (at your option) any later version.
0010  *
0011  *  This library is distributed in the hope that it will be useful,
0012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  *  Library General Public License for more details.
0015  *
0016  *  You should have received a copy of the GNU Library General Public
0017  *  License along with this library; if not, write to the Free Software
0018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0019  */
0020 
0021 #ifndef _KJS_RANGE_H_
0022 #define _KJS_RANGE_H_
0023 
0024 #include <QPointer>
0025 
0026 #include "ecma/kjs_dom.h"
0027 #include "xml/dom_docimpl.h"
0028 #include "xml/dom2_rangeimpl.h"
0029 #include "xml/dom_selection.h"
0030 
0031 namespace KJS
0032 {
0033 
0034 class DOMRange : public DOMObject
0035 {
0036 public:
0037     DOMRange(ExecState *exec, DOM::RangeImpl *r);
0038     ~DOMRange();
0039     using KJS::JSObject::getOwnPropertySlot;
0040     bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
0041     JSValue *getValueProperty(ExecState *exec, int token) const;
0042     // no put - all read-only
0043     const ClassInfo *classInfo() const override
0044     {
0045         return &info;
0046     }
0047     static const ClassInfo info;
0048     enum { StartContainer, StartOffset, EndContainer, EndOffset, Collapsed,
0049            CommonAncestorContainer,
0050            SetStart, SetEnd, SetStartBefore, SetStartAfter, SetEndBefore,
0051            SetEndAfter, Collapse, SelectNode, SelectNodeContents,
0052            CompareBoundaryPoints, DeleteContents, ExtractContents,
0053            CloneContents, InsertNode, SurroundContents, CloneRange, ToString,
0054            Detach, CreateContextualFragment
0055          };
0056     DOM::RangeImpl *impl() const
0057     {
0058         return m_impl.get();
0059     }
0060 protected:
0061     SharedPtr<DOM::RangeImpl> m_impl;
0062 };
0063 
0064 class DOMSelection: public JSObject
0065 {
0066 public:
0067     DOMSelection(ExecState *exec, DOM::DocumentImpl *parentDocument);
0068 
0069     using KJS::JSObject::getOwnPropertySlot;
0070     bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
0071     JSValue *getValueProperty(ExecState *exec, int token) const;
0072     // no put - all read-only
0073 
0074     const ClassInfo *classInfo() const override
0075     {
0076         return &info;
0077     }
0078     static const ClassInfo info;
0079 
0080     enum { AnchorNode, AnchorOffset, FocusNode, FocusOffset, IsCollapsed,
0081            Collapsed, CollapseToStart, CollapseToEnd, SelectAllChildren,
0082            DeleteFromDocument, RangeCount, GetRangeAt, AddRange, RemoveRange, RemoveAllRanges, ToString
0083          };
0084 
0085     DOM::Selection currentSelection() const;
0086     bool           attached() const; // if document & part are still alive..
0087     QPointer<DOM::DocumentImpl> m_document;
0088 };
0089 
0090 // Constructor object Range
0091 class RangeConstructor : public DOMObject
0092 {
0093 public:
0094     RangeConstructor(ExecState *);
0095     using KJS::JSObject::getOwnPropertySlot;
0096     bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
0097     JSValue *getValueProperty(ExecState *, int token) const;
0098     // no put - all read-only
0099     const ClassInfo *classInfo() const override
0100     {
0101         return &info;
0102     }
0103     static const ClassInfo info;
0104 };
0105 
0106 JSValue *getDOMRange(ExecState *exec, DOM::RangeImpl *r);
0107 JSValue *getRangeConstructor(ExecState *exec);
0108 JSObject *getRangeExceptionConstructor(ExecState *exec);
0109 
0110 /**
0111  * Convert an object to a RangeImpl. Returns 0 if not possible
0112  */
0113 DOM::RangeImpl *toRange(JSValue *);
0114 
0115 DEFINE_PSEUDO_CONSTRUCTOR(RangeExceptionPseudoCtor)
0116 
0117 class RangeException : public DOMObject
0118 {
0119 public:
0120     RangeException(ExecState *exec);
0121     const ClassInfo *classInfo() const override
0122     {
0123         return &info;
0124     }
0125     static const ClassInfo info;
0126 };
0127 
0128 } // namespace
0129 
0130 #endif