📄 mgjs_common.cpp
字号:
#include "mgjs_main.h"#include <../misc/htmlattrs.h> #include <html_formimpl.h>#include <htmltags.h>#if 0enum HTMLCollectionImpl_Type { // from HTMLDocument DOC_IMAGES, // all IMG elements in the document DOC_APPLETS, // all OBJECT and APPLET elements DOC_FORMS, // all FORMS DOC_LINKS, // all A _and_ AREA elements with a value for href DOC_ANCHORS, // all A elements with a value for name // from HTMLTable, HTMLTableSection, HTMLTableRow TABLE_ROWS, // all rows in this table or tablesection TABLE_TBODIES, // all TBODY elements in this table TSECTION_ROWS, // all rows elements in this table section TR_CELLS, // all CELLS in this row // from FORM FORM_ELEMENTS, // from SELECT SELECT_OPTIONS, // from HTMLMap MAP_AREAS, DOC_ALL // "all" elements };#endifunsigned long HTMLCollectionImpl_calcLength(NodeImpl *current,int type) { unsigned long len = 0; while(current) { if(!current->isTextNode()) { bool deep = true; HTMLElementImpl *e = static_cast<HTMLElementImpl *>(current); switch(type) { case DOC_IMAGES: if(e->id() == ID_IMG) len++; break; case DOC_FORMS: if(e->id() == ID_FORM) len++; break; case TABLE_TBODIES: if(e->id() == ID_TBODY) len++; else if(e->id() == ID_TABLE) deep = false; break; case TR_CELLS: if(e->id() == ID_TD) len++; else if(e->id() == ID_TABLE) deep = false; break; case TABLE_ROWS: case TSECTION_ROWS: if(e->id() == ID_TR || e->id() == ID_TH) len++; else if(e->id() == ID_TABLE) deep = false; break; case SELECT_OPTIONS: if(e->id() == ID_OPTION) len++; break; case MAP_AREAS: if(e->id() == ID_AREA) len++; break; case FORM_ELEMENTS: switch(e->id()) { case ID_INPUT: case ID_BUTTON: case ID_SELECT: case ID_TEXTAREA: case ID_ISINDEX: //case ID_LABEL: // ### does it really belong here??? len++; break; default: break; } break; case DOC_APPLETS: // all OBJECT and APPLET elements if(e->id() == ID_OBJECT || e->id() == ID_APPLET) len++; break; case DOC_LINKS: // all A _and_ AREA elements with a value for href if(e->id() == ID_A || e->id() == ID_AREA) if(e->getAttribute(ATTR_HREF) != 0) len++; break; case DOC_ANCHORS: // all A elements with a value for name if(e->id() == ID_A) if(e->getAttribute(ATTR_NAME) != 0) len++; break; case DOC_ALL: // "all" elements len++; break; default:;// kdDebug( 6030 ) << "Error in HTMLCollection, wrong tagId!" << endl; } if(deep && current->firstChild()) len += HTMLCollectionImpl_calcLength(current->firstChild(),type); } current = current->nextSibling(); } return len;}// since the collections are to be "live", we have to do the// calculation every time...unsigned long HTMLCollectionImpl_length(NodeImpl *base,int type){ return HTMLCollectionImpl_calcLength(base->firstChild(),type);}NodeImpl *HTMLCollectionImpl_getItem(NodeImpl *current, int index, int &len,int type){ while(current) { if(!current->isTextNode()) { bool deep = true; HTMLElementImpl *e = static_cast<HTMLElementImpl *>(current); switch(type) { case DOC_IMAGES: if(e->id() == ID_IMG) len++; break; case DOC_FORMS: if(e->id() == ID_FORM) len++; break; case TABLE_TBODIES: if(e->id() == ID_TBODY) len++; else if(e->id() == ID_TABLE) deep = false; break; case TR_CELLS: if(e->id() == ID_TD) len++; else if(e->id() == ID_TABLE) deep = false; break; case TABLE_ROWS: case TSECTION_ROWS: if(e->id() == ID_TR || e->id() == ID_TH) len++; else if(e->id() == ID_TABLE) deep = false; break; case SELECT_OPTIONS: if(e->id() == ID_OPTION) len++; break; case MAP_AREAS: if(e->id() == ID_AREA) len++; break; case FORM_ELEMENTS: switch(e->id()) { case ID_INPUT: case ID_BUTTON: case ID_SELECT: case ID_TEXTAREA: case ID_ISINDEX: //case ID_LABEL: // ### does it really belong here??? len++; break; default: break; } break; case DOC_APPLETS: // all OBJECT and APPLET elements if(e->id() == ID_OBJECT || e->id() == ID_APPLET) len++; break; case DOC_LINKS: // all A _and_ AREA elements with a value for href if(e->id() == ID_A || e->id() == ID_AREA) if(e->getAttribute(ATTR_HREF) != 0) len++; break; case DOC_ANCHORS: // all A elements with a value for name if(e->id() == ID_A) if(e->getAttribute(ATTR_NAME) != 0) len++; break; case DOC_ALL: len++; break; default:;// kdDebug( 6030 ) << "Error in HTMLCollection, wrong tagId!" << endl; } if(len == (index + 1)) return current; NodeImpl *retval=0; if(deep && current->firstChild()) retval = HTMLCollectionImpl_getItem(current->firstChild(), index, len,type); if(retval) return retval; } current = current->nextSibling(); } return 0;}NodeImpl *HTMLCollectionImpl_item(NodeImpl *base, unsigned long index ,int type){ int pos = 0; return HTMLCollectionImpl_getItem(base->firstChild(), index, pos,type);}NodeImpl *HTMLCollectionImpl_getNamedItem(NodeImpl *current, int attr_id, const DOMString &name ,int type) { if(name.isEmpty()) return 0; while(current) { if(!current->isTextNode()) { bool deep = true; bool check = false; HTMLElementImpl *e = static_cast<HTMLElementImpl *>(current); switch(type) { case DOC_IMAGES: if(e->id() == ID_IMG) check = true; break; case DOC_FORMS: if(e->id() == ID_FORM) check = true; break; case TABLE_TBODIES: if(e->id() == ID_TBODY) check = true; else if(e->id() == ID_TABLE) deep = false; break; case TR_CELLS: if(e->id() == ID_TD) check = true; else if(e->id() == ID_TABLE) deep = false; break; case TABLE_ROWS: case TSECTION_ROWS: if(e->id() == ID_TR || e->id() == ID_TH) check = true; else if(e->id() == ID_TABLE) deep = false; break; case SELECT_OPTIONS: if(e->id() == ID_OPTION) check = true; break; case MAP_AREAS: if(e->id() == ID_AREA) check = true; break; case FORM_ELEMENTS: switch(e->id()) { case ID_INPUT: case ID_BUTTON: case ID_SELECT: case ID_TEXTAREA: case ID_ISINDEX: //case ID_LABEL: // ### does it really belong here??? check = true; break; default: break; } break; case DOC_APPLETS: // all OBJECT and APPLET elements if(e->id() == ID_OBJECT || e->id() == ID_APPLET) check = true; break; case DOC_LINKS: // all A _and_ AREA elements with a value for href if(e->id() == ID_A || e->id() == ID_AREA) if(e->getAttribute(ATTR_HREF) != 0) check = true; break; case DOC_ANCHORS: // all A elements with a value for name if(e->id() == ID_A) if(e->getAttribute(ATTR_NAME) != 0) check = true; break; case DOC_ALL: check = true; break; default:// kdDebug( 6030 ) << "Error in HTMLCollection, wrong tagId!" << endl; break; } if(check && e->getAttribute(attr_id) == name) { //kdDebug( 6030 ) << "found node: " << e << " " << current << " " << e->id() << endl; return current; } NodeImpl *retval = 0; if(deep && current->firstChild()) retval = HTMLCollectionImpl_getNamedItem(current->firstChild(), attr_id, name, type); if(retval) { //kdDebug( 6030 ) << "got a return value " << retval << endl; return retval; } } current = current->nextSibling(); } return 0;}NodeImpl *HTMLCollectionImpl_namedItem(NodeImpl *base, const DOMString &name ,int type){ NodeImpl *n; n = HTMLCollectionImpl_getNamedItem(base->firstChild(), ATTR_ID, name, type); if(n) return n; return HTMLCollectionImpl_getNamedItem(base->firstChild(), ATTR_NAME, name, type);}JSBool HTML_NewObjectByElementCommon(JSContext *cx, JSObject *obj, JSObject *protoObj,JSObject *parentObj,ElementImpl *eImpl ,jsval *rval){ JSObject *newObj=NULL; if(!eImpl)return JS_FALSE;#if 0 //DEBUG_BY_XHTANG fprintf(stderr,"Common.cpp:eImpl->id:%d\n",eImpl->id());#endif switch(eImpl->id()){ case ID_BODY: newObj = NewScriptHTMLBodyElement(cx,protoObj,parentObj,eImpl); break; case ID_FORM: newObj=NewScriptHTMLFormElement(cx,protoObj,parentObj,eImpl); break; case ID_INPUT: newObj=NewScriptHTMLInputElement(cx,protoObj,parentObj,eImpl); break; case ID_SELECT: newObj=NewScriptHTMLSelectElement(cx,protoObj,parentObj,eImpl); break; case ID_BUTTON: newObj=NewScriptHTMLButtonElement(cx,protoObj,parentObj,eImpl); break; case ID_TEXTAREA: newObj=NewScriptHTMLAreaElement(cx,protoObj,parentObj,eImpl); break; case ID_OPTION: newObj=NewScriptHTMLOptionElement(cx,protoObj,parentObj,eImpl); break; case ID_P: newObj=NewScriptHTMLParagraphElement(cx,protoObj,parentObj,eImpl); break; case ID_OL: newObj=NewScriptHTMLOListElement(cx,protoObj,parentObj,eImpl); break; case ID_UL: newObj=NewScriptHTMLUListElement(cx,protoObj,parentObj,eImpl); break; case ID_DL: newObj=NewScriptHTMLDListElement(cx,protoObj,parentObj,eImpl); break; case ID_HR: newObj=NewScriptHTMLHRElement(cx,protoObj,parentObj,eImpl); break; case ID_PRE: newObj=NewScriptHTMLPreElement(cx,protoObj,parentObj,eImpl); break; case ID_DIV: newObj=NewScriptHTMLDivElement(cx,protoObj,parentObj,eImpl); break; case ID_LEGEND: newObj=NewScriptHTMLLegendElement(cx,protoObj,parentObj,eImpl); break; case ID_LABEL: newObj=NewScriptHTMLLabelElement(cx,protoObj,parentObj,eImpl); break; case ID_FIELDSET: newObj=NewScriptHTMLFieldSetElement(cx,protoObj,parentObj,eImpl); break; case ID_TABLE: newObj=NewScriptHTMLTableElement(cx,protoObj,parentObj,eImpl); break; case ID_TR: newObj=NewScriptHTMLTableRowElement(cx,protoObj,parentObj,eImpl); break; case ID_TH: case ID_TD: newObj=NewScriptHTMLTableCellElement(cx,protoObj,parentObj,eImpl); break; case ID_COL: newObj=NewScriptHTMLTableColElement(cx,protoObj,parentObj,eImpl); break; case ID_CAPTION: newObj=NewScriptHTMLTableCaptionElement(cx,protoObj,parentObj,eImpl); break; case ID_THEAD: case ID_TBODY: case ID_TFOOT: newObj=NewScriptHTMLTableSectionElement(cx,protoObj,parentObj,eImpl); break; case ID_OBJECT: newObj=NewScriptHTMLObjectElement(cx,protoObj,parentObj,eImpl); break; case ID_OPTGROUP: newObj=NewScriptHTMLOptGroupElement(cx,protoObj,parentObj,eImpl); break; case ID_DIR: newObj=NewScriptHTMLDirectoryElement(cx,protoObj,parentObj,eImpl); break; case ID_MENU: newObj=NewScriptHTMLMenuElement(cx,protoObj,parentObj,eImpl); break; case ID_H1: case ID_H2: case ID_H3: case ID_H4: case ID_H5: case ID_H6: newObj=NewScriptHTMLHeadingElement(cx,protoObj,parentObj,eImpl); break; case ID_Q: newObj=NewScriptHTMLQuoteElement(cx,protoObj,parentObj,eImpl); break; case ID_BR: newObj=NewScriptHTMLBRElement(cx,protoObj,parentObj,eImpl); break; case ID_PARAM: newObj=NewScriptHTMLParamElement(cx,protoObj,parentObj,eImpl); break; case ID_SCRIPT: newObj=NewScriptHTMLScriptElement(cx,protoObj,parentObj,eImpl); break; case ID_AREA: newObj=NewScriptHTMLAreaElement(cx,protoObj,parentObj,eImpl); break; case ID_MAP: newObj=NewScriptHTMLMapElement(cx,protoObj,parentObj,eImpl); break; case ID_APPLET: newObj=NewScriptHTMLAppletElement(cx,protoObj,parentObj,eImpl); break; case ID_IMG: newObj=NewScriptHTMLImageElement(cx,protoObj,parentObj,eImpl); break; case ID_A: newObj=NewScriptHTMLAnchorElement(cx,protoObj,parentObj,eImpl); break; case ID_INS: case ID_DEL: newObj=NewScriptHTMLModElement(cx,protoObj,parentObj,eImpl); break; case ID_FONT: newObj=NewScriptHTMLFontElement(cx,protoObj,parentObj,eImpl); break; case ID_BASEFONT: newObj=NewScriptHTMLBaseFontElement(cx,protoObj,parentObj,eImpl); break; case ID_BASE: newObj=NewScriptHTMLBaseElement(cx,protoObj,parentObj,eImpl); break; case ID_ISINDEX: newObj=NewScriptHTMLIsIndexElement(cx,protoObj,parentObj,eImpl); break; case ID_STYLE: newObj=NewScriptHTMLStyleElement(cx,protoObj,parentObj,eImpl); break; case ID_META: newObj=NewScriptHTMLMetaElement(cx,protoObj,parentObj,eImpl); break; case ID_LINK: newObj=NewScriptHTMLLinkElement(cx,protoObj,parentObj,eImpl); break; case ID_HEAD: newObj=NewScriptHTMLHeadElement(cx,protoObj,parentObj,eImpl); break; case ID_HTML: newObj=NewScriptHTMLHtmlElement(cx,protoObj,parentObj,eImpl); break; case ID_TITLE: newObj=NewScriptHTMLTitleElement(cx,protoObj,parentObj,eImpl); break; case ID_FRAMESET: newObj=NewScriptHTMLFrameSetElement(cx,protoObj,parentObj,eImpl); break; case ID_FRAME: newObj=NewScriptHTMLFrameElement(cx,protoObj,parentObj,eImpl); break; case ID_IFRAME: newObj=NewScriptHTMLIFrameElement(cx,protoObj,parentObj,eImpl); break;#if 0 default: newObj=NewScriptHTMLElement(cx,mdocp->Element,0,eImpl); break;#endif } if(!newObj)return JS_FALSE; *rval=OBJECT_TO_JSVAL(newObj); return JS_TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -