mshtml: Implement IHTMLRect2 for HTMLRect.

This commit is contained in:
Evan Tang 2023-01-18 16:14:19 -06:00 committed by Alexandre Julliard
parent 8870d51d3e
commit 8b0868c176
6 changed files with 151 additions and 1 deletions

View file

@ -529,6 +529,7 @@ HRESULT create_element(HTMLDocumentNode *doc, const WCHAR *tag, HTMLElement **re
typedef struct {
DispatchEx dispex;
IHTMLRect IHTMLRect_iface;
IHTMLRect2 IHTMLRect2_iface;
LONG ref;
@ -550,6 +551,8 @@ static HRESULT WINAPI HTMLRect_QueryInterface(IHTMLRect *iface, REFIID riid, voi
*ppv = &This->IHTMLRect_iface;
}else if(IsEqualGUID(&IID_IHTMLRect, riid)) {
*ppv = &This->IHTMLRect_iface;
}else if (IsEqualGUID(&IID_IHTMLRect2, riid)) {
*ppv = &This->IHTMLRect2_iface;
}else if(dispex_query_interface(&This->dispex, riid, ppv)) {
return *ppv ? S_OK : E_NOINTERFACE;
}else {
@ -723,6 +726,91 @@ static HRESULT WINAPI HTMLRect_get_bottom(IHTMLRect *iface, LONG *p)
return S_OK;
}
static inline HTMLRect *impl_from_IHTMLRect2(IHTMLRect2 *iface)
{
return CONTAINING_RECORD(iface, HTMLRect, IHTMLRect2_iface);
}
static HRESULT WINAPI HTMLRect2_QueryInterface(IHTMLRect2 *iface, REFIID riid, void **ppv)
{
HTMLRect *This = impl_from_IHTMLRect2(iface);
return IHTMLRect_QueryInterface(&This->IHTMLRect_iface, riid, ppv);
}
static ULONG WINAPI HTMLRect2_AddRef(IHTMLRect2 *iface)
{
HTMLRect *This = impl_from_IHTMLRect2(iface);
return IHTMLRect_AddRef(&This->IHTMLRect_iface);
}
static ULONG WINAPI HTMLRect2_Release(IHTMLRect2 *iface)
{
HTMLRect *This = impl_from_IHTMLRect2(iface);
return IHTMLRect_Release(&This->IHTMLRect_iface);
}
static HRESULT WINAPI HTMLRect2_GetTypeInfoCount(IHTMLRect2 *iface, UINT *pctinfo)
{
HTMLRect *This = impl_from_IHTMLRect2(iface);
return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
}
static HRESULT WINAPI HTMLRect2_GetTypeInfo(IHTMLRect2 *iface, UINT iTInfo,
LCID lcid, ITypeInfo **ppTInfo)
{
HTMLRect *This = impl_from_IHTMLRect2(iface);
return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
}
static HRESULT WINAPI HTMLRect2_GetIDsOfNames(IHTMLRect2 *iface, REFIID riid,
LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
HTMLRect *This = impl_from_IHTMLRect2(iface);
return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
lcid, rgDispId);
}
static HRESULT WINAPI HTMLRect2_Invoke(IHTMLRect2 *iface, DISPID dispIdMember,
REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
HTMLRect *This = impl_from_IHTMLRect2(iface);
return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
pDispParams, pVarResult, pExcepInfo, puArgErr);
}
static HRESULT WINAPI HTMLRect2_get_width(IHTMLRect2 *iface, FLOAT *p)
{
HTMLRect *This = impl_from_IHTMLRect2(iface);
nsresult nsres;
TRACE("(%p)->(%p)\n", This, p);
nsres = nsIDOMClientRect_GetWidth(This->nsrect, p);
if (NS_FAILED(nsres)) {
ERR("GetWidth failed: %08lx\n", nsres);
return E_FAIL;
}
return S_OK;
}
static HRESULT WINAPI HTMLRect2_get_height(IHTMLRect2 *iface, FLOAT *p)
{
HTMLRect *This = impl_from_IHTMLRect2(iface);
nsresult nsres;
TRACE("(%p)->(%p)\n", This, p);
nsres = nsIDOMClientRect_GetHeight(This->nsrect, p);
if (NS_FAILED(nsres)) {
ERR("GetHeight failed: %08lx\n", nsres);
return E_FAIL;
}
return S_OK;
}
static const IHTMLRectVtbl HTMLRectVtbl = {
HTMLRect_QueryInterface,
HTMLRect_AddRef,
@ -741,6 +829,24 @@ static const IHTMLRectVtbl HTMLRectVtbl = {
HTMLRect_get_bottom
};
static const IHTMLRect2Vtbl HTMLRect2Vtbl = {
HTMLRect2_QueryInterface,
HTMLRect2_AddRef,
HTMLRect2_Release,
HTMLRect2_GetTypeInfoCount,
HTMLRect2_GetTypeInfo,
HTMLRect2_GetIDsOfNames,
HTMLRect2_Invoke,
HTMLRect2_get_width,
HTMLRect2_get_height,
};
void HTMLRect_init_dispex_info(dispex_data_t *info, compat_mode_t mode)
{
if (mode >= COMPAT_MODE_IE9)
dispex_info_add_interface(info, IHTMLRect2_tid, NULL);
}
static const tid_t HTMLRect_iface_tids[] = {
IHTMLRect_tid,
0
@ -749,7 +855,8 @@ static dispex_static_data_t HTMLRect_dispex = {
L"ClientRect",
NULL,
IHTMLRect_tid,
HTMLRect_iface_tids
HTMLRect_iface_tids,
HTMLRect_init_dispex_info
};
static HRESULT create_html_rect(nsIDOMClientRect *nsrect, compat_mode_t compat_mode, IHTMLRect **ret)
@ -761,6 +868,7 @@ static HRESULT create_html_rect(nsIDOMClientRect *nsrect, compat_mode_t compat_m
return E_OUTOFMEMORY;
rect->IHTMLRect_iface.lpVtbl = &HTMLRectVtbl;
rect->IHTMLRect2_iface.lpVtbl = &HTMLRect2Vtbl;
rect->ref = 1;
init_dispatch(&rect->dispex, (IUnknown*)&rect->IHTMLRect_iface, &HTMLRect_dispex, compat_mode);

View file

@ -237,6 +237,7 @@ typedef struct EventTarget EventTarget;
XIID(IHTMLPerformanceTiming) \
XIID(IHTMLPluginsCollection) \
XIID(IHTMLRect) \
XIID(IHTMLRect2) \
XIID(IHTMLRectCollection) \
XIID(IHTMLScreen) \
XIID(IHTMLScriptElement) \

View file

@ -557,6 +557,23 @@ sync_test("stylesheet_props", function() {
test_exposed("rules", true);
});
sync_test("rect_props", function() {
document.body.innerHTML = '<div>test</div>';
var elem = document.body.firstChild;
var rect = elem.getBoundingClientRect();
function test_exposed(prop, expect) {
if(expect)
ok(prop in rect, prop + " not found in rect object.");
else
ok(!(prop in rect), prop + " found in rect object.");
}
var v = document.documentMode;
test_exposed("width", v >= 9);
test_exposed("height", v >= 9);
});
sync_test("xhr open", function() {
var e = false;
try {

View file

@ -293,6 +293,8 @@ sync_test("rects", function() {
ok(rects.length === 1, "rect.length = " + rects.length);
ok(rects[0].top === rect.top, "rects[0].top = " + rects[0].top + " rect.top = " + rect.top);
ok(rects[0].bottom === rect.bottom, "rects[0].bottom = " + rects[0].bottom + " rect.bottom = " + rect.bottom);
ok(rect.height === rect.bottom - rect.top, "rect.height = " + rect.height + " rect.bottom = " + rect.bottom + " rect.top = " + rect.top);
ok(rect.width === rect.right - rect.left, "rect.width = " + rect.width + " rect.right = " + rect.right + " rect.left = " + rect.left);
elem = document.createElement("style");
rects = elem.getClientRects();

View file

@ -4135,6 +4135,10 @@
#define DISPID_IHTMLRECT_RIGHT DISPID_OMRECT+3
#define DISPID_IHTMLRECT_BOTTOM DISPID_OMRECT+4
/* IHTMLRect2 */
#define DISPID_IHTMLRECT2_WIDTH DISPID_OMRECT+5
#define DISPID_IHTMLRECT2_HEIGHT DISPID_OMRECT+6
/* IHTMLRectCollection */
#define DISPID_IHTMLRECTCOLLECTION_LENGTH DISPID_COLLECTION
#define DISPID_IHTMLRECTCOLLECTION__NEWENUM DISPID_NEWENUM

View file

@ -7937,6 +7937,24 @@ interface IHTMLRect : IDispatch
HRESULT bottom([retval, out] LONG *p);
}
/*****************************************************************************
* IHTMLRect2 interface
*/
[
odl,
oleautomation,
dual,
uuid(3051076c-98b5-11cf-bb82-00aa00bdce0b)
]
interface IHTMLRect2 : IDispatch
{
[propget, id(DISPID_IHTMLRECT2_WIDTH)]
HRESULT width([retval, out] FLOAT *p);
[propget, id(DISPID_IHTMLRECT2_HEIGHT)]
HRESULT height([retval, out] FLOAT *p);
}
/*****************************************************************************
* IHTMLRectCollection interface
*/