Commit 91af3c56 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

mshtml: Move handle_insert_comment to mutation.c.

parent 327dc2c4
...@@ -506,7 +506,6 @@ void NSContainer_Release(NSContainer*); ...@@ -506,7 +506,6 @@ void NSContainer_Release(NSContainer*);
void init_mutation(NSContainer*); void init_mutation(NSContainer*);
void set_mutation_observer(NSContainer*,nsIDOMHTMLDocument*); void set_mutation_observer(NSContainer*,nsIDOMHTMLDocument*);
BOOL handle_insert_comment(HTMLDocument *doc, const PRUnichar *comment);
void HTMLDocument_LockContainer(HTMLDocument*,BOOL); void HTMLDocument_LockContainer(HTMLDocument*,BOOL);
void show_context_menu(HTMLDocument*,DWORD,POINT*,IDispatch*); void show_context_menu(HTMLDocument*,DWORD,POINT*,IDispatch*);
......
...@@ -55,6 +55,144 @@ void set_mutation_observer(NSContainer *nscontainer, nsIDOMHTMLDocument *nshtmld ...@@ -55,6 +55,144 @@ void set_mutation_observer(NSContainer *nscontainer, nsIDOMHTMLDocument *nshtmld
nsIDOMNSDocument_Release(nsdoc); nsIDOMNSDocument_Release(nsdoc);
} }
#define IE_MAJOR_VERSION 7
#define IE_MINOR_VERSION 0
static BOOL handle_insert_comment(HTMLDocument *doc, const PRUnichar *comment)
{
DWORD len;
int majorv = 0, minorv = 0;
const PRUnichar *ptr, *end;
nsAString nsstr;
PRUnichar *buf;
nsresult nsres;
enum {
CMP_EQ,
CMP_LT,
CMP_LTE,
CMP_GT,
CMP_GTE
} cmpt = CMP_EQ;
static const PRUnichar endifW[] = {'<','!','[','e','n','d','i','f',']'};
if(comment[0] != '[' || comment[1] != 'i' || comment[2] != 'f')
return FALSE;
ptr = comment+3;
while(isspaceW(*ptr))
ptr++;
if(ptr[0] == 'l' && ptr[1] == 't') {
ptr += 2;
if(*ptr == 'e') {
cmpt = CMP_LTE;
ptr++;
}else {
cmpt = CMP_LT;
}
}else if(ptr[0] == 'g' && ptr[1] == 't') {
ptr += 2;
if(*ptr == 'e') {
cmpt = CMP_GTE;
ptr++;
}else {
cmpt = CMP_GT;
}
}
if(!isspaceW(*ptr++))
return FALSE;
while(isspaceW(*ptr))
ptr++;
if(ptr[0] != 'I' || ptr[1] != 'E')
return FALSE;
ptr +=2;
if(!isspaceW(*ptr++))
return FALSE;
while(isspaceW(*ptr))
ptr++;
if(!isdigitW(*ptr))
return FALSE;
while(isdigitW(*ptr))
majorv = majorv*10 + (*ptr++ - '0');
if(*ptr == '.') {
if(!isdigitW(*ptr))
return FALSE;
while(isdigitW(*ptr))
minorv = minorv*10 + (*ptr++ - '0');
}
while(isspaceW(*ptr))
ptr++;
if(ptr[0] != ']' || ptr[1] != '>')
return FALSE;
ptr += 2;
len = strlenW(ptr);
if(len < sizeof(endifW)/sizeof(WCHAR))
return FALSE;
end = ptr + len-sizeof(endifW)/sizeof(WCHAR);
if(memcmp(end, endifW, sizeof(endifW)))
return FALSE;
switch(cmpt) {
case CMP_EQ:
if(majorv == IE_MAJOR_VERSION && minorv == IE_MINOR_VERSION)
break;
return FALSE;
case CMP_LT:
if(majorv > IE_MAJOR_VERSION)
break;
if(majorv == IE_MAJOR_VERSION && minorv > IE_MINOR_VERSION)
break;
return FALSE;
case CMP_LTE:
if(majorv > IE_MAJOR_VERSION)
break;
if(majorv == IE_MAJOR_VERSION && minorv >= IE_MINOR_VERSION)
break;
return FALSE;
case CMP_GT:
if(majorv < IE_MAJOR_VERSION)
break;
if(majorv == IE_MAJOR_VERSION && minorv < IE_MINOR_VERSION)
break;
return FALSE;
case CMP_GTE:
if(majorv < IE_MAJOR_VERSION)
break;
if(majorv == IE_MAJOR_VERSION && minorv <= IE_MINOR_VERSION)
break;
return FALSE;
}
buf = heap_alloc((end-ptr+1)*sizeof(WCHAR));
if(!buf)
return FALSE;
memcpy(buf, ptr, (end-ptr)*sizeof(WCHAR));
buf[end-ptr] = 0;
nsAString_Init(&nsstr, buf);
heap_free(buf);
/* FIXME: Find better way to insert HTML to document. */
nsres = nsIDOMHTMLDocument_Write(doc->nsdoc, &nsstr);
nsAString_Finish(&nsstr);
if(NS_FAILED(nsres)) {
ERR("Write failed: %08x\n", nsres);
return FALSE;
}
return TRUE;
}
static void add_script_runner(NSContainer *This) static void add_script_runner(NSContainer *This)
{ {
nsIDOMNSDocument *nsdoc; nsIDOMNSDocument *nsdoc;
......
...@@ -175,144 +175,6 @@ static nsresult NSAPI handle_load(nsIDOMEventListener *iface, nsIDOMEvent *event ...@@ -175,144 +175,6 @@ static nsresult NSAPI handle_load(nsIDOMEventListener *iface, nsIDOMEvent *event
return NS_OK; return NS_OK;
} }
#define IE_MAJOR_VERSION 7
#define IE_MINOR_VERSION 0
BOOL handle_insert_comment(HTMLDocument *doc, const PRUnichar *comment)
{
DWORD len;
int majorv = 0, minorv = 0;
const PRUnichar *ptr, *end;
nsAString nsstr;
PRUnichar *buf;
nsresult nsres;
enum {
CMP_EQ,
CMP_LT,
CMP_LTE,
CMP_GT,
CMP_GTE
} cmpt = CMP_EQ;
static const PRUnichar endifW[] = {'<','!','[','e','n','d','i','f',']'};
if(comment[0] != '[' || comment[1] != 'i' || comment[2] != 'f')
return FALSE;
ptr = comment+3;
while(isspaceW(*ptr))
ptr++;
if(ptr[0] == 'l' && ptr[1] == 't') {
ptr += 2;
if(*ptr == 'e') {
cmpt = CMP_LTE;
ptr++;
}else {
cmpt = CMP_LT;
}
}else if(ptr[0] == 'g' && ptr[1] == 't') {
ptr += 2;
if(*ptr == 'e') {
cmpt = CMP_GTE;
ptr++;
}else {
cmpt = CMP_GT;
}
}
if(!isspaceW(*ptr++))
return FALSE;
while(isspaceW(*ptr))
ptr++;
if(ptr[0] != 'I' || ptr[1] != 'E')
return FALSE;
ptr +=2;
if(!isspaceW(*ptr++))
return FALSE;
while(isspaceW(*ptr))
ptr++;
if(!isdigitW(*ptr))
return FALSE;
while(isdigitW(*ptr))
majorv = majorv*10 + (*ptr++ - '0');
if(*ptr == '.') {
if(!isdigitW(*ptr))
return FALSE;
while(isdigitW(*ptr))
minorv = minorv*10 + (*ptr++ - '0');
}
while(isspaceW(*ptr))
ptr++;
if(ptr[0] != ']' || ptr[1] != '>')
return FALSE;
ptr += 2;
len = strlenW(ptr);
if(len < sizeof(endifW)/sizeof(WCHAR))
return FALSE;
end = ptr + len-sizeof(endifW)/sizeof(WCHAR);
if(memcmp(end, endifW, sizeof(endifW)))
return FALSE;
switch(cmpt) {
case CMP_EQ:
if(majorv == IE_MAJOR_VERSION && minorv == IE_MINOR_VERSION)
break;
return FALSE;
case CMP_LT:
if(majorv > IE_MAJOR_VERSION)
break;
if(majorv == IE_MAJOR_VERSION && minorv > IE_MINOR_VERSION)
break;
return FALSE;
case CMP_LTE:
if(majorv > IE_MAJOR_VERSION)
break;
if(majorv == IE_MAJOR_VERSION && minorv >= IE_MINOR_VERSION)
break;
return FALSE;
case CMP_GT:
if(majorv < IE_MAJOR_VERSION)
break;
if(majorv == IE_MAJOR_VERSION && minorv < IE_MINOR_VERSION)
break;
return FALSE;
case CMP_GTE:
if(majorv < IE_MAJOR_VERSION)
break;
if(majorv == IE_MAJOR_VERSION && minorv <= IE_MINOR_VERSION)
break;
return FALSE;
}
buf = heap_alloc((end-ptr+1)*sizeof(WCHAR));
if(!buf)
return FALSE;
memcpy(buf, ptr, (end-ptr)*sizeof(WCHAR));
buf[end-ptr] = 0;
nsAString_Init(&nsstr, buf);
heap_free(buf);
/* FIXME: Find better way to insert HTML to document. */
nsres = nsIDOMHTMLDocument_Write(doc->nsdoc, &nsstr);
nsAString_Finish(&nsstr);
if(NS_FAILED(nsres)) {
ERR("Write failed: %08x\n", nsres);
return FALSE;
}
return TRUE;
}
static nsresult NSAPI handle_htmlevent(nsIDOMEventListener *iface, nsIDOMEvent *event) static nsresult NSAPI handle_htmlevent(nsIDOMEventListener *iface, nsIDOMEvent *event)
{ {
NSContainer *This = NSEVENTLIST_THIS(iface)->This; NSContainer *This = NSEVENTLIST_THIS(iface)->This;
......
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