# khtml Library API Documentation

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

This file is part of the documentation for khtml Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:33:19 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003