Commit b918a532 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

mshtml: Implement window.matchMedia() with MediaQueryList stub.

parent 7e2beeec
......@@ -3166,6 +3166,15 @@ static HRESULT WINAPI window_private_cancelAnimationFrame(IWineHTMLWindowPrivate
return S_OK;
}
static HRESULT WINAPI window_private_matchMedia(IWineHTMLWindowPrivate *iface, BSTR media_query, IDispatch **media_query_list)
{
HTMLWindow *This = impl_from_IWineHTMLWindowPrivateVtbl(iface);
TRACE("iface %p, media_query %s\n", iface, debugstr_w(media_query));
return create_media_query_list(This, media_query, media_query_list);
}
static HRESULT WINAPI window_private_get_console(IWineHTMLWindowPrivate *iface, IDispatch **console)
{
HTMLWindow *This = impl_from_IWineHTMLWindowPrivateVtbl(iface);
......@@ -3192,6 +3201,7 @@ static const IWineHTMLWindowPrivateVtbl WineHTMLWindowPrivateVtbl = {
window_private_requestAnimationFrame,
window_private_cancelAnimationFrame,
window_private_get_console,
window_private_matchMedia,
};
static inline HTMLWindow *impl_from_IWineHTMLWindowCompatPrivateVtbl(IWineHTMLWindowCompatPrivate *iface)
......
......@@ -285,7 +285,8 @@ typedef struct EventTarget EventTarget;
XIID(IWineHTMLWindowPrivate) \
XIID(IWineHTMLWindowCompatPrivate) \
XIID(IWineXMLHttpRequestPrivate) \
XIID(IWineMSHTMLConsole)
XIID(IWineMSHTMLConsole) \
XIID(IWineMSHTMLMediaQueryList)
typedef enum {
#define XIID(iface) iface ## _tid,
......@@ -1432,3 +1433,4 @@ IInternetSecurityManager *get_security_manager(void) DECLSPEC_HIDDEN;
extern HINSTANCE hInst DECLSPEC_HIDDEN;
void create_console(compat_mode_t compat_mode, IWineMSHTMLConsole **ret) DECLSPEC_HIDDEN;
HRESULT create_media_query_list(HTMLWindow *window, BSTR media_query, IDispatch **ret) DECLSPEC_HIDDEN;
......@@ -81,6 +81,25 @@ interface IWineMSHTMLConsole : IDispatch
oleautomation,
dual,
hidden,
uuid(fd55b4b6-2813-4fb4-829d-380099474ab0)
]
interface IWineMSHTMLMediaQueryList : IDispatch
{
[propget, id(1)]
HRESULT media([retval, out] BSTR *p);
[propget, id(2)]
HRESULT matches([retval, out] VARIANT_BOOL *p);
[id(3)]
HRESULT addListener([in] VARIANT *listener);
[id(4)]
HRESULT removeListener([in] VARIANT *listener);
}
[
odl,
oleautomation,
dual,
hidden,
uuid(1b5939fc-8f84-43f3-8d89-f9a92069fad7)
]
interface IWineHTMLWindowPrivate : IDispatch
......@@ -91,6 +110,8 @@ interface IWineHTMLWindowPrivate : IDispatch
HRESULT cancelAnimationFrame([in] VARIANT timer_id);
[propget, id(52)]
HRESULT console([retval, out] IDispatch **console);
[id(53)]
HRESULT matchMedia([in] BSTR media_query, [retval, out] IDispatch **media_query_list);
}
[
......
......@@ -902,6 +902,17 @@ interface nsIDOMStyleSheetList : nsISupports
[
object,
uuid(e0e49c52-915b-40f9-9cba-6026305cdf3e),
local
]
interface nsIDOMMediaQueryList : nsISupports
{
nsresult GetMedia(nsAString *aMedia);
nsresult GetMatches(bool *_retval);
}
[
object,
uuid(450cf0ba-de90-4f86-85bf-e10cc8b8713f),
local
]
......
......@@ -2645,3 +2645,190 @@ void create_console(compat_mode_t compat_mode, IWineMSHTMLConsole **ret)
*ret = &obj->IWineMSHTMLConsole_iface;
}
struct media_query_list {
DispatchEx dispex;
IWineMSHTMLMediaQueryList IWineMSHTMLMediaQueryList_iface;
LONG ref;
nsIDOMMediaQueryList *nsquerylist;
};
static inline struct media_query_list *impl_from_IWineMSHTMLMediaQueryList(IWineMSHTMLMediaQueryList *iface)
{
return CONTAINING_RECORD(iface, struct media_query_list, IWineMSHTMLMediaQueryList_iface);
}
static HRESULT WINAPI media_query_list_QueryInterface(IWineMSHTMLMediaQueryList *iface, REFIID riid, void **ppv)
{
struct media_query_list *media_query_list = impl_from_IWineMSHTMLMediaQueryList(iface);
TRACE("(%p)->(%s %p)\n", media_query_list, debugstr_mshtml_guid(riid), ppv);
if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IWineMSHTMLMediaQueryList, riid)) {
*ppv = &media_query_list->IWineMSHTMLMediaQueryList_iface;
}else if(dispex_query_interface(&media_query_list->dispex, riid, ppv)) {
return *ppv ? S_OK : E_NOINTERFACE;
}else {
*ppv = NULL;
return E_NOINTERFACE;
}
IUnknown_AddRef((IUnknown*)*ppv);
return S_OK;
}
static ULONG WINAPI media_query_list_AddRef(IWineMSHTMLMediaQueryList *iface)
{
struct media_query_list *media_query_list = impl_from_IWineMSHTMLMediaQueryList(iface);
LONG ref = InterlockedIncrement(&media_query_list->ref);
TRACE("(%p) ref=%ld\n", media_query_list, ref);
return ref;
}
static ULONG WINAPI media_query_list_Release(IWineMSHTMLMediaQueryList *iface)
{
struct media_query_list *media_query_list = impl_from_IWineMSHTMLMediaQueryList(iface);
LONG ref = InterlockedDecrement(&media_query_list->ref);
TRACE("(%p) ref=%ld\n", media_query_list, ref);
if(!ref) {
nsIDOMMediaQueryList_Release(media_query_list->nsquerylist);
release_dispex(&media_query_list->dispex);
heap_free(media_query_list);
}
return ref;
}
static HRESULT WINAPI media_query_list_GetTypeInfoCount(IWineMSHTMLMediaQueryList *iface, UINT *pctinfo)
{
struct media_query_list *media_query_list = impl_from_IWineMSHTMLMediaQueryList(iface);
TRACE("(%p)->(%p)\n", media_query_list, pctinfo);
return IDispatchEx_GetTypeInfoCount(&media_query_list->dispex.IDispatchEx_iface, pctinfo);
}
static HRESULT WINAPI media_query_list_GetTypeInfo(IWineMSHTMLMediaQueryList *iface, UINT iTInfo,
LCID lcid, ITypeInfo **ppTInfo)
{
struct media_query_list *media_query_list = impl_from_IWineMSHTMLMediaQueryList(iface);
return IDispatchEx_GetTypeInfo(&media_query_list->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
}
static HRESULT WINAPI media_query_list_GetIDsOfNames(IWineMSHTMLMediaQueryList *iface, REFIID riid,
LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
{
struct media_query_list *media_query_list = impl_from_IWineMSHTMLMediaQueryList(iface);
return IDispatchEx_GetIDsOfNames(&media_query_list->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
lcid, rgDispId);
}
static HRESULT WINAPI media_query_list_Invoke(IWineMSHTMLMediaQueryList *iface, DISPID dispIdMember,
REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
struct media_query_list *media_query_list = impl_from_IWineMSHTMLMediaQueryList(iface);
return IDispatchEx_Invoke(&media_query_list->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
pDispParams, pVarResult, pExcepInfo, puArgErr);
}
static HRESULT WINAPI media_query_list_get_media(IWineMSHTMLMediaQueryList *iface, BSTR *p)
{
struct media_query_list *media_query_list = impl_from_IWineMSHTMLMediaQueryList(iface);
FIXME("(%p)->(%p)\n", media_query_list, p);
return E_NOTIMPL;
}
static HRESULT WINAPI media_query_list_get_matches(IWineMSHTMLMediaQueryList *iface, VARIANT_BOOL *p)
{
struct media_query_list *media_query_list = impl_from_IWineMSHTMLMediaQueryList(iface);
FIXME("(%p)->(%p)\n", media_query_list, p);
return E_NOTIMPL;
}
static HRESULT WINAPI media_query_list_addListener(IWineMSHTMLMediaQueryList *iface, VARIANT *listener)
{
struct media_query_list *media_query_list = impl_from_IWineMSHTMLMediaQueryList(iface);
FIXME("(%p)->(%s)", media_query_list, debugstr_variant(listener));
return E_NOTIMPL;
}
static HRESULT WINAPI media_query_list_removeListener(IWineMSHTMLMediaQueryList *iface, VARIANT *listener)
{
struct media_query_list *media_query_list = impl_from_IWineMSHTMLMediaQueryList(iface);
FIXME("(%p)->(%s)", media_query_list, debugstr_variant(listener));
return E_NOTIMPL;
}
static const IWineMSHTMLMediaQueryListVtbl media_query_list_vtbl = {
media_query_list_QueryInterface,
media_query_list_AddRef,
media_query_list_Release,
media_query_list_GetTypeInfoCount,
media_query_list_GetTypeInfo,
media_query_list_GetIDsOfNames,
media_query_list_Invoke,
media_query_list_get_media,
media_query_list_get_matches,
media_query_list_addListener,
media_query_list_removeListener
};
static const tid_t media_query_list_iface_tids[] = {
IWineMSHTMLMediaQueryList_tid,
0
};
static dispex_static_data_t media_query_list_dispex = {
L"MediaQueryList",
NULL,
IWineMSHTMLMediaQueryList_tid,
media_query_list_iface_tids
};
HRESULT create_media_query_list(HTMLWindow *window, BSTR media_query, IDispatch **ret)
{
struct media_query_list *media_query_list;
nsISupports *nsunk;
nsAString nsstr;
nsresult nsres;
if(!media_query || !media_query[0])
return E_INVALIDARG;
if(!(media_query_list = heap_alloc(sizeof(*media_query_list))))
return E_OUTOFMEMORY;
nsAString_InitDepend(&nsstr, media_query);
nsres = nsIDOMWindow_MatchMedia(window->outer_window->nswindow, &nsstr, &nsunk);
nsAString_Finish(&nsstr);
if(NS_FAILED(nsres)) {
heap_free(media_query_list);
return map_nsresult(nsres);
}
nsres = nsISupports_QueryInterface(nsunk, &IID_nsIDOMMediaQueryList, (void**)&media_query_list->nsquerylist);
assert(NS_SUCCEEDED(nsres));
nsISupports_Release(nsunk);
media_query_list->IWineMSHTMLMediaQueryList_iface.lpVtbl = &media_query_list_vtbl;
media_query_list->ref = 1;
init_dispatch(&media_query_list->dispex, (IUnknown*)&media_query_list->IWineMSHTMLMediaQueryList_iface,
&media_query_list_dispex, dispex_compat_mode(&window->inner_window->event_target.dispex));
*ret = (IDispatch*)&media_query_list->IWineMSHTMLMediaQueryList_iface;
return S_OK;
}
......@@ -253,6 +253,7 @@ sync_test("builtin_toString", function() {
if(v >= 10) {
test("classList", e.classList, "DOMTokenList", "testclass another ");
test("console", window.console, "Console");
test("mediaQueryList", window.matchMedia("(hover:hover)"), "MediaQueryList");
}
if(v >= 9) {
document.body.innerHTML = "<!--...-->";
......@@ -364,6 +365,7 @@ sync_test("window_props", function() {
test_exposed("Set", v >= 11);
test_exposed("performance", true);
test_exposed("console", v >= 10);
test_exposed("matchMedia", v >= 10);
});
sync_test("domimpl_props", function() {
......
......@@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
var E_INVALIDARG = 0x80070057;
var JS_E_PROP_DESC_MISMATCH = 0x800a01bd;
var JS_E_NUMBER_EXPECTED = 0x800a1389;
var JS_E_FUNCTION_EXPECTED = 0x800a138a;
......@@ -2016,3 +2017,14 @@ sync_test("console", function() {
}
ok(except, "console.timeLog: expected exception");
});
sync_test("matchMedia", function() {
var mql;
try {
mql = window.matchMedia("");
}catch(ex) {
var n = ex.number >>> 0;
ok(n === E_INVALIDARG, "matchMedia('') threw " + n);
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment