Move DOM_StyleDatabaseFromContext and DOMMOZ_NewStyleDatabase into libmocha,

where we're already pulling in the entire client.
Updated TODO (still out of date?).
This commit is contained in:
shaver%netscape.com 1998-10-09 00:50:27 +00:00
Родитель e45bcb7f60
Коммит 4af08b186c
4 изменённых файлов: 24 добавлений и 413 удалений

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

@ -1,45 +0,0 @@
#!gmake
#
# 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 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.
DEPTH = ../..
MODULE = dom
LIBRARY_NAME = dom
REQUIRES = js dom
ifdef MOZILLA_CLIENT
REQUIRES += lay img layer util
# hack until PERIGNON takes over the world
REQUIRES += style
endif
EXPORTS = dom.h domstyle.h
CSRCS = domattr.c \
domcore.c \
domdoc.c \
domelement.c \
domnode.c \
domstyle.c \
domtext.c \
$(NULL)
include $(DEPTH)/config/rules.mk
DEFINES += -DDOM

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

@ -1,27 +0,0 @@
General:
- document.create*
- escape HTML entities (JS entities?) coming into the text functions
Style:
- add a CSS-parsing input API, or extract CSS->JS conversion from
libstyle
- DOM_StyleIsDirty/DOM_LockStyle/DOM_UnlockStyle to allow global
caching of style data during document layout without racing with
alterations from mocha thread.
Layout:
- make proper LO_Elements for table stuff (pollmann)
- stick the DOM_StyleGetElementProperty stuff in all the right places
(reflow?)
- make <HR> honour inherited style (colour, etc.)
libmocha:
- move destruction into LM_ReleaseDocument
- add destruction of style db
- look closely at the implicit pop stuff in DOM_HTMLPushNode
- wire up node reordering
- put single <HTML> element child on #document at creation (and never
pop it off)
XML:
- everything, really

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

@ -24,14 +24,18 @@
#include "dom_priv.h"
#ifdef DEBUG_shaver
/* #define DEBUG_shaver_style_primitives 1 */
#define DEBUG_shaver_style_primitives 1
#define DEBUG_shaver_verbose 1
#define DEBUG_shaver_SME 1
#endif
#define STYLE_DB_FROM_CX(db, cx) \
PR_BEGIN_MACRO \
(db) = DOM_StyleDatabaseFromContext(cx); \
if (!db) \
return JS_FALSE; \
{ \
(db) = DOM_StyleDatabaseFromContext(cx); \
if (!db) \
return JS_FALSE; \
} \
PR_END_MACRO
/* if either is present, they must both be and match */
@ -78,151 +82,6 @@ DOM_DestroyStyleDatabase(JSContext *cx, DOM_StyleDatabase *db)
XP_FREE(db);
}
#ifdef MOZILLA_CLIENT
#include "lo_ele.h"
#include "structs.h"
#include "layout.h"
#include "laystyle.h"
#include "proto.h"
#define IMAGE_DEF_ANCHOR_BORDER 2
#define IMAGE_DEF_VERTICAL_SPACE 0
DOM_StyleDatabase *
DOMMOZ_NewStyleDatabase(JSContext *cx, lo_DocState *state)
{
DOM_StyleDatabase *db;
LO_Color visitCol, linkCol;
DOM_StyleSelector *sel, *imgsel;
DOM_AttributeEntry *entry;
lo_TopState *top = state->top_state;
/*
* Install default rules.
* In an ideal world (perhaps 5.0?), we would parse .netscape/ua.css
* at startup and keep the JSSS style buffer around for execution
* right here. That would be very cool in many ways, including the
* fact that people could have ua.css at all. We might want to
* make the weighting stuff work correctly at the same time, too,
* but I don't think it's vital.
*/
db = DOM_NewStyleDatabase(cx);
if (!db)
return NULL;
linkCol.red = STATE_UNVISITED_ANCHOR_RED(state);
linkCol.green = STATE_UNVISITED_ANCHOR_GREEN(state);
linkCol.blue = STATE_UNVISITED_ANCHOR_BLUE(state);
visitCol.red = STATE_VISITED_ANCHOR_RED(state);
visitCol.green = STATE_VISITED_ANCHOR_GREEN(state);
visitCol.blue = STATE_VISITED_ANCHOR_BLUE(state);
top->style_db = db;
sel = DOM_StyleFindSelectorFull(cx, db, NULL, SELECTOR_TAG,
"A", NULL, "link");
if (!sel)
goto error;
#define SET_DEFAULT_VALUE(name, value) \
entry = DOM_StyleAddRule(cx, db, sel, name, "default"); \
if (!entry) \
goto error; \
entry->dirty = JS_FALSE; \
entry->data = value;
/* A:link { color:prefLinkColor } */
SET_DEFAULT_VALUE(COLOR_STYLE, *(uint32*)&linkCol);
/* A:link { text-decoration:underline } */
if (lo_underline_anchors() &&
!DOM_StyleAddRule(cx, db, sel, TEXTDECORATION_STYLE, "underline"))
goto error;
sel = DOM_StyleFindSelectorFull(cx, db, NULL, SELECTOR_TAG,
"A", NULL, "visited");
if (!sel)
goto error;
/* A:visited { color:prefVisitedLinkColor } */
SET_DEFAULT_VALUE(COLOR_STYLE, *(uint32*)&visitCol);
/* A:visited { text-decoration:underline } */
if (lo_underline_anchors() &&
!DOM_StyleAddRule(cx, db, sel, TEXTDECORATION_STYLE, "underline"))
goto error;
/* set styles for IMG within A:link and A:visited */
/* XXX should set (and teach layout about) borderTop/Bottom, etc. */
imgsel = DOM_StyleFindSelectorFull(cx, db, NULL, SELECTOR_TAG,
"IMG", NULL, NULL);
if (!imgsel)
goto error;
/* set border styles for ``A:link IMG'' */
sel = DOM_StyleFindSelectorFull(cx, db, imgsel, SELECTOR_TAG,
"A", NULL, "link");
if (!sel)
goto error;
SET_DEFAULT_VALUE(BORDERWIDTH_STYLE, IMAGE_DEF_ANCHOR_BORDER);
SET_DEFAULT_VALUE(PADDING_STYLE, IMAGE_DEF_VERTICAL_SPACE);
/* set border styles for ``A:visited IMG'' */
sel = DOM_StyleFindSelectorFull(cx, db, imgsel, SELECTOR_TAG,
"A", NULL, "visited");
if (!sel)
goto error;
SET_DEFAULT_VALUE(BORDERWIDTH_STYLE, IMAGE_DEF_ANCHOR_BORDER);
SET_DEFAULT_VALUE(PADDING_STYLE, IMAGE_DEF_VERTICAL_SPACE);
#ifdef DEBUG_shaver
fprintf(stderr, "successfully added all default rules\n");
#endif
return db;
error:
if (db)
DOM_DestroyStyleDatabase(cx, db);
return NULL;
}
DOM_StyleDatabase *
DOM_StyleDatabaseFromContext(JSContext *cx)
{
MochaDecoder *decoder;
lo_TopState *top;
lo_DocState *state;
DOM_StyleDatabase *db = NULL;
if (!cx)
return NULL;
decoder = JS_GetPrivate(cx, JS_GetGlobalObject(cx));
if (!decoder)
return NULL;
LO_LockLayout();
top = lo_FetchTopState(decoder->window_context->doc_id);
if (!top)
goto out;
if (top->style_db) {
LO_UnlockLayout();
return (DOM_StyleDatabase *)top->style_db;
}
state = top->doc_state;
if (!state)
goto out;
db = DOMMOZ_NewStyleDatabase(cx, state);
top->style_db = db;
out:
LO_UnlockLayout();
return db;
}
#endif /* MOZILLA_CLIENT */
static JSBool
InsertBaseSelector(JSContext *cx, DOM_StyleDatabase *db,
DOM_StyleSelector *sel)
@ -303,12 +162,22 @@ GetBaseSelector(JSContext *cx, DOM_StyleDatabase *db, uint8 type,
DOM_StyleToken pseudo, JSBool strict)
{
DOM_StyleSelector *sel;
#ifdef DEBUG_shaver
fprintf(stderr, "getting base selector %d from db %p\n", type, db);
#endif
if (!cx)
return NULL;
if (!db)
STYLE_DB_FROM_CX(db, cx);
if (!db)
return NULL;
if (!db) {
db = DOM_StyleDatabaseFromContext(cx);
#ifdef DEBUG_shaver
fprintf(stderr, "got new db %p\n", db);
#endif
if (!db)
return NULL;
}
sel = PL_HashTableLookup(db->ht, token);
for (; sel; sel = sel->sibling) {
@ -658,6 +527,8 @@ DOM_StyleGetProperty(JSContext *cx, DOM_StyleDatabase *db,
token = iter->tagName;
extra = NULL;
break;
default:
continue;
}
if (!token)
continue;

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

@ -1,188 +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 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.
*/
/*
* Perignon: store style information in the DOM, using CSS-1 selectors.
*/
#include "jsapi.h"
#include "dom.h"
#include "plhash.h"
#ifndef DOM_STYLE_H
#define DOM_STYLE_H
typedef struct DOM_StyleDatabase DOM_StyleDatabase;
typedef struct DOM_StyleSelector DOM_StyleSelector;
typedef struct DOM_StyleRule DOM_StyleRule;
/*
* DOM_StyleTokens are used for identification of elements ("H1"), style
* properties ("color"), style values ("blue") and pseudo-classes ("visited").
*/
/* this may become int or something later, for speed */
typedef const char *DOM_StyleToken;
enum {
SELECTOR_UNKNOWN = 0,
SELECTOR_ID,
SELECTOR_CLASS,
SELECTOR_TAG
};
struct DOM_StyleDatabase {
PLHashTable *ht;
};
DOM_StyleDatabase *
DOM_NewStyleDatabase(JSContext *cx);
void
DOM_DestroyStyleDatabase(JSContext *cx, DOM_StyleDatabase *db);
/*
* Find or create the StyleDatabase for the given JSContext.
* The embedder must provide an implementation, or #define MOZILLA_CLIENT
* to get the Mozilla-specific one which depends on MochaDecoder and
* MWContext and lo_TopState and stuff.
*/
DOM_StyleDatabase *
DOM_StyleDatabaseFromContext(JSContext *cx);
struct DOM_StyleSelector {
int8 type;
DOM_StyleToken selector;
DOM_StyleToken pseudo;
DOM_StyleToken extra;
DOM_StyleSelector *enclosing;
DOM_StyleSelector *sibling;
DOM_StyleRule *rules;
JSObject *mocha_object; /* reflection for this selector's rules */
};
/*
* Find or create a selector for the given enclosing element type, starting
* from the provided (optional) base selector.
*
* Usage examples:
*
* Find/create a selector for "B"
* sel = DOM_StyleFindSelector(cx, db, NULL, "B", NULL);
*
* Now find/create a selector for "CODE B":
* sel2 = DOM_StyleFindSelector(cx, db, sel, "CODE", NULL);
*
* And ".myclass CODE B":
* sel3 = DOM_StyleFindSelector(cx, db, sel2, ".myclass", NULL);
*/
DOM_StyleSelector *
DOM_StyleFindSelector(JSContext *cx, DOM_StyleDatabase *db,
DOM_StyleSelector *base, DOM_StyleToken enclosing,
DOM_StyleToken pseudo);
/*
* As above, but take type explicitly rather than parsing leading # or . for
* ID or class. For classes or extra is a tag or NULL. For tags, extra is an
* ID or NULL. (For ID, extra is ignored.)
*/
DOM_StyleSelector *
DOM_StyleFindSelectorFull(JSContext *cx, DOM_StyleDatabase *db,
DOM_StyleSelector *base, uint8 type,
DOM_StyleToken enclosing, DOM_StyleToken extra,
DOM_StyleToken pseudo);
struct DOM_StyleRule {
DOM_AttributeEntry entry;
int16 weight;
DOM_StyleRule *next;
};
/*
* Parses a style rule and adds it to the style database.
* If len is 0, rule is presumed to be NUL-terminated. (XXX NYI)
*
* Usage example:
*
* DOM_StyleParseRule(JSContext *cx, DOM_StyleDatabase *db,
* "A:visited { color: blue }", 0, DOM_STYLE_WEIGHT_AUTHOR);
*/
#define DOM_STYLE_WEIGHT_NONE 0
#define DOM_STYLE_WEIGHT_UA 2
#define DOM_STYLE_WEIGHT_USER 4
#define DOM_STYLE_WEIGHT_AUTHOR 6
JSBool
DOM_StyleParseRule(JSContext *cx, DOM_StyleDatabase *db, const char *rule,
uintN len, intN baseWeight);
/*
* Get a style property for a node.
* The node must be an Element or Text node. If it's a text node, the
* enclosing Element is used for finding matches. The implementation is
* necessarily somewhat hairy. See domstyle.c for details.
*
* If db is NULL, DOM_StyleDatabaseFromContext is used to find it.
*
* Usage examples:
*
* Get the color for a section of text:
* DOM_StyleGetProperty(cx, db, (DOM_Node *)text, "color", &entry);
*
* Find the display property of a list item:
* DOM_StyleGetProperty(cx, db, (DOM_Node *)listItem, "display", &entry);
*/
JSBool
DOM_StyleGetProperty(JSContext *cx, DOM_StyleDatabase *db, DOM_Node *node,
DOM_StyleToken property, DOM_AttributeEntry **entryp);
/*
* Get/set the pseudoclass for an element
*/
DOM_StyleToken
DOM_GetElementPseudo(JSContext *cx, DOM_Element *element);
JSBool
DOM_SetElementPseudo(JSContext *cx, DOM_Element *element,
DOM_StyleToken pseudo);
/*
* Add a property to the provided selector.
*
* DOM_StyleAddRule(cx, db, sel, "color", "blue");
*/
DOM_AttributeEntry *
DOM_StyleAddRule(JSContext *cx, DOM_StyleDatabase *db, DOM_StyleSelector *sel,
DOM_StyleToken name, const char *value);
/*
* Resolve classes, tags, ids, contextual on the given object.
*/
JSBool
DOM_DocObjectResolveStyleProps(JSContext *cx, JSObject *obj, jsval id);
/*
* The contextual selector JS function: contextual("H1", "EM");
*/
JSBool
DOM_JSContextual(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval);
#endif /* DOM_STYLE_H */