| # khtml Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# kjs_range.cpp

    00001 // -*- c-basic-offset: 2 -*-
    00002 /*
    00003  *  This file is part of the KDE libraries
    00004  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
    00005  *
    00006  *  This library is free software; you can redistribute it and/or
    00007  *  modify it under the terms of the GNU Library General Public
    00008  *  License as published by the Free Software Foundation; either
    00009  *  version 2 of the License, or (at your option) any later version.
    00010  *
    00011  *  This library is distributed in the hope that it will be useful,
    00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014  *  Library General Public License for more details.
    00015  *
    00016  *  You should have received a copy of the GNU Library General Public
    00017  *  License along with this library; if not, write to the Free Software
    00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00019  */
    00020
    00021 #include "kjs_range.h"
    00022 #include "kjs_range.lut.h"
    00023 #include <kdebug.h>
    00024
    00025 using namespace KJS;
    00026
    00027 // -------------------------------------------------------------------------
    00028
    00029 const ClassInfo DOMRange::info = { "Range", 0, &DOMRangeTable, 0 };
    00030 /*
    00031 @begin DOMRangeTable 7
    00032   startContainer        DOMRange::StartContainer        DontDelete|ReadOnly
    00033   startOffset           DOMRange::StartOffset           DontDelete|ReadOnly
    00034   endContainer          DOMRange::EndContainer          DontDelete|ReadOnly
    00035   endOffset             DOMRange::EndOffset             DontDelete|ReadOnly
    00036   collapsed             DOMRange::Collapsed             DontDelete|ReadOnly
    00037   commonAncestorContainer DOMRange::CommonAncestorContainer     DontDelete|ReadOnly
    00038 @end
    00039 @begin DOMRangeProtoTable 17
    00040   setStart              DOMRange::SetStart              DontDelete|Function 2
    00041   setEnd                DOMRange::SetEnd                DontDelete|Function 2
    00042   setStartBefore        DOMRange::SetStartBefore        DontDelete|Function 1
    00043   setStartAfter         DOMRange::SetStartAfter         DontDelete|Function 1
    00044   setEndBefore          DOMRange::SetEndBefore          DontDelete|Function 1
    00045   setEndAfter           DOMRange::SetEndAfter           DontDelete|Function 1
    00046   collapse              DOMRange::Collapse              DontDelete|Function 1
    00047   selectNode            DOMRange::SelectNode            DontDelete|Function 1
    00048   selectNodeContents    DOMRange::SelectNodeContents    DontDelete|Function 1
    00049   compareBoundaryPoints DOMRange::CompareBoundaryPoints DontDelete|Function 2
    00050   deleteContents        DOMRange::DeleteContents        DontDelete|Function 0
    00051   extractContents       DOMRange::ExtractContents       DontDelete|Function 0
    00052   cloneContents         DOMRange::CloneContents         DontDelete|Function 0
    00053   insertNode            DOMRange::InsertNode            DontDelete|Function 1
    00054   surroundContents      DOMRange::SurroundContents      DontDelete|Function 1
    00055   cloneRange            DOMRange::CloneRange            DontDelete|Function 0
    00056   toString              DOMRange::ToString              DontDelete|Function 0
    00057   detach                DOMRange::Detach                DontDelete|Function 0
    00058 @end
    00059 */
    00060 DEFINE_PROTOTYPE("DOMRange",DOMRangeProto)
    00061 IMPLEMENT_PROTOFUNC_DOM(DOMRangeProtoFunc)
    00062 IMPLEMENT_PROTOTYPE(DOMRangeProto,DOMRangeProtoFunc)
    00063
    00064 DOMRange::DOMRange(ExecState *exec, DOM::Range r)
    00065  : DOMObject(DOMRangeProto::self(exec)), range(r) {}
    00066
    00067 DOMRange::~DOMRange()
    00068 {
    00069   ScriptInterpreter::forgetDOMObject(range.handle());
    00070 }
    00071
    00072 Value DOMRange::tryGet(ExecState *exec, const UString &p) const
    00073 {
    00074   return DOMObjectLookupGetValue<DOMRange,DOMObject>(exec,p,&DOMRangeTable,this);
    00075 }
    00076
    00077 Value DOMRange::getValueProperty(ExecState *exec, int token) const
    00078 {
    00079   switch (token) {
    00080   case StartContainer:
    00081     return getDOMNode(exec,range.startContainer());
    00082   case StartOffset:
    00083     return Number(range.startOffset());
    00084   case EndContainer:
    00085     return getDOMNode(exec,range.endContainer());
    00086   case EndOffset:
    00087     return Number(range.endOffset());
    00088   case Collapsed:
    00089     return Boolean(range.collapsed());
    00090   case CommonAncestorContainer: {
    00091     DOM::Range range2 = range; // avoid const error
    00092     return getDOMNode(exec,range2.commonAncestorContainer());
    00093   }
    00094   default:
    00095     kdWarning() << "Unhandled token in DOMRange::getValueProperty : " << token << endl;
    00096     return Value();
    00097   }
    00098 }
    00099
    00100 Value DOMRangeProtoFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
    00101 {
    00102   KJS_CHECK_THIS( KJS::DOMRange, thisObj );
    00103   DOM::Range range = static_cast<DOMRange *>(thisObj.imp())->toRange();
    00104   Value result;
    00105
    00106   switch (id) {
    00107     case DOMRange::SetStart:
    00108       range.setStart(toNode(args[0]),args[1].toInteger(exec));
    00109       result = Undefined();
    00110       break;
    00111     case DOMRange::SetEnd:
    00112       range.setEnd(toNode(args[0]),args[1].toInteger(exec));
    00113       result = Undefined();
    00114       break;
    00115     case DOMRange::SetStartBefore:
    00116       range.setStartBefore(toNode(args[0]));
    00117       result = Undefined();
    00118       break;
    00119     case DOMRange::SetStartAfter:
    00120       range.setStartAfter(toNode(args[0]));
    00121       result = Undefined();
    00122       break;
    00123     case DOMRange::SetEndBefore:
    00124       range.setEndBefore(toNode(args[0]));
    00125       result = Undefined();
    00126       break;
    00127     case DOMRange::SetEndAfter:
    00128       range.setEndAfter(toNode(args[0]));
    00129       result = Undefined();
    00130       break;
    00131     case DOMRange::Collapse:
    00132       range.collapse(args[0].toBoolean(exec));
    00133       result = Undefined();
    00134       break;
    00135     case DOMRange::SelectNode:
    00136       range.selectNode(toNode(args[0]));
    00137       result = Undefined();
    00138       break;
    00139     case DOMRange::SelectNodeContents:
    00140       range.selectNodeContents(toNode(args[0]));
    00141       result = Undefined();
    00142       break;
    00143     case DOMRange::CompareBoundaryPoints:
    00144       result = Number(range.compareBoundaryPoints(static_cast<DOM::Range::CompareHow>(args[0].toInteger(exec)),toRange(args[1])));
    00145       break;
    00146     case DOMRange::DeleteContents:
    00147       range.deleteContents();
    00148       result = Undefined();
    00149       break;
    00150     case DOMRange::ExtractContents:
    00151       result = getDOMNode(exec,range.extractContents());
    00152       break;
    00153     case DOMRange::CloneContents:
    00154       result = getDOMNode(exec,range.cloneContents());
    00155       break;
    00156     case DOMRange::InsertNode:
    00157       range.insertNode(toNode(args[0]));
    00158       result = Undefined();
    00159       break;
    00160     case DOMRange::SurroundContents:
    00161       range.surroundContents(toNode(args[0]));
    00162       result = Undefined();
    00163       break;
    00164     case DOMRange::CloneRange:
    00165       result = getDOMRange(exec,range.cloneRange());
    00166       break;
    00167     case DOMRange::ToString:
    00168       result = getString(range.toString());
    00169       break;
    00170     case DOMRange::Detach:
    00171       range.detach();
    00172       result = Undefined();
    00173       break;
    00174   };
    00175
    00176   return result;
    00177 }
    00178
    00179 Value KJS::getDOMRange(ExecState *exec, DOM::Range r)
    00180 {
    00181   return cacheDOMObject<DOM::Range, KJS::DOMRange>(exec, r);
    00182 }
    00183
    00184 // -------------------------------------------------------------------------
    00185
    00186 const ClassInfo RangeConstructor::info = { "RangeConstructor", 0, &RangeConstructorTable, 0 };
    00187 /*
    00188 @begin RangeConstructorTable 5
    00189   START_TO_START        DOM::Range::START_TO_START      DontDelete|ReadOnly
    00190   START_TO_END          DOM::Range::START_TO_END        DontDelete|ReadOnly
    00191   END_TO_END            DOM::Range::END_TO_END          DontDelete|ReadOnly
    00192   END_TO_START          DOM::Range::END_TO_START        DontDelete|ReadOnly
    00193 @end
    00194 */
    00195
    00196 RangeConstructor::RangeConstructor(ExecState *exec)
    00197   : DOMObject(exec->interpreter()->builtinObjectPrototype()) { }
    00198
    00199 Value RangeConstructor::tryGet(ExecState *exec, const UString &p) const
    00200 {
    00201   return DOMObjectLookupGetValue<RangeConstructor,DOMObject>(exec,p,&RangeConstructorTable,this);
    00202 }
    00203
    00204 Value RangeConstructor::getValueProperty(ExecState *, int token) const
    00205 {
    00206   return Number(token);
    00207 }
    00208
    00209 Value KJS::getRangeConstructor(ExecState *exec)
    00210 {
    00211   return cacheGlobalObject<RangeConstructor>(exec, "[[range.constructor]]");
    00212 }
    00213
    00214
    00215 DOM::Range KJS::toRange(const Value& val)
    00216 {
    00217   Object obj = Object::dynamicCast(val);
    00218   if (obj.isNull() || !obj.inherits(&DOMRange::info))
    00219     return DOM::Range();
    00220
    00221   const DOMRange *dobj = static_cast<const DOMRange*>(obj.imp());
    00222   return dobj->toRange();
    00223 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:34:24 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001