moved to pub
This commit is contained in:
24
base/Makefile
Normal file
24
base/Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
#!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 = ..
|
||||
|
||||
DIRS = src tests
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
23
base/makefile.win
Normal file
23
base/makefile.win
Normal file
@@ -0,0 +1,23 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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=..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DIRS=src tests
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
62
base/src/Makefile
Normal file
62
base/src/Makefile
Normal file
@@ -0,0 +1,62 @@
|
||||
#!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=../../..
|
||||
|
||||
DEFINES =-D_IMPL_NS_BASE
|
||||
|
||||
LIBRARY_NAME = raptorbase
|
||||
|
||||
CPPSRCS = \
|
||||
nsArena.cpp \
|
||||
nsAtomTable.cpp \
|
||||
nsByteBuffer.cpp \
|
||||
nsCRT.cpp \
|
||||
nsInputStream.cpp \
|
||||
nsString.cpp \
|
||||
nsUnicharBuffer.cpp \
|
||||
nsUnicharInputStream.cpp \
|
||||
nsURL.cpp \
|
||||
nsVoidArray.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nscore.h \
|
||||
nsCRT.h \
|
||||
nsIArena.h \
|
||||
nsIAtom.h \
|
||||
nsIByteBuffer.h \
|
||||
nsIInputStream.h \
|
||||
nsITimer.h \
|
||||
nsITimerCallback.h \
|
||||
nsIUnicharBuffer.h \
|
||||
nsIUnicharInputStream.h \
|
||||
nsIURL.h \
|
||||
nsString.h \
|
||||
nsVoidArray.h \
|
||||
nsUnitConversion.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = raptor
|
||||
|
||||
REQUIRES = xpcom netlib raptor
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
TARGET = $(LIBARY)
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
74
base/src/makefile.win
Normal file
74
base/src/makefile.win
Normal file
@@ -0,0 +1,74 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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=..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DIRS = windows
|
||||
|
||||
DEFINES=-D_IMPL_NS_BASE
|
||||
LIBRARY_NAME=raptorbase
|
||||
|
||||
CPPSRCS=nsArena.cpp nsAtomTable.cpp nsByteBuffer.cpp nsCRT.cpp \
|
||||
nsInputStream.cpp nsString.cpp nsUnicharBuffer.cpp \
|
||||
nsUnicharInputStream.cpp nsURL.cpp nsVoidArray.cpp
|
||||
|
||||
CPP_OBJS=.\$(OBJDIR)\nsArena.obj .\$(OBJDIR)\nsAtomTable.obj \
|
||||
.\$(OBJDIR)\nsByteBuffer.obj .\$(OBJDIR)\nsCRT.obj \
|
||||
.\$(OBJDIR)\nsInputStream.obj .\$(OBJDIR)\nsString.obj \
|
||||
.\$(OBJDIR)\nsUnicharBuffer.obj .\$(OBJDIR)\nsUnicharInputStream.obj \
|
||||
.\$(OBJDIR)\nsURL.obj .\$(OBJDIR)\nsVoidArray.obj
|
||||
|
||||
EXPORTS=nscore.h nsCRT.h nsIArena.h nsIAtom.h nsIByteBuffer.h \
|
||||
nsIInputStream.h nsITimer.h nsITimerCallback.h nsIUnicharBuffer.h \
|
||||
nsIUnicharInputStream.h nsIURL.h nsString.h nsVoidArray.h \
|
||||
nsUnitConversion.h
|
||||
|
||||
MODULE=raptor
|
||||
|
||||
REQUIRES=xpcom netlib raptor
|
||||
|
||||
LINCS=-I$(XPDIST)\public\xpcom -I$(XPDIST)\public\netlib \
|
||||
-I$(XPDIST)\public\raptor
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
DLLNAME = raptorbase
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
OBJS = $(OBJS) .\$(OBJDIR)\nsTimer.obj
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
# These are the libraries we need to link with to create the dll
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\libplc21.lib \
|
||||
$(DIST)\lib\netlib.lib \
|
||||
$(LIBNSPR)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
libs:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\$(DLLNAME).dll
|
||||
rm -f $(DIST)\lib\$(DLLNAME).lib
|
||||
80
base/src/nsArena.cpp
Normal file
80
base/src/nsArena.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsIArena.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#define PL_ARENA_CONST_ALIGN_MASK 7
|
||||
#include "plarena.h"
|
||||
|
||||
static NS_DEFINE_IID(kArenaIID, NS_IARENA_IID);
|
||||
|
||||
// Simple arena implementation layered on plarena
|
||||
class ArenaImpl : public nsIArena {
|
||||
public:
|
||||
ArenaImpl(PRInt32 aBlockSize);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual void* Alloc(PRInt32 aSize);
|
||||
|
||||
protected:
|
||||
~ArenaImpl();
|
||||
|
||||
PLArenaPool mPool;
|
||||
PRInt32 mBlockSize;
|
||||
};
|
||||
|
||||
ArenaImpl::ArenaImpl(PRInt32 aBlockSize)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
if (aBlockSize < NS_MIN_ARENA_BLOCK_SIZE) {
|
||||
aBlockSize = NS_DEFAULT_ARENA_BLOCK_SIZE;
|
||||
}
|
||||
PL_INIT_ARENA_POOL(&mPool, "nsIArena", aBlockSize);
|
||||
mBlockSize = aBlockSize;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ArenaImpl,kArenaIID)
|
||||
|
||||
ArenaImpl::~ArenaImpl()
|
||||
{
|
||||
PL_FinishArenaPool(&mPool);
|
||||
}
|
||||
|
||||
void* ArenaImpl::Alloc(PRInt32 size)
|
||||
{
|
||||
// Adjust size so that it's a multiple of sizeof(double)
|
||||
PRInt32 align = size & (sizeof(double) - 1);
|
||||
if (0 != align) {
|
||||
size += sizeof(double) - align;
|
||||
}
|
||||
|
||||
void* p;
|
||||
PL_ARENA_ALLOCATE(p, &mPool, size);
|
||||
return p;
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_NewHeapArena(nsIArena** aInstancePtrResult,
|
||||
PRInt32 aArenaBlockSize)
|
||||
{
|
||||
ArenaImpl* it = new ArenaImpl(aArenaBlockSize);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kArenaIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
144
base/src/nsAtomTable.cpp
Normal file
144
base/src/nsAtomTable.cpp
Normal file
@@ -0,0 +1,144 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsIAtom.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
#include "plhash.h"
|
||||
|
||||
/**
|
||||
* The shared hash table for atom lookups.
|
||||
*/
|
||||
static nsrefcnt gAtoms;
|
||||
static struct PLHashTable* gAtomHashTable;
|
||||
|
||||
class AtomImpl : public nsIAtom {
|
||||
public:
|
||||
AtomImpl();
|
||||
~AtomImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
void* operator new(size_t size, const PRUnichar* us, PRInt32 uslen);
|
||||
|
||||
virtual void ToString(nsString& aBuf) const;
|
||||
|
||||
virtual const PRUnichar* GetUnicode() const;
|
||||
|
||||
// Actually more; 0 terminated. This slot is reserved for the
|
||||
// terminating zero.
|
||||
PRUnichar mString[1];
|
||||
};
|
||||
|
||||
AtomImpl::AtomImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
// Every live atom holds a reference on the atom hashtable
|
||||
gAtoms++;
|
||||
}
|
||||
|
||||
AtomImpl::~AtomImpl()
|
||||
{
|
||||
NS_PRECONDITION(nsnull != gAtomHashTable, "null atom hashtable");
|
||||
if (nsnull != gAtomHashTable) {
|
||||
PL_HashTableRemove(gAtomHashTable, mString);
|
||||
nsrefcnt cnt = --gAtoms;
|
||||
if (0 == cnt) {
|
||||
// When the last atom is destroyed, the atom arena is destroyed
|
||||
NS_ASSERTION(0 == gAtomHashTable->nentries, "bad atom table");
|
||||
PL_HashTableDestroy(gAtomHashTable);
|
||||
gAtomHashTable = nsnull;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kIAtomIID, NS_IATOM_IID);
|
||||
NS_IMPL_ISUPPORTS(AtomImpl, kIAtomIID);
|
||||
|
||||
void* AtomImpl::operator new(size_t size, const PRUnichar* us, PRInt32 uslen)
|
||||
{
|
||||
size = size + uslen * sizeof(PRUnichar);
|
||||
AtomImpl* ii = (AtomImpl*) new char[size];
|
||||
nsCRT::memcpy(ii->mString, us, uslen * sizeof(PRUnichar));
|
||||
ii->mString[uslen] = 0;
|
||||
return ii;
|
||||
}
|
||||
|
||||
void AtomImpl::ToString(nsString& aBuf) const
|
||||
{
|
||||
aBuf.SetLength(0);
|
||||
aBuf.Append(mString, nsCRT::strlen(mString));
|
||||
}
|
||||
|
||||
const PRUnichar* AtomImpl::GetUnicode() const
|
||||
{
|
||||
return mString;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static PLHashNumber HashKey(const PRUnichar* k)
|
||||
{
|
||||
return (PLHashNumber) nsCRT::HashCode(k);
|
||||
}
|
||||
|
||||
static PRIntn CompareKeys(const PRUnichar* k1, const PRUnichar* k2)
|
||||
{
|
||||
return nsCRT::strcmp(k1, k2) == 0;
|
||||
}
|
||||
|
||||
NS_BASE nsIAtom* NS_NewAtom(const char* isolatin1)
|
||||
{
|
||||
nsAutoString tmp(isolatin1);
|
||||
return NS_NewAtom(tmp.GetUnicode());
|
||||
}
|
||||
|
||||
NS_BASE nsIAtom* NS_NewAtom(const nsString& aString)
|
||||
{
|
||||
return NS_NewAtom(aString.GetUnicode());
|
||||
}
|
||||
|
||||
NS_BASE nsIAtom* NS_NewAtom(const PRUnichar* us)
|
||||
{
|
||||
if (nsnull == gAtomHashTable) {
|
||||
gAtomHashTable = PL_NewHashTable(8, (PLHashFunction) HashKey,
|
||||
(PLHashComparator) CompareKeys,
|
||||
(PLHashComparator) nsnull,
|
||||
nsnull, nsnull);
|
||||
}
|
||||
PRInt32 uslen;
|
||||
PRInt32 hashCode = nsCRT::HashCode(us, &uslen);
|
||||
PLHashEntry** hep = PL_HashTableRawLookup(gAtomHashTable, hashCode, us);
|
||||
PLHashEntry* he = *hep;
|
||||
if (nsnull != he) {
|
||||
nsIAtom* id = (nsIAtom*) he->value;
|
||||
NS_ADDREF(id);
|
||||
return id;
|
||||
}
|
||||
AtomImpl* id = new(us, uslen) AtomImpl();
|
||||
PL_HashTableRawAdd(gAtomHashTable, hep, hashCode, id->mString, id);
|
||||
NS_ADDREF(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
NS_BASE nsrefcnt NS_GetNumberOfAtoms(void)
|
||||
{
|
||||
if (nsnull != gAtomHashTable) {
|
||||
NS_PRECONDITION(nsrefcnt(gAtomHashTable->nentries) == gAtoms, "bad atom table");
|
||||
}
|
||||
return gAtoms;
|
||||
}
|
||||
135
base/src/nsByteBuffer.cpp
Normal file
135
base/src/nsByteBuffer.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsIByteBuffer.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#define MIN_BUFFER_SIZE 32
|
||||
|
||||
class ByteBufferImpl : public nsIByteBuffer {
|
||||
public:
|
||||
ByteBufferImpl(PRInt32 aBufferSize);
|
||||
~ByteBufferImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
virtual PRInt32 GetLength() const;
|
||||
virtual PRInt32 GetBufferSize() const;
|
||||
virtual char* GetBuffer() const;
|
||||
virtual PRBool Grow(PRInt32 aNewSize);
|
||||
virtual PRInt32 Fill(PRInt32* aErrorCode, nsIInputStream* aStream,
|
||||
PRInt32 aKeep);
|
||||
|
||||
char* mBuffer;
|
||||
PRInt32 mSpace;
|
||||
PRInt32 mLength;
|
||||
};
|
||||
|
||||
ByteBufferImpl::ByteBufferImpl(PRInt32 aBufferSize)
|
||||
{
|
||||
if (PRUint32(aBufferSize) < MIN_BUFFER_SIZE) {
|
||||
aBufferSize = MIN_BUFFER_SIZE;
|
||||
}
|
||||
mSpace = aBufferSize;
|
||||
mBuffer = new char[aBufferSize];
|
||||
mLength = 0;
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
NS_DEFINE_IID(kByteBufferIID,NS_IBYTE_BUFFER_IID);
|
||||
NS_IMPL_ISUPPORTS(ByteBufferImpl,kByteBufferIID)
|
||||
|
||||
ByteBufferImpl::~ByteBufferImpl()
|
||||
{
|
||||
if (nsnull != mBuffer) {
|
||||
delete mBuffer;
|
||||
mBuffer = nsnull;
|
||||
}
|
||||
mLength = 0;
|
||||
}
|
||||
|
||||
PRInt32 ByteBufferImpl::GetLength() const
|
||||
{
|
||||
return mLength;
|
||||
}
|
||||
|
||||
PRInt32 ByteBufferImpl::GetBufferSize() const
|
||||
{
|
||||
return mSpace;
|
||||
}
|
||||
|
||||
char* ByteBufferImpl::GetBuffer() const
|
||||
{
|
||||
return mBuffer;
|
||||
}
|
||||
|
||||
PRBool ByteBufferImpl::Grow(PRInt32 aNewSize)
|
||||
{
|
||||
if (PRUint32(aNewSize) < MIN_BUFFER_SIZE) {
|
||||
aNewSize = MIN_BUFFER_SIZE;
|
||||
}
|
||||
char* newbuf = new char[aNewSize];
|
||||
if (nsnull != newbuf) {
|
||||
if (0 != mLength) {
|
||||
nsCRT::memcpy(newbuf, mBuffer, mLength);
|
||||
}
|
||||
delete mBuffer;
|
||||
mBuffer = newbuf;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRInt32 ByteBufferImpl::Fill(PRInt32* aErrorCode, nsIInputStream* aStream,
|
||||
PRInt32 aKeep)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aStream, "null stream");
|
||||
NS_PRECONDITION(PRUint32(aKeep) <= PRUint32(mLength), "illegal keep count");
|
||||
if ((nsnull == aStream) || (PRUint32(aKeep) > PRUint32(mLength))) {
|
||||
// whoops
|
||||
*aErrorCode = NS_INPUTSTREAM_ILLEGAL_ARGS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != aKeep) {
|
||||
// Slide over kept data
|
||||
nsCRT::memmove(mBuffer, mBuffer + (mLength - aKeep), aKeep);
|
||||
}
|
||||
|
||||
// Read in some new data
|
||||
mLength = aKeep;
|
||||
PRInt32 amount = mSpace - aKeep;
|
||||
PRInt32 nb = aStream->Read(aErrorCode, mBuffer, aKeep, amount);
|
||||
if (nb > 0) {
|
||||
mLength += nb;
|
||||
}
|
||||
return nb;
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_NewByteBuffer(nsIByteBuffer** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
PRInt32 aBufferSize)
|
||||
{
|
||||
if (nsnull != aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
ByteBufferImpl* it = new ByteBufferImpl(aBufferSize);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kByteBufferIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
290
base/src/nsCRT.cpp
Normal file
290
base/src/nsCRT.cpp
Normal file
@@ -0,0 +1,290 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsCRT.h"
|
||||
|
||||
// XXX Bug: These tables don't lowercase the upper 128 characters properly
|
||||
|
||||
// This table maps uppercase characters to lower case characters;
|
||||
// characters that are neither upper nor lower case are unaffected.
|
||||
static const unsigned char kUpper2Lower[256] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
||||
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
||||
64,
|
||||
|
||||
// upper band mapped to lower [A-Z] => [a-z]
|
||||
97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
|
||||
112,113,114,115,116,117,118,119,120,121,122,
|
||||
|
||||
91, 92, 93, 94, 95,
|
||||
96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
|
||||
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
|
||||
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
|
||||
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
|
||||
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
|
||||
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
|
||||
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
|
||||
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
|
||||
224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
|
||||
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
|
||||
};
|
||||
|
||||
static const unsigned char kLower2Upper[256] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
||||
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
||||
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
|
||||
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
|
||||
96,
|
||||
|
||||
// lower band mapped to upper [a-z] => [A-Z]
|
||||
65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
|
||||
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
|
||||
|
||||
123,124,125,126,127,
|
||||
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
|
||||
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
|
||||
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
|
||||
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
|
||||
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
|
||||
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
|
||||
224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
|
||||
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
|
||||
};
|
||||
|
||||
static const PRUnichar kIsoLatin1ToUCS2[256] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
||||
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
||||
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
|
||||
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
|
||||
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
|
||||
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
|
||||
96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
|
||||
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
|
||||
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
|
||||
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
|
||||
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
|
||||
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
|
||||
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
|
||||
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
|
||||
224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
|
||||
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
#define TOLOWER(_ucs2) \
|
||||
(((_ucs2) < 256) ? PRUnichar(kUpper2Lower[_ucs2]) : _ToLower(_ucs2))
|
||||
|
||||
#define TOUPPER(_ucs2) \
|
||||
(((_ucs2) < 256) ? PRUnichar(kLower2Upper[_ucs2]) : _ToUpper(_ucs2))
|
||||
|
||||
static PRUnichar _ToLower(PRUnichar aChar)
|
||||
{
|
||||
// XXX need i18n code here
|
||||
return aChar;
|
||||
}
|
||||
|
||||
static PRUnichar _ToUpper(PRUnichar aChar)
|
||||
{
|
||||
// XXX need i18n code here
|
||||
return aChar;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
PRUnichar nsCRT::ToUpper(PRUnichar aChar)
|
||||
{
|
||||
return TOUPPER(aChar);
|
||||
}
|
||||
|
||||
PRUnichar nsCRT::ToLower(PRUnichar aChar)
|
||||
{
|
||||
return TOLOWER(aChar);
|
||||
}
|
||||
|
||||
PRInt32 nsCRT::strlen(const PRUnichar* s)
|
||||
{
|
||||
PRInt32 len = 0;
|
||||
while (*s++ != 0) {
|
||||
len++;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
PRInt32 nsCRT::strcmp(const PRUnichar* s1, const PRUnichar* s2)
|
||||
{
|
||||
for (;;) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = *s2++;
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
if (c1 == 0) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// characters following a null character are not compared
|
||||
PRInt32 nsCRT::strncmp(const PRUnichar* s1, const PRUnichar* s2, PRInt32 n)
|
||||
{
|
||||
while (--n >= 0) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = *s2++;
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
if (c1 == 0) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const PRUnichar* s2)
|
||||
{
|
||||
for (;;) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = *s2++;
|
||||
if (c1 != c2) {
|
||||
c1 = TOLOWER(c1);
|
||||
c2 = TOLOWER(c2);
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (c1 == 0) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const PRUnichar* s2, PRInt32 n)
|
||||
{
|
||||
while (--n >= 0) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = *s2++;
|
||||
if (c1 != c2) {
|
||||
c1 = TOLOWER(c1);
|
||||
c2 = TOLOWER(c2);
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (c1 == 0) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 nsCRT::strcmp(const PRUnichar* s1, const char* s2)
|
||||
{
|
||||
for (;;) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
if (c1 == 0) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 nsCRT::strncmp(const PRUnichar* s1, const char* s2, PRInt32 n)
|
||||
{
|
||||
while (--n >= 0) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
if (c1 == 0) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 nsCRT::strcasecmp(const PRUnichar* s1, const char* s2)
|
||||
{
|
||||
for (;;) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
|
||||
if (c1 != c2) {
|
||||
c1 = TOLOWER(c1);
|
||||
c2 = TOLOWER(c2);
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (c1 == 0) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 nsCRT::strncasecmp(const PRUnichar* s1, const char* s2, PRInt32 n)
|
||||
{
|
||||
while (--n >= 0) {
|
||||
PRUnichar c1 = *s1++;
|
||||
PRUnichar c2 = kIsoLatin1ToUCS2[*(const unsigned char*)s2++];
|
||||
if (c1 != c2) {
|
||||
c1 = TOLOWER(c1);
|
||||
c2 = TOLOWER(c2);
|
||||
if (c1 != c2) {
|
||||
if (c1 < c2) return -1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (c1 == 0) break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 nsCRT::HashCode(const PRUnichar* us)
|
||||
{
|
||||
PRInt32 rv = 0;
|
||||
PRUnichar ch;
|
||||
while ((ch = *us++) != 0) {
|
||||
// FYI: rv = rv*37 + ch
|
||||
rv = ((rv << 5) + (rv << 2) + rv) + ch;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
PRInt32 nsCRT::HashCode(const PRUnichar* us, PRInt32* uslenp)
|
||||
{
|
||||
PRInt32 rv = 0;
|
||||
PRInt32 len = 0;
|
||||
PRUnichar ch;
|
||||
while ((ch = *us++) != 0) {
|
||||
// FYI: rv = rv*37 + ch
|
||||
rv = ((rv << 5) + (rv << 2) + rv) + ch;
|
||||
len++;
|
||||
}
|
||||
*uslenp = len;
|
||||
return rv;
|
||||
}
|
||||
|
||||
PRInt32 nsCRT::atoi( const PRUnichar *string )
|
||||
{
|
||||
return atoi(string);
|
||||
}
|
||||
|
||||
110
base/src/nsCRT.h
Normal file
110
base/src/nsCRT.h
Normal file
@@ -0,0 +1,110 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsCRT_h___
|
||||
#define nsCRT_h___
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "plstr.h"
|
||||
#include "nscore.h"
|
||||
|
||||
/// This is a wrapper class around all the C runtime functions.
|
||||
|
||||
class NS_BASE nsCRT {
|
||||
public:
|
||||
/** Copy bytes from aSrc to aDest.
|
||||
@param aDest the destination address
|
||||
@param aSrc the source address
|
||||
@param aCount the number of bytes to copy
|
||||
*/
|
||||
static void memcpy(void* aDest, const void* aSrc, PRInt32 aCount) {
|
||||
::memcpy(aDest, aSrc, (size_t)aCount);
|
||||
}
|
||||
|
||||
static void memmove(void* aDest, const void* aSrc, PRInt32 aCount) {
|
||||
::memmove(aDest, aSrc, (size_t)aCount);
|
||||
}
|
||||
|
||||
static void memset(void* aDest, PRUint8 aByte, PRInt32 aCount) {
|
||||
::memset(aDest, aByte, aCount);
|
||||
}
|
||||
|
||||
static void zero(void* aDest, PRInt32 aCount) {
|
||||
::memset(aDest, 0, (size_t)aCount);
|
||||
}
|
||||
|
||||
/** Compute the string length of s
|
||||
@param s the string in question
|
||||
@return the length of s
|
||||
*/
|
||||
static PRInt32 strlen(const char* s) {
|
||||
return PRInt32(::strlen(s));
|
||||
}
|
||||
|
||||
/// Compare s1 and s2.
|
||||
static PRInt32 strcmp(const char* s1, const char* s2) {
|
||||
return PRInt32(PL_strcmp(s1, s2));
|
||||
}
|
||||
|
||||
/// Case-insensitive string comparison.
|
||||
static PRInt32 strcasecmp(const char* s1, const char* s2) {
|
||||
return PRInt32(PL_strcasecmp(s1, s2));
|
||||
}
|
||||
|
||||
/// Like strlen except for ucs2 strings
|
||||
static PRInt32 strlen(const PRUnichar* s);
|
||||
|
||||
/// Like strcmp except for ucs2 strings
|
||||
static PRInt32 strcmp(const PRUnichar* s1, const PRUnichar* s2);
|
||||
/// Like strcmp except for ucs2 strings
|
||||
static PRInt32 strncmp(const PRUnichar* s1, const PRUnichar* s2,
|
||||
PRInt32 aMaxLen);
|
||||
|
||||
/// Like strcasecmp except for ucs2 strings
|
||||
static PRInt32 strcasecmp(const PRUnichar* s1, const PRUnichar* s2);
|
||||
/// Like strncasecmp except for ucs2 strings
|
||||
static PRInt32 strncasecmp(const PRUnichar* s1, const PRUnichar* s2,
|
||||
PRInt32 aMaxLen);
|
||||
|
||||
/// Like strcmp with a char* and a ucs2 string
|
||||
static PRInt32 strcmp(const PRUnichar* s1, const char* s2);
|
||||
/// Like strncmp with a char* and a ucs2 string
|
||||
static PRInt32 strncmp(const PRUnichar* s1, const char* s2,
|
||||
PRInt32 aMaxLen);
|
||||
|
||||
/// Like strcasecmp with a char* and a ucs2 string
|
||||
static PRInt32 strcasecmp(const PRUnichar* s1, const char* s2);
|
||||
/// Like strncasecmp with a char* and a ucs2 string
|
||||
static PRInt32 strncasecmp(const PRUnichar* s1, const char* s2,
|
||||
PRInt32 aMaxLen);
|
||||
|
||||
/// Compute a hashcode for a ucs2 string
|
||||
static PRInt32 HashCode(const PRUnichar* s1);
|
||||
|
||||
/// Same as above except that we return the length in s1len
|
||||
static PRInt32 HashCode(const PRUnichar* s1, PRInt32* s1len);
|
||||
|
||||
/// String to integer.
|
||||
static PRInt32 atoi( const PRUnichar *string );
|
||||
|
||||
static PRUnichar ToUpper(PRUnichar aChar);
|
||||
|
||||
static PRUnichar ToLower(PRUnichar aChar);
|
||||
};
|
||||
|
||||
#endif /* nsCRT_h___ */
|
||||
51
base/src/nsIArena.h
Normal file
51
base/src/nsIArena.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIArena_h___
|
||||
#define nsIArena_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
#define NS_MIN_ARENA_BLOCK_SIZE 64
|
||||
#define NS_DEFAULT_ARENA_BLOCK_SIZE 4096
|
||||
|
||||
/// Interface IID for nsIArena
|
||||
#define NS_IARENA_IID \
|
||||
{ 0xa24fdad0, 0x93b4, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/** Interface to a memory arena abstraction. Arena's use large blocks
|
||||
* of memory to allocate smaller objects. Arena's provide no free
|
||||
* operator; instead, all of the objects in the arena are deallocated
|
||||
* by deallocating the arena (e.g. when it's reference count goes to
|
||||
* zero)
|
||||
*/
|
||||
class nsIArena : public nsISupports {
|
||||
public:
|
||||
virtual void* Alloc(PRInt32 size) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new arena using the desired block size for allocating the
|
||||
* underlying memory blocks. The underlying memory blocks are allocated
|
||||
* using the PR heap.
|
||||
*/
|
||||
extern NS_BASE nsresult NS_NewHeapArena(nsIArena** aInstancePtrResult,
|
||||
PRInt32 aArenaBlockSize = 0);
|
||||
|
||||
#endif /* nsIArena_h___ */
|
||||
71
base/src/nsIAtom.h
Normal file
71
base/src/nsIAtom.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIAtom_h___
|
||||
#define nsIAtom_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
class nsString;
|
||||
|
||||
#define NS_IATOM_IID \
|
||||
{ 0x3d1b15b0, 0x93b4, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/**
|
||||
* A globally unique identfier. nsIAtom's can be compared for
|
||||
* equality by using operator '=='. These objects are reference
|
||||
* counted like other nsISupports objects. When you are done with
|
||||
* the atom, NS_RELEASE it.
|
||||
*/
|
||||
class nsIAtom : public nsISupports {
|
||||
public:
|
||||
/**
|
||||
* Translate the unicode string into the stringbuf.
|
||||
*/
|
||||
virtual void ToString(nsString& aString) const = 0;
|
||||
|
||||
/**
|
||||
* Return a pointer to a zero terminated unicode string.
|
||||
*/
|
||||
virtual const PRUnichar* GetUnicode() const = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Find an atom that matches the given iso-latin1 C string. The
|
||||
* C string is translated into it's unicode equivalent.
|
||||
*/
|
||||
extern NS_BASE nsIAtom* NS_NewAtom(const char* isolatin1);
|
||||
|
||||
/**
|
||||
* Find an atom that matches the given unicode string. The string is assumed
|
||||
* to be zero terminated.
|
||||
*/
|
||||
extern NS_BASE nsIAtom* NS_NewAtom(const PRUnichar* unicode);
|
||||
|
||||
/**
|
||||
* Find an atom that matches the given string.
|
||||
*/
|
||||
extern NS_BASE nsIAtom* NS_NewAtom(const nsString& aString);
|
||||
|
||||
/**
|
||||
* Return a count of the total number of atoms currently
|
||||
* alive in the system.
|
||||
*/
|
||||
extern NS_BASE nsrefcnt NS_GetNumberOfAtoms(void);
|
||||
|
||||
#endif /* nsIAtom_h___ */
|
||||
56
base/src/nsIByteBuffer.h
Normal file
56
base/src/nsIByteBuffer.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIByteBuffer_h___
|
||||
#define nsIByteBuffer_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIInputStream;
|
||||
|
||||
#define NS_IBYTE_BUFFER_IID \
|
||||
{ 0xe4a6e4b0, 0x93b4, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/** Interface to a buffer that holds bytes */
|
||||
class nsIByteBuffer : public nsISupports {
|
||||
public:
|
||||
/** @return length of buffer, i.e. how many bytes are currently in it. */
|
||||
virtual PRInt32 GetLength() const = 0;
|
||||
|
||||
/** @return number of bytes allocated in the buffer */
|
||||
virtual PRInt32 GetBufferSize() const = 0;
|
||||
|
||||
/** @return the buffer */
|
||||
virtual char* GetBuffer() const = 0;
|
||||
|
||||
/** Grow buffer to aNewSize bytes. */
|
||||
virtual PRBool Grow(PRInt32 aNewSize) = 0;
|
||||
|
||||
/** Fill the buffer with data from aStream. Don't grow the buffer, only
|
||||
* read until length of buffer equals buffer size. */
|
||||
virtual PRInt32 Fill(PRInt32* aErrorCode, nsIInputStream* aStream,
|
||||
PRInt32 aKeep) = 0;
|
||||
};
|
||||
|
||||
/** Create a new byte buffer using the given buffer size. */
|
||||
extern NS_BASE nsresult NS_NewByteBuffer(nsIByteBuffer** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
PRInt32 aBufferSize = 0);
|
||||
|
||||
#endif /* nsIByteBuffer_h___ */
|
||||
74
base/src/nsIInputStream.h
Normal file
74
base/src/nsIInputStream.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIInputStream_h___
|
||||
#define nsIInputStream_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
#define NS_IINPUTSTREAM_IID \
|
||||
{ 0x022396f0, 0x93b5, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/** Abstract byte input stream */
|
||||
class nsIInputStream : public nsISupports {
|
||||
public:
|
||||
/** Read data from the stream.
|
||||
* @param aErrorCode the error code if an error occurs
|
||||
* @param aBuf the buffer into which the data is read
|
||||
* @param aOffset the start offset of the data
|
||||
* @param aCount the maximum number of bytes to read
|
||||
* @return number of bytes read or -1 if error
|
||||
*/
|
||||
virtual PRInt32 Read(PRInt32* aErrorCode,
|
||||
char* aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount) = 0;
|
||||
|
||||
/** Close the stream. */
|
||||
virtual void Close() = 0;
|
||||
};
|
||||
|
||||
/** Error codes */
|
||||
//@{
|
||||
// XXX fix up the values to work with nsqresult
|
||||
/// End of file
|
||||
#define NS_INPUTSTREAM_EOF 1
|
||||
/// Stream closed
|
||||
#define NS_INPUTSTREAM_CLOSED 2
|
||||
/// Error from the operating system
|
||||
#define NS_INPUTSTREAM_OSERROR 3
|
||||
/// Illegal arguments
|
||||
#define NS_INPUTSTREAM_ILLEGAL_ARGS 4
|
||||
/// For unichar streams
|
||||
#define NS_INPUTSTREAM_NO_CONVERTER 5
|
||||
/// For unichar streams
|
||||
#define NS_INPUTSTREAM_BAD_CONVERSION 6
|
||||
//@}
|
||||
|
||||
/** Open a file using a local file name. Return an input stream that
|
||||
can read the file. Use an implementation of nsIByteBuffer to do
|
||||
buffered reading of the stream. */
|
||||
extern NS_BASE nsresult NS_OpenFile(nsIInputStream** aInstancePtrResult,
|
||||
const char* aLocalFileName);
|
||||
|
||||
/** Open a stream from a resource file name. Need two sents? */
|
||||
extern NS_BASE nsresult NS_OpenResource(nsIInputStream** aInstancePtrResult,
|
||||
const char* aResourceFileName);
|
||||
|
||||
#endif /* nsInputStream_h___ */
|
||||
62
base/src/nsITimer.h
Normal file
62
base/src/nsITimer.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsITimer_h___
|
||||
#define nsITimer_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsITimer;
|
||||
class nsITimerCallback;
|
||||
|
||||
/// Signature of timer callback function
|
||||
typedef void
|
||||
(*nsTimerCallbackFunc) (nsITimer *aTimer, void *aClosure);
|
||||
|
||||
/// Interface IID for nsITimer
|
||||
#define NS_ITIMER_IID \
|
||||
{ 0x497eed20, 0xb740, 0x11d1, \
|
||||
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
|
||||
|
||||
/**
|
||||
* Timer class, used to invoke a function or method after a fixed
|
||||
* millisecond interval.
|
||||
*/
|
||||
class nsITimer : public nsISupports {
|
||||
public:
|
||||
virtual nsresult Init(nsTimerCallbackFunc aFunc,
|
||||
void *aClosure,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)=0;
|
||||
|
||||
virtual nsresult Init(nsITimerCallback *aCallback,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)=0;
|
||||
|
||||
/// Cancels the timeout
|
||||
virtual void Cancel()=0;
|
||||
|
||||
virtual PRUint32 GetDelay()=0;
|
||||
|
||||
virtual void SetDelay(PRUint32 aDelay)=0;
|
||||
};
|
||||
|
||||
/** Factory method for creating an nsITimer */
|
||||
extern NS_BASE nsresult NS_NewTimer(nsITimer** aInstancePtrResult);
|
||||
|
||||
#endif
|
||||
41
base/src/nsITimerCallback.h
Normal file
41
base/src/nsITimerCallback.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsITimerCallback_h___
|
||||
#define nsITimerCallback_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsITimer;
|
||||
|
||||
/// Interface IID for nsITimerCallback
|
||||
#define NS_ITIMERCALLBACK_IID \
|
||||
{ 0x5079b3a0, 0xb743, 0x11d1, \
|
||||
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
|
||||
|
||||
/**
|
||||
* Interface implemented by users of the nsITimer class. An instance
|
||||
* of this interface is passed in when creating a timer. The Notify()
|
||||
* method of that instance is invoked after the specified delay.
|
||||
*/
|
||||
class nsITimerCallback : public nsISupports {
|
||||
public:
|
||||
virtual void Notify(nsITimer *timer)=0;
|
||||
};
|
||||
|
||||
#endif
|
||||
90
base/src/nsIURL.h
Normal file
90
base/src/nsIURL.h
Normal file
@@ -0,0 +1,90 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIURL_h___
|
||||
#define nsIURL_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
class nsIInputStream;
|
||||
class nsString;
|
||||
|
||||
#define NS_IURL_IID \
|
||||
{ 0x6ecb2900, 0x93b5, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/**
|
||||
* TEMPORARY INTERFACE; this <B><EM><STRONG>will</STRONG></EM></B> will be
|
||||
* going away
|
||||
*/
|
||||
class nsIURL : public nsISupports {
|
||||
public:
|
||||
/** Open the url for reading and return a new input stream for the
|
||||
* url. The caller must release the input stream when done with it.
|
||||
*/
|
||||
virtual nsIInputStream* Open(PRInt32* aErrorCode) const = 0;
|
||||
|
||||
/** Equality operator */
|
||||
virtual PRBool operator==(const nsIURL& aURL) const = 0;
|
||||
|
||||
|
||||
/** Accessors */
|
||||
//@{
|
||||
/**
|
||||
@return protocol part of the URL */
|
||||
virtual const char* GetProtocol() const = 0;
|
||||
|
||||
/** @return host part of the URL */
|
||||
virtual const char* GetHost() const = 0;
|
||||
|
||||
/** @return file part of the URL */
|
||||
virtual const char* GetFile() const = 0;
|
||||
|
||||
/** @return ref part of the URL */
|
||||
virtual const char* GetRef() const = 0;
|
||||
|
||||
/** @return string originally used to construct the URL */
|
||||
virtual const char* GetSpec() const = 0;
|
||||
|
||||
/** @return ref part of the URL */
|
||||
virtual PRInt32 GetPort() const = 0;
|
||||
//@}
|
||||
|
||||
/** Write the URL to aString, overwriting previous contents. */
|
||||
virtual void ToString(nsString& aString) const = 0;
|
||||
};
|
||||
|
||||
/** Create a new URL from aSpec. */
|
||||
extern NS_BASE nsresult NS_NewURL(nsIURL** aInstancePtrResult,
|
||||
const nsString& aSpec);
|
||||
|
||||
/** Create a new URL, interpreting aSpec as relative to aURL. */
|
||||
extern NS_BASE nsresult NS_NewURL(nsIURL** aInstancePtrResult,
|
||||
const nsIURL* aURL,
|
||||
const nsString& aSpec);
|
||||
|
||||
/**
|
||||
* Utility routine to take a url (may be nsnull) and a base url (may
|
||||
* be empty), and a url spec and combine them properly into a new
|
||||
* absolute url.
|
||||
*/
|
||||
extern NS_BASE nsresult NS_MakeAbsoluteURL(nsIURL* aURL,
|
||||
const nsString& aBaseURL,
|
||||
const nsString& aSpec,
|
||||
nsString& aResult);
|
||||
|
||||
#endif /* nsIURL_h___ */
|
||||
46
base/src/nsIUnicharBuffer.h
Normal file
46
base/src/nsIUnicharBuffer.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIUnicharBuffer_h___
|
||||
#define nsIUnicharBuffer_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
class nsIUnicharInputStream;
|
||||
|
||||
#define NS_IUNICHAR_BUFFER_IID \
|
||||
{ 0x14cf6970, 0x93b5, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/// Interface to a buffer that holds unicode characters
|
||||
class nsIUnicharBuffer : public nsISupports {
|
||||
public:
|
||||
virtual PRInt32 GetLength() const = 0;
|
||||
virtual PRInt32 GetBufferSize() const = 0;
|
||||
virtual PRUnichar* GetBuffer() const = 0;
|
||||
virtual PRBool Grow(PRInt32 aNewSize) = 0;
|
||||
virtual PRInt32 Fill(PRInt32* aErrorCode, nsIUnicharInputStream* aStream,
|
||||
PRInt32 aKeep) = 0;
|
||||
};
|
||||
|
||||
/// Factory method for nsIUnicharBuffer.
|
||||
extern NS_BASE nsresult
|
||||
NS_NewUnicharBuffer(nsIUnicharBuffer** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
PRInt32 aBufferSize = 0);
|
||||
|
||||
#endif /* nsIUnicharBuffer_h___ */
|
||||
98
base/src/nsIUnicharInputStream.h
Normal file
98
base/src/nsIUnicharInputStream.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIUnicharInputStream_h___
|
||||
#define nsIUnicharInputStream_h___
|
||||
|
||||
#include "nsIInputStream.h"
|
||||
class nsString;
|
||||
|
||||
#define NS_IUNICHAR_INPUT_STREAM_IID \
|
||||
{ 0x2d97fbf0, 0x93b5, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
#define NS_IB2UCONVERTER_IID \
|
||||
{ 0x35e40290, 0x93b5, 0x11d1, \
|
||||
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
/// Enumeration of character set ids.
|
||||
enum nsCharSetID {
|
||||
eCharSetID_IsoLatin1 = 0,
|
||||
eCharSetID_UTF8,
|
||||
eCharSetID_ShiftJis,
|
||||
// XXX more i'm sure...
|
||||
};
|
||||
|
||||
/** Abstract unicode character input stream
|
||||
* @see nsIInputStream
|
||||
*/
|
||||
class nsIUnicharInputStream : public nsISupports {
|
||||
public:
|
||||
virtual PRInt32 Read(PRInt32* aErrorCode,
|
||||
PRUnichar* aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount) = 0;
|
||||
virtual void Close() = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a nsIUnicharInputStream that wraps up a string. Data is fed
|
||||
* from the string out until the done. When this object is destroyed
|
||||
* it destroyes the string (so make a copy if you don't want it doing
|
||||
* that)
|
||||
*/
|
||||
extern NS_BASE nsresult
|
||||
NS_NewStringUnicharInputStream(nsIUnicharInputStream** aInstancePtrResult,
|
||||
nsString* aString);
|
||||
|
||||
/// Abstract interface for converting from bytes to unicode characters
|
||||
class nsIB2UConverter : public nsISupports {
|
||||
public:
|
||||
/** aDstLen is updated to indicate how much data was translated into
|
||||
* aDst; aSrcLen is updated to indicate how much data was used in
|
||||
* the source buffer.
|
||||
*/
|
||||
virtual PRInt32 Convert(PRUnichar* aDst,
|
||||
PRInt32 aDstOffset,
|
||||
PRInt32& aDstLen,
|
||||
const char* aSrc,
|
||||
PRInt32 aSrcOffset,
|
||||
PRInt32& aSrcLen) = 0;
|
||||
};
|
||||
|
||||
/** Create a new nsUnicharInputStream that provides a converter for the
|
||||
* byte input stream aStreamToWrap. If no converter can be found then
|
||||
* nsnull is returned and the error code is set to
|
||||
* NS_INPUTSTREAM_NO_CONVERTER.
|
||||
*/
|
||||
extern NS_BASE nsresult
|
||||
NS_NewConverterStream(nsIUnicharInputStream** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
nsIInputStream* aStreamToWrap,
|
||||
PRInt32 aBufferSize = 0,
|
||||
nsCharSetID aCharSet = eCharSetID_IsoLatin1);
|
||||
|
||||
/** Create a new nsB2UConverter for the given character set. When given
|
||||
* nsnull, the converter for iso-latin1 to unicode is provided. If no
|
||||
* converter can be found, nsnull is returned.
|
||||
*/
|
||||
extern NS_BASE nsresult
|
||||
NS_NewB2UConverter(nsIB2UConverter** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
nsCharSetID aCharSet = eCharSetID_IsoLatin1);
|
||||
|
||||
#endif /* nsUnicharInputStream_h___ */
|
||||
191
base/src/nsInputStream.cpp
Normal file
191
base/src/nsInputStream.cpp
Normal file
@@ -0,0 +1,191 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsIInputStream.h"
|
||||
#include "prprf.h"
|
||||
#include <fcntl.h>
|
||||
#ifdef XP_PC
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
// File input stream class
|
||||
class FileInputStream : public nsIInputStream {
|
||||
public:
|
||||
FileInputStream(PRInt32 aFD);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
virtual PRInt32 Read(PRInt32* aErrorCode,
|
||||
char* aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount);
|
||||
virtual void Close();
|
||||
|
||||
protected:
|
||||
~FileInputStream();
|
||||
|
||||
PRInt32 mFD;
|
||||
};
|
||||
|
||||
FileInputStream::FileInputStream(PRInt32 aFD)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mFD = aFD;
|
||||
}
|
||||
|
||||
NS_DEFINE_IID(kIInputStreamIID, NS_IINPUTSTREAM_IID);
|
||||
NS_IMPL_ISUPPORTS(FileInputStream,kIInputStreamIID);
|
||||
|
||||
FileInputStream::~FileInputStream()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
PRInt32 FileInputStream::Read(PRInt32* aErrorCode,
|
||||
char* aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount)
|
||||
{
|
||||
NS_PRECONDITION(aOffset >= 0, "illegal offset");
|
||||
NS_PRECONDITION(aCount >= 0, "illegal count");
|
||||
NS_PRECONDITION(mFD != -1, "closed");
|
||||
if ((aOffset < 0) || (aCount < 0)) {
|
||||
*aErrorCode = NS_INPUTSTREAM_ILLEGAL_ARGS;
|
||||
return -1;
|
||||
}
|
||||
if (mFD == -1) {
|
||||
*aErrorCode = NS_INPUTSTREAM_CLOSED;
|
||||
return -1;
|
||||
}
|
||||
PRInt32 nb = PRInt32( ::read(mFD, aBuf + aOffset, aCount) );
|
||||
if (nb <= 0) {
|
||||
if (nb < 0) {
|
||||
*aErrorCode = NS_INPUTSTREAM_OSERROR;
|
||||
return -1;
|
||||
}
|
||||
*aErrorCode = NS_INPUTSTREAM_EOF;
|
||||
}
|
||||
return nb;
|
||||
}
|
||||
|
||||
void FileInputStream::Close()
|
||||
{
|
||||
if (-1 != mFD) {
|
||||
::close(mFD);
|
||||
mFD = -1;
|
||||
}
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_OpenFile(nsIInputStream** aInstancePtrResult,
|
||||
const char* aLocalFileName)
|
||||
{
|
||||
#ifdef XP_PC
|
||||
char* lfn = strdup(aLocalFileName);
|
||||
char* cp = lfn;
|
||||
while ((cp = strchr(cp, '/')) != 0) {
|
||||
*cp = '\\';
|
||||
cp++;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef XP_PC
|
||||
PRInt32 fd = ::open(lfn, O_RDONLY | O_BINARY);
|
||||
free(lfn);
|
||||
#else
|
||||
|
||||
#ifdef NS_WIN32
|
||||
PRInt32 fd = ::open(aLocalFileName, O_RDONLY | O_BINARY);
|
||||
#endif
|
||||
#ifdef XP_UNIX
|
||||
PRInt32 fd = ::open(aLocalFileName, O_RDONLY);
|
||||
#endif
|
||||
|
||||
#endif //XP_PC
|
||||
|
||||
if (fd == -1) {
|
||||
return NS_INPUTSTREAM_OSERROR;
|
||||
}
|
||||
FileInputStream* it = new FileInputStream(fd);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kIInputStreamIID, (void**)aInstancePtrResult);
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_OpenResource(nsIInputStream** aInstancePtrResult,
|
||||
const char* aResourceFileName)
|
||||
{
|
||||
// XXX For now, resources are not in jar files
|
||||
// Find base path name to the resource file
|
||||
char* resourceBase;
|
||||
char* cp;
|
||||
|
||||
#ifdef XP_PC
|
||||
// XXX For now, all resources are relative to the .exe file
|
||||
resourceBase = new char[2000];
|
||||
DWORD mfnLen = GetModuleFileName(NULL, resourceBase, 2000);
|
||||
cp = strrchr(resourceBase, '\\');
|
||||
if (nsnull != cp) {
|
||||
*cp = '\0';
|
||||
}
|
||||
#endif
|
||||
#ifdef XP_UNIX
|
||||
// FIX ME: write me!;
|
||||
#endif
|
||||
|
||||
// Join base path to resource name
|
||||
if (aResourceFileName[0] == '/') {
|
||||
aResourceFileName++;
|
||||
}
|
||||
PRInt32 baseLen = strlen(resourceBase);
|
||||
PRInt32 resLen = strlen(aResourceFileName);
|
||||
PRInt32 totalLen = baseLen + 1 + resLen + 1;
|
||||
char* fileName = new char[totalLen];
|
||||
PR_snprintf(fileName, totalLen, "%s/%s", resourceBase, aResourceFileName);
|
||||
|
||||
#ifdef XP_PC
|
||||
while ((cp = strchr(fileName, '/')) != 0) {
|
||||
*cp = '\\';
|
||||
cp++;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get
|
||||
#ifdef NS_WIN32
|
||||
PRInt32 fd = ::open(fileName, O_RDONLY | O_BINARY);
|
||||
#endif
|
||||
#ifdef XP_UNIX
|
||||
PRInt32 fd = ::open(fileName, O_RDONLY);
|
||||
#endif
|
||||
|
||||
delete fileName;
|
||||
|
||||
#ifdef XP_PC
|
||||
delete resourceBase;
|
||||
#endif
|
||||
|
||||
if (fd == -1) {
|
||||
return NS_INPUTSTREAM_OSERROR;
|
||||
}
|
||||
FileInputStream* it = new FileInputStream(fd);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kIInputStreamIID, (void**)aInstancePtrResult);
|
||||
}
|
||||
1979
base/src/nsString.cpp
Normal file
1979
base/src/nsString.cpp
Normal file
File diff suppressed because it is too large
Load Diff
233
base/src/nsString.h
Normal file
233
base/src/nsString.h
Normal file
@@ -0,0 +1,233 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* MODULE NOTES:
|
||||
* LAST MODS: gess 28Feb98
|
||||
*
|
||||
* This very simple string class that knows how to do
|
||||
* efficient (dynamic) resizing. It offers almost no
|
||||
* i18n support, and will undoubtedly have to be replaced.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _NSSTRING
|
||||
#define _NSSTRING
|
||||
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include "nsIAtom.h"
|
||||
#include <iostream.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
class NS_BASE nsString {
|
||||
public:
|
||||
|
||||
nsString(const char* anISOLatin1="");
|
||||
nsString(const nsString&);
|
||||
nsString(const PRUnichar* aUnicode);
|
||||
virtual ~nsString();
|
||||
|
||||
PRInt32 Length() const { return mLength; }
|
||||
|
||||
void SetLength(PRInt32 aLength);
|
||||
void Truncate(PRInt32 anIndex=0);
|
||||
virtual void EnsureCapacityFor(PRInt32 aNewLength);
|
||||
|
||||
///accessor methods
|
||||
//@{
|
||||
PRUnichar* GetUnicode(void) const;
|
||||
operator PRUnichar*() const;
|
||||
|
||||
#if 0
|
||||
// This is NOT allowed because it has to do a malloc to
|
||||
// create the iso-latin-1 version of the unicode string
|
||||
operator char*() const;
|
||||
#endif
|
||||
|
||||
PRUnichar* operator()() const;
|
||||
PRUnichar operator()(PRInt32 i) const;
|
||||
PRUnichar& operator[](PRInt32 i) const;
|
||||
PRUnichar& CharAt(PRInt32 anIndex) const;
|
||||
PRUnichar& First() const;
|
||||
PRUnichar& Last() const;
|
||||
|
||||
//string creation methods...
|
||||
nsString operator+(const nsString& aString);
|
||||
nsString operator+(const char* anISOLatin1);
|
||||
nsString operator+(char aChar);
|
||||
nsString operator+(const PRUnichar* aBuffer);
|
||||
nsString operator+(PRUnichar aChar);
|
||||
|
||||
void ToLowerCase();
|
||||
void ToLowerCase(nsString& aString) const;
|
||||
void ToUpperCase();
|
||||
void ToUpperCase(nsString& aString) const;
|
||||
|
||||
nsString* ToNewString() const;
|
||||
char* ToNewCString() const;
|
||||
|
||||
char* ToCString(char* aBuf,PRInt32 aBufLength) const;
|
||||
void ToString(nsString& aString) const;
|
||||
|
||||
PRUnichar* ToNewUnicode() const;
|
||||
float ToFloat(PRInt32* aErrorCode) const;
|
||||
PRInt32 ToInteger(PRInt32* aErrorCode) const;
|
||||
//@}
|
||||
|
||||
///string manipulation methods...
|
||||
//@{
|
||||
nsString& operator=(const nsString& aString);
|
||||
nsString& operator=(const char* anISOLatin1);
|
||||
nsString& operator=(char aChar);
|
||||
nsString& operator=(const PRUnichar* aBuffer);
|
||||
nsString& operator=(PRUnichar aChar);
|
||||
nsString& SetString(const PRUnichar* aStr,PRInt32 aLength=-1);
|
||||
nsString& SetString(const char* anISOLatin1,PRInt32 aLength=-1);
|
||||
|
||||
nsString& operator+=(const nsString& aString);
|
||||
nsString& operator+=(const char* anISOLatin1);
|
||||
nsString& operator+=(const PRUnichar* aBuffer);
|
||||
nsString& operator+=(PRUnichar aChar);
|
||||
nsString& Append(const nsString& aString,PRInt32 aLength=-1);
|
||||
nsString& Append(const char* anISOLatin1,PRInt32 aLength=-1);
|
||||
nsString& Append(char aChar);
|
||||
nsString& Append(const PRUnichar* aBuffer,PRInt32 aLength=-1);
|
||||
nsString& Append(PRUnichar aChar);
|
||||
nsString& Append(PRInt32 aInteger,PRInt32 aRadix); //radix=8,10 or 16
|
||||
nsString& Append(float aFloat);
|
||||
|
||||
PRInt32 Left(nsString& aCopy,PRInt32 aCount);
|
||||
PRInt32 Mid(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount);
|
||||
PRInt32 Right(nsString& aCopy,PRInt32 aCount);
|
||||
PRInt32 Insert(nsString& aCopy,PRInt32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
nsString& Cut(PRInt32 anOffset,PRInt32 aCount);
|
||||
nsString& StripChars(const char* aSet);
|
||||
nsString& StripWhitespace();
|
||||
nsString& Trim( const char* aSet,
|
||||
PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,
|
||||
PRBool aEliminateTrailing=PR_TRUE);
|
||||
static PRBool IsSpace(PRUnichar ch);
|
||||
static PRBool IsAlpha(PRUnichar ch);
|
||||
//@}
|
||||
|
||||
///searching methods...
|
||||
//@{
|
||||
PRInt32 Find(const char* anISOLatin1) const;
|
||||
PRInt32 Find(const PRUnichar* aString) const;
|
||||
PRInt32 Find(PRUnichar aChar,PRInt32 offset=0) const;
|
||||
PRInt32 Find(const nsString& aString) const;
|
||||
PRInt32 FindFirstCharInSet(const char* anISOLatin1Set,PRInt32 offset=0) const;
|
||||
PRInt32 FindFirstCharInSet(nsString& aString,PRInt32 offset=0) const;
|
||||
PRInt32 FindLastCharInSet(const char* anISOLatin1Set,PRInt32 offset=0) const;
|
||||
PRInt32 FindLastCharInSet(nsString& aString,PRInt32 offset=0) const;
|
||||
PRInt32 RFind(const char* anISOLatin1,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFind(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
//@}
|
||||
|
||||
///comparision methods...
|
||||
//@{
|
||||
virtual PRInt32 Compare(const nsString &S,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
virtual PRInt32 Compare(const char *anISOLatin1,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
virtual PRInt32 Compare(const PRUnichar *aString,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
PRInt32 operator==(const nsString &S) const;
|
||||
PRInt32 operator==(const char *anISOLatin1) const;
|
||||
PRInt32 operator==(const PRUnichar* aString) const;
|
||||
PRInt32 operator!=(const nsString &S) const;
|
||||
PRInt32 operator!=(const char *anISOLatin1) const;
|
||||
PRInt32 operator!=(const PRUnichar* aString) const;
|
||||
PRInt32 operator<(const nsString &S) const;
|
||||
PRInt32 operator<(const char *anISOLatin1) const;
|
||||
PRInt32 operator<(const PRUnichar* aString) const;
|
||||
PRInt32 operator>(const nsString &S) const;
|
||||
PRInt32 operator>(const char *anISOLatin1) const;
|
||||
PRInt32 operator>(const PRUnichar* aString) const;
|
||||
PRInt32 operator<=(const nsString &S) const;
|
||||
PRInt32 operator<=(const char *anISOLatin1) const;
|
||||
PRInt32 operator<=(const PRUnichar* aString) const;
|
||||
PRInt32 operator>=(const nsString &S) const;
|
||||
PRInt32 operator>=(const char *anISOLatin1) const;
|
||||
PRInt32 operator>=(const PRUnichar* aString) const;
|
||||
|
||||
PRBool Equals(const nsString& aString) const;
|
||||
PRBool Equals(const char* anISOLatin1) const;
|
||||
PRBool Equals(const nsIAtom *aAtom) const;
|
||||
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2) const;
|
||||
|
||||
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* anISOLatin1) const;
|
||||
PRBool EqualsIgnoreCase(const nsIAtom *aAtom) const;
|
||||
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
|
||||
//@}
|
||||
|
||||
static void SelfTest();
|
||||
virtual void DebugDump(ostream& aStream) const;
|
||||
|
||||
protected:
|
||||
|
||||
typedef PRUnichar chartype;
|
||||
|
||||
chartype* mStr;
|
||||
PRInt32 mLength;
|
||||
PRInt32 mCapacity;
|
||||
static PRInt32 mInstanceCount;
|
||||
};
|
||||
|
||||
extern NS_BASE int fputs(const nsString& aString, FILE* out);
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A version of nsString which is designed to be used as an automatic
|
||||
* variable. It attempts to operate out of a fixed size internal
|
||||
* buffer until too much data is added; then a dynamic buffer is
|
||||
* allocated and grown as necessary.
|
||||
*/
|
||||
// XXX template this with a parameter for the size of the buffer?
|
||||
class NS_BASE nsAutoString : public nsString {
|
||||
public:
|
||||
nsAutoString();
|
||||
nsAutoString(const nsString& other);
|
||||
nsAutoString(const nsAutoString& other);
|
||||
nsAutoString(PRUnichar aChar);
|
||||
nsAutoString(const char* isolatin1);
|
||||
nsAutoString(const PRUnichar* us, PRInt32 uslen = -1);
|
||||
virtual ~nsAutoString();
|
||||
|
||||
static void SelfTest();
|
||||
|
||||
protected:
|
||||
virtual void EnsureCapacityFor(PRInt32 aNewLength);
|
||||
|
||||
PRUnichar mBuf[32];
|
||||
|
||||
private:
|
||||
// XXX these need writing I suppose
|
||||
nsAutoString& operator=(const nsAutoString& other);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
344
base/src/nsURL.cpp
Normal file
344
base/src/nsURL.cpp
Normal file
@@ -0,0 +1,344 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsIURL.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsINetService.h"
|
||||
#include "nsString.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdio.h>/* XXX */
|
||||
#include "plstr.h"
|
||||
|
||||
class URLImpl : public nsIURL {
|
||||
public:
|
||||
URLImpl(const nsString& aSpec);
|
||||
URLImpl(const nsIURL* aURL, const nsString& aSpec);
|
||||
~URLImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual PRBool operator==(const nsIURL& aURL) const;
|
||||
virtual nsIInputStream* Open(PRInt32* aErrorCode) const;
|
||||
virtual const char* GetProtocol() const;
|
||||
virtual const char* GetHost() const;
|
||||
virtual const char* GetFile() const;
|
||||
virtual const char* GetRef() const;
|
||||
virtual const char* GetSpec() const;
|
||||
virtual PRInt32 GetPort() const;
|
||||
|
||||
virtual void ToString(nsString& aString) const;
|
||||
|
||||
char* mSpec;
|
||||
char* mProtocol;
|
||||
char* mHost;
|
||||
char* mFile;
|
||||
char* mRef;
|
||||
PRInt32 mPort;
|
||||
PRBool mOK;
|
||||
|
||||
nsresult ParseURL(const nsIURL* aURL, const nsString& aSpec);
|
||||
};
|
||||
|
||||
URLImpl::URLImpl(const nsString& aSpec)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
ParseURL(nsnull, aSpec);
|
||||
}
|
||||
|
||||
URLImpl::URLImpl(const nsIURL* aURL, const nsString& aSpec)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
ParseURL(aURL, aSpec);
|
||||
}
|
||||
|
||||
NS_DEFINE_IID(kURLIID, NS_IURL_IID);
|
||||
|
||||
NS_IMPL_ISUPPORTS(URLImpl, kURLIID)
|
||||
|
||||
URLImpl::~URLImpl()
|
||||
{
|
||||
free(mSpec);
|
||||
free(mProtocol);
|
||||
free(mHost);
|
||||
free(mFile);
|
||||
free(mRef);
|
||||
}
|
||||
|
||||
PRBool URLImpl::operator==(const nsIURL& aURL) const
|
||||
{
|
||||
URLImpl& other = (URLImpl&)aURL; // XXX ?
|
||||
return PRBool((0 == PL_strcmp(mProtocol, other.mProtocol)) &&
|
||||
(0 == PL_strcasecmp(mHost, other.mHost)) &&
|
||||
(0 == PL_strcmp(mFile, other.mFile)));
|
||||
}
|
||||
|
||||
const char* URLImpl::GetProtocol() const
|
||||
{
|
||||
return mProtocol;
|
||||
}
|
||||
|
||||
const char* URLImpl::GetHost() const
|
||||
{
|
||||
return mHost;
|
||||
}
|
||||
|
||||
const char* URLImpl::GetFile() const
|
||||
{
|
||||
return mFile;
|
||||
}
|
||||
|
||||
const char* URLImpl::GetSpec() const
|
||||
{
|
||||
return mSpec;
|
||||
}
|
||||
|
||||
const char* URLImpl::GetRef() const
|
||||
{
|
||||
return mRef;
|
||||
}
|
||||
|
||||
PRInt32 URLImpl::GetPort() const
|
||||
{
|
||||
return mPort;
|
||||
}
|
||||
|
||||
|
||||
void URLImpl::ToString(nsString& aString) const
|
||||
{
|
||||
aString.SetLength(0);
|
||||
aString.Append(mProtocol);
|
||||
aString.Append("://");
|
||||
if (nsnull != mHost) {
|
||||
aString.Append(mHost);
|
||||
if (0 < mPort) {
|
||||
aString.Append(':');
|
||||
aString.Append(mPort, 10);
|
||||
}
|
||||
}
|
||||
aString.Append(mFile);
|
||||
if (nsnull != mRef) {
|
||||
aString.Append('#');
|
||||
aString.Append(mRef);
|
||||
}
|
||||
}
|
||||
|
||||
// XXX recode to use nsString api's
|
||||
|
||||
// XXX don't bother with port numbers
|
||||
// XXX don't bother with ref's
|
||||
// XXX null pointer checks are incomplete
|
||||
nsresult URLImpl::ParseURL(const nsIURL* aURL, const nsString& aSpec)
|
||||
{
|
||||
// XXX hack!
|
||||
char* cSpec = aSpec.ToNewCString();
|
||||
|
||||
const char* uProtocol = nsnull;
|
||||
const char* uHost = nsnull;
|
||||
const char* uFile = nsnull;
|
||||
PRInt32 uPort = -1;
|
||||
if (nsnull != aURL) {
|
||||
uProtocol = aURL->GetProtocol();
|
||||
uHost = aURL->GetHost();
|
||||
uFile = aURL->GetFile();
|
||||
uPort = aURL->GetPort();
|
||||
}
|
||||
|
||||
mProtocol = nsnull;
|
||||
mHost = nsnull;
|
||||
mFile = nsnull;
|
||||
mRef = nsnull;
|
||||
mPort = -1;
|
||||
mSpec = nsnull;
|
||||
|
||||
if (nsnull == cSpec) {
|
||||
delete cSpec;
|
||||
if (nsnull == aURL) {
|
||||
delete cSpec;
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
mProtocol = (nsnull != uProtocol) ? PL_strdup(uProtocol) : nsnull;
|
||||
mHost = (nsnull != uHost) ? PL_strdup(uHost) : nsnull;
|
||||
mPort = uPort;
|
||||
mFile = (nsnull != uFile) ? PL_strdup(uFile) : nsnull;
|
||||
delete cSpec;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mSpec = PL_strdup(cSpec);
|
||||
const char* cp = PL_strchr(cSpec, ':');
|
||||
if (nsnull == cp) {
|
||||
// relative spec
|
||||
if (nsnull == aURL) {
|
||||
delete cSpec;
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
// keep protocol and host
|
||||
mProtocol = (nsnull != uProtocol) ? PL_strdup(uProtocol) : nsnull;
|
||||
mHost = (nsnull != uHost) ? PL_strdup(uHost) : nsnull;
|
||||
mPort = uPort;
|
||||
|
||||
// figure out file name
|
||||
PRInt32 len = PL_strlen(cSpec) + 1;
|
||||
if ((len > 1) && (cSpec[0] == '/')) {
|
||||
// Relative spec is absolute to the server
|
||||
mFile = PL_strdup(cSpec);
|
||||
} else {
|
||||
char* dp = PL_strrchr(uFile, '/');
|
||||
PRInt32 dirlen = (dp + 1) - uFile;
|
||||
mFile = (char*) malloc(dirlen + len);
|
||||
PL_strncpy(mFile, uFile, dirlen);
|
||||
PL_strcpy(mFile + dirlen, cSpec);
|
||||
}
|
||||
} else {
|
||||
// absolute spec
|
||||
|
||||
// get protocol first
|
||||
PRInt32 plen = cp - cSpec;
|
||||
mProtocol = (char*) malloc(plen + 1);
|
||||
PL_strncpy(mProtocol, cSpec, plen);
|
||||
mProtocol[plen] = 0;
|
||||
cp++; // eat : in protocol
|
||||
|
||||
// skip over one, two or three slashes
|
||||
if (*cp == '/') {
|
||||
cp++;
|
||||
if (*cp == '/') {
|
||||
cp++;
|
||||
if (*cp == '/') {
|
||||
cp++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
delete cSpec;
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
}
|
||||
|
||||
const char* cp0 = cp;
|
||||
if ((PL_strcmp(mProtocol, "resource") == 0) ||
|
||||
(PL_strcmp(mProtocol, "file") == 0)) {
|
||||
// resource/file url's do not have host names.
|
||||
// The remainder of the string is the file name
|
||||
PRInt32 flen = PL_strlen(cp);
|
||||
mFile = (char*) malloc(flen + 1);
|
||||
PL_strcpy(mFile, cp);
|
||||
|
||||
#ifdef NS_WIN32
|
||||
if (PL_strcmp(mProtocol, "file") == 0) {
|
||||
// If the filename starts with a "x|" where is an single
|
||||
// character then we assume it's a drive name and change the
|
||||
// vertical bar back to a ":"
|
||||
if ((flen >= 2) && (mFile[1] == '|')) {
|
||||
mFile[1] = ':';
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
// Host name follows protocol for http style urls
|
||||
cp = PL_strchr(cp, '/');
|
||||
if (nsnull == cp) {
|
||||
// There is no file name, only a host name
|
||||
PRInt32 hlen = PL_strlen(cp0);
|
||||
mHost = (char*) malloc(hlen + 1);
|
||||
PL_strcpy(mHost, cp0);
|
||||
|
||||
// Set filename to "/"
|
||||
mFile = (char*) malloc(2);
|
||||
mFile[0] = '/';
|
||||
mFile[1] = 0;
|
||||
}
|
||||
else {
|
||||
PRInt32 hlen = cp - cp0;
|
||||
mHost = (char*) malloc(hlen + 1);
|
||||
PL_strncpy(mHost, cp0, hlen);
|
||||
mHost[hlen] = 0;
|
||||
|
||||
// The rest is the file name
|
||||
PRInt32 flen = PL_strlen(cp);
|
||||
mFile = (char*) malloc(flen + 1);
|
||||
PL_strcpy(mFile, cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//printf("protocol='%s' host='%s' file='%s'\n", mProtocol, mHost, mFile);
|
||||
delete cSpec;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIInputStream* URLImpl::Open(PRInt32* aErrorCode) const
|
||||
{
|
||||
nsresult rv;
|
||||
nsIInputStream* in = nsnull;
|
||||
|
||||
if (PL_strcmp(mProtocol, "file") == 0) {
|
||||
rv = NS_OpenFile(&in, mFile);
|
||||
} else if (PL_strcmp(mProtocol, "resource") == 0) {
|
||||
rv = NS_OpenResource(&in, mFile);
|
||||
} else {
|
||||
nsINetService *inet;
|
||||
|
||||
rv = NS_NewINetService(&inet, nsnull);
|
||||
if (NS_OK == rv) {
|
||||
rv = inet->OpenBlockingStream(mSpec, NULL, &in);
|
||||
}
|
||||
}
|
||||
*aErrorCode = rv;
|
||||
return in;
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_NewURL(nsIURL** aInstancePtrResult,
|
||||
const nsString& aSpec)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
URLImpl* it = new URLImpl(aSpec);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kURLIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_NewURL(nsIURL** aInstancePtrResult,
|
||||
const nsIURL* aURL,
|
||||
const nsString& aSpec)
|
||||
{
|
||||
URLImpl* it = new URLImpl(aURL, aSpec);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kURLIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_MakeAbsoluteURL(nsIURL* aURL,
|
||||
const nsString& aBaseURL,
|
||||
const nsString& aSpec,
|
||||
nsString& aResult)
|
||||
{
|
||||
if (0 < aBaseURL.Length()) {
|
||||
URLImpl base(aBaseURL);
|
||||
URLImpl url(&base, aSpec);
|
||||
url.ToString(aResult);
|
||||
} else {
|
||||
URLImpl url(aURL, aSpec);
|
||||
url.ToString(aResult);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
137
base/src/nsUnicharBuffer.cpp
Normal file
137
base/src/nsUnicharBuffer.cpp
Normal file
@@ -0,0 +1,137 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsIUnicharBuffer.h"
|
||||
#include "nsIUnicharInputStream.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#define MIN_BUFFER_SIZE 32
|
||||
|
||||
class UnicharBufferImpl : public nsIUnicharBuffer {
|
||||
public:
|
||||
UnicharBufferImpl(PRInt32 aBufferSize);
|
||||
~UnicharBufferImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
virtual PRInt32 GetLength() const;
|
||||
virtual PRInt32 GetBufferSize() const;
|
||||
virtual PRUnichar* GetBuffer() const;
|
||||
virtual PRBool Grow(PRInt32 aNewSize);
|
||||
virtual PRInt32 Fill(PRInt32* aErrorCode, nsIUnicharInputStream* aStream,
|
||||
PRInt32 aKeep);
|
||||
|
||||
PRUnichar* mBuffer;
|
||||
PRInt32 mSpace;
|
||||
PRInt32 mLength;
|
||||
};
|
||||
|
||||
UnicharBufferImpl::UnicharBufferImpl(PRInt32 aBufferSize)
|
||||
{
|
||||
if (PRUint32(aBufferSize) < MIN_BUFFER_SIZE) {
|
||||
aBufferSize = MIN_BUFFER_SIZE;
|
||||
}
|
||||
mSpace = aBufferSize;
|
||||
mBuffer = new PRUnichar[aBufferSize];
|
||||
mLength = 0;
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
NS_DEFINE_IID(kUnicharBufferIID, NS_IUNICHAR_BUFFER_IID);
|
||||
NS_IMPL_ISUPPORTS(UnicharBufferImpl,kUnicharBufferIID)
|
||||
|
||||
UnicharBufferImpl::~UnicharBufferImpl()
|
||||
{
|
||||
if (nsnull != mBuffer) {
|
||||
delete mBuffer;
|
||||
mBuffer = nsnull;
|
||||
}
|
||||
mLength = 0;
|
||||
}
|
||||
|
||||
PRInt32 UnicharBufferImpl::GetLength() const
|
||||
{
|
||||
return mLength;
|
||||
}
|
||||
|
||||
PRInt32 UnicharBufferImpl::GetBufferSize() const
|
||||
{
|
||||
return mSpace;
|
||||
}
|
||||
|
||||
PRUnichar* UnicharBufferImpl::GetBuffer() const
|
||||
{
|
||||
return mBuffer;
|
||||
}
|
||||
|
||||
PRBool UnicharBufferImpl::Grow(PRInt32 aNewSize)
|
||||
{
|
||||
if (PRUint32(aNewSize) < MIN_BUFFER_SIZE) {
|
||||
aNewSize = MIN_BUFFER_SIZE;
|
||||
}
|
||||
PRUnichar* newbuf = new PRUnichar[aNewSize];
|
||||
if (nsnull != newbuf) {
|
||||
if (0 != mLength) {
|
||||
nsCRT::memcpy(newbuf, mBuffer, mLength * sizeof(PRUnichar));
|
||||
}
|
||||
delete mBuffer;
|
||||
mBuffer = newbuf;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRInt32 UnicharBufferImpl::Fill(PRInt32* aErrorCode,
|
||||
nsIUnicharInputStream* aStream,
|
||||
PRInt32 aKeep)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aStream, "null stream");
|
||||
NS_PRECONDITION(PRUint32(aKeep) < PRUint32(mLength), "illegal keep count");
|
||||
if ((nsnull == aStream) || (PRUint32(aKeep) >= PRUint32(mLength))) {
|
||||
// whoops
|
||||
*aErrorCode = NS_INPUTSTREAM_ILLEGAL_ARGS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != aKeep) {
|
||||
// Slide over kept data
|
||||
nsCRT::memmove(mBuffer, mBuffer + (mLength - aKeep),
|
||||
aKeep * sizeof(PRUnichar));
|
||||
}
|
||||
|
||||
// Read in some new data
|
||||
mLength = aKeep;
|
||||
PRInt32 amount = mSpace - aKeep;
|
||||
PRInt32 nb = aStream->Read(aErrorCode, mBuffer, aKeep, amount);
|
||||
if (nb > 0) {
|
||||
mLength += nb;
|
||||
}
|
||||
return nb;
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_NewUnicharBuffer(nsIUnicharBuffer** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
PRInt32 aBufferSize)
|
||||
{
|
||||
if (nsnull != aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
UnicharBufferImpl* it = new UnicharBufferImpl(aBufferSize);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kUnicharBufferIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
328
base/src/nsUnicharInputStream.cpp
Normal file
328
base/src/nsUnicharInputStream.cpp
Normal file
@@ -0,0 +1,328 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsIUnicharInputStream.h"
|
||||
#include "nsIByteBuffer.h"
|
||||
#include "nsIUnicharBuffer.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
#include <fcntl.h>
|
||||
#ifdef NS_WIN32
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
static NS_DEFINE_IID(kIUnicharInputStreamIID, NS_IUNICHAR_INPUT_STREAM_IID);
|
||||
|
||||
class StringUnicharInputStream : public nsIUnicharInputStream {
|
||||
public:
|
||||
StringUnicharInputStream(nsString* aString);
|
||||
~StringUnicharInputStream();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual PRInt32 Read(PRInt32* aErrorCode,
|
||||
PRUnichar* aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount);
|
||||
virtual void Close();
|
||||
|
||||
nsString* mString;
|
||||
PRInt32 mPos;
|
||||
PRInt32 mLen;
|
||||
};
|
||||
|
||||
StringUnicharInputStream::StringUnicharInputStream(nsString* aString)
|
||||
{
|
||||
mString = aString;
|
||||
mPos = 0;
|
||||
mLen = aString->Length();
|
||||
}
|
||||
|
||||
StringUnicharInputStream::~StringUnicharInputStream()
|
||||
{
|
||||
if (nsnull != mString) {
|
||||
delete mString;
|
||||
}
|
||||
}
|
||||
|
||||
PRInt32 StringUnicharInputStream::Read(PRInt32* aErrorCode,
|
||||
PRUnichar* aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount)
|
||||
{
|
||||
if (mPos >= mLen) {
|
||||
return -1;
|
||||
}
|
||||
const PRUnichar* us = mString->GetUnicode();
|
||||
PRInt32 amount = mLen - mPos;
|
||||
if (amount > aCount) {
|
||||
amount = aCount;
|
||||
}
|
||||
nsCRT::memcpy(aBuf + aOffset, us + mPos, sizeof(PRUnichar) * amount);
|
||||
mPos += amount;
|
||||
return amount;
|
||||
}
|
||||
|
||||
void StringUnicharInputStream::Close()
|
||||
{
|
||||
mPos = mLen;
|
||||
if (nsnull != mString) {
|
||||
delete mString;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(StringUnicharInputStream, kIUnicharInputStreamIID);
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewStringUnicharInputStream(nsIUnicharInputStream** aInstancePtrResult,
|
||||
nsString* aString)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aString, "null ptr");
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
||||
if ((nsnull == aString) || (nsnull == aInstancePtrResult)) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
StringUnicharInputStream* it = new StringUnicharInputStream(aString);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kIUnicharInputStreamIID,
|
||||
(void**) aInstancePtrResult);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class IsoLatin1Converter : public nsIB2UConverter {
|
||||
public:
|
||||
IsoLatin1Converter();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
virtual PRInt32 Convert(PRUnichar* aDst,
|
||||
PRInt32 aDstOffset,
|
||||
PRInt32& aDstLen,
|
||||
const char* aSrc,
|
||||
PRInt32 aSrcOffset,
|
||||
PRInt32& aSrcLen);
|
||||
};
|
||||
|
||||
IsoLatin1Converter::IsoLatin1Converter()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
NS_DEFINE_IID(kIB2UConverterIID, NS_IB2UCONVERTER_IID);
|
||||
NS_IMPL_ISUPPORTS(IsoLatin1Converter,kIB2UConverterIID);
|
||||
|
||||
PRInt32 IsoLatin1Converter::Convert(PRUnichar* aDst,
|
||||
PRInt32 aDstOffset,
|
||||
PRInt32& aDstLen,
|
||||
const char* aSrc,
|
||||
PRInt32 aSrcOffset,
|
||||
PRInt32& aSrcLen)
|
||||
{
|
||||
PRInt32 amount = aSrcLen;
|
||||
if (aSrcLen > aDstLen) {
|
||||
amount = aDstLen;
|
||||
}
|
||||
const char* end = aSrc + amount;
|
||||
while (aSrc < end) {
|
||||
PRUint8 isoLatin1 = PRUint8(*aSrc++);
|
||||
/* XXX insert table based lookup converter here */
|
||||
*aDst++ = isoLatin1;
|
||||
}
|
||||
aDstLen = amount;
|
||||
aSrcLen = amount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_BASE nsresult
|
||||
NS_NewB2UConverter(nsIB2UConverter** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
nsCharSetID aCharSet)
|
||||
{
|
||||
if (nsnull != aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
if (eCharSetID_IsoLatin1 != aCharSet) {
|
||||
return NS_INPUTSTREAM_NO_CONVERTER;
|
||||
}
|
||||
IsoLatin1Converter* it = new IsoLatin1Converter();
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kIB2UConverterIID, (void**)aInstancePtrResult);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class ConverterInputStream : public nsIUnicharInputStream {
|
||||
public:
|
||||
ConverterInputStream(nsIInputStream* aStream,
|
||||
nsIB2UConverter* aConverter,
|
||||
PRInt32 aBufSize);
|
||||
~ConverterInputStream();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
virtual PRInt32 Read(PRInt32* aErrorCode,
|
||||
PRUnichar* aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount);
|
||||
virtual void Close();
|
||||
|
||||
protected:
|
||||
PRInt32 Fill(PRInt32* aErrorCode);
|
||||
|
||||
nsIInputStream* mInput;
|
||||
nsIB2UConverter* mConverter;
|
||||
nsIByteBuffer* mByteData;
|
||||
PRInt32 mByteDataOffset;
|
||||
nsIUnicharBuffer* mUnicharData;
|
||||
PRInt32 mUnicharDataOffset;
|
||||
PRInt32 mUnicharDataLength;
|
||||
};
|
||||
|
||||
ConverterInputStream::ConverterInputStream(nsIInputStream* aStream,
|
||||
nsIB2UConverter* aConverter,
|
||||
PRInt32 aBufferSize)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mInput = aStream; aStream->AddRef();
|
||||
mConverter = aConverter; aConverter->AddRef();
|
||||
if (aBufferSize == 0) {
|
||||
aBufferSize = 8192;
|
||||
}
|
||||
nsresult rv1 = NS_NewByteBuffer(&mByteData, nsnull, aBufferSize);
|
||||
nsresult rv2 = NS_NewUnicharBuffer(&mUnicharData, nsnull, aBufferSize);
|
||||
mByteDataOffset = 0;
|
||||
mUnicharDataOffset = 0;
|
||||
mUnicharDataLength = 0;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ConverterInputStream,kIUnicharInputStreamIID);
|
||||
|
||||
ConverterInputStream::~ConverterInputStream()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void ConverterInputStream::Close()
|
||||
{
|
||||
if (nsnull != mInput) {
|
||||
mInput->Release();
|
||||
mInput = nsnull;
|
||||
}
|
||||
if (nsnull != mConverter) {
|
||||
mConverter->Release();
|
||||
mConverter = nsnull;
|
||||
}
|
||||
if (nsnull != mByteData) {
|
||||
mByteData->Release();
|
||||
mByteData = nsnull;
|
||||
}
|
||||
if (nsnull != mUnicharData) {
|
||||
mUnicharData->Release();
|
||||
mUnicharData = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
PRInt32 ConverterInputStream::Read(PRInt32* aErrorCode,
|
||||
PRUnichar* aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount)
|
||||
{
|
||||
PRInt32 rv = mUnicharDataLength - mUnicharDataOffset;
|
||||
if (0 == rv) {
|
||||
// Fill the unichar buffer
|
||||
rv = Fill(aErrorCode);
|
||||
if (rv <= 0) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
if (rv > aCount) {
|
||||
rv = aCount;
|
||||
}
|
||||
nsCRT::memcpy(aBuf + aOffset, mUnicharData->GetBuffer() + mUnicharDataOffset,
|
||||
rv * sizeof(PRUnichar));
|
||||
mUnicharDataOffset += rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
PRInt32 ConverterInputStream::Fill(PRInt32* aErrorCode)
|
||||
{
|
||||
if (nsnull == mInput) {
|
||||
// We already closed the stream!
|
||||
*aErrorCode = NS_INPUTSTREAM_CLOSED;
|
||||
return -1;
|
||||
}
|
||||
|
||||
PRInt32 remainder = mByteData->GetLength() - mByteDataOffset;
|
||||
mByteDataOffset = remainder;
|
||||
PRInt32 nb = mByteData->Fill(aErrorCode, mInput, remainder);
|
||||
if (nb <= 0) {
|
||||
// Because we assume a many to one conversion, the lingering data
|
||||
// in the byte buffer must be a partial conversion
|
||||
// fragment. Because we know that we have recieved no more new
|
||||
// data to add to it, we can't convert it. Therefore, we discard
|
||||
// it.
|
||||
return nb;
|
||||
}
|
||||
NS_ASSERTION(remainder + nb == mByteData->GetLength(), "bad nb");
|
||||
|
||||
// Now convert as much of the byte buffer to unicode as possible
|
||||
PRInt32 dstLen = mUnicharData->GetBufferSize();
|
||||
PRInt32 srcLen = remainder + nb;
|
||||
*aErrorCode = mConverter->Convert(mUnicharData->GetBuffer(), 0, dstLen,
|
||||
mByteData->GetBuffer(), 0, srcLen);
|
||||
mUnicharDataOffset = 0;
|
||||
mUnicharDataLength = dstLen;
|
||||
mByteDataOffset += srcLen;
|
||||
return dstLen;
|
||||
}
|
||||
|
||||
// XXX hook up auto-detect here (do we need more info, like the url?)
|
||||
NS_BASE nsresult
|
||||
NS_NewConverterStream(nsIUnicharInputStream** aInstancePtrResult,
|
||||
nsISupports* aOuter,
|
||||
nsIInputStream* aStreamToWrap,
|
||||
PRInt32 aBufferSize,
|
||||
nsCharSetID aCharSet)
|
||||
{
|
||||
if (nsnull != aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
|
||||
// Create converter
|
||||
nsIB2UConverter* converter;
|
||||
nsresult rv = NS_NewB2UConverter(&converter, nsnull, aCharSet);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Create converter input stream
|
||||
ConverterInputStream* it =
|
||||
new ConverterInputStream(aStreamToWrap, converter, aBufferSize);
|
||||
converter->Release();
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return it->QueryInterface(kIUnicharInputStreamIID,
|
||||
(void **) aInstancePtrResult);
|
||||
}
|
||||
71
base/src/nsUnitConversion.h
Normal file
71
base/src/nsUnitConversion.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsUnitConversion_h__
|
||||
#define nsUnitConversion_h__
|
||||
|
||||
#include "nscore.h"
|
||||
#include <math.h>
|
||||
|
||||
/// Unit conversion macros
|
||||
//@{
|
||||
#define TWIPS_CONST 20
|
||||
#define TWIPS_CONST_FLOAT 20.0f
|
||||
|
||||
#define NS_POINTS_TO_TWIPS_INT(x) ((PRInt32)(TWIPS_CONST * (x)))
|
||||
#define NS_TWIPS_TO_POINTS_INT(x) ((PRInt32)((x) / TWIPS_CONST))
|
||||
|
||||
#define NS_POINTS_TO_TWIPS_FLOAT(x) (TWIPS_CONST_FLOAT * (x))
|
||||
#define NS_TWIPS_TO_POINTS_FLOAT(x) ((x) / TWIPS_CONST_FLOAT)
|
||||
|
||||
#define NS_INCHES_TO_TWIPS(x) (72.0f * TWIPS_CONST_FLOAT * (x)) // 72 points per inch
|
||||
#define NS_FEET_TO_TWIPS(x) (72.0f * 12.0f * TWIPS_CONST_FLOAT * (x))
|
||||
#define NS_MILES_TO_TWIPS(x) (72.0f * 12.0f * 5280.0f * TWIPS_CONST_FLOAT * (x))
|
||||
|
||||
#define NS_MILLIMETERS_TO_TWIPS(x) (72.0f * 0.03937f * TWIPS_CONST_FLOAT * (x))
|
||||
#define NS_CENTIMETERS_TO_TWIPS(x) (72.0f * 0.3937f * TWIPS_CONST_FLOAT * (x))
|
||||
#define NS_METERS_TO_TWIPS(x) (72.0f * 39.37f * TWIPS_CONST_FLOAT * (x))
|
||||
#define NS_KILOMETERS_TO_TWIPS(x) (72.0f * 39370.0f * TWIPS_CONST_FLOAT * (x))
|
||||
|
||||
#define NS_PICAS_TO_TWIPS(x) (12.0f * TWIPS_CONST_FLOAT * (x)) // 12 points per pica
|
||||
#define NS_DIDOTS_TO_TWIPS(x) ((16.0f / 15.0f) * TWIPS_CONST_FLOAT * (x)) // 15 didots per 16 points
|
||||
#define NS_CICEROS_TO_TWIPS(x) ((12.0f * 16.0f / 15.0f) * TWIPS_CONST_FLOAT * (x)) // 12 didots per cicero
|
||||
|
||||
#define NS_TWIPS_TO_INCHES(x) ((1.0f / (72.0f * TWIPS_CONST_FLOAT)) * (x))
|
||||
#define NS_TWIPS_TO_FEET(x) ((1.0f / (72.0f * 12.0f * TWIPS_CONST_FLOAT)) * (x))
|
||||
#define NS_TWIPS_TO_MILES(x) ((1.0f / (72.0f * 12.0f * 5280.0f * TWIPS_CONST_FLOAT)) * (x))
|
||||
|
||||
#define NS_TWIPS_TO_MILLIMETERS(x) ((1.0f / (72.0f * 0.03937f * TWIPS_CONST_FLOAT)) * (x))
|
||||
#define NS_TWIPS_TO_CENTIMETERS(x) ((1.0f / (72.0f * 0.3937f * TWIPS_CONST_FLOAT)) * (x))
|
||||
#define NS_TWIPS_TO_METERS(x) ((1.0f / (72.0f * 39.37f * TWIPS_CONST_FLOAT)) * (x))
|
||||
#define NS_TWIPS_TO_KILOMETERS(x) ((1.0f / (72.0f * 39370.0f * TWIPS_CONST_FLOAT)) * (x))
|
||||
|
||||
#define NS_TWIPS_TO_PICAS(x) ((1.0f / (12.0f * TWIPS_CONST_FLOAT)) * (x))
|
||||
#define NS_TWIPS_TO_DIDOTS(x) ((1.0f / ((16.0f / 15.0f) * TWIPS_CONST_FLOAT)) * (x))
|
||||
#define NS_TWIPS_TO_CICEROS(x) ((1.0f / ((12.0f * 16.0f / 15.0f) * TWIPS_CONST_FLOAT)) * (x))
|
||||
//@}
|
||||
|
||||
|
||||
/// use these for all of your rounding needs...
|
||||
//@{
|
||||
|
||||
#define NS_TO_INT_FLOOR(x) ((PRInt32)floor(x))
|
||||
#define NS_TO_INT_CEIL(x) ((PRInt32)ceil(x))
|
||||
#define NS_TO_INT_ROUND(x) ((PRInt32)floor((x) + 0.5))
|
||||
#define NS_TO_INT_ROUND_EXCLUSIVE(x) ((PRInt32)floor((x) + 0.4999999999999999))
|
||||
//@}
|
||||
#endif
|
||||
172
base/src/nsVoidArray.cpp
Normal file
172
base/src/nsVoidArray.cpp
Normal file
@@ -0,0 +1,172 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
static PRInt32 kGrowArrayBy = 8;
|
||||
|
||||
nsVoidArray::nsVoidArray()
|
||||
{
|
||||
mArray = nsnull;
|
||||
mArraySize = 0;
|
||||
mCount = 0;
|
||||
}
|
||||
|
||||
nsVoidArray& nsVoidArray::operator=(const nsVoidArray& other)
|
||||
{
|
||||
if (nsnull != mArray) {
|
||||
delete mArray;
|
||||
}
|
||||
PRInt32 otherCount = other.mCount;
|
||||
mArraySize = otherCount;
|
||||
mCount = otherCount;
|
||||
if (otherCount != 0) {
|
||||
mArray = new void*[otherCount];
|
||||
nsCRT::memcpy(mArray, other.mArray, otherCount * sizeof(void*));
|
||||
} else {
|
||||
mArray = nsnull;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsVoidArray::~nsVoidArray()
|
||||
{
|
||||
if (nsnull != mArray) {
|
||||
delete mArray;
|
||||
}
|
||||
}
|
||||
|
||||
void* nsVoidArray::ElementAt(PRInt32 aIndex) const
|
||||
{
|
||||
if (PRUint32(aIndex) >= PRUint32(mCount)) {
|
||||
return nsnull;
|
||||
}
|
||||
return mArray[aIndex];
|
||||
}
|
||||
|
||||
PRInt32 nsVoidArray::IndexOf(void* aPossibleElement) const
|
||||
{
|
||||
void** ap = mArray;
|
||||
void** end = ap + mCount;
|
||||
while (ap < end) {
|
||||
if (*ap == aPossibleElement) {
|
||||
return ap - mArray;
|
||||
}
|
||||
ap++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
PRBool nsVoidArray::InsertElementAt(void* aElement, PRInt32 aIndex)
|
||||
{
|
||||
PRInt32 oldCount = mCount;
|
||||
if (PRUint32(aIndex) > PRUint32(oldCount)) {
|
||||
// An invalid index causes the insertion to fail
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if (oldCount + 1 > mArraySize) {
|
||||
// We have to grow the array
|
||||
PRInt32 newCount = oldCount + kGrowArrayBy;
|
||||
void** newArray = new void*[newCount];
|
||||
if (mArray != nsnull && aIndex != 0)
|
||||
nsCRT::memcpy(newArray, mArray, aIndex * sizeof(void*));
|
||||
PRInt32 slide = oldCount - aIndex;
|
||||
if (0 != slide) {
|
||||
// Slide data over to make room for the insertion
|
||||
nsCRT::memcpy(newArray + aIndex + 1, mArray + aIndex,
|
||||
slide * sizeof(void*));
|
||||
}
|
||||
if (mArray != nsnull)
|
||||
delete mArray;
|
||||
mArray = newArray;
|
||||
mArraySize = newCount;
|
||||
} else {
|
||||
// The array is already large enough
|
||||
PRInt32 slide = oldCount - aIndex;
|
||||
if (0 != slide) {
|
||||
// Slide data over to make room for the insertion
|
||||
nsCRT::memmove(mArray + aIndex + 1, mArray + aIndex,
|
||||
slide * sizeof(void*));
|
||||
}
|
||||
}
|
||||
mArray[aIndex] = aElement;
|
||||
mCount++;
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsVoidArray::ReplaceElementAt(void* aElement, PRInt32 aIndex)
|
||||
{
|
||||
if (PRUint32(aIndex) >= PRUint32(mCount)) {
|
||||
// An invalid index causes the replace to fail
|
||||
return PR_FALSE;
|
||||
}
|
||||
mArray[aIndex] = aElement;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsVoidArray::RemoveElementAt(PRInt32 aIndex)
|
||||
{
|
||||
PRInt32 oldCount = mCount;
|
||||
if (PRUint32(aIndex) >= PRUint32(oldCount)) {
|
||||
// An invalid index causes the replace to fail
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// We don't need to move any elements if we're removing the
|
||||
// last element in the array
|
||||
if (aIndex < (oldCount - 1)) {
|
||||
nsCRT::memmove(mArray + aIndex, mArray + aIndex + 1,
|
||||
(oldCount - 1 - aIndex) * sizeof(void*));
|
||||
}
|
||||
|
||||
mCount--;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsVoidArray::RemoveElement(void* aElement)
|
||||
{
|
||||
void** ep = mArray;
|
||||
void** end = ep + mCount;
|
||||
while (ep < end) {
|
||||
void* e = *ep++;
|
||||
if (e == aElement) {
|
||||
ep--;
|
||||
return RemoveElementAt(PRInt32(ep - mArray));
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
void nsVoidArray::Clear()
|
||||
{
|
||||
mCount = 0;
|
||||
}
|
||||
|
||||
void nsVoidArray::Compact()
|
||||
{
|
||||
PRInt32 count = mCount;
|
||||
if (mArraySize != count) {
|
||||
void** newArray = new void*[count];
|
||||
nsCRT::memcpy(newArray, mArray, count * sizeof(void*));
|
||||
delete mArray;
|
||||
mArray = newArray;
|
||||
mArraySize = count;
|
||||
}
|
||||
}
|
||||
64
base/src/nsVoidArray.h
Normal file
64
base/src/nsVoidArray.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsVoidArray_h___
|
||||
#define nsVoidArray_h___
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
/// A basic zero-based array of void*'s that manages its own memory
|
||||
class NS_BASE nsVoidArray {
|
||||
public:
|
||||
nsVoidArray();
|
||||
~nsVoidArray();
|
||||
|
||||
nsVoidArray& operator=(const nsVoidArray& other);
|
||||
|
||||
PRInt32 Count() const {
|
||||
return mCount;
|
||||
}
|
||||
|
||||
void* ElementAt(PRInt32 aIndex) const;
|
||||
void* operator[](PRInt32 aIndex) const { return ElementAt(aIndex); }
|
||||
|
||||
PRInt32 IndexOf(void* aPossibleElement) const;
|
||||
|
||||
PRBool InsertElementAt(void* aElement, PRInt32 aIndex);
|
||||
|
||||
PRBool ReplaceElementAt(void* aElement, PRInt32 aIndex);
|
||||
|
||||
PRBool AppendElement(void* aElement) {
|
||||
return InsertElementAt(aElement, mCount);
|
||||
}
|
||||
|
||||
PRBool RemoveElement(void* aElement);
|
||||
PRBool RemoveElementAt(PRInt32 aIndex);
|
||||
void Clear();
|
||||
|
||||
void Compact();
|
||||
|
||||
protected:
|
||||
void** mArray;
|
||||
PRInt32 mArraySize;
|
||||
PRInt32 mCount;
|
||||
|
||||
private:
|
||||
/// Copy constructors are not allowed
|
||||
nsVoidArray(const nsVoidArray& other);
|
||||
};
|
||||
|
||||
#endif /* nsVoidArray_h___ */
|
||||
100
base/src/nscore.h
Normal file
100
base/src/nscore.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nscore_h___
|
||||
#define nscore_h___
|
||||
|
||||
#ifdef _WIN32
|
||||
#define NS_WIN32 1
|
||||
#endif
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
/** ucs2 datatype for 2 byte unicode characters */
|
||||
typedef PRUint16 PRUcs2;
|
||||
|
||||
/** ucs4 datatype for 4 byte unicode characters */
|
||||
typedef PRUint32 PRUcs4;
|
||||
|
||||
#ifdef NS_UCS4
|
||||
typedef PRUcs4 PRUnichar;
|
||||
#else
|
||||
typedef PRUcs2 PRUnichar;
|
||||
#endif
|
||||
|
||||
/// The preferred symbol for null.
|
||||
#define nsnull 0
|
||||
|
||||
/* Define brackets for protecting C code from C++ */
|
||||
#ifdef __cplusplus
|
||||
#define NS_BEGIN_EXTERN_C extern "C" {
|
||||
#define NS_END_EXTERN_C }
|
||||
#else
|
||||
#define NS_BEGIN_EXTERN_C
|
||||
#define NS_END_EXTERN_C
|
||||
#endif
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
/* Import/export defines */
|
||||
|
||||
#ifdef NS_WIN32
|
||||
#define NS_IMPORT _declspec(dllimport)
|
||||
#define NS_EXPORT _declspec(dllexport)
|
||||
#else
|
||||
/* XXX do something useful? */
|
||||
#define NS_IMPORT
|
||||
#define NS_EXPORT
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_BASE
|
||||
#define NS_BASE NS_EXPORT
|
||||
#else
|
||||
#define NS_BASE NS_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_DOM
|
||||
#define NS_DOM NS_EXPORT
|
||||
#else
|
||||
#define NS_DOM NS_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_WIDGET
|
||||
#define NS_WIDGET NS_EXPORT
|
||||
#else
|
||||
#define NS_WIDGET NS_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_VIEW
|
||||
#define NS_VIEW NS_EXPORT
|
||||
#else
|
||||
#define NS_VIEW NS_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_GFXNONXP
|
||||
#define NS_GFXNONXP NS_EXPORT
|
||||
#else
|
||||
#define NS_GFXNONXP NS_IMPORT
|
||||
#endif
|
||||
|
||||
#ifdef _IMPL_NS_GFX
|
||||
#define NS_GFX NS_EXPORT
|
||||
#else
|
||||
#define NS_GFX NS_IMPORT
|
||||
#endif
|
||||
|
||||
#endif /* nscore_h___ */
|
||||
40
base/src/windows/makefile.win
Normal file
40
base/src/windows/makefile.win
Normal file
@@ -0,0 +1,40 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DEFINES=-D_IMPL_NS_BASE
|
||||
LIBRARY_NAME=gmbase
|
||||
MODULE=raptor
|
||||
REQUIRES=xpcom raptor
|
||||
|
||||
CPPSRCS=nsTimer.cpp
|
||||
|
||||
CPP_OBJS=.\$(OBJDIR)\nsTimer.obj
|
||||
|
||||
LINCS=-I$(XPDIST)\public\xpcom -I$(XPDIST)\public\raptor
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
-D_IMPL_NS_BASE \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
libs:: $(OBJS)
|
||||
$(MAKE_INSTALL) $(OBJDIR)\nsTimer.obj ..\$(OBJDIR)
|
||||
364
base/src/windows/nsTimer.cpp
Normal file
364
base/src/windows/nsTimer.cpp
Normal file
@@ -0,0 +1,364 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsITimer.h"
|
||||
#include "nsITimerCallback.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prlog.h"
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
#include <limits.h>
|
||||
|
||||
static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID);
|
||||
|
||||
/*
|
||||
* Implementation of timers lifted from Windows front-end file timer.cpp
|
||||
*/
|
||||
class TimerImpl : public nsITimer {
|
||||
public:
|
||||
static TimerImpl *gTimerList;
|
||||
static UINT gWindowsTimer;
|
||||
static DWORD gNextFire;
|
||||
static DWORD gSyncHack;
|
||||
|
||||
static void ProcessTimeouts(DWORD aNow);
|
||||
static void SyncTimeoutPeriod(DWORD aTickCount);
|
||||
|
||||
public:
|
||||
TimerImpl();
|
||||
~TimerImpl();
|
||||
|
||||
virtual nsresult Init(nsTimerCallbackFunc aFunc,
|
||||
void *aClosure,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay);
|
||||
|
||||
virtual nsresult Init(nsITimerCallback *aCallback,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual void Cancel();
|
||||
void Fire(DWORD aNow);
|
||||
|
||||
virtual PRUint32 GetDelay() { return mDelay; }
|
||||
virtual void SetDelay(PRUint32 aDelay) {};
|
||||
|
||||
private:
|
||||
nsresult Init(PRUint32 aDelay);
|
||||
|
||||
PRUint32 mDelay;
|
||||
nsTimerCallbackFunc mFunc;
|
||||
void *mClosure;
|
||||
nsITimerCallback *mCallback;
|
||||
DWORD mFireTime;
|
||||
// PRBool mRepeat;
|
||||
TimerImpl *mNext;
|
||||
};
|
||||
|
||||
TimerImpl *TimerImpl::gTimerList = NULL;
|
||||
UINT TimerImpl::gWindowsTimer = 0;
|
||||
DWORD TimerImpl::gNextFire = (DWORD)-1;
|
||||
DWORD TimerImpl::gSyncHack = 0;
|
||||
|
||||
void CALLBACK FireTimeout(HWND aWindow,
|
||||
UINT aMessage,
|
||||
UINT aTimerID,
|
||||
DWORD aTime)
|
||||
{
|
||||
static BOOL bCanEnter = TRUE;
|
||||
|
||||
// Don't allow old timer messages in here.
|
||||
if(aMessage != WM_TIMER) {
|
||||
PR_ASSERT(0);
|
||||
return;
|
||||
}
|
||||
|
||||
if(aTimerID != TimerImpl::gWindowsTimer) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Block only one entry into this function, or else.
|
||||
if(bCanEnter) {
|
||||
bCanEnter = FALSE;
|
||||
// see if we need to fork off any timeout functions
|
||||
if(TimerImpl::gTimerList) {
|
||||
TimerImpl::ProcessTimeouts(aTime);
|
||||
}
|
||||
bCanEnter = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
// Function to correctly have the timer be set.
|
||||
void
|
||||
TimerImpl::SyncTimeoutPeriod(DWORD aTickCount)
|
||||
{
|
||||
// May want us to set tick count ourselves.
|
||||
if(aTickCount == 0) {
|
||||
if(gSyncHack == 0) {
|
||||
aTickCount = ::GetTickCount();
|
||||
}
|
||||
else {
|
||||
aTickCount = gSyncHack;
|
||||
}
|
||||
}
|
||||
|
||||
// If there's no list, we should clear the timer.
|
||||
if(!gTimerList) {
|
||||
if(gWindowsTimer) {
|
||||
::KillTimer(NULL, gWindowsTimer);
|
||||
gWindowsTimer = 0;
|
||||
gNextFire = (DWORD)-1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// See if we need to clear the current timer.
|
||||
// Curcumstances are that if the timer will not
|
||||
// fire on time for the next timeout.
|
||||
BOOL bSetTimer = FALSE;
|
||||
TimerImpl *pTimeout = gTimerList;
|
||||
if(gWindowsTimer) {
|
||||
if(pTimeout->mFireTime != gNextFire) {
|
||||
::KillTimer(NULL, gWindowsTimer);
|
||||
gWindowsTimer = 0;
|
||||
gNextFire = (DWORD)-1;
|
||||
|
||||
// Set the timer.
|
||||
bSetTimer = TRUE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// No timer set, attempt.
|
||||
bSetTimer = TRUE;
|
||||
}
|
||||
|
||||
if(bSetTimer) {
|
||||
DWORD dwFireWhen = pTimeout->mFireTime > aTickCount ?
|
||||
pTimeout->mFireTime - aTickCount : 0;
|
||||
if(dwFireWhen > UINT_MAX) {
|
||||
dwFireWhen = UINT_MAX;
|
||||
}
|
||||
UINT uFireWhen = (UINT)dwFireWhen;
|
||||
|
||||
PR_ASSERT(gWindowsTimer == 0);
|
||||
gWindowsTimer = ::SetTimer(NULL, 0, uFireWhen, (TIMERPROC)FireTimeout);
|
||||
|
||||
if(gWindowsTimer) {
|
||||
// Set the fire time.
|
||||
gNextFire = pTimeout->mFireTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Walk down the timeout list and launch anyone appropriate
|
||||
void
|
||||
TimerImpl::ProcessTimeouts(DWORD aNow)
|
||||
{
|
||||
TimerImpl *p = gTimerList;
|
||||
if(aNow == 0) {
|
||||
aNow = ::GetTickCount();
|
||||
}
|
||||
|
||||
BOOL bCalledSync = FALSE;
|
||||
|
||||
// Set the hack, such that when FE_ClearTimeout
|
||||
// calls SyncTimeoutPeriod, that GetTickCount()
|
||||
// overhead is not incurred.
|
||||
gSyncHack = aNow;
|
||||
|
||||
// loop over all entries
|
||||
while(p) {
|
||||
// send it
|
||||
if(p->mFireTime < aNow) {
|
||||
p->Fire(aNow);
|
||||
|
||||
// Clear the timer.
|
||||
// Period synced.
|
||||
p->Cancel();
|
||||
bCalledSync = TRUE;
|
||||
|
||||
// Reset the loop (can't look at p->pNext now, and called
|
||||
// code may have added/cleared timers).
|
||||
// (could do this by going recursive and returning).
|
||||
p = gTimerList;
|
||||
} else {
|
||||
// Make sure we fire an timer.
|
||||
// Also, we need to check to see if things are backing up (they
|
||||
// may be asking to be fired long before we ever get to them,
|
||||
// and we don't want to pass in negative values to the real
|
||||
// timer code, or it takes days to fire....
|
||||
if(bCalledSync == FALSE) {
|
||||
SyncTimeoutPeriod(aNow);
|
||||
bCalledSync = TRUE;
|
||||
}
|
||||
// Get next timer.
|
||||
p = p->mNext;
|
||||
}
|
||||
}
|
||||
gSyncHack = 0;
|
||||
}
|
||||
|
||||
|
||||
TimerImpl::TimerImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mFunc = NULL;
|
||||
mCallback = NULL;
|
||||
mNext = NULL;
|
||||
}
|
||||
|
||||
TimerImpl::~TimerImpl()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(nsTimerCallbackFunc aFunc,
|
||||
void *aClosure,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)
|
||||
{
|
||||
mFunc = aFunc;
|
||||
mClosure = aClosure;
|
||||
// mRepeat = aRepeat;
|
||||
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(nsITimerCallback *aCallback,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)
|
||||
{
|
||||
mCallback = aCallback;
|
||||
// mRepeat = aRepeat;
|
||||
|
||||
return Init(aDelay);
|
||||
}
|
||||
|
||||
nsresult
|
||||
TimerImpl::Init(PRUint32 aDelay)
|
||||
{
|
||||
DWORD dwNow = ::GetTickCount();
|
||||
|
||||
mDelay = aDelay;
|
||||
mFireTime = (DWORD) aDelay + dwNow;
|
||||
mNext = NULL;
|
||||
|
||||
// add it to the list
|
||||
if(!gTimerList) {
|
||||
// no list add it
|
||||
gTimerList = this;
|
||||
}
|
||||
else {
|
||||
|
||||
// is it before everything else on the list?
|
||||
if(mFireTime < gTimerList->mFireTime) {
|
||||
|
||||
mNext = gTimerList;
|
||||
gTimerList = this;
|
||||
|
||||
} else {
|
||||
|
||||
TimerImpl * pPrev = gTimerList;
|
||||
TimerImpl * pCurrent = gTimerList;
|
||||
|
||||
while(pCurrent && (pCurrent->mFireTime <= mFireTime)) {
|
||||
pPrev = pCurrent;
|
||||
pCurrent = pCurrent->mNext;
|
||||
}
|
||||
|
||||
PR_ASSERT(pPrev);
|
||||
|
||||
// insert it after pPrev (this could be at the end of the list)
|
||||
mNext = pPrev->mNext;
|
||||
pPrev->mNext = this;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
NS_ADDREF(this);
|
||||
|
||||
// Sync the timer fire period.
|
||||
SyncTimeoutPeriod(dwNow);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID)
|
||||
|
||||
void
|
||||
TimerImpl::Fire(DWORD aNow)
|
||||
{
|
||||
if (mFunc != NULL) {
|
||||
(*mFunc)(this, mClosure);
|
||||
}
|
||||
else if (mCallback != NULL) {
|
||||
mCallback->Notify(this);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TimerImpl::Cancel()
|
||||
{
|
||||
TimerImpl *me = this;
|
||||
|
||||
if(gTimerList == this) {
|
||||
|
||||
// first element in the list lossage
|
||||
gTimerList = mNext;
|
||||
|
||||
} else {
|
||||
|
||||
// walk until no next pointer
|
||||
for(TimerImpl * p = gTimerList; p && p->mNext && (p->mNext != this); p = p->mNext)
|
||||
;
|
||||
|
||||
// if we found something valid pull it out of the list
|
||||
if(p && p->mNext && p->mNext == this) {
|
||||
p->mNext = mNext;
|
||||
|
||||
} else {
|
||||
// get out before we delete something that looks bogus
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// if we got here it must have been a valid element so trash it
|
||||
NS_RELEASE(me);
|
||||
|
||||
// If there's now no be sure to clear the timer.
|
||||
SyncTimeoutPeriod(0);
|
||||
}
|
||||
|
||||
NS_BASE nsresult NS_NewTimer(nsITimer** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
TimerImpl *timer = new TimerImpl();
|
||||
if (nsnull == timer) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
104
base/tests/CvtURL.cpp
Normal file
104
base/tests/CvtURL.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "nsIUnicharInputStream.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsString.h"
|
||||
#include "prprf.h"
|
||||
#include "prtime.h"
|
||||
|
||||
static nsCharSetID ConvertCharacterSetName(const char* aName)
|
||||
{
|
||||
if (nsCRT::strcasecmp(aName, "iso-latin-1") == 0) {
|
||||
return eCharSetID_IsoLatin1;
|
||||
}
|
||||
return (nsCharSetID) -1;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (3 != argc) {
|
||||
printf("usage: CvtURL url character-set-name\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
char* characterSetName = argv[2];
|
||||
nsCharSetID cset = ConvertCharacterSetName(characterSetName);
|
||||
if (PRInt32(cset) < 0) {
|
||||
printf("illegal character set name: '%s'\n", characterSetName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Create url object
|
||||
char* urlName = argv[1];
|
||||
nsIURL* url;
|
||||
nsresult rv = NS_NewURL(&url, urlName);
|
||||
if (NS_OK != rv) {
|
||||
printf("invalid URL: '%s'\n", urlName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Get an input stream from the url
|
||||
PRInt32 ec;
|
||||
nsIInputStream* in = url->Open(&ec);
|
||||
if (nsnull == in) {
|
||||
printf("open of url('%s') failed: error=%x\n", urlName, ec);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Translate the input using the argument character set id into unicode
|
||||
nsIUnicharInputStream* uin;
|
||||
rv = NS_NewConverterStream(&uin, nsnull, in, 0, cset);
|
||||
if (NS_OK != rv) {
|
||||
printf("can't create converter input stream: %d\n", rv);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Read the input and write some output
|
||||
PRTime start = PR_Now();
|
||||
PRInt32 count = 0;
|
||||
for (;;) {
|
||||
PRUnichar buf[1000];
|
||||
PRInt32 nb = uin->Read(&ec, buf, 0, 1000);
|
||||
if (nb <= 0) {
|
||||
if (nb < 0) {
|
||||
printf("i/o error: %d\n", ec);
|
||||
}
|
||||
break;
|
||||
}
|
||||
count += nb;
|
||||
}
|
||||
PRTime end = PR_Now();
|
||||
PRTime conversion, ustoms;
|
||||
LL_I2L(ustoms, 1000);
|
||||
LL_SUB(conversion, end, start);
|
||||
LL_DIV(conversion, conversion, ustoms);
|
||||
char buf[500];
|
||||
PR_snprintf(buf, sizeof(buf),
|
||||
"converting and discarding %d bytes took %lldms",
|
||||
count, conversion);
|
||||
puts(buf);
|
||||
|
||||
// Release the objects
|
||||
in->Release();
|
||||
uin->Release();
|
||||
url->Release();
|
||||
|
||||
return 0;
|
||||
}
|
||||
55
base/tests/Makefile
Normal file
55
base/tests/Makefile
Normal file
@@ -0,0 +1,55 @@
|
||||
#!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=../../..
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
CPPSRCS = \
|
||||
TestAtoms.cpp \
|
||||
TestCRT.cpp \
|
||||
$(NULL)
|
||||
|
||||
INCLUDES+=-I../src -I$(PUBLIC)/xpcom
|
||||
|
||||
OBJS = $(CPPSRCS:.cpp=.o)
|
||||
|
||||
EX_LIBS = \
|
||||
$(DIST)/lib/libraptorbase.a \
|
||||
$(DIST)/lib/libxpcom.a \
|
||||
$(DIST)/lib/libplc21.a \
|
||||
$(DIST)/lib/libplds21.a \
|
||||
$(DIST)/lib/libnspr21.a \
|
||||
$(NULL)
|
||||
|
||||
PROGS = $(addprefix $(OBJDIR)/, $(CPPSRCS:.cpp=))
|
||||
|
||||
TARGETS = $(PROGS)
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
||||
$(OBJDIR)/%.o: %.cpp
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CCC) -o $@ $(CFLAGS) -c $*.cpp
|
||||
|
||||
$(PROGS):$(OBJDIR)/%: $(OBJDIR)/%.o $(EX_LIBS)
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CCC) -o $@ $@.o $(LDFLAGS) $(EX_LIBS) $(OS_LIBS)
|
||||
|
||||
install:: $(TARGETS)
|
||||
$(INSTALL) $(TARGETS) $(DIST)/bin
|
||||
|
||||
108
base/tests/TestAtoms.cpp
Normal file
108
base/tests/TestAtoms.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsIAtom.h"
|
||||
#include "nsString.h"
|
||||
#include "prprf.h"
|
||||
#include "prtime.h"
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C" int _CrtSetDbgFlag(int);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
FILE* fp = fopen("words.txt", "r");
|
||||
if (nsnull == fp) {
|
||||
printf("can't open words.txt\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
PRInt32 count = 0;
|
||||
PRUnichar** strings = new PRUnichar*[60000];
|
||||
nsIAtom** ids = new nsIAtom*[60000];
|
||||
nsAutoString s1, s2;
|
||||
PRTime start = PR_Now();
|
||||
for (PRInt32 i = 0; i < 60000; i++) {
|
||||
char buf[1000];
|
||||
char* s = fgets(buf, sizeof(buf), fp);
|
||||
if (nsnull == s) {
|
||||
break;
|
||||
}
|
||||
nsAutoString sb(buf);
|
||||
strings[count++] = sb.ToNewUnicode();
|
||||
sb.ToUpperCase();
|
||||
strings[count++] = sb.ToNewUnicode();
|
||||
}
|
||||
PRTime end0 = PR_Now();
|
||||
|
||||
// Find and create idents
|
||||
for (i = 0; i < count; i++) {
|
||||
ids[i] = NS_NewAtom(strings[i]);
|
||||
}
|
||||
PRUnichar qqs[1]; qqs[0] = 0;
|
||||
nsIAtom* qq = NS_NewAtom(qqs);
|
||||
PRTime end1 = PR_Now();
|
||||
|
||||
// Now make sure we can find all the idents we just made
|
||||
for (i = 0; i < count; i++) {
|
||||
nsIAtom* id = NS_NewAtom(ids[i]->GetUnicode());
|
||||
if (id != ids[i]) {
|
||||
id->ToString(s1);
|
||||
ids[i]->ToString(s2);
|
||||
printf("find failed: id='%s' ids[%d]='%s'\n",
|
||||
s1.ToNewCString(), i, s2.ToNewCString());
|
||||
return -1;
|
||||
}
|
||||
NS_RELEASE(id);
|
||||
}
|
||||
PRTime end2 = PR_Now();
|
||||
|
||||
// Destroy all the atoms we just made
|
||||
NS_RELEASE(qq);
|
||||
for (i = 0; i < count; i++) {
|
||||
NS_RELEASE(ids[i]);
|
||||
}
|
||||
|
||||
// Print out timings
|
||||
PRTime end3 = PR_Now();
|
||||
PRTime creates, finds, lookups, dtor, ustoms;
|
||||
LL_I2L(ustoms, 1000);
|
||||
LL_SUB(creates, end0, start);
|
||||
LL_DIV(creates, creates, ustoms);
|
||||
LL_SUB(finds, end1, end0);
|
||||
LL_DIV(finds, finds, ustoms);
|
||||
LL_SUB(lookups, end2, end1);
|
||||
LL_DIV(lookups, lookups, ustoms);
|
||||
LL_SUB(dtor, end3, end2);
|
||||
char buf[500];
|
||||
PR_snprintf(buf, sizeof(buf), "making %d ident strings took %lldms",
|
||||
count, creates);
|
||||
puts(buf);
|
||||
PR_snprintf(buf, sizeof(buf), "%d new idents took %lldms",
|
||||
count, finds);
|
||||
puts(buf);
|
||||
PR_snprintf(buf, sizeof(buf), "%d ident lookups took %lldms",
|
||||
count, lookups);
|
||||
puts(buf);
|
||||
PR_snprintf(buf, sizeof(buf), "dtor took %lldusec", dtor);
|
||||
puts(buf);
|
||||
|
||||
printf("%d live atoms\n", NS_GetNumberOfAtoms());
|
||||
NS_POSTCONDITION(0 == NS_GetNumberOfAtoms(), "dangling atoms");
|
||||
|
||||
return 0;
|
||||
}
|
||||
89
base/tests/TestCRT.cpp
Normal file
89
base/tests/TestCRT.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nsCRT.h"
|
||||
#include "nsString.h"
|
||||
#include "plstr.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
// Verify that nsCRT versions of string comparison routines get the
|
||||
// same answers as the native non-unicode versions. We only pass in
|
||||
// iso-latin-1 strings, so the comparision must be valid.
|
||||
static void Check(const char* s1, const char* s2, PRIntn n)
|
||||
{
|
||||
PRIntn clib = PL_strcmp(s1, s2);
|
||||
PRIntn clib_n = PL_strncmp(s1, s2, n);
|
||||
PRIntn clib_case = PL_strcasecmp(s1, s2);
|
||||
PRIntn clib_case_n = PL_strncasecmp(s1, s2, n);
|
||||
|
||||
nsAutoString t1(s1), t2(s2);
|
||||
PRUnichar* us1 = t1.GetUnicode();
|
||||
PRUnichar* us2 = t2.GetUnicode();
|
||||
|
||||
PRIntn u = nsCRT::strcmp(us1, s2);
|
||||
PRIntn u_n = nsCRT::strncmp(us1, s2, n);
|
||||
PRIntn u_case = nsCRT::strcasecmp(us1, s2);
|
||||
PRIntn u_case_n = nsCRT::strncasecmp(us1, s2, n);
|
||||
|
||||
PRIntn u2 = nsCRT::strcmp(us1, us2);
|
||||
PRIntn u2_n = nsCRT::strncmp(us1, us2, n);
|
||||
PRIntn u2_case = nsCRT::strcasecmp(us1, us2);
|
||||
PRIntn u2_case_n = nsCRT::strncasecmp(us1, us2, n);
|
||||
|
||||
NS_ASSERTION(clib == u, "strcmp");
|
||||
NS_ASSERTION(clib_n == u_n, "strncmp");
|
||||
NS_ASSERTION(clib_case == u_case, "strcasecmp");
|
||||
NS_ASSERTION(clib_case_n == u_case_n, "strncasecmp");
|
||||
|
||||
NS_ASSERTION(clib == u2, "strcmp");
|
||||
NS_ASSERTION(clib_n == u2_n, "strncmp");
|
||||
NS_ASSERTION(clib_case == u2_case, "strcasecmp");
|
||||
NS_ASSERTION(clib_case_n == u2_case_n, "strncasecmp");
|
||||
}
|
||||
|
||||
struct Test {
|
||||
const char* s1;
|
||||
const char* s2;
|
||||
PRIntn n;
|
||||
};
|
||||
|
||||
static Test tests[] = {
|
||||
{ "foo", "foo", 3 },
|
||||
{ "foo", "fo", 3 },
|
||||
|
||||
{ "foo", "bar", 3 },
|
||||
{ "foo", "ba", 3 },
|
||||
|
||||
{ "foo", "zap", 3 },
|
||||
{ "foo", "za", 3 },
|
||||
|
||||
{ "bar", "foo", 3 },
|
||||
{ "bar", "fo", 3 },
|
||||
|
||||
{ "bar", "foo", 3 },
|
||||
{ "bar", "fo", 3 },
|
||||
};
|
||||
#define NUM_TESTS (sizeof(tests) / sizeof(tests[0]))
|
||||
|
||||
void main()
|
||||
{
|
||||
Test* tp = tests;
|
||||
for (PRIntn i = 0; i < NUM_TESTS; i++, tp++) {
|
||||
Check(tp->s1, tp->s2, tp->n);
|
||||
}
|
||||
}
|
||||
200
base/tests/TimerTest.cpp
Normal file
200
base/tests/TimerTest.cpp
Normal file
@@ -0,0 +1,200 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsITimerCallback.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "resources.h"
|
||||
|
||||
static char* class1Name = "TimerTest";
|
||||
|
||||
static HANDLE gInstance, gPrevInstance;
|
||||
static nsVoidArray *gTimeouts = NULL;
|
||||
|
||||
static void CreateRepeat(PRUint32 aDelay);
|
||||
|
||||
void
|
||||
MyCallback (nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
printf("Timer executed with delay %d\n", (int)aClosure);
|
||||
|
||||
if (gTimeouts->RemoveElement(aTimer) == PR_TRUE) {
|
||||
NS_RELEASE(aTimer);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
MyRepeatCallback (nsITimer *aTimer, void *aClosure)
|
||||
{
|
||||
printf("Timer executed with delay %d\n", (int)aClosure);
|
||||
|
||||
if (gTimeouts->RemoveElement(aTimer) == PR_TRUE) {
|
||||
NS_RELEASE(aTimer);
|
||||
}
|
||||
|
||||
CreateRepeat((PRUint32)aClosure);
|
||||
}
|
||||
|
||||
static void
|
||||
CreateOneShot(PRUint32 aDelay)
|
||||
{
|
||||
nsITimer *timer;
|
||||
|
||||
NS_NewTimer(&timer);
|
||||
timer->Init(MyCallback, (void *)aDelay, aDelay);
|
||||
|
||||
gTimeouts->AppendElement(timer);
|
||||
}
|
||||
|
||||
static void
|
||||
CreateRepeat(PRUint32 aDelay)
|
||||
{
|
||||
nsITimer *timer;
|
||||
|
||||
NS_NewTimer(&timer);
|
||||
timer->Init(MyRepeatCallback, (void *)aDelay, aDelay);
|
||||
|
||||
gTimeouts->AppendElement(timer);
|
||||
}
|
||||
|
||||
static void
|
||||
CancelAll()
|
||||
{
|
||||
int i, count = gTimeouts->Count();
|
||||
|
||||
for (i=0; i < count; i++) {
|
||||
nsITimer *timer = (nsITimer *)gTimeouts->ElementAt(i);
|
||||
|
||||
if (timer != NULL) {
|
||||
timer->Cancel();
|
||||
NS_RELEASE(timer);
|
||||
}
|
||||
}
|
||||
|
||||
gTimeouts->Clear();
|
||||
}
|
||||
|
||||
long PASCAL
|
||||
WndProc(HWND hWnd, UINT msg, WPARAM param, LPARAM lparam)
|
||||
{
|
||||
HMENU hMenu;
|
||||
|
||||
switch (msg) {
|
||||
case WM_COMMAND:
|
||||
hMenu = GetMenu(hWnd);
|
||||
|
||||
switch (LOWORD(param)) {
|
||||
case TIMER_EXIT:
|
||||
::DestroyWindow(hWnd);
|
||||
exit(0);
|
||||
|
||||
case TIMER_1SECOND:
|
||||
CreateOneShot(1000);
|
||||
break;
|
||||
case TIMER_5SECOND:
|
||||
CreateOneShot(5000);
|
||||
break;
|
||||
case TIMER_10SECOND:
|
||||
CreateOneShot(10000);
|
||||
break;
|
||||
|
||||
case TIMER_1REPEAT:
|
||||
CreateRepeat(1000);
|
||||
break;
|
||||
case TIMER_5REPEAT:
|
||||
CreateRepeat(5000);
|
||||
break;
|
||||
case TIMER_10REPEAT:
|
||||
CreateRepeat(10000);
|
||||
break;
|
||||
|
||||
case TIMER_CANCEL:
|
||||
CancelAll();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd, msg, param, lparam);
|
||||
}
|
||||
|
||||
static HWND CreateTopLevel(const char* clazz, const char* title,
|
||||
int aWidth, int aHeight)
|
||||
{
|
||||
// Create a simple top level window
|
||||
HWND window = ::CreateWindowEx(WS_EX_CLIENTEDGE,
|
||||
clazz, title,
|
||||
WS_OVERLAPPEDWINDOW|WS_CLIPCHILDREN,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
aWidth, aHeight,
|
||||
HWND_DESKTOP,
|
||||
NULL,
|
||||
gInstance,
|
||||
NULL);
|
||||
|
||||
::ShowWindow(window, SW_SHOW);
|
||||
::UpdateWindow(window);
|
||||
return window;
|
||||
}
|
||||
|
||||
int PASCAL
|
||||
WinMain(HANDLE instance, HANDLE prevInstance, LPSTR cmdParam, int nCmdShow)
|
||||
{
|
||||
gInstance = instance;
|
||||
|
||||
if (!prevInstance) {
|
||||
WNDCLASS wndClass;
|
||||
wndClass.style = 0;
|
||||
wndClass.lpfnWndProc = WndProc;
|
||||
wndClass.cbClsExtra = 0;
|
||||
wndClass.cbWndExtra = 0;
|
||||
wndClass.hInstance = gInstance;
|
||||
wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wndClass.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
|
||||
wndClass.lpszMenuName = class1Name;
|
||||
wndClass.lpszClassName = class1Name;
|
||||
RegisterClass(&wndClass);
|
||||
}
|
||||
|
||||
// Create our first top level window
|
||||
HWND window = CreateTopLevel(class1Name, "Raptor HTML Viewer", 620, 400);
|
||||
|
||||
gTimeouts = new nsVoidArray();
|
||||
|
||||
// Process messages
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
return msg.wParam;
|
||||
}
|
||||
|
||||
void main(int argc, char **argv)
|
||||
{
|
||||
WinMain(GetModuleHandle(NULL), NULL, 0, SW_SHOW);
|
||||
}
|
||||
75
base/tests/makefile.win
Normal file
75
base/tests/makefile.win
Normal file
@@ -0,0 +1,75 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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=..\..
|
||||
|
||||
MAKE_OBJ_TYPE = EXE
|
||||
PROG0 = .\$(OBJDIR)\TimerTest.exe
|
||||
PROG1 = .\$(OBJDIR)\TestAtoms.exe
|
||||
PROG2 = .\$(OBJDIR)\CvtURL.exe
|
||||
PROG3 = .\$(OBJDIR)\TestCRT.exe
|
||||
RESFILE = timer.res
|
||||
PROGRAMS = $(PROG0) $(PROG1) $(PROG2) $(PROG3)
|
||||
|
||||
LINCS=-I..\src -I$(PUBLIC)\xpcom
|
||||
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(DIST)\lib\netlib.lib \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\libplc21.lib \
|
||||
$(RESFILE)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(PROGRAMS)
|
||||
$(MAKE_INSTALL) $(PROG0) $(DIST)\bin
|
||||
$(MAKE_INSTALL) $(PROG1) $(DIST)\bin
|
||||
$(MAKE_INSTALL) $(PROG2) $(DIST)\bin
|
||||
$(MAKE_INSTALL) $(PROG3) $(DIST)\bin
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\bin\TimerTest.exe
|
||||
rm -f $(DIST)\bin\TestAtoms.exe
|
||||
rm -f $(DIST)\bin\CvtURL.exe
|
||||
rm -f $(DIST)\bin\TestCRT.exe
|
||||
|
||||
# Move this into config/obj.inc when it's allowed
|
||||
.cpp{.\$(OBJDIR)\}.exe:
|
||||
$(CC) @<<$(CFGFILE)
|
||||
$(CFLAGS)
|
||||
$(LCFLAGS)
|
||||
$(LINCS)
|
||||
$(LINCS_1)
|
||||
$(INCS)
|
||||
$(LLIBS)
|
||||
$(OS_LIBS)
|
||||
-Fd$(PBDFILE)
|
||||
-Fe.\$(OBJDIR)\
|
||||
-Fo.\$(OBJDIR)\
|
||||
$(CURDIR)$(*B).cpp
|
||||
<<KEEP
|
||||
|
||||
$(PROG0): $(OBJDIR) TimerTest.cpp $(RESFILE)
|
||||
|
||||
$(PROG1): $(OBJDIR) TestAtoms.cpp
|
||||
|
||||
$(PROG2): $(OBJDIR) CvtURL.cpp
|
||||
|
||||
$(PROG2): $(OBJDIR) TestCRT.cpp
|
||||
|
||||
32
base/tests/resources.h
Normal file
32
base/tests/resources.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef resources_h___
|
||||
#define resources_h___
|
||||
|
||||
#define TIMER_1SECOND 40000
|
||||
#define TIMER_5SECOND 40001
|
||||
#define TIMER_10SECOND 40002
|
||||
|
||||
#define TIMER_1REPEAT 40003
|
||||
#define TIMER_5REPEAT 40004
|
||||
#define TIMER_10REPEAT 40005
|
||||
|
||||
#define TIMER_CANCEL 40006
|
||||
#define TIMER_EXIT 40010
|
||||
|
||||
#endif /* resources_h___ */
|
||||
38
base/tests/timer.rc
Normal file
38
base/tests/timer.rc
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
#include "resources.h"
|
||||
|
||||
TIMERTEST MENU DISCARDABLE
|
||||
{
|
||||
POPUP "Debug"
|
||||
{
|
||||
POPUP "One Shot"
|
||||
{
|
||||
MENUITEM "1 second", TIMER_1SECOND
|
||||
MENUITEM "5 second", TIMER_5SECOND
|
||||
MENUITEM "10 second", TIMER_10SECOND
|
||||
}
|
||||
POPUP "Repeated"
|
||||
{
|
||||
MENUITEM "1 second", TIMER_1REPEAT
|
||||
MENUITEM "5 second", TIMER_5REPEAT
|
||||
MENUITEM "10 second", TIMER_10REPEAT
|
||||
}
|
||||
MENUITEM "Cancel All", TIMER_CANCEL
|
||||
MENUITEM "Exit", TIMER_EXIT
|
||||
}
|
||||
}
|
||||
116
content/base/public/nsIContent.h
Normal file
116
content/base/public/nsIContent.h
Normal file
@@ -0,0 +1,116 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIContent_h___
|
||||
#define nsIContent_h___
|
||||
|
||||
#include <stdio.h>
|
||||
#include "nslayout.h"
|
||||
#include "nsISupports.h"
|
||||
class nsIAtom;
|
||||
class nsIContentDelegate;
|
||||
class nsIDocument;
|
||||
class nsIPresContext;
|
||||
class nsISizeofHandler;
|
||||
class nsString;
|
||||
class nsString;
|
||||
class nsVoidArray;
|
||||
|
||||
// IID for the nsIContent interface
|
||||
#define NS_ICONTENT_IID \
|
||||
{ 0x78030220, 0x9447, 0x11d1, \
|
||||
{0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
/**
|
||||
* Content attribute states
|
||||
*/
|
||||
enum nsContentAttr {
|
||||
// Attribute does not exist on the piece of content
|
||||
eContentAttr_NotThere,
|
||||
|
||||
// Attribute exists, but has no value, e.g. "BORDER" in <TABLE BORDER>
|
||||
eContentAttr_NoValue,
|
||||
|
||||
// Attribute exists and has a value. However, value may be the
|
||||
// empty string. e.g. <TABLE BORDER="1"> or <TABLE BORDER="">
|
||||
eContentAttr_HasValue,
|
||||
};
|
||||
|
||||
// A node of content in a documents content model. This interface
|
||||
// is supported by all content objects.
|
||||
class nsIContent : public nsISupports
|
||||
{
|
||||
public:
|
||||
virtual nsIDocument* GetDocument() const = 0;
|
||||
virtual void SetDocument(nsIDocument* aDocument) = 0;
|
||||
|
||||
virtual nsIContent* GetParent() const = 0;
|
||||
virtual void SetParent(nsIContent* aParent) = 0;
|
||||
|
||||
virtual PRBool CanContainChildren() const = 0;
|
||||
virtual PRInt32 ChildCount() const = 0;
|
||||
virtual nsIContent* ChildAt(PRInt32 aIndex) const = 0;
|
||||
virtual PRInt32 IndexOf(nsIContent* aPossibleChild) const = 0;
|
||||
virtual PRBool InsertChildAt(nsIContent* aKid, PRInt32 aIndex) = 0;
|
||||
virtual PRBool ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex) = 0;
|
||||
virtual PRBool AppendChild(nsIContent* aKid) = 0;
|
||||
virtual PRBool RemoveChildAt(PRInt32 aIndex) = 0;
|
||||
|
||||
virtual nsIAtom* GetTag() const = 0;
|
||||
|
||||
/**
|
||||
* Set attribute values. All attribute values are assumed to have a
|
||||
* canonical String representation that can be used for these
|
||||
* methods. The setAttribute method is assumed to perform a translation
|
||||
* of the canonical form into the underlying content specific
|
||||
* form.
|
||||
*
|
||||
* aValue may legitimately be the empty string.
|
||||
*/
|
||||
virtual void SetAttribute(const nsString& aName, const nsString& aValue) = 0;
|
||||
|
||||
/**
|
||||
* Get the current value of the attribute. This returns a form that is
|
||||
* suitable for passing back into setAttribute.
|
||||
*
|
||||
* <UL>
|
||||
*
|
||||
* <LI>If the attribute is not set and has no default value, return
|
||||
* eContentAttr_NotThere.
|
||||
*
|
||||
* <LI>If the attribute exists, but has no value, return
|
||||
* eContentAttr_NoValue.
|
||||
*
|
||||
* <LI>If the attribute has a value, empty or otherwise, set ret to
|
||||
* be the value, and return eContentAttr_HasValue.
|
||||
*
|
||||
* </UL> */
|
||||
virtual nsContentAttr GetAttribute(const nsString& aName,
|
||||
nsString& aResult) const = 0;
|
||||
|
||||
virtual nsIContentDelegate* GetDelegate(nsIPresContext* aCX) = 0;
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0;
|
||||
|
||||
/**
|
||||
* Return the number of bytes consumed by this node of content and
|
||||
* anything that it can reach.
|
||||
*/
|
||||
virtual PRUint32 SizeOf(nsISizeofHandler* aHandler) const = 0;
|
||||
};
|
||||
|
||||
#endif /* nsIContent_h___ */
|
||||
163
content/base/public/nsIDocument.h
Normal file
163
content/base/public/nsIDocument.h
Normal file
@@ -0,0 +1,163 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIDocument_h___
|
||||
#define nsIDocument_h___
|
||||
|
||||
#include "nslayout.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIUnicharInputStream.h"
|
||||
class nsIArena;
|
||||
class nsIContent;
|
||||
class nsIDocumentContainer;
|
||||
class nsIDocumentObserver;
|
||||
class nsIPresContext;
|
||||
class nsIPresShell;
|
||||
class nsISubContent;
|
||||
class nsIStyleSet;
|
||||
class nsIStyleSheet;
|
||||
class nsIURL;
|
||||
class nsIViewManager;
|
||||
class nsString;
|
||||
|
||||
// IID for the nsIDocument interface
|
||||
#define NS_IDOCUMENT_IID \
|
||||
{ 0x94c6ceb0, 0x9447, 0x11d1, \
|
||||
{0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Document interface
|
||||
class nsIDocument : public nsISupports {
|
||||
public:
|
||||
// All documents have a memory arena associated with them which is
|
||||
// used for memory allocation during document creation. This call
|
||||
// returns the arena associated with this document.
|
||||
virtual nsIArena* GetArena() = 0;
|
||||
|
||||
virtual void LoadURL(nsIURL* aURL) = 0;
|
||||
|
||||
virtual void StartDocumentLoad() = 0;
|
||||
virtual void PauseDocumentLoad() = 0;
|
||||
virtual void StopDocumentLoad() = 0;
|
||||
virtual void WaitForDocumentLoad() = 0;
|
||||
virtual PRBool IsDocumentLoaded() = 0;
|
||||
|
||||
/**
|
||||
* Return the title of the document. May return null.
|
||||
*/
|
||||
virtual const nsString* GetDocumentTitle() const = 0;
|
||||
|
||||
/**
|
||||
* Return the URL for the document. May return null.
|
||||
*/
|
||||
virtual nsIURL* GetDocumentURL() const = 0;
|
||||
|
||||
/**
|
||||
* Return a standard name for the document's character set. This will
|
||||
* trigger a startDocumentLoad if necessary to answer the question.
|
||||
*/
|
||||
virtual nsCharSetID GetDocumentCharacterSet() const = 0;
|
||||
virtual void SetDocumentCharacterSet(nsCharSetID aCharSetID) = 0;
|
||||
|
||||
/**
|
||||
* Create a new presentation shell that will use aContext for
|
||||
* it's presentation context (presentation context's <b>must not</b> be
|
||||
* shared among multiple presentation shell's).
|
||||
*/
|
||||
virtual nsIPresShell* CreateShell(nsIPresContext* aContext,
|
||||
nsIViewManager* aViewManager,
|
||||
nsIStyleSet* aStyleSet) = 0;
|
||||
virtual PRBool DeleteShell(nsIPresShell* aShell) = 0;
|
||||
virtual PRInt32 GetNumberOfShells() = 0;
|
||||
virtual nsIPresShell* GetShellAt(PRInt32 aIndex) = 0;
|
||||
|
||||
/**
|
||||
* Return the parent document of this document. Will return null
|
||||
* unless this document is within a compound document and has a parent.
|
||||
*/
|
||||
virtual nsIDocument* GetParentDocument() = 0;
|
||||
virtual void SetParentDocument(nsIDocument* aParent) = 0;
|
||||
virtual void AddSubDocument(nsIDocument* aSubDoc) = 0;
|
||||
virtual PRInt32 GetNumberOfSubDocuments() = 0;
|
||||
virtual nsIDocument* GetSubDocumentAt(PRInt32 aIndex) = 0;
|
||||
|
||||
/**
|
||||
* Return the root content object for this document.
|
||||
*/
|
||||
virtual nsIContent* GetRootContent() = 0;
|
||||
virtual void SetRootContent(nsIContent* aRoot) = 0;
|
||||
|
||||
/**
|
||||
* Get the style sheets owned by this document.
|
||||
*/
|
||||
virtual PRInt32 GetNumberOfStyleSheets() = 0;
|
||||
virtual nsIStyleSheet* GetStyleSheetAt(PRInt32 aIndex) = 0;
|
||||
virtual void AddStyleSheet(nsIStyleSheet* aSheet) = 0;
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Document notification API's
|
||||
|
||||
/**
|
||||
* Add a new observer of document change notifications. Whenever
|
||||
* content is changed, appended, inserted or removed the observers are
|
||||
* informed.
|
||||
*/
|
||||
virtual void AddObserver(nsIDocumentObserver* aObserver) = 0;
|
||||
|
||||
/**
|
||||
* Remove an observer of document change notifications. This will
|
||||
* return false if the observer cannot be found.
|
||||
*/
|
||||
virtual PRBool RemoveObserver(nsIDocumentObserver* aObserver) = 0;
|
||||
|
||||
// Observation hooks used by content nodes to propagate
|
||||
// notifications to document observers.
|
||||
virtual void ContentChanged(nsIContent* aContent,
|
||||
nsISubContent* aSubContent,
|
||||
PRInt32 aChangeType) = 0;
|
||||
|
||||
virtual void ContentAppended(nsIContent* aContainer) = 0;
|
||||
|
||||
virtual void ContentInserted(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) = 0;
|
||||
|
||||
virtual void ContentReplaced(nsIContent* aContainer,
|
||||
nsIContent* aOldChild,
|
||||
nsIContent* aNewChild,
|
||||
PRInt32 aIndexInContainer) = 0;
|
||||
|
||||
virtual void ContentWillBeRemoved(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) = 0;
|
||||
|
||||
virtual void ContentHasBeenRemoved(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) = 0;
|
||||
};
|
||||
|
||||
// XXX Belongs somewhere else
|
||||
extern NS_LAYOUT nsresult
|
||||
NS_NewHTMLDocument(nsIDocument** aInstancePtrResult);
|
||||
|
||||
// XXX temporary - it's going away!
|
||||
extern NS_LAYOUT void
|
||||
NS_HackAppendContent(nsIDocument* aDoc);
|
||||
|
||||
#endif /* nsIDocument_h___ */
|
||||
71
content/base/public/nsIDocumentContainer.h
Normal file
71
content/base/public/nsIDocumentContainer.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIDocumentContainer_h___
|
||||
#define nsIDocumentContainer_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
class nsIScriptable;
|
||||
class nsIScriptEnvironment;
|
||||
class nsIURL;
|
||||
|
||||
#define NS_IDOCUMENT_CONTAINER_IID \
|
||||
{ 0x8efd4470, 0x944d, 0x11d1, \
|
||||
{0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
class nIDocumentContainer : public nsISupports {
|
||||
public:
|
||||
/**
|
||||
* Display the specified URL with the given connection.
|
||||
*
|
||||
* @param url the URL to display
|
||||
* @param connection the connection to use.
|
||||
*/
|
||||
virtual void Display(nsIURL* aURL) = 0;
|
||||
|
||||
/**
|
||||
* Returns a script environment for the specified language and version.
|
||||
* The expectation is that the script environment already has been
|
||||
* set up with a container object. If a script environment has already
|
||||
* been requested for the given language, the same instance should
|
||||
* be returned.
|
||||
*
|
||||
* @param language the scripting language for the environment. If this
|
||||
* is null, returns the default scripting environment.
|
||||
* @param majorVersion the major version number of the language
|
||||
* @param minorVersion the minor version number of the language
|
||||
* @return the script environment for the language
|
||||
* @see mg.magellan.script.IScriptEnvrionment
|
||||
*/
|
||||
virtual nsIScriptEnvironment*
|
||||
GetScriptEnvironment(nsString* aLanguage,
|
||||
PRInt32 aMajorVersion,
|
||||
PRInt32 aMinorVersion) = 0;
|
||||
|
||||
/**
|
||||
* Returns the scriptable container object for the document container.
|
||||
* The scriptable object will be used as the scoping object in the
|
||||
* definition of scriptable classes used in the Document Object Model.
|
||||
*
|
||||
* @return the scriptable container for the application
|
||||
* @see mg.magellan.script.IScriptable
|
||||
* @see mg.magellan.script.IScriptEnvrionment
|
||||
*/
|
||||
virtual nsIScriptable* GetScriptableContainer() = 0;
|
||||
}
|
||||
|
||||
#endif /* nsIDocumentContainer_h___ */
|
||||
160
content/base/public/nsIDocumentObserver.h
Normal file
160
content/base/public/nsIDocumentObserver.h
Normal file
@@ -0,0 +1,160 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIDocumentObserver_h___
|
||||
#define nsIDocumentObserver_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
class nsIContent;
|
||||
class nsISubContent;
|
||||
class nsIStyleSheet;
|
||||
class nsString;
|
||||
|
||||
#define NS_IDOCUMENTOBSERVER_IID \
|
||||
{ 0xb3f92460, 0x944c, 0x11d1, \
|
||||
{0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
// Document observer interface
|
||||
class nsIDocumentObserver : public nsISupports {
|
||||
public:
|
||||
/**
|
||||
* This is called when the documents title has arrived.
|
||||
*/
|
||||
NS_IMETHOD SetTitle(const nsString& aTitle) = 0;
|
||||
|
||||
/**
|
||||
* Notify that a content model update is beginning. This call can be
|
||||
* nested.
|
||||
*/
|
||||
virtual void BeginUpdate() = 0;
|
||||
|
||||
/**
|
||||
* Notify that a content model update is finished. This call can be
|
||||
* nested.
|
||||
*/
|
||||
virtual void EndUpdate() = 0;
|
||||
|
||||
/**
|
||||
* Notification that the content model has changed. This method is
|
||||
* called automatically by content objects when their state is changed
|
||||
* (therefore there is normally no need to invoke this method
|
||||
* directly). The notification is passed to any
|
||||
* IDocumentObservers. The notification is passed on to all of the
|
||||
* document observers. <p>
|
||||
*
|
||||
* This notification is not sent when a piece of content is
|
||||
* added/removed from the document (the other notifications are used
|
||||
* for that).
|
||||
*
|
||||
* @param aContent the piece of content that changed
|
||||
* @param aSubContent subrange information about the piece of content
|
||||
* that change
|
||||
* @param aChangeType one of the change types (kLogicalChange,
|
||||
* kPhysicalChange or kRenderingChange)
|
||||
*/
|
||||
virtual void ContentChanged(nsIContent* aContent,
|
||||
nsISubContent* aSubContent,
|
||||
PRInt32 aChangeType) = 0;
|
||||
|
||||
/**
|
||||
* Notifcation that the content model has had data appended to the
|
||||
* given content object. This method is called automatically by the
|
||||
* content container objects when a new content object is appended to
|
||||
* the container (therefore there is normally no need to invoke this
|
||||
* method directly). The notification is passed on to all of the
|
||||
* document observers.
|
||||
*
|
||||
* @param aContainer the container that had a new child appended
|
||||
*/
|
||||
virtual void ContentAppended(nsIContent* aContainer) = 0;
|
||||
|
||||
/**
|
||||
* Notification that content has been inserted. This method is called
|
||||
* automatically by the content container objects when a new content
|
||||
* object is inserted in the container (therefore there is normally no
|
||||
* need to invoke this method directly). The notification is passed on
|
||||
* to all of the document observers.
|
||||
*
|
||||
* @param aContainer the container that now contains aChild
|
||||
* @param aChild the child that was inserted
|
||||
* @param aIndexInContainer the index of the child in the container
|
||||
*/
|
||||
virtual void ContentInserted(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) = 0;
|
||||
|
||||
/**
|
||||
* Notification that content has been replaced. This method is called
|
||||
* automatically by the content container objects when a content object
|
||||
* is replaced in the container (therefore there is normally no need to
|
||||
* invoke this method directly). The notification is passed on to all
|
||||
* of the document observers.
|
||||
*
|
||||
* @param aContainer the container that now contains aChild
|
||||
* @param aOldChild the child that was replaced
|
||||
* @param aNewChild the child that replaced aOldChild
|
||||
* @param aIndexInContainer the index of the old and new child in the
|
||||
* container
|
||||
*/
|
||||
virtual void ContentReplaced(nsIContent* aContainer,
|
||||
nsIContent* aOldChild,
|
||||
nsIContent* aNewChild,
|
||||
PRInt32 aIndexInContainer) = 0;
|
||||
|
||||
/**
|
||||
* Content is going to be removed immediately after this call. This
|
||||
* method is called automatically by content container objects when a
|
||||
* content object is about to be removed from the container (therefore
|
||||
* there is normally no need to invoke this method directly). The
|
||||
* notification is passed on to all of the document observers.
|
||||
*
|
||||
* @param aContainer the container that contains aChild
|
||||
* @param aChild the child that will be removed
|
||||
* @param aIndexInContainer the index of the child in the container
|
||||
*/
|
||||
virtual void ContentWillBeRemoved(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) = 0;
|
||||
|
||||
/**
|
||||
* Content has just been removed. This method is called automatically
|
||||
* by content container objects when a content object has just been
|
||||
* removed from the container (therefore there is normally no need to
|
||||
* invoke this method directly). The notification is passed on to all
|
||||
* of the document observers.
|
||||
*
|
||||
* @param aContainer the container that had a child removed
|
||||
* @param aChild the child that was just removed
|
||||
* @param aIndexInContainer the index of the child in the container
|
||||
* before it was removed
|
||||
*/
|
||||
virtual void ContentHasBeenRemoved(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) = 0;
|
||||
|
||||
/**
|
||||
* A StyleSheet has just been added to the document.
|
||||
* This method is called automatically when a StyleSheet gets added
|
||||
* to the document. The notification is passed on to all of the
|
||||
* document observers.
|
||||
*
|
||||
* @param aStyleSheet the StyleSheet that has been added
|
||||
*/
|
||||
virtual void StyleSheetAdded(nsIStyleSheet* aStyleSheet) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsIDocumentObserver_h___ */
|
||||
43
content/base/public/nsIStyleRule.h
Normal file
43
content/base/public/nsIStyleRule.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIStyleRule_h___
|
||||
#define nsIStyleRule_h___
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "nslayout.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIStyleContext;
|
||||
class nsIPresContext;
|
||||
|
||||
// IID for the nsIStyleRule interface {40ae5c90-ad6a-11d1-8031-006008159b5a}
|
||||
#define NS_ISTYLE_RULE_IID \
|
||||
{0x40ae5c90, 0xad6a, 0x11d1, {0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
|
||||
|
||||
class nsIStyleRule : public nsISupports {
|
||||
public:
|
||||
virtual PRBool Equals(const nsIStyleRule* aRule) const = 0;
|
||||
virtual PRUint32 HashValue(void) const = 0;
|
||||
|
||||
virtual void MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext) = 0;
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0;
|
||||
};
|
||||
|
||||
#endif /* nsIStyleRule_h___ */
|
||||
50
content/base/public/nsIStyleSheet.h
Normal file
50
content/base/public/nsIStyleSheet.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIStyleSheet_h___
|
||||
#define nsIStyleSheet_h___
|
||||
|
||||
#include <stdio.h>
|
||||
#include "nsISupports.h"
|
||||
class nsIAtom;
|
||||
class nsIURL;
|
||||
class nsIStyleRule;
|
||||
class nsISupportsArray;
|
||||
class nsIPresContext;
|
||||
class nsIContent;
|
||||
class nsIFrame;
|
||||
|
||||
// IID for the nsIStyleSheet interface {8c4a80a0-ad6a-11d1-8031-006008159b5a}
|
||||
#define NS_ISTYLE_SHEET_IID \
|
||||
{0x8c4a80a0, 0xad6a, 0x11d1, {0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
|
||||
|
||||
class nsIStyleSheet : public nsISupports {
|
||||
public:
|
||||
virtual nsIURL* GetURL(void) = 0;
|
||||
|
||||
// populate void array with nsIStyleRule*
|
||||
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParentFrame,
|
||||
nsISupportsArray* aResults) = 0;
|
||||
|
||||
// XXX style rule enumerations
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0;
|
||||
};
|
||||
|
||||
#endif /* nsIStyleSheet_h___ */
|
||||
48
content/base/public/nsITextContent.h
Normal file
48
content/base/public/nsITextContent.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsITextContent_h___
|
||||
#define nsITextContent_h___
|
||||
|
||||
#include "nslayout.h"
|
||||
class nsString;
|
||||
|
||||
// IID for the nsITextContent interface
|
||||
#define NS_ITEXTCONTENT_IID \
|
||||
{ 0xdd0755d0, 0x944d, 0x11d1, \
|
||||
{0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
// Abstract interface for textual content. Note that this interface
|
||||
// does not implement nsISupports (which means it's not transitive or
|
||||
// reflexive). This is done for efficiency reasons.
|
||||
class nsITextContent {
|
||||
public:
|
||||
/*
|
||||
* Get the total length of the text content.
|
||||
*/
|
||||
virtual PRInt32 GetLength() = 0;
|
||||
|
||||
/*
|
||||
* Copy a subrange of the text content into aBuf starting at aOffset
|
||||
* for aCount characters. aBuf's length will be reset before the
|
||||
* copy occurs and it's length upon return will reflect the amount
|
||||
* of data copied.
|
||||
*/
|
||||
virtual void GetText(nsString& aBuf, PRInt32 aOffset, PRInt32 aCount) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsITextContent_h___ */
|
||||
618
content/base/src/nsDocument.cpp
Normal file
618
content/base/src/nsDocument.cpp
Normal file
@@ -0,0 +1,618 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsDocument.h"
|
||||
#include "nsIArena.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIStyleSet.h"
|
||||
#include "nsIStyleSheet.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIDocumentObserver.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
||||
|
||||
#include "nsIDOMElement.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
|
||||
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
||||
static NS_DEFINE_IID(kIDOMElementIID, NS_IDOMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
|
||||
|
||||
nsDocument::nsDocument()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mArena = nsnull;
|
||||
mDocumentTitle = nsnull;
|
||||
mDocumentURL = nsnull;
|
||||
mCharacterSet = eCharSetID_IsoLatin1;
|
||||
mParentDocument = nsnull;
|
||||
mRootContent = nsnull;
|
||||
mScriptObject = nsnull;
|
||||
|
||||
Init();/* XXX */
|
||||
}
|
||||
|
||||
nsDocument::~nsDocument()
|
||||
{
|
||||
if (nsnull != mDocumentTitle) {
|
||||
delete mDocumentTitle;
|
||||
mDocumentTitle = nsnull;
|
||||
}
|
||||
NS_IF_RELEASE(mDocumentURL);
|
||||
|
||||
mParentDocument = nsnull;
|
||||
|
||||
// Delete references to sub-documents
|
||||
PRInt32 index = mSubDocuments.Count();
|
||||
while (--index >= 0) {
|
||||
nsIDocument* subdoc = (nsIDocument*) mSubDocuments.ElementAt(index);
|
||||
NS_RELEASE(subdoc);
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mRootContent);
|
||||
// Delete references to style sheets
|
||||
index = mStyleSheets.Count();
|
||||
while (--index >= 0) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*) mStyleSheets.ElementAt(index);
|
||||
NS_RELEASE(sheet);
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mArena);
|
||||
}
|
||||
|
||||
nsresult nsDocument::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kIDocumentIID)) {
|
||||
*aInstancePtr = (void*)(nsIDocument*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMDocumentIID)) {
|
||||
*aInstancePtr = (void*)(nsIDOMDocument*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
*aInstancePtr = (void*)(nsIScriptObjectOwner*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)(nsIDocument*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsDocument)
|
||||
NS_IMPL_RELEASE(nsDocument)
|
||||
|
||||
nsresult nsDocument::Init()
|
||||
{
|
||||
nsresult rv = NS_NewHeapArena(&mArena, nsnull);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIArena* nsDocument::GetArena()
|
||||
{
|
||||
if (nsnull != mArena) {
|
||||
NS_ADDREF(mArena);
|
||||
}
|
||||
return mArena;
|
||||
}
|
||||
|
||||
void nsDocument::StartDocumentLoad()
|
||||
{
|
||||
}
|
||||
|
||||
void nsDocument::PauseDocumentLoad()
|
||||
{
|
||||
}
|
||||
|
||||
void nsDocument::StopDocumentLoad()
|
||||
{
|
||||
}
|
||||
|
||||
void nsDocument::WaitForDocumentLoad()
|
||||
{
|
||||
}
|
||||
|
||||
PRBool nsDocument::IsDocumentLoaded()
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
const nsString* nsDocument::GetDocumentTitle() const
|
||||
{
|
||||
return mDocumentTitle;
|
||||
}
|
||||
|
||||
nsIURL* nsDocument::GetDocumentURL() const
|
||||
{
|
||||
NS_IF_ADDREF(mDocumentURL);
|
||||
return mDocumentURL;
|
||||
}
|
||||
|
||||
nsCharSetID nsDocument::GetDocumentCharacterSet() const
|
||||
{
|
||||
return mCharacterSet;
|
||||
}
|
||||
|
||||
void nsDocument::SetDocumentCharacterSet(nsCharSetID aCharSetID)
|
||||
{
|
||||
mCharacterSet = aCharSetID;
|
||||
}
|
||||
|
||||
nsIPresShell* nsDocument::CreateShell(nsIPresContext* aContext,
|
||||
nsIViewManager* aViewManager,
|
||||
nsIStyleSet* aStyleSet)
|
||||
{
|
||||
nsIPresShell* shell;
|
||||
nsresult status = NS_NewPresShell(&shell);
|
||||
if ((NS_OK == status) &&
|
||||
(NS_OK == shell->Init(this, aContext, aViewManager, aStyleSet))) {
|
||||
// Note: we don't hold a ref to the shell (it holds a ref to us)
|
||||
mPresShells.AppendElement(shell);
|
||||
}
|
||||
return shell;
|
||||
}
|
||||
|
||||
PRBool nsDocument::DeleteShell(nsIPresShell* aShell)
|
||||
{
|
||||
return mPresShells.RemoveElement(aShell);
|
||||
}
|
||||
|
||||
PRInt32 nsDocument::GetNumberOfShells()
|
||||
{
|
||||
return mPresShells.Count();
|
||||
}
|
||||
|
||||
nsIPresShell* nsDocument::GetShellAt(PRInt32 aIndex)
|
||||
{
|
||||
nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(aIndex);
|
||||
if (nsnull != shell) {
|
||||
NS_ADDREF(shell);
|
||||
}
|
||||
return shell;
|
||||
}
|
||||
|
||||
nsIDocument* nsDocument::GetParentDocument()
|
||||
{
|
||||
if (nsnull != mParentDocument) {
|
||||
NS_ADDREF(mParentDocument);
|
||||
}
|
||||
return mParentDocument;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note that we do *not* AddRef our parent because that would
|
||||
* create a circular reference.
|
||||
*/
|
||||
void nsDocument::SetParentDocument(nsIDocument* aParent)
|
||||
{
|
||||
mParentDocument = aParent;
|
||||
}
|
||||
|
||||
void nsDocument::AddSubDocument(nsIDocument* aSubDoc)
|
||||
{
|
||||
NS_ADDREF(aSubDoc);
|
||||
mSubDocuments.AppendElement(aSubDoc);
|
||||
}
|
||||
|
||||
PRInt32 nsDocument::GetNumberOfSubDocuments()
|
||||
{
|
||||
return mSubDocuments.Count();
|
||||
}
|
||||
|
||||
nsIDocument* nsDocument::GetSubDocumentAt(PRInt32 aIndex)
|
||||
{
|
||||
nsIDocument* doc = (nsIDocument*) mSubDocuments.ElementAt(aIndex);
|
||||
if (nsnull != doc) {
|
||||
NS_ADDREF(doc);
|
||||
}
|
||||
return doc;
|
||||
}
|
||||
|
||||
nsIContent* nsDocument::GetRootContent()
|
||||
{
|
||||
if (nsnull != mRootContent) {
|
||||
NS_ADDREF(mRootContent);
|
||||
}
|
||||
return mRootContent;
|
||||
}
|
||||
|
||||
void nsDocument::SetRootContent(nsIContent* aRoot)
|
||||
{
|
||||
NS_IF_RELEASE(mRootContent);
|
||||
if (nsnull != aRoot) {
|
||||
mRootContent = aRoot;
|
||||
NS_ADDREF(aRoot);
|
||||
}
|
||||
}
|
||||
|
||||
PRInt32 nsDocument::GetNumberOfStyleSheets()
|
||||
{
|
||||
return mStyleSheets.Count();
|
||||
}
|
||||
|
||||
nsIStyleSheet* nsDocument::GetStyleSheetAt(PRInt32 aIndex)
|
||||
{
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)mStyleSheets.ElementAt(aIndex);
|
||||
NS_IF_ADDREF(sheet);
|
||||
return sheet;
|
||||
}
|
||||
|
||||
void nsDocument::AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet)
|
||||
{
|
||||
aSet->AppendDocStyleSheet(aSheet);
|
||||
}
|
||||
|
||||
void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
mStyleSheets.AppendElement(aSheet);
|
||||
NS_ADDREF(aSheet);
|
||||
|
||||
PRInt32 count = mPresShells.Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
|
||||
nsIStyleSet* set = shell->GetStyleSet();
|
||||
if (nsnull != set) {
|
||||
AddStyleSheetToSet(aSheet, set);
|
||||
NS_RELEASE(set);
|
||||
}
|
||||
}
|
||||
|
||||
count = mObservers.Count();
|
||||
for (index = 0; index < count; index++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
|
||||
observer->StyleSheetAdded(aSheet);
|
||||
}
|
||||
}
|
||||
|
||||
// Note: We don't hold a reference to the document observer; we assume
|
||||
// that it has a live reference to the document.
|
||||
void nsDocument::AddObserver(nsIDocumentObserver* aObserver)
|
||||
{
|
||||
mObservers.AppendElement(aObserver);
|
||||
}
|
||||
|
||||
PRBool nsDocument::RemoveObserver(nsIDocumentObserver* aObserver)
|
||||
{
|
||||
return mObservers.RemoveElement(aObserver);
|
||||
}
|
||||
|
||||
void nsDocument::ContentChanged(nsIContent* aContent,
|
||||
nsISubContent* aSubContent,
|
||||
PRInt32 aChangeType)
|
||||
{
|
||||
PRInt32 count = mObservers.Count();
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
||||
observer->ContentChanged(aContent, aSubContent, aChangeType);
|
||||
}
|
||||
}
|
||||
|
||||
void nsDocument::ContentAppended(nsIContent* aContainer)
|
||||
{
|
||||
PRInt32 count = mObservers.Count();
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
||||
observer->ContentAppended(aContainer);
|
||||
}
|
||||
}
|
||||
|
||||
void nsDocument::ContentInserted(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer)
|
||||
{
|
||||
PRInt32 count = mObservers.Count();
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
||||
observer->ContentInserted(aContainer, aChild, aIndexInContainer);
|
||||
}
|
||||
}
|
||||
|
||||
void nsDocument::ContentReplaced(nsIContent* aContainer,
|
||||
nsIContent* aOldChild,
|
||||
nsIContent* aNewChild,
|
||||
PRInt32 aIndexInContainer)
|
||||
{
|
||||
PRInt32 count = mObservers.Count();
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
||||
observer->ContentReplaced(aContainer, aOldChild, aNewChild,
|
||||
aIndexInContainer);
|
||||
}
|
||||
}
|
||||
|
||||
void nsDocument::ContentWillBeRemoved(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer)
|
||||
{
|
||||
PRInt32 count = mObservers.Count();
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
||||
observer->ContentWillBeRemoved(aContainer, aChild, aIndexInContainer);
|
||||
}
|
||||
}
|
||||
|
||||
void nsDocument::ContentHasBeenRemoved(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer)
|
||||
{
|
||||
PRInt32 count = mObservers.Count();
|
||||
for (PRInt32 i = 0; i < count; i++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
||||
observer->ContentHasBeenRemoved(aContainer, aChild, aIndexInContainer);
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsDocument::GetScriptObject(JSContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
res = NS_NewScriptDocument(aContext, this, nsnull, (JSObject**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDocument::ResetScriptObject()
|
||||
{
|
||||
mScriptObject = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// nsIDOMDocument interface
|
||||
//
|
||||
nsresult nsDocument::GetNodeType(PRInt32 *aType)
|
||||
{
|
||||
*aType = nsIDOMNode::DOCUMENT;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDocument::GetParentNode(nsIDOMNode **aNode)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsDocument::GetChildNodes(nsIDOMNodeIterator **aIterator)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::HasChildNodes()
|
||||
{
|
||||
if (nsnull != mRootContent) {
|
||||
return NS_OK;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult nsDocument::GetFirstChild(nsIDOMNode **aNode)
|
||||
{
|
||||
if (nsnull != mRootContent) {
|
||||
nsresult res = mRootContent->QueryInterface(kIDOMNodeIID, (void**)aNode);
|
||||
NS_ASSERTION(NS_OK == res, "Must be a DOM Node");
|
||||
return res;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsDocument::GetPreviousSibling(nsIDOMNode **aNode)
|
||||
{
|
||||
// no siblings
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsDocument::GetNextSibling(nsIDOMNode **aNode)
|
||||
{
|
||||
// no siblings
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsDocument::InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild)
|
||||
{
|
||||
// a document has only one child
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult nsDocument::ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != newChild && nsnull != oldChild, "null arg");
|
||||
nsIContent* content;
|
||||
|
||||
nsresult res = oldChild->QueryInterface(kIContentIID, (void**)&content);
|
||||
if (NS_OK == res) {
|
||||
// check that we are replacing the root content
|
||||
if (content == mRootContent) {
|
||||
nsIContent* newContent;
|
||||
res = newChild->QueryInterface(kIContentIID, (void**)&newContent);
|
||||
if (NS_OK == res) {
|
||||
SetRootContent(newContent);
|
||||
NS_RELEASE(newContent);
|
||||
}
|
||||
else NS_ASSERTION(0, "Must be an nsIContent"); // nsIContent not supported. Who are you?
|
||||
}
|
||||
|
||||
NS_RELEASE(content);
|
||||
}
|
||||
else NS_ASSERTION(0, "Must be an nsIContent"); // nsIContent not supported. Who are you?
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDocument::RemoveChild(nsIDOMNode *oldChild)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != oldChild, "null arg");
|
||||
nsIContent* content;
|
||||
|
||||
nsresult res = oldChild->QueryInterface(kIContentIID, (void**)&content);
|
||||
if (NS_OK == res) {
|
||||
if (content == mRootContent) {
|
||||
NS_RELEASE(mRootContent);
|
||||
mRootContent = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDocument::GetMasterDoc(nsIDOMDocument **aDocument)
|
||||
{
|
||||
AddRef();
|
||||
*aDocument = (nsIDOMDocument*)this;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDocument::SetMasterDoc(nsIDOMDocument *aDocument)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::GetDocumentType(nsIDOMNode **aDocType)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::SetDocumentType(nsIDOMNode *aNode)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::GetDocumentElement(nsIDOMElement **aElement)
|
||||
{
|
||||
nsresult res = NS_ERROR_FAILURE;
|
||||
|
||||
if (nsnull != mRootContent) {
|
||||
res = mRootContent->QueryInterface(kIDOMElementIID, (void**)aElement);
|
||||
NS_ASSERTION(NS_OK == res, "Must be a DOM Element");
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDocument::SetDocumentElement(nsIDOMElement *aElement)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aElement, "null arg");
|
||||
nsIContent* content;
|
||||
|
||||
nsresult res = aElement->QueryInterface(kIContentIID, (void**)&content);
|
||||
if (NS_OK == res) {
|
||||
SetRootContent(content);
|
||||
NS_RELEASE(content);
|
||||
}
|
||||
else NS_ASSERTION(0, "Must be an nsIContent"); // nsIContent not supported. Who are you?
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsDocument::GetDocumentContext(nsIDOMDocumentContext **aDocContext)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::SetDocumentContext(nsIDOMDocumentContext *aContext)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::CreateDocumentContext(nsIDOMDocumentContext **aDocContext)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::CreateElement(nsString &aTagName,
|
||||
nsIDOMAttributeList *aAttributes,
|
||||
nsIDOMElement **aElement)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::CreateTextNode(nsString &aData, nsIDOMText** aTextNode)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::CreateComment(nsString &aData, nsIDOMComment **aComment)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::CreatePI(nsString &aName, nsString &aData, nsIDOMPI **aPI)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::CreateAttribute(nsString &aName,
|
||||
nsIDOMNode *value,
|
||||
nsIDOMAttribute **aAttribute)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::CreateAttributeList(nsIDOMAttributeList **aAttributesList)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::CreateTreeIterator(nsIDOMNode **aNode, nsIDOMTreeIterator **aTreeIterator)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsDocument::GetElementsByTagName(nsIDOMNodeIterator **aIterator)
|
||||
{
|
||||
//XXX TBI
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
187
content/base/src/nsDocument.h
Normal file
187
content/base/src/nsDocument.h
Normal file
@@ -0,0 +1,187 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsDocument_h___
|
||||
#define nsDocument_h___
|
||||
|
||||
#include "nsIDocument.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
|
||||
// Base class for our document implementations
|
||||
class nsDocument : public nsIDocument, public nsIDOMDocument, public nsIScriptObjectOwner {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsIArena* GetArena();
|
||||
|
||||
virtual void StartDocumentLoad();
|
||||
virtual void PauseDocumentLoad();
|
||||
virtual void StopDocumentLoad();
|
||||
virtual void WaitForDocumentLoad();
|
||||
virtual PRBool IsDocumentLoaded();
|
||||
|
||||
/**
|
||||
* Return the title of the document. May return null.
|
||||
*/
|
||||
virtual const nsString* GetDocumentTitle() const;
|
||||
|
||||
/**
|
||||
* Return the URL for the document. May return null.
|
||||
*/
|
||||
virtual nsIURL* GetDocumentURL() const;
|
||||
|
||||
/**
|
||||
* Return a standard name for the document's character set. This will
|
||||
* trigger a startDocumentLoad if necessary to answer the question.
|
||||
*/
|
||||
virtual nsCharSetID GetDocumentCharacterSet() const;
|
||||
virtual void SetDocumentCharacterSet(nsCharSetID aCharSetID);
|
||||
|
||||
/**
|
||||
* Create a new presentation shell that will use aContext for
|
||||
* it's presentation context (presentation context's <b>must not</b> be
|
||||
* shared among multiple presentation shell's).
|
||||
*/
|
||||
virtual nsIPresShell* CreateShell(nsIPresContext* aContext,
|
||||
nsIViewManager* aViewManager,
|
||||
nsIStyleSet* aStyleSet);
|
||||
virtual PRBool DeleteShell(nsIPresShell* aShell);
|
||||
virtual PRInt32 GetNumberOfShells();
|
||||
virtual nsIPresShell* GetShellAt(PRInt32 aIndex);
|
||||
|
||||
/**
|
||||
* Return the parent document of this document. Will return null
|
||||
* unless this document is within a compound document and has a parent.
|
||||
*/
|
||||
virtual nsIDocument* GetParentDocument();
|
||||
virtual void SetParentDocument(nsIDocument* aParent);
|
||||
virtual void AddSubDocument(nsIDocument* aSubDoc);
|
||||
virtual PRInt32 GetNumberOfSubDocuments();
|
||||
virtual nsIDocument* GetSubDocumentAt(PRInt32 aIndex);
|
||||
|
||||
/**
|
||||
* Return the root content object for this document.
|
||||
*/
|
||||
virtual nsIContent* GetRootContent();
|
||||
virtual void SetRootContent(nsIContent* aRoot);
|
||||
|
||||
/**
|
||||
* Get the style sheets owned by this document.
|
||||
*/
|
||||
virtual PRInt32 GetNumberOfStyleSheets();
|
||||
virtual nsIStyleSheet* GetStyleSheetAt(PRInt32 aIndex);
|
||||
virtual void AddStyleSheet(nsIStyleSheet* aSheet);
|
||||
|
||||
/**
|
||||
* Add a new observer of document change notifications. Whenever
|
||||
* content is changed, appended, inserted or removed the observers are
|
||||
* informed.
|
||||
*/
|
||||
virtual void AddObserver(nsIDocumentObserver* aObserver);
|
||||
|
||||
/**
|
||||
* Remove an observer of document change notifications. This will
|
||||
* return false if the observer cannot be found.
|
||||
*/
|
||||
virtual PRBool RemoveObserver(nsIDocumentObserver* aObserver);
|
||||
|
||||
// Observation hooks used by content nodes to propagate
|
||||
// notifications to document observers.
|
||||
virtual void ContentChanged(nsIContent* aContent,
|
||||
nsISubContent* aSubContent,
|
||||
PRInt32 aChangeType);
|
||||
|
||||
virtual void ContentAppended(nsIContent* aContainer);
|
||||
|
||||
virtual void ContentInserted(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer);
|
||||
|
||||
virtual void ContentReplaced(nsIContent* aContainer,
|
||||
nsIContent* aOldChild,
|
||||
nsIContent* aNewChild,
|
||||
PRInt32 aIndexInContainer);
|
||||
|
||||
virtual void ContentWillBeRemoved(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer);
|
||||
|
||||
virtual void ContentHasBeenRemoved(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer);
|
||||
|
||||
public:
|
||||
|
||||
virtual nsresult GetScriptObject(JSContext *aContext, void** aScriptObject);
|
||||
virtual nsresult ResetScriptObject();
|
||||
|
||||
// nsIDOMDocument interface
|
||||
virtual nsresult GetNodeType(PRInt32 *aType);
|
||||
virtual nsresult GetParentNode(nsIDOMNode **aNode);
|
||||
virtual nsresult GetChildNodes(nsIDOMNodeIterator **aIterator);
|
||||
virtual nsresult HasChildNodes();
|
||||
virtual nsresult GetFirstChild(nsIDOMNode **aNode);
|
||||
virtual nsresult GetPreviousSibling(nsIDOMNode **aNode);
|
||||
virtual nsresult GetNextSibling(nsIDOMNode **aNode);
|
||||
virtual nsresult InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild);
|
||||
virtual nsresult ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild);
|
||||
virtual nsresult RemoveChild(nsIDOMNode *oldChild);
|
||||
virtual nsresult GetMasterDoc(nsIDOMDocument **aDocument);
|
||||
virtual nsresult SetMasterDoc(nsIDOMDocument *aDocument);
|
||||
virtual nsresult GetDocumentType(nsIDOMNode **aDocType);
|
||||
virtual nsresult SetDocumentType(nsIDOMNode *aNode);
|
||||
virtual nsresult GetDocumentElement(nsIDOMElement **aElement);
|
||||
virtual nsresult SetDocumentElement(nsIDOMElement *aElement);
|
||||
virtual nsresult GetDocumentContext(nsIDOMDocumentContext **aDocContext);
|
||||
virtual nsresult SetDocumentContext(nsIDOMDocumentContext *aContext);
|
||||
virtual nsresult CreateDocumentContext(nsIDOMDocumentContext **aDocContext);
|
||||
virtual nsresult CreateElement(nsString &aTagName,
|
||||
nsIDOMAttributeList *aAttributes,
|
||||
nsIDOMElement **aElement);
|
||||
virtual nsresult CreateTextNode(nsString &aData, nsIDOMText** aTextNode);
|
||||
virtual nsresult CreateComment(nsString &aData, nsIDOMComment **aComment);
|
||||
virtual nsresult CreatePI(nsString &aName, nsString &aData, nsIDOMPI **aPI);
|
||||
virtual nsresult CreateAttribute(nsString &aName,
|
||||
nsIDOMNode *value,
|
||||
nsIDOMAttribute **aAttribute);
|
||||
virtual nsresult CreateAttributeList(nsIDOMAttributeList **aAttributesList);
|
||||
virtual nsresult CreateTreeIterator(nsIDOMNode **aNode, nsIDOMTreeIterator **aTreeIterator);
|
||||
virtual nsresult GetElementsByTagName(nsIDOMNodeIterator **aIterator);
|
||||
|
||||
protected:
|
||||
virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet); // subclass hook
|
||||
|
||||
nsDocument();
|
||||
virtual ~nsDocument();
|
||||
nsresult Init();
|
||||
|
||||
nsIArena* mArena;
|
||||
nsString* mDocumentTitle;
|
||||
nsIURL* mDocumentURL;
|
||||
nsCharSetID mCharacterSet;
|
||||
nsIDocument* mParentDocument;
|
||||
nsVoidArray mSubDocuments;
|
||||
nsVoidArray mPresShells;
|
||||
nsIContent* mRootContent;
|
||||
nsVoidArray mStyleSheets;
|
||||
nsVoidArray mObservers;
|
||||
void* mScriptObject;
|
||||
};
|
||||
|
||||
#endif /* nsDocument_h___ */
|
||||
257
content/base/src/nsHTMLValue.cpp
Normal file
257
content/base/src/nsHTMLValue.cpp
Normal file
@@ -0,0 +1,257 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nsHTMLValue.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
const nsHTMLValue nsHTMLValue::kNull;
|
||||
|
||||
nsHTMLValue::nsHTMLValue(void)
|
||||
: mUnit(eHTMLUnit_Null)
|
||||
{
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit)
|
||||
: mUnit(aUnit)
|
||||
{
|
||||
mValue.mInt = aValue;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(float aValue, nsHTMLUnit aUnit)
|
||||
: mUnit(aUnit)
|
||||
{
|
||||
mValue.mFloat = aValue;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(const nsString& aValue)
|
||||
: mUnit(eHTMLUnit_String)
|
||||
{
|
||||
mValue.mString = aValue.ToNewString();
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nsISupports* aValue)
|
||||
: mUnit(eHTMLUnit_ISupports)
|
||||
{
|
||||
mValue.mISupports = aValue;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nscolor aValue)
|
||||
: mUnit(eHTMLUnit_Color)
|
||||
{
|
||||
mValue.mColor = aValue;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(const nsHTMLValue& aCopy)
|
||||
: mUnit(aCopy.mUnit)
|
||||
{
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull != aCopy.mValue.mString) {
|
||||
mValue.mString = aCopy.mValue.mString->ToNewString();
|
||||
}
|
||||
else {
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
mValue.mISupports = aCopy.mValue.mISupports;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
mValue.mColor = aCopy.mValue.mColor;
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
mValue.mFloat = aCopy.mValue.mFloat;
|
||||
}
|
||||
else {
|
||||
mValue.mInt = aCopy.mValue.mInt;
|
||||
}
|
||||
}
|
||||
|
||||
nsHTMLValue::~nsHTMLValue(void)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
nsHTMLValue& nsHTMLValue::operator=(const nsHTMLValue& aCopy)
|
||||
{
|
||||
Reset();
|
||||
mUnit = aCopy.mUnit;
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull != aCopy.mValue.mString) {
|
||||
mValue.mString = aCopy.mValue.mString->ToNewString();
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
mValue.mISupports = aCopy.mValue.mISupports;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
mValue.mColor = aCopy.mValue.mColor;
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
mValue.mFloat = aCopy.mValue.mFloat;
|
||||
}
|
||||
else {
|
||||
mValue.mInt = aCopy.mValue.mInt;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
PRBool nsHTMLValue::operator==(const nsHTMLValue& aOther) const
|
||||
{
|
||||
if (mUnit == aOther.mUnit) {
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull == mValue.mString) {
|
||||
if (nsnull == aOther.mValue.mString) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
else if (nsnull != aOther.mValue.mString) {
|
||||
return mValue.mString->Equals(*(aOther.mValue.mString));
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
return PRBool(mValue.mISupports == aOther.mValue.mISupports);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
return PRBool(mValue.mColor == aOther.mValue.mColor);
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
return PRBool(mValue.mFloat == aOther.mValue.mFloat);
|
||||
}
|
||||
else {
|
||||
return PRBool(mValue.mInt == aOther.mValue.mInt);
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
void nsHTMLValue::Reset(void)
|
||||
{
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull != mValue.mString) {
|
||||
delete mValue.mString;
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
NS_IF_RELEASE(mValue.mISupports);
|
||||
}
|
||||
mUnit = eHTMLUnit_Null;
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
|
||||
|
||||
void nsHTMLValue::Set(PRInt32 aValue, nsHTMLUnit aUnit)
|
||||
{
|
||||
Reset();
|
||||
mUnit = aUnit;
|
||||
mValue.mInt = aValue;
|
||||
}
|
||||
|
||||
void nsHTMLValue::Set(float aValue, nsHTMLUnit aUnit)
|
||||
{
|
||||
Reset();
|
||||
mUnit = aUnit;
|
||||
mValue.mFloat = aValue;
|
||||
}
|
||||
|
||||
void nsHTMLValue::Set(const nsString& aValue)
|
||||
{
|
||||
Reset();
|
||||
mUnit = eHTMLUnit_String;
|
||||
mValue.mString = aValue.ToNewString();
|
||||
}
|
||||
|
||||
void nsHTMLValue::Set(nsISupports* aValue)
|
||||
{
|
||||
Reset();
|
||||
mUnit = eHTMLUnit_ISupports;
|
||||
mValue.mISupports = aValue;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
|
||||
void nsHTMLValue::Set(nscolor aValue)
|
||||
{
|
||||
Reset();
|
||||
mUnit = eHTMLUnit_Color;
|
||||
mValue.mColor = aValue;
|
||||
}
|
||||
|
||||
void nsHTMLValue::AppendToString(nsString& aBuffer) const
|
||||
{
|
||||
if (eHTMLUnit_Null == mUnit) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull != mValue.mString) {
|
||||
aBuffer.Append('"');
|
||||
aBuffer.Append(*(mValue.mString));
|
||||
aBuffer.Append('"');
|
||||
}
|
||||
else {
|
||||
aBuffer.Append("null str");
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
aBuffer.Append("0x");
|
||||
aBuffer.Append((PRInt32)mValue.mISupports, 16);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
aBuffer.Append("(0x");
|
||||
aBuffer.Append(NS_GET_R(mValue.mColor), 16);
|
||||
aBuffer.Append(" 0x");
|
||||
aBuffer.Append(NS_GET_G(mValue.mColor), 16);
|
||||
aBuffer.Append(" 0x");
|
||||
aBuffer.Append(NS_GET_B(mValue.mColor), 16);
|
||||
aBuffer.Append(" 0x");
|
||||
aBuffer.Append(NS_GET_A(mValue.mColor), 16);
|
||||
aBuffer.Append(')');
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
aBuffer.Append(mValue.mFloat);
|
||||
}
|
||||
else {
|
||||
aBuffer.Append(mValue.mInt, 10);
|
||||
aBuffer.Append("[0x");
|
||||
aBuffer.Append(mValue.mInt, 16);
|
||||
aBuffer.Append(']');
|
||||
}
|
||||
|
||||
switch (mUnit) {
|
||||
case eHTMLUnit_Null: break;
|
||||
case eHTMLUnit_String: break;
|
||||
case eHTMLUnit_ISupports: aBuffer.Append("ptr"); break;
|
||||
case eHTMLUnit_Absolute: break;
|
||||
case eHTMLUnit_Enumerated: aBuffer.Append("enum"); break;
|
||||
case eHTMLUnit_Color: aBuffer.Append("rbga"); break;
|
||||
case eHTMLUnit_Percent: aBuffer.Append("%"); break;
|
||||
case eHTMLUnit_Pixel: aBuffer.Append("px"); break;
|
||||
}
|
||||
aBuffer.Append(' ');
|
||||
}
|
||||
|
||||
void nsHTMLValue::ToString(nsString& aBuffer) const
|
||||
{
|
||||
aBuffer.SetLength(0);
|
||||
AppendToString(aBuffer);
|
||||
}
|
||||
|
||||
138
content/base/src/nsHTMLValue.h
Normal file
138
content/base/src/nsHTMLValue.h
Normal file
@@ -0,0 +1,138 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsHTMLValue_h___
|
||||
#define nsHTMLValue_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsString.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
|
||||
enum nsHTMLUnit {
|
||||
eHTMLUnit_Null = 0, // (n/a) null unit, value is not specified
|
||||
eHTMLUnit_String = 10, // (nsString) a string value
|
||||
eHTMLUnit_ISupports = 20, // (nsISupports*) a ref counted interface
|
||||
eHTMLUnit_Absolute = 50, // (int) simple value
|
||||
eHTMLUnit_Enumerated = 51, // (int) value has enumerated meaning
|
||||
eHTMLUnit_Color = 80, // (color) an RGBA value
|
||||
eHTMLUnit_Percent = 90, // (float) 1.0 == 100%) value is percentage of something
|
||||
|
||||
// Screen relative measure
|
||||
eHTMLUnit_Pixel = 600, // (int) screen pixels
|
||||
};
|
||||
|
||||
class nsHTMLValue {
|
||||
public:
|
||||
nsHTMLValue(void);
|
||||
nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit = eHTMLUnit_Absolute);
|
||||
nsHTMLValue(float aValue, nsHTMLUnit aUnit = eHTMLUnit_Pixel);
|
||||
nsHTMLValue(const nsString& aValue);
|
||||
nsHTMLValue(nsISupports* aValue);
|
||||
nsHTMLValue(nscolor aValue);
|
||||
nsHTMLValue(const nsHTMLValue& aCopy);
|
||||
~nsHTMLValue(void);
|
||||
|
||||
nsHTMLValue& operator=(const nsHTMLValue& aCopy);
|
||||
PRBool operator==(const nsHTMLValue& aOther) const;
|
||||
|
||||
nsHTMLUnit GetUnit(void) const { return mUnit; }
|
||||
PRInt32 GetIntValue(void) const;
|
||||
float GetFloatValue(void) const;
|
||||
nsString& GetStringValue(nsString& aBuffer) const;
|
||||
nsISupports* GetISupportsValue(void) const;
|
||||
nscolor GetColorValue(void) const;
|
||||
|
||||
void Reset(void);
|
||||
void Set(PRInt32 aValue, nsHTMLUnit aUnit = eHTMLUnit_Absolute);
|
||||
void Set(float aValue, nsHTMLUnit aUnit = eHTMLUnit_Pixel);
|
||||
void Set(const nsString& aValue);
|
||||
void Set(nsISupports* aValue);
|
||||
void Set(nscolor aValue);
|
||||
|
||||
void AppendToString(nsString& aBuffer) const;
|
||||
void ToString(nsString& aBuffer) const;
|
||||
|
||||
protected:
|
||||
nsHTMLUnit mUnit;
|
||||
union {
|
||||
PRInt32 mInt;
|
||||
float mFloat;
|
||||
nsString* mString;
|
||||
nsISupports* mISupports;
|
||||
nscolor mColor;
|
||||
} mValue;
|
||||
|
||||
public:
|
||||
static const nsHTMLValue kNull;
|
||||
};
|
||||
|
||||
inline PRInt32 nsHTMLValue::GetIntValue(void) const
|
||||
{
|
||||
NS_ASSERTION((mUnit == eHTMLUnit_Absolute) ||
|
||||
(mUnit == eHTMLUnit_Enumerated) ||
|
||||
(mUnit == eHTMLUnit_Pixel), "not an int value");
|
||||
if ((mUnit == eHTMLUnit_Absolute) ||
|
||||
(mUnit == eHTMLUnit_Enumerated) ||
|
||||
(mUnit == eHTMLUnit_Pixel)) {
|
||||
return mValue.mInt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline float nsHTMLValue::GetFloatValue(void) const
|
||||
{
|
||||
NS_ASSERTION(mUnit == eHTMLUnit_Percent, "not a float value");
|
||||
if (mUnit == eHTMLUnit_Percent) {
|
||||
return mValue.mFloat;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
inline nsString& nsHTMLValue::GetStringValue(nsString& aBuffer) const
|
||||
{
|
||||
NS_ASSERTION((mUnit == eHTMLUnit_String) || (mUnit == eHTMLUnit_Null), "not a string value");
|
||||
aBuffer.SetLength(0);
|
||||
if ((mUnit == eHTMLUnit_String) && (nsnull != mValue.mString)) {
|
||||
aBuffer.Append(*(mValue.mString));
|
||||
}
|
||||
return aBuffer;
|
||||
}
|
||||
|
||||
inline nsISupports* nsHTMLValue::GetISupportsValue(void) const
|
||||
{
|
||||
NS_ASSERTION(mUnit == eHTMLUnit_ISupports, "not an ISupports value");
|
||||
if (mUnit == eHTMLUnit_ISupports) {
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
return mValue.mISupports;
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
inline nscolor nsHTMLValue::GetColorValue(void) const
|
||||
{
|
||||
NS_ASSERTION(mUnit == eHTMLUnit_Color, "not a color value");
|
||||
if (mUnit == eHTMLUnit_Color) {
|
||||
return mValue.mColor;
|
||||
}
|
||||
return NS_RGB(0,0,0);
|
||||
}
|
||||
|
||||
|
||||
#endif /* nsHTMLValue_h___ */
|
||||
|
||||
613
content/base/src/nsStyleContext.cpp
Normal file
613
content/base/src/nsStyleContext.cpp
Normal file
@@ -0,0 +1,613 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsString.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIStyleRule.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#include "nsIFrame.h"
|
||||
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static PRBool gsDebug = PR_FALSE;
|
||||
#else
|
||||
static const PRBool gsDebug = PR_FALSE;
|
||||
#endif
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kStyleFontSID, NS_STYLEFONT_SID);
|
||||
static NS_DEFINE_IID(kStyleColorSID, NS_STYLECOLOR_SID);
|
||||
static NS_DEFINE_IID(kStyleListSID, NS_STYLELIST_SID);
|
||||
static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID);
|
||||
|
||||
static NS_DEFINE_IID(kIStyleContextIID, NS_ISTYLECONTEXT_IID);
|
||||
|
||||
nsStyleFont::nsStyleFont(const nsFont& aFont)
|
||||
: mFont(aFont)
|
||||
{
|
||||
}
|
||||
|
||||
nsStyleFont::~nsStyleFont(void)
|
||||
{
|
||||
}
|
||||
|
||||
struct StyleFontImpl : public nsStyleFont {
|
||||
StyleFontImpl(const nsFont& aFont)
|
||||
: nsStyleFont(aFont)
|
||||
{}
|
||||
~StyleFontImpl()
|
||||
{}
|
||||
|
||||
virtual const nsID& GetID(void)
|
||||
{ return kStyleFontSID; }
|
||||
|
||||
virtual void InheritFrom(const nsStyleFont& aCopy);
|
||||
|
||||
private: // These are not allowed
|
||||
StyleFontImpl(const StyleFontImpl& aOther);
|
||||
StyleFontImpl& operator=(const StyleFontImpl& aOther);
|
||||
};
|
||||
|
||||
void StyleFontImpl::InheritFrom(const nsStyleFont& aCopy)
|
||||
{
|
||||
mFont = aCopy.mFont;
|
||||
mThreeD = aCopy.mThreeD;
|
||||
}
|
||||
|
||||
struct StyleColorImpl: public nsStyleColor {
|
||||
StyleColorImpl(void)
|
||||
{
|
||||
mBackgroundAttachment = NS_STYLE_BG_ATTACHMENT_SCROLL;
|
||||
mBackgroundFlags = NS_STYLE_BG_COLOR_TRANSPARENT;
|
||||
mBackgroundRepeat = NS_STYLE_BG_REPEAT_OFF;
|
||||
|
||||
mBackgroundColor = NS_RGB(192,192,192);
|
||||
}
|
||||
|
||||
~StyleColorImpl(void)
|
||||
{}
|
||||
|
||||
virtual const nsID& GetID(void)
|
||||
{ return kStyleColorSID; }
|
||||
|
||||
virtual void InheritFrom(const nsStyleColor& aCopy);
|
||||
|
||||
private: // These are not allowed
|
||||
StyleColorImpl(const StyleColorImpl& aOther);
|
||||
StyleColorImpl& operator=(const StyleColorImpl& aOther);
|
||||
};
|
||||
|
||||
void StyleColorImpl::InheritFrom(const nsStyleColor& aCopy)
|
||||
{
|
||||
mColor = aCopy.mColor;
|
||||
|
||||
mBackgroundFlags = NS_STYLE_BG_COLOR_TRANSPARENT;
|
||||
}
|
||||
|
||||
|
||||
struct StyleListImpl: public nsStyleList {
|
||||
StyleListImpl(void)
|
||||
{
|
||||
mListStyleType = NS_STYLE_LIST_STYLE_BASIC;
|
||||
mListStylePosition = NS_STYLE_LIST_STYLE_POSITION_OUTSIDE;
|
||||
}
|
||||
|
||||
~StyleListImpl(void)
|
||||
{
|
||||
}
|
||||
|
||||
virtual const nsID& GetID(void)
|
||||
{ return kStyleListSID; }
|
||||
|
||||
virtual void InheritFrom(const nsStyleList& aCopy);
|
||||
};
|
||||
|
||||
void StyleListImpl::InheritFrom(const nsStyleList& aCopy)
|
||||
{
|
||||
mListStyleType = aCopy.mListStyleType;
|
||||
mListStyleImage = aCopy.mListStyleImage;
|
||||
mListStylePosition = aCopy.mListStylePosition;
|
||||
}
|
||||
|
||||
nsStyleMolecule::nsStyleMolecule()
|
||||
{
|
||||
}
|
||||
|
||||
nsStyleMolecule::~nsStyleMolecule()
|
||||
{
|
||||
}
|
||||
|
||||
struct StyleMoleculeImpl : public nsStyleMolecule {
|
||||
StyleMoleculeImpl(void)
|
||||
{}
|
||||
~StyleMoleculeImpl(void)
|
||||
{}
|
||||
|
||||
virtual const nsID& GetID(void)
|
||||
{ return kStyleMoleculeSID; }
|
||||
|
||||
virtual void InheritFrom(const nsStyleMolecule& aCopy);
|
||||
|
||||
private: // These are not allowed
|
||||
StyleMoleculeImpl(const StyleMoleculeImpl& aOther);
|
||||
StyleMoleculeImpl& operator=(const StyleMoleculeImpl& aOther);
|
||||
};
|
||||
|
||||
void StyleMoleculeImpl::InheritFrom(const nsStyleMolecule& aCopy)
|
||||
{
|
||||
cursor = aCopy.cursor;
|
||||
direction = aCopy.direction;
|
||||
|
||||
textDecoration = aCopy.textDecoration;
|
||||
|
||||
textAlign = aCopy.textAlign;
|
||||
whiteSpace = aCopy.whiteSpace;
|
||||
|
||||
// lineHeight = aCopy.lineHeight;
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class StyleContextImpl : public nsIStyleContext {
|
||||
public:
|
||||
StyleContextImpl(nsIStyleContext* aParent, nsISupportsArray* aRules, nsIPresContext* aPresContext);
|
||||
~StyleContextImpl();
|
||||
|
||||
void* operator new(size_t sz) {
|
||||
void* rv = new char[sz];
|
||||
nsCRT::zero(rv, sz);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsIStyleContext* GetParent(void) const;
|
||||
virtual nsISupportsArray* GetStyleRules(void) const;
|
||||
|
||||
virtual PRBool Equals(const nsIStyleContext* aOther) const;
|
||||
virtual PRUint32 HashValue(void) const;
|
||||
|
||||
virtual nsStyleStruct* GetData(const nsIID& aSID);
|
||||
|
||||
virtual void InheritFrom(const StyleContextImpl& aParent);
|
||||
|
||||
virtual void HackStyleFor(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aFrame);
|
||||
|
||||
nsIStyleContext* mParent;
|
||||
PRUint32 mHashValid: 1;
|
||||
PRUint32 mHashValue: 31;
|
||||
nsISupportsArray* mRules;
|
||||
|
||||
// the style data...
|
||||
StyleFontImpl mFont;
|
||||
StyleColorImpl mColor;
|
||||
StyleListImpl mList;
|
||||
// xxx backward support hack
|
||||
StyleMoleculeImpl mMolecule;
|
||||
};
|
||||
|
||||
StyleContextImpl::StyleContextImpl(nsIStyleContext* aParent, nsISupportsArray* aRules,
|
||||
nsIPresContext* aPresContext)
|
||||
: mParent(aParent), // weak ref
|
||||
mRules(aRules),
|
||||
mFont(aPresContext->GetDefaultFont()),
|
||||
mColor(),
|
||||
mList(),
|
||||
mMolecule()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_IF_ADDREF(mRules);
|
||||
|
||||
if (nsnull != aParent) {
|
||||
InheritFrom((StyleContextImpl&)*aParent);
|
||||
}
|
||||
|
||||
if (nsnull != mRules) {
|
||||
PRInt32 index = mRules->Count();
|
||||
while (0 < index) {
|
||||
nsIStyleRule* rule = (nsIStyleRule*)mRules->ElementAt(--index);
|
||||
rule->MapStyleInto(this, aPresContext);
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StyleContextImpl::~StyleContextImpl()
|
||||
{
|
||||
mParent = nsnull; // weak ref
|
||||
NS_IF_RELEASE(mRules);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(StyleContextImpl, kIStyleContextIID)
|
||||
|
||||
nsIStyleContext* StyleContextImpl::GetParent(void) const
|
||||
{
|
||||
NS_IF_ADDREF(mParent);
|
||||
return mParent;
|
||||
}
|
||||
|
||||
nsISupportsArray* StyleContextImpl::GetStyleRules(void) const
|
||||
{
|
||||
NS_IF_ADDREF(mRules);
|
||||
return mRules;
|
||||
}
|
||||
|
||||
|
||||
PRBool StyleContextImpl::Equals(const nsIStyleContext* aOther) const
|
||||
{
|
||||
PRBool result = PR_TRUE;
|
||||
const StyleContextImpl* other = (StyleContextImpl*)aOther;
|
||||
|
||||
if (other != this) {
|
||||
if (mParent != other->mParent) {
|
||||
result = PR_FALSE;
|
||||
}
|
||||
else {
|
||||
if ((nsnull != mRules) && (nsnull != other->mRules)) {
|
||||
result = mRules->Equals(other->mRules);
|
||||
}
|
||||
else {
|
||||
result = PRBool((nsnull == mRules) && (nsnull == other->mRules));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PRUint32 StyleContextImpl::HashValue(void) const
|
||||
{
|
||||
if (0 == mHashValid) {
|
||||
((StyleContextImpl*)this)->mHashValue = ((nsnull != mParent) ? mParent->HashValue() : 0);
|
||||
if (nsnull != mRules) {
|
||||
PRInt32 index = mRules->Count();
|
||||
while (0 <= --index) {
|
||||
nsIStyleRule* rule = (nsIStyleRule*)mRules->ElementAt(index);
|
||||
PRUint32 hash = rule->HashValue();
|
||||
((StyleContextImpl*)this)->mHashValue ^= (hash & 0x7FFFFFFF);
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
}
|
||||
((StyleContextImpl*)this)->mHashValid = 1;
|
||||
}
|
||||
return mHashValue;
|
||||
}
|
||||
|
||||
|
||||
nsStyleStruct* StyleContextImpl::GetData(const nsIID& aSID)
|
||||
{
|
||||
if (aSID.Equals(kStyleFontSID)) {
|
||||
return &mFont;
|
||||
}
|
||||
if (aSID.Equals(kStyleColorSID)) {
|
||||
return &mColor;
|
||||
}
|
||||
if (aSID.Equals(kStyleListSID)) {
|
||||
return &mList;
|
||||
}
|
||||
if (aSID.Equals(kStyleMoleculeSID)) {
|
||||
return &mMolecule;
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
void StyleContextImpl::InheritFrom(const StyleContextImpl& aParent)
|
||||
{
|
||||
mFont.InheritFrom(aParent.mFont);
|
||||
mColor.InheritFrom(aParent.mColor);
|
||||
mList.InheritFrom(aParent.mList);
|
||||
mMolecule.InheritFrom(aParent.mMolecule);
|
||||
}
|
||||
|
||||
void StyleContextImpl::HackStyleFor(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParentFrame)
|
||||
{
|
||||
/*
|
||||
mColor.mColor = NS_RGB(0, 0, 0);
|
||||
*/
|
||||
|
||||
mMolecule.display = NS_STYLE_DISPLAY_BLOCK;
|
||||
mMolecule.whiteSpace = NS_STYLE_WHITESPACE_NORMAL;
|
||||
mMolecule.verticalAlign = NS_STYLE_VERTICAL_ALIGN_BASELINE;
|
||||
mMolecule.textAlign = NS_STYLE_TEXT_ALIGN_LEFT;
|
||||
|
||||
mMolecule.positionFlags = NS_STYLE_POSITION_STATIC;
|
||||
mMolecule.floats = 0;
|
||||
|
||||
// XXX If it's a B guy then make it inline
|
||||
nsIAtom* tag = aContent->GetTag();
|
||||
nsAutoString buf;
|
||||
if (tag != nsnull) {
|
||||
tag->ToString(buf);
|
||||
NS_RELEASE(tag);
|
||||
if (buf.EqualsIgnoreCase("B")) {
|
||||
// float p2t = aPresContext->GetPixelsToTwips();
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
// mColor.mBackgroundColor = NS_RGB(128, 128, 255);
|
||||
// mColor.mBackgroundFlags = 0;
|
||||
// mMolecule.border.top = nscoord(5 * p2t);
|
||||
// mMolecule.border.right = nscoord(5 * p2t);
|
||||
// mMolecule.border.bottom = nscoord(5 * p2t);
|
||||
// mMolecule.border.left = nscoord(5 * p2t);
|
||||
// for (int i = 0; i < 4; i++) {
|
||||
// mMolecule.borderStyle[i] = NS_STYLE_BORDER_STYLE_INSET;
|
||||
// mMolecule.borderColor[i] = NS_RGB(128, 128, 128);
|
||||
// }
|
||||
} else if (buf.EqualsIgnoreCase("A")) {
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
mMolecule.cursor = NS_STYLE_CURSOR_HAND;
|
||||
} else if (buf.EqualsIgnoreCase("BR")) {
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
nsString align("CLEAR");
|
||||
nsString value;
|
||||
if (eContentAttr_HasValue == aContent->GetAttribute(align, value)) {
|
||||
if (0 == value.Compare("left", PR_TRUE)) {
|
||||
mMolecule.clear = NS_STYLE_CLEAR_LEFT;
|
||||
} else if (0 == value.Compare("right", PR_TRUE)) {
|
||||
mMolecule.clear = NS_STYLE_CLEAR_RIGHT;
|
||||
} else if (0 == value.Compare("all", PR_TRUE)) {
|
||||
mMolecule.clear = NS_STYLE_CLEAR_BOTH;
|
||||
}
|
||||
}
|
||||
} else if (buf.EqualsIgnoreCase("SPACER")) {
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
} else if (buf.EqualsIgnoreCase("WBR")) {
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
} else if (buf.EqualsIgnoreCase("INPUT")) {
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
} else if (buf.EqualsIgnoreCase("I")) {
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
} else if (buf.EqualsIgnoreCase("S")) {
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
} else if (buf.EqualsIgnoreCase("PRE")) {
|
||||
mMolecule.whiteSpace = NS_STYLE_WHITESPACE_PRE;
|
||||
mMolecule.margin.top = NS_POINTS_TO_TWIPS_INT(3);
|
||||
mMolecule.margin.bottom = NS_POINTS_TO_TWIPS_INT(3);
|
||||
// mColor.mBackgroundImage = "resource:/res/gear1.gif";
|
||||
// mColor.mBackgroundRepeat = NS_STYLE_BG_REPEAT_XY;
|
||||
} else if (buf.EqualsIgnoreCase("U")) {
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
} else if (buf.EqualsIgnoreCase("FONT")) {
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
} else if (buf.EqualsIgnoreCase("THREED")) {
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
mFont.mThreeD = 1;
|
||||
} else if (buf.EqualsIgnoreCase("TT")) {
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
// mFont.mFont.name.SetLength(0);
|
||||
// mFont.mFont.name.Append("Courier");
|
||||
// mMolecule.positionFlags = NS_STYLE_POSITION_RELATIVE;
|
||||
// mMolecule.left = -50;
|
||||
// mMolecule.top = -50;
|
||||
} else if (buf.EqualsIgnoreCase("IMG")) {
|
||||
float p2t = aPresContext->GetPixelsToTwips();
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
mMolecule.padding.top = nscoord(2 * p2t);
|
||||
mMolecule.padding.right = nscoord(2 * p2t);
|
||||
mMolecule.padding.bottom = nscoord(2 * p2t);
|
||||
mMolecule.padding.left = nscoord(2 * p2t);
|
||||
nsString align("ALIGN");
|
||||
nsString value;
|
||||
if (eContentAttr_HasValue == aContent->GetAttribute(align, value)) {
|
||||
if (0 == value.Compare("left", PR_TRUE)) {
|
||||
mMolecule.floats = NS_STYLE_FLOAT_LEFT;
|
||||
} else if (0 == value.Compare("right", PR_TRUE)) {
|
||||
mMolecule.floats = NS_STYLE_FLOAT_RIGHT;
|
||||
}
|
||||
}
|
||||
} else if (buf.EqualsIgnoreCase("P")) {
|
||||
// mMolecule.textAlign = NS_STYLE_TEXT_ALIGN_CENTER;
|
||||
mMolecule.margin.top = NS_POINTS_TO_TWIPS_INT(2);
|
||||
mMolecule.margin.bottom = NS_POINTS_TO_TWIPS_INT(2);
|
||||
} else if (buf.EqualsIgnoreCase("BODY")) {
|
||||
float p2t = aPresContext->GetPixelsToTwips();
|
||||
// mColor.mBackgroundColor = NS_RGB(255, 255, 255);
|
||||
// mColor.mBackgroundFlags = 0;
|
||||
//mColor.mBackgroundFlags = 0;
|
||||
//mColor.mBackgroundImage = "resource:/res/rock_gra.gif";
|
||||
//mColor.mBackgroundRepeat = NS_STYLE_BG_REPEAT_XY;
|
||||
mMolecule.padding.top = nscoord(5 * p2t);
|
||||
mMolecule.padding.right = nscoord(5 * p2t);
|
||||
mMolecule.padding.bottom = nscoord(5 * p2t);
|
||||
mMolecule.padding.left = nscoord(5 * p2t);
|
||||
mMolecule.border.top = nscoord(1 * p2t);
|
||||
mMolecule.border.right = nscoord(1 * p2t);
|
||||
mMolecule.border.bottom = nscoord(1 * p2t);
|
||||
mMolecule.border.left = nscoord(1 * p2t);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
mMolecule.borderStyle[i] = NS_STYLE_BORDER_STYLE_SOLID;
|
||||
mMolecule.borderColor[i] = NS_RGB(0, 255, 0);
|
||||
}
|
||||
} else if (buf.EqualsIgnoreCase("LI")) {
|
||||
mMolecule.display = NS_STYLE_DISPLAY_LIST_ITEM;
|
||||
} else if (buf.EqualsIgnoreCase("UL") || buf.EqualsIgnoreCase("OL")) {
|
||||
float p2t = aPresContext->GetPixelsToTwips();
|
||||
mMolecule.padding.left = nscoord(40 * p2t);
|
||||
mMolecule.margin.top = NS_POINTS_TO_TWIPS_INT(5);
|
||||
mMolecule.margin.bottom = NS_POINTS_TO_TWIPS_INT(5);
|
||||
} else if (buf.EqualsIgnoreCase("TABLE")) { // TABLE
|
||||
mMolecule.border.top = NS_POINTS_TO_TWIPS_INT(1);
|
||||
mMolecule.border.bottom = NS_POINTS_TO_TWIPS_INT(1);
|
||||
mMolecule.border.right = NS_POINTS_TO_TWIPS_INT(1);
|
||||
mMolecule.border.left = NS_POINTS_TO_TWIPS_INT(1);
|
||||
mMolecule.borderStyle[0] = mMolecule.borderStyle[1] =
|
||||
mMolecule.borderStyle[2] = mMolecule.borderStyle[3] = NS_STYLE_BORDER_STYLE_SOLID;
|
||||
mMolecule.fixedWidth = -1;
|
||||
mMolecule.proportionalWidth = 100;
|
||||
nsString align("ALIGN");
|
||||
nsString value;
|
||||
if (eContentAttr_HasValue == aContent->GetAttribute(align, value)) {
|
||||
if (0 == value.Compare("left", PR_TRUE)) {
|
||||
mMolecule.floats = NS_STYLE_FLOAT_LEFT;
|
||||
} else if (0 == value.Compare("right", PR_TRUE)) {
|
||||
mMolecule.floats = NS_STYLE_FLOAT_RIGHT;
|
||||
}
|
||||
}
|
||||
} else if (buf.EqualsIgnoreCase("CAPTION")) { // CAPTION
|
||||
mMolecule.verticalAlign = NS_STYLE_VERTICAL_ALIGN_TOP;
|
||||
} else if (buf.EqualsIgnoreCase("TBODY")) { // TBODY
|
||||
mMolecule.padding.top = NS_POINTS_TO_TWIPS_INT(1);
|
||||
mMolecule.padding.bottom = NS_POINTS_TO_TWIPS_INT(1);
|
||||
mMolecule.padding.right = NS_POINTS_TO_TWIPS_INT(1);
|
||||
mMolecule.padding.left = NS_POINTS_TO_TWIPS_INT(1);
|
||||
} else if (buf.EqualsIgnoreCase("TR")) { // TROW
|
||||
mMolecule.padding.top = NS_POINTS_TO_TWIPS_INT(1);
|
||||
mMolecule.padding.bottom = NS_POINTS_TO_TWIPS_INT(1);
|
||||
mMolecule.padding.right = NS_POINTS_TO_TWIPS_INT(1);
|
||||
mMolecule.padding.left = NS_POINTS_TO_TWIPS_INT(1);
|
||||
} else if (buf.EqualsIgnoreCase("TD")) { // TD
|
||||
float p2t = aPresContext->GetPixelsToTwips();
|
||||
|
||||
|
||||
// Set padding to twenty for testing purposes
|
||||
int cellPadding = 1;
|
||||
if (gsDebug==PR_TRUE)
|
||||
cellPadding = 20;
|
||||
mMolecule.verticalAlign = NS_STYLE_VERTICAL_ALIGN_MIDDLE;
|
||||
|
||||
mMolecule.padding.top = NS_POINTS_TO_TWIPS_INT(cellPadding);
|
||||
mMolecule.padding.bottom = NS_POINTS_TO_TWIPS_INT(cellPadding);
|
||||
mMolecule.padding.right = NS_POINTS_TO_TWIPS_INT(cellPadding);
|
||||
mMolecule.padding.left = NS_POINTS_TO_TWIPS_INT(cellPadding);
|
||||
// mColor.mBackgroundColor = NS_RGB(255, 255, 0);
|
||||
// mColor.mBackgroundFlags = 0;
|
||||
mMolecule.border.top = nscoord(1 * p2t);
|
||||
mMolecule.border.right = nscoord(1 * p2t);
|
||||
mMolecule.border.bottom = nscoord(1 * p2t);
|
||||
mMolecule.border.left = nscoord(1 * p2t);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
mMolecule.borderStyle[i] = NS_STYLE_BORDER_STYLE_SOLID;
|
||||
mMolecule.borderColor[i] = NS_RGB(128, 128, 128);
|
||||
}
|
||||
mMolecule.fixedWidth = -1;
|
||||
mMolecule.proportionalWidth = -1;
|
||||
mMolecule.fixedHeight = -1;
|
||||
mMolecule.proportionalHeight = -1;
|
||||
|
||||
} else if (buf.EqualsIgnoreCase("COL")) {
|
||||
mMolecule.fixedWidth = -1;
|
||||
mMolecule.proportionalWidth = -1;
|
||||
mMolecule.fixedHeight = -1;
|
||||
mMolecule.proportionalHeight = -1;
|
||||
}
|
||||
} else {
|
||||
// It's text (!)
|
||||
mMolecule.display = NS_STYLE_DISPLAY_INLINE;
|
||||
mMolecule.cursor = NS_STYLE_CURSOR_IBEAM;
|
||||
nsIContent* content = aParentFrame->GetContent();
|
||||
nsIAtom* parentTag = content->GetTag();
|
||||
parentTag->ToString(buf);
|
||||
NS_RELEASE(content);
|
||||
NS_RELEASE(parentTag);
|
||||
if (buf.EqualsIgnoreCase("B")) {
|
||||
// mFont.mFont.size = NS_POINTS_TO_TWIPS_INT(18);
|
||||
// mFont.mFont.weight = NS_FONT_WEIGHT_BOLD;
|
||||
} else if (buf.EqualsIgnoreCase("A")) {
|
||||
// mColor.mColor = NS_RGB(0,0,255);
|
||||
// mFont.mFont.decorations = NS_FONT_DECORATION_UNDERLINE;
|
||||
// This simulates a <PRE><A>text inheritance rule
|
||||
// Check the parent of the A
|
||||
nsIFrame* parentParentFrame = aParentFrame->GetGeometricParent();
|
||||
if (nsnull != parentParentFrame) {
|
||||
nsIContent* parentParentContent = parentParentFrame->GetContent();
|
||||
nsIAtom* parentParentTag = parentParentContent->GetTag();
|
||||
parentParentTag->ToString(buf);
|
||||
NS_RELEASE(parentParentTag);
|
||||
NS_RELEASE(parentParentContent);
|
||||
if (buf.EqualsIgnoreCase("PRE")) {
|
||||
mMolecule.whiteSpace = NS_STYLE_WHITESPACE_PRE;
|
||||
// mFont.mFont.name.SetLength(0);
|
||||
// mFont.mFont.name.Append("Courier");
|
||||
}
|
||||
}
|
||||
} else if (buf.EqualsIgnoreCase("THREED")) {
|
||||
// mFont.mFont.size = NS_POINTS_TO_TWIPS_INT(18);
|
||||
// mFont.mFont.weight = NS_FONT_WEIGHT_BOLD;
|
||||
mFont.mThreeD = 1;
|
||||
} else if (buf.EqualsIgnoreCase("I")) {
|
||||
// mFont.mFont.style = NS_FONT_STYLE_ITALIC;
|
||||
} else if (buf.EqualsIgnoreCase("BLINK")) {
|
||||
// mFont.mFont.decorations |= NS_STYLE_TEXT_DECORATION_BLINK;
|
||||
} else if (buf.EqualsIgnoreCase("TT")) {
|
||||
// mFont.mFont.name.SetLength(0);
|
||||
// mFont.mFont.name.Append("Courier");
|
||||
} else if (buf.EqualsIgnoreCase("S")) {
|
||||
// mFont.mFont.decorations = NS_FONT_DECORATION_LINE_THROUGH;
|
||||
} else if (buf.EqualsIgnoreCase("U")) {
|
||||
// mFont.mFont.decorations = NS_FONT_DECORATION_UNDERLINE;
|
||||
} else if (buf.EqualsIgnoreCase("PRE")) {
|
||||
mMolecule.whiteSpace = NS_STYLE_WHITESPACE_PRE;
|
||||
// mFont.mFont.name.SetLength(0);
|
||||
// mFont.mFont.name.Append("Courier");
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
if ((NS_STYLE_DISPLAY_BLOCK == mMolecule.display) ||
|
||||
(NS_STYLE_DISPLAY_LIST_ITEM == mMolecule.display)) {
|
||||
// Always justify text (take that ie)
|
||||
mMolecule.textAlign = NS_STYLE_TEXT_ALIGN_JUSTIFY;
|
||||
}
|
||||
#endif
|
||||
|
||||
mMolecule.borderPadding.top =
|
||||
mMolecule.border.top + mMolecule.padding.top;
|
||||
mMolecule.borderPadding.right =
|
||||
mMolecule.border.right + mMolecule.padding.right;
|
||||
mMolecule.borderPadding.bottom =
|
||||
mMolecule.border.bottom + mMolecule.padding.bottom;
|
||||
mMolecule.borderPadding.left =
|
||||
mMolecule.border.left + mMolecule.padding.left;
|
||||
|
||||
}
|
||||
|
||||
NS_LAYOUT nsresult
|
||||
NS_NewStyleContext(nsIStyleContext** aInstancePtrResult,
|
||||
nsISupportsArray* aRules,
|
||||
nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParentFrame)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
nsIStyleContext* parent = nsnull;
|
||||
if (nsnull != aParentFrame) {
|
||||
parent = aParentFrame->GetStyleContext(aPresContext);
|
||||
NS_ASSERTION(nsnull != parent, "parent frame must have style context");
|
||||
}
|
||||
|
||||
StyleContextImpl* context = new StyleContextImpl(parent, aRules, aPresContext);
|
||||
NS_IF_RELEASE(parent);
|
||||
if (nsnull == context) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
context->HackStyleFor(aPresContext, aContent, aParentFrame);
|
||||
|
||||
return context->QueryInterface(kIStyleContextIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
530
content/base/src/nsStyleSet.cpp
Normal file
530
content/base/src/nsStyleSet.cpp
Normal file
@@ -0,0 +1,530 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsIStyleSet.h"
|
||||
#include "nsIStyleSheet.h"
|
||||
#include "nsIStyleRule.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsHashtable.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kIStyleSetIID, NS_ISTYLE_SET_IID);
|
||||
|
||||
class ContextKey : public nsHashKey {
|
||||
public:
|
||||
ContextKey(nsIStyleContext* aContext);
|
||||
ContextKey(nsIStyleContext* aParent, nsISupportsArray* aRules);
|
||||
~ContextKey(void);
|
||||
|
||||
void SetContext(nsIStyleContext* aContext);
|
||||
|
||||
PRBool Equals(const nsHashKey* aOther) const;
|
||||
PRUint32 HashValue(void) const;
|
||||
nsHashKey* Clone(void) const;
|
||||
|
||||
private:
|
||||
ContextKey(void);
|
||||
ContextKey(const ContextKey& aCopy);
|
||||
ContextKey& operator=(const ContextKey& aCopy) const;
|
||||
|
||||
protected:
|
||||
nsIStyleContext* mContext;
|
||||
nsIStyleContext* mParent;
|
||||
nsISupportsArray* mRules;
|
||||
};
|
||||
|
||||
ContextKey::ContextKey(nsIStyleContext* aContext)
|
||||
: mContext(aContext),
|
||||
mParent(nsnull),
|
||||
mRules(nsnull)
|
||||
{
|
||||
NS_IF_ADDREF(mContext);
|
||||
}
|
||||
|
||||
ContextKey::ContextKey(nsIStyleContext* aParent, nsISupportsArray* aRules)
|
||||
: mContext(nsnull),
|
||||
mParent(aParent),
|
||||
mRules(aRules)
|
||||
{
|
||||
NS_IF_ADDREF(mParent);
|
||||
NS_IF_ADDREF(mRules);
|
||||
}
|
||||
|
||||
ContextKey::ContextKey(const ContextKey& aCopy)
|
||||
: mContext(aCopy.mContext),
|
||||
mParent(aCopy.mParent),
|
||||
mRules(aCopy.mRules)
|
||||
{
|
||||
NS_IF_ADDREF(mContext);
|
||||
NS_IF_ADDREF(mParent);
|
||||
NS_IF_ADDREF(mRules);
|
||||
}
|
||||
|
||||
ContextKey::~ContextKey(void)
|
||||
{
|
||||
NS_IF_RELEASE(mContext);
|
||||
NS_IF_RELEASE(mParent);
|
||||
NS_IF_RELEASE(mRules);
|
||||
}
|
||||
|
||||
void ContextKey::SetContext(nsIStyleContext* aContext)
|
||||
{
|
||||
if (aContext != mContext) {
|
||||
NS_IF_RELEASE(mContext);
|
||||
mContext = aContext;
|
||||
NS_IF_ADDREF(mContext);
|
||||
}
|
||||
NS_IF_RELEASE(mParent);
|
||||
NS_IF_RELEASE(mRules);
|
||||
}
|
||||
|
||||
PRBool ContextKey::Equals(const nsHashKey* aOther) const
|
||||
{
|
||||
PRBool result = PR_TRUE;
|
||||
const ContextKey* other = (const ContextKey*)aOther;
|
||||
|
||||
if (other != this) {
|
||||
if ((nsnull == mContext) || (nsnull == other->mContext) || (mContext != other->mContext)) {
|
||||
nsIStyleContext* otherParent = other->mParent;
|
||||
if ((nsnull == otherParent) && (nsnull != other->mContext)) {
|
||||
otherParent = other->mContext->GetParent();
|
||||
}
|
||||
else {
|
||||
NS_IF_ADDREF(otherParent); // simulate the above addref
|
||||
}
|
||||
|
||||
if (mParent == otherParent) {
|
||||
nsISupportsArray* otherRules = other->mRules;
|
||||
if ((nsnull == otherRules) && (nsnull != other->mContext)) {
|
||||
otherRules = other->mContext->GetStyleRules();
|
||||
}
|
||||
else {
|
||||
NS_IF_ADDREF(otherRules); // simulate the above addref
|
||||
}
|
||||
if ((nsnull != mRules) && (nsnull != otherRules)) {
|
||||
result = mRules->Equals(otherRules);
|
||||
}
|
||||
else {
|
||||
result = PRBool((nsnull == mRules) && (nsnull == otherRules));
|
||||
}
|
||||
NS_IF_RELEASE(otherRules);
|
||||
}
|
||||
else {
|
||||
result = PR_FALSE;
|
||||
}
|
||||
NS_IF_RELEASE(otherParent);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PRUint32 ContextKey::HashValue(void) const
|
||||
{
|
||||
if (nsnull != mContext) {
|
||||
return mContext->HashValue();
|
||||
}
|
||||
// we don't have a context yet, compute it like it would
|
||||
PRUint32 hashValue = ((nsnull != mParent) ? mParent->HashValue() : 0);
|
||||
if (nsnull != mRules) {
|
||||
PRInt32 index = mRules->Count();
|
||||
while (0 <= --index) {
|
||||
nsIStyleRule* rule = (nsIStyleRule*)mRules->ElementAt(index);
|
||||
PRUint32 hash = rule->HashValue();
|
||||
hashValue ^= (hash & 0x7FFFFFFF);
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
}
|
||||
return hashValue;
|
||||
}
|
||||
|
||||
nsHashKey* ContextKey::Clone(void) const
|
||||
{
|
||||
return new ContextKey(*this);
|
||||
}
|
||||
|
||||
|
||||
class StyleSetImpl : public nsIStyleSet {
|
||||
public:
|
||||
StyleSetImpl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual void AppendOverrideStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual void InsertOverrideStyleSheetAfter(nsIStyleSheet* aSheet,
|
||||
nsIStyleSheet* aAfterSheet);
|
||||
virtual void InsertOverrideStyleSheetBefore(nsIStyleSheet* aSheet,
|
||||
nsIStyleSheet* aBeforeSheet);
|
||||
virtual void RemoveOverrideStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual PRInt32 GetNumberOfOverrideStyleSheets();
|
||||
virtual nsIStyleSheet* GetOverrideStyleSheetAt(PRInt32 aIndex);
|
||||
|
||||
virtual void AppendDocStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual void InsertDocStyleSheetAfter(nsIStyleSheet* aSheet,
|
||||
nsIStyleSheet* aAfterSheet);
|
||||
virtual void InsertDocStyleSheetBefore(nsIStyleSheet* aSheet,
|
||||
nsIStyleSheet* aBeforeSheet);
|
||||
virtual void RemoveDocStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual PRInt32 GetNumberOfDocStyleSheets();
|
||||
virtual nsIStyleSheet* GetDocStyleSheetAt(PRInt32 aIndex);
|
||||
|
||||
virtual void AppendBackstopStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual void InsertBackstopStyleSheetAfter(nsIStyleSheet* aSheet,
|
||||
nsIStyleSheet* aAfterSheet);
|
||||
virtual void InsertBackstopStyleSheetBefore(nsIStyleSheet* aSheet,
|
||||
nsIStyleSheet* aBeforeSheet);
|
||||
virtual void RemoveBackstopStyleSheet(nsIStyleSheet* aSheet);
|
||||
virtual PRInt32 GetNumberOfBackstopStyleSheets();
|
||||
virtual nsIStyleSheet* GetBackstopStyleSheetAt(PRInt32 aIndex);
|
||||
|
||||
virtual nsIStyleContext* ResolveStyleFor(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParentFrame);
|
||||
|
||||
// xxx style rules enumeration
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0);
|
||||
|
||||
private:
|
||||
// These are not supported and are not implemented!
|
||||
StyleSetImpl(const StyleSetImpl& aCopy);
|
||||
StyleSetImpl& operator=(const StyleSetImpl& aCopy);
|
||||
|
||||
protected:
|
||||
virtual ~StyleSetImpl();
|
||||
PRBool EnsureArray(nsISupportsArray** aArray);
|
||||
PRInt32 RulesMatching(nsISupportsArray* aSheets,
|
||||
nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParentFrame,
|
||||
nsISupportsArray* aResults);
|
||||
void List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets);
|
||||
|
||||
nsISupportsArray* mOverrideSheets;
|
||||
nsISupportsArray* mDocSheets;
|
||||
nsISupportsArray* mBackstopSheets;
|
||||
nsHashtable mStyleContexts;
|
||||
};
|
||||
|
||||
|
||||
StyleSetImpl::StyleSetImpl()
|
||||
: mOverrideSheets(nsnull),
|
||||
mDocSheets(nsnull),
|
||||
mBackstopSheets(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
PRBool ReleaseContext(nsHashKey *aKey, void *aData)
|
||||
{
|
||||
((nsIStyleContext*)aData)->Release();
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
StyleSetImpl::~StyleSetImpl()
|
||||
{
|
||||
NS_IF_RELEASE(mOverrideSheets);
|
||||
NS_IF_RELEASE(mDocSheets);
|
||||
NS_IF_RELEASE(mBackstopSheets);
|
||||
mStyleContexts.Enumerate(ReleaseContext);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(StyleSetImpl, kIStyleSetIID)
|
||||
|
||||
PRBool StyleSetImpl::EnsureArray(nsISupportsArray** aArray)
|
||||
{
|
||||
if (nsnull == *aArray) {
|
||||
if (NS_OK != NS_NewISupportsArray(aArray)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
// ----- Override sheets
|
||||
|
||||
void StyleSetImpl::AppendOverrideStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
if (EnsureArray(&mOverrideSheets)) {
|
||||
mOverrideSheets->AppendElement(aSheet);
|
||||
}
|
||||
}
|
||||
|
||||
void StyleSetImpl::InsertOverrideStyleSheetAfter(nsIStyleSheet* aSheet,
|
||||
nsIStyleSheet* aAfterSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
if (EnsureArray(&mOverrideSheets)) {
|
||||
PRInt32 index = mOverrideSheets->IndexOf(aAfterSheet);
|
||||
mOverrideSheets->InsertElementAt(aSheet, ++index);
|
||||
}
|
||||
}
|
||||
|
||||
void StyleSetImpl::InsertOverrideStyleSheetBefore(nsIStyleSheet* aSheet,
|
||||
nsIStyleSheet* aBeforeSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
if (EnsureArray(&mOverrideSheets)) {
|
||||
PRInt32 index = mOverrideSheets->IndexOf(aBeforeSheet);
|
||||
mOverrideSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0));
|
||||
}
|
||||
}
|
||||
|
||||
void StyleSetImpl::RemoveOverrideStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
|
||||
if (nsnull != mOverrideSheets) {
|
||||
mOverrideSheets->RemoveElement(aSheet);
|
||||
}
|
||||
}
|
||||
|
||||
PRInt32 StyleSetImpl::GetNumberOfOverrideStyleSheets()
|
||||
{
|
||||
if (nsnull != mOverrideSheets) {
|
||||
return mOverrideSheets->Count();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsIStyleSheet* StyleSetImpl::GetOverrideStyleSheetAt(PRInt32 aIndex)
|
||||
{
|
||||
nsIStyleSheet* sheet = nsnull;
|
||||
if (nsnull == mOverrideSheets) {
|
||||
sheet = (nsIStyleSheet*)mOverrideSheets->ElementAt(aIndex);
|
||||
}
|
||||
return sheet;
|
||||
}
|
||||
|
||||
// -------- Doc Sheets
|
||||
|
||||
void StyleSetImpl::AppendDocStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
if (EnsureArray(&mDocSheets)) {
|
||||
mDocSheets->AppendElement(aSheet);
|
||||
}
|
||||
}
|
||||
|
||||
void StyleSetImpl::InsertDocStyleSheetAfter(nsIStyleSheet* aSheet,
|
||||
nsIStyleSheet* aAfterSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
if (EnsureArray(&mDocSheets)) {
|
||||
PRInt32 index = mDocSheets->IndexOf(aAfterSheet);
|
||||
mDocSheets->InsertElementAt(aSheet, ++index);
|
||||
}
|
||||
}
|
||||
|
||||
void StyleSetImpl::InsertDocStyleSheetBefore(nsIStyleSheet* aSheet,
|
||||
nsIStyleSheet* aBeforeSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
if (EnsureArray(&mDocSheets)) {
|
||||
PRInt32 index = mDocSheets->IndexOf(aBeforeSheet);
|
||||
mDocSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0));
|
||||
}
|
||||
}
|
||||
|
||||
void StyleSetImpl::RemoveDocStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
|
||||
if (nsnull != mDocSheets) {
|
||||
mDocSheets->RemoveElement(aSheet);
|
||||
}
|
||||
}
|
||||
|
||||
PRInt32 StyleSetImpl::GetNumberOfDocStyleSheets()
|
||||
{
|
||||
if (nsnull != mDocSheets) {
|
||||
return mDocSheets->Count();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsIStyleSheet* StyleSetImpl::GetDocStyleSheetAt(PRInt32 aIndex)
|
||||
{
|
||||
nsIStyleSheet* sheet = nsnull;
|
||||
if (nsnull == mDocSheets) {
|
||||
sheet = (nsIStyleSheet*)mDocSheets->ElementAt(aIndex);
|
||||
}
|
||||
return sheet;
|
||||
}
|
||||
|
||||
// ------ backstop sheets
|
||||
|
||||
void StyleSetImpl::AppendBackstopStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
if (EnsureArray(&mBackstopSheets)) {
|
||||
mBackstopSheets->AppendElement(aSheet);
|
||||
}
|
||||
}
|
||||
|
||||
void StyleSetImpl::InsertBackstopStyleSheetAfter(nsIStyleSheet* aSheet,
|
||||
nsIStyleSheet* aAfterSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
if (EnsureArray(&mBackstopSheets)) {
|
||||
PRInt32 index = mBackstopSheets->IndexOf(aAfterSheet);
|
||||
mBackstopSheets->InsertElementAt(aSheet, ++index);
|
||||
}
|
||||
}
|
||||
|
||||
void StyleSetImpl::InsertBackstopStyleSheetBefore(nsIStyleSheet* aSheet,
|
||||
nsIStyleSheet* aBeforeSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
if (EnsureArray(&mBackstopSheets)) {
|
||||
PRInt32 index = mBackstopSheets->IndexOf(aBeforeSheet);
|
||||
mBackstopSheets->InsertElementAt(aSheet, ((-1 < index) ? index : 0));
|
||||
}
|
||||
}
|
||||
|
||||
void StyleSetImpl::RemoveBackstopStyleSheet(nsIStyleSheet* aSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
|
||||
if (nsnull != mBackstopSheets) {
|
||||
mBackstopSheets->RemoveElement(aSheet);
|
||||
}
|
||||
}
|
||||
|
||||
PRInt32 StyleSetImpl::GetNumberOfBackstopStyleSheets()
|
||||
{
|
||||
if (nsnull != mBackstopSheets) {
|
||||
return mBackstopSheets->Count();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsIStyleSheet* StyleSetImpl::GetBackstopStyleSheetAt(PRInt32 aIndex)
|
||||
{
|
||||
nsIStyleSheet* sheet = nsnull;
|
||||
if (nsnull == mBackstopSheets) {
|
||||
sheet = (nsIStyleSheet*)mBackstopSheets->ElementAt(aIndex);
|
||||
}
|
||||
return sheet;
|
||||
}
|
||||
|
||||
PRInt32 StyleSetImpl::RulesMatching(nsISupportsArray* aSheets,
|
||||
nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParentFrame,
|
||||
nsISupportsArray* aResults)
|
||||
{
|
||||
PRInt32 ruleCount = 0;
|
||||
|
||||
if (nsnull != aSheets) {
|
||||
PRInt32 sheetCount = aSheets->Count();
|
||||
PRInt32 index;
|
||||
for (index = 0; index < sheetCount; index++) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheets->ElementAt(index);
|
||||
ruleCount += sheet->RulesMatching(aPresContext, aContent, aParentFrame,
|
||||
aResults);
|
||||
NS_RELEASE(sheet);
|
||||
}
|
||||
}
|
||||
return ruleCount;
|
||||
}
|
||||
|
||||
nsIStyleContext* StyleSetImpl::ResolveStyleFor(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParentFrame)
|
||||
{
|
||||
nsIStyleContext* result = nsnull;
|
||||
|
||||
nsIStyleContext* parentContext = nsnull;
|
||||
|
||||
if (nsnull != aParentFrame) {
|
||||
parentContext = aParentFrame->GetStyleContext(aPresContext);
|
||||
NS_ASSERTION(nsnull != parentContext, "parent must have style context");
|
||||
}
|
||||
|
||||
// want to check parent frame's context for cached child context first
|
||||
|
||||
// then do a brute force rule search
|
||||
|
||||
nsISupportsArray* rules = nsnull;
|
||||
if (NS_OK == NS_NewISupportsArray(&rules)) {
|
||||
PRInt32 ruleCount = RulesMatching(mOverrideSheets, aPresContext, aContent, aParentFrame, rules);
|
||||
ruleCount += RulesMatching(mDocSheets, aPresContext, aContent, aParentFrame, rules);
|
||||
ruleCount += RulesMatching(mBackstopSheets, aPresContext, aContent, aParentFrame, rules);
|
||||
|
||||
// then check for cached ruleSet to context or create
|
||||
ContextKey tempKey(parentContext, rules);
|
||||
result = (nsIStyleContext*)mStyleContexts.Get(&tempKey);
|
||||
if (nsnull == result) {
|
||||
if (NS_OK == NS_NewStyleContext(&result, rules, aPresContext, aContent, aParentFrame)) {
|
||||
tempKey.SetContext(result);
|
||||
mStyleContexts.Put(&tempKey, result); // hashtable clones key, so this is OK (table gets first ref)
|
||||
NS_ADDREF(result); // add ref for the caller
|
||||
//fprintf(stdout, "+");
|
||||
}
|
||||
}
|
||||
else {
|
||||
NS_ADDREF(result);
|
||||
//fprintf(stdout, "-");
|
||||
}
|
||||
NS_RELEASE(rules);
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(parentContext);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// xxx style rules enumeration
|
||||
|
||||
void StyleSetImpl::List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets)
|
||||
{
|
||||
PRInt32 count = ((nsnull != aSheets) ? aSheets->Count() : 0);
|
||||
|
||||
for (PRInt32 index = 0; index < count; index++) {
|
||||
nsIStyleSheet* sheet = (nsIStyleSheet*)aSheets->ElementAt(index);
|
||||
sheet->List(out, aIndent);
|
||||
fputs("\n", out);
|
||||
NS_RELEASE(sheet);
|
||||
}
|
||||
}
|
||||
|
||||
void StyleSetImpl::List(FILE* out, PRInt32 aIndent)
|
||||
{
|
||||
List(out, aIndent, mOverrideSheets);
|
||||
List(out, aIndent, mDocSheets);
|
||||
List(out, aIndent, mBackstopSheets);
|
||||
}
|
||||
|
||||
|
||||
NS_LAYOUT nsresult
|
||||
NS_NewStyleSet(nsIStyleSet** aInstancePtrResult)
|
||||
{
|
||||
if (aInstancePtrResult == nsnull) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
StyleSetImpl *it = new StyleSetImpl();
|
||||
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kIStyleSetIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
89
content/html/content/public/nsIHTMLContent.h
Normal file
89
content/html/content/public/nsIHTMLContent.h
Normal file
@@ -0,0 +1,89 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIHTMLContent_h___
|
||||
#define nsIHTMLContent_h___
|
||||
|
||||
#include "nsIContent.h"
|
||||
#include "nsHTMLValue.h"
|
||||
class nsString;
|
||||
class nsIFrame;
|
||||
class nsISupportsArray;
|
||||
class nsIStyleRule;
|
||||
class nsIStyleContext;
|
||||
class nsIPresContext;
|
||||
|
||||
// IID for the nsIHTMLContent class
|
||||
#define NS_IHTMLCONTENT_IID \
|
||||
{ 0xb9e110b0, 0x94d6, 0x11d1, \
|
||||
{0x89, 0x5c, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
|
||||
|
||||
// Abstract interface for all html content
|
||||
class nsIHTMLContent : public nsIContent {
|
||||
public:
|
||||
/**
|
||||
* If this html content is a container, then compact asks it to minimize
|
||||
* it's storage usage.
|
||||
*/
|
||||
virtual void Compact() = 0;
|
||||
|
||||
virtual void SetAttribute(const nsString& aName, const nsString& aValue) = 0;
|
||||
virtual void SetAttribute(nsIAtom* aAttribute, const nsString& aValue) = 0;
|
||||
virtual void SetAttribute(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue=nsHTMLValue::kNull) = 0;
|
||||
|
||||
virtual void UnsetAttribute(nsIAtom* aAttribute) = 0;
|
||||
|
||||
virtual nsContentAttr GetAttribute(const nsString& aName,
|
||||
nsString& aResult) const = 0;
|
||||
virtual nsContentAttr GetAttribute(nsIAtom* aAttribute,
|
||||
nsHTMLValue& aValue) const = 0;
|
||||
virtual PRInt32 GetAllAttributeNames(nsISupportsArray* aArray) const = 0;
|
||||
virtual PRInt32 GetAttributeCount(void) const = 0;
|
||||
|
||||
virtual void SetID(nsIAtom* aID) = 0;
|
||||
virtual nsIAtom* GetID(void) const = 0;
|
||||
virtual void SetClass(nsIAtom* aClass) = 0; // XXX this will have to change for CSS2
|
||||
virtual nsIAtom* GetClass(void) const = 0; // XXX this will have to change for CSS2
|
||||
|
||||
virtual nsIStyleRule* GetStyleRule(void) = 0;
|
||||
|
||||
virtual void MapAttributesInto(nsIStyleContext* aContext,
|
||||
nsIPresContext* aPresContext) = 0;
|
||||
|
||||
/**
|
||||
* Translate this piece of content to html. Note that this only
|
||||
* translates this content object, not any children it might
|
||||
* have. The caller is responsible for recursing down the
|
||||
* hierarchy.
|
||||
*/
|
||||
// XXX add in output character set information so that we know how
|
||||
// to encode non 7 bit characters
|
||||
virtual void ToHTMLString(nsString& aResult) const = 0;
|
||||
|
||||
virtual void ToHTML(FILE* out) const = 0;
|
||||
|
||||
/**
|
||||
* Used by the html content's delegate to create a frame
|
||||
* for the content.
|
||||
*/
|
||||
virtual nsIFrame* CreateFrame(nsIPresContext* aPresContext,
|
||||
PRInt32 aIndexInParent,
|
||||
nsIFrame* aParentFrame) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsIHTMLContent_h___ */
|
||||
367
content/html/content/src/nsHTMLAtoms.cpp
Normal file
367
content/html/content/src/nsHTMLAtoms.cpp
Normal file
@@ -0,0 +1,367 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsHTMLAtoms.h"
|
||||
|
||||
nsIAtom* nsHTMLAtoms::a;
|
||||
nsIAtom* nsHTMLAtoms::above;
|
||||
nsIAtom* nsHTMLAtoms::action;
|
||||
nsIAtom* nsHTMLAtoms::align;
|
||||
nsIAtom* nsHTMLAtoms::alink;
|
||||
nsIAtom* nsHTMLAtoms::alt;
|
||||
nsIAtom* nsHTMLAtoms::archive;
|
||||
nsIAtom* nsHTMLAtoms::background;
|
||||
nsIAtom* nsHTMLAtoms::below;
|
||||
nsIAtom* nsHTMLAtoms::bgcolor;
|
||||
nsIAtom* nsHTMLAtoms::body;
|
||||
nsIAtom* nsHTMLAtoms::border;
|
||||
nsIAtom* nsHTMLAtoms::bordercolor;
|
||||
nsIAtom* nsHTMLAtoms::bottompadding;
|
||||
nsIAtom* nsHTMLAtoms::br;
|
||||
nsIAtom* nsHTMLAtoms::cellpadding;
|
||||
nsIAtom* nsHTMLAtoms::cellspacing;
|
||||
nsIAtom* nsHTMLAtoms::checked;
|
||||
nsIAtom* nsHTMLAtoms::kClass;
|
||||
nsIAtom* nsHTMLAtoms::classid;
|
||||
nsIAtom* nsHTMLAtoms::clear;
|
||||
nsIAtom* nsHTMLAtoms::clip;
|
||||
nsIAtom* nsHTMLAtoms::code;
|
||||
nsIAtom* nsHTMLAtoms::codebase;
|
||||
nsIAtom* nsHTMLAtoms::color;
|
||||
nsIAtom* nsHTMLAtoms::cols;
|
||||
nsIAtom* nsHTMLAtoms::colspan;
|
||||
nsIAtom* nsHTMLAtoms::compact;
|
||||
nsIAtom* nsHTMLAtoms::coords;
|
||||
nsIAtom* nsHTMLAtoms::data;
|
||||
nsIAtom* nsHTMLAtoms::dir;
|
||||
nsIAtom* nsHTMLAtoms::div;
|
||||
nsIAtom* nsHTMLAtoms::dl;
|
||||
nsIAtom* nsHTMLAtoms::encoding;
|
||||
nsIAtom* nsHTMLAtoms::face;
|
||||
nsIAtom* nsHTMLAtoms::font;
|
||||
nsIAtom* nsHTMLAtoms::fontWeight;
|
||||
nsIAtom* nsHTMLAtoms::frameborder;
|
||||
nsIAtom* nsHTMLAtoms::gutter;
|
||||
nsIAtom* nsHTMLAtoms::h1;
|
||||
nsIAtom* nsHTMLAtoms::h2;
|
||||
nsIAtom* nsHTMLAtoms::h3;
|
||||
nsIAtom* nsHTMLAtoms::h4;
|
||||
nsIAtom* nsHTMLAtoms::h5;
|
||||
nsIAtom* nsHTMLAtoms::h6;
|
||||
nsIAtom* nsHTMLAtoms::height;
|
||||
nsIAtom* nsHTMLAtoms::hidden;
|
||||
nsIAtom* nsHTMLAtoms::href;
|
||||
nsIAtom* nsHTMLAtoms::hspace;
|
||||
nsIAtom* nsHTMLAtoms::httpEquiv;
|
||||
nsIAtom* nsHTMLAtoms::id;
|
||||
nsIAtom* nsHTMLAtoms::ismap;
|
||||
nsIAtom* nsHTMLAtoms::language;
|
||||
nsIAtom* nsHTMLAtoms::li;
|
||||
nsIAtom* nsHTMLAtoms::link;
|
||||
nsIAtom* nsHTMLAtoms::left;
|
||||
nsIAtom* nsHTMLAtoms::leftpadding;
|
||||
nsIAtom* nsHTMLAtoms::lowsrc;
|
||||
nsIAtom* nsHTMLAtoms::marginheight;
|
||||
nsIAtom* nsHTMLAtoms::marginwidth;
|
||||
nsIAtom* nsHTMLAtoms::maxlength;
|
||||
nsIAtom* nsHTMLAtoms::mayscript;
|
||||
nsIAtom* nsHTMLAtoms::menu;
|
||||
nsIAtom* nsHTMLAtoms::method;
|
||||
nsIAtom* nsHTMLAtoms::multicol;
|
||||
nsIAtom* nsHTMLAtoms::multiple;
|
||||
nsIAtom* nsHTMLAtoms::name;
|
||||
nsIAtom* nsHTMLAtoms::noresize;
|
||||
nsIAtom* nsHTMLAtoms::noshade;
|
||||
nsIAtom* nsHTMLAtoms::nowrap;
|
||||
nsIAtom* nsHTMLAtoms::ol;
|
||||
nsIAtom* nsHTMLAtoms::onblur;
|
||||
nsIAtom* nsHTMLAtoms::onfocus;
|
||||
nsIAtom* nsHTMLAtoms::onload;
|
||||
nsIAtom* nsHTMLAtoms::onunload;
|
||||
nsIAtom* nsHTMLAtoms::overflow;
|
||||
nsIAtom* nsHTMLAtoms::p;
|
||||
nsIAtom* nsHTMLAtoms::pagex;
|
||||
nsIAtom* nsHTMLAtoms::pagey;
|
||||
nsIAtom* nsHTMLAtoms::pointSize;
|
||||
nsIAtom* nsHTMLAtoms::pre;
|
||||
nsIAtom* nsHTMLAtoms::prompt;
|
||||
nsIAtom* nsHTMLAtoms::rel;
|
||||
nsIAtom* nsHTMLAtoms::rightpadding;
|
||||
nsIAtom* nsHTMLAtoms::rows;
|
||||
nsIAtom* nsHTMLAtoms::rowspan;
|
||||
nsIAtom* nsHTMLAtoms::scrolling;
|
||||
nsIAtom* nsHTMLAtoms::selected;
|
||||
nsIAtom* nsHTMLAtoms::shape;
|
||||
nsIAtom* nsHTMLAtoms::size;
|
||||
nsIAtom* nsHTMLAtoms::src;
|
||||
nsIAtom* nsHTMLAtoms::start;
|
||||
nsIAtom* nsHTMLAtoms::suppress;
|
||||
nsIAtom* nsHTMLAtoms::tabstop;
|
||||
nsIAtom* nsHTMLAtoms::target;
|
||||
nsIAtom* nsHTMLAtoms::text;
|
||||
nsIAtom* nsHTMLAtoms::top;
|
||||
nsIAtom* nsHTMLAtoms::toppadding;
|
||||
nsIAtom* nsHTMLAtoms::type;
|
||||
nsIAtom* nsHTMLAtoms::ul;
|
||||
nsIAtom* nsHTMLAtoms::usemap;
|
||||
nsIAtom* nsHTMLAtoms::valign;
|
||||
nsIAtom* nsHTMLAtoms::value;
|
||||
nsIAtom* nsHTMLAtoms::variable;
|
||||
nsIAtom* nsHTMLAtoms::visibility;
|
||||
nsIAtom* nsHTMLAtoms::vlink;
|
||||
nsIAtom* nsHTMLAtoms::vspace;
|
||||
nsIAtom* nsHTMLAtoms::width;
|
||||
nsIAtom* nsHTMLAtoms::wrap;
|
||||
nsIAtom* nsHTMLAtoms::zindex;
|
||||
|
||||
|
||||
static nsrefcnt gRefCnt;
|
||||
|
||||
void nsHTMLAtoms::AddrefAtoms()
|
||||
{
|
||||
if (0 == gRefCnt) {
|
||||
a = NS_NewAtom("A");
|
||||
above = NS_NewAtom("ABOVE");
|
||||
action = NS_NewAtom("ACTION");
|
||||
align = NS_NewAtom("ALIGN");
|
||||
alink = NS_NewAtom("ALINK");
|
||||
alt = NS_NewAtom("ALT");
|
||||
archive = NS_NewAtom("ARCHIVE");
|
||||
background = NS_NewAtom("BACKGROUND");
|
||||
below = NS_NewAtom("BELOW");
|
||||
bgcolor = NS_NewAtom("BGCOLOR");
|
||||
body = NS_NewAtom("BODY");
|
||||
border = NS_NewAtom("BORDER");
|
||||
bordercolor = NS_NewAtom("BORDERCOLOR");
|
||||
bottompadding = NS_NewAtom("BOTTOMPADDING");
|
||||
br = NS_NewAtom("BR");
|
||||
cellpadding = NS_NewAtom("CELLPADDING");
|
||||
cellspacing = NS_NewAtom("CELLSPACING");
|
||||
checked = NS_NewAtom("CHECKED");
|
||||
kClass = NS_NewAtom("CLASS");
|
||||
classid = NS_NewAtom("CLASSID");
|
||||
clear = NS_NewAtom("CLEAR");
|
||||
clip = NS_NewAtom("CLIP");
|
||||
code = NS_NewAtom("CODE");
|
||||
codebase = NS_NewAtom("CODEBASE");
|
||||
color = NS_NewAtom("COLOR");
|
||||
cols = NS_NewAtom("COLS");
|
||||
colspan = NS_NewAtom("COLSPAN");
|
||||
compact = NS_NewAtom("COMPACT");
|
||||
coords = NS_NewAtom("COORDS");
|
||||
dir = NS_NewAtom("DIR");
|
||||
div = NS_NewAtom("DIV");
|
||||
dl = NS_NewAtom("DL");
|
||||
data = NS_NewAtom("DATA");
|
||||
encoding = NS_NewAtom("ENCODING");
|
||||
face = NS_NewAtom("FACE");
|
||||
font = NS_NewAtom("FONT");
|
||||
fontWeight = NS_NewAtom("FONT-WEIGHT");
|
||||
frameborder = NS_NewAtom("FRAMEBORDER");
|
||||
gutter = NS_NewAtom("GUTTER");
|
||||
h1 = NS_NewAtom("H1");
|
||||
h2 = NS_NewAtom("H2");
|
||||
h3 = NS_NewAtom("H3");
|
||||
h4 = NS_NewAtom("H4");
|
||||
h5 = NS_NewAtom("H5");
|
||||
h6 = NS_NewAtom("H6");
|
||||
height = NS_NewAtom("HEIGHT");
|
||||
hidden = NS_NewAtom("HIDDEN");
|
||||
href = NS_NewAtom("HREF");
|
||||
hspace = NS_NewAtom("HSPACE");
|
||||
httpEquiv = NS_NewAtom("HTTP-EQUIV");
|
||||
id = NS_NewAtom("ID");
|
||||
ismap = NS_NewAtom("ISMAP");
|
||||
language = NS_NewAtom("LANGUAGE");
|
||||
li = NS_NewAtom("LI");
|
||||
link = NS_NewAtom("LINK");
|
||||
left = NS_NewAtom("LEFT");
|
||||
leftpadding = NS_NewAtom("LEFTPADDING");
|
||||
lowsrc = NS_NewAtom("LOWSRC");
|
||||
marginheight = NS_NewAtom("MARGINHEIGHT");
|
||||
marginwidth = NS_NewAtom("MARGINWIDTH");
|
||||
maxlength = NS_NewAtom("MAXLENGTH");
|
||||
mayscript = NS_NewAtom("MAYSCRIPT");
|
||||
menu = NS_NewAtom("MENU");
|
||||
method = NS_NewAtom("METHOD");
|
||||
multicol = NS_NewAtom("MULTICOL");
|
||||
multiple = NS_NewAtom("MULTIPLE");
|
||||
name = NS_NewAtom("NAME");
|
||||
noresize = NS_NewAtom("NORESIZE");
|
||||
noshade = NS_NewAtom("NOSHADE");
|
||||
nowrap = NS_NewAtom("NOWRAP");
|
||||
ol = NS_NewAtom("OL");
|
||||
onblur = NS_NewAtom("ONBLUR");
|
||||
onfocus = NS_NewAtom("ONFOCUS");
|
||||
onload = NS_NewAtom("ONLOAD");
|
||||
onunload = NS_NewAtom("ONUNLOAD");
|
||||
overflow = NS_NewAtom("OVERFLOW");
|
||||
p = NS_NewAtom("P");
|
||||
pagex = NS_NewAtom("PAGEX");
|
||||
pagey = NS_NewAtom("PAGEY");
|
||||
pointSize = NS_NewAtom("POINT-SIZE");
|
||||
pre = NS_NewAtom("PRE");
|
||||
prompt = NS_NewAtom("PROMPT");
|
||||
rel = NS_NewAtom("REL");
|
||||
rightpadding = NS_NewAtom("RIGHTPADDING");
|
||||
rows = NS_NewAtom("ROWS");
|
||||
rowspan = NS_NewAtom("ROWSPAN");
|
||||
scrolling = NS_NewAtom("SCROLLING");
|
||||
selected = NS_NewAtom("SELECTED");
|
||||
shape = NS_NewAtom("SHAPE");
|
||||
size = NS_NewAtom("SIZE");
|
||||
src = NS_NewAtom("SRC");
|
||||
start = NS_NewAtom("START");
|
||||
suppress = NS_NewAtom("SUPPRESS");
|
||||
tabstop = NS_NewAtom("TABSTOP");
|
||||
target = NS_NewAtom("TARGET");
|
||||
text = NS_NewAtom("TEXT");
|
||||
top = NS_NewAtom("TOP");
|
||||
toppadding = NS_NewAtom("TOPPADDING");
|
||||
type = NS_NewAtom("TYPE");
|
||||
ul = NS_NewAtom("UL");
|
||||
usemap = NS_NewAtom("USEMAP");
|
||||
valign = NS_NewAtom("VALIGN");
|
||||
value = NS_NewAtom("VALUE");
|
||||
variable = NS_NewAtom("VARIABLE");
|
||||
visibility = NS_NewAtom("VISIBILITY");
|
||||
vlink = NS_NewAtom("VLINK");
|
||||
vspace = NS_NewAtom("VSPACE");
|
||||
width = NS_NewAtom("WIDTH");
|
||||
wrap = NS_NewAtom("WRAP");
|
||||
zindex = NS_NewAtom("ZINDEX");
|
||||
}
|
||||
++gRefCnt;
|
||||
}
|
||||
|
||||
void nsHTMLAtoms::ReleaseAtoms()
|
||||
{
|
||||
NS_PRECONDITION(gRefCnt != 0, "bad release atoms");
|
||||
if (--gRefCnt == 0) {
|
||||
NS_RELEASE(a);
|
||||
NS_RELEASE(above);
|
||||
NS_RELEASE(action);
|
||||
NS_RELEASE(align);
|
||||
NS_RELEASE(alink);
|
||||
NS_RELEASE(alt);
|
||||
NS_RELEASE(archive);
|
||||
NS_RELEASE(background);
|
||||
NS_RELEASE(below);
|
||||
NS_RELEASE(bgcolor);
|
||||
NS_RELEASE(body);
|
||||
NS_RELEASE(border);
|
||||
NS_RELEASE(bordercolor);
|
||||
NS_RELEASE(bottompadding);
|
||||
NS_RELEASE(br);
|
||||
NS_RELEASE(cellpadding);
|
||||
NS_RELEASE(cellspacing);
|
||||
NS_RELEASE(checked);
|
||||
NS_RELEASE(kClass);
|
||||
NS_RELEASE(classid);
|
||||
NS_RELEASE(clear);
|
||||
NS_RELEASE(clip);
|
||||
NS_RELEASE(code);
|
||||
NS_RELEASE(codebase);
|
||||
NS_RELEASE(color);
|
||||
NS_RELEASE(cols);
|
||||
NS_RELEASE(colspan);
|
||||
NS_RELEASE(compact);
|
||||
NS_RELEASE(coords);
|
||||
NS_RELEASE(dir);
|
||||
NS_RELEASE(div);
|
||||
NS_RELEASE(dl);
|
||||
NS_RELEASE(data);
|
||||
NS_RELEASE(encoding);
|
||||
NS_RELEASE(face);
|
||||
NS_RELEASE(font);
|
||||
NS_RELEASE(fontWeight);
|
||||
NS_RELEASE(frameborder);
|
||||
NS_RELEASE(gutter);
|
||||
NS_RELEASE(h1);
|
||||
NS_RELEASE(h2);
|
||||
NS_RELEASE(h3);
|
||||
NS_RELEASE(h4);
|
||||
NS_RELEASE(h5);
|
||||
NS_RELEASE(h6);
|
||||
NS_RELEASE(height);
|
||||
NS_RELEASE(hidden);
|
||||
NS_RELEASE(href);
|
||||
NS_RELEASE(hspace);
|
||||
NS_RELEASE(httpEquiv);
|
||||
NS_RELEASE(id);
|
||||
NS_RELEASE(ismap);
|
||||
NS_RELEASE(language);
|
||||
NS_RELEASE(li);
|
||||
NS_RELEASE(link);
|
||||
NS_RELEASE(left);
|
||||
NS_RELEASE(leftpadding);
|
||||
NS_RELEASE(lowsrc);
|
||||
NS_RELEASE(marginheight);
|
||||
NS_RELEASE(marginwidth);
|
||||
NS_RELEASE(maxlength);
|
||||
NS_RELEASE(mayscript);
|
||||
NS_RELEASE(menu);
|
||||
NS_RELEASE(method);
|
||||
NS_RELEASE(multicol);
|
||||
NS_RELEASE(multiple);
|
||||
NS_RELEASE(name);
|
||||
NS_RELEASE(noresize);
|
||||
NS_RELEASE(noshade);
|
||||
NS_RELEASE(nowrap);
|
||||
NS_RELEASE(ol);
|
||||
NS_RELEASE(onblur);
|
||||
NS_RELEASE(onfocus);
|
||||
NS_RELEASE(onload);
|
||||
NS_RELEASE(onunload);
|
||||
NS_RELEASE(overflow);
|
||||
NS_RELEASE(p);
|
||||
NS_RELEASE(pagex);
|
||||
NS_RELEASE(pagey);
|
||||
NS_RELEASE(pointSize);
|
||||
NS_RELEASE(pre);
|
||||
NS_RELEASE(prompt);
|
||||
NS_RELEASE(rel);
|
||||
NS_RELEASE(rightpadding);
|
||||
NS_RELEASE(rows);
|
||||
NS_RELEASE(rowspan);
|
||||
NS_RELEASE(scrolling);
|
||||
NS_RELEASE(selected);
|
||||
NS_RELEASE(shape);
|
||||
NS_RELEASE(size);
|
||||
NS_RELEASE(src);
|
||||
NS_RELEASE(start);
|
||||
NS_RELEASE(suppress);
|
||||
NS_RELEASE(tabstop);
|
||||
NS_RELEASE(target);
|
||||
NS_RELEASE(text);
|
||||
NS_RELEASE(top);
|
||||
NS_RELEASE(toppadding);
|
||||
NS_RELEASE(type);
|
||||
NS_RELEASE(ul);
|
||||
NS_RELEASE(usemap);
|
||||
NS_RELEASE(valign);
|
||||
NS_RELEASE(value);
|
||||
NS_RELEASE(variable);
|
||||
NS_RELEASE(visibility);
|
||||
NS_RELEASE(vlink);
|
||||
NS_RELEASE(vspace);
|
||||
NS_RELEASE(width);
|
||||
NS_RELEASE(wrap);
|
||||
NS_RELEASE(zindex);
|
||||
}
|
||||
}
|
||||
|
||||
168
content/html/content/src/nsHTMLAtoms.h
Normal file
168
content/html/content/src/nsHTMLAtoms.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsHTMLAtoms_h___
|
||||
#define nsHTMLAtoms_h___
|
||||
|
||||
#include "nsIAtom.h"
|
||||
|
||||
/**
|
||||
* This class wraps up the creation (and destruction) of the standard
|
||||
* set of html atoms used during normal html handling. This objects
|
||||
* are created when the first html content object is created and they
|
||||
* are destroyed when the last html content object is destroyed.
|
||||
*/
|
||||
class nsHTMLAtoms {
|
||||
public:
|
||||
|
||||
static void AddrefAtoms();
|
||||
static void ReleaseAtoms();
|
||||
|
||||
// Alphabetical list of html attribute atoms
|
||||
static nsIAtom* a;
|
||||
static nsIAtom* above;
|
||||
static nsIAtom* action;
|
||||
static nsIAtom* align;
|
||||
static nsIAtom* alink;
|
||||
static nsIAtom* alt;
|
||||
static nsIAtom* archive;
|
||||
|
||||
static nsIAtom* background;
|
||||
static nsIAtom* below;
|
||||
static nsIAtom* bgcolor;
|
||||
static nsIAtom* body;
|
||||
static nsIAtom* border;
|
||||
static nsIAtom* bordercolor;
|
||||
static nsIAtom* bottompadding;
|
||||
static nsIAtom* br;
|
||||
|
||||
static nsIAtom* cellpadding;
|
||||
static nsIAtom* cellspacing;
|
||||
static nsIAtom* checked;
|
||||
static nsIAtom* kClass;
|
||||
static nsIAtom* classid;
|
||||
static nsIAtom* clear;
|
||||
static nsIAtom* clip;
|
||||
static nsIAtom* code;
|
||||
static nsIAtom* codebase;
|
||||
static nsIAtom* color;
|
||||
static nsIAtom* cols;
|
||||
static nsIAtom* colspan;
|
||||
static nsIAtom* compact;
|
||||
static nsIAtom* coords;
|
||||
|
||||
static nsIAtom* data;
|
||||
static nsIAtom* dir;
|
||||
static nsIAtom* div;
|
||||
static nsIAtom* dl;
|
||||
|
||||
static nsIAtom* encoding;
|
||||
|
||||
static nsIAtom* face;
|
||||
static nsIAtom* font;
|
||||
static nsIAtom* fontWeight;
|
||||
static nsIAtom* frameborder;
|
||||
|
||||
static nsIAtom* gutter;
|
||||
|
||||
static nsIAtom* h1;
|
||||
static nsIAtom* h2;
|
||||
static nsIAtom* h3;
|
||||
static nsIAtom* h4;
|
||||
static nsIAtom* h5;
|
||||
static nsIAtom* h6;
|
||||
static nsIAtom* height;
|
||||
static nsIAtom* hidden;
|
||||
static nsIAtom* href;
|
||||
static nsIAtom* hspace;
|
||||
static nsIAtom* httpEquiv;
|
||||
|
||||
static nsIAtom* id;
|
||||
static nsIAtom* ismap;
|
||||
|
||||
static nsIAtom* language;
|
||||
static nsIAtom* li;
|
||||
static nsIAtom* link;
|
||||
static nsIAtom* left;
|
||||
static nsIAtom* leftpadding;
|
||||
static nsIAtom* lowsrc;
|
||||
|
||||
static nsIAtom* marginheight;
|
||||
static nsIAtom* marginwidth;
|
||||
static nsIAtom* maxlength;
|
||||
static nsIAtom* mayscript;
|
||||
static nsIAtom* menu;
|
||||
static nsIAtom* method;
|
||||
static nsIAtom* multicol;
|
||||
static nsIAtom* multiple;
|
||||
|
||||
static nsIAtom* name;
|
||||
static nsIAtom* noresize;
|
||||
static nsIAtom* noshade;
|
||||
static nsIAtom* nowrap;
|
||||
|
||||
static nsIAtom* ol;
|
||||
static nsIAtom* onblur;
|
||||
static nsIAtom* onfocus;
|
||||
static nsIAtom* onload;
|
||||
static nsIAtom* onunload;
|
||||
static nsIAtom* overflow;
|
||||
|
||||
static nsIAtom* p;
|
||||
static nsIAtom* pagex;
|
||||
static nsIAtom* pagey;
|
||||
static nsIAtom* pointSize;
|
||||
static nsIAtom* pre;
|
||||
static nsIAtom* prompt;
|
||||
|
||||
static nsIAtom* rel;
|
||||
static nsIAtom* rightpadding;
|
||||
static nsIAtom* rows;
|
||||
static nsIAtom* rowspan;
|
||||
|
||||
static nsIAtom* scrolling;
|
||||
static nsIAtom* selected;
|
||||
static nsIAtom* shape;
|
||||
static nsIAtom* size;
|
||||
static nsIAtom* src;
|
||||
static nsIAtom* start;
|
||||
static nsIAtom* suppress;
|
||||
|
||||
static nsIAtom* tabstop;
|
||||
static nsIAtom* target;
|
||||
static nsIAtom* text;
|
||||
static nsIAtom* top;
|
||||
static nsIAtom* toppadding;
|
||||
static nsIAtom* type;
|
||||
|
||||
static nsIAtom* ul;
|
||||
static nsIAtom* usemap;
|
||||
|
||||
static nsIAtom* valign;
|
||||
static nsIAtom* value;
|
||||
static nsIAtom* variable;
|
||||
static nsIAtom* visibility;
|
||||
static nsIAtom* vlink;
|
||||
static nsIAtom* vspace;
|
||||
|
||||
static nsIAtom* width;
|
||||
static nsIAtom* wrap;
|
||||
|
||||
static nsIAtom* zindex;
|
||||
};
|
||||
|
||||
#endif /* nsHTMLAtoms_h___ */
|
||||
1054
content/html/document/src/nsHTMLContentSink.cpp
Normal file
1054
content/html/document/src/nsHTMLContentSink.cpp
Normal file
File diff suppressed because it is too large
Load Diff
280
content/html/document/src/nsHTMLDocument.cpp
Normal file
280
content/html/document/src/nsHTMLDocument.cpp
Normal file
@@ -0,0 +1,280 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsHTMLDocument.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsIHTMLContentSink.h"
|
||||
#include "nsHTMLParts.h"
|
||||
#include "nsIHTMLStyleSheet.h"
|
||||
#include "nsIStyleSet.h"
|
||||
#include "nsIDocumentObserver.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIImageMap.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kIHTMLDocumentIID, NS_IHTMLDOCUMENT_IID);
|
||||
|
||||
NS_LAYOUT nsresult
|
||||
NS_NewHTMLDocument(nsIDocument** aInstancePtrResult)
|
||||
{
|
||||
nsHTMLDocument* doc = new nsHTMLDocument();
|
||||
return doc->QueryInterface(kIDocumentIID, (void**) aInstancePtrResult);
|
||||
}
|
||||
|
||||
nsHTMLDocument::nsHTMLDocument()
|
||||
: nsDocument(),
|
||||
mAttrStyleSheet(nsnull)
|
||||
{
|
||||
nsHTMLAtoms::AddrefAtoms();
|
||||
}
|
||||
|
||||
nsHTMLDocument::~nsHTMLDocument()
|
||||
{
|
||||
NS_IF_RELEASE(mAttrStyleSheet);
|
||||
nsHTMLAtoms::ReleaseAtoms();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLDocument::QueryInterface(REFNSIID aIID,
|
||||
void** aInstancePtr)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtr, "null ptr");
|
||||
if (nsnull == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kIHTMLDocumentIID)) {
|
||||
AddRef();
|
||||
*aInstancePtr = (void**) &mIHTMLDocument;
|
||||
return NS_OK;
|
||||
}
|
||||
return nsDocument::QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
void nsHTMLDocument::LoadURL(nsIURL* aURL)
|
||||
{
|
||||
NS_IF_RELEASE(mAttrStyleSheet);
|
||||
NS_IF_RELEASE(mDocumentURL);
|
||||
if (nsnull != mDocumentTitle) {
|
||||
delete mDocumentTitle;
|
||||
mDocumentTitle = nsnull;
|
||||
}
|
||||
|
||||
mDocumentURL = aURL;
|
||||
NS_ADDREF(aURL);
|
||||
|
||||
nsIParser* parser;
|
||||
nsresult rv = NS_NewHTMLParser(&parser);
|
||||
if (NS_OK == rv) {
|
||||
nsIHTMLContentSink* sink;
|
||||
rv = NS_NewHTMLContentSink(&sink, this, aURL);
|
||||
if (NS_OK == rv) {
|
||||
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL)) {
|
||||
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
|
||||
}
|
||||
|
||||
parser->SetContentSink(sink);
|
||||
parser->Parse(aURL);
|
||||
NS_RELEASE(sink);
|
||||
}
|
||||
NS_RELEASE(parser);
|
||||
}
|
||||
//XXX return NS_OK;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kIDocumentObserverIID, NS_IDOCUMENTOBSERVER_IID);
|
||||
|
||||
NS_IMETHODIMP nsHTMLDocument::SetTitle(const nsString& aTitle)
|
||||
{
|
||||
if (nsnull == mDocumentTitle) {
|
||||
mDocumentTitle = new nsString(aTitle);
|
||||
}
|
||||
else {
|
||||
*mDocumentTitle = aTitle;
|
||||
}
|
||||
|
||||
// Pass on title to observers
|
||||
PRInt32 i, n = mObservers.Count();
|
||||
for (i = 0; i < n; i++) {
|
||||
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
|
||||
observer->SetTitle(*mDocumentTitle);
|
||||
}
|
||||
|
||||
// Pass on to any interested containers
|
||||
n = mPresShells.Count();
|
||||
for (i = 0; i < n; i++) {
|
||||
nsIPresShell* shell = (nsIPresShell*) mPresShells.ElementAt(i);
|
||||
nsIPresContext* cx = shell->GetPresContext();
|
||||
nsISupports* container;
|
||||
if (NS_OK == cx->GetContainer(&container)) {
|
||||
if (nsnull != container) {
|
||||
nsIDocumentObserver* docob;
|
||||
if (NS_OK == container->QueryInterface(kIDocumentObserverIID,
|
||||
(void**) &docob)) {
|
||||
docob->SetTitle(aTitle);
|
||||
NS_RELEASE(docob);
|
||||
}
|
||||
NS_RELEASE(container);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(cx);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLDocument::AddImageMap(nsIImageMap* aMap)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aMap, "null ptr");
|
||||
if (nsnull == aMap) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (mImageMaps.AppendElement(aMap)) {
|
||||
NS_ADDREF(aMap);
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLDocument::GetImageMap(const nsString& aMapName,
|
||||
nsIImageMap** aResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aResult, "null ptr");
|
||||
if (nsnull == aResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
nsAutoString name;
|
||||
PRInt32 i, n = mImageMaps.Count();
|
||||
for (i = 0; i < n; i++) {
|
||||
nsIImageMap* map = (nsIImageMap*) mImageMaps.ElementAt(i);
|
||||
if (NS_OK == map->GetName(name)) {
|
||||
if (name.EqualsIgnoreCase(aMapName)) {
|
||||
*aResult = map;
|
||||
NS_ADDREF(map);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;/* XXX NS_NOT_FOUND */
|
||||
}
|
||||
|
||||
void nsHTMLDocument::AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet)
|
||||
{
|
||||
if ((nsnull != mAttrStyleSheet) && (aSheet != mAttrStyleSheet)) {
|
||||
aSet->InsertDocStyleSheetBefore(aSheet, mAttrStyleSheet);
|
||||
}
|
||||
else {
|
||||
aSet->AppendDocStyleSheet(aSheet);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
// Aggregation class to give nsHTMLDocument the nsIHTMLDocument interface
|
||||
|
||||
#define GET_OUTER() \
|
||||
((nsHTMLDocument*) ((char*)this - nsHTMLDocument::GetOuterOffset()))
|
||||
|
||||
nsHTMLDocument::AggIHTMLDocument::AggIHTMLDocument() {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsHTMLDocument::AggIHTMLDocument::~AggIHTMLDocument() { }
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt) nsHTMLDocument::AggIHTMLDocument::AddRef() {
|
||||
return GET_OUTER()->AddRef();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt) nsHTMLDocument::AggIHTMLDocument::Release() {
|
||||
return GET_OUTER()->Release();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLDocument::AggIHTMLDocument::QueryInterface(REFNSIID aIID,
|
||||
void** aInstancePtr)
|
||||
{
|
||||
return GET_OUTER()->QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLDocument::AggIHTMLDocument::SetTitle(const nsString& aTitle) {
|
||||
return GET_OUTER()->SetTitle(aTitle);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLDocument::AggIHTMLDocument::AddImageMap(nsIImageMap* aMap) {
|
||||
return GET_OUTER()->AddImageMap(aMap);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsHTMLDocument::AggIHTMLDocument::GetImageMap(const nsString& aMapName,
|
||||
nsIImageMap** aResult) {
|
||||
return GET_OUTER()->GetImageMap(aMapName, aResult);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
|
||||
NS_LAYOUT void
|
||||
NS_HackAppendContent(nsIDocument* aDoc)
|
||||
{
|
||||
((nsHTMLDocument*)aDoc)->HackAppendContent();
|
||||
}
|
||||
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsIAtom.h"
|
||||
|
||||
static const char* kBigParagraph =
|
||||
"This is some text. It will be word wrapped because our container will "
|
||||
"word wrap us. It will also be baseline aligned because our container "
|
||||
"will do that too. ";
|
||||
|
||||
#define NUM_BIG_TEXTS 114
|
||||
|
||||
nsresult nsHTMLDocument::HackAppendSimpleSpan(nsIContent* aContainer,
|
||||
const char* aTag,
|
||||
const char* aText)
|
||||
{
|
||||
nsIHTMLContent* span;
|
||||
nsIHTMLContent* text;
|
||||
nsIAtom* atom = NS_NewAtom(aTag);
|
||||
nsresult rv = NS_NewHTMLContainer(&span, atom);
|
||||
if (NS_OK == rv) {
|
||||
nsAutoString tmp;
|
||||
for (PRIntn i = 0; i < NUM_BIG_TEXTS; i++) {
|
||||
tmp.Append(aText);
|
||||
}
|
||||
rv = NS_NewHTMLText(&text, tmp.GetUnicode(), tmp.Length());
|
||||
if (NS_OK == rv) {
|
||||
span->AppendChild(text);
|
||||
NS_RELEASE(text);
|
||||
}
|
||||
aContainer->AppendChild(span);
|
||||
NS_RELEASE(span);
|
||||
}
|
||||
NS_RELEASE(atom);
|
||||
return rv;
|
||||
}
|
||||
|
||||
void nsHTMLDocument::HackAppendContent()
|
||||
{
|
||||
nsIContent* body = mRootContent->ChildAt(0);
|
||||
HackAppendSimpleSpan(body, "P", kBigParagraph);
|
||||
NS_RELEASE(body);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
76
content/html/document/src/nsHTMLDocument.h
Normal file
76
content/html/document/src/nsHTMLDocument.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsHTMLDocument_h___
|
||||
#define nsHTMLDocument_h___
|
||||
|
||||
#include "nsDocument.h"
|
||||
#include "nsIHTMLDocument.h"
|
||||
|
||||
class nsIHTMLStyleSheet;
|
||||
|
||||
class nsHTMLDocument : public nsDocument {
|
||||
public:
|
||||
nsHTMLDocument();
|
||||
virtual ~nsHTMLDocument();
|
||||
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
virtual void LoadURL(nsIURL* aURL);
|
||||
|
||||
NS_IMETHOD SetTitle(const nsString& aTitle);
|
||||
|
||||
NS_IMETHOD AddImageMap(nsIImageMap* aMap);
|
||||
|
||||
NS_IMETHOD GetImageMap(const nsString& aMapName, nsIImageMap** aResult);
|
||||
|
||||
static PRInt32 GetOuterOffset() {
|
||||
return offsetof(nsHTMLDocument,mIHTMLDocument);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void AddStyleSheetToSet(nsIStyleSheet* aSheet, nsIStyleSet* aSet);
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
public:
|
||||
void HackAppendContent();
|
||||
|
||||
protected:
|
||||
nsresult HackAppendSimpleSpan(nsIContent* aContainer, const char* aTag,
|
||||
const char* aText);
|
||||
#endif
|
||||
|
||||
class AggIHTMLDocument : public nsIHTMLDocument {
|
||||
public:
|
||||
AggIHTMLDocument();
|
||||
~AggIHTMLDocument();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD SetTitle(const nsString& aTitle);
|
||||
|
||||
NS_IMETHOD AddImageMap(nsIImageMap* aMap);
|
||||
|
||||
NS_IMETHOD GetImageMap(const nsString& aMapName, nsIImageMap** aResult);
|
||||
};
|
||||
|
||||
AggIHTMLDocument mIHTMLDocument;
|
||||
nsIHTMLStyleSheet* mAttrStyleSheet;
|
||||
nsVoidArray mImageMaps;
|
||||
};
|
||||
|
||||
#endif /* nsHTMLDocument_h___ */
|
||||
41
content/html/document/src/nsIHTMLDocument.h
Normal file
41
content/html/document/src/nsIHTMLDocument.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIHTMLDocument_h___
|
||||
#define nsIHTMLDocument_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
class nsIImageMap;
|
||||
class nsString;
|
||||
|
||||
/* b2a848b0-d0a9-11d1-89b1-006008911b81 */
|
||||
#define NS_IHTMLDOCUMENT_IID \
|
||||
{0xb2a848b0, 0xd0a9, 0x11d1, {0x89, 0xb1, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81}}
|
||||
|
||||
/**
|
||||
* HTML document extensions to nsIDocument.
|
||||
*/
|
||||
class nsIHTMLDocument : public nsISupports {
|
||||
public:
|
||||
NS_IMETHOD SetTitle(const nsString& aTitle) = 0;
|
||||
|
||||
NS_IMETHOD AddImageMap(nsIImageMap* aMap) = 0;
|
||||
|
||||
NS_IMETHOD GetImageMap(const nsString& aMapName, nsIImageMap** aResult) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsIHTMLDocument_h___ */
|
||||
56
content/html/style/public/nsICSSParser.h
Normal file
56
content/html/style/public/nsICSSParser.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsCSS1Parser_h___
|
||||
#define nsCSS1Parser_h___
|
||||
|
||||
#include "nslayout.h"
|
||||
#include "nsISupports.h"
|
||||
class nsIStyleSheet;
|
||||
class nsIUnicharInputStream;
|
||||
class nsIURL;
|
||||
|
||||
#define NS_ICSS_PARSER_IID \
|
||||
{ 0xcc9c0610, 0x968c, 0x11d1, \
|
||||
{0x93, 0x23, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32} }
|
||||
|
||||
// Interface to the css parser.
|
||||
class nsICSSParser : public nsISupports {
|
||||
public:
|
||||
// Return a mask of the various css standards that this parser
|
||||
// supports.
|
||||
virtual PRUint32 GetInfoMask() = 0;
|
||||
|
||||
// Set a style sheet for the parser to fill in. The style sheet must
|
||||
// implement the nsICSSStyleSheet interface
|
||||
virtual nsresult SetStyleSheet(nsIStyleSheet* aSheet) = 0;
|
||||
|
||||
virtual nsIStyleSheet* Parse(PRInt32* aErrorCode,
|
||||
nsIUnicharInputStream* aInput,
|
||||
nsIURL* aInputURL) = 0;
|
||||
};
|
||||
|
||||
// Values or'd in the GetInfoMask; other bits are reserved
|
||||
#define NS_CSS_GETINFO_CSS1 ((PRUint32) 0x00000001L)
|
||||
#define NS_CSS_GETINFO_CSSP ((PRUint32) 0x00000002L)
|
||||
#define NS_CSS_GETINFO_CSS2 ((PRUint32) 0x00000004L)
|
||||
#define NS_CSS_GETINFO_CSS_FROSTING ((PRUint32) 0x00000008L)
|
||||
|
||||
extern NS_HTML nsresult
|
||||
NS_NewCSSParser(nsICSSParser** aInstancePtrResult);
|
||||
|
||||
#endif /* nsCSS1Parser_h___ */
|
||||
1350
content/html/style/src/nsCSSDeclaration.cpp
Normal file
1350
content/html/style/src/nsCSSDeclaration.cpp
Normal file
File diff suppressed because it is too large
Load Diff
40
content/html/style/src/nsCSSKeywords.h
Normal file
40
content/html/style/src/nsCSSKeywords.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsCSSKeywords_h___
|
||||
#define nsCSSKeywords_h___
|
||||
|
||||
#include "nslayout.h"
|
||||
#include "nsCSSKeywordIDs.h"
|
||||
|
||||
class NS_LAYOUT nsCSSKeywords {
|
||||
public:
|
||||
// Given a null terminated string of 7 bit characters, return the
|
||||
// tag id (see nsHTMLTagIDs.h) for the tag or -1 if the tag is not
|
||||
// known. The lookup function uses a perfect hash.
|
||||
static PRInt32 LookupName(const char* str);
|
||||
|
||||
struct NameTableEntry {
|
||||
const char* name;
|
||||
PRInt32 id;
|
||||
};
|
||||
|
||||
// A table whose index is the tag id (from LookupName)
|
||||
static const NameTableEntry kNameTable[];
|
||||
};
|
||||
|
||||
#endif /* nsCSSKeywords_h___ */
|
||||
229
content/html/style/src/nsCSSLayout.cpp
Normal file
229
content/html/style/src/nsCSSLayout.cpp
Normal file
@@ -0,0 +1,229 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsCSSLayout.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsRect.h"
|
||||
|
||||
static NS_DEFINE_IID(kStyleMoleculeSID, NS_STYLEMOLECULE_SID);
|
||||
|
||||
// XXX what about ebina's center vs. ncsa-center?
|
||||
/*
|
||||
* Notes: It's a known fact that this doesn't do what ebina's layout
|
||||
* engine does because his code did vertical alignment on the
|
||||
* fly. Hopefully that's ok because his code generated surprising
|
||||
* results in a number of unusual cases.
|
||||
*/
|
||||
nscoord nsCSSLayout::VerticallyAlignChildren(nsIPresContext* aCX,
|
||||
nsIFrame* aContainer,
|
||||
nsStyleFont* aContainerFont,
|
||||
nscoord aY0,
|
||||
nsIFrame* aFirstChild,
|
||||
PRIntn aChildCount,
|
||||
nscoord* aAscents,
|
||||
nscoord aMaxAscent)
|
||||
{
|
||||
// Determine minimum and maximum y values for the line and
|
||||
// perform alignment of all children except those requesting bottom
|
||||
// alignment. The second pass will align bottom children (if any)
|
||||
nsIFontMetrics* fm = aCX->GetMetricsFor(aContainerFont->mFont);
|
||||
nsIFrame* kid = aFirstChild;
|
||||
nsRect kidRect;
|
||||
nscoord minY = aY0;
|
||||
nscoord maxY = aY0;
|
||||
PRIntn bottomAlignKids = 0;
|
||||
PRIntn kidCount = aChildCount;
|
||||
while (--kidCount >= 0) {
|
||||
nscoord kidAscent = *aAscents++;
|
||||
nsIStyleContext* kidSC = kid->GetStyleContext(aCX);
|
||||
nsIContent* kidContent = kid->GetContent();
|
||||
nsStyleMolecule* kidMol =
|
||||
(nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID);
|
||||
PRIntn verticalAlign = kidMol->verticalAlign;
|
||||
float verticalAlignPct = kidMol->verticalAlignPct;
|
||||
NS_RELEASE(kidSC);
|
||||
NS_RELEASE(kidContent);
|
||||
|
||||
kid->GetRect(kidRect);
|
||||
|
||||
// Vertically align the child
|
||||
nscoord kidYTop = 0;
|
||||
switch (verticalAlign) {
|
||||
default:
|
||||
case NS_STYLE_VERTICAL_ALIGN_BASELINE:
|
||||
// Align the kid's baseline at the max baseline
|
||||
kidYTop = aMaxAscent - kidAscent;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_TOP:
|
||||
// Align the top of the kid with the top of the line box
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_SUB:
|
||||
// Move baseline by 1/2 the ascent of the child.
|
||||
// NOTE: CSSx doesn't seem to specify what subscripting does
|
||||
// so we are using ebina's logic
|
||||
kidYTop = aMaxAscent + (kidAscent/2) - kidAscent;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_SUPER:
|
||||
// Move baseline by 1/2 the ascent of the child
|
||||
// NOTE: CSSx doesn't seem to specify what superscripting does
|
||||
// so we are using ebina's logic
|
||||
kidYTop = aMaxAscent - (kidAscent/2) - kidAscent;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_BOTTOM:
|
||||
bottomAlignKids++;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_MIDDLE:
|
||||
kidYTop = aMaxAscent - (fm->GetHeight(/*'x'XXX */) / 2) - kidRect.height/2;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_TEXT_BOTTOM:
|
||||
kidYTop = aMaxAscent + fm->GetMaxDescent() - kidRect.height;
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_TEXT_TOP:
|
||||
kidYTop = aMaxAscent - fm->GetMaxAscent();
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_LENGTH:
|
||||
// XXX css2 hasn't yet specified what this means!
|
||||
break;
|
||||
|
||||
case NS_STYLE_VERTICAL_ALIGN_PCT:
|
||||
// XXX need kidMol->lineHeight in translated to a value form...
|
||||
break;
|
||||
}
|
||||
|
||||
// Place kid and update min and max Y values
|
||||
nscoord y = aY0 + kidYTop;
|
||||
if (y < minY) minY = y;
|
||||
kid->MoveTo(kidRect.x, y);
|
||||
y += kidRect.height;
|
||||
if (y > maxY) maxY = y;
|
||||
|
||||
kid = kid->GetNextSibling();
|
||||
}
|
||||
|
||||
nscoord lineHeight = maxY - minY;
|
||||
|
||||
if (0 != bottomAlignKids) {
|
||||
// Position all of the bottom aligned children
|
||||
kidCount = aChildCount;
|
||||
kid = aFirstChild;
|
||||
while (--kidCount >= 0) {
|
||||
// Get kid's vertical align style data
|
||||
nsIStyleContext* kidSC = kid->GetStyleContext(aCX);
|
||||
nsIContent* kidContent = kid->GetContent();
|
||||
nsStyleMolecule* kidMol =
|
||||
(nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID);
|
||||
PRIntn verticalAlign = kidMol->verticalAlign;
|
||||
NS_RELEASE(kidSC);
|
||||
NS_RELEASE(kidContent);
|
||||
|
||||
// Vertically align the child
|
||||
if (verticalAlign == NS_STYLE_VERTICAL_ALIGN_BOTTOM) {
|
||||
// Place kid along the bottom
|
||||
kid->GetRect(kidRect);
|
||||
kid->MoveTo(kidRect.x, aY0 + lineHeight - kidRect.height);
|
||||
if (--bottomAlignKids == 0) {
|
||||
// Stop on lost bottom aligned kid
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
kid = kid->GetNextSibling();
|
||||
}
|
||||
}
|
||||
|
||||
NS_RELEASE(fm);
|
||||
return lineHeight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Horizontally place the children in the container frame.
|
||||
*/
|
||||
void nsCSSLayout::HorizontallyPlaceChildren(nsIPresContext* aCX,
|
||||
nsIFrame* aContainer,
|
||||
nsStyleMolecule* aContainerStyle,
|
||||
nsIFrame* aFirstChild,
|
||||
PRInt32 aChildCount,
|
||||
nscoord aLineWidth,
|
||||
nscoord aMaxWidth)
|
||||
{
|
||||
PRIntn textAlign = aContainerStyle->textAlign;
|
||||
|
||||
nscoord dx = 0;
|
||||
switch (textAlign) {
|
||||
case NS_STYLE_TEXT_ALIGN_LEFT:
|
||||
case NS_STYLE_TEXT_ALIGN_JUSTIFY:
|
||||
// Default layout has everything aligned left
|
||||
return;
|
||||
|
||||
case NS_STYLE_TEXT_ALIGN_RIGHT:
|
||||
dx = aMaxWidth - aLineWidth;
|
||||
break;
|
||||
|
||||
case NS_STYLE_TEXT_ALIGN_CENTER:
|
||||
dx = (aMaxWidth - aLineWidth) / 2;
|
||||
break;
|
||||
}
|
||||
|
||||
// Position children
|
||||
nsPoint origin;
|
||||
nsIFrame* kid = aFirstChild;
|
||||
while (--aChildCount >= 0) {
|
||||
kid->GetOrigin(origin);
|
||||
kid->MoveTo(origin.x + dx, origin.y);
|
||||
kid = kid->GetNextSibling();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply css relative positioning to any child that requires it.
|
||||
*/
|
||||
void nsCSSLayout::RelativePositionChildren(nsIPresContext* aCX,
|
||||
nsIFrame* aContainer,
|
||||
nsStyleMolecule* aContainerStyle,
|
||||
nsIFrame* aFirstChild,
|
||||
PRInt32 aChildCount)
|
||||
{
|
||||
nsPoint origin;
|
||||
nsIFrame* kid = aFirstChild;
|
||||
while (--aChildCount >= 0) {
|
||||
nsIContent* kidContent = kid->GetContent();
|
||||
nsIStyleContext* kidSC = kid->GetStyleContext(aCX);
|
||||
nsStyleMolecule* kidMol = (nsStyleMolecule*)kidSC->GetData(kStyleMoleculeSID);
|
||||
if (NS_STYLE_POSITION_RELATIVE == kidMol->positionFlags) {
|
||||
kid->GetOrigin(origin);
|
||||
nscoord dx = kidMol->left;
|
||||
nscoord dy = kidMol->top;
|
||||
kid->MoveTo(origin.x + dx, origin.y + dy);
|
||||
}
|
||||
NS_RELEASE(kidContent);
|
||||
NS_RELEASE(kidSC);
|
||||
kid = kid->GetNextSibling();
|
||||
}
|
||||
}
|
||||
2186
content/html/style/src/nsCSSParser.cpp
Normal file
2186
content/html/style/src/nsCSSParser.cpp
Normal file
File diff suppressed because it is too large
Load Diff
40
content/html/style/src/nsCSSProps.h
Normal file
40
content/html/style/src/nsCSSProps.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsCSSProps_h___
|
||||
#define nsCSSProps_h___
|
||||
|
||||
#include "nslayout.h"
|
||||
#include "nsCSSPropIDs.h"
|
||||
|
||||
class NS_LAYOUT nsCSSProps {
|
||||
public:
|
||||
// Given a null terminated string of 7 bit characters, return the
|
||||
// tag id (see nsCSSPropIDs.h) for the tag or -1 if the tag is not
|
||||
// known. The lookup function uses a perfect hash.
|
||||
static PRInt32 LookupName(const char* str);
|
||||
|
||||
struct NameTableEntry {
|
||||
const char* name;
|
||||
PRInt32 id;
|
||||
};
|
||||
|
||||
// A table whose index is the tag id (from nsCSSPropIDs)
|
||||
static const NameTableEntry kNameTable[];
|
||||
};
|
||||
|
||||
#endif /* nsCSSProps_h___ */
|
||||
585
content/html/style/src/nsCSSScanner.cpp
Normal file
585
content/html/style/src/nsCSSScanner.cpp
Normal file
@@ -0,0 +1,585 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsCSSScanner.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIUnicharInputStream.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
static char* kNullPointer = "null pointer";
|
||||
#endif
|
||||
|
||||
// Don't bother collecting whitespace characters in token's mIdent buffer
|
||||
#undef COLLECT_WHITESPACE
|
||||
|
||||
#define BUFFER_SIZE 256
|
||||
|
||||
static const PRUnichar CSS_ESCAPE = PRUnichar('\\');
|
||||
|
||||
static const PRUint8 IS_LATIN1 = 0x01;
|
||||
static const PRUint8 IS_DIGIT = 0x02;
|
||||
static const PRUint8 IS_HEX_DIGIT = 0x04;
|
||||
static const PRUint8 IS_ALPHA = 0x08;
|
||||
static const PRUint8 START_IDENT = 0x10;
|
||||
static const PRUint8 IS_IDENT = 0x20;
|
||||
static const PRUint8 IS_WHITESPACE = 0x40;
|
||||
|
||||
static PRUint8* gLexTable;
|
||||
|
||||
static void BuildLexTable()
|
||||
{
|
||||
PRUint8* lt = new PRUint8[256];
|
||||
nsCRT::zero(lt, 256);
|
||||
gLexTable = lt;
|
||||
|
||||
int i;
|
||||
lt[CSS_ESCAPE] = START_IDENT;
|
||||
lt['-'] |= IS_IDENT;
|
||||
// XXX add in other whitespace chars
|
||||
lt[' '] |= IS_WHITESPACE;
|
||||
lt['\t'] |= IS_WHITESPACE;
|
||||
lt['\r'] |= IS_WHITESPACE;
|
||||
lt['\n'] |= IS_WHITESPACE;
|
||||
for (i = 161; i <= 255; i++) {
|
||||
lt[i] |= IS_LATIN1 | IS_IDENT | START_IDENT;
|
||||
}
|
||||
for (i = '0'; i <= '9'; i++) {
|
||||
lt[i] |= IS_DIGIT | IS_HEX_DIGIT | IS_IDENT;
|
||||
}
|
||||
for (i = 'A'; i <= 'Z'; i++) {
|
||||
if ((i >= 'A') && (i <= 'F')) {
|
||||
lt[i] |= IS_HEX_DIGIT;
|
||||
lt[i+32] |= IS_HEX_DIGIT;
|
||||
}
|
||||
lt[i] |= IS_ALPHA | IS_IDENT | START_IDENT;
|
||||
lt[i+32] |= IS_ALPHA | IS_IDENT | START_IDENT;
|
||||
}
|
||||
}
|
||||
|
||||
nsCSSToken::nsCSSToken()
|
||||
{
|
||||
mType = eCSSToken_Symbol;
|
||||
}
|
||||
|
||||
nsCSSScanner::nsCSSScanner()
|
||||
{
|
||||
if (nsnull == gLexTable) {
|
||||
// XXX need a monitor
|
||||
BuildLexTable();
|
||||
}
|
||||
mInput = nsnull;
|
||||
mBuffer = new PRUnichar[BUFFER_SIZE];
|
||||
mOffset = 0;
|
||||
mCount = 0;
|
||||
mLookAhead = -1;
|
||||
}
|
||||
|
||||
nsCSSScanner::~nsCSSScanner()
|
||||
{
|
||||
Close();
|
||||
if (nsnull != mBuffer) {
|
||||
delete mBuffer;
|
||||
mBuffer = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
void nsCSSScanner::Init(nsIUnicharInputStream* aInput)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInput, kNullPointer);
|
||||
Close();
|
||||
mInput = aInput;
|
||||
if (nsnull != aInput) {
|
||||
aInput->AddRef();
|
||||
}
|
||||
}
|
||||
|
||||
void nsCSSScanner::Close()
|
||||
{
|
||||
NS_IF_RELEASE(mInput);
|
||||
}
|
||||
|
||||
// Returns -1 on error or eof
|
||||
PRInt32 nsCSSScanner::Read(PRInt32* aErrorCode)
|
||||
{
|
||||
PRInt32 rv;
|
||||
if (mLookAhead >= 0) {
|
||||
rv = mLookAhead;
|
||||
mLookAhead = -1;
|
||||
} else {
|
||||
if (mCount < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (mOffset == mCount) {
|
||||
mOffset = 0;
|
||||
mCount = mInput->Read(aErrorCode, mBuffer, 0, BUFFER_SIZE);
|
||||
if (mCount <= 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
rv = PRInt32(mBuffer[mOffset++]);
|
||||
}
|
||||
mLastRead = rv;
|
||||
//printf("Read => %x\n", rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
PRInt32 nsCSSScanner::Peek(PRInt32* aErrorCode)
|
||||
{
|
||||
if (mLookAhead < 0) {
|
||||
mLookAhead = Read(aErrorCode);
|
||||
if (mLookAhead < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
//printf("Peek => %x\n", mLookAhead);
|
||||
return mLookAhead;
|
||||
}
|
||||
|
||||
void nsCSSScanner::Unread()
|
||||
{
|
||||
NS_PRECONDITION((mLastRead >= 0) && (mLookAhead < 0), "double pushback");
|
||||
mLookAhead = mLastRead;
|
||||
mLastRead = -1;
|
||||
}
|
||||
|
||||
PRBool nsCSSScanner::LookAhead(PRInt32* aErrorCode, PRUnichar aChar)
|
||||
{
|
||||
PRInt32 ch = Read(aErrorCode);
|
||||
if (ch < 0) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (ch == aChar) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
Unread();
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsCSSScanner::EatWhiteSpace(PRInt32* aErrorCode)
|
||||
{
|
||||
PRBool eaten = PR_FALSE;
|
||||
for (;;) {
|
||||
PRInt32 ch = Read(aErrorCode);
|
||||
if (ch < 0) {
|
||||
break;
|
||||
}
|
||||
if ((ch == ' ') || (ch == '\n') || (ch == '\r') || (ch == '\t')) {
|
||||
eaten = PR_TRUE;
|
||||
continue;
|
||||
}
|
||||
Unread();
|
||||
break;
|
||||
}
|
||||
return eaten;
|
||||
}
|
||||
|
||||
PRBool nsCSSScanner::EatNewline(PRInt32* aErrorCode)
|
||||
{
|
||||
PRInt32 ch = Read(aErrorCode);
|
||||
if (ch < 0) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
PRBool eaten = PR_FALSE;
|
||||
if (ch == '\r') {
|
||||
eaten = PR_TRUE;
|
||||
ch = Peek(aErrorCode);
|
||||
if (ch == '\n') {
|
||||
(void) Read(aErrorCode);
|
||||
}
|
||||
} else if (ch == '\n') {
|
||||
eaten = PR_TRUE;
|
||||
} else {
|
||||
Unread();
|
||||
}
|
||||
return eaten;
|
||||
}
|
||||
|
||||
PRBool nsCSSScanner::Next(PRInt32* aErrorCode, nsCSSToken* aToken)
|
||||
{
|
||||
PRInt32 ch = Read(aErrorCode);
|
||||
if (ch < 0) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (ch < 256) {
|
||||
PRUint8* lexTable = gLexTable;
|
||||
|
||||
// IDENT
|
||||
if ((lexTable[ch] & START_IDENT) != 0) {
|
||||
return ParseIdent(aErrorCode, ch, aToken);
|
||||
}
|
||||
|
||||
// AT_KEYWORD
|
||||
if (ch == '@') {
|
||||
PRInt32 nextChar = Peek(aErrorCode);
|
||||
if ((nextChar >= 0) && (nextChar <= 255)) {
|
||||
if ((lexTable[nextChar] & START_IDENT) != 0) {
|
||||
return ParseAtKeyword(aErrorCode, ch, aToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NUMBER or DIM
|
||||
if ((ch == '.') || (ch == '+') || (ch == '-')) {
|
||||
PRInt32 nextChar = Peek(aErrorCode);
|
||||
if ((nextChar >= 0) && (nextChar <= 255)) {
|
||||
if ((lexTable[nextChar] & IS_DIGIT) != 0) {
|
||||
return ParseNumber(aErrorCode, ch, aToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((lexTable[ch] & IS_DIGIT) != 0) {
|
||||
return ParseNumber(aErrorCode, ch, aToken);
|
||||
}
|
||||
|
||||
// ID
|
||||
if (ch == '#') {
|
||||
return ParseID(aErrorCode, ch, aToken);
|
||||
}
|
||||
|
||||
// STRING
|
||||
if ((ch == '"') || (ch == '\'')) {
|
||||
return ParseString(aErrorCode, ch, aToken);
|
||||
}
|
||||
|
||||
// WS
|
||||
if ((lexTable[ch] & IS_WHITESPACE) != 0) {
|
||||
aToken->mType = eCSSToken_WhiteSpace;
|
||||
aToken->mIdent.SetLength(0);
|
||||
aToken->mIdent.Append(PRUnichar(ch));
|
||||
(void) EatWhiteSpace(aErrorCode);
|
||||
return PR_TRUE;
|
||||
}
|
||||
if (ch == '/') {
|
||||
PRInt32 nextChar = Peek(aErrorCode);
|
||||
if (nextChar == '/') {
|
||||
(void) Read(aErrorCode);
|
||||
aToken->mIdent.SetLength(0);
|
||||
aToken->mIdent.Append(PRUnichar(ch));
|
||||
aToken->mIdent.Append(PRUnichar(ch));
|
||||
return ParseEOLComment(aErrorCode, aToken);
|
||||
} else if (nextChar == '*') {
|
||||
(void) Read(aErrorCode);
|
||||
aToken->mIdent.SetLength(0);
|
||||
aToken->mIdent.Append(PRUnichar(ch));
|
||||
aToken->mIdent.Append(PRUnichar(nextChar));
|
||||
return ParseCComment(aErrorCode, aToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
aToken->mType = eCSSToken_Symbol;
|
||||
aToken->mSymbol = ch;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRInt32 nsCSSScanner::ParseEscape(PRInt32* aErrorCode)
|
||||
{
|
||||
PRUint8* lexTable = gLexTable;
|
||||
PRInt32 ch = Peek(aErrorCode);
|
||||
if (ch < 0) {
|
||||
return CSS_ESCAPE;
|
||||
}
|
||||
if ((ch <= 255) && ((lexTable[ch] & IS_HEX_DIGIT) != 0)) {
|
||||
PRInt32 rv = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
ch = Read(aErrorCode);
|
||||
if (ch < 0) {
|
||||
// Whoops: error or premature eof
|
||||
break;
|
||||
}
|
||||
if ((lexTable[ch] & IS_HEX_DIGIT) != 0) {
|
||||
if ((lexTable[ch] & IS_DIGIT) != 0) {
|
||||
rv = rv * 16 + (ch - '0');
|
||||
} else {
|
||||
// Note: c&7 just keeps the low three bits which causes
|
||||
// upper and lower case alphabetics to both yield their
|
||||
// "relative to 10" value for computing the hex value.
|
||||
rv = rv * 16 + (ch & 0x7) + 10;
|
||||
}
|
||||
} else {
|
||||
Unread();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
} else {
|
||||
// "Any character except a hexidecimal digit can be escaped to
|
||||
// remove its special meaning by putting a backslash in front"
|
||||
// -- CSS1 spec section 7.1
|
||||
(void) Read(aErrorCode);
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gather up the characters in an identifier. The identfier was
|
||||
* started by "aChar" which will be appended to aIdent. The result
|
||||
* will be aIdent with all of the identifier characters appended
|
||||
* until the first non-identifier character is seen. The termination
|
||||
* character is unread for the future re-reading.
|
||||
*/
|
||||
PRBool nsCSSScanner::GatherIdent(PRInt32* aErrorCode, PRInt32 aChar,
|
||||
nsString& aIdent)
|
||||
{
|
||||
if (aChar == CSS_ESCAPE) {
|
||||
aChar = ParseEscape(aErrorCode);
|
||||
}
|
||||
for (;;) {
|
||||
aChar = Read(aErrorCode);
|
||||
if (aChar < 0) break;
|
||||
if (aChar == CSS_ESCAPE) {
|
||||
aChar = ParseEscape(aErrorCode);
|
||||
aIdent.Append(PRUnichar(aChar));
|
||||
} else if ((aChar <= 255) && ((gLexTable[aChar] & IS_IDENT) != 0)) {
|
||||
aIdent.Append(PRUnichar(aChar));
|
||||
} else {
|
||||
Unread();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsCSSScanner::ParseID(PRInt32* aErrorCode,
|
||||
PRInt32 aChar,
|
||||
nsCSSToken* aToken)
|
||||
{
|
||||
aToken->mIdent.SetLength(0);
|
||||
aToken->mType = eCSSToken_ID;
|
||||
return GatherIdent(aErrorCode, aChar, aToken->mIdent);
|
||||
}
|
||||
|
||||
PRBool nsCSSScanner::ParseIdent(PRInt32* aErrorCode,
|
||||
PRInt32 aChar,
|
||||
nsCSSToken* aToken)
|
||||
{
|
||||
nsString& ident = aToken->mIdent;
|
||||
ident.SetLength(0);
|
||||
ident.Append(PRUnichar(aChar));
|
||||
if (!GatherIdent(aErrorCode, aChar, ident)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// Process a url lexical token. A CSS1 url token can contain
|
||||
// characters beyond identifier characters (e.g. '/', ':', etc.)
|
||||
// Because of this the normal rules for tokenizing the input don't
|
||||
// apply very well. To simplify the parser and relax some of the
|
||||
// requirements on the scanner we parse url's here. If we find a
|
||||
// malformed URL then we emit a token of type "InvalidURL" so that
|
||||
// the CSS1 parser can ignore the invalid input. We attempt to eat
|
||||
// the right amount of input data when an invalid URL is presented.
|
||||
nsCSSTokenType tokenType = eCSSToken_Ident;
|
||||
if (ident.EqualsIgnoreCase("url")) {
|
||||
tokenType = eCSSToken_InvalidURL;
|
||||
if (LookAhead(aErrorCode, '(')) {
|
||||
// Skip leading whitespace
|
||||
(void) EatWhiteSpace(aErrorCode);
|
||||
ident.SetLength(0);
|
||||
|
||||
PRInt32 c = Read(aErrorCode);
|
||||
if (c == ')') {
|
||||
// empty url spec: this is invalid
|
||||
} else if ((c == '"') || (c == '\'')) {
|
||||
// start of a quoted url
|
||||
if (!GatherString(aErrorCode, c, ident)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (!EatWhiteSpace(aErrorCode)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (LookAhead(aErrorCode, ')')) {
|
||||
tokenType = eCSSToken_URL;
|
||||
}
|
||||
} else {
|
||||
// start of a non-quoted url
|
||||
Unread();
|
||||
PRBool ok = PR_TRUE;
|
||||
for (;;) {
|
||||
c = Read(aErrorCode);
|
||||
if (c < 0) break;
|
||||
if (c == CSS_ESCAPE) {
|
||||
c = ParseEscape(aErrorCode);
|
||||
ident.Append(PRUnichar(c));
|
||||
} else if ((c == '"') || (c == '\'') || (c == '(')) {
|
||||
// This is an invalid URL spec
|
||||
ok = PR_FALSE;
|
||||
} else if ((256 >= c) && ((gLexTable[c] & IS_WHITESPACE) != 0)) {
|
||||
// Whitespace is allowed at the end of the URL
|
||||
(void) EatWhiteSpace(aErrorCode);
|
||||
if (LookAhead(aErrorCode, ')')) {
|
||||
// done!
|
||||
break;
|
||||
}
|
||||
// Whitespace is followed by something other than a
|
||||
// ")". This is an invalid url spec.
|
||||
ok = PR_FALSE;
|
||||
} else if (c == ')') {
|
||||
// All done
|
||||
break;
|
||||
} else {
|
||||
// A regular url character.
|
||||
ident.Append(PRUnichar(c));
|
||||
}
|
||||
}
|
||||
|
||||
// If the result of the above scanning is ok then change the token
|
||||
// type to a useful one.
|
||||
if (ok) {
|
||||
tokenType = eCSSToken_URL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
aToken->mType = tokenType;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsCSSScanner::ParseAtKeyword(PRInt32* aErrorCode, PRInt32 aChar,
|
||||
nsCSSToken* aToken)
|
||||
{
|
||||
aToken->mIdent.SetLength(0);
|
||||
aToken->mType = eCSSToken_AtKeyword;
|
||||
return GatherIdent(aErrorCode, aChar, aToken->mIdent);
|
||||
}
|
||||
|
||||
PRBool nsCSSScanner::ParseNumber(PRInt32* aErrorCode, PRInt32 c,
|
||||
nsCSSToken* aToken)
|
||||
{
|
||||
nsString& ident = aToken->mIdent;
|
||||
ident.SetLength(0);
|
||||
PRBool gotDot = (c == '.') ? PR_TRUE : PR_FALSE;
|
||||
if (c != '+') {
|
||||
ident.Append(PRUnichar(c));
|
||||
}
|
||||
|
||||
// Gather up characters that make up the number
|
||||
PRUint8* lexTable = gLexTable;
|
||||
for (;;) {
|
||||
c = Read(aErrorCode);
|
||||
if (c < 0) break;
|
||||
if (!gotDot && (c == '.')) {
|
||||
gotDot = PR_TRUE;
|
||||
} else if ((c > 255) || ((lexTable[c] & IS_DIGIT) == 0)) {
|
||||
break;
|
||||
}
|
||||
ident.Append(PRUnichar(c));
|
||||
}
|
||||
|
||||
// Convert number to floating point
|
||||
nsCSSTokenType type = eCSSToken_Number;
|
||||
PRInt32 ec;
|
||||
float value = ident.ToFloat(&ec);
|
||||
|
||||
// Look at character that terminated the number
|
||||
aToken->mIntegerValid = PR_FALSE;
|
||||
if (c >= 0) {
|
||||
if ((c <= 255) && ((lexTable[c] & START_IDENT) != 0)) {
|
||||
ident.SetLength(0);
|
||||
ident.Append(PRUnichar(c));
|
||||
if (!GatherIdent(aErrorCode, c, ident)) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
type = eCSSToken_Dimension;
|
||||
} else if ('%' == c) {
|
||||
type = eCSSToken_Percentage;
|
||||
value = value / 100.0f;
|
||||
} else {
|
||||
// Put back character that stopped numeric scan
|
||||
Unread();
|
||||
if (!gotDot) {
|
||||
aToken->mInteger = ident.ToInteger(&ec);
|
||||
aToken->mIntegerValid = PR_TRUE;
|
||||
}
|
||||
ident.SetLength(0);
|
||||
}
|
||||
}
|
||||
aToken->mNumber = value;
|
||||
aToken->mType = type;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsCSSScanner::ParseCComment(PRInt32* aErrorCode, nsCSSToken* aToken)
|
||||
{
|
||||
nsString& ident = aToken->mIdent;
|
||||
for (;;) {
|
||||
PRInt32 ch = Read(aErrorCode);
|
||||
if (ch < 0) break;
|
||||
if (ch == '*') {
|
||||
if (LookAhead(aErrorCode, '/')) {
|
||||
ident.Append(PRUnichar(ch));
|
||||
ident.Append('/');
|
||||
break;
|
||||
}
|
||||
}
|
||||
#ifdef COLLECT_WHITESPACE
|
||||
ident.Append(PRUnichar(ch));
|
||||
#endif
|
||||
}
|
||||
aToken->mType = eCSSToken_WhiteSpace;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsCSSScanner::ParseEOLComment(PRInt32* aErrorCode, nsCSSToken* aToken)
|
||||
{
|
||||
nsString& ident = aToken->mIdent;
|
||||
ident.SetLength(0);
|
||||
for (;;) {
|
||||
if (EatNewline(aErrorCode)) {
|
||||
break;
|
||||
}
|
||||
PRInt32 ch = Read(aErrorCode);
|
||||
if (ch < 0) {
|
||||
break;
|
||||
}
|
||||
#ifdef COLLECT_WHITESPACE
|
||||
ident.Append(PRUnichar(ch));
|
||||
#endif
|
||||
}
|
||||
aToken->mType = eCSSToken_WhiteSpace;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsCSSScanner::GatherString(PRInt32* aErrorCode, PRInt32 aStop,
|
||||
nsString& aBuffer)
|
||||
{
|
||||
for (;;) {
|
||||
PRInt32 ch = Read(aErrorCode);
|
||||
if (ch < 0) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
if (ch == aStop) {
|
||||
break;
|
||||
}
|
||||
if (ch == CSS_ESCAPE) {
|
||||
ch = ParseEscape(aErrorCode);
|
||||
if (ch < 0) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
aBuffer.Append(PRUnichar(ch));
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRBool nsCSSScanner::ParseString(PRInt32* aErrorCode, PRInt32 aStop,
|
||||
nsCSSToken* aToken)
|
||||
{
|
||||
aToken->mIdent.SetLength(0);
|
||||
aToken->mType = eCSSToken_String;
|
||||
return GatherString(aErrorCode, aStop, aToken->mIdent);
|
||||
}
|
||||
118
content/html/style/src/nsCSSScanner.h
Normal file
118
content/html/style/src/nsCSSScanner.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsCSSScanner_h___
|
||||
#define nsCSSScanner_h___
|
||||
|
||||
#include "nsString.h"
|
||||
class nsIUnicharInputStream;
|
||||
|
||||
// Token types
|
||||
enum nsCSSTokenType {
|
||||
// A css identifier (e.g. foo)
|
||||
eCSSToken_Ident = 0,
|
||||
|
||||
// A css at keyword (e.g. @foo)
|
||||
eCSSToken_AtKeyword = 1,
|
||||
|
||||
// A css number without a percentage or dimension; with percentage;
|
||||
// without percentage but with a dimension
|
||||
eCSSToken_Number = 2,
|
||||
eCSSToken_Percentage = 3,
|
||||
eCSSToken_Dimension = 4,
|
||||
|
||||
// A css string (e.g. "foo" or 'foo')
|
||||
eCSSToken_String = 5,
|
||||
|
||||
// Whitespace (e.g. " " or "/* abc */" or "// foo <eol>")
|
||||
eCSSToken_WhiteSpace = 6,
|
||||
|
||||
// A css symbol (e.g. ':', ';', '+', etc.)
|
||||
eCSSToken_Symbol = 7,
|
||||
|
||||
eCSSToken_URL = 8, // use getString
|
||||
eCSSToken_InvalidURL = 9, // doesn't matter
|
||||
|
||||
// A css1 id (e.g. #foo3)
|
||||
eCSSToken_ID = 10, // use getString()
|
||||
};
|
||||
|
||||
struct nsCSSToken {
|
||||
nsCSSTokenType mType;
|
||||
nsAutoString mIdent;
|
||||
float mNumber;
|
||||
PRInt32 mInteger;
|
||||
PRUnichar mSymbol;
|
||||
PRBool mIntegerValid;
|
||||
|
||||
nsCSSToken();
|
||||
|
||||
PRBool isDimension() {
|
||||
return (PRBool)
|
||||
((eCSSToken_Dimension == mType) ||
|
||||
((eCSSToken_Number == mType) && (mNumber == 0.0f)));
|
||||
}
|
||||
};
|
||||
|
||||
// CSS Scanner API. Used to tokenize an input stream using the CSS
|
||||
// forward compatible tokenization rules. This implementation is
|
||||
// private to this package and is only used internally by the css
|
||||
// parser.
|
||||
class nsCSSScanner {
|
||||
public:
|
||||
nsCSSScanner();
|
||||
~nsCSSScanner();
|
||||
|
||||
// Init the scanner.
|
||||
void Init(nsIUnicharInputStream* aInput);
|
||||
|
||||
// Get the next token. Return nsfalse on EOF or ERROR. aTokenResult
|
||||
// is filled in with the data for the token.
|
||||
PRBool Next(PRInt32* aErrorCode, nsCSSToken* aTokenResult);
|
||||
|
||||
protected:
|
||||
void Close();
|
||||
PRInt32 Read(PRInt32* aErrorCode);
|
||||
PRInt32 Peek(PRInt32* aErrorCode);
|
||||
void Unread();
|
||||
PRBool LookAhead(PRInt32* aErrorCode, PRUnichar aChar);
|
||||
PRBool EatWhiteSpace(PRInt32* aErrorCode);
|
||||
PRBool EatNewline(PRInt32* aErrorCode);
|
||||
|
||||
PRInt32 ParseEscape(PRInt32* aErrorCode);
|
||||
PRBool ParseIdent(PRInt32* aErrorCode, PRInt32 aChar, nsCSSToken* aResult);
|
||||
PRBool ParseAtKeyword(PRInt32* aErrorCode, PRInt32 aChar,
|
||||
nsCSSToken* aResult);
|
||||
PRBool ParseNumber(PRInt32* aErrorCode, PRInt32 aChar, nsCSSToken* aResult);
|
||||
PRBool ParseID(PRInt32* aErrorCode, PRInt32 aChar, nsCSSToken* aResult);
|
||||
PRBool ParseString(PRInt32* aErrorCode, PRInt32 aChar, nsCSSToken* aResult);
|
||||
PRBool ParseEOLComment(PRInt32* aErrorCode, nsCSSToken* aResult);
|
||||
PRBool ParseCComment(PRInt32* aErrorCode, nsCSSToken* aResult);
|
||||
|
||||
PRBool GatherString(PRInt32* aErrorCode, PRInt32 aStop,
|
||||
nsString& aString);
|
||||
PRBool GatherIdent(PRInt32* aErrorCode, PRInt32 aChar, nsString& aIdent);
|
||||
|
||||
nsIUnicharInputStream* mInput;
|
||||
PRUnichar* mBuffer;
|
||||
PRInt32 mOffset;
|
||||
PRInt32 mCount;
|
||||
PRInt32 mLookAhead;
|
||||
PRInt32 mLastRead;
|
||||
};
|
||||
|
||||
#endif /* nsCSSScanner_h___ */
|
||||
1350
content/html/style/src/nsCSSStruct.cpp
Normal file
1350
content/html/style/src/nsCSSStruct.cpp
Normal file
File diff suppressed because it is too large
Load Diff
683
content/html/style/src/nsCSSStyleRule.cpp
Normal file
683
content/html/style/src/nsCSSStyleRule.cpp
Normal file
@@ -0,0 +1,683 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsICSSStyleRule.h"
|
||||
#include "nsICSSDeclaration.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIArena.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStyleConsts.h"
|
||||
#include "nsUnitConversion.h"
|
||||
|
||||
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
|
||||
static NS_DEFINE_IID(kICSSDeclarationIID, NS_ICSS_DECLARATION_IID);
|
||||
static NS_DEFINE_IID(kICSSStyleRuleIID, NS_ICSS_STYLE_RULE_IID);
|
||||
|
||||
static NS_DEFINE_IID(kStyleFontSID, NS_STYLEFONT_SID);
|
||||
static NS_DEFINE_IID(kStyleColorSID, NS_STYLECOLOR_SID);
|
||||
static NS_DEFINE_IID(kStyleListSID, NS_STYLELIST_SID);
|
||||
|
||||
static NS_DEFINE_IID(kCSSFontSID, NS_CSS_FONT_SID);
|
||||
static NS_DEFINE_IID(kCSSColorSID, NS_CSS_COLOR_SID);
|
||||
static NS_DEFINE_IID(kCSSTextSID, NS_CSS_TEXT_SID);
|
||||
static NS_DEFINE_IID(kCSSMarginSID, NS_CSS_MARGIN_SID);
|
||||
static NS_DEFINE_IID(kCSSPositionSID, NS_CSS_POSITION_SID);
|
||||
static NS_DEFINE_IID(kCSSListSID, NS_CSS_LIST_SID);
|
||||
|
||||
|
||||
// -- nsCSSSelector -------------------------------
|
||||
|
||||
nsCSSSelector::nsCSSSelector()
|
||||
: mTag(nsnull), mID(nsnull), mClass(nsnull), mPseudoClass(nsnull),
|
||||
mNext(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
nsCSSSelector::nsCSSSelector(nsIAtom* aTag, nsIAtom* aID, nsIAtom* aClass, nsIAtom* aPseudoClass)
|
||||
: mTag(aTag), mID(aID), mClass(aClass), mPseudoClass(aPseudoClass),
|
||||
mNext(nsnull)
|
||||
{
|
||||
NS_IF_ADDREF(mTag);
|
||||
NS_IF_ADDREF(mID);
|
||||
NS_IF_ADDREF(mClass);
|
||||
NS_IF_ADDREF(mPseudoClass);
|
||||
}
|
||||
|
||||
nsCSSSelector::nsCSSSelector(const nsCSSSelector& aCopy)
|
||||
: mTag(aCopy.mTag), mID(aCopy.mID), mClass(aCopy.mClass), mPseudoClass(aCopy.mPseudoClass),
|
||||
mNext(nsnull)
|
||||
{ // implmented to support extension to CSS2 (when we have to copy the array)
|
||||
NS_IF_ADDREF(mTag);
|
||||
NS_IF_ADDREF(mID);
|
||||
NS_IF_ADDREF(mClass);
|
||||
NS_IF_ADDREF(mPseudoClass);
|
||||
}
|
||||
|
||||
nsCSSSelector::~nsCSSSelector()
|
||||
{
|
||||
NS_IF_RELEASE(mTag);
|
||||
NS_IF_RELEASE(mID);
|
||||
NS_IF_RELEASE(mClass);
|
||||
NS_IF_RELEASE(mPseudoClass);
|
||||
}
|
||||
|
||||
nsCSSSelector& nsCSSSelector::operator=(const nsCSSSelector& aCopy)
|
||||
{
|
||||
NS_IF_RELEASE(mTag);
|
||||
NS_IF_RELEASE(mID);
|
||||
NS_IF_RELEASE(mClass);
|
||||
NS_IF_RELEASE(mPseudoClass);
|
||||
mTag = aCopy.mTag;
|
||||
mID = aCopy.mID;
|
||||
mClass = aCopy.mClass;
|
||||
mPseudoClass = aCopy.mPseudoClass;
|
||||
NS_IF_ADDREF(mTag);
|
||||
NS_IF_ADDREF(mID);
|
||||
NS_IF_ADDREF(mClass);
|
||||
NS_IF_ADDREF(mPseudoClass);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PRBool nsCSSSelector::Equals(const nsCSSSelector* aOther) const
|
||||
{
|
||||
if (nsnull != aOther) {
|
||||
return (PRBool)((aOther->mTag == mTag) && (aOther->mID == mID) &&
|
||||
(aOther->mClass == mClass) && (aOther->mPseudoClass == mPseudoClass));
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
void nsCSSSelector::Set(const nsString& aTag, const nsString& aID,
|
||||
const nsString& aClass, const nsString& aPseudoClass)
|
||||
{
|
||||
NS_IF_RELEASE(mTag);
|
||||
NS_IF_RELEASE(mID);
|
||||
NS_IF_RELEASE(mClass);
|
||||
NS_IF_RELEASE(mPseudoClass);
|
||||
if (0 < aTag.Length()) {
|
||||
mTag = NS_NewAtom(aTag);
|
||||
}
|
||||
if (0 < aID.Length()) {
|
||||
mID = NS_NewAtom(aID);
|
||||
}
|
||||
if (0 < aClass.Length()) {
|
||||
mClass = NS_NewAtom(aClass);
|
||||
}
|
||||
if (0 < aPseudoClass.Length()) {
|
||||
mPseudoClass = NS_NewAtom(aPseudoClass);
|
||||
}
|
||||
}
|
||||
|
||||
// -- nsCSSStyleRule -------------------------------
|
||||
|
||||
class CSSStyleRuleImpl : public nsICSSStyleRule {
|
||||
public:
|
||||
void* operator new(size_t size);
|
||||
void* operator new(size_t size, nsIArena* aArena);
|
||||
void operator delete(void* ptr);
|
||||
|
||||
CSSStyleRuleImpl(const nsCSSSelector& aSelector);
|
||||
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
|
||||
virtual PRBool Equals(const nsIStyleRule* aRule) const;
|
||||
virtual PRUint32 HashValue(void) const;
|
||||
|
||||
virtual nsCSSSelector* FirstSelector(void);
|
||||
virtual void AddSelector(const nsCSSSelector& aSelector);
|
||||
virtual void DeleteSelector(nsCSSSelector* aSelector);
|
||||
|
||||
virtual nsICSSDeclaration* GetDeclaration(void) const;
|
||||
virtual void SetDeclaration(nsICSSDeclaration* aDeclaration);
|
||||
|
||||
virtual PRInt32 GetWeight(void) const;
|
||||
virtual void SetWeight(PRInt32 aWeight);
|
||||
|
||||
virtual nscoord CalcLength(const nsCSSValue& aValue, nsStyleFont* aFont,
|
||||
nsIPresContext* aPresContext);
|
||||
virtual void MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
private:
|
||||
// These are not supported and are not implemented!
|
||||
CSSStyleRuleImpl(const CSSStyleRuleImpl& aCopy);
|
||||
CSSStyleRuleImpl& operator=(const CSSStyleRuleImpl& aCopy);
|
||||
|
||||
protected:
|
||||
virtual ~CSSStyleRuleImpl();
|
||||
|
||||
protected:
|
||||
PRUint32 mInHeap : 1;
|
||||
PRUint32 mRefCnt : 31;
|
||||
|
||||
nsCSSSelector mSelector;
|
||||
nsICSSDeclaration* mDeclaration;
|
||||
PRInt32 mWeight;
|
||||
};
|
||||
|
||||
|
||||
void* CSSStyleRuleImpl::operator new(size_t size)
|
||||
{
|
||||
CSSStyleRuleImpl* rv = (CSSStyleRuleImpl*) ::operator new(size);
|
||||
#ifdef NS_DEBUG
|
||||
if (nsnull != rv) {
|
||||
nsCRT::memset(rv, 0xEE, size);
|
||||
}
|
||||
#endif
|
||||
rv->mInHeap = 1;
|
||||
return (void*) rv;
|
||||
}
|
||||
|
||||
void* CSSStyleRuleImpl::operator new(size_t size, nsIArena* aArena)
|
||||
{
|
||||
CSSStyleRuleImpl* rv = (CSSStyleRuleImpl*) aArena->Alloc(PRInt32(size));
|
||||
#ifdef NS_DEBUG
|
||||
if (nsnull != rv) {
|
||||
nsCRT::memset(rv, 0xEE, size);
|
||||
}
|
||||
#endif
|
||||
rv->mInHeap = 0;
|
||||
return (void*) rv;
|
||||
}
|
||||
|
||||
void CSSStyleRuleImpl::operator delete(void* ptr)
|
||||
{
|
||||
CSSStyleRuleImpl* rule = (CSSStyleRuleImpl*) ptr;
|
||||
if (nsnull != rule) {
|
||||
if (rule->mInHeap) {
|
||||
::delete ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
CSSStyleRuleImpl::CSSStyleRuleImpl(const nsCSSSelector& aSelector)
|
||||
: mSelector(aSelector), mDeclaration(nsnull), mWeight(0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
CSSStyleRuleImpl::~CSSStyleRuleImpl()
|
||||
{
|
||||
nsCSSSelector* next = mSelector.mNext;
|
||||
|
||||
while (nsnull != next) {
|
||||
nsCSSSelector* selector = next;
|
||||
next = selector->mNext;
|
||||
delete selector;
|
||||
}
|
||||
NS_IF_RELEASE(mDeclaration);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(CSSStyleRuleImpl)
|
||||
NS_IMPL_RELEASE(CSSStyleRuleImpl)
|
||||
|
||||
nsresult CSSStyleRuleImpl::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kICSSStyleRuleIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsICSSStyleRule*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIStyleRuleIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIStyleRule*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsISupports*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
PRBool CSSStyleRuleImpl::Equals(const nsIStyleRule* aRule) const
|
||||
{
|
||||
nsICSSStyleRule* iCSSRule;
|
||||
|
||||
if (this == aRule) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
if ((nsnull != aRule) &&
|
||||
(NS_OK == ((nsIStyleRule*)aRule)->QueryInterface(kICSSStyleRuleIID, (void**) &iCSSRule))) {
|
||||
|
||||
CSSStyleRuleImpl* rule = (CSSStyleRuleImpl*)iCSSRule;
|
||||
const nsCSSSelector* local = &mSelector;
|
||||
const nsCSSSelector* other = &(rule->mSelector);
|
||||
PRBool result = PR_TRUE;
|
||||
|
||||
while ((PR_TRUE == result) && (nsnull != local) && (nsnull != other)) {
|
||||
if (! local->Equals(other)) {
|
||||
result = PR_FALSE;
|
||||
}
|
||||
local = local->mNext;
|
||||
other = other->mNext;
|
||||
}
|
||||
if ((nsnull != local) || (nsnull != other)) { // more were left
|
||||
result = PR_FALSE;
|
||||
}
|
||||
if ((rule->mDeclaration != mDeclaration) ||
|
||||
(rule->mWeight != mWeight)) {
|
||||
result = PR_FALSE;
|
||||
}
|
||||
NS_RELEASE(iCSSRule);
|
||||
return result;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRUint32 CSSStyleRuleImpl::HashValue(void) const
|
||||
{
|
||||
return (PRUint32)this;
|
||||
}
|
||||
|
||||
nsCSSSelector* CSSStyleRuleImpl::FirstSelector(void)
|
||||
{
|
||||
return &mSelector;
|
||||
}
|
||||
|
||||
void CSSStyleRuleImpl::AddSelector(const nsCSSSelector& aSelector)
|
||||
{
|
||||
nsCSSSelector* selector = new nsCSSSelector(aSelector);
|
||||
nsCSSSelector* last = &mSelector;
|
||||
|
||||
while (nsnull != last->mNext) {
|
||||
last = last->mNext;
|
||||
}
|
||||
last->mNext = selector;
|
||||
}
|
||||
|
||||
|
||||
void CSSStyleRuleImpl::DeleteSelector(nsCSSSelector* aSelector)
|
||||
{
|
||||
if (nsnull != aSelector) {
|
||||
if (&mSelector == aSelector) { // handle first selector
|
||||
mSelector = *aSelector; // assign value
|
||||
mSelector.mNext = aSelector->mNext;
|
||||
delete aSelector;
|
||||
}
|
||||
else {
|
||||
nsCSSSelector* selector = &mSelector;
|
||||
|
||||
while (nsnull != selector->mNext) {
|
||||
if (aSelector == selector->mNext) {
|
||||
selector->mNext = aSelector->mNext;
|
||||
delete aSelector;
|
||||
return;
|
||||
}
|
||||
selector = selector->mNext;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsICSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const
|
||||
{
|
||||
NS_IF_ADDREF(mDeclaration);
|
||||
return mDeclaration;
|
||||
}
|
||||
|
||||
void CSSStyleRuleImpl::SetDeclaration(nsICSSDeclaration* aDeclaration)
|
||||
{
|
||||
NS_IF_RELEASE(mDeclaration);
|
||||
mDeclaration = aDeclaration;
|
||||
NS_IF_ADDREF(mDeclaration);
|
||||
}
|
||||
|
||||
PRInt32 CSSStyleRuleImpl::GetWeight(void) const
|
||||
{
|
||||
return mWeight;
|
||||
}
|
||||
|
||||
void CSSStyleRuleImpl::SetWeight(PRInt32 aWeight)
|
||||
{
|
||||
mWeight = aWeight;
|
||||
}
|
||||
|
||||
nscoord CSSStyleRuleImpl::CalcLength(const nsCSSValue& aValue, nsStyleFont* aFont,
|
||||
nsIPresContext* aPresContext)
|
||||
{
|
||||
NS_ASSERTION(aValue.IsLengthUnit(), "not a length unit");
|
||||
if (aValue.IsFixedLengthUnit()) {
|
||||
return aValue.GetLengthTwips();
|
||||
}
|
||||
nsCSSUnit unit = aValue.GetUnit();
|
||||
switch (unit) {
|
||||
case eCSSUnit_EM:
|
||||
return aFont->mFont.size;
|
||||
case eCSSUnit_EN:
|
||||
return (aFont->mFont.size / 2);
|
||||
case eCSSUnit_XHeight:
|
||||
NS_NOTYETIMPLEMENTED("x height unit");
|
||||
return ((aFont->mFont.size / 3) * 2); // XXX HACK!
|
||||
case eCSSUnit_CapHeight:
|
||||
NS_NOTYETIMPLEMENTED("cap height unit");
|
||||
return ((aFont->mFont.size / 3) * 2); // XXX HACK!
|
||||
|
||||
case eCSSUnit_Pixel:
|
||||
return (nscoord)(aPresContext->GetPixelsToTwips() * aValue.GetFloatValue());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CSSStyleRuleImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
||||
{
|
||||
if (nsnull != mDeclaration) {
|
||||
nsStyleFont* font = (nsStyleFont*)aContext->GetData(kStyleFontSID);
|
||||
|
||||
nsCSSFont* ourFont;
|
||||
if (NS_OK == mDeclaration->GetData(kCSSFontSID, (nsCSSStruct**)&ourFont)) {
|
||||
if (nsnull != ourFont) {
|
||||
nsStyleFont* parentFont = font;
|
||||
nsIStyleContext* parentContext = aContext->GetParent();
|
||||
if (nsnull != parentContext) {
|
||||
parentFont = (nsStyleFont*)parentContext->GetData(kStyleFontSID);
|
||||
}
|
||||
|
||||
// font-family: string list
|
||||
if (ourFont->mFamily.GetUnit() == eCSSUnit_String) {
|
||||
nsAutoString familyList;
|
||||
ourFont->mFamily.GetStringValue(familyList);
|
||||
// XXX meeds font support to determine usable fonts
|
||||
// parse up the CSS string & remove the quotes
|
||||
// XXX only does first until we can tell what are installed fonts
|
||||
nsAutoString family;
|
||||
PRInt32 index = familyList.Find(PRUnichar(','));
|
||||
if (-1 < index) {
|
||||
familyList.Left(family, index);
|
||||
}
|
||||
else {
|
||||
family.Append(familyList);
|
||||
}
|
||||
family.StripChars("\"");
|
||||
family.StripWhitespace();
|
||||
|
||||
font->mFont.name = family;
|
||||
}
|
||||
|
||||
// font-style: enum
|
||||
if (ourFont->mStyle.GetUnit() == eCSSUnit_Enumerated) {
|
||||
font->mFont.style = ourFont->mStyle.GetIntValue();
|
||||
}
|
||||
|
||||
// font-variant: enum
|
||||
if (ourFont->mVariant.GetUnit() == eCSSUnit_Enumerated) {
|
||||
font->mFont.variant = ourFont->mVariant.GetIntValue();
|
||||
}
|
||||
|
||||
// font-weight: abs, enum
|
||||
if (ourFont->mWeight.GetUnit() == eCSSUnit_Absolute) {
|
||||
font->mFont.style = ourFont->mWeight.GetIntValue();
|
||||
}
|
||||
else if (ourFont->mWeight.GetUnit() == eCSSUnit_Enumerated) {
|
||||
PRInt32 value = ourFont->mWeight.GetIntValue();
|
||||
switch (value) {
|
||||
case NS_STYLE_FONT_WEIGHT_NORMAL:
|
||||
case NS_STYLE_FONT_WEIGHT_BOLD:
|
||||
font->mFont.weight = value;
|
||||
break;
|
||||
case NS_STYLE_FONT_WEIGHT_BOLDER:
|
||||
case NS_STYLE_FONT_WEIGHT_LIGHTER:
|
||||
font->mFont.weight = (parentFont->mFont.weight + value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// font-size: enum, length, percent
|
||||
if (ourFont->mSize.GetUnit() == eCSSUnit_Enumerated) {
|
||||
static float kFontScale[7] = {
|
||||
0.5f, // xx-small
|
||||
0.666667f, // x-small
|
||||
0.833333f, // small
|
||||
1.0f, // medium
|
||||
1.5f, // large
|
||||
1.5f * 1.5f, // x-large
|
||||
1.5f * 1.5f * 1.5f, // xx-large
|
||||
};
|
||||
PRInt32 value = ourFont->mSize.GetIntValue();
|
||||
|
||||
const nsFont& normal = aPresContext->GetDefaultFont(); // use normal font or body font??
|
||||
if ((NS_STYLE_FONT_SIZE_XXSMALL <= value) &&
|
||||
(value <= NS_STYLE_FONT_SIZE_XXLARGE)) {
|
||||
font->mFont.size = (nscoord)((float)normal.size * kFontScale[value]);
|
||||
}
|
||||
else if (NS_STYLE_FONT_SIZE_LARGER == value) {
|
||||
PRInt32 index;
|
||||
for (index = NS_STYLE_FONT_SIZE_XXSMALL;
|
||||
index < NS_STYLE_FONT_SIZE_XXLARGE; index++)
|
||||
if (parentFont->mFont.size < (nscoord)((float)normal.size * kFontScale[index]))
|
||||
break;
|
||||
font->mFont.size = (nscoord)((float)normal.size * kFontScale[index]);
|
||||
}
|
||||
else if (NS_STYLE_FONT_SIZE_SMALLER == value) {
|
||||
PRInt32 index;
|
||||
for (index = NS_STYLE_FONT_SIZE_XXLARGE;
|
||||
index > NS_STYLE_FONT_SIZE_XXSMALL; index--)
|
||||
if (parentFont->mFont.size > (nscoord)((float)normal.size * kFontScale[index]))
|
||||
break;
|
||||
font->mFont.size = (nscoord)((float)normal.size * kFontScale[index]);
|
||||
}
|
||||
}
|
||||
else if (ourFont->mSize.IsLengthUnit()) {
|
||||
font->mFont.size = CalcLength(ourFont->mSize, parentFont, aPresContext);
|
||||
}
|
||||
else if (ourFont->mSize.GetUnit() == eCSSUnit_Percent) {
|
||||
font->mFont.size = (nscoord)((float)(parentFont->mFont.size) * ourFont->mSize.GetFloatValue());
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(parentContext);
|
||||
}
|
||||
}
|
||||
|
||||
nsCSSText* ourText;
|
||||
if (NS_OK == mDeclaration->GetData(kCSSTextSID, (nsCSSStruct**)&ourText)) {
|
||||
if (nsnull != ourText) {
|
||||
|
||||
// text-decoration: enum, absolute (bit field)
|
||||
if (ourText->mDecoration.GetUnit() == eCSSUnit_Enumerated) {
|
||||
font->mFont.decorations = ourText->mDecoration.GetIntValue();
|
||||
}
|
||||
else if (ourText->mDecoration.GetUnit() == eCSSUnit_Absolute) {
|
||||
font->mFont.decorations = ourText->mDecoration.GetIntValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nsCSSColor* ourColor;
|
||||
if (NS_OK == mDeclaration->GetData(kCSSColorSID, (nsCSSStruct**)&ourColor)) {
|
||||
if (nsnull != ourColor) {
|
||||
nsStyleColor* color = (nsStyleColor*)aContext->GetData(kStyleColorSID);
|
||||
|
||||
// color: color
|
||||
if (ourColor->mColor.GetUnit() == eCSSUnit_Color) {
|
||||
color->mColor = ourColor->mColor.GetColorValue();
|
||||
}
|
||||
|
||||
// background-color: color, enum (flags)
|
||||
if (ourColor->mBackColor.GetUnit() == eCSSUnit_Color) {
|
||||
color->mBackgroundColor = ourColor->mBackColor.GetColorValue();
|
||||
color->mBackgroundFlags &= ~NS_STYLE_BG_COLOR_TRANSPARENT;
|
||||
}
|
||||
else if (ourColor->mBackColor.GetUnit() == eCSSUnit_Enumerated) {
|
||||
color->mBackgroundFlags |= NS_STYLE_BG_COLOR_TRANSPARENT;
|
||||
}
|
||||
|
||||
// background-image: string, enum (flags)
|
||||
if (ourColor->mBackImage.GetUnit() == eCSSUnit_String) {
|
||||
ourColor->mBackImage.GetStringValue(color->mBackgroundImage);
|
||||
color->mBackgroundFlags &= ~NS_STYLE_BG_IMAGE_NONE;
|
||||
}
|
||||
else if (ourColor->mBackImage.GetUnit() == eCSSUnit_Enumerated) {
|
||||
color->mBackgroundFlags |= NS_STYLE_BG_IMAGE_NONE;
|
||||
}
|
||||
|
||||
// background-repeat: enum
|
||||
if (ourColor->mBackRepeat.GetUnit() == eCSSUnit_Enumerated) {
|
||||
color->mBackgroundRepeat = ourColor->mBackRepeat.GetIntValue();
|
||||
}
|
||||
|
||||
// background-attachment: enum
|
||||
if (ourColor->mBackAttachment.GetUnit() == eCSSUnit_Enumerated) {
|
||||
color->mBackgroundAttachment = ourColor->mBackAttachment.GetIntValue();
|
||||
}
|
||||
|
||||
// background-position: length, percent (flags)
|
||||
if (ourColor->mBackPositionX.GetUnit() == eCSSUnit_Percent) {
|
||||
color->mBackgroundXPosition = (nscoord)(TWIPS_CONST_FLOAT * ourColor->mBackPositionX.GetFloatValue());
|
||||
color->mBackgroundFlags |= NS_STYLE_BG_X_POSITION_PCT;
|
||||
color->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_LENGTH;
|
||||
}
|
||||
else if (ourColor->mBackPositionX.IsLengthUnit()) {
|
||||
color->mBackgroundXPosition = CalcLength(ourColor->mBackPositionX,
|
||||
font, aPresContext);
|
||||
color->mBackgroundFlags |= NS_STYLE_BG_X_POSITION_LENGTH;
|
||||
color->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_PCT;
|
||||
}
|
||||
if (ourColor->mBackPositionY.GetUnit() == eCSSUnit_Percent) {
|
||||
color->mBackgroundYPosition = (nscoord)(TWIPS_CONST_FLOAT * ourColor->mBackPositionY.GetFloatValue());
|
||||
color->mBackgroundFlags |= NS_STYLE_BG_Y_POSITION_PCT;
|
||||
color->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_LENGTH;
|
||||
}
|
||||
else if (ourColor->mBackPositionY.IsLengthUnit()) {
|
||||
color->mBackgroundYPosition = CalcLength(ourColor->mBackPositionY,
|
||||
font, aPresContext);
|
||||
color->mBackgroundFlags |= NS_STYLE_BG_Y_POSITION_LENGTH;
|
||||
color->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_PCT;
|
||||
}
|
||||
|
||||
// XXX: NYI nsCSSValue mBackFilter;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nsCSSList* ourList;
|
||||
if (NS_OK == mDeclaration->GetData(kCSSListSID, (nsCSSStruct**)&ourList)) {
|
||||
if (nsnull != ourList) {
|
||||
nsStyleList* list = (nsStyleList*)aContext->GetData(kStyleListSID);
|
||||
|
||||
// list-style-type: enum
|
||||
if (ourList->mType.GetUnit() == eCSSUnit_Enumerated) {
|
||||
list->mListStyleType = ourList->mType.GetIntValue();
|
||||
}
|
||||
|
||||
// list-style-image: string
|
||||
if (ourList->mImage.GetUnit() == eCSSUnit_String) {
|
||||
ourList->mImage.GetStringValue(list->mListStyleImage);
|
||||
}
|
||||
else if (ourList->mImage.GetUnit() == eCSSUnit_Enumerated) { // handle "none"
|
||||
list->mListStyleImage = "";
|
||||
}
|
||||
|
||||
// list-style-position: enum
|
||||
if (ourList->mPosition.GetUnit() == eCSSUnit_Enumerated) {
|
||||
list->mListStyleType = ourList->mPosition.GetIntValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void ListSelector(FILE* out, const nsCSSSelector* aSelector)
|
||||
{
|
||||
nsAutoString buffer;
|
||||
|
||||
if (nsnull != aSelector->mTag) {
|
||||
aSelector->mTag->ToString(buffer);
|
||||
fputs(buffer, out);
|
||||
}
|
||||
if (nsnull != aSelector->mID) {
|
||||
aSelector->mID->ToString(buffer);
|
||||
fputs("#", out);
|
||||
fputs(buffer, out);
|
||||
}
|
||||
if (nsnull != aSelector->mClass) {
|
||||
aSelector->mClass->ToString(buffer);
|
||||
fputs(".", out);
|
||||
fputs(buffer, out);
|
||||
}
|
||||
if (nsnull != aSelector->mPseudoClass) {
|
||||
aSelector->mPseudoClass->ToString(buffer);
|
||||
fputs(":", out);
|
||||
fputs(buffer, out);
|
||||
}
|
||||
}
|
||||
|
||||
void CSSStyleRuleImpl::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
// Indent
|
||||
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
||||
|
||||
const nsCSSSelector* selector = &mSelector;
|
||||
|
||||
while (nsnull != selector) {
|
||||
ListSelector(out, selector);
|
||||
fputs(" ", out);
|
||||
selector = selector->mNext;
|
||||
}
|
||||
|
||||
nsAutoString buffer;
|
||||
|
||||
buffer.Append("weight: ");
|
||||
buffer.Append(mWeight, 10);
|
||||
buffer.Append(" ");
|
||||
fputs(buffer, out);
|
||||
if (nsnull != mDeclaration) {
|
||||
mDeclaration->List(out);
|
||||
}
|
||||
else {
|
||||
fputs("{ null declaration }", out);
|
||||
}
|
||||
fputs("\n", out);
|
||||
}
|
||||
|
||||
NS_HTML nsresult
|
||||
NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult, const nsCSSSelector& aSelector)
|
||||
{
|
||||
if (aInstancePtrResult == nsnull) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
CSSStyleRuleImpl *it = new CSSStyleRuleImpl(aSelector);
|
||||
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kICSSStyleRuleIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
364
content/html/style/src/nsCSSStyleSheet.cpp
Normal file
364
content/html/style/src/nsCSSStyleSheet.cpp
Normal file
@@ -0,0 +1,364 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsICSSStyleSheet.h"
|
||||
#include "nsIArena.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsICSSStyleRule.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsIFrame.h"
|
||||
#include "nsString.h"
|
||||
|
||||
static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID);
|
||||
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
|
||||
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
|
||||
static NS_DEFINE_IID(kIHTMLContentIID, NS_IHTMLCONTENT_IID);
|
||||
|
||||
|
||||
class CSSStyleSheetImpl : public nsICSSStyleSheet {
|
||||
public:
|
||||
void* operator new(size_t size);
|
||||
void* operator new(size_t size, nsIArena* aArena);
|
||||
void operator delete(void* ptr);
|
||||
|
||||
CSSStyleSheetImpl(nsIURL* aURL);
|
||||
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
|
||||
virtual PRBool SelectorMatches(nsCSSSelector* aSelector,
|
||||
nsIContent* aContent);
|
||||
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParentFrame,
|
||||
nsISupportsArray* aResults);
|
||||
|
||||
virtual nsIURL* GetURL(void);
|
||||
|
||||
virtual PRBool ContainsStyleSheet(nsIURL* aURL);
|
||||
|
||||
virtual void AppendStyleSheet(nsICSSStyleSheet* aSheet);
|
||||
|
||||
// XXX do these belong here or are they generic?
|
||||
virtual void PrependStyleRule(nsICSSStyleRule* aRule);
|
||||
virtual void AppendStyleRule(nsICSSStyleRule* aRule);
|
||||
|
||||
// XXX style rule enumerations
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
private:
|
||||
// These are not supported and are not implemented!
|
||||
CSSStyleSheetImpl(const CSSStyleSheetImpl& aCopy);
|
||||
CSSStyleSheetImpl& operator=(const CSSStyleSheetImpl& aCopy);
|
||||
|
||||
protected:
|
||||
virtual ~CSSStyleSheetImpl();
|
||||
|
||||
protected:
|
||||
PRUint32 mInHeap : 1;
|
||||
PRUint32 mRefCnt : 31;
|
||||
|
||||
nsIURL* mURL;
|
||||
CSSStyleSheetImpl* mFirstChild;
|
||||
nsISupportsArray* mRules;
|
||||
CSSStyleSheetImpl* mNext;
|
||||
};
|
||||
|
||||
|
||||
void* CSSStyleSheetImpl::operator new(size_t size)
|
||||
{
|
||||
CSSStyleSheetImpl* rv = (CSSStyleSheetImpl*) ::operator new(size);
|
||||
#ifdef NS_DEBUG
|
||||
if (nsnull != rv) {
|
||||
nsCRT::memset(rv, 0xEE, size);
|
||||
}
|
||||
#endif
|
||||
rv->mInHeap = 1;
|
||||
return (void*) rv;
|
||||
}
|
||||
|
||||
void* CSSStyleSheetImpl::operator new(size_t size, nsIArena* aArena)
|
||||
{
|
||||
CSSStyleSheetImpl* rv = (CSSStyleSheetImpl*) aArena->Alloc(PRInt32(size));
|
||||
#ifdef NS_DEBUG
|
||||
if (nsnull != rv) {
|
||||
nsCRT::memset(rv, 0xEE, size);
|
||||
}
|
||||
#endif
|
||||
rv->mInHeap = 0;
|
||||
return (void*) rv;
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::operator delete(void* ptr)
|
||||
{
|
||||
CSSStyleSheetImpl* sheet = (CSSStyleSheetImpl*) ptr;
|
||||
if (nsnull != sheet) {
|
||||
if (sheet->mInHeap) {
|
||||
::delete ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
CSSStyleSheetImpl::CSSStyleSheetImpl(nsIURL* aURL)
|
||||
: nsICSSStyleSheet(),
|
||||
mURL(aURL), mFirstChild(nsnull), mRules(nsnull), mNext(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mURL);
|
||||
}
|
||||
|
||||
CSSStyleSheetImpl::~CSSStyleSheetImpl()
|
||||
{
|
||||
NS_RELEASE(mURL);
|
||||
NS_IF_RELEASE(mFirstChild);
|
||||
NS_IF_RELEASE(mRules);
|
||||
NS_IF_RELEASE(mNext);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(CSSStyleSheetImpl)
|
||||
NS_IMPL_RELEASE(CSSStyleSheetImpl)
|
||||
|
||||
nsresult CSSStyleSheetImpl::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kICSSStyleSheetIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsICSSStyleSheet*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIStyleSheetIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIStyleSheet*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsISupports*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
PRBool CSSStyleSheetImpl::SelectorMatches(nsCSSSelector* aSelector, nsIContent* aContent)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
|
||||
if ((nsnull == aSelector->mTag) || (aSelector->mTag == aContent->GetTag())) {
|
||||
if ((nsnull != aSelector->mClass) || (nsnull != aSelector->mTag)) {
|
||||
nsIHTMLContent* htmlContent;
|
||||
if (NS_OK == aContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent)) {
|
||||
if ((nsnull == aSelector->mClass) || (aSelector->mClass == htmlContent->GetClass())) {
|
||||
if ((nsnull == aSelector->mID) || (aSelector->mID == htmlContent->GetID())) {
|
||||
result = PR_TRUE;
|
||||
}
|
||||
}
|
||||
NS_RELEASE(htmlContent);
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = PR_TRUE;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PRInt32 CSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParentFrame,
|
||||
nsISupportsArray* aResults)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aPresContext, "null arg");
|
||||
NS_PRECONDITION(nsnull != aContent, "null arg");
|
||||
// NS_PRECONDITION(nsnull != aParentFrame, "null arg");
|
||||
NS_PRECONDITION(nsnull != aResults, "null arg");
|
||||
|
||||
PRInt32 matchCount = 0;
|
||||
CSSStyleSheetImpl* child = mFirstChild;
|
||||
while (nsnull != child) {
|
||||
matchCount += child->RulesMatching(aPresContext, aContent, aParentFrame, aResults);
|
||||
child = child->mNext;
|
||||
}
|
||||
|
||||
PRInt32 count = ((nsnull != mRules) ? mRules->Count() : 0);
|
||||
|
||||
for (PRInt32 index = 0; index < count; index++) {
|
||||
nsICSSStyleRule* rule = (nsICSSStyleRule*)mRules->ElementAt(index);
|
||||
|
||||
nsCSSSelector* selector = rule->FirstSelector();
|
||||
if (SelectorMatches(selector, aContent)) {
|
||||
selector = selector->mNext;
|
||||
nsIFrame* frame = aParentFrame;
|
||||
while ((nsnull != selector) && (nsnull != frame)) { // check compound selectors
|
||||
nsIContent* content = frame->GetContent();
|
||||
if (SelectorMatches(selector, content)) {
|
||||
selector = selector->mNext;
|
||||
}
|
||||
frame = frame->GetGeometricParent();
|
||||
NS_RELEASE(content);
|
||||
}
|
||||
if (nsnull == selector) { // ran out, it matched
|
||||
nsIStyleRule* iRule;
|
||||
if (NS_OK == rule->QueryInterface(kIStyleRuleIID, (void**)&iRule)) {
|
||||
aResults->AppendElement(iRule);
|
||||
NS_RELEASE(iRule);
|
||||
matchCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
return matchCount;
|
||||
}
|
||||
|
||||
nsIURL* CSSStyleSheetImpl::GetURL(void)
|
||||
{
|
||||
NS_ADDREF(mURL);
|
||||
return mURL;
|
||||
}
|
||||
|
||||
PRBool CSSStyleSheetImpl::ContainsStyleSheet(nsIURL* aURL)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aURL, "null arg");
|
||||
|
||||
PRBool result = (*mURL == *aURL);
|
||||
|
||||
CSSStyleSheetImpl* child = mFirstChild;
|
||||
while ((PR_FALSE == result) && (nsnull != child)) {
|
||||
result = child->ContainsStyleSheet(aURL);
|
||||
child = child->mNext;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::AppendStyleSheet(nsICSSStyleSheet* aSheet)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
||||
|
||||
if (nsnull == mFirstChild) {
|
||||
mFirstChild = (CSSStyleSheetImpl*)aSheet;
|
||||
}
|
||||
else {
|
||||
CSSStyleSheetImpl* child = mFirstChild;
|
||||
while (nsnull != child->mNext) {
|
||||
child = child->mNext;
|
||||
}
|
||||
child->mNext = (CSSStyleSheetImpl*)aSheet;
|
||||
}
|
||||
NS_ADDREF(aSheet);
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::PrependStyleRule(nsICSSStyleRule* aRule)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aRule, "null arg");
|
||||
NS_ADDREF(aRule);
|
||||
//XXX replace this with a binary search?
|
||||
PRInt32 weight = aRule->GetWeight();
|
||||
if (nsnull == mRules) {
|
||||
if (NS_OK != NS_NewISupportsArray(&mRules))
|
||||
return;
|
||||
}
|
||||
PRInt32 index = mRules->Count();
|
||||
while (0 <= --index) {
|
||||
nsICSSStyleRule* rule = (nsICSSStyleRule*)mRules->ElementAt(index);
|
||||
if (rule->GetWeight() > weight) { // insert before rules with equal or lesser weight
|
||||
NS_RELEASE(rule);
|
||||
break;
|
||||
}
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
mRules->InsertElementAt(aRule, index + 1);
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aRule, "null arg");
|
||||
NS_ADDREF(aRule);
|
||||
|
||||
//XXX replace this with a binary search?
|
||||
PRInt32 weight = aRule->GetWeight();
|
||||
if (nsnull == mRules) {
|
||||
if (NS_OK != NS_NewISupportsArray(&mRules))
|
||||
return;
|
||||
}
|
||||
PRInt32 count = mRules->Count();
|
||||
PRInt32 index = -1;
|
||||
while (++index < count) {
|
||||
nsICSSStyleRule* rule = (nsICSSStyleRule*)mRules->ElementAt(index);
|
||||
if (rule->GetWeight() < weight) { // insert after rules with equal or greater weight (before lower weight)
|
||||
NS_RELEASE(rule);
|
||||
break;
|
||||
}
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
mRules->InsertElementAt(aRule, index);
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
nsAutoString buffer;
|
||||
PRInt32 index;
|
||||
|
||||
// Indent
|
||||
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
||||
|
||||
fputs("CSS Style Sheet: ", out);
|
||||
mURL->ToString(buffer);
|
||||
fputs(buffer, out);
|
||||
fputs("\n", out);
|
||||
|
||||
CSSStyleSheetImpl* child = mFirstChild;
|
||||
while (nsnull != child) {
|
||||
child->List(out, aIndent + 1);
|
||||
child = child->mNext;
|
||||
}
|
||||
|
||||
PRInt32 count = ((nsnull != mRules) ? mRules->Count() : 0);
|
||||
|
||||
for (index = 0; index < count; index++) {
|
||||
nsICSSStyleRule* rule = (nsICSSStyleRule*)mRules->ElementAt(index);
|
||||
rule->List(out, aIndent);
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
}
|
||||
|
||||
NS_HTML nsresult
|
||||
NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult, nsIURL* aURL)
|
||||
{
|
||||
if (aInstancePtrResult == nsnull) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
CSSStyleSheetImpl *it = new CSSStyleSheetImpl(aURL);
|
||||
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kICSSStyleSheetIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
672
content/html/style/src/nsHTMLAttributes.cpp
Normal file
672
content/html/style/src/nsHTMLAttributes.cpp
Normal file
@@ -0,0 +1,672 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nsIHTMLAttributes.h"
|
||||
#include "nsIStyleRule.h"
|
||||
#include "nsString.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIArena.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
|
||||
static NS_DEFINE_IID(kIHTMLAttributesIID, NS_IHTML_ATTRIBUTES_IID);
|
||||
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
|
||||
|
||||
|
||||
struct HTMLAttribute {
|
||||
HTMLAttribute(nsIAtom* aAttribute, const nsString& aValue)
|
||||
: mAttribute(aAttribute),
|
||||
mValue(aValue),
|
||||
mNext(nsnull)
|
||||
{
|
||||
NS_IF_ADDREF(mAttribute);
|
||||
}
|
||||
|
||||
HTMLAttribute(nsIAtom* aAttribute, const nsHTMLValue& aValue)
|
||||
: mAttribute(aAttribute),
|
||||
mValue(aValue),
|
||||
mNext(nsnull)
|
||||
{
|
||||
NS_IF_ADDREF(mAttribute);
|
||||
}
|
||||
|
||||
HTMLAttribute(const HTMLAttribute& aCopy)
|
||||
: mAttribute(aCopy.mAttribute),
|
||||
mValue(aCopy.mValue),
|
||||
mNext(nsnull)
|
||||
{
|
||||
NS_IF_ADDREF(mAttribute);
|
||||
}
|
||||
|
||||
~HTMLAttribute(void)
|
||||
{
|
||||
NS_IF_RELEASE(mAttribute);
|
||||
}
|
||||
|
||||
HTMLAttribute& operator=(const HTMLAttribute& aCopy)
|
||||
{
|
||||
NS_IF_RELEASE(mAttribute);
|
||||
mAttribute = aCopy.mAttribute;
|
||||
NS_IF_ADDREF(mAttribute);
|
||||
mValue = aCopy.mValue;
|
||||
return *this;
|
||||
}
|
||||
|
||||
PRBool operator==(const HTMLAttribute& aOther) const
|
||||
{
|
||||
return PRBool((mAttribute == aOther.mAttribute) &&
|
||||
(mValue == aOther.mValue));
|
||||
}
|
||||
|
||||
void Reset(void)
|
||||
{
|
||||
NS_IF_RELEASE(mAttribute);
|
||||
mValue.Reset();
|
||||
}
|
||||
|
||||
void AppendToString(nsString& aBuffer) const
|
||||
{
|
||||
if (nsnull != mAttribute) {
|
||||
nsAutoString temp;
|
||||
mAttribute->ToString(temp);
|
||||
aBuffer.Append(temp);
|
||||
if (eHTMLUnit_Null != mValue.GetUnit()) {
|
||||
aBuffer.Append(" = ");
|
||||
mValue.AppendToString(aBuffer);
|
||||
}
|
||||
}
|
||||
else {
|
||||
aBuffer.Append("null");
|
||||
}
|
||||
}
|
||||
|
||||
void ToString(nsString& aBuffer) const
|
||||
{
|
||||
if (nsnull != mAttribute) {
|
||||
mAttribute->ToString(aBuffer);
|
||||
if (eHTMLUnit_Null != mValue.GetUnit()) {
|
||||
aBuffer.Append(" = ");
|
||||
mValue.AppendToString(aBuffer);
|
||||
}
|
||||
}
|
||||
else {
|
||||
aBuffer.SetLength(0);
|
||||
aBuffer.Append("null");
|
||||
}
|
||||
}
|
||||
|
||||
nsIAtom* mAttribute;
|
||||
nsHTMLValue mValue;
|
||||
HTMLAttribute* mNext;
|
||||
};
|
||||
|
||||
// ----------------
|
||||
|
||||
|
||||
class HTMLAttributesImpl: public nsIHTMLAttributes, public nsIStyleRule {
|
||||
public:
|
||||
void* operator new(size_t size);
|
||||
void* operator new(size_t size, nsIArena* aArena);
|
||||
void operator delete(void* ptr);
|
||||
|
||||
HTMLAttributesImpl(nsIHTMLContent* aContent);
|
||||
~HTMLAttributesImpl(void);
|
||||
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
|
||||
virtual PRBool Equals(const nsIStyleRule* aRule) const;
|
||||
virtual PRUint32 HashValue(void) const;
|
||||
|
||||
virtual PRInt32 SetAttribute(nsIAtom* aAttribute, const nsString& aValue);
|
||||
virtual PRInt32 SetAttribute(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue = nsHTMLValue::kNull);
|
||||
virtual PRInt32 UnsetAttribute(nsIAtom* aAttribute);
|
||||
virtual nsContentAttr GetAttribute(nsIAtom* aAttribute,
|
||||
nsHTMLValue& aValue) const;
|
||||
virtual PRInt32 GetAllAttributeNames(nsISupportsArray* aArray) const;
|
||||
virtual PRInt32 Count(void) const;
|
||||
|
||||
virtual PRInt32 SetID(nsIAtom* aID);
|
||||
virtual nsIAtom* GetID(void) const;
|
||||
virtual PRInt32 SetClass(nsIAtom* aClass); // XXX this will have to change for CSS2
|
||||
virtual nsIAtom* GetClass(void) const; // XXX this will have to change for CSS2
|
||||
|
||||
virtual void MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
private:
|
||||
HTMLAttributesImpl(const HTMLAttributesImpl& aCopy);
|
||||
HTMLAttributesImpl& operator=(const HTMLAttributesImpl& aCopy);
|
||||
PRBool operator==(const HTMLAttributesImpl& aCopy) const;
|
||||
|
||||
protected:
|
||||
PRUint32 mInHeap : 1;
|
||||
PRUint32 mRefCnt : 31;
|
||||
|
||||
nsIHTMLContent* mContent;
|
||||
PRInt32 mCount;
|
||||
HTMLAttribute* mFirst;
|
||||
nsIAtom* mID;
|
||||
nsIAtom* mClass;
|
||||
};
|
||||
|
||||
void* HTMLAttributesImpl::operator new(size_t size)
|
||||
{
|
||||
HTMLAttributesImpl* rv = (HTMLAttributesImpl*) ::operator new(size);
|
||||
#ifdef NS_DEBUG
|
||||
if (nsnull != rv) {
|
||||
nsCRT::memset(rv, 0xEE, size);
|
||||
}
|
||||
#endif
|
||||
rv->mInHeap = 1;
|
||||
return (void*) rv;
|
||||
}
|
||||
|
||||
void* HTMLAttributesImpl::operator new(size_t size, nsIArena* aArena)
|
||||
{
|
||||
HTMLAttributesImpl* rv = (HTMLAttributesImpl*) aArena->Alloc(PRInt32(size));
|
||||
#ifdef NS_DEBUG
|
||||
if (nsnull != rv) {
|
||||
nsCRT::memset(rv, 0xEE, size);
|
||||
}
|
||||
#endif
|
||||
rv->mInHeap = 0;
|
||||
return (void*) rv;
|
||||
}
|
||||
|
||||
void HTMLAttributesImpl::operator delete(void* ptr)
|
||||
{
|
||||
HTMLAttributesImpl* attr = (HTMLAttributesImpl*) ptr;
|
||||
if (nsnull != attr) {
|
||||
if (attr->mInHeap) {
|
||||
::delete ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HTMLAttributesImpl::HTMLAttributesImpl(nsIHTMLContent* aContent)
|
||||
: mContent(aContent), // weak ref
|
||||
mFirst(nsnull),
|
||||
mCount(0),
|
||||
mID(nsnull),
|
||||
mClass(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
HTMLAttributesImpl::~HTMLAttributesImpl(void)
|
||||
{
|
||||
HTMLAttribute* next = mFirst;
|
||||
while (nsnull != next) {
|
||||
HTMLAttribute* attr = next;
|
||||
next = next->mNext;
|
||||
delete attr;
|
||||
}
|
||||
NS_IF_RELEASE(mID);
|
||||
NS_IF_RELEASE(mClass);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(HTMLAttributesImpl)
|
||||
NS_IMPL_RELEASE(HTMLAttributesImpl)
|
||||
|
||||
nsresult HTMLAttributesImpl::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kIHTMLAttributesIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIHTMLAttributes*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIStyleRuleIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIStyleRule*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsISupports*)(nsIHTMLAttributes*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
PRBool HTMLAttributesImpl::Equals(const nsIStyleRule* aRule) const
|
||||
{
|
||||
nsIHTMLAttributes* iHTMLAttr;
|
||||
|
||||
if (this == aRule) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
if ((nsnull != aRule) &&
|
||||
(NS_OK == ((nsIStyleRule*)aRule)->QueryInterface(kIHTMLAttributesIID, (void**) &iHTMLAttr))) {
|
||||
|
||||
const HTMLAttributesImpl* other = (HTMLAttributesImpl*)iHTMLAttr;
|
||||
PRBool result = PR_FALSE;
|
||||
|
||||
if (mCount == other->mCount) {
|
||||
if ((mID == other->mID) && (mClass == other->mClass)) {
|
||||
const HTMLAttribute* attr = mFirst;
|
||||
const HTMLAttribute* otherAttr = other->mFirst;
|
||||
|
||||
result = PR_TRUE;
|
||||
while (nsnull != attr) {
|
||||
if (! ((*attr) == (*otherAttr))) {
|
||||
result = PR_FALSE;
|
||||
break;
|
||||
}
|
||||
attr = attr->mNext;
|
||||
otherAttr = otherAttr->mNext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NS_RELEASE(iHTMLAttr);
|
||||
return result;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRUint32 HTMLAttributesImpl::HashValue(void) const
|
||||
{
|
||||
return (PRUint32)this;
|
||||
}
|
||||
|
||||
PRInt32 HTMLAttributesImpl::SetAttribute(nsIAtom* aAttribute, const nsString& aValue)
|
||||
{
|
||||
if (nsHTMLAtoms::id == aAttribute) {
|
||||
nsIAtom* id = NS_NewAtom(aValue);
|
||||
PRInt32 result = SetID (id);
|
||||
NS_RELEASE(id);
|
||||
return result;
|
||||
}
|
||||
if (nsHTMLAtoms::kClass == aAttribute) {
|
||||
nsIAtom* classA = NS_NewAtom(aValue);
|
||||
PRInt32 result = SetClass (classA);
|
||||
NS_RELEASE(classA);
|
||||
return result;
|
||||
}
|
||||
|
||||
HTMLAttribute* last = nsnull;
|
||||
HTMLAttribute* attr = mFirst;
|
||||
|
||||
while (nsnull != attr) {
|
||||
if (attr->mAttribute == aAttribute) {
|
||||
attr->mValue.Set (aValue);
|
||||
return mCount;
|
||||
}
|
||||
last = attr;
|
||||
attr = attr->mNext;
|
||||
}
|
||||
|
||||
attr = new HTMLAttribute(aAttribute, aValue);
|
||||
if (nsnull == last) {
|
||||
mFirst = attr;
|
||||
}
|
||||
else {
|
||||
last->mNext = attr;
|
||||
}
|
||||
return ++mCount;
|
||||
}
|
||||
|
||||
PRInt32 HTMLAttributesImpl::SetAttribute(nsIAtom* aAttribute, const nsHTMLValue& aValue)
|
||||
{
|
||||
if (nsHTMLAtoms::id == aAttribute) {
|
||||
nsAutoString buffer;
|
||||
nsIAtom* id = NS_NewAtom(aValue.GetStringValue(buffer));
|
||||
PRInt32 result = SetID (id);
|
||||
NS_RELEASE(id);
|
||||
return result;
|
||||
}
|
||||
if (nsHTMLAtoms::kClass == aAttribute) {
|
||||
nsAutoString buffer;
|
||||
nsIAtom* classA = NS_NewAtom(aValue.GetStringValue(buffer));
|
||||
PRInt32 result = SetClass (classA);
|
||||
NS_RELEASE(classA);
|
||||
return result;
|
||||
}
|
||||
|
||||
HTMLAttribute* last = nsnull;
|
||||
HTMLAttribute* attr = mFirst;
|
||||
|
||||
while (nsnull != attr) {
|
||||
if (attr->mAttribute == aAttribute) {
|
||||
attr->mValue = aValue;
|
||||
return mCount;
|
||||
}
|
||||
last = attr;
|
||||
attr = attr->mNext;
|
||||
}
|
||||
|
||||
attr = new HTMLAttribute(aAttribute, aValue);
|
||||
if (nsnull == last) {
|
||||
mFirst = attr;
|
||||
}
|
||||
else {
|
||||
last->mNext = attr;
|
||||
}
|
||||
return ++mCount;
|
||||
}
|
||||
|
||||
PRInt32 HTMLAttributesImpl::UnsetAttribute(nsIAtom* aAttribute)
|
||||
{
|
||||
if (nsHTMLAtoms::id == aAttribute) {
|
||||
return SetID (nsnull);
|
||||
}
|
||||
if (nsHTMLAtoms::kClass == aAttribute) {
|
||||
return SetClass (nsnull);
|
||||
}
|
||||
|
||||
HTMLAttribute* prev = nsnull;
|
||||
HTMLAttribute* attr = mFirst;
|
||||
|
||||
while (nsnull != attr) {
|
||||
if (attr->mAttribute == aAttribute) {
|
||||
if (nsnull == prev) {
|
||||
mFirst = attr->mNext;
|
||||
}
|
||||
else {
|
||||
prev->mNext = attr->mNext;
|
||||
}
|
||||
delete attr;
|
||||
mCount--;
|
||||
break;
|
||||
}
|
||||
prev = attr;
|
||||
attr = attr->mNext;
|
||||
}
|
||||
return mCount;
|
||||
}
|
||||
|
||||
nsContentAttr HTMLAttributesImpl::GetAttribute(nsIAtom* aAttribute,
|
||||
nsHTMLValue& aValue) const
|
||||
{
|
||||
aValue.Reset();
|
||||
if (nsHTMLAtoms::id == aAttribute) {
|
||||
nsIAtom* id = GetID();
|
||||
if (nsnull != id) {
|
||||
nsAutoString buffer;
|
||||
id->ToString(buffer);
|
||||
aValue.Set(buffer);
|
||||
NS_RELEASE(id);
|
||||
return eContentAttr_HasValue;
|
||||
}
|
||||
return eContentAttr_NotThere;
|
||||
}
|
||||
if (nsHTMLAtoms::kClass == aAttribute) {
|
||||
nsIAtom* classA = GetClass();
|
||||
if (nsnull != classA) {
|
||||
nsAutoString buffer;
|
||||
classA->ToString(buffer);
|
||||
aValue.Set(buffer);
|
||||
NS_RELEASE(classA);
|
||||
return eContentAttr_HasValue;
|
||||
}
|
||||
return eContentAttr_NotThere;
|
||||
}
|
||||
|
||||
HTMLAttribute* attr = mFirst;
|
||||
|
||||
while (nsnull != attr) {
|
||||
if (attr->mAttribute == aAttribute) {
|
||||
aValue = attr->mValue;
|
||||
return ((attr->mValue.GetUnit() == eHTMLUnit_Null) ? eContentAttr_NoValue : eContentAttr_HasValue);
|
||||
}
|
||||
attr = attr->mNext;
|
||||
}
|
||||
return eContentAttr_NotThere;
|
||||
}
|
||||
|
||||
PRInt32 HTMLAttributesImpl::GetAllAttributeNames(nsISupportsArray* aArray) const
|
||||
{
|
||||
NS_ASSERTION(nsnull != aArray, "null arg");
|
||||
|
||||
if (nsnull == aArray) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (nsnull != mID) {
|
||||
aArray->AppendElement((nsIAtom*)nsHTMLAtoms::id);
|
||||
}
|
||||
if (nsnull != mClass) {
|
||||
aArray->AppendElement((nsIAtom*)nsHTMLAtoms::kClass);
|
||||
}
|
||||
|
||||
HTMLAttribute* attr = mFirst;
|
||||
|
||||
while (nsnull != attr) {
|
||||
aArray->AppendElement(attr->mAttribute);
|
||||
attr = attr->mNext;
|
||||
}
|
||||
return mCount;
|
||||
}
|
||||
|
||||
PRInt32 HTMLAttributesImpl::Count(void) const
|
||||
{
|
||||
return mCount;
|
||||
}
|
||||
|
||||
PRInt32 HTMLAttributesImpl::SetID(nsIAtom* aID)
|
||||
{
|
||||
if (aID != mID) {
|
||||
if (nsnull != mID) {
|
||||
NS_RELEASE(mID);
|
||||
mCount--;
|
||||
}
|
||||
mID = aID;
|
||||
if (nsnull != mID) {
|
||||
NS_ADDREF(mID);
|
||||
mCount++;
|
||||
}
|
||||
}
|
||||
return mCount;
|
||||
}
|
||||
|
||||
nsIAtom* HTMLAttributesImpl::GetID(void) const
|
||||
{
|
||||
NS_IF_ADDREF(mID);
|
||||
return mID;
|
||||
}
|
||||
|
||||
PRInt32 HTMLAttributesImpl::SetClass(nsIAtom* aClass)
|
||||
{
|
||||
if (aClass != mClass) {
|
||||
if (nsnull != mClass) {
|
||||
NS_RELEASE(mClass);
|
||||
mCount--;
|
||||
}
|
||||
mClass = aClass;
|
||||
if (nsnull != mClass) {
|
||||
NS_ADDREF(mClass);
|
||||
mCount++;
|
||||
}
|
||||
}
|
||||
return mCount;
|
||||
}
|
||||
|
||||
nsIAtom* HTMLAttributesImpl::GetClass(void) const
|
||||
{
|
||||
NS_IF_ADDREF(mClass);
|
||||
return mClass;
|
||||
}
|
||||
|
||||
void HTMLAttributesImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext)
|
||||
{
|
||||
if (nsnull != mContent) {
|
||||
mContent->MapAttributesInto(aContext, aPresContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HTMLAttributesImpl::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
HTMLAttribute* attr = mFirst;
|
||||
nsString buffer;
|
||||
|
||||
while (nsnull != attr) {
|
||||
fputs("\n", out);
|
||||
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
||||
attr->ToString(buffer);
|
||||
fputs(buffer, out);
|
||||
attr = attr->mNext;
|
||||
}
|
||||
}
|
||||
|
||||
extern NS_HTML nsresult
|
||||
NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult, nsIHTMLContent* aContent)
|
||||
{
|
||||
if (aInstancePtrResult == nsnull) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
HTMLAttributesImpl *it = new HTMLAttributesImpl(aContent);
|
||||
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kIHTMLAttributesIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
|
||||
marginwidth; marginheight: px
|
||||
|
||||
border: px
|
||||
|
||||
align(DIV): left, right, center, justify
|
||||
align: left, right, center, abscenter
|
||||
valign: baseline, top, bottom, middle, center
|
||||
align(image): abscenter, left, right, texttop, absbottom, baseline, center, bottom, top, middle, absmiddle
|
||||
|
||||
dir: rtl, ltr
|
||||
|
||||
width: px, %
|
||||
height: px, %
|
||||
|
||||
vspace; hspace: px
|
||||
|
||||
type(list): none, disc, (circle | round), square, decimal, lower-roman, upper-roman, lower-alpha, upper-alpha
|
||||
|
||||
href: url
|
||||
target: string
|
||||
src: url(string?)
|
||||
color: color
|
||||
face: string
|
||||
suppress: bool
|
||||
|
||||
style: string
|
||||
class: string (list)
|
||||
id: string
|
||||
name: string
|
||||
|
||||
//a
|
||||
link; vlink; alink: color
|
||||
|
||||
//body
|
||||
background: url
|
||||
bgcolor: color
|
||||
text: color
|
||||
|
||||
//frameset
|
||||
bordercolor: color
|
||||
|
||||
//layer
|
||||
background: url
|
||||
bgcolor: color
|
||||
|
||||
//q
|
||||
lang: string
|
||||
|
||||
//table
|
||||
background: url
|
||||
bgcolor: color
|
||||
bordercolor: color
|
||||
cellspacing: px
|
||||
cellpadding: px
|
||||
toppadding; leftpadding; bottompadding; rightpadding: px
|
||||
cols: int
|
||||
|
||||
//td
|
||||
background: url
|
||||
bgcolor: color
|
||||
nowrap: bool
|
||||
colspan; rowspan: int
|
||||
|
||||
//tr
|
||||
background: url
|
||||
bgcolor: color
|
||||
|
||||
//colgroup
|
||||
span: int
|
||||
|
||||
//col
|
||||
repeat: int
|
||||
|
||||
//ul;ol
|
||||
compact: bool
|
||||
start: int
|
||||
|
||||
//li
|
||||
value: int
|
||||
|
||||
//hr;spacer
|
||||
size: px
|
||||
|
||||
//multicol
|
||||
cols: int
|
||||
gutter: px
|
||||
|
||||
//input
|
||||
type: string
|
||||
value: string
|
||||
|
||||
//factory methods:
|
||||
GetStringData
|
||||
GetBoolData
|
||||
GetInvBoolData
|
||||
GetPixelIntData
|
||||
GetValueOrPctData
|
||||
GetValueData
|
||||
|
||||
//tag methods
|
||||
getAttribute
|
||||
getIntAttribute
|
||||
getKeywordAttribute
|
||||
getSignedAttribute
|
||||
getValueOrPctAttribute
|
||||
|
||||
|
||||
//notes
|
||||
nsIAtom->value table
|
||||
|
||||
#endif
|
||||
214
content/html/style/src/nsHTMLStyleSheet.cpp
Normal file
214
content/html/style/src/nsHTMLStyleSheet.cpp
Normal file
@@ -0,0 +1,214 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsIHTMLStyleSheet.h"
|
||||
#include "nsIArena.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsIStyleRule.h"
|
||||
|
||||
static NS_DEFINE_IID(kIHTMLStyleSheetIID, NS_IHTML_STYLE_SHEET_IID);
|
||||
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
|
||||
static NS_DEFINE_IID(kIHTMLContentIID, NS_IHTMLCONTENT_IID);
|
||||
|
||||
|
||||
class HTMLStyleSheetImpl : public nsIHTMLStyleSheet {
|
||||
public:
|
||||
void* operator new(size_t size);
|
||||
void* operator new(size_t size, nsIArena* aArena);
|
||||
void operator delete(void* ptr);
|
||||
|
||||
HTMLStyleSheetImpl(nsIURL* aURL);
|
||||
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
|
||||
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParentFrame,
|
||||
nsISupportsArray* aResults);
|
||||
|
||||
virtual nsIURL* GetURL(void);
|
||||
|
||||
// XXX style rule enumerations
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
private:
|
||||
// These are not supported and are not implemented!
|
||||
HTMLStyleSheetImpl(const HTMLStyleSheetImpl& aCopy);
|
||||
HTMLStyleSheetImpl& operator=(const HTMLStyleSheetImpl& aCopy);
|
||||
|
||||
protected:
|
||||
virtual ~HTMLStyleSheetImpl();
|
||||
|
||||
protected:
|
||||
PRUint32 mInHeap : 1;
|
||||
PRUint32 mRefCnt : 31;
|
||||
|
||||
nsIURL* mURL;
|
||||
};
|
||||
|
||||
|
||||
void* HTMLStyleSheetImpl::operator new(size_t size)
|
||||
{
|
||||
HTMLStyleSheetImpl* rv = (HTMLStyleSheetImpl*) ::operator new(size);
|
||||
#ifdef NS_DEBUG
|
||||
if (nsnull != rv) {
|
||||
nsCRT::memset(rv, 0xEE, size);
|
||||
}
|
||||
#endif
|
||||
rv->mInHeap = 1;
|
||||
return (void*) rv;
|
||||
}
|
||||
|
||||
void* HTMLStyleSheetImpl::operator new(size_t size, nsIArena* aArena)
|
||||
{
|
||||
HTMLStyleSheetImpl* rv = (HTMLStyleSheetImpl*) aArena->Alloc(PRInt32(size));
|
||||
#ifdef NS_DEBUG
|
||||
if (nsnull != rv) {
|
||||
nsCRT::memset(rv, 0xEE, size);
|
||||
}
|
||||
#endif
|
||||
rv->mInHeap = 0;
|
||||
return (void*) rv;
|
||||
}
|
||||
|
||||
void HTMLStyleSheetImpl::operator delete(void* ptr)
|
||||
{
|
||||
HTMLStyleSheetImpl* sheet = (HTMLStyleSheetImpl*) ptr;
|
||||
if (nsnull != sheet) {
|
||||
if (sheet->mInHeap) {
|
||||
::delete ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
HTMLStyleSheetImpl::HTMLStyleSheetImpl(nsIURL* aURL)
|
||||
: nsIHTMLStyleSheet(),
|
||||
mURL(aURL)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mURL);
|
||||
}
|
||||
|
||||
HTMLStyleSheetImpl::~HTMLStyleSheetImpl()
|
||||
{
|
||||
NS_RELEASE(mURL);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(HTMLStyleSheetImpl)
|
||||
NS_IMPL_RELEASE(HTMLStyleSheetImpl)
|
||||
|
||||
nsresult HTMLStyleSheetImpl::QueryInterface(const nsIID& aIID,
|
||||
void** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
|
||||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kIHTMLStyleSheetIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIHTMLStyleSheet*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIStyleSheetIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsIStyleSheet*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsISupports*)this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
|
||||
nsIContent* aContent,
|
||||
nsIFrame* aParentFrame,
|
||||
nsISupportsArray* aResults)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aPresContext, "null arg");
|
||||
NS_PRECONDITION(nsnull != aContent, "null arg");
|
||||
// NS_PRECONDITION(nsnull != aParentFrame, "null arg");
|
||||
NS_PRECONDITION(nsnull != aResults, "null arg");
|
||||
|
||||
PRInt32 matchCount = 0;
|
||||
|
||||
nsIHTMLContent* htmlContent;
|
||||
|
||||
// for now, just get the one and only style rule from the content
|
||||
// this may need some special handling for pseudo-frames
|
||||
if (NS_OK == aContent->QueryInterface(kIHTMLContentIID, (void**)&htmlContent)) {
|
||||
nsIStyleRule* rule = htmlContent->GetStyleRule();
|
||||
|
||||
if (nsnull != rule) {
|
||||
aResults->AppendElement(rule);
|
||||
NS_RELEASE(rule);
|
||||
matchCount++;
|
||||
}
|
||||
|
||||
NS_RELEASE(htmlContent);
|
||||
}
|
||||
|
||||
return matchCount;
|
||||
}
|
||||
|
||||
nsIURL* HTMLStyleSheetImpl::GetURL(void)
|
||||
{
|
||||
NS_ADDREF(mURL);
|
||||
return mURL;
|
||||
}
|
||||
|
||||
void HTMLStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
nsAutoString buffer;
|
||||
|
||||
// Indent
|
||||
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
||||
|
||||
fputs("HTML Style Sheet: ", out);
|
||||
mURL->ToString(buffer);
|
||||
fputs(buffer, out);
|
||||
fputs("\n", out);
|
||||
|
||||
}
|
||||
|
||||
NS_HTML nsresult
|
||||
NS_NewHTMLStyleSheet(nsIHTMLStyleSheet** aInstancePtrResult, nsIURL* aURL)
|
||||
{
|
||||
if (aInstancePtrResult == nsnull) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
HTMLStyleSheetImpl *it = new HTMLStyleSheetImpl(aURL);
|
||||
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return it->QueryInterface(kIHTMLStyleSheetIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
257
content/html/style/src/nsHTMLValue.cpp
Normal file
257
content/html/style/src/nsHTMLValue.cpp
Normal file
@@ -0,0 +1,257 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nsHTMLValue.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
const nsHTMLValue nsHTMLValue::kNull;
|
||||
|
||||
nsHTMLValue::nsHTMLValue(void)
|
||||
: mUnit(eHTMLUnit_Null)
|
||||
{
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit)
|
||||
: mUnit(aUnit)
|
||||
{
|
||||
mValue.mInt = aValue;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(float aValue, nsHTMLUnit aUnit)
|
||||
: mUnit(aUnit)
|
||||
{
|
||||
mValue.mFloat = aValue;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(const nsString& aValue)
|
||||
: mUnit(eHTMLUnit_String)
|
||||
{
|
||||
mValue.mString = aValue.ToNewString();
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nsISupports* aValue)
|
||||
: mUnit(eHTMLUnit_ISupports)
|
||||
{
|
||||
mValue.mISupports = aValue;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nscolor aValue)
|
||||
: mUnit(eHTMLUnit_Color)
|
||||
{
|
||||
mValue.mColor = aValue;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(const nsHTMLValue& aCopy)
|
||||
: mUnit(aCopy.mUnit)
|
||||
{
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull != aCopy.mValue.mString) {
|
||||
mValue.mString = aCopy.mValue.mString->ToNewString();
|
||||
}
|
||||
else {
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
mValue.mISupports = aCopy.mValue.mISupports;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
mValue.mColor = aCopy.mValue.mColor;
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
mValue.mFloat = aCopy.mValue.mFloat;
|
||||
}
|
||||
else {
|
||||
mValue.mInt = aCopy.mValue.mInt;
|
||||
}
|
||||
}
|
||||
|
||||
nsHTMLValue::~nsHTMLValue(void)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
nsHTMLValue& nsHTMLValue::operator=(const nsHTMLValue& aCopy)
|
||||
{
|
||||
Reset();
|
||||
mUnit = aCopy.mUnit;
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull != aCopy.mValue.mString) {
|
||||
mValue.mString = aCopy.mValue.mString->ToNewString();
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
mValue.mISupports = aCopy.mValue.mISupports;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
mValue.mColor = aCopy.mValue.mColor;
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
mValue.mFloat = aCopy.mValue.mFloat;
|
||||
}
|
||||
else {
|
||||
mValue.mInt = aCopy.mValue.mInt;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
PRBool nsHTMLValue::operator==(const nsHTMLValue& aOther) const
|
||||
{
|
||||
if (mUnit == aOther.mUnit) {
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull == mValue.mString) {
|
||||
if (nsnull == aOther.mValue.mString) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
else if (nsnull != aOther.mValue.mString) {
|
||||
return mValue.mString->Equals(*(aOther.mValue.mString));
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
return PRBool(mValue.mISupports == aOther.mValue.mISupports);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
return PRBool(mValue.mColor == aOther.mValue.mColor);
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
return PRBool(mValue.mFloat == aOther.mValue.mFloat);
|
||||
}
|
||||
else {
|
||||
return PRBool(mValue.mInt == aOther.mValue.mInt);
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
void nsHTMLValue::Reset(void)
|
||||
{
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull != mValue.mString) {
|
||||
delete mValue.mString;
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
NS_IF_RELEASE(mValue.mISupports);
|
||||
}
|
||||
mUnit = eHTMLUnit_Null;
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
|
||||
|
||||
void nsHTMLValue::Set(PRInt32 aValue, nsHTMLUnit aUnit)
|
||||
{
|
||||
Reset();
|
||||
mUnit = aUnit;
|
||||
mValue.mInt = aValue;
|
||||
}
|
||||
|
||||
void nsHTMLValue::Set(float aValue, nsHTMLUnit aUnit)
|
||||
{
|
||||
Reset();
|
||||
mUnit = aUnit;
|
||||
mValue.mFloat = aValue;
|
||||
}
|
||||
|
||||
void nsHTMLValue::Set(const nsString& aValue)
|
||||
{
|
||||
Reset();
|
||||
mUnit = eHTMLUnit_String;
|
||||
mValue.mString = aValue.ToNewString();
|
||||
}
|
||||
|
||||
void nsHTMLValue::Set(nsISupports* aValue)
|
||||
{
|
||||
Reset();
|
||||
mUnit = eHTMLUnit_ISupports;
|
||||
mValue.mISupports = aValue;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
|
||||
void nsHTMLValue::Set(nscolor aValue)
|
||||
{
|
||||
Reset();
|
||||
mUnit = eHTMLUnit_Color;
|
||||
mValue.mColor = aValue;
|
||||
}
|
||||
|
||||
void nsHTMLValue::AppendToString(nsString& aBuffer) const
|
||||
{
|
||||
if (eHTMLUnit_Null == mUnit) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull != mValue.mString) {
|
||||
aBuffer.Append('"');
|
||||
aBuffer.Append(*(mValue.mString));
|
||||
aBuffer.Append('"');
|
||||
}
|
||||
else {
|
||||
aBuffer.Append("null str");
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
aBuffer.Append("0x");
|
||||
aBuffer.Append((PRInt32)mValue.mISupports, 16);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
aBuffer.Append("(0x");
|
||||
aBuffer.Append(NS_GET_R(mValue.mColor), 16);
|
||||
aBuffer.Append(" 0x");
|
||||
aBuffer.Append(NS_GET_G(mValue.mColor), 16);
|
||||
aBuffer.Append(" 0x");
|
||||
aBuffer.Append(NS_GET_B(mValue.mColor), 16);
|
||||
aBuffer.Append(" 0x");
|
||||
aBuffer.Append(NS_GET_A(mValue.mColor), 16);
|
||||
aBuffer.Append(')');
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
aBuffer.Append(mValue.mFloat);
|
||||
}
|
||||
else {
|
||||
aBuffer.Append(mValue.mInt, 10);
|
||||
aBuffer.Append("[0x");
|
||||
aBuffer.Append(mValue.mInt, 16);
|
||||
aBuffer.Append(']');
|
||||
}
|
||||
|
||||
switch (mUnit) {
|
||||
case eHTMLUnit_Null: break;
|
||||
case eHTMLUnit_String: break;
|
||||
case eHTMLUnit_ISupports: aBuffer.Append("ptr"); break;
|
||||
case eHTMLUnit_Absolute: break;
|
||||
case eHTMLUnit_Enumerated: aBuffer.Append("enum"); break;
|
||||
case eHTMLUnit_Color: aBuffer.Append("rbga"); break;
|
||||
case eHTMLUnit_Percent: aBuffer.Append("%"); break;
|
||||
case eHTMLUnit_Pixel: aBuffer.Append("px"); break;
|
||||
}
|
||||
aBuffer.Append(' ');
|
||||
}
|
||||
|
||||
void nsHTMLValue::ToString(nsString& aBuffer) const
|
||||
{
|
||||
aBuffer.SetLength(0);
|
||||
AppendToString(aBuffer);
|
||||
}
|
||||
|
||||
138
content/html/style/src/nsHTMLValue.h
Normal file
138
content/html/style/src/nsHTMLValue.h
Normal file
@@ -0,0 +1,138 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsHTMLValue_h___
|
||||
#define nsHTMLValue_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsString.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
|
||||
enum nsHTMLUnit {
|
||||
eHTMLUnit_Null = 0, // (n/a) null unit, value is not specified
|
||||
eHTMLUnit_String = 10, // (nsString) a string value
|
||||
eHTMLUnit_ISupports = 20, // (nsISupports*) a ref counted interface
|
||||
eHTMLUnit_Absolute = 50, // (int) simple value
|
||||
eHTMLUnit_Enumerated = 51, // (int) value has enumerated meaning
|
||||
eHTMLUnit_Color = 80, // (color) an RGBA value
|
||||
eHTMLUnit_Percent = 90, // (float) 1.0 == 100%) value is percentage of something
|
||||
|
||||
// Screen relative measure
|
||||
eHTMLUnit_Pixel = 600, // (int) screen pixels
|
||||
};
|
||||
|
||||
class nsHTMLValue {
|
||||
public:
|
||||
nsHTMLValue(void);
|
||||
nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit = eHTMLUnit_Absolute);
|
||||
nsHTMLValue(float aValue, nsHTMLUnit aUnit = eHTMLUnit_Pixel);
|
||||
nsHTMLValue(const nsString& aValue);
|
||||
nsHTMLValue(nsISupports* aValue);
|
||||
nsHTMLValue(nscolor aValue);
|
||||
nsHTMLValue(const nsHTMLValue& aCopy);
|
||||
~nsHTMLValue(void);
|
||||
|
||||
nsHTMLValue& operator=(const nsHTMLValue& aCopy);
|
||||
PRBool operator==(const nsHTMLValue& aOther) const;
|
||||
|
||||
nsHTMLUnit GetUnit(void) const { return mUnit; }
|
||||
PRInt32 GetIntValue(void) const;
|
||||
float GetFloatValue(void) const;
|
||||
nsString& GetStringValue(nsString& aBuffer) const;
|
||||
nsISupports* GetISupportsValue(void) const;
|
||||
nscolor GetColorValue(void) const;
|
||||
|
||||
void Reset(void);
|
||||
void Set(PRInt32 aValue, nsHTMLUnit aUnit = eHTMLUnit_Absolute);
|
||||
void Set(float aValue, nsHTMLUnit aUnit = eHTMLUnit_Pixel);
|
||||
void Set(const nsString& aValue);
|
||||
void Set(nsISupports* aValue);
|
||||
void Set(nscolor aValue);
|
||||
|
||||
void AppendToString(nsString& aBuffer) const;
|
||||
void ToString(nsString& aBuffer) const;
|
||||
|
||||
protected:
|
||||
nsHTMLUnit mUnit;
|
||||
union {
|
||||
PRInt32 mInt;
|
||||
float mFloat;
|
||||
nsString* mString;
|
||||
nsISupports* mISupports;
|
||||
nscolor mColor;
|
||||
} mValue;
|
||||
|
||||
public:
|
||||
static const nsHTMLValue kNull;
|
||||
};
|
||||
|
||||
inline PRInt32 nsHTMLValue::GetIntValue(void) const
|
||||
{
|
||||
NS_ASSERTION((mUnit == eHTMLUnit_Absolute) ||
|
||||
(mUnit == eHTMLUnit_Enumerated) ||
|
||||
(mUnit == eHTMLUnit_Pixel), "not an int value");
|
||||
if ((mUnit == eHTMLUnit_Absolute) ||
|
||||
(mUnit == eHTMLUnit_Enumerated) ||
|
||||
(mUnit == eHTMLUnit_Pixel)) {
|
||||
return mValue.mInt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline float nsHTMLValue::GetFloatValue(void) const
|
||||
{
|
||||
NS_ASSERTION(mUnit == eHTMLUnit_Percent, "not a float value");
|
||||
if (mUnit == eHTMLUnit_Percent) {
|
||||
return mValue.mFloat;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
inline nsString& nsHTMLValue::GetStringValue(nsString& aBuffer) const
|
||||
{
|
||||
NS_ASSERTION((mUnit == eHTMLUnit_String) || (mUnit == eHTMLUnit_Null), "not a string value");
|
||||
aBuffer.SetLength(0);
|
||||
if ((mUnit == eHTMLUnit_String) && (nsnull != mValue.mString)) {
|
||||
aBuffer.Append(*(mValue.mString));
|
||||
}
|
||||
return aBuffer;
|
||||
}
|
||||
|
||||
inline nsISupports* nsHTMLValue::GetISupportsValue(void) const
|
||||
{
|
||||
NS_ASSERTION(mUnit == eHTMLUnit_ISupports, "not an ISupports value");
|
||||
if (mUnit == eHTMLUnit_ISupports) {
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
return mValue.mISupports;
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
inline nscolor nsHTMLValue::GetColorValue(void) const
|
||||
{
|
||||
NS_ASSERTION(mUnit == eHTMLUnit_Color, "not a color value");
|
||||
if (mUnit == eHTMLUnit_Color) {
|
||||
return mValue.mColor;
|
||||
}
|
||||
return NS_RGB(0,0,0);
|
||||
}
|
||||
|
||||
|
||||
#endif /* nsHTMLValue_h___ */
|
||||
|
||||
305
content/html/style/src/nsICSSDeclaration.h
Normal file
305
content/html/style/src/nsICSSDeclaration.h
Normal file
@@ -0,0 +1,305 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsICSSDeclaration_h___
|
||||
#define nsICSSDeclaration_h___
|
||||
|
||||
#include "nslayout.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsColor.h"
|
||||
#include "stdio.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCoord.h"
|
||||
|
||||
|
||||
enum nsCSSUnit {
|
||||
eCSSUnit_Null = 0, // (n/a) null unit, value is not specified
|
||||
eCSSUnit_Auto = 1, // (n/a) value is algorithmic
|
||||
eCSSUnit_String = 10, // (nsString) a string value
|
||||
eCSSUnit_Absolute = 50, // (int) simple value
|
||||
eCSSUnit_Enumerated = 51, // (int) value has enumerated meaning
|
||||
eCSSUnit_Color = 80, // (color) an RGBA value
|
||||
eCSSUnit_Percent = 90, // (float) 1.0 == 100%) value is percentage of something
|
||||
eCSSUnit_Number = 91, // (float) value is numeric (usually multiplier, different behavior that percent)
|
||||
|
||||
// US English
|
||||
eCSSUnit_Inch = 100, // (float) Standard length
|
||||
eCSSUnit_Foot = 101, // (float) 12 inches
|
||||
eCSSUnit_Mile = 102, // (float) 5280 feet
|
||||
|
||||
// Metric
|
||||
eCSSUnit_Millimeter = 207, // (float) 1/1000 meter
|
||||
eCSSUnit_Centimeter = 208, // (float) 1/100 meter
|
||||
eCSSUnit_Meter = 210, // (float) Standard length
|
||||
eCSSUnit_Kilometer = 213, // (float) 1000 meters
|
||||
|
||||
// US Typographic
|
||||
eCSSUnit_Point = 300, // (float) 1/72 inch
|
||||
eCSSUnit_Pica = 301, // (float) 12 points == 1/6 inch
|
||||
|
||||
// European Typographic
|
||||
eCSSUnit_Didot = 400, // (float) 15 didots == 16 points
|
||||
eCSSUnit_Cicero = 401, // (float) 12 didots
|
||||
|
||||
// relative units
|
||||
// Font relative measure
|
||||
eCSSUnit_EM = 800, // (float) == current font size
|
||||
eCSSUnit_EN = 801, // (float) .5 em
|
||||
eCSSUnit_XHeight = 802, // (float) distance from top of lower case x to baseline
|
||||
eCSSUnit_CapHeight = 803, // (float) distance from top of uppercase case H to baseline
|
||||
|
||||
// Screen relative measure
|
||||
eCSSUnit_Pixel = 900 // (float)
|
||||
};
|
||||
|
||||
struct nsCSSStruct {
|
||||
virtual const nsID& GetID(void) = 0;
|
||||
};
|
||||
|
||||
class nsCSSValue {
|
||||
public:
|
||||
nsCSSValue(void);
|
||||
nsCSSValue(PRInt32 aValue, nsCSSUnit aUnit);
|
||||
nsCSSValue(float aValue, nsCSSUnit aUnit);
|
||||
nsCSSValue(const nsString& aValue);
|
||||
nsCSSValue(nscolor aValue);
|
||||
nsCSSValue(const nsCSSValue& aCopy);
|
||||
~nsCSSValue(void);
|
||||
|
||||
nsCSSValue& operator=(const nsCSSValue& aCopy);
|
||||
PRBool operator==(const nsCSSValue& aOther) const;
|
||||
|
||||
nsCSSUnit GetUnit(void) const { return mUnit; };
|
||||
PRBool IsLengthUnit(void) const
|
||||
{ return PRBool(eCSSUnit_Inch <= mUnit); }
|
||||
PRBool IsFixedLengthUnit(void) const
|
||||
{ return PRBool((eCSSUnit_Inch <= mUnit) && (mUnit < eCSSUnit_EM)); }
|
||||
PRBool IsRelativeLengthUnit(void) const
|
||||
{ return PRBool(eCSSUnit_EM <= mUnit); }
|
||||
|
||||
PRInt32 GetIntValue(void) const;
|
||||
float GetFloatValue(void) const;
|
||||
nsString& GetStringValue(nsString& aBuffer) const;
|
||||
nscolor GetColorValue(void) const;
|
||||
nscoord GetLengthTwips(void) const;
|
||||
|
||||
void Reset(void);
|
||||
void Set(PRInt32 aValue, nsCSSUnit aUnit);
|
||||
void Set(float aValue, nsCSSUnit aUnit);
|
||||
void Set(const nsString& aValue);
|
||||
void Set(nscolor aValue);
|
||||
|
||||
void AppendToString(nsString& aBuffer, PRInt32 aPropID = -1) const;
|
||||
void ToString(nsString& aBuffer, PRInt32 aPropID = -1) const;
|
||||
|
||||
protected:
|
||||
nsCSSUnit mUnit;
|
||||
union {
|
||||
PRInt32 mInt;
|
||||
float mFloat;
|
||||
nsString* mString;
|
||||
nscolor mColor;
|
||||
} mValue;
|
||||
};
|
||||
|
||||
inline PRInt32 nsCSSValue::GetIntValue(void) const
|
||||
{
|
||||
NS_ASSERTION((mUnit == eCSSUnit_Absolute) ||
|
||||
(mUnit == eCSSUnit_Enumerated), "not an int value");
|
||||
if ((mUnit == eCSSUnit_Absolute) ||
|
||||
(mUnit == eCSSUnit_Enumerated)) {
|
||||
return mValue.mInt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline float nsCSSValue::GetFloatValue(void) const
|
||||
{
|
||||
NS_ASSERTION((mUnit != eCSSUnit_Null) &&
|
||||
(mUnit != eCSSUnit_Absolute) &&
|
||||
(mUnit != eCSSUnit_Enumerated) &&
|
||||
(mUnit != eCSSUnit_String) &&
|
||||
(mUnit != eCSSUnit_Color), "not a float value");
|
||||
if ((mUnit != eCSSUnit_Null) &&
|
||||
(mUnit != eCSSUnit_Absolute) &&
|
||||
(mUnit != eCSSUnit_Enumerated) &&
|
||||
(mUnit != eCSSUnit_String) &&
|
||||
(mUnit != eCSSUnit_Color)) {
|
||||
return mValue.mFloat;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
inline nsString& nsCSSValue::GetStringValue(nsString& aBuffer) const
|
||||
{
|
||||
NS_ASSERTION((mUnit == eCSSUnit_String), "not a string value");
|
||||
aBuffer.Truncate();
|
||||
if ((mUnit == eCSSUnit_String) && (nsnull != mValue.mString)) {
|
||||
aBuffer.Append(*(mValue.mString));
|
||||
}
|
||||
return aBuffer;
|
||||
}
|
||||
|
||||
inline nscolor nsCSSValue::GetColorValue(void) const
|
||||
{
|
||||
NS_ASSERTION((mUnit == eCSSUnit_Color), "not a color value");
|
||||
if (mUnit == eCSSUnit_Color) {
|
||||
return mValue.mColor;
|
||||
}
|
||||
return NS_RGB(0,0,0);
|
||||
}
|
||||
|
||||
// SID for the nsCSSFont struct {f645dbf8-b48a-11d1-9ca5-0060088f9ff7}
|
||||
#define NS_CSS_FONT_SID \
|
||||
{0xf645dbf8, 0xb48a, 0x11d1, {0x9c, 0xa5, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7}}
|
||||
|
||||
// SID for the nsCSSColor struct {fd825f22-b48a-11d1-9ca5-0060088f9ff7}
|
||||
#define NS_CSS_COLOR_SID \
|
||||
{0xfd825f22, 0xb48a, 0x11d1, {0x9c, 0xa5, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7}}
|
||||
|
||||
// SID for the nsCSSText struct {fe13ce94-b48a-11d1-9ca5-0060088f9ff7}
|
||||
#define NS_CSS_TEXT_SID \
|
||||
{0xfe13ce94, 0xb48a, 0x11d1, {0x9c, 0xa5, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7}}
|
||||
|
||||
// SID for the nsCSSMargin struct {fe6019d4-b48a-11d1-9ca5-0060088f9ff7}
|
||||
#define NS_CSS_MARGIN_SID \
|
||||
{0xfe6019d4, 0xb48a, 0x11d1, {0x9c, 0xa5, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7}}
|
||||
|
||||
// SID for the nsCSSPosition struct {fee33b2a-b48a-11d1-9ca5-0060088f9ff7}
|
||||
#define NS_CSS_POSITION_SID \
|
||||
{0xfee33b2a, 0xb48a, 0x11d1, {0x9c, 0xa5, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7}}
|
||||
|
||||
// SID for the nsCSSList struct {603f8266-b48b-11d1-9ca5-0060088f9ff7}
|
||||
#define NS_CSS_LIST_SID \
|
||||
{0x603f8266, 0xb48b, 0x11d1, {0x9c, 0xa5, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7}}
|
||||
|
||||
// IID for the nsICSSDeclaration interface {7b36b9ac-b48d-11d1-9ca5-0060088f9ff7}
|
||||
#define NS_ICSS_DECLARATION_IID \
|
||||
{0x7b36b9ac, 0xb48d, 0x11d1, {0x9c, 0xa5, 0x00, 0x60, 0x08, 0x8f, 0x9f, 0xf7}}
|
||||
|
||||
struct nsCSSFont : public nsCSSStruct {
|
||||
const nsID& GetID(void);
|
||||
void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
nsCSSValue mFamily;
|
||||
nsCSSValue mStyle;
|
||||
nsCSSValue mVariant;
|
||||
nsCSSValue mWeight;
|
||||
nsCSSValue mSize;
|
||||
};
|
||||
|
||||
struct nsCSSColor : public nsCSSStruct {
|
||||
const nsID& GetID(void);
|
||||
void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
nsCSSValue mColor;
|
||||
nsCSSValue mBackColor;
|
||||
nsCSSValue mBackImage;
|
||||
nsCSSValue mBackRepeat;
|
||||
nsCSSValue mBackAttachment;
|
||||
nsCSSValue mBackPositionX;
|
||||
nsCSSValue mBackPositionY;
|
||||
nsCSSValue mBackFilter;
|
||||
};
|
||||
|
||||
struct nsCSSText : public nsCSSStruct {
|
||||
const nsID& GetID(void);
|
||||
void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
nsCSSValue mWordSpacing;
|
||||
nsCSSValue mLetterSpacing;
|
||||
nsCSSValue mDecoration;
|
||||
nsCSSValue mVertAlign;
|
||||
nsCSSValue mTransform;
|
||||
nsCSSValue mHorzAlign;
|
||||
nsCSSValue mIndent;
|
||||
nsCSSValue mLineHeight;
|
||||
nsCSSValue mWhiteSpace;
|
||||
};
|
||||
|
||||
struct nsCSSRect {
|
||||
void List(FILE* out = 0, PRInt32 aPropID = -1, PRInt32 aIndent = 0) const;
|
||||
|
||||
nsCSSValue mTop;
|
||||
nsCSSValue mRight;
|
||||
nsCSSValue mBottom;
|
||||
nsCSSValue mLeft;
|
||||
};
|
||||
|
||||
struct nsCSSMargin : public nsCSSStruct {
|
||||
nsCSSMargin(void);
|
||||
~nsCSSMargin(void);
|
||||
const nsID& GetID(void);
|
||||
void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
nsCSSRect* mMargin;
|
||||
nsCSSRect* mPadding;
|
||||
nsCSSRect* mBorder;
|
||||
nsCSSRect* mColor;
|
||||
nsCSSRect* mStyle;
|
||||
};
|
||||
|
||||
struct nsCSSPosition : public nsCSSStruct {
|
||||
nsCSSPosition(void);
|
||||
~nsCSSPosition(void);
|
||||
const nsID& GetID(void);
|
||||
void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
nsCSSValue mPosition;
|
||||
nsCSSValue mWidth;
|
||||
nsCSSValue mHeight;
|
||||
nsCSSValue mLeft;
|
||||
nsCSSValue mTop;
|
||||
nsCSSRect* mClip;
|
||||
nsCSSValue mOverflow;
|
||||
nsCSSValue mZIndex;
|
||||
nsCSSValue mVisibility;
|
||||
nsCSSValue mFloat;
|
||||
nsCSSValue mClear;
|
||||
nsCSSValue mDisplay;
|
||||
nsCSSValue mFilter;
|
||||
};
|
||||
|
||||
struct nsCSSList : public nsCSSStruct {
|
||||
const nsID& GetID(void);
|
||||
void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
nsCSSValue mType;
|
||||
nsCSSValue mImage;
|
||||
nsCSSValue mPosition;
|
||||
};
|
||||
|
||||
|
||||
class nsICSSDeclaration : public nsISupports {
|
||||
public:
|
||||
virtual nsresult GetData(const nsID& aIID, nsCSSStruct** aData) = 0;
|
||||
virtual nsresult EnsureData(const nsID& aSID, nsCSSStruct** aData) = 0;
|
||||
|
||||
virtual nsresult AddValue(const char* aProperty, const nsCSSValue& aValue) = 0;
|
||||
virtual nsresult AddValue(PRInt32 aProperty, const nsCSSValue& aValue) = 0;
|
||||
// XXX make nscolor a struct to avoid type conflicts
|
||||
virtual nsresult GetValue(const char* aProperty, nsCSSValue& aValue) = 0;
|
||||
virtual nsresult GetValue(PRInt32 aProperty, nsCSSValue& aValue) = 0;
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0;
|
||||
};
|
||||
|
||||
extern NS_HTML nsresult
|
||||
NS_NewCSSDeclaration(nsICSSDeclaration** aInstancePtrResult);
|
||||
|
||||
#endif /* nsICSSDeclaration_h___ */
|
||||
|
||||
76
content/html/style/src/nsICSSStyleRule.h
Normal file
76
content/html/style/src/nsICSSStyleRule.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsICSSStyleRule_h___
|
||||
#define nsICSSStyleRule_h___
|
||||
|
||||
#include <stdio.h>
|
||||
#include "nslayout.h"
|
||||
#include "nsIStyleRule.h"
|
||||
class nsIAtom;
|
||||
class nsIArena;
|
||||
class nsString;
|
||||
class nsICSSDeclaration;
|
||||
|
||||
|
||||
struct nsCSSSelector {
|
||||
public:
|
||||
nsCSSSelector();
|
||||
nsCSSSelector(nsIAtom* aTag, nsIAtom* aID, nsIAtom* aClass, nsIAtom* aPseudoClass);
|
||||
nsCSSSelector(const nsCSSSelector& aCopy);
|
||||
~nsCSSSelector();
|
||||
|
||||
nsCSSSelector& operator=(const nsCSSSelector& aCopy);
|
||||
PRBool Equals(const nsCSSSelector* aOther) const;
|
||||
|
||||
void Set(const nsString& aTag, const nsString& aID, const nsString& aClass, const nsString& aPseudoClass);
|
||||
|
||||
public:
|
||||
nsIAtom* mTag;
|
||||
nsIAtom* mID;
|
||||
nsIAtom* mClass; // this'll have to be an array for CSS2
|
||||
nsIAtom* mPseudoClass;
|
||||
|
||||
nsCSSSelector* mNext;
|
||||
};
|
||||
|
||||
// IID for the nsICSSStyleRule interface {7c277af0-af19-11d1-8031-006008159b5a}
|
||||
#define NS_ICSS_STYLE_RULE_IID \
|
||||
{0x7c277af0, 0xaf19, 0x11d1, {0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
|
||||
|
||||
class nsICSSStyleRule : public nsIStyleRule {
|
||||
public:
|
||||
virtual PRBool Equals(const nsIStyleRule* aRule) const = 0;
|
||||
virtual PRUint32 HashValue(void) const = 0;
|
||||
|
||||
virtual nsCSSSelector* FirstSelector(void) = 0;
|
||||
virtual void AddSelector(const nsCSSSelector& aSelector) = 0;
|
||||
virtual void DeleteSelector(nsCSSSelector* aSelector) = 0;
|
||||
|
||||
virtual nsICSSDeclaration* GetDeclaration(void) const = 0;
|
||||
virtual void SetDeclaration(nsICSSDeclaration* aDeclaration) = 0;
|
||||
|
||||
virtual PRInt32 GetWeight(void) const = 0;
|
||||
virtual void SetWeight(PRInt32 aWeight) = 0;
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0;
|
||||
};
|
||||
|
||||
extern NS_HTML nsresult
|
||||
NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult, const nsCSSSelector& aSelector);
|
||||
|
||||
#endif /* nsICSSStyleRule_h___ */
|
||||
59
content/html/style/src/nsIHTMLAttributes.h
Normal file
59
content/html/style/src/nsIHTMLAttributes.h
Normal file
@@ -0,0 +1,59 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsIHTMLAttributes_h___
|
||||
#define nsIHTMLAttributes_h___
|
||||
|
||||
#include "nslayout.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsHTMLValue.h"
|
||||
#include "nsIContent.h"
|
||||
class nsIAtom;
|
||||
class nsISupportsArray;
|
||||
class nsIHTMLContent;
|
||||
|
||||
|
||||
// IID for the nsIHTMLAttributes interface {a18f85f0-c058-11d1-8031-006008159b5a}
|
||||
#define NS_IHTML_ATTRIBUTES_IID \
|
||||
{0xa18f85f0, 0xc058, 0x11d1, \
|
||||
{0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
|
||||
|
||||
class nsIHTMLAttributes : public nsISupports {
|
||||
public:
|
||||
virtual PRInt32 SetAttribute(nsIAtom* aAttribute, const nsString& aValue) = 0;
|
||||
virtual PRInt32 SetAttribute(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue = nsHTMLValue::kNull) = 0;
|
||||
virtual PRInt32 UnsetAttribute(nsIAtom* aAttribute) = 0;
|
||||
virtual nsContentAttr GetAttribute(nsIAtom* aAttribute,
|
||||
nsHTMLValue& aValue) const = 0;
|
||||
virtual PRInt32 GetAllAttributeNames(nsISupportsArray* aArray) const = 0;
|
||||
|
||||
virtual PRInt32 Count(void) const = 0;
|
||||
|
||||
virtual PRInt32 SetID(nsIAtom* aID) = 0;
|
||||
virtual nsIAtom* GetID(void) const = 0;
|
||||
virtual PRInt32 SetClass(nsIAtom* aClass) = 0; // XXX this will have to change for CSS2
|
||||
virtual nsIAtom* GetClass(void) const = 0; // XXX this will have to change for CSS2
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0;
|
||||
};
|
||||
|
||||
extern NS_HTML nsresult
|
||||
NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult, nsIHTMLContent* aContent);
|
||||
|
||||
#endif /* nsIHTMLAttributes_h___ */
|
||||
|
||||
40
content/shared/public/nsCSSKeywords.h
Normal file
40
content/shared/public/nsCSSKeywords.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsCSSKeywords_h___
|
||||
#define nsCSSKeywords_h___
|
||||
|
||||
#include "nslayout.h"
|
||||
#include "nsCSSKeywordIDs.h"
|
||||
|
||||
class NS_LAYOUT nsCSSKeywords {
|
||||
public:
|
||||
// Given a null terminated string of 7 bit characters, return the
|
||||
// tag id (see nsHTMLTagIDs.h) for the tag or -1 if the tag is not
|
||||
// known. The lookup function uses a perfect hash.
|
||||
static PRInt32 LookupName(const char* str);
|
||||
|
||||
struct NameTableEntry {
|
||||
const char* name;
|
||||
PRInt32 id;
|
||||
};
|
||||
|
||||
// A table whose index is the tag id (from LookupName)
|
||||
static const NameTableEntry kNameTable[];
|
||||
};
|
||||
|
||||
#endif /* nsCSSKeywords_h___ */
|
||||
40
content/shared/public/nsCSSProps.h
Normal file
40
content/shared/public/nsCSSProps.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsCSSProps_h___
|
||||
#define nsCSSProps_h___
|
||||
|
||||
#include "nslayout.h"
|
||||
#include "nsCSSPropIDs.h"
|
||||
|
||||
class NS_LAYOUT nsCSSProps {
|
||||
public:
|
||||
// Given a null terminated string of 7 bit characters, return the
|
||||
// tag id (see nsCSSPropIDs.h) for the tag or -1 if the tag is not
|
||||
// known. The lookup function uses a perfect hash.
|
||||
static PRInt32 LookupName(const char* str);
|
||||
|
||||
struct NameTableEntry {
|
||||
const char* name;
|
||||
PRInt32 id;
|
||||
};
|
||||
|
||||
// A table whose index is the tag id (from nsCSSPropIDs)
|
||||
static const NameTableEntry kNameTable[];
|
||||
};
|
||||
|
||||
#endif /* nsCSSProps_h___ */
|
||||
168
content/shared/public/nsHTMLAtoms.h
Normal file
168
content/shared/public/nsHTMLAtoms.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsHTMLAtoms_h___
|
||||
#define nsHTMLAtoms_h___
|
||||
|
||||
#include "nsIAtom.h"
|
||||
|
||||
/**
|
||||
* This class wraps up the creation (and destruction) of the standard
|
||||
* set of html atoms used during normal html handling. This objects
|
||||
* are created when the first html content object is created and they
|
||||
* are destroyed when the last html content object is destroyed.
|
||||
*/
|
||||
class nsHTMLAtoms {
|
||||
public:
|
||||
|
||||
static void AddrefAtoms();
|
||||
static void ReleaseAtoms();
|
||||
|
||||
// Alphabetical list of html attribute atoms
|
||||
static nsIAtom* a;
|
||||
static nsIAtom* above;
|
||||
static nsIAtom* action;
|
||||
static nsIAtom* align;
|
||||
static nsIAtom* alink;
|
||||
static nsIAtom* alt;
|
||||
static nsIAtom* archive;
|
||||
|
||||
static nsIAtom* background;
|
||||
static nsIAtom* below;
|
||||
static nsIAtom* bgcolor;
|
||||
static nsIAtom* body;
|
||||
static nsIAtom* border;
|
||||
static nsIAtom* bordercolor;
|
||||
static nsIAtom* bottompadding;
|
||||
static nsIAtom* br;
|
||||
|
||||
static nsIAtom* cellpadding;
|
||||
static nsIAtom* cellspacing;
|
||||
static nsIAtom* checked;
|
||||
static nsIAtom* kClass;
|
||||
static nsIAtom* classid;
|
||||
static nsIAtom* clear;
|
||||
static nsIAtom* clip;
|
||||
static nsIAtom* code;
|
||||
static nsIAtom* codebase;
|
||||
static nsIAtom* color;
|
||||
static nsIAtom* cols;
|
||||
static nsIAtom* colspan;
|
||||
static nsIAtom* compact;
|
||||
static nsIAtom* coords;
|
||||
|
||||
static nsIAtom* data;
|
||||
static nsIAtom* dir;
|
||||
static nsIAtom* div;
|
||||
static nsIAtom* dl;
|
||||
|
||||
static nsIAtom* encoding;
|
||||
|
||||
static nsIAtom* face;
|
||||
static nsIAtom* font;
|
||||
static nsIAtom* fontWeight;
|
||||
static nsIAtom* frameborder;
|
||||
|
||||
static nsIAtom* gutter;
|
||||
|
||||
static nsIAtom* h1;
|
||||
static nsIAtom* h2;
|
||||
static nsIAtom* h3;
|
||||
static nsIAtom* h4;
|
||||
static nsIAtom* h5;
|
||||
static nsIAtom* h6;
|
||||
static nsIAtom* height;
|
||||
static nsIAtom* hidden;
|
||||
static nsIAtom* href;
|
||||
static nsIAtom* hspace;
|
||||
static nsIAtom* httpEquiv;
|
||||
|
||||
static nsIAtom* id;
|
||||
static nsIAtom* ismap;
|
||||
|
||||
static nsIAtom* language;
|
||||
static nsIAtom* li;
|
||||
static nsIAtom* link;
|
||||
static nsIAtom* left;
|
||||
static nsIAtom* leftpadding;
|
||||
static nsIAtom* lowsrc;
|
||||
|
||||
static nsIAtom* marginheight;
|
||||
static nsIAtom* marginwidth;
|
||||
static nsIAtom* maxlength;
|
||||
static nsIAtom* mayscript;
|
||||
static nsIAtom* menu;
|
||||
static nsIAtom* method;
|
||||
static nsIAtom* multicol;
|
||||
static nsIAtom* multiple;
|
||||
|
||||
static nsIAtom* name;
|
||||
static nsIAtom* noresize;
|
||||
static nsIAtom* noshade;
|
||||
static nsIAtom* nowrap;
|
||||
|
||||
static nsIAtom* ol;
|
||||
static nsIAtom* onblur;
|
||||
static nsIAtom* onfocus;
|
||||
static nsIAtom* onload;
|
||||
static nsIAtom* onunload;
|
||||
static nsIAtom* overflow;
|
||||
|
||||
static nsIAtom* p;
|
||||
static nsIAtom* pagex;
|
||||
static nsIAtom* pagey;
|
||||
static nsIAtom* pointSize;
|
||||
static nsIAtom* pre;
|
||||
static nsIAtom* prompt;
|
||||
|
||||
static nsIAtom* rel;
|
||||
static nsIAtom* rightpadding;
|
||||
static nsIAtom* rows;
|
||||
static nsIAtom* rowspan;
|
||||
|
||||
static nsIAtom* scrolling;
|
||||
static nsIAtom* selected;
|
||||
static nsIAtom* shape;
|
||||
static nsIAtom* size;
|
||||
static nsIAtom* src;
|
||||
static nsIAtom* start;
|
||||
static nsIAtom* suppress;
|
||||
|
||||
static nsIAtom* tabstop;
|
||||
static nsIAtom* target;
|
||||
static nsIAtom* text;
|
||||
static nsIAtom* top;
|
||||
static nsIAtom* toppadding;
|
||||
static nsIAtom* type;
|
||||
|
||||
static nsIAtom* ul;
|
||||
static nsIAtom* usemap;
|
||||
|
||||
static nsIAtom* valign;
|
||||
static nsIAtom* value;
|
||||
static nsIAtom* variable;
|
||||
static nsIAtom* visibility;
|
||||
static nsIAtom* vlink;
|
||||
static nsIAtom* vspace;
|
||||
|
||||
static nsIAtom* width;
|
||||
static nsIAtom* wrap;
|
||||
|
||||
static nsIAtom* zindex;
|
||||
};
|
||||
|
||||
#endif /* nsHTMLAtoms_h___ */
|
||||
138
content/shared/public/nsHTMLValue.h
Normal file
138
content/shared/public/nsHTMLValue.h
Normal file
@@ -0,0 +1,138 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#ifndef nsHTMLValue_h___
|
||||
#define nsHTMLValue_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsString.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
|
||||
enum nsHTMLUnit {
|
||||
eHTMLUnit_Null = 0, // (n/a) null unit, value is not specified
|
||||
eHTMLUnit_String = 10, // (nsString) a string value
|
||||
eHTMLUnit_ISupports = 20, // (nsISupports*) a ref counted interface
|
||||
eHTMLUnit_Absolute = 50, // (int) simple value
|
||||
eHTMLUnit_Enumerated = 51, // (int) value has enumerated meaning
|
||||
eHTMLUnit_Color = 80, // (color) an RGBA value
|
||||
eHTMLUnit_Percent = 90, // (float) 1.0 == 100%) value is percentage of something
|
||||
|
||||
// Screen relative measure
|
||||
eHTMLUnit_Pixel = 600, // (int) screen pixels
|
||||
};
|
||||
|
||||
class nsHTMLValue {
|
||||
public:
|
||||
nsHTMLValue(void);
|
||||
nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit = eHTMLUnit_Absolute);
|
||||
nsHTMLValue(float aValue, nsHTMLUnit aUnit = eHTMLUnit_Pixel);
|
||||
nsHTMLValue(const nsString& aValue);
|
||||
nsHTMLValue(nsISupports* aValue);
|
||||
nsHTMLValue(nscolor aValue);
|
||||
nsHTMLValue(const nsHTMLValue& aCopy);
|
||||
~nsHTMLValue(void);
|
||||
|
||||
nsHTMLValue& operator=(const nsHTMLValue& aCopy);
|
||||
PRBool operator==(const nsHTMLValue& aOther) const;
|
||||
|
||||
nsHTMLUnit GetUnit(void) const { return mUnit; }
|
||||
PRInt32 GetIntValue(void) const;
|
||||
float GetFloatValue(void) const;
|
||||
nsString& GetStringValue(nsString& aBuffer) const;
|
||||
nsISupports* GetISupportsValue(void) const;
|
||||
nscolor GetColorValue(void) const;
|
||||
|
||||
void Reset(void);
|
||||
void Set(PRInt32 aValue, nsHTMLUnit aUnit = eHTMLUnit_Absolute);
|
||||
void Set(float aValue, nsHTMLUnit aUnit = eHTMLUnit_Pixel);
|
||||
void Set(const nsString& aValue);
|
||||
void Set(nsISupports* aValue);
|
||||
void Set(nscolor aValue);
|
||||
|
||||
void AppendToString(nsString& aBuffer) const;
|
||||
void ToString(nsString& aBuffer) const;
|
||||
|
||||
protected:
|
||||
nsHTMLUnit mUnit;
|
||||
union {
|
||||
PRInt32 mInt;
|
||||
float mFloat;
|
||||
nsString* mString;
|
||||
nsISupports* mISupports;
|
||||
nscolor mColor;
|
||||
} mValue;
|
||||
|
||||
public:
|
||||
static const nsHTMLValue kNull;
|
||||
};
|
||||
|
||||
inline PRInt32 nsHTMLValue::GetIntValue(void) const
|
||||
{
|
||||
NS_ASSERTION((mUnit == eHTMLUnit_Absolute) ||
|
||||
(mUnit == eHTMLUnit_Enumerated) ||
|
||||
(mUnit == eHTMLUnit_Pixel), "not an int value");
|
||||
if ((mUnit == eHTMLUnit_Absolute) ||
|
||||
(mUnit == eHTMLUnit_Enumerated) ||
|
||||
(mUnit == eHTMLUnit_Pixel)) {
|
||||
return mValue.mInt;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline float nsHTMLValue::GetFloatValue(void) const
|
||||
{
|
||||
NS_ASSERTION(mUnit == eHTMLUnit_Percent, "not a float value");
|
||||
if (mUnit == eHTMLUnit_Percent) {
|
||||
return mValue.mFloat;
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
inline nsString& nsHTMLValue::GetStringValue(nsString& aBuffer) const
|
||||
{
|
||||
NS_ASSERTION((mUnit == eHTMLUnit_String) || (mUnit == eHTMLUnit_Null), "not a string value");
|
||||
aBuffer.SetLength(0);
|
||||
if ((mUnit == eHTMLUnit_String) && (nsnull != mValue.mString)) {
|
||||
aBuffer.Append(*(mValue.mString));
|
||||
}
|
||||
return aBuffer;
|
||||
}
|
||||
|
||||
inline nsISupports* nsHTMLValue::GetISupportsValue(void) const
|
||||
{
|
||||
NS_ASSERTION(mUnit == eHTMLUnit_ISupports, "not an ISupports value");
|
||||
if (mUnit == eHTMLUnit_ISupports) {
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
return mValue.mISupports;
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
inline nscolor nsHTMLValue::GetColorValue(void) const
|
||||
{
|
||||
NS_ASSERTION(mUnit == eHTMLUnit_Color, "not a color value");
|
||||
if (mUnit == eHTMLUnit_Color) {
|
||||
return mValue.mColor;
|
||||
}
|
||||
return NS_RGB(0,0,0);
|
||||
}
|
||||
|
||||
|
||||
#endif /* nsHTMLValue_h___ */
|
||||
|
||||
389
content/shared/src/nsCSSKeywords.cpp
Normal file
389
content/shared/src/nsCSSKeywords.cpp
Normal file
@@ -0,0 +1,389 @@
|
||||
|
||||
/*
|
||||
** This is a generated file, do not edit it. This file is created by
|
||||
** genhash.pl
|
||||
*/
|
||||
|
||||
#include "plstr.h"
|
||||
#include "nsCSSKeywords.h"
|
||||
#define TOTAL_KEYWORDS 86
|
||||
#define MIN_WORD_LENGTH 2
|
||||
#define MAX_WORD_LENGTH 12
|
||||
#define MIN_HASH_VALUE 8
|
||||
#define MAX_HASH_VALUE 322
|
||||
/* maximum key range = 315, duplicates = 0 */
|
||||
|
||||
|
||||
struct StaticNameTable {
|
||||
char* tag;
|
||||
PRInt32 id;
|
||||
};
|
||||
|
||||
static const unsigned char kLowerLookup[256] = {
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
|
||||
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
|
||||
48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
|
||||
64,
|
||||
97,98,99,100,101,102,103,104,105,106,107,108,109,
|
||||
110,111,112,113,114,115,116,117,118,119,120,121,122,
|
||||
|
||||
91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
|
||||
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
|
||||
|
||||
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
|
||||
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
|
||||
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
|
||||
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
|
||||
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
|
||||
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
|
||||
224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
|
||||
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
|
||||
};
|
||||
|
||||
#define MYLOWER(x) kLowerLookup[((x) & 0x7f)]
|
||||
|
||||
/**
|
||||
* Map a name to an ID or -1
|
||||
*/
|
||||
PRInt32 nsCSSKeywords::LookupName(const char* str)
|
||||
{
|
||||
static unsigned short asso_values[] =
|
||||
{
|
||||
323, 323, 323, 323, 323, 323, 323, 323, 323, 323,
|
||||
323, 323, 323, 323, 323, 323, 323, 323, 323, 323,
|
||||
323, 323, 323, 323, 323, 323, 323, 323, 323, 323,
|
||||
323, 323, 323, 323, 323, 323, 323, 323, 323, 323,
|
||||
323, 323, 323, 323, 323, 15, 323, 323, 323, 323,
|
||||
323, 323, 323, 323, 323, 323, 323, 323, 323, 323,
|
||||
323, 323, 323, 323, 323, 323, 323, 323, 323, 323,
|
||||
323, 323, 323, 323, 323, 323, 323, 323, 323, 323,
|
||||
323, 323, 323, 323, 323, 323, 323, 323, 323, 323,
|
||||
323, 323, 323, 323, 323, 323, 323, 5, 125, 115,
|
||||
35, 0, 5, 55, 60, 110, 0, 5, 0, 5,
|
||||
75, 0, 90, 5, 0, 25, 0, 27, 0, 90,
|
||||
10, 0, 323, 323, 323, 323, 323, 323,
|
||||
};
|
||||
static unsigned char lengthtable[] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 8, 4, 5, 6, 2, 0,
|
||||
0, 0, 0, 2, 0, 0, 0, 11, 2, 0, 0, 0, 11, 0,
|
||||
0, 0, 0, 0, 7, 6, 7, 0, 4, 0, 0, 0, 5, 0,
|
||||
7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0,
|
||||
0, 7, 0, 7, 0, 6, 0, 6, 0, 5, 0, 0, 6, 0,
|
||||
0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 6, 0, 8,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 6, 0,
|
||||
8, 9, 0, 0, 0, 0, 9, 0, 6, 7, 8, 0, 0, 11,
|
||||
2, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0,
|
||||
0, 2, 0, 0, 0, 6, 7, 0, 0, 5, 6, 0, 0, 0,
|
||||
0, 0, 7, 0, 0, 0, 6, 5, 0, 9, 5, 6, 0, 0,
|
||||
4, 0, 6, 7, 0, 0, 0, 0, 0, 8, 4, 5, 0, 0,
|
||||
0, 9, 5, 0, 7, 0, 0, 0, 11, 0, 0, 0, 5, 0,
|
||||
0, 3, 0, 10, 0, 0, 0, 4, 0, 6, 0, 0, 0, 0,
|
||||
6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 5, 6, 0, 0, 0, 10, 9, 0, 0,
|
||||
0, 0, 0, 0, 11, 0, 0, 6, 0, 0, 0, 0, 6, 0,
|
||||
8, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 4, 0, 0,
|
||||
7, 0, 0, 0, 9, 0, 0, 0, 0, 6, 2, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 6, 0, 0, 4, 0, 0, 0, 11,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, 0,
|
||||
2,
|
||||
};
|
||||
static struct StaticNameTable wordlist[] =
|
||||
{
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"relative", 56},
|
||||
{"left", 32},
|
||||
{"large", 30},
|
||||
{"larger", 31},
|
||||
{"em", 18},
|
||||
{"",}, {"",}, {"",}, {"",},
|
||||
{"mm", 41},
|
||||
{"",}, {"",}, {"",},
|
||||
{"transparent", 76},
|
||||
{"ex", 19},
|
||||
{"",}, {"",}, {"",},
|
||||
{"text-bottom", 71},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"x-large", 82},
|
||||
{"outset", 48},
|
||||
{"outside", 49},
|
||||
{"",},
|
||||
{"auto", 1},
|
||||
{"",}, {"",}, {"",},
|
||||
{"small", 63},
|
||||
{"",},
|
||||
{"smaller", 65},
|
||||
{"xx-small", 85},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"medium", 39},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"x-small", 83},
|
||||
{"",},
|
||||
{"justify", 29},
|
||||
{"",},
|
||||
{"groove", 21},
|
||||
{"",},
|
||||
{"square", 67},
|
||||
{"",},
|
||||
{"solid", 66},
|
||||
{"",}, {"",},
|
||||
{"double", 17},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"dotted", 16},
|
||||
{"",}, {"",}, {"",}, {"",},
|
||||
{"normal", 44},
|
||||
{"",},
|
||||
{"overline", 50},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"pt", 54},
|
||||
{"pre", 53},
|
||||
{"",}, {"",},
|
||||
{"repeat", 57},
|
||||
{"",},
|
||||
{"xx-large", 84},
|
||||
{"no-repeat", 42},
|
||||
{"",}, {"",}, {"",}, {"",},
|
||||
{"lowercase", 38},
|
||||
{"",},
|
||||
{"dashed", 13},
|
||||
{"noshade", 45},
|
||||
{"text-top", 72},
|
||||
{"",}, {"",},
|
||||
{"lower-alpha", 36},
|
||||
{"px", 55},
|
||||
{"repeat-y", 59},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"repeat-x", 58},
|
||||
{"",}, {"",}, {"",},
|
||||
{"cm", 12},
|
||||
{"",}, {"",}, {"",},
|
||||
{"bolder", 6},
|
||||
{"oblique", 47},
|
||||
{"",}, {"",},
|
||||
{"block", 4},
|
||||
{"bottom", 8},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"visible", 81},
|
||||
{"",}, {"",}, {"",},
|
||||
{"scroll", 62},
|
||||
{"super", 70},
|
||||
{"",},
|
||||
{"list-item", 35},
|
||||
{"ridge", 60},
|
||||
{"static", 68},
|
||||
{"",}, {"",},
|
||||
{"none", 43},
|
||||
{"",},
|
||||
{"middle", 40},
|
||||
{"decimal", 14},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"absolute", 0},
|
||||
{"bold", 5},
|
||||
{"fixed", 20},
|
||||
{"",}, {"",}, {"",},
|
||||
{"paragraph", 51},
|
||||
{"right", 61},
|
||||
{"",},
|
||||
{"lighter", 33},
|
||||
{"",}, {"",}, {"",},
|
||||
{"lower-roman", 37},
|
||||
{"",}, {"",}, {"",},
|
||||
{"thick", 73},
|
||||
{"",}, {"",},
|
||||
{"top", 75},
|
||||
{"",},
|
||||
{"small-caps", 64},
|
||||
{"",}, {"",}, {"",},
|
||||
{"both", 7},
|
||||
{"",},
|
||||
{"inline", 25},
|
||||
{"",}, {"",}, {"",}, {"",},
|
||||
{"center", 10},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
|
||||
{"inset", 26},
|
||||
{"inside", 27},
|
||||
{"",}, {"",}, {"",},
|
||||
{"capitalize", 9},
|
||||
{"uppercase", 80},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"upper-alpha", 78},
|
||||
{"",}, {"",},
|
||||
{"circle", 11},
|
||||
{"",}, {"",}, {"",}, {"",},
|
||||
{"italic", 28},
|
||||
{"",},
|
||||
{"baseline", 2},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"blink", 3},
|
||||
{"",}, {"",}, {"",},
|
||||
{"thin", 74},
|
||||
{"",}, {"",},
|
||||
{"inherit", 24},
|
||||
{"",}, {"",}, {"",},
|
||||
{"underline", 77},
|
||||
{"",}, {"",}, {"",}, {"",},
|
||||
{"nowrap", 46},
|
||||
{"in", 23},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"hidden", 22},
|
||||
{"",}, {"",},
|
||||
{"disc", 15},
|
||||
{"",}, {"",}, {"",},
|
||||
{"upper-roman", 79},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"",}, {"",},
|
||||
{"sub", 69},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"",}, {"",},
|
||||
{"line-through", 34},
|
||||
{"",}, {"",}, {"",}, {"",},
|
||||
{"pc", 52},
|
||||
};
|
||||
|
||||
if (str != NULL) {
|
||||
int len = PL_strlen(str);
|
||||
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) {
|
||||
register int hval = len;
|
||||
|
||||
switch (hval)
|
||||
{
|
||||
default:
|
||||
case 7:
|
||||
hval += asso_values[MYLOWER(str[6])];
|
||||
case 6:
|
||||
case 5:
|
||||
case 4:
|
||||
case 3:
|
||||
hval += asso_values[MYLOWER(str[2])];
|
||||
case 2:
|
||||
hval += asso_values[MYLOWER(str[1])];
|
||||
case 1:
|
||||
hval += asso_values[MYLOWER(str[0])];
|
||||
break;
|
||||
}
|
||||
hval += asso_values[MYLOWER(str[len - 1])];
|
||||
if (hval <= MAX_HASH_VALUE && hval >= MIN_HASH_VALUE) {
|
||||
if (len == lengthtable[hval]) {
|
||||
register const char *tag = wordlist[hval].tag;
|
||||
|
||||
/*
|
||||
** While not at the end of the string, if they ever differ
|
||||
** they are not equal. We know "tag" is already lower case.
|
||||
*/
|
||||
while ((*tag != '\0')&&(*str != '\0')) {
|
||||
if (*tag != (char) MYLOWER(*str)) {
|
||||
return -1;
|
||||
}
|
||||
tag++;
|
||||
str++;
|
||||
}
|
||||
|
||||
/*
|
||||
** One of the strings has ended, if they are both ended, then they
|
||||
** are equal, otherwise not.
|
||||
*/
|
||||
if ((*tag == '\0')&&(*str == '\0')) {
|
||||
return wordlist[hval].id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
const nsCSSKeywords::NameTableEntry nsCSSKeywords::kNameTable[] = {
|
||||
{ "absolute", 0 },
|
||||
{ "auto", 1 },
|
||||
{ "baseline", 2 },
|
||||
{ "blink", 3 },
|
||||
{ "block", 4 },
|
||||
{ "bold", 5 },
|
||||
{ "bolder", 6 },
|
||||
{ "both", 7 },
|
||||
{ "bottom", 8 },
|
||||
{ "capitalize", 9 },
|
||||
{ "center", 10 },
|
||||
{ "circle", 11 },
|
||||
{ "cm", 12 },
|
||||
{ "dashed", 13 },
|
||||
{ "decimal", 14 },
|
||||
{ "disc", 15 },
|
||||
{ "dotted", 16 },
|
||||
{ "double", 17 },
|
||||
{ "em", 18 },
|
||||
{ "ex", 19 },
|
||||
{ "fixed", 20 },
|
||||
{ "groove", 21 },
|
||||
{ "hidden", 22 },
|
||||
{ "in", 23 },
|
||||
{ "inherit", 24 },
|
||||
{ "inline", 25 },
|
||||
{ "inset", 26 },
|
||||
{ "inside", 27 },
|
||||
{ "italic", 28 },
|
||||
{ "justify", 29 },
|
||||
{ "large", 30 },
|
||||
{ "larger", 31 },
|
||||
{ "left", 32 },
|
||||
{ "lighter", 33 },
|
||||
{ "line-through", 34 },
|
||||
{ "list-item", 35 },
|
||||
{ "lower-alpha", 36 },
|
||||
{ "lower-roman", 37 },
|
||||
{ "lowercase", 38 },
|
||||
{ "medium", 39 },
|
||||
{ "middle", 40 },
|
||||
{ "mm", 41 },
|
||||
{ "no-repeat", 42 },
|
||||
{ "none", 43 },
|
||||
{ "normal", 44 },
|
||||
{ "noshade", 45 },
|
||||
{ "nowrap", 46 },
|
||||
{ "oblique", 47 },
|
||||
{ "outset", 48 },
|
||||
{ "outside", 49 },
|
||||
{ "overline", 50 },
|
||||
{ "paragraph", 51 },
|
||||
{ "pc", 52 },
|
||||
{ "pre", 53 },
|
||||
{ "pt", 54 },
|
||||
{ "px", 55 },
|
||||
{ "relative", 56 },
|
||||
{ "repeat", 57 },
|
||||
{ "repeat-x", 58 },
|
||||
{ "repeat-y", 59 },
|
||||
{ "ridge", 60 },
|
||||
{ "right", 61 },
|
||||
{ "scroll", 62 },
|
||||
{ "small", 63 },
|
||||
{ "small-caps", 64 },
|
||||
{ "smaller", 65 },
|
||||
{ "solid", 66 },
|
||||
{ "square", 67 },
|
||||
{ "static", 68 },
|
||||
{ "sub", 69 },
|
||||
{ "super", 70 },
|
||||
{ "text-bottom", 71 },
|
||||
{ "text-top", 72 },
|
||||
{ "thick", 73 },
|
||||
{ "thin", 74 },
|
||||
{ "top", 75 },
|
||||
{ "transparent", 76 },
|
||||
{ "underline", 77 },
|
||||
{ "upper-alpha", 78 },
|
||||
{ "upper-roman", 79 },
|
||||
{ "uppercase", 80 },
|
||||
{ "visible", 81 },
|
||||
{ "x-large", 82 },
|
||||
{ "x-small", 83 },
|
||||
{ "xx-large", 84 },
|
||||
{ "xx-small", 85 },
|
||||
};
|
||||
347
content/shared/src/nsCSSProps.cpp
Normal file
347
content/shared/src/nsCSSProps.cpp
Normal file
@@ -0,0 +1,347 @@
|
||||
|
||||
/*
|
||||
** This is a generated file, do not edit it. This file is created by
|
||||
** genhash.pl
|
||||
*/
|
||||
|
||||
#include "plstr.h"
|
||||
#include "nsCSSProps.h"
|
||||
#define TOTAL_KEYWORDS 76
|
||||
#define MIN_WORD_LENGTH 3
|
||||
#define MAX_WORD_LENGTH 21
|
||||
#define MIN_HASH_VALUE 6
|
||||
#define MAX_HASH_VALUE 212
|
||||
/* maximum key range = 207, duplicates = 0 */
|
||||
|
||||
|
||||
struct StaticNameTable {
|
||||
char* tag;
|
||||
PRInt32 id;
|
||||
};
|
||||
|
||||
static const unsigned char kLowerLookup[256] = {
|
||||
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
|
||||
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,
|
||||
32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,
|
||||
48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,
|
||||
64,
|
||||
97,98,99,100,101,102,103,104,105,106,107,108,109,
|
||||
110,111,112,113,114,115,116,117,118,119,120,121,122,
|
||||
|
||||
91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,
|
||||
112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,
|
||||
|
||||
128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
|
||||
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
|
||||
160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
|
||||
176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
|
||||
192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
|
||||
208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,
|
||||
224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,
|
||||
240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255
|
||||
};
|
||||
|
||||
#define MYLOWER(x) kLowerLookup[((x) & 0x7f)]
|
||||
|
||||
/**
|
||||
* Map a name to an ID or -1
|
||||
*/
|
||||
PRInt32 nsCSSProps::LookupName(const char* str)
|
||||
{
|
||||
static unsigned char asso_values[] =
|
||||
{
|
||||
213, 213, 213, 213, 213, 213, 213, 213, 213, 213,
|
||||
213, 213, 213, 213, 213, 213, 213, 213, 213, 213,
|
||||
213, 213, 213, 213, 213, 213, 213, 213, 213, 213,
|
||||
213, 213, 213, 213, 213, 213, 213, 213, 213, 213,
|
||||
213, 213, 213, 213, 213, 30, 213, 213, 213, 213,
|
||||
213, 213, 213, 213, 213, 213, 213, 213, 213, 213,
|
||||
213, 213, 213, 213, 213, 213, 213, 213, 213, 213,
|
||||
213, 213, 213, 213, 213, 213, 213, 213, 213, 213,
|
||||
213, 213, 213, 213, 213, 213, 213, 213, 213, 213,
|
||||
213, 213, 213, 213, 213, 213, 213, 45, 0, 85,
|
||||
45, 25, 5, 20, 80, 0, 213, 213, 25, 75,
|
||||
0, 0, 5, 213, 0, 65, 40, 213, 0, 65,
|
||||
10, 15, 10, 213, 213, 213, 213, 213,
|
||||
};
|
||||
static unsigned char lengthtable[] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 6, 12, 8,
|
||||
0, 10, 0, 0, 0, 19, 0, 0, 0, 0, 0, 10, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0,
|
||||
0, 0, 19, 0, 0, 17, 3, 4, 0, 11, 0, 0, 0, 0,
|
||||
0, 0, 18, 0, 0, 0, 12, 0, 0, 0, 11, 17, 0, 19,
|
||||
0, 0, 17, 0, 0, 5, 21, 7, 0, 0, 0, 21, 7, 18,
|
||||
14, 0, 16, 0, 13, 0, 5, 0, 12, 0, 4, 0, 0, 12,
|
||||
8, 19, 10, 16, 17, 0, 9, 10, 16, 0, 0, 0, 0, 0,
|
||||
7, 0, 19, 5, 11, 0, 0, 4, 10, 11, 0, 0, 14, 10,
|
||||
6, 17, 0, 0, 0, 16, 0, 0, 0, 10, 0, 0, 18, 0,
|
||||
0, 0, 12, 0, 0, 0, 16, 0, 0, 0, 5, 21, 0, 0,
|
||||
0, 0, 11, 0, 0, 0, 10, 16, 0, 8, 0, 15, 0, 0,
|
||||
0, 0, 15, 11, 12, 0, 0, 0, 0, 0, 0, 14, 0, 0,
|
||||
12, 13, 9, 0, 0, 0, 0, 0, 0, 6, 0, 0, 14, 0,
|
||||
11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 0,
|
||||
0, 11, 12,
|
||||
};
|
||||
static struct StaticNameTable wordlist[] =
|
||||
{
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"border", 9},
|
||||
{"",}, {"",}, {"",}, {"",},
|
||||
{"filter", 37},
|
||||
{"border-color", 14},
|
||||
{"position", 64},
|
||||
{"",},
|
||||
{"border-top", 24},
|
||||
{"",}, {"",}, {"",},
|
||||
{"border-bottom-color", 11},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"visibility", 71},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"",},
|
||||
{"font-family", 40},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"border-bottom-style", 12},
|
||||
{"",}, {"",},
|
||||
{"border-left-color", 16},
|
||||
{"top", 69},
|
||||
{"font", 39},
|
||||
{"",},
|
||||
{"border-left", 15},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"border-right-color", 20},
|
||||
{"",}, {"",}, {"",},
|
||||
{"border-style", 23},
|
||||
{"",}, {"",}, {"",},
|
||||
{"padding-top", 63},
|
||||
{"background-filter", 3},
|
||||
{"",},
|
||||
{"background-position", 5},
|
||||
{"",}, {"",},
|
||||
{"border-left-style", 17},
|
||||
{"",}, {"",},
|
||||
{"float", 38},
|
||||
{"background-x-position", 6},
|
||||
{"padding", 59},
|
||||
{"",}, {"",}, {"",},
|
||||
{"background-y-position", 7},
|
||||
{"z-index", 75},
|
||||
{"border-right-style", 21},
|
||||
{"letter-spacing", 47},
|
||||
{"",},
|
||||
{"background-image", 4},
|
||||
{"",},
|
||||
{"border-bottom", 10},
|
||||
{"",},
|
||||
{"color", 35},
|
||||
{"",},
|
||||
{"border-right", 19},
|
||||
{"",},
|
||||
{"left", 46},
|
||||
{"",}, {"",},
|
||||
{"font-variant", 43},
|
||||
{"overflow", 58},
|
||||
{"border-bottom-width", 13},
|
||||
{"background", 0},
|
||||
{"border-top-color", 25},
|
||||
{"background-repeat", 8},
|
||||
{"",},
|
||||
{"font-size", 41},
|
||||
{"font-style", 42},
|
||||
{"border-top-style", 26},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"display", 36},
|
||||
{"",},
|
||||
{"list-style-position", 51},
|
||||
{"clear", 29},
|
||||
{"text-indent", 67},
|
||||
{"",}, {"",},
|
||||
{"clip", 30},
|
||||
{"text-align", 65},
|
||||
{"font-weight", 44},
|
||||
{"",}, {"",},
|
||||
{"vertical-align", 70},
|
||||
{"list-style", 49},
|
||||
{"margin", 53},
|
||||
{"border-left-width", 18},
|
||||
{"",}, {"",}, {"",},
|
||||
{"list-style-image", 50},
|
||||
{"",}, {"",}, {"",},
|
||||
{"margin-top", 57},
|
||||
{"",}, {"",},
|
||||
{"border-right-width", 22},
|
||||
{"",}, {"",}, {"",},
|
||||
{"padding-left", 61},
|
||||
{"",}, {"",}, {"",},
|
||||
{"background-color", 2},
|
||||
{"",}, {"",}, {"",},
|
||||
{"width", 73},
|
||||
{"background-attachment", 1},
|
||||
{"",}, {"",}, {"",}, {"",},
|
||||
{"line-height", 48},
|
||||
{"",}, {"",}, {"",},
|
||||
{"clip-right", 33},
|
||||
{"border-top-width", 27},
|
||||
{"",},
|
||||
{"clip-top", 34},
|
||||
{"",},
|
||||
{"text-decoration", 66},
|
||||
{"",}, {"",}, {"",}, {"",},
|
||||
{"list-style-type", 52},
|
||||
{"margin-left", 55},
|
||||
{"border-width", 28},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"padding-bottom", 60},
|
||||
{"",}, {"",},
|
||||
{"word-spacing", 74},
|
||||
{"padding-right", 62},
|
||||
{"clip-left", 32},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"height", 45},
|
||||
{"",}, {"",},
|
||||
{"text-transform", 68},
|
||||
{"",},
|
||||
{"clip-bottom", 31},
|
||||
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
|
||||
{"",}, {"",},
|
||||
{"margin-bottom", 54},
|
||||
{"",}, {"",},
|
||||
{"white-space", 72},
|
||||
{"margin-right", 56},
|
||||
};
|
||||
|
||||
if (str != NULL) {
|
||||
int len = PL_strlen(str);
|
||||
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH) {
|
||||
register int hval = len;
|
||||
|
||||
switch (hval)
|
||||
{
|
||||
default:
|
||||
case 12:
|
||||
hval += asso_values[MYLOWER(str[11])];
|
||||
case 11:
|
||||
case 10:
|
||||
case 9:
|
||||
case 8:
|
||||
case 7:
|
||||
case 6:
|
||||
hval += asso_values[MYLOWER(str[5])];
|
||||
case 5:
|
||||
case 4:
|
||||
case 3:
|
||||
case 2:
|
||||
hval += asso_values[MYLOWER(str[1])];
|
||||
case 1:
|
||||
hval += asso_values[MYLOWER(str[0])];
|
||||
break;
|
||||
}
|
||||
hval += asso_values[MYLOWER(str[len - 1])];
|
||||
if (hval <= MAX_HASH_VALUE && hval >= MIN_HASH_VALUE) {
|
||||
if (len == lengthtable[hval]) {
|
||||
register const char *tag = wordlist[hval].tag;
|
||||
|
||||
/*
|
||||
** While not at the end of the string, if they ever differ
|
||||
** they are not equal. We know "tag" is already lower case.
|
||||
*/
|
||||
while ((*tag != '\0')&&(*str != '\0')) {
|
||||
if (*tag != (char) MYLOWER(*str)) {
|
||||
return -1;
|
||||
}
|
||||
tag++;
|
||||
str++;
|
||||
}
|
||||
|
||||
/*
|
||||
** One of the strings has ended, if they are both ended, then they
|
||||
** are equal, otherwise not.
|
||||
*/
|
||||
if ((*tag == '\0')&&(*str == '\0')) {
|
||||
return wordlist[hval].id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
const nsCSSProps::NameTableEntry nsCSSProps::kNameTable[] = {
|
||||
{ "background", 0 },
|
||||
{ "background-attachment", 1 },
|
||||
{ "background-color", 2 },
|
||||
{ "background-filter", 3 },
|
||||
{ "background-image", 4 },
|
||||
{ "background-position", 5 },
|
||||
{ "background-x-position", 6 },
|
||||
{ "background-y-position", 7 },
|
||||
{ "background-repeat", 8 },
|
||||
{ "border", 9 },
|
||||
{ "border-bottom", 10 },
|
||||
{ "border-bottom-color", 11 },
|
||||
{ "border-bottom-style", 12 },
|
||||
{ "border-bottom-width", 13 },
|
||||
{ "border-color", 14 },
|
||||
{ "border-left", 15 },
|
||||
{ "border-left-color", 16 },
|
||||
{ "border-left-style", 17 },
|
||||
{ "border-left-width", 18 },
|
||||
{ "border-right", 19 },
|
||||
{ "border-right-color", 20 },
|
||||
{ "border-right-style", 21 },
|
||||
{ "border-right-width", 22 },
|
||||
{ "border-style", 23 },
|
||||
{ "border-top", 24 },
|
||||
{ "border-top-color", 25 },
|
||||
{ "border-top-style", 26 },
|
||||
{ "border-top-width", 27 },
|
||||
{ "border-width", 28 },
|
||||
{ "clear", 29 },
|
||||
{ "clip", 30 },
|
||||
{ "clip-bottom", 31 },
|
||||
{ "clip-left", 32 },
|
||||
{ "clip-right", 33 },
|
||||
{ "clip-top", 34 },
|
||||
{ "color", 35 },
|
||||
{ "display", 36 },
|
||||
{ "filter", 37 },
|
||||
{ "float", 38 },
|
||||
{ "font", 39 },
|
||||
{ "font-family", 40 },
|
||||
{ "font-size", 41 },
|
||||
{ "font-style", 42 },
|
||||
{ "font-variant", 43 },
|
||||
{ "font-weight", 44 },
|
||||
{ "height", 45 },
|
||||
{ "left", 46 },
|
||||
{ "letter-spacing", 47 },
|
||||
{ "line-height", 48 },
|
||||
{ "list-style", 49 },
|
||||
{ "list-style-image", 50 },
|
||||
{ "list-style-position", 51 },
|
||||
{ "list-style-type", 52 },
|
||||
{ "margin", 53 },
|
||||
{ "margin-bottom", 54 },
|
||||
{ "margin-left", 55 },
|
||||
{ "margin-right", 56 },
|
||||
{ "margin-top", 57 },
|
||||
{ "overflow", 58 },
|
||||
{ "padding", 59 },
|
||||
{ "padding-bottom", 60 },
|
||||
{ "padding-left", 61 },
|
||||
{ "padding-right", 62 },
|
||||
{ "padding-top", 63 },
|
||||
{ "position", 64 },
|
||||
{ "text-align", 65 },
|
||||
{ "text-decoration", 66 },
|
||||
{ "text-indent", 67 },
|
||||
{ "text-transform", 68 },
|
||||
{ "top", 69 },
|
||||
{ "vertical-align", 70 },
|
||||
{ "visibility", 71 },
|
||||
{ "white-space", 72 },
|
||||
{ "width", 73 },
|
||||
{ "word-spacing", 74 },
|
||||
{ "z-index", 75 },
|
||||
};
|
||||
367
content/shared/src/nsHTMLAtoms.cpp
Normal file
367
content/shared/src/nsHTMLAtoms.cpp
Normal file
@@ -0,0 +1,367 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "nsHTMLAtoms.h"
|
||||
|
||||
nsIAtom* nsHTMLAtoms::a;
|
||||
nsIAtom* nsHTMLAtoms::above;
|
||||
nsIAtom* nsHTMLAtoms::action;
|
||||
nsIAtom* nsHTMLAtoms::align;
|
||||
nsIAtom* nsHTMLAtoms::alink;
|
||||
nsIAtom* nsHTMLAtoms::alt;
|
||||
nsIAtom* nsHTMLAtoms::archive;
|
||||
nsIAtom* nsHTMLAtoms::background;
|
||||
nsIAtom* nsHTMLAtoms::below;
|
||||
nsIAtom* nsHTMLAtoms::bgcolor;
|
||||
nsIAtom* nsHTMLAtoms::body;
|
||||
nsIAtom* nsHTMLAtoms::border;
|
||||
nsIAtom* nsHTMLAtoms::bordercolor;
|
||||
nsIAtom* nsHTMLAtoms::bottompadding;
|
||||
nsIAtom* nsHTMLAtoms::br;
|
||||
nsIAtom* nsHTMLAtoms::cellpadding;
|
||||
nsIAtom* nsHTMLAtoms::cellspacing;
|
||||
nsIAtom* nsHTMLAtoms::checked;
|
||||
nsIAtom* nsHTMLAtoms::kClass;
|
||||
nsIAtom* nsHTMLAtoms::classid;
|
||||
nsIAtom* nsHTMLAtoms::clear;
|
||||
nsIAtom* nsHTMLAtoms::clip;
|
||||
nsIAtom* nsHTMLAtoms::code;
|
||||
nsIAtom* nsHTMLAtoms::codebase;
|
||||
nsIAtom* nsHTMLAtoms::color;
|
||||
nsIAtom* nsHTMLAtoms::cols;
|
||||
nsIAtom* nsHTMLAtoms::colspan;
|
||||
nsIAtom* nsHTMLAtoms::compact;
|
||||
nsIAtom* nsHTMLAtoms::coords;
|
||||
nsIAtom* nsHTMLAtoms::data;
|
||||
nsIAtom* nsHTMLAtoms::dir;
|
||||
nsIAtom* nsHTMLAtoms::div;
|
||||
nsIAtom* nsHTMLAtoms::dl;
|
||||
nsIAtom* nsHTMLAtoms::encoding;
|
||||
nsIAtom* nsHTMLAtoms::face;
|
||||
nsIAtom* nsHTMLAtoms::font;
|
||||
nsIAtom* nsHTMLAtoms::fontWeight;
|
||||
nsIAtom* nsHTMLAtoms::frameborder;
|
||||
nsIAtom* nsHTMLAtoms::gutter;
|
||||
nsIAtom* nsHTMLAtoms::h1;
|
||||
nsIAtom* nsHTMLAtoms::h2;
|
||||
nsIAtom* nsHTMLAtoms::h3;
|
||||
nsIAtom* nsHTMLAtoms::h4;
|
||||
nsIAtom* nsHTMLAtoms::h5;
|
||||
nsIAtom* nsHTMLAtoms::h6;
|
||||
nsIAtom* nsHTMLAtoms::height;
|
||||
nsIAtom* nsHTMLAtoms::hidden;
|
||||
nsIAtom* nsHTMLAtoms::href;
|
||||
nsIAtom* nsHTMLAtoms::hspace;
|
||||
nsIAtom* nsHTMLAtoms::httpEquiv;
|
||||
nsIAtom* nsHTMLAtoms::id;
|
||||
nsIAtom* nsHTMLAtoms::ismap;
|
||||
nsIAtom* nsHTMLAtoms::language;
|
||||
nsIAtom* nsHTMLAtoms::li;
|
||||
nsIAtom* nsHTMLAtoms::link;
|
||||
nsIAtom* nsHTMLAtoms::left;
|
||||
nsIAtom* nsHTMLAtoms::leftpadding;
|
||||
nsIAtom* nsHTMLAtoms::lowsrc;
|
||||
nsIAtom* nsHTMLAtoms::marginheight;
|
||||
nsIAtom* nsHTMLAtoms::marginwidth;
|
||||
nsIAtom* nsHTMLAtoms::maxlength;
|
||||
nsIAtom* nsHTMLAtoms::mayscript;
|
||||
nsIAtom* nsHTMLAtoms::menu;
|
||||
nsIAtom* nsHTMLAtoms::method;
|
||||
nsIAtom* nsHTMLAtoms::multicol;
|
||||
nsIAtom* nsHTMLAtoms::multiple;
|
||||
nsIAtom* nsHTMLAtoms::name;
|
||||
nsIAtom* nsHTMLAtoms::noresize;
|
||||
nsIAtom* nsHTMLAtoms::noshade;
|
||||
nsIAtom* nsHTMLAtoms::nowrap;
|
||||
nsIAtom* nsHTMLAtoms::ol;
|
||||
nsIAtom* nsHTMLAtoms::onblur;
|
||||
nsIAtom* nsHTMLAtoms::onfocus;
|
||||
nsIAtom* nsHTMLAtoms::onload;
|
||||
nsIAtom* nsHTMLAtoms::onunload;
|
||||
nsIAtom* nsHTMLAtoms::overflow;
|
||||
nsIAtom* nsHTMLAtoms::p;
|
||||
nsIAtom* nsHTMLAtoms::pagex;
|
||||
nsIAtom* nsHTMLAtoms::pagey;
|
||||
nsIAtom* nsHTMLAtoms::pointSize;
|
||||
nsIAtom* nsHTMLAtoms::pre;
|
||||
nsIAtom* nsHTMLAtoms::prompt;
|
||||
nsIAtom* nsHTMLAtoms::rel;
|
||||
nsIAtom* nsHTMLAtoms::rightpadding;
|
||||
nsIAtom* nsHTMLAtoms::rows;
|
||||
nsIAtom* nsHTMLAtoms::rowspan;
|
||||
nsIAtom* nsHTMLAtoms::scrolling;
|
||||
nsIAtom* nsHTMLAtoms::selected;
|
||||
nsIAtom* nsHTMLAtoms::shape;
|
||||
nsIAtom* nsHTMLAtoms::size;
|
||||
nsIAtom* nsHTMLAtoms::src;
|
||||
nsIAtom* nsHTMLAtoms::start;
|
||||
nsIAtom* nsHTMLAtoms::suppress;
|
||||
nsIAtom* nsHTMLAtoms::tabstop;
|
||||
nsIAtom* nsHTMLAtoms::target;
|
||||
nsIAtom* nsHTMLAtoms::text;
|
||||
nsIAtom* nsHTMLAtoms::top;
|
||||
nsIAtom* nsHTMLAtoms::toppadding;
|
||||
nsIAtom* nsHTMLAtoms::type;
|
||||
nsIAtom* nsHTMLAtoms::ul;
|
||||
nsIAtom* nsHTMLAtoms::usemap;
|
||||
nsIAtom* nsHTMLAtoms::valign;
|
||||
nsIAtom* nsHTMLAtoms::value;
|
||||
nsIAtom* nsHTMLAtoms::variable;
|
||||
nsIAtom* nsHTMLAtoms::visibility;
|
||||
nsIAtom* nsHTMLAtoms::vlink;
|
||||
nsIAtom* nsHTMLAtoms::vspace;
|
||||
nsIAtom* nsHTMLAtoms::width;
|
||||
nsIAtom* nsHTMLAtoms::wrap;
|
||||
nsIAtom* nsHTMLAtoms::zindex;
|
||||
|
||||
|
||||
static nsrefcnt gRefCnt;
|
||||
|
||||
void nsHTMLAtoms::AddrefAtoms()
|
||||
{
|
||||
if (0 == gRefCnt) {
|
||||
a = NS_NewAtom("A");
|
||||
above = NS_NewAtom("ABOVE");
|
||||
action = NS_NewAtom("ACTION");
|
||||
align = NS_NewAtom("ALIGN");
|
||||
alink = NS_NewAtom("ALINK");
|
||||
alt = NS_NewAtom("ALT");
|
||||
archive = NS_NewAtom("ARCHIVE");
|
||||
background = NS_NewAtom("BACKGROUND");
|
||||
below = NS_NewAtom("BELOW");
|
||||
bgcolor = NS_NewAtom("BGCOLOR");
|
||||
body = NS_NewAtom("BODY");
|
||||
border = NS_NewAtom("BORDER");
|
||||
bordercolor = NS_NewAtom("BORDERCOLOR");
|
||||
bottompadding = NS_NewAtom("BOTTOMPADDING");
|
||||
br = NS_NewAtom("BR");
|
||||
cellpadding = NS_NewAtom("CELLPADDING");
|
||||
cellspacing = NS_NewAtom("CELLSPACING");
|
||||
checked = NS_NewAtom("CHECKED");
|
||||
kClass = NS_NewAtom("CLASS");
|
||||
classid = NS_NewAtom("CLASSID");
|
||||
clear = NS_NewAtom("CLEAR");
|
||||
clip = NS_NewAtom("CLIP");
|
||||
code = NS_NewAtom("CODE");
|
||||
codebase = NS_NewAtom("CODEBASE");
|
||||
color = NS_NewAtom("COLOR");
|
||||
cols = NS_NewAtom("COLS");
|
||||
colspan = NS_NewAtom("COLSPAN");
|
||||
compact = NS_NewAtom("COMPACT");
|
||||
coords = NS_NewAtom("COORDS");
|
||||
dir = NS_NewAtom("DIR");
|
||||
div = NS_NewAtom("DIV");
|
||||
dl = NS_NewAtom("DL");
|
||||
data = NS_NewAtom("DATA");
|
||||
encoding = NS_NewAtom("ENCODING");
|
||||
face = NS_NewAtom("FACE");
|
||||
font = NS_NewAtom("FONT");
|
||||
fontWeight = NS_NewAtom("FONT-WEIGHT");
|
||||
frameborder = NS_NewAtom("FRAMEBORDER");
|
||||
gutter = NS_NewAtom("GUTTER");
|
||||
h1 = NS_NewAtom("H1");
|
||||
h2 = NS_NewAtom("H2");
|
||||
h3 = NS_NewAtom("H3");
|
||||
h4 = NS_NewAtom("H4");
|
||||
h5 = NS_NewAtom("H5");
|
||||
h6 = NS_NewAtom("H6");
|
||||
height = NS_NewAtom("HEIGHT");
|
||||
hidden = NS_NewAtom("HIDDEN");
|
||||
href = NS_NewAtom("HREF");
|
||||
hspace = NS_NewAtom("HSPACE");
|
||||
httpEquiv = NS_NewAtom("HTTP-EQUIV");
|
||||
id = NS_NewAtom("ID");
|
||||
ismap = NS_NewAtom("ISMAP");
|
||||
language = NS_NewAtom("LANGUAGE");
|
||||
li = NS_NewAtom("LI");
|
||||
link = NS_NewAtom("LINK");
|
||||
left = NS_NewAtom("LEFT");
|
||||
leftpadding = NS_NewAtom("LEFTPADDING");
|
||||
lowsrc = NS_NewAtom("LOWSRC");
|
||||
marginheight = NS_NewAtom("MARGINHEIGHT");
|
||||
marginwidth = NS_NewAtom("MARGINWIDTH");
|
||||
maxlength = NS_NewAtom("MAXLENGTH");
|
||||
mayscript = NS_NewAtom("MAYSCRIPT");
|
||||
menu = NS_NewAtom("MENU");
|
||||
method = NS_NewAtom("METHOD");
|
||||
multicol = NS_NewAtom("MULTICOL");
|
||||
multiple = NS_NewAtom("MULTIPLE");
|
||||
name = NS_NewAtom("NAME");
|
||||
noresize = NS_NewAtom("NORESIZE");
|
||||
noshade = NS_NewAtom("NOSHADE");
|
||||
nowrap = NS_NewAtom("NOWRAP");
|
||||
ol = NS_NewAtom("OL");
|
||||
onblur = NS_NewAtom("ONBLUR");
|
||||
onfocus = NS_NewAtom("ONFOCUS");
|
||||
onload = NS_NewAtom("ONLOAD");
|
||||
onunload = NS_NewAtom("ONUNLOAD");
|
||||
overflow = NS_NewAtom("OVERFLOW");
|
||||
p = NS_NewAtom("P");
|
||||
pagex = NS_NewAtom("PAGEX");
|
||||
pagey = NS_NewAtom("PAGEY");
|
||||
pointSize = NS_NewAtom("POINT-SIZE");
|
||||
pre = NS_NewAtom("PRE");
|
||||
prompt = NS_NewAtom("PROMPT");
|
||||
rel = NS_NewAtom("REL");
|
||||
rightpadding = NS_NewAtom("RIGHTPADDING");
|
||||
rows = NS_NewAtom("ROWS");
|
||||
rowspan = NS_NewAtom("ROWSPAN");
|
||||
scrolling = NS_NewAtom("SCROLLING");
|
||||
selected = NS_NewAtom("SELECTED");
|
||||
shape = NS_NewAtom("SHAPE");
|
||||
size = NS_NewAtom("SIZE");
|
||||
src = NS_NewAtom("SRC");
|
||||
start = NS_NewAtom("START");
|
||||
suppress = NS_NewAtom("SUPPRESS");
|
||||
tabstop = NS_NewAtom("TABSTOP");
|
||||
target = NS_NewAtom("TARGET");
|
||||
text = NS_NewAtom("TEXT");
|
||||
top = NS_NewAtom("TOP");
|
||||
toppadding = NS_NewAtom("TOPPADDING");
|
||||
type = NS_NewAtom("TYPE");
|
||||
ul = NS_NewAtom("UL");
|
||||
usemap = NS_NewAtom("USEMAP");
|
||||
valign = NS_NewAtom("VALIGN");
|
||||
value = NS_NewAtom("VALUE");
|
||||
variable = NS_NewAtom("VARIABLE");
|
||||
visibility = NS_NewAtom("VISIBILITY");
|
||||
vlink = NS_NewAtom("VLINK");
|
||||
vspace = NS_NewAtom("VSPACE");
|
||||
width = NS_NewAtom("WIDTH");
|
||||
wrap = NS_NewAtom("WRAP");
|
||||
zindex = NS_NewAtom("ZINDEX");
|
||||
}
|
||||
++gRefCnt;
|
||||
}
|
||||
|
||||
void nsHTMLAtoms::ReleaseAtoms()
|
||||
{
|
||||
NS_PRECONDITION(gRefCnt != 0, "bad release atoms");
|
||||
if (--gRefCnt == 0) {
|
||||
NS_RELEASE(a);
|
||||
NS_RELEASE(above);
|
||||
NS_RELEASE(action);
|
||||
NS_RELEASE(align);
|
||||
NS_RELEASE(alink);
|
||||
NS_RELEASE(alt);
|
||||
NS_RELEASE(archive);
|
||||
NS_RELEASE(background);
|
||||
NS_RELEASE(below);
|
||||
NS_RELEASE(bgcolor);
|
||||
NS_RELEASE(body);
|
||||
NS_RELEASE(border);
|
||||
NS_RELEASE(bordercolor);
|
||||
NS_RELEASE(bottompadding);
|
||||
NS_RELEASE(br);
|
||||
NS_RELEASE(cellpadding);
|
||||
NS_RELEASE(cellspacing);
|
||||
NS_RELEASE(checked);
|
||||
NS_RELEASE(kClass);
|
||||
NS_RELEASE(classid);
|
||||
NS_RELEASE(clear);
|
||||
NS_RELEASE(clip);
|
||||
NS_RELEASE(code);
|
||||
NS_RELEASE(codebase);
|
||||
NS_RELEASE(color);
|
||||
NS_RELEASE(cols);
|
||||
NS_RELEASE(colspan);
|
||||
NS_RELEASE(compact);
|
||||
NS_RELEASE(coords);
|
||||
NS_RELEASE(dir);
|
||||
NS_RELEASE(div);
|
||||
NS_RELEASE(dl);
|
||||
NS_RELEASE(data);
|
||||
NS_RELEASE(encoding);
|
||||
NS_RELEASE(face);
|
||||
NS_RELEASE(font);
|
||||
NS_RELEASE(fontWeight);
|
||||
NS_RELEASE(frameborder);
|
||||
NS_RELEASE(gutter);
|
||||
NS_RELEASE(h1);
|
||||
NS_RELEASE(h2);
|
||||
NS_RELEASE(h3);
|
||||
NS_RELEASE(h4);
|
||||
NS_RELEASE(h5);
|
||||
NS_RELEASE(h6);
|
||||
NS_RELEASE(height);
|
||||
NS_RELEASE(hidden);
|
||||
NS_RELEASE(href);
|
||||
NS_RELEASE(hspace);
|
||||
NS_RELEASE(httpEquiv);
|
||||
NS_RELEASE(id);
|
||||
NS_RELEASE(ismap);
|
||||
NS_RELEASE(language);
|
||||
NS_RELEASE(li);
|
||||
NS_RELEASE(link);
|
||||
NS_RELEASE(left);
|
||||
NS_RELEASE(leftpadding);
|
||||
NS_RELEASE(lowsrc);
|
||||
NS_RELEASE(marginheight);
|
||||
NS_RELEASE(marginwidth);
|
||||
NS_RELEASE(maxlength);
|
||||
NS_RELEASE(mayscript);
|
||||
NS_RELEASE(menu);
|
||||
NS_RELEASE(method);
|
||||
NS_RELEASE(multicol);
|
||||
NS_RELEASE(multiple);
|
||||
NS_RELEASE(name);
|
||||
NS_RELEASE(noresize);
|
||||
NS_RELEASE(noshade);
|
||||
NS_RELEASE(nowrap);
|
||||
NS_RELEASE(ol);
|
||||
NS_RELEASE(onblur);
|
||||
NS_RELEASE(onfocus);
|
||||
NS_RELEASE(onload);
|
||||
NS_RELEASE(onunload);
|
||||
NS_RELEASE(overflow);
|
||||
NS_RELEASE(p);
|
||||
NS_RELEASE(pagex);
|
||||
NS_RELEASE(pagey);
|
||||
NS_RELEASE(pointSize);
|
||||
NS_RELEASE(pre);
|
||||
NS_RELEASE(prompt);
|
||||
NS_RELEASE(rel);
|
||||
NS_RELEASE(rightpadding);
|
||||
NS_RELEASE(rows);
|
||||
NS_RELEASE(rowspan);
|
||||
NS_RELEASE(scrolling);
|
||||
NS_RELEASE(selected);
|
||||
NS_RELEASE(shape);
|
||||
NS_RELEASE(size);
|
||||
NS_RELEASE(src);
|
||||
NS_RELEASE(start);
|
||||
NS_RELEASE(suppress);
|
||||
NS_RELEASE(tabstop);
|
||||
NS_RELEASE(target);
|
||||
NS_RELEASE(text);
|
||||
NS_RELEASE(top);
|
||||
NS_RELEASE(toppadding);
|
||||
NS_RELEASE(type);
|
||||
NS_RELEASE(ul);
|
||||
NS_RELEASE(usemap);
|
||||
NS_RELEASE(valign);
|
||||
NS_RELEASE(value);
|
||||
NS_RELEASE(variable);
|
||||
NS_RELEASE(visibility);
|
||||
NS_RELEASE(vlink);
|
||||
NS_RELEASE(vspace);
|
||||
NS_RELEASE(width);
|
||||
NS_RELEASE(wrap);
|
||||
NS_RELEASE(zindex);
|
||||
}
|
||||
}
|
||||
|
||||
257
content/shared/src/nsHTMLValue.cpp
Normal file
257
content/shared/src/nsHTMLValue.cpp
Normal file
@@ -0,0 +1,257 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "nsHTMLValue.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
const nsHTMLValue nsHTMLValue::kNull;
|
||||
|
||||
nsHTMLValue::nsHTMLValue(void)
|
||||
: mUnit(eHTMLUnit_Null)
|
||||
{
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(PRInt32 aValue, nsHTMLUnit aUnit)
|
||||
: mUnit(aUnit)
|
||||
{
|
||||
mValue.mInt = aValue;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(float aValue, nsHTMLUnit aUnit)
|
||||
: mUnit(aUnit)
|
||||
{
|
||||
mValue.mFloat = aValue;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(const nsString& aValue)
|
||||
: mUnit(eHTMLUnit_String)
|
||||
{
|
||||
mValue.mString = aValue.ToNewString();
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nsISupports* aValue)
|
||||
: mUnit(eHTMLUnit_ISupports)
|
||||
{
|
||||
mValue.mISupports = aValue;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(nscolor aValue)
|
||||
: mUnit(eHTMLUnit_Color)
|
||||
{
|
||||
mValue.mColor = aValue;
|
||||
}
|
||||
|
||||
nsHTMLValue::nsHTMLValue(const nsHTMLValue& aCopy)
|
||||
: mUnit(aCopy.mUnit)
|
||||
{
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull != aCopy.mValue.mString) {
|
||||
mValue.mString = aCopy.mValue.mString->ToNewString();
|
||||
}
|
||||
else {
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
mValue.mISupports = aCopy.mValue.mISupports;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
mValue.mColor = aCopy.mValue.mColor;
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
mValue.mFloat = aCopy.mValue.mFloat;
|
||||
}
|
||||
else {
|
||||
mValue.mInt = aCopy.mValue.mInt;
|
||||
}
|
||||
}
|
||||
|
||||
nsHTMLValue::~nsHTMLValue(void)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
nsHTMLValue& nsHTMLValue::operator=(const nsHTMLValue& aCopy)
|
||||
{
|
||||
Reset();
|
||||
mUnit = aCopy.mUnit;
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull != aCopy.mValue.mString) {
|
||||
mValue.mString = aCopy.mValue.mString->ToNewString();
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
mValue.mISupports = aCopy.mValue.mISupports;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
mValue.mColor = aCopy.mValue.mColor;
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
mValue.mFloat = aCopy.mValue.mFloat;
|
||||
}
|
||||
else {
|
||||
mValue.mInt = aCopy.mValue.mInt;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
PRBool nsHTMLValue::operator==(const nsHTMLValue& aOther) const
|
||||
{
|
||||
if (mUnit == aOther.mUnit) {
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull == mValue.mString) {
|
||||
if (nsnull == aOther.mValue.mString) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
}
|
||||
else if (nsnull != aOther.mValue.mString) {
|
||||
return mValue.mString->Equals(*(aOther.mValue.mString));
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
return PRBool(mValue.mISupports == aOther.mValue.mISupports);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
return PRBool(mValue.mColor == aOther.mValue.mColor);
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
return PRBool(mValue.mFloat == aOther.mValue.mFloat);
|
||||
}
|
||||
else {
|
||||
return PRBool(mValue.mInt == aOther.mValue.mInt);
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
void nsHTMLValue::Reset(void)
|
||||
{
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull != mValue.mString) {
|
||||
delete mValue.mString;
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
NS_IF_RELEASE(mValue.mISupports);
|
||||
}
|
||||
mUnit = eHTMLUnit_Null;
|
||||
mValue.mString = nsnull;
|
||||
}
|
||||
|
||||
|
||||
void nsHTMLValue::Set(PRInt32 aValue, nsHTMLUnit aUnit)
|
||||
{
|
||||
Reset();
|
||||
mUnit = aUnit;
|
||||
mValue.mInt = aValue;
|
||||
}
|
||||
|
||||
void nsHTMLValue::Set(float aValue, nsHTMLUnit aUnit)
|
||||
{
|
||||
Reset();
|
||||
mUnit = aUnit;
|
||||
mValue.mFloat = aValue;
|
||||
}
|
||||
|
||||
void nsHTMLValue::Set(const nsString& aValue)
|
||||
{
|
||||
Reset();
|
||||
mUnit = eHTMLUnit_String;
|
||||
mValue.mString = aValue.ToNewString();
|
||||
}
|
||||
|
||||
void nsHTMLValue::Set(nsISupports* aValue)
|
||||
{
|
||||
Reset();
|
||||
mUnit = eHTMLUnit_ISupports;
|
||||
mValue.mISupports = aValue;
|
||||
NS_IF_ADDREF(mValue.mISupports);
|
||||
}
|
||||
|
||||
void nsHTMLValue::Set(nscolor aValue)
|
||||
{
|
||||
Reset();
|
||||
mUnit = eHTMLUnit_Color;
|
||||
mValue.mColor = aValue;
|
||||
}
|
||||
|
||||
void nsHTMLValue::AppendToString(nsString& aBuffer) const
|
||||
{
|
||||
if (eHTMLUnit_Null == mUnit) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (eHTMLUnit_String == mUnit) {
|
||||
if (nsnull != mValue.mString) {
|
||||
aBuffer.Append('"');
|
||||
aBuffer.Append(*(mValue.mString));
|
||||
aBuffer.Append('"');
|
||||
}
|
||||
else {
|
||||
aBuffer.Append("null str");
|
||||
}
|
||||
}
|
||||
else if (eHTMLUnit_ISupports == mUnit) {
|
||||
aBuffer.Append("0x");
|
||||
aBuffer.Append((PRInt32)mValue.mISupports, 16);
|
||||
}
|
||||
else if (eHTMLUnit_Color == mUnit){
|
||||
aBuffer.Append("(0x");
|
||||
aBuffer.Append(NS_GET_R(mValue.mColor), 16);
|
||||
aBuffer.Append(" 0x");
|
||||
aBuffer.Append(NS_GET_G(mValue.mColor), 16);
|
||||
aBuffer.Append(" 0x");
|
||||
aBuffer.Append(NS_GET_B(mValue.mColor), 16);
|
||||
aBuffer.Append(" 0x");
|
||||
aBuffer.Append(NS_GET_A(mValue.mColor), 16);
|
||||
aBuffer.Append(')');
|
||||
}
|
||||
else if (eHTMLUnit_Percent == mUnit) {
|
||||
aBuffer.Append(mValue.mFloat);
|
||||
}
|
||||
else {
|
||||
aBuffer.Append(mValue.mInt, 10);
|
||||
aBuffer.Append("[0x");
|
||||
aBuffer.Append(mValue.mInt, 16);
|
||||
aBuffer.Append(']');
|
||||
}
|
||||
|
||||
switch (mUnit) {
|
||||
case eHTMLUnit_Null: break;
|
||||
case eHTMLUnit_String: break;
|
||||
case eHTMLUnit_ISupports: aBuffer.Append("ptr"); break;
|
||||
case eHTMLUnit_Absolute: break;
|
||||
case eHTMLUnit_Enumerated: aBuffer.Append("enum"); break;
|
||||
case eHTMLUnit_Color: aBuffer.Append("rbga"); break;
|
||||
case eHTMLUnit_Percent: aBuffer.Append("%"); break;
|
||||
case eHTMLUnit_Pixel: aBuffer.Append("px"); break;
|
||||
}
|
||||
aBuffer.Append(' ');
|
||||
}
|
||||
|
||||
void nsHTMLValue::ToString(nsString& aBuffer) const
|
||||
{
|
||||
aBuffer.SetLength(0);
|
||||
AppendToString(aBuffer);
|
||||
}
|
||||
|
||||
24
dom/Makefile
Normal file
24
dom/Makefile
Normal file
@@ -0,0 +1,24 @@
|
||||
#!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 = ..
|
||||
|
||||
DIRS = public src
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
22
dom/makefile.win
Normal file
22
dom/makefile.win
Normal file
@@ -0,0 +1,22 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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=..
|
||||
|
||||
DIRS= public src
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
34
dom/public/Makefile
Normal file
34
dom/public/Makefile
Normal file
@@ -0,0 +1,34 @@
|
||||
#!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=../..
|
||||
|
||||
DIRS = coreDom
|
||||
|
||||
DEFINES = -D_IMPL_NS_DOM
|
||||
|
||||
EXPORTS = \
|
||||
nsIScriptContext.h \
|
||||
nsIScriptObject.h \
|
||||
nsIScriptObjectOwner.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = dom
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
38
dom/public/coreDom/Makefile
Normal file
38
dom/public/coreDom/Makefile
Normal file
@@ -0,0 +1,38 @@
|
||||
#!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=../../..
|
||||
|
||||
DEFINES = -D_IMPL_NS_DOM
|
||||
|
||||
EXPORTS = \
|
||||
nsDOM.h \
|
||||
nsIDOMAttribute.h \
|
||||
nsIDOMComment.h \
|
||||
nsIDOMDocument.h \
|
||||
nsIDOMElement.h \
|
||||
nsIDOMIterators.h \
|
||||
nsIDOMNode.h \
|
||||
nsIDOMPI.h \
|
||||
nsIDOMText.h \
|
||||
$(NULL)
|
||||
|
||||
MODULE = dom
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
28
dom/public/coreDom/makefile.win
Normal file
28
dom/public/coreDom/makefile.win
Normal file
@@ -0,0 +1,28 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DEFINES=-D_IMPL_NS_DOM
|
||||
EXPORTS=nsDOM.h nsIDOMAttribute.h nsIDOMComment.h nsIDOMDocument.h \
|
||||
nsIDOMElement.h nsIDOMIterators.h nsIDOMNode.h nsIDOMPI.h \
|
||||
nsIDOMText.h
|
||||
MODULE=dom
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
39
dom/public/coreDom/nsDOM.h
Normal file
39
dom/public/coreDom/nsDOM.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsDOM_h__
|
||||
#define nsDOM_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIDOMDocument;
|
||||
class nsString;
|
||||
|
||||
#define NS_IDOM_IID \
|
||||
{ /* 8f6bca70-ce42-11d1-b724-00600891d8c9 */ \
|
||||
0x8f6bca70, 0xce42, 0x11d1, \
|
||||
{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} }
|
||||
|
||||
class nsIDOM : public nsISupports {
|
||||
public:
|
||||
virtual nsresult CreateDocument(nsString &type, nsIDOMDocument** aDocument) = 0;
|
||||
virtual nsresult HasFeature(nsString &aFeature) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // nsDOM_h__
|
||||
61
dom/public/coreDom/nsIDOMAttribute.h
Normal file
61
dom/public/coreDom/nsIDOMAttribute.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsIDOMAttribute_h__
|
||||
#define nsIDOMAttribute_h__
|
||||
|
||||
#include "nsDOM.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
// forward declaration
|
||||
class nsIDOMNode;
|
||||
|
||||
#define NS_IDOMATTRIBUTE_IID \
|
||||
{ /* 8f6bca77-ce42-11d1-b724-00600891d8c9 */ \
|
||||
0x8f6bca77, 0xce42, 0x11d1, \
|
||||
{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} }
|
||||
|
||||
class nsIDOMAttribute : public nsISupports {
|
||||
public:
|
||||
virtual nsresult GetName(nsString &aName) = 0;
|
||||
//attribute Node value;
|
||||
virtual nsresult GetValue(nsString &aName /*nsIDOMNode **aValue*/) = 0;
|
||||
virtual nsresult SetValue(nsString &aName /*nsIDOMNode *aValue*/) = 0;
|
||||
//attribute boolean specified;
|
||||
virtual nsresult GetSpecified() = 0;
|
||||
virtual nsresult SetSpecified(PRBool specified) = 0;
|
||||
virtual nsresult ToString(nsString &aString) = 0;
|
||||
};
|
||||
|
||||
#define NS_IDOMATTRIBUTELIST_IID \
|
||||
{ /* 8f6bca78-ce42-11d1-b724-00600891d8c9 */ \
|
||||
0x8f6bca78, 0xce42, 0x11d1, \
|
||||
{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} }
|
||||
|
||||
class nsIDOMAttributeList : public nsISupports {
|
||||
public:
|
||||
virtual nsresult GetAttribute(nsString &aAttrName, nsIDOMAttribute** aAttribute) = 0;
|
||||
virtual nsresult SetAttribute(nsIDOMAttribute *attr) = 0;
|
||||
virtual nsresult Remove(nsString &attrName, nsIDOMAttribute** aAttribute) = 0;
|
||||
virtual nsresult Item(PRUint32 aIndex, nsIDOMAttribute** aAttribute) = 0;
|
||||
virtual nsresult GetLength(PRUint32 *aLength) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // nsIDOMAttribute_h__
|
||||
|
||||
38
dom/public/coreDom/nsIDOMComment.h
Normal file
38
dom/public/coreDom/nsIDOMComment.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsIDOMComment_h__
|
||||
#define nsIDOMComment_h__
|
||||
|
||||
#include "nsDOM.h"
|
||||
#include "nsIDOMNode.h"
|
||||
|
||||
#define NS_IDOMCOMMENT_IID \
|
||||
{ /* 8f6bca7a-ce42-11d1-b724-00600891d8c9 */ \
|
||||
0x8f6bca7a, 0xce42, 0x11d1, \
|
||||
{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} }
|
||||
|
||||
class nsIDOMComment : public nsIDOMNode {
|
||||
public:
|
||||
//attribute UniString data;
|
||||
virtual nsresult GetData(nsString &aData) = 0;
|
||||
virtual nsresult SetData(nsString &aData) = 0;
|
||||
};
|
||||
|
||||
#endif // nsIDOMComment_h__
|
||||
|
||||
96
dom/public/coreDom/nsIDOMDocument.h
Normal file
96
dom/public/coreDom/nsIDOMDocument.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsIDOMDocument_h__
|
||||
#define nsIDOMDocument_h__
|
||||
|
||||
#include "nsDOM.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIDOMNode.h"
|
||||
|
||||
// forward declaration
|
||||
class nsIDOMDocument;
|
||||
class nsIDOMElement;
|
||||
class nsIDOMText;
|
||||
class nsIDOMComment;
|
||||
class nsIDOMPI;
|
||||
class nsIDOMAttribute;
|
||||
class nsIDOMAttributeList;
|
||||
class nsIDOMNodeIterator;
|
||||
class nsIDOMTreeIterator;
|
||||
|
||||
#define NS_IDOMDOCUMENTCONTEXT_IID \
|
||||
{ /* 8f6bca71-ce42-11d1-b724-00600891d8c9 */ \
|
||||
0x8f6bca71, 0xce42, 0x11d1, \
|
||||
{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} }
|
||||
|
||||
class nsIDOMDocumentContext : public nsISupports {
|
||||
public:
|
||||
//attribute Document document;
|
||||
virtual nsresult GetDocument(nsIDOMDocument **aDocument) = 0;
|
||||
virtual nsresult SetDocument(nsIDOMDocument *aDocument) = 0;
|
||||
};
|
||||
|
||||
#define NS_IDOMDOCUMENTFRAGMENT_IID \
|
||||
{ /* 8f6bca72-ce42-11d1-b724-00600891d8c9 */ \
|
||||
0x8f6bca72, 0xce42, 0x11d1, \
|
||||
{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} }
|
||||
|
||||
class nsIDOMDocumentFragment : public nsIDOMNode {
|
||||
public:
|
||||
//attribute Document masterDoc;
|
||||
virtual nsresult GetMasterDoc(nsIDOMDocument **aDocument) = 0;
|
||||
virtual nsresult SetMasterDoc(nsIDOMDocument *aDocument) = 0;
|
||||
};
|
||||
|
||||
#define NS_IDOMDOCUMENT_IID \
|
||||
{ /* 8f6bca73-ce42-11d1-b724-00600891d8c9 */ \
|
||||
0x8f6bca73, 0xce42, 0x11d1, \
|
||||
{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} }
|
||||
|
||||
class nsIDOMDocument : public nsIDOMDocumentFragment {
|
||||
public:
|
||||
//attribute Node documentType;
|
||||
virtual nsresult GetDocumentType(nsIDOMNode **aDocType) = 0;
|
||||
virtual nsresult SetDocumentType(nsIDOMNode *aNode) = 0;
|
||||
|
||||
//attribute Element documentElement;
|
||||
virtual nsresult GetDocumentElement(nsIDOMElement **aElement) = 0;
|
||||
virtual nsresult SetDocumentElement(nsIDOMElement *aElement) = 0;
|
||||
|
||||
//attribute DocumentContext contextInfo;
|
||||
virtual nsresult GetDocumentContext(nsIDOMDocumentContext **aDocContext) = 0;
|
||||
virtual nsresult SetDocumentContext(nsIDOMDocumentContext *aContext) = 0;
|
||||
|
||||
virtual nsresult CreateDocumentContext(nsIDOMDocumentContext **aDocContext) = 0;
|
||||
virtual nsresult CreateElement(nsString &aTagName,
|
||||
nsIDOMAttributeList *aAttributes,
|
||||
nsIDOMElement **aElement) = 0;
|
||||
virtual nsresult CreateTextNode(nsString &aData, nsIDOMText** aTextNode) = 0;
|
||||
virtual nsresult CreateComment(nsString &aData, nsIDOMComment **aComment) = 0;
|
||||
virtual nsresult CreatePI(nsString &aName, nsString &aData, nsIDOMPI **aPI) = 0;
|
||||
virtual nsresult CreateAttribute(nsString &aName,
|
||||
nsIDOMNode *value,
|
||||
nsIDOMAttribute **aAttribute) = 0;
|
||||
virtual nsresult CreateAttributeList(nsIDOMAttributeList **aAttributesList) = 0;
|
||||
virtual nsresult CreateTreeIterator(nsIDOMNode **aNode, nsIDOMTreeIterator **aTreeIterator) = 0;
|
||||
virtual nsresult GetElementsByTagName(nsIDOMNodeIterator **aIterator) = 0;
|
||||
};
|
||||
|
||||
#endif // nsIDOMDocument_h__
|
||||
|
||||
50
dom/public/coreDom/nsIDOMElement.h
Normal file
50
dom/public/coreDom/nsIDOMElement.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsIDOMElement_h__
|
||||
#define nsIDOMElement_h__
|
||||
|
||||
#include "nsDOM.h"
|
||||
#include "nsIDOMNode.h"
|
||||
|
||||
// forward declaration
|
||||
class nsIDOMAttribute;
|
||||
class nsIDOMAttributeList;
|
||||
class nsIDOMNodeIterator;
|
||||
|
||||
#define NS_IDOMELEMENT_IID \
|
||||
{ /* 8f6bca79-ce42-11d1-b724-00600891d8c9 */ \
|
||||
0x8f6bca79, 0xce42, 0x11d1, \
|
||||
{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} }
|
||||
|
||||
class nsIDOMElement : public nsIDOMNode {
|
||||
public:
|
||||
virtual nsresult GetTagName(nsString &aName) = 0;
|
||||
virtual nsresult GetAttributes(nsIDOMAttributeList **aAttributeList) = 0;
|
||||
virtual nsresult GetDOMAttribute(nsString &aName, nsString &aValue) = 0;
|
||||
virtual nsresult SetDOMAttribute(nsString &aName, nsString &aValue) = 0;
|
||||
virtual nsresult RemoveAttribute(nsString &aName) = 0;
|
||||
virtual nsresult GetAttributeNode(nsString &aName, nsIDOMAttribute **aAttribute) = 0;
|
||||
virtual nsresult SetAttributeNode(nsIDOMAttribute *aAttribute) = 0;
|
||||
virtual nsresult RemoveAttributeNode(nsIDOMAttribute *aAttribute) = 0;
|
||||
virtual nsresult GetElementsByTagName(nsString &aName,nsIDOMNodeIterator **aIterator) = 0;
|
||||
virtual nsresult Normalize() = 0;
|
||||
};
|
||||
|
||||
#endif // nsIDOMElement_h__
|
||||
|
||||
64
dom/public/coreDom/nsIDOMIterators.h
Normal file
64
dom/public/coreDom/nsIDOMIterators.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsIDOMIterators_h__
|
||||
#define nsIDOMIterators_h__
|
||||
|
||||
#include "nsDOM.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
// forward declaration
|
||||
class nsIDOMNode;
|
||||
|
||||
#define NS_IDOMNODEITERATOR_IID \
|
||||
{ /* 8f6bca75-ce42-11d1-b724-00600891d8c9 */ \
|
||||
0x8f6bca75, 0xce42, 0x11d1, \
|
||||
{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} }
|
||||
|
||||
class nsIDOMNodeIterator : public nsISupports {
|
||||
public:
|
||||
virtual nsresult SetFilter(PRInt32 aFilter, PRBool aFilterOn) = 0;
|
||||
virtual nsresult GetLength(PRUint32 *aLength) = 0;
|
||||
virtual nsresult GetCurrentNode(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult GetNextNode(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult GetPreviousNode(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult ToFirst(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult ToLast(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult MoveTo(int aNth, nsIDOMNode **aNode) = 0;
|
||||
};
|
||||
|
||||
#define NS_IDOMTREEITERATOR_IID \
|
||||
{ /* 8f6bca76-ce42-11d1-b724-00600891d8c9 */ \
|
||||
0x8f6bca76, 0xce42, 0x11d1, \
|
||||
{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} }
|
||||
|
||||
class nsIDOMTreeIterator : public nsIDOMNodeIterator {
|
||||
public:
|
||||
virtual nsresult NumChildren(PRUint32 *aLength) = 0;
|
||||
virtual nsresult NumPreviousSiblings(PRUint32 *aLength) = 0;
|
||||
virtual nsresult NumNextSiblings(PRUint32 *aLength) = 0;
|
||||
virtual nsresult ToParent(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult ToPreviousSibling(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult ToNextSibling(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult ToFirstChild(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult ToLastChild(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult ToNthChild(nsIDOMNode **aNode) = 0;
|
||||
};
|
||||
|
||||
#endif // nsIDOMIterators_h__
|
||||
|
||||
58
dom/public/coreDom/nsIDOMNode.h
Normal file
58
dom/public/coreDom/nsIDOMNode.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsIDOMNode_h__
|
||||
#define nsIDOMNode_h__
|
||||
|
||||
#include "nsDOM.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
// forward declaration
|
||||
class nsIDOMNodeIterator;
|
||||
|
||||
#define NS_IDOMNODE_IID \
|
||||
{ /* 8f6bca74-ce42-11d1-b724-00600891d8c9 */ \
|
||||
0x8f6bca74, 0xce42, 0x11d1, \
|
||||
{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} }
|
||||
|
||||
class nsIDOMNode : public nsISupports {
|
||||
public:
|
||||
// NodeType
|
||||
enum NodeType {
|
||||
DOCUMENT = 1,
|
||||
ELEMENT = 2,
|
||||
ATTRIBUTE = 3,
|
||||
PI = 4,
|
||||
COMMENT = 5,
|
||||
TEXT = 6
|
||||
};
|
||||
|
||||
virtual nsresult GetNodeType(PRInt32 *aType) = 0;
|
||||
virtual nsresult GetParentNode(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult GetChildNodes(nsIDOMNodeIterator **aIterator) = 0;
|
||||
virtual nsresult HasChildNodes() = 0;
|
||||
virtual nsresult GetFirstChild(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult GetPreviousSibling(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult GetNextSibling(nsIDOMNode **aNode) = 0;
|
||||
virtual nsresult InsertBefore(nsIDOMNode *newChild, nsIDOMNode *refChild) = 0;
|
||||
virtual nsresult ReplaceChild(nsIDOMNode *newChild, nsIDOMNode *oldChild) = 0;
|
||||
virtual nsresult RemoveChild(nsIDOMNode *oldChild) = 0;
|
||||
};
|
||||
|
||||
#endif // nsIDOMNode_h__
|
||||
|
||||
37
dom/public/coreDom/nsIDOMPI.h
Normal file
37
dom/public/coreDom/nsIDOMPI.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsIDOMPI_h__
|
||||
#define nsIDOMPI_h__
|
||||
|
||||
#include "nsDOM.h"
|
||||
#include "nsIDOMNode.h"
|
||||
|
||||
|
||||
class nsIDOMPI : public nsIDOMNode {
|
||||
public:
|
||||
//attribute UniString name;
|
||||
virtual UniString GetName() = 0;
|
||||
virtual void SetName(UniString name) = 0;
|
||||
//attribute UniString data;
|
||||
virtual UniString GetData() = 0;
|
||||
virtual void SetData(UniString data) = 0;
|
||||
};
|
||||
|
||||
#endif // nsIDOMPI_h__
|
||||
|
||||
46
dom/public/coreDom/nsIDOMText.h
Normal file
46
dom/public/coreDom/nsIDOMText.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsIDOMText_h__
|
||||
#define nsIDOMText_h__
|
||||
|
||||
#include "nsDOM.h"
|
||||
#include "nsIDOMNode.h"
|
||||
|
||||
// forward declaration
|
||||
class nsIDOMElement;
|
||||
|
||||
#define NS_IDOMTEXT_IID \
|
||||
{ /* 8f6bca7b-ce42-11d1-b724-00600891d8c9 */ \
|
||||
0x8f6bca7b, 0xce42, 0x11d1, \
|
||||
{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} }
|
||||
|
||||
class nsIDOMText : public nsIDOMNode {
|
||||
public:
|
||||
//attribute UniString data;
|
||||
virtual nsresult GetData(nsString &aString) = 0;
|
||||
virtual nsresult SetData(nsString &aString) = 0;
|
||||
virtual nsresult Append(nsString &aData) = 0;
|
||||
virtual nsresult Insert(int offset, nsString &aData) = 0;
|
||||
virtual nsresult Delete(int offset, int count) = 0;
|
||||
virtual nsresult Replace(int offset, int count, nsString &aData) = 0;
|
||||
virtual nsresult Splice(nsIDOMElement *element, int offset, int count) = 0;
|
||||
};
|
||||
|
||||
#endif // nsIDOMText_h__
|
||||
|
||||
28
dom/public/makefile.win
Normal file
28
dom/public/makefile.win
Normal file
@@ -0,0 +1,28 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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=..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DIRS=coreDom
|
||||
DEFINES=-D_IMPL_NS_DOM
|
||||
EXPORTS=nsIScriptContext.h nsIScriptObject.h nsIScriptObjectOwner.h
|
||||
|
||||
MODULE=dom
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
53
dom/public/nsIScriptContext.h
Normal file
53
dom/public/nsIScriptContext.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef nsIScriptContext_h__
|
||||
#define nsIScriptContext_h__
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
#include "jsapi.h"
|
||||
|
||||
//
|
||||
// This dependency will disappear soon. A more general "global object"
|
||||
// interface will be defined. nsIWebWidget is too specific
|
||||
//
|
||||
class nsIWebWidget;
|
||||
|
||||
#define NS_ISCRIPTCONTEXT_IID \
|
||||
{ /* 8f6bca7d-ce42-11d1-b724-00600891d8c9 */ \
|
||||
0x8f6bca7d, 0xce42, 0x11d1, \
|
||||
{0xb7, 0x24, 0x00, 0x60, 0x08, 0x91, 0xd8, 0xc9} }
|
||||
|
||||
class nsIScriptContext : public nsISupports {
|
||||
public:
|
||||
virtual PRBool EvaluateString(const char *aScript,
|
||||
PRUint32 aScriptSize,
|
||||
jsval *aRetValue) = 0;
|
||||
virtual JSObject* GetGlobalObject() = 0;
|
||||
virtual JSContext* GetContext() = 0;
|
||||
virtual nsresult InitAllClasses() = 0;
|
||||
// This dependency (nsIWebWidget) will disappear soon. A more general "global object"
|
||||
// interface will be defined. nsIWebWidget is too specific
|
||||
virtual nsresult InitContext(nsIWebWidget *aGlobalObject) = 0;
|
||||
};
|
||||
|
||||
extern "C" NS_DOM NS_CreateContext(nsIWebWidget *aGlobal, nsIScriptContext **aContext);
|
||||
|
||||
#endif // nsIScriptContext_h__
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user