Fixing most of bug 62536. Adding support for the properties scrollTop, scrollLeft, scrollHeight, scrollWidth, clientHeight, clientWidth and the method scrollIntoView() to elements for compatibility with IE. Patch by Fabian <hidday@geocities.com> and myself, r=peterv@netscape.com, sr=jband@netscape.com

This commit is contained in:
jst%netscape.com 2001-10-17 01:17:47 +00:00
Родитель b59d40bdc8
Коммит 31a4b75f6d
5 изменённых файлов: 485 добавлений и 84 удалений

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

@ -70,6 +70,8 @@
#include "nsNetUtil.h"
#include "nsStyleConsts.h"
#include "nsIFrame.h"
#include "nsIScrollableFrame.h"
#include "nsIScrollableView.h"
#include "nsRange.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
@ -1186,6 +1188,293 @@ nsGenericHTMLElement::SetInnerHTML(const nsAReadableString& aInnerHTML)
return thisNode->AppendChild(df, getter_AddRefs(tmpNode));
}
nsresult
nsGenericHTMLElement::GetScrollInfo(nsIScrollableView **aScrollableView,
float *aP2T, float *aT2P)
{
*aScrollableView = nsnull;
*aP2T = 0.0f;
*aT2P = 0.0f;
// Get the the document
nsCOMPtr<nsIDocument> doc;
GetDocument(*getter_AddRefs(doc));
if (!doc) {
return NS_OK;
}
// Get the presentation shell
nsCOMPtr<nsIPresShell> presShell;
doc->GetShellAt(0, getter_AddRefs(presShell));
if (!presShell) {
return NS_OK;
}
// Get the primary frame for this element
nsIFrame *frame = nsnull;
presShell->GetPrimaryFrameFor(this, &frame);
if (!frame) {
return NS_OK;
}
// Get the presentation context
nsCOMPtr<nsIPresContext> presContext;
presShell->GetPresContext(getter_AddRefs(presContext));
if (!presContext) {
return NS_OK;
}
presContext->GetPixelsToTwips(aP2T);
presContext->GetTwipsToPixels(aT2P);
// Get the scrollable frame
nsIScrollableFrame *scrollFrame = nsnull;
CallQueryInterface(frame, &scrollFrame);
if (!scrollFrame) {
return NS_OK;
}
// Get the scrollable view
scrollFrame->GetScrollableView(presContext, aScrollableView);
return NS_OK;
}
nsresult
nsGenericHTMLElement::GetScrollTop(PRInt32* aScrollTop)
{
NS_ENSURE_ARG_POINTER(aScrollTop);
*aScrollTop = 0;
nsIScrollableView *view = nsnull;
nsresult rv = NS_OK;
float p2t, t2p;
GetScrollInfo(&view, &p2t, &t2p);
if (view) {
nscoord xPos, yPos;
rv = view->GetScrollPosition(xPos, yPos);
*aScrollTop = NSTwipsToIntPixels(yPos, t2p);
}
return rv;
}
nsresult
nsGenericHTMLElement::SetScrollTop(PRInt32 aScrollTop)
{
nsIScrollableView *view = nsnull;
nsresult rv = NS_OK;
float p2t, t2p;
GetScrollInfo(&view, &p2t, &t2p);
if (view) {
nscoord xPos, yPos;
rv = view->GetScrollPosition(xPos, yPos);
if (NS_SUCCEEDED(rv)) {
rv = view->ScrollTo(xPos, NSIntPixelsToTwips(aScrollTop, p2t),
NS_VMREFRESH_IMMEDIATE);
}
}
return rv;
}
nsresult
nsGenericHTMLElement::GetScrollLeft(PRInt32* aScrollLeft)
{
NS_ENSURE_ARG_POINTER(aScrollLeft);
*aScrollLeft = 0;
nsIScrollableView *view = nsnull;
nsresult rv = NS_OK;
float p2t, t2p;
GetScrollInfo(&view, &p2t, &t2p);
if (view) {
nscoord xPos, yPos;
rv = view->GetScrollPosition(xPos, yPos);
*aScrollLeft = NSTwipsToIntPixels(xPos, t2p);
}
return rv;
}
nsresult
nsGenericHTMLElement::SetScrollLeft(PRInt32 aScrollLeft)
{
nsIScrollableView *view = nsnull;
nsresult rv = NS_OK;
float p2t, t2p;
GetScrollInfo(&view, &p2t, &t2p);
if (view) {
nscoord xPos, yPos;
rv = view->GetScrollPosition(xPos, yPos);
if (NS_SUCCEEDED(rv)) {
rv = view->ScrollTo(NSIntPixelsToTwips(aScrollLeft, p2t),
yPos, NS_VMREFRESH_IMMEDIATE);
}
}
return rv;
}
nsresult
nsGenericHTMLElement::GetScrollHeight(PRInt32* aScrollHeight)
{
NS_ENSURE_ARG_POINTER(aScrollHeight);
*aScrollHeight = 0;
nsIScrollableView *scrollView = nsnull;
nsresult rv = NS_OK;
float p2t, t2p;
GetScrollInfo(&scrollView, &p2t, &t2p);
if (scrollView) {
// xMax and yMax is the total length of our container
nscoord xMax, yMax;
rv = scrollView->GetContainerSize(&xMax, &yMax);
const nsIView *view = nsnull;
nscoord xClip, yClip;
scrollView->GetClipView(&view);
view->GetDimensions(&xClip, &yClip);
*aScrollHeight = NSTwipsToIntPixels(yMax - yClip, t2p);
}
return rv;
}
nsresult
nsGenericHTMLElement::GetScrollWidth(PRInt32* aScrollWidth)
{
NS_ENSURE_ARG_POINTER(aScrollWidth);
*aScrollWidth = 0;
nsIScrollableView *scrollView = nsnull;
nsresult rv = NS_OK;
float p2t, t2p;
GetScrollInfo(&scrollView, &p2t, &t2p);
if (scrollView) {
nscoord xMax, yMax;
rv = scrollView->GetContainerSize(&xMax, &yMax);
const nsIView *view = nsnull;
nscoord xClip, yClip;
scrollView->GetClipView(&view);
view->GetDimensions(&xClip, &yClip);
*aScrollWidth = NSTwipsToIntPixels(xMax - xClip, t2p);
}
return rv;
}
nsresult
nsGenericHTMLElement::GetClientHeight(PRInt32* aClientHeight)
{
NS_ENSURE_ARG_POINTER(aClientHeight);
*aClientHeight = 0;
nsIScrollableView *scrollView = nsnull;
nsresult rv = NS_OK;
float p2t, t2p;
GetScrollInfo(&scrollView, &p2t, &t2p);
if (scrollView) {
const nsIView *view = nsnull;
nscoord xClip, yClip;
scrollView->GetClipView(&view);
view->GetDimensions(&xClip, &yClip);
*aClientHeight = NSTwipsToIntPixels(yClip, t2p);
}
return rv;
}
nsresult
nsGenericHTMLElement::GetClientWidth(PRInt32* aClientWidth)
{
NS_ENSURE_ARG_POINTER(aClientWidth);
*aClientWidth = 0;
nsIScrollableView *scrollView = nsnull;
nsresult rv = NS_OK;
float p2t, t2p;
GetScrollInfo(&scrollView, &p2t, &t2p);
if (scrollView) {
const nsIView *view = nsnull;
nscoord xClip, yClip;
scrollView->GetClipView(&view);
view->GetDimensions(&xClip, &yClip);
*aClientWidth = NSTwipsToIntPixels(xClip, t2p);
}
return rv;
}
nsresult
nsGenericHTMLElement::ScrollIntoView(PRBool aTop)
{
// Get the the document
nsCOMPtr<nsIDocument> doc;
GetDocument(*getter_AddRefs(doc));
if (!doc) {
return NS_OK;
}
// Get the presentation shell
nsCOMPtr<nsIPresShell> presShell;
doc->GetShellAt(0, getter_AddRefs(presShell));
if (!presShell) {
return NS_OK;
}
// Get the primary frame for this element
nsIFrame *frame = nsnull;
presShell->GetPrimaryFrameFor(this, &frame);
if (!frame) {
return NS_OK;
}
PRIntn vpercent = aTop ? NS_PRESSHELL_SCROLL_TOP :
NS_PRESSHELL_SCROLL_ANYWHERE;
presShell->ScrollFrameIntoView(frame, vpercent,
NS_PRESSHELL_SCROLL_ANYWHERE);
return NS_OK;
}
static nsIHTMLStyleSheet* GetAttrStyleSheet(nsIDocument* aDocument)
{
nsIHTMLStyleSheet* sheet = nsnull;

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

@ -66,6 +66,7 @@ class nsIURI;
class nsIFormControlFrame;
class nsIForm;
class nsIPresState;
class nsIScrollableView;
struct nsRect;
extern void GetGenericHTMLElementIIDs(nsVoidArray& aArray);
@ -104,27 +105,39 @@ public:
nsIDOMNodeList** aReturn);
// Implementation for nsIDOMHTMLElement
NS_METHOD GetId(nsAWritableString& aId);
NS_METHOD SetId(const nsAReadableString& aId);
NS_METHOD GetTitle(nsAWritableString& aTitle);
NS_METHOD SetTitle(const nsAReadableString& aTitle);
NS_METHOD GetLang(nsAWritableString& aLang);
NS_METHOD SetLang(const nsAReadableString& aLang);
NS_METHOD GetDir(nsAWritableString& aDir);
NS_METHOD SetDir(const nsAReadableString& aDir);
NS_METHOD GetClassName(nsAWritableString& aClassName);
NS_METHOD SetClassName(const nsAReadableString& aClassName);
NS_METHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle);
NS_METHOD GetOffsetTop(PRInt32* aOffsetTop);
NS_METHOD GetOffsetLeft(PRInt32* aOffsetLeft);
NS_METHOD GetOffsetWidth(PRInt32* aOffsetWidth);
NS_METHOD GetOffsetHeight(PRInt32* aOffsetHeight);
NS_METHOD GetOffsetParent(nsIDOMElement** aOffsetParent);
NS_METHOD GetInnerHTML(nsAWritableString& aInnerHTML);
NS_METHOD SetInnerHTML(const nsAReadableString& aInnerHTML);
NS_METHOD GetOffsetRect(nsRect& aRect,
nsresult GetId(nsAWritableString& aId);
nsresult SetId(const nsAReadableString& aId);
nsresult GetTitle(nsAWritableString& aTitle);
nsresult SetTitle(const nsAReadableString& aTitle);
nsresult GetLang(nsAWritableString& aLang);
nsresult SetLang(const nsAReadableString& aLang);
nsresult GetDir(nsAWritableString& aDir);
nsresult SetDir(const nsAReadableString& aDir);
nsresult GetClassName(nsAWritableString& aClassName);
nsresult SetClassName(const nsAReadableString& aClassName);
nsresult GetStyle(nsIDOMCSSStyleDeclaration** aStyle);
nsresult GetOffsetTop(PRInt32* aOffsetTop);
nsresult GetOffsetLeft(PRInt32* aOffsetLeft);
nsresult GetOffsetWidth(PRInt32* aOffsetWidth);
nsresult GetOffsetHeight(PRInt32* aOffsetHeight);
nsresult GetOffsetParent(nsIDOMElement** aOffsetParent);
nsresult GetInnerHTML(nsAWritableString& aInnerHTML);
nsresult SetInnerHTML(const nsAReadableString& aInnerHTML);
nsresult GetScrollTop(PRInt32* aScrollTop);
nsresult SetScrollTop(PRInt32 aScrollTop);
nsresult GetScrollLeft(PRInt32* aScrollLeft);
nsresult SetScrollLeft(PRInt32 aScrollLeft);
nsresult GetScrollHeight(PRInt32* aScrollHeight);
nsresult GetScrollWidth(PRInt32* aScrollWidth);
nsresult GetClientHeight(PRInt32* aClientHeight);
nsresult GetClientWidth(PRInt32* aClientWidth);
nsresult ScrollIntoView(PRBool aTop);
nsresult GetOffsetRect(nsRect& aRect,
nsIAtom* aOffsetParentTag,
nsIContent** aOffsetParent);
nsresult GetScrollInfo(nsIScrollableView **aScrollableView, float *aP2T,
float *aT2P);
// Implementation for nsIContent
NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep,

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

@ -48,4 +48,16 @@ interface nsIDOMNSHTMLElement : nsISupports
readonly attribute long offsetHeight;
readonly attribute nsIDOMElement offsetParent;
attribute DOMString innerHTML;
attribute long scrollTop;
attribute long scrollLeft;
readonly attribute long scrollHeight;
readonly attribute long scrollWidth;
readonly attribute long clientHeight;
readonly attribute long clientWidth;
// |top| is optional in JS, scriptability of this method is done in
// nsHTMLElementSH
[noscript] void scrollIntoView(in boolean top);
};

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

@ -455,127 +455,127 @@ static nsDOMClassInfoData sClassInfoData[] = {
ARRAY_SCRIPTABLE_FLAGS)
// HTML element classes
NS_DEFINE_CLASSINFO_DATA(HTMLAnchorElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLAnchorElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLAppletElement, nsHTMLAppletElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLAreaElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLAreaElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLBRElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLBRElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLBaseElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLBaseElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLBaseFontElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLBaseFontElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLBodyElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLBodyElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLButtonElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLButtonElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLDListElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLDListElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLDelElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLDelElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLDirectoryElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLDirectoryElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLDivElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLDivElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLEmbedElement, nsHTMLPluginObjElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLFieldSetElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLFieldSetElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLFontElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLFontElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLFormElement, nsHTMLFormElementSH,
ELEMENT_SCRIPTABLE_FLAGS |
nsIXPCScriptable::WANT_GETPROPERTY)
NS_DEFINE_CLASSINFO_DATA(HTMLFrameElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLFrameElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLFrameSetElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLFrameSetElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLHRElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLHRElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLHeadElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLHeadElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLHeadingElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLHeadingElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLHtmlElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLHtmlElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLIFrameElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLIFrameElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLImageElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLImageElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLInputElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLInputElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLInsElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLInsElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLIsIndexElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLIsIndexElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLLIElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLLIElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLLabelElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLLabelElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLLegendElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLLegendElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLLinkElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLLinkElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLMapElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLMapElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLMenuElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLMenuElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLMetaElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLMetaElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLModElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLModElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLOListElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLOListElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLObjectElement, nsHTMLPluginObjElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLOptGroupElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLOptGroupElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLOptionElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLOptionElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLParagraphElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLParagraphElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLParamElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLParamElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLPreElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLPreElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLQuoteElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLQuoteElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLScriptElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLScriptElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLSelectElement, nsHTMLSelectElementSH,
ELEMENT_SCRIPTABLE_FLAGS |
nsIXPCScriptable::WANT_GETPROPERTY)
NS_DEFINE_CLASSINFO_DATA(HTMLSpacerElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLSpacerElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLSpanElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLSpanElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLStyleElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLStyleElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLTableCaptionElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLTableCaptionElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLTableCellElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLTableCellElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLTableColElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLTableColElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLTableColGroupElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLTableColGroupElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLTableElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLTableElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLTableRowElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLTableRowElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLTableSectionElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLTableSectionElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLTextAreaElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLTextAreaElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLTitleElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLTitleElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLUListElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLUListElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLUnknownElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLUnknownElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(HTMLWBRElement, nsElementSH,
NS_DEFINE_CLASSINFO_DATA(HTMLWBRElement, nsHTMLElementSH,
ELEMENT_SCRIPTABLE_FLAGS)
// CSS classes
@ -708,6 +708,7 @@ JSString *nsDOMClassInfo::sOnerror_id = nsnull;
JSString *nsDOMClassInfo::sOnpaint_id = nsnull;
JSString *nsDOMClassInfo::sOnresize_id = nsnull;
JSString *nsDOMClassInfo::sOnscroll_id = nsnull;
JSString *nsDOMClassInfo::sScrollIntoView_id = nsnull;
const JSClass *nsDOMClassInfo::sObjectClass = nsnull;
@ -754,6 +755,7 @@ nsDOMClassInfo::DefineStaticJSStrings(JSContext *cx)
sOnpaint_id = ::JS_InternString(cx, "onpaint");
sOnresize_id = ::JS_InternString(cx, "onresize");
sOnscroll_id = ::JS_InternString(cx, "onscroll");
sScrollIntoView_id = ::JS_InternString(cx, "scrollIntoView");
return NS_OK;
}
@ -2150,6 +2152,7 @@ nsDOMClassInfo::ShutDown()
sOnpaint_id = jsnullstring;
sOnresize_id = jsnullstring;
sOnscroll_id = jsnullstring;
sScrollIntoView_id = jsnullstring;
NS_IF_RELEASE(sXPConnect);
NS_IF_RELEASE(sSecMan);
@ -2627,7 +2630,7 @@ DefineInterfaceConstants(JSContext *cx, JSObject *obj, const nsIID *aIID)
return NS_OK;
}
JSBool JS_DLL_CALLBACK
static JSBool JS_DLL_CALLBACK
NativeConstructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv,
jsval *rval)
{
@ -3763,6 +3766,59 @@ nsHTMLDocumentSH::GetProperty(nsIXPConnectWrappedNative *wrapper,
}
// HTMLElement helper
// static
JSBool
nsHTMLElementSH::ScrollIntoView(JSContext *cx, JSObject *obj, uintN argc,
jsval *argv, jsval *rval)
{
nsCOMPtr<nsIXPConnectWrappedNative> wrapper;
nsresult rv =
sXPConnect->GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wrapper));
NS_ENSURE_SUCCESS(rv, JS_FALSE);
nsCOMPtr<nsISupports> native;
rv = wrapper->GetNative(getter_AddRefs(native));
NS_ENSURE_SUCCESS(rv, JS_FALSE);
nsCOMPtr<nsIDOMNSHTMLElement> element(do_QueryInterface(native));
NS_ENSURE_TRUE(element, JS_FALSE);
JSBool top = JS_TRUE;
if (argc > 0) {
::JS_ValueToBoolean(cx, argv[0], &top);
}
rv = element->ScrollIntoView(top);
*rval = JSVAL_VOID;
return NS_SUCCEEDED(rv);
}
NS_IMETHODIMP
nsHTMLElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsval id, PRUint32 flags,
JSObject **objp, PRBool *_retval)
{
if ((!(JSRESOLVE_ASSIGNING & flags)) &&
id == STRING_TO_JSVAL(sScrollIntoView_id)) {
JSFunction *cfnc =
::JS_DefineFunction(cx, obj, ::JS_GetStringBytes(sScrollIntoView_id),
ScrollIntoView, 0, 0);
*objp = obj;
return cfnc ? NS_OK : NS_ERROR_UNEXPECTED;
}
return nsElementSH::NewResolve(wrapper, cx, obj, id, flags, objp, _retval);
}
// HTMLFormElement helper
// static
@ -3825,7 +3881,8 @@ nsHTMLFormElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper,
}
}
return nsElementSH::NewResolve(wrapper, cx, obj, id, flags, objp, _retval);
return nsHTMLElementSH::NewResolve(wrapper, cx, obj, id, flags, objp,
_retval);
}
@ -4373,7 +4430,8 @@ nsHTMLPluginObjElementSH::NewResolve(nsIXPConnectWrappedNative *wrapper,
}
}
return nsElementSH::NewResolve(wrapper, cx, obj, id, flags, objp, _retval);
return nsHTMLElementSH::NewResolve(wrapper, cx, obj, id, flags, objp,
_retval);
}

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

@ -146,6 +146,7 @@ protected:
static JSString *sOnpaint_id;
static JSString *sOnresize_id;
static JSString *sOnscroll_id;
static JSString *sScrollIntoView_id;
static const JSClass *sObjectClass;
};
@ -486,12 +487,40 @@ public:
};
// HTMLFormElement helper
// HTMLElement helper
class nsHTMLFormElementSH : public nsElementSH
class nsHTMLElementSH : public nsElementSH
{
protected:
nsHTMLFormElementSH(nsDOMClassInfoID aID) : nsElementSH(aID)
nsHTMLElementSH(nsDOMClassInfoID aID) : nsElementSH(aID)
{
}
virtual ~nsHTMLElementSH()
{
}
static JSBool ScrollIntoView(JSContext *cx, JSObject *obj, uintN argc,
jsval *argv, jsval *rval);
public:
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
JSObject *obj, jsval id, PRUint32 flags,
JSObject **objp, PRBool *_retval);
static nsIClassInfo *doCreate(nsDOMClassInfoID aID)
{
return new nsHTMLElementSH(aID);
}
};
// HTMLFormElement helper
class nsHTMLFormElementSH : public nsHTMLElementSH
{
protected:
nsHTMLFormElementSH(nsDOMClassInfoID aID) : nsHTMLElementSH(aID)
{
}
@ -519,10 +548,10 @@ public:
// HTMLSelectElement helper
class nsHTMLSelectElementSH : public nsElementSH
class nsHTMLSelectElementSH : public nsHTMLElementSH
{
protected:
nsHTMLSelectElementSH(nsDOMClassInfoID aID) : nsElementSH(aID)
nsHTMLSelectElementSH(nsDOMClassInfoID aID) : nsHTMLElementSH(aID)
{
}
@ -550,10 +579,10 @@ public:
// Base helper for external HTML object (such as a plugin or an
// applet)
class nsHTMLExternalObjSH : public nsElementSH
class nsHTMLExternalObjSH : public nsHTMLElementSH
{
protected:
nsHTMLExternalObjSH(nsDOMClassInfoID aID) : nsElementSH(aID)
nsHTMLExternalObjSH(nsDOMClassInfoID aID) : nsHTMLElementSH(aID)
{
}