mshtml: Added IHTMLWindow3::setInterval implementation.

This commit is contained in:
Jacek Caban 2008-06-27 14:11:38 -05:00 committed by Alexandre Julliard
parent 0d56f1058f
commit 74f29f1087
3 changed files with 41 additions and 24 deletions

View File

@ -846,7 +846,8 @@ static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, I
return E_NOTIMPL; return E_NOTIMPL;
} }
static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, long msec, VARIANT *language, long *timer_id) static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, long msec, VARIANT *language,
BOOL interval, long *timer_id)
{ {
IDispatch *disp = NULL; IDispatch *disp = NULL;
@ -868,7 +869,7 @@ static HRESULT window_set_timer(HTMLWindow *This, VARIANT *expr, long msec, VARI
if(!disp) if(!disp)
return E_FAIL; return E_FAIL;
*timer_id = set_task_timer(This->doc, msec, disp); *timer_id = set_task_timer(This->doc, msec, interval, disp);
IDispatch_Release(disp); IDispatch_Release(disp);
return S_OK; return S_OK;
@ -881,15 +882,17 @@ static HRESULT WINAPI HTMLWindow3_setTimeout(IHTMLWindow3 *iface, VARIANT *expre
TRACE("(%p)->(%p(%d) %ld %p %p)\n", This, expression, V_VT(expression), msec, language, timerID); TRACE("(%p)->(%p(%d) %ld %p %p)\n", This, expression, V_VT(expression), msec, language, timerID);
return window_set_timer(This, expression, msec, language, timerID); return window_set_timer(This, expression, msec, language, FALSE, timerID);
} }
static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, long msec, static HRESULT WINAPI HTMLWindow3_setInterval(IHTMLWindow3 *iface, VARIANT *expression, long msec,
VARIANT *language, long *timerID) VARIANT *language, long *timerID)
{ {
HTMLWindow *This = HTMLWINDOW3_THIS(iface); HTMLWindow *This = HTMLWINDOW3_THIS(iface);
FIXME("(%p)->(%p %ld %p %p)\n", This, expression, msec, language, timerID);
return E_NOTIMPL; TRACE("(%p)->(%p %ld %p %p)\n", This, expression, msec, language, timerID);
return window_set_timer(This, expression, msec, language, TRUE, timerID);
} }
static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface) static HRESULT WINAPI HTMLWindow3_print(IHTMLWindow3 *iface)

View File

@ -623,7 +623,7 @@ thread_data_t *get_thread_data(BOOL);
HWND get_thread_hwnd(void); HWND get_thread_hwnd(void);
void push_task(task_t*); void push_task(task_t*);
void remove_doc_tasks(const HTMLDocument*); void remove_doc_tasks(const HTMLDocument*);
DWORD set_task_timer(HTMLDocument*,DWORD,IDispatch*); DWORD set_task_timer(HTMLDocument*,DWORD,BOOL,IDispatch*);
HRESULT get_typeinfo(tid_t,ITypeInfo**); HRESULT get_typeinfo(tid_t,ITypeInfo**);
void release_typelib(void); void release_typelib(void);

View File

@ -43,6 +43,7 @@ typedef struct {
HTMLDocument *doc; HTMLDocument *doc;
DWORD id; DWORD id;
DWORD time; DWORD time;
DWORD interval;
IDispatch *disp; IDispatch *disp;
struct list entry; struct list entry;
@ -123,7 +124,29 @@ void remove_doc_tasks(const HTMLDocument *doc)
} }
} }
DWORD set_task_timer(HTMLDocument *doc, DWORD msec, IDispatch *disp) static BOOL queue_timer(thread_data_t *thread_data, task_timer_t *timer)
{
task_timer_t *iter;
if(list_empty(&thread_data->timer_list)
|| LIST_ENTRY(list_head(&thread_data->timer_list), task_timer_t, entry)->time > timer->time) {
list_add_head(&thread_data->timer_list, &timer->entry);
return TRUE;
}
LIST_FOR_EACH_ENTRY(iter, &thread_data->timer_list, task_timer_t, entry) {
if(iter->time > timer->time) {
list_add_tail(&iter->entry, &timer->entry);
return FALSE;
}
}
list_add_tail(&thread_data->timer_list, &timer->entry);
return FALSE;
}
DWORD set_task_timer(HTMLDocument *doc, DWORD msec, BOOL interval, IDispatch *disp)
{ {
thread_data_t *thread_data = get_thread_data(TRUE); thread_data_t *thread_data = get_thread_data(TRUE);
task_timer_t *timer; task_timer_t *timer;
@ -135,27 +158,13 @@ DWORD set_task_timer(HTMLDocument *doc, DWORD msec, IDispatch *disp)
timer->id = id_cnt++; timer->id = id_cnt++;
timer->doc = doc; timer->doc = doc;
timer->time = tc + msec; timer->time = tc + msec;
timer->interval = interval ? msec : 0;
IDispatch_AddRef(disp); IDispatch_AddRef(disp);
timer->disp = disp; timer->disp = disp;
if(list_empty(&thread_data->timer_list) if(queue_timer(thread_data, timer))
|| LIST_ENTRY(list_head(&thread_data->timer_list), task_timer_t, entry)->time > timer->time) {
list_add_head(&thread_data->timer_list, &timer->entry);
SetTimer(thread_data->thread_hwnd, TIMER_ID, msec, NULL); SetTimer(thread_data->thread_hwnd, TIMER_ID, msec, NULL);
}else {
task_timer_t *iter;
LIST_FOR_EACH_ENTRY(iter, &thread_data->timer_list, task_timer_t, entry) {
if(iter->time > timer->time) {
list_add_tail(&iter->entry, &timer->entry);
return timer->id;
}
}
list_add_tail(&thread_data->timer_list, &timer->entry);
}
return timer->id; return timer->id;
} }
@ -354,7 +363,12 @@ static LRESULT process_timer(void)
call_disp_func(timer->doc, timer->disp); call_disp_func(timer->doc, timer->disp);
release_task_timer(thread_data->thread_hwnd, timer); if(timer->interval) {
timer->time += timer->interval;
queue_timer(thread_data, timer);
}else {
release_task_timer(thread_data->thread_hwnd, timer);
}
} }
KillTimer(thread_data->thread_hwnd, TIMER_ID); KillTimer(thread_data->thread_hwnd, TIMER_ID);