perignon now compiles, and back out brendan's xp.h change

This commit is contained in:
shaver%netscape.com 1998-09-16 14:45:07 +00:00
Родитель a1ad0f723b
Коммит 2886b9a12f
6 изменённых файлов: 84 добавлений и 248 удалений

Просмотреть файл

@ -29,6 +29,7 @@ CSRCS = domattr.c \
domdoc.c \
domelement.c \
domnode.c \
domstyle.c \
domtext.c \
$(NULL)

Просмотреть файл

@ -26,7 +26,10 @@
#define DOM_PRIV_H
#include "dom.h"
#include "xp.h"
#include "xp_mem.h"
#include "xpassert.h"
#include "xp_str.h"
/* #include "xp.h" -- this pulls in half the freaking client...no thanks! */
JSObject *
dom_NodeInit(JSContext *cx, JSObject *obj);

Просмотреть файл

@ -168,6 +168,7 @@ JSClass DOM_DOMClass = {
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, dom_finalize
};
#if 0
static JSBool
dom_hasFeature(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
@ -188,4 +189,5 @@ static JSFunctionSpec dom_methods[] = {
{"hasFeature", dom_hasFeature, 2},
{0}
};
#endif

Просмотреть файл

@ -1,223 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* DOM Document, DocumentFragment implementation.
*/
#include "dom_priv.h"
typedef struct DOM_DocumentFragmentStruct {
DOM_Node node;
void *data;
} DOM_DocumentFragmentStruct;
static JSBool
docfrag_masterDoc_get(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
return JS_TRUE;
}
static JSPropertySpec docfrag_props[] = {
{"masterDoc", -1, 0, docfrag_masterDoc_get},
{0}
};
/*
* Document
*
* XXX mush this stuff into existing "document" in lm_doc.c?
*/
typedef struct DOM_DocumentStruct {
DOM_DocumentFragmentStruct fragment;
} DOM_DocumentStruct;
static void
document_finalize(JSContext *cx, JSObject *obj)
{
/* chain destructors */
/* node_finalize(cx, obj); */
}
static JSBool
document_setter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
return JS_TRUE;
}
static JSBool
document_getter(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
return JS_TRUE;
}
JSClass DOM_DocumentClass = {
"Document", JSCLASS_HAS_PRIVATE,
JS_PropertyStub, JS_PropertyStub, document_getter, document_setter,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, document_finalize
};
static JSBool
doc_createEntity(JSContext *cx, JSObject* obj, uintN argc, jsval *argv,
jsval *rval)
{
/* new Entity */
return JS_TRUE;
}
static JSBool
doc_createEntityReference(JSContext *cx, JSObject* obj, uintN argc,
jsval *argv, jsval *rval)
{
/* new EntityReference */
return JS_TRUE;
}
static JSBool
doc_createDocumentFragment(JSContext *cx, JSObject* obj, uintN argc,
jsval *argv, jsval *rval)
{
/* new DocumentFragment */
return JS_TRUE;
}
static JSBool
doc_createElement(JSContext *cx, JSObject* obj, uintN argc, jsval *argv,
jsval *rval)
{
JSString *tagName;
if (!JS_ConvertArguments(cx, argc, argv, "S", &tagName))
return JS_FALSE;
/* new Element */
return JS_TRUE;
}
static JSBool
doc_createTextNode(JSContext *cx, JSObject* obj, uintN argc, jsval *argv,
jsval *rval)
{
JSString *text;
if (!JS_ConvertArguments(cx, argc, argv, "S", &text))
return JS_FALSE;
/* new TextNode */
return JS_TRUE;
}
static JSBool
doc_createComment(JSContext *cx, JSObject* obj, uintN argc, jsval *argv,
jsval *rval)
{
JSString *comment;
if (!JS_ConvertArguments(cx, argc, argv, "S", &comment))
return JS_FALSE;
/* new Comment */
return JS_TRUE;
}
static JSBool
doc_createCDATASection(JSContext *cx, JSObject* obj, uintN argc, jsval *argv,
jsval *rval)
{
JSString *cdata;
if (!JS_ConvertArguments(cx, argc, argv, "S", &cdata))
return JS_FALSE;
/* new CDATA */
return JS_TRUE;
}
static JSBool
doc_createProcessingInstruction(JSContext *cx, JSObject* obj, uintN argc,
jsval *argv, jsval *rval)
{
JSString *target, *data;
if (!JS_ConvertArguments(cx, argc, argv, "SS", &target, &data))
return JS_FALSE;
/* new PI */
return JS_TRUE;
}
static JSBool
doc_createAttribute(JSContext *cx, JSObject* obj, uintN argc, jsval *argv,
jsval *rval)
{
JSString *name;
if (!JS_ConvertArguments(cx, argc, argv, "S", &name))
return JS_FALSE;
/* new attr */
return JS_TRUE;
}
static JSBool
doc_getElementsByTagName(JSContext *cx, JSObject* obj, uintN argc,
jsval *argv, jsval *rval)
{
JSString *tagName;
if (!JS_ConvertArguments(cx, argc, argv, "S", &tagName))
return JS_FALSE;
return JS_TRUE;
}
static JSFunctionSpec document_methods[] = {
{"createEntity", doc_createEntity, 0},
{"createEntityReference", doc_createEntityReference, 0},
{"createDocumentFragment", doc_createDocumentFragment, 0},
{"createElement", doc_createElement, 1},
{"createTextNode", doc_createTextNode, 1},
{"createComment", doc_createComment, 1},
{"createCDATASection", doc_createCDATASection, 1},
{"createProcessingInstruction", doc_createProcessingInstruction, 2},
{"createAttribute", doc_createAttribute, 1},
{"getElementsByTagName", doc_getElementsByTagName, 1},
{0}
};
enum {
DOCUMENT_DOCTYPE = -1,
DOCUMENT_IMPLEMENTATION = -2,
DOCUMENT_DOCUMENTELEMENT = -3
};
static JSPropertySpec document_props[] = {
{"doctype", DOCUMENT_DOCTYPE},
{"implementation", DOCUMENT_IMPLEMENTATION},
{"documentElement", DOCUMENT_DOCUMENTELEMENT},
{0}
};
static JSBool
Document(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *vp)
{
return JS_TRUE;
}
JSObject *
DOM_DocumentInit(JSContext *cx, JSObject *scope, JSObject *docfrag_prototype)
{
JSObject *documentProto;
documentProto = JS_InitClass(cx, scope, docfrag_prototype,
&DOM_DocumentClass, Document, 0,
document_props, document_methods,
NULL, NULL);
if (!documentProto)
return NULL;
return documentProto;
}

Просмотреть файл

@ -18,6 +18,54 @@
#include "domstyle.h"
static int
CompareSelectors(const void *v1, const void *v2)
{
DOM_StyleSelector *s1 = (DOM_StyleSelector *)v1,
*s2 = (DOM_StyleSelector *)v2;
return s1->type == s2->type &&
/* compare base selector */
!XP_STRCMP(s1->selector, s2->selector) &&
/* if both have a psuedo, they have to match, else both must be NULL */
(s1->pseudo && s2->pseudo ?
XP_STRCMP(s1->pseudo, s2->pseudo) :
!(s1 || s2));
}
DOM_StyleDatabase *
DOM_NewStyleDatabase(JSContext *cx)
{
DOM_StyleDatabase *db = XP_NEW_ZAP(DOM_StyleDatabase);
if (!db)
return NULL;
db->ht = PL_NewHashTable(32, PL_HashString, PL_CompareStrings,
CompareSelectors, NULL, NULL);
if (!db->ht) {
XP_FREE(db);
return NULL;
}
return db;
}
void
DOM_DestroyStyleDatabase(JSContext *cx, DOM_StyleDatabase *db)
{
PL_HashTableDestroy(db->ht);
XP_FREE(db);
}
static JSBool
InsertBaseSelector(JSContext *cx, DOM_StyleDatabase *db,
DOM_StyleSelector *sel)
{
return PL_HashTableAdd(db->ht, sel->selector, sel) != NULL;
}
static DOM_StyleSelector *
GetBaseSelector(JSContext *cx, DOM_StyleDatabase *db, DOM_StyleToken type,
DOM_StyleToken pseudo)
@ -30,16 +78,16 @@ GetBaseSelector(JSContext *cx, DOM_StyleDatabase *db, DOM_StyleToken type,
static void
DestroySelector(JSContext *cx, DOM_StyleSelector *sel)
{
XP_FREE(sel->selector);
XP_FREE((char *)sel->selector);
if (sel->pseudo)
XP_FREE(sel->pseudo);
XP_FREE((char *)sel->pseudo);
if (sel->rules) {
DOM_StyleRule *iter, *next;
iter = sel->rules;
do {
next = iter->next;
XP_FREE(iter->entry.name);
XP_FREE(iter->entry.value);
XP_FREE((char *)iter->entry.name);
XP_FREE((char *)iter->entry.value);
XP_FREE(iter);
iter = next;
} while (iter);
@ -93,23 +141,24 @@ GetPseudo(JSContext *cx, DOM_Element *element)
return entry ? entry->value : NULL;
}
#define ELEMENT_IS_TYPE(node, element) \
(!XP_STRCMP(((element))->tagName, (type)))
#define PSEUDO_MATCHES(p1, p2) (!XP_STRCMP((p1), (p2)))
#ifdef DEBUG_shaver
#define MATCH() \
#ifdef DEBUG_shaver \
fprintf(stderr, "selector %s:%s matches element %s\n", \
sel->selector, sel->pseudo ? sel->pseudo : "", \
element->tagName); \
element->tagName);
#else
#define MATCH()
#endif
#ifdef DEBUG_shaver
#define NO_MATCH() \
#ifdef DEBUG_shaver \
fprintf(stderr, "selector %s:%s doesn't match element %s\n", \
sel->selector, sel->pseudo ? sel->pseudo : "", \
element->tagName); \
element->tagName);
#else
#define NO_MATCH()
#endif
static JSBool
@ -117,9 +166,12 @@ SelectorMatchesToken(JSContext *cx, DOM_StyleSelector *sel,
DOM_StyleToken token, DOM_StyleToken pseudo)
{
/* XXX handle #ID and .class */
return !XPSTRCMP(sel->type, token);
return !XP_STRCMP(sel->selector, token);
}
#define ELEMENT_IS_TYPE(element, type) \
(!XP_STRCMP(((element))->tagName, (type)))
static JSBool
SelectorMatchesElement(JSContext *cx, DOM_Element *element,
DOM_StyleSelector *sel)
@ -128,7 +180,7 @@ SelectorMatchesElement(JSContext *cx, DOM_Element *element,
if (ELEMENT_IS_TYPE(element, sel->selector)) {
/* check pseudo, if any */
if (sel->pseudo) {
DOM_StyleToken elementPseudo = GetPseudo(element);
DOM_StyleToken elementPseudo = GetPseudo(cx, element);
if (PSEUDO_MATCHES(sel->pseudo, elementPseudo)) {
MATCH();
return JS_TRUE;
@ -163,7 +215,7 @@ AncestorOfType(JSContext *cx, DOM_Element *element, DOM_StyleSelector *sel)
/* check type */
if (SelectorMatchesElement(cx, element, sel))
return element;
element = (DOM_Element *)element.node->parent;
element = (DOM_Element *)element->node.parent;
} while (element);
return NULL;
@ -187,7 +239,7 @@ CheckSelector(JSContext *cx, DOM_Element *element, DOM_StyleSelector *sel,
if (sel->rules) {
uintN score = SELECTOR_SCORE(sel, specificity);
if (score > *best) { /* are we the best so far? */
entry = RuleValueFor(sel, property);
entry = RuleValueFor(cx, sel->rules, property);
if (entry) { /* do we have a value for this property? */
#ifdef DEBUG_shaver
fprintf(stderr, "- score %d, value %s\n",
@ -220,7 +272,7 @@ CheckSelector(JSContext *cx, DOM_Element *element, DOM_StyleSelector *sel,
JSBool
DOM_StyleGetProperty(JSContext *cx, DOM_StyleDatabase *db,
DOM_Node *node, DOM_StyleToken property.
DOM_Node *node, DOM_StyleToken property,
DOM_StyleToken pseudo, DOM_AttributeEntry **entryp)
{
DOM_StyleSelector *sel;
@ -236,7 +288,7 @@ DOM_StyleGetProperty(JSContext *cx, DOM_StyleDatabase *db,
*entryp = NULL;
sel = GetBaseSelector(db, element->tagName);
sel = GetBaseSelector(cx, db, element->tagName, GetPseudo(cx, element));
if (!sel)
return JS_TRUE;

Просмотреть файл

@ -22,7 +22,8 @@
*/
#include "jsapi.h"
#include "dom.h"
#include "dom_priv.h"
#include "plhash.h"
#ifndef DOM_STYLE_H
#define DOM_STYLE_H
@ -45,14 +46,14 @@ typedef const char *DOM_StyleToken;
#define DOM_PSEUDOIZE(sel) ((sel) | DOM_STYLE_PSEUDO_TAG)
enum {
SELECTOR_UNKNOWN = 0
SELECTOR_UNKNOWN = 0,
SELECTOR_ID,
SELECTOR_CLASS,
SELECTOR_TAG
};
struct DOM_StyleDatabase {
PRHashTable *hashtable; /* PRHash, from js/ref or nsprpub, depending? */
PLHashTable *ht; /* PRHash, from js/ref or nsprpub, depending? */
};
DOM_StyleDatabase *
@ -99,8 +100,8 @@ struct DOM_StyleRule {
*
* Usage example:
*
* DOM_StyleAddRule(JSContext *cx, DOM_StyleDatabase *db,
* "A:visited { color: blue }", 0, DOM_STYLE_WEIGHT_AUTHOR);
* DOM_StyleParseRule(JSContext *cx, DOM_StyleDatabase *db,
* "A:visited { color: blue }", 0, DOM_STYLE_WEIGHT_AUTHOR);
*/
#define DOM_STYLE_WEIGHT_NONE 0
@ -109,8 +110,8 @@ struct DOM_StyleRule {
#define DOM_STYLE_WEIGHT_AUTHOR 6
JSBool
DOM_StyleAddRule(JSContext *cx, DOM_StyleDatabase *db, const char *rule,
uintN len, intN baseWeight);
DOM_StyleParseRule(JSContext *cx, DOM_StyleDatabase *db, const char *rule,
uintN len, intN baseWeight);
/*
* Get a style property for a node.