bug 23400: Need to expose api GetDocumentCharacterSet() to JS. r=vidur.

git-svn-id: svn://10.0.0.236/trunk@57887 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
tao%netscape.com 2000-01-15 02:01:05 +00:00
parent ebb5dd54af
commit ecd98e520f
13 changed files with 246 additions and 24 deletions

View File

@ -1909,6 +1909,12 @@ nsDocument::GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)
return NS_OK;
}
NS_IMETHODIMP
nsDocument::GetCharacterSet(nsString& aCharacterSet)
{
return GetDocumentCharacterSet(aCharacterSet);
}
NS_IMETHODIMP
nsDocument::CreateElementWithNameSpace(const nsString& aTagName,
const nsString& aNameSpace,

View File

@ -334,6 +334,7 @@ public:
NS_IMETHOD CreateEntityReference(const nsString& aName, nsIDOMEntityReference** aReturn);
NS_IMETHOD GetElementsByTagName(const nsString& aTagname, nsIDOMNodeList** aReturn);
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets);
NS_IMETHOD GetCharacterSet(nsString& aCharacterSet);
NS_IMETHOD CreateElementWithNameSpace(const nsString& aTagName,
const nsString& aNameSpace,
nsIDOMElement** aReturn);

View File

@ -695,15 +695,11 @@ nsXULDocument::StartDocumentLoad(const char* aCommand,
rv = PrepareStyleSheets(mDocumentURL);
if (NS_FAILED(rv)) return rv;
// Get the content type, if possible, to see if it's a cached XUL
// load. We explicitly ignore failure at this point, because
// certain hacks (cough, the directory viewer) need to be able to
// StartDocumentLoad() before the channel's content type has been
// detected.
nsXPIDLCString contentType;
(void) aChannel->GetContentType(getter_Copies(contentType));
rv = aChannel->GetContentType(getter_Copies(contentType));
if (NS_FAILED(rv)) return rv;
if (contentType && PL_strcmp(contentType, "text/cached-xul") == 0) {
if (PL_strcmp("text/cached-xul", (const char*) contentType) == 0) {
// Look in the chrome cache: we've got this puppy loaded
// already.
nsCOMPtr<nsIXULPrototypeDocument> proto;
@ -2496,6 +2492,11 @@ nsXULDocument::GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULDocument::GetCharacterSet(nsString& aCharacterSet)
{
return GetDocumentCharacterSet(aCharacterSet);
}
NS_IMETHODIMP
nsXULDocument::CreateElementWithNameSpace(const nsString& aTagName,
@ -3447,16 +3448,53 @@ nsXULDocument::StartLayout(void)
if (! webShellContainer)
return NS_ERROR_UNEXPECTED;
PRBool intrinsic = PR_FALSE;
nsCOMPtr<nsIBrowserWindow> browser;
browser = do_QueryInterface(webShellContainer);
if (browser) {
browser->IsIntrinsicallySized(intrinsic);
}
else {
// XXX we're XUL embedded inside an iframe?
}
nsRect r;
cx->GetVisibleArea(r);
if (intrinsic) {
// Flow at an unconstrained width and height
r.width = NS_UNCONSTRAINEDSIZE;
r.height = NS_UNCONSTRAINEDSIZE;
}
// Trigger a refresh before the call to InitialReflow(), because
// the view manager's UpdateView() function is dropping dirty rects if
// refresh is disabled rather than accumulating them until refresh is
// enabled and then triggering a repaint...
if (browser) {
// We're top-level.
// See if we have attributes on our root tag that set the width and height.
// read "height" attribute// Convert r.width and r.height to twips.
float p2t;
cx->GetPixelsToTwips(&p2t);
nsCOMPtr<nsIDOMElement> windowElement = do_QueryInterface(mRootContent);
nsString sizeString;
PRInt32 specSize;
PRInt32 errorCode;
if (NS_SUCCEEDED(windowElement->GetAttribute("height", sizeString))) {
specSize = sizeString.ToInteger(&errorCode);
if (NS_SUCCEEDED(errorCode) && specSize > 0)
r.height = NSIntPixelsToTwips(specSize, p2t);
}
// read "width" attribute
if (NS_SUCCEEDED(windowElement->GetAttribute("width", sizeString))) {
specSize = sizeString.ToInteger(&errorCode);
if (NS_SUCCEEDED(errorCode) || specSize > 0)
r.width = NSIntPixelsToTwips(specSize, p2t);
}
}
cx->SetVisibleArea(r);
// XXX Copy of the code below. See XXX below for details...
// Now trigger a refresh
nsCOMPtr<nsIViewManager> vm;
shell->GetViewManager(getter_AddRefs(vm));
if (vm) {
@ -3473,6 +3511,53 @@ nsXULDocument::StartLayout(void)
shell->InitialReflow(r.width, r.height);
if (browser) {
// We're top level.
// Retrieve the answer.
cx->GetVisibleArea(r);
// Perform the resize
PRInt32 chromeX,chromeY,chromeWidth,chromeHeight;
nsCOMPtr<nsIBaseWindow> docShellWin(do_QueryInterface(webShell));
NS_ABORT_IF_FALSE(docShellWin, "QI Failed!!!!");
docShellWin->GetPositionAndSize(&chromeX, &chromeY, &chromeWidth,
&chromeHeight);
float t2p;
cx->GetTwipsToPixels(&t2p);
PRInt32 width = PRInt32((float)r.width*t2p);
PRInt32 height = PRInt32((float)r.height*t2p);
PRInt32 widthDelta = width - chromeWidth;
PRInt32 heightDelta = height - chromeHeight;
nsRect windowBounds;
browser->GetWindowBounds(windowBounds);
browser->SizeWindowTo(windowBounds.width + widthDelta,
windowBounds.height + heightDelta);
}
// XXX Moving this call up before the call to InitialReflow(), because
// the view manager's UpdateView() function is dropping dirty rects if
// refresh is disabled rather than accumulating them until refresh is
// enabled and then triggering a repaint...
#if 0
// Now trigger a refresh
nsCOMPtr<nsIViewManager> vm;
shell->GetViewManager(getter_AddRefs(vm));
if (vm) {
nsCOMPtr<nsIContentViewer> contentViewer;
nsresult rv = webShell->GetContentViewer(getter_AddRefs(contentViewer));
if (NS_SUCCEEDED(rv) && (contentViewer != nsnull)) {
PRBool enabled;
contentViewer->GetEnableRendering(&enabled);
if (enabled) {
vm->EnableRefresh();
}
}
}
#endif
// Start observing the document _after_ we do the initial
// reflow. Otherwise, we'll get into an trouble trying to
// create kids before the root frame is established.

View File

@ -329,6 +329,7 @@ public:
// nsIDOMNSDocument interface
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets);
NS_IMETHOD GetCharacterSet(nsString& aCharacterSet);
NS_IMETHOD CreateElementWithNameSpace(const nsString& aTagName, const nsString& aNameSpace, nsIDOMElement** aResult);
NS_IMETHOD CreateRange(nsIDOMRange** aRange);
NS_IMETHOD GetWidth(PRInt32* aWidth);

View File

@ -46,6 +46,8 @@ public:
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)=0;
NS_IMETHOD GetCharacterSet(nsString& aCharacterSet)=0;
NS_IMETHOD CreateElementWithNameSpace(const nsString& aTagName, const nsString& aNameSpace, nsIDOMElement** aReturn)=0;
NS_IMETHOD CreateRange(nsIDOMRange** aReturn)=0;
@ -56,6 +58,7 @@ public:
NS_IMETHOD GetWidth(PRInt32* aWidth); \
NS_IMETHOD GetHeight(PRInt32* aHeight); \
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets); \
NS_IMETHOD GetCharacterSet(nsString& aCharacterSet); \
NS_IMETHOD CreateElementWithNameSpace(const nsString& aTagName, const nsString& aNameSpace, nsIDOMElement** aReturn); \
NS_IMETHOD CreateRange(nsIDOMRange** aReturn); \
@ -65,6 +68,7 @@ public:
NS_IMETHOD GetWidth(PRInt32* aWidth) { return _to GetWidth(aWidth); } \
NS_IMETHOD GetHeight(PRInt32* aHeight) { return _to GetHeight(aHeight); } \
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets) { return _to GetStyleSheets(aStyleSheets); } \
NS_IMETHOD GetCharacterSet(nsString& aCharacterSet) { return _to GetCharacterSet(aCharacterSet); } \
NS_IMETHOD CreateElementWithNameSpace(const nsString& aTagName, const nsString& aNameSpace, nsIDOMElement** aReturn) { return _to CreateElementWithNameSpace(aTagName, aNameSpace, aReturn); } \
NS_IMETHOD CreateRange(nsIDOMRange** aReturn) { return _to CreateRange(aReturn); } \

View File

@ -29,6 +29,7 @@
readonly attribute long width;
readonly attribute long height;
readonly attribute StyleSheetCollection styleSheets;
readonly attribute DOMString characterSet;
Element createElementWithNameSpace(in DOMString tagName,
in DOMString nameSpace)
raises(DOMException); Range createRange();

View File

@ -672,6 +672,7 @@ enum nsDOMProp {
NS_DOM_PROP_NODELIST_LENGTH,
NS_DOM_PROP_NOTATION_PUBLICID,
NS_DOM_PROP_NOTATION_SYSTEMID,
NS_DOM_PROP_NSDOCUMENT_CHARACTERSET,
NS_DOM_PROP_NSDOCUMENT_CREATEELEMENTWITHNAMESPACE,
NS_DOM_PROP_NSDOCUMENT_CREATERANGE,
NS_DOM_PROP_NSDOCUMENT_HEIGHT,

View File

@ -671,6 +671,7 @@
"nodelist.length", \
"notation.publicid", \
"notation.systemid", \
"nsdocument.characterset", \
"nsdocument.createelementwithnamespace", \
"nsdocument.createrange", \
"nsdocument.height", \

View File

@ -79,7 +79,9 @@ enum Document_slots {
DOCUMENT_DOCUMENTELEMENT = -3,
NSDOCUMENT_WIDTH = -4,
NSDOCUMENT_HEIGHT = -5,
NSDOCUMENT_STYLESHEETS = -6
NSDOCUMENT_STYLESHEETS = -6,
NSDOCUMENT_CHARACTERSET = -7
};
/***********************************************************************/
@ -240,6 +242,32 @@ GetDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
}
break;
}
case NSDOCUMENT_CHARACTERSET:
{
PRBool ok = PR_FALSE;
secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_NSDOCUMENT_CHARACTERSET, PR_FALSE, &ok);
if (!ok) {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_SECURITY_ERR);
}
nsAutoString prop;
nsIDOMNSDocument* b;
if (NS_OK == a->QueryInterface(kINSDocumentIID, (void **)&b)) {
nsresult result = NS_OK;
result = b->GetCharacterSet(prop);
if(NS_SUCCEEDED(result)) {
nsJSUtils::nsConvertStringToJSVal(prop, cx, vp);
NS_RELEASE(b);
}
else {
NS_RELEASE(b);
return nsJSUtils::nsReportError(cx, obj, result);
}
}
else {
return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_WRONG_TYPE_ERR);
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, obj, id, vp);
}
@ -908,7 +936,8 @@ static JSPropertySpec DocumentProperties[] =
{"width", NSDOCUMENT_WIDTH, JSPROP_ENUMERATE | JSPROP_READONLY},
{"height", NSDOCUMENT_HEIGHT, JSPROP_ENUMERATE | JSPROP_READONLY},
{"styleSheets", NSDOCUMENT_STYLESHEETS, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
{"characterSet", NSDOCUMENT_CHARACTERSET, JSPROP_ENUMERATE | JSPROP_READONLY},
{0}
};

View File

@ -1909,6 +1909,12 @@ nsDocument::GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)
return NS_OK;
}
NS_IMETHODIMP
nsDocument::GetCharacterSet(nsString& aCharacterSet)
{
return GetDocumentCharacterSet(aCharacterSet);
}
NS_IMETHODIMP
nsDocument::CreateElementWithNameSpace(const nsString& aTagName,
const nsString& aNameSpace,

View File

@ -334,6 +334,7 @@ public:
NS_IMETHOD CreateEntityReference(const nsString& aName, nsIDOMEntityReference** aReturn);
NS_IMETHOD GetElementsByTagName(const nsString& aTagname, nsIDOMNodeList** aReturn);
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets);
NS_IMETHOD GetCharacterSet(nsString& aCharacterSet);
NS_IMETHOD CreateElementWithNameSpace(const nsString& aTagName,
const nsString& aNameSpace,
nsIDOMElement** aReturn);

View File

@ -695,15 +695,11 @@ nsXULDocument::StartDocumentLoad(const char* aCommand,
rv = PrepareStyleSheets(mDocumentURL);
if (NS_FAILED(rv)) return rv;
// Get the content type, if possible, to see if it's a cached XUL
// load. We explicitly ignore failure at this point, because
// certain hacks (cough, the directory viewer) need to be able to
// StartDocumentLoad() before the channel's content type has been
// detected.
nsXPIDLCString contentType;
(void) aChannel->GetContentType(getter_Copies(contentType));
rv = aChannel->GetContentType(getter_Copies(contentType));
if (NS_FAILED(rv)) return rv;
if (contentType && PL_strcmp(contentType, "text/cached-xul") == 0) {
if (PL_strcmp("text/cached-xul", (const char*) contentType) == 0) {
// Look in the chrome cache: we've got this puppy loaded
// already.
nsCOMPtr<nsIXULPrototypeDocument> proto;
@ -2496,6 +2492,11 @@ nsXULDocument::GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXULDocument::GetCharacterSet(nsString& aCharacterSet)
{
return GetDocumentCharacterSet(aCharacterSet);
}
NS_IMETHODIMP
nsXULDocument::CreateElementWithNameSpace(const nsString& aTagName,
@ -3447,16 +3448,53 @@ nsXULDocument::StartLayout(void)
if (! webShellContainer)
return NS_ERROR_UNEXPECTED;
PRBool intrinsic = PR_FALSE;
nsCOMPtr<nsIBrowserWindow> browser;
browser = do_QueryInterface(webShellContainer);
if (browser) {
browser->IsIntrinsicallySized(intrinsic);
}
else {
// XXX we're XUL embedded inside an iframe?
}
nsRect r;
cx->GetVisibleArea(r);
if (intrinsic) {
// Flow at an unconstrained width and height
r.width = NS_UNCONSTRAINEDSIZE;
r.height = NS_UNCONSTRAINEDSIZE;
}
// Trigger a refresh before the call to InitialReflow(), because
// the view manager's UpdateView() function is dropping dirty rects if
// refresh is disabled rather than accumulating them until refresh is
// enabled and then triggering a repaint...
if (browser) {
// We're top-level.
// See if we have attributes on our root tag that set the width and height.
// read "height" attribute// Convert r.width and r.height to twips.
float p2t;
cx->GetPixelsToTwips(&p2t);
nsCOMPtr<nsIDOMElement> windowElement = do_QueryInterface(mRootContent);
nsString sizeString;
PRInt32 specSize;
PRInt32 errorCode;
if (NS_SUCCEEDED(windowElement->GetAttribute("height", sizeString))) {
specSize = sizeString.ToInteger(&errorCode);
if (NS_SUCCEEDED(errorCode) && specSize > 0)
r.height = NSIntPixelsToTwips(specSize, p2t);
}
// read "width" attribute
if (NS_SUCCEEDED(windowElement->GetAttribute("width", sizeString))) {
specSize = sizeString.ToInteger(&errorCode);
if (NS_SUCCEEDED(errorCode) || specSize > 0)
r.width = NSIntPixelsToTwips(specSize, p2t);
}
}
cx->SetVisibleArea(r);
// XXX Copy of the code below. See XXX below for details...
// Now trigger a refresh
nsCOMPtr<nsIViewManager> vm;
shell->GetViewManager(getter_AddRefs(vm));
if (vm) {
@ -3473,6 +3511,53 @@ nsXULDocument::StartLayout(void)
shell->InitialReflow(r.width, r.height);
if (browser) {
// We're top level.
// Retrieve the answer.
cx->GetVisibleArea(r);
// Perform the resize
PRInt32 chromeX,chromeY,chromeWidth,chromeHeight;
nsCOMPtr<nsIBaseWindow> docShellWin(do_QueryInterface(webShell));
NS_ABORT_IF_FALSE(docShellWin, "QI Failed!!!!");
docShellWin->GetPositionAndSize(&chromeX, &chromeY, &chromeWidth,
&chromeHeight);
float t2p;
cx->GetTwipsToPixels(&t2p);
PRInt32 width = PRInt32((float)r.width*t2p);
PRInt32 height = PRInt32((float)r.height*t2p);
PRInt32 widthDelta = width - chromeWidth;
PRInt32 heightDelta = height - chromeHeight;
nsRect windowBounds;
browser->GetWindowBounds(windowBounds);
browser->SizeWindowTo(windowBounds.width + widthDelta,
windowBounds.height + heightDelta);
}
// XXX Moving this call up before the call to InitialReflow(), because
// the view manager's UpdateView() function is dropping dirty rects if
// refresh is disabled rather than accumulating them until refresh is
// enabled and then triggering a repaint...
#if 0
// Now trigger a refresh
nsCOMPtr<nsIViewManager> vm;
shell->GetViewManager(getter_AddRefs(vm));
if (vm) {
nsCOMPtr<nsIContentViewer> contentViewer;
nsresult rv = webShell->GetContentViewer(getter_AddRefs(contentViewer));
if (NS_SUCCEEDED(rv) && (contentViewer != nsnull)) {
PRBool enabled;
contentViewer->GetEnableRendering(&enabled);
if (enabled) {
vm->EnableRefresh();
}
}
}
#endif
// Start observing the document _after_ we do the initial
// reflow. Otherwise, we'll get into an trouble trying to
// create kids before the root frame is established.

View File

@ -329,6 +329,7 @@ public:
// nsIDOMNSDocument interface
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets);
NS_IMETHOD GetCharacterSet(nsString& aCharacterSet);
NS_IMETHOD CreateElementWithNameSpace(const nsString& aTagName, const nsString& aNameSpace, nsIDOMElement** aResult);
NS_IMETHOD CreateRange(nsIDOMRange** aRange);
NS_IMETHOD GetWidth(PRInt32* aWidth);