2006-07-05 20:38:15 +00:00
|
|
|
/*
|
2007-09-12 21:36:48 +00:00
|
|
|
* Copyright 2006-2007 Jacek Caban for CodeWeavers
|
2006-07-05 20:38:15 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2014-11-12 15:25:31 +00:00
|
|
|
#include <assert.h>
|
2006-07-05 20:38:15 +00:00
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
2007-12-06 11:23:22 +00:00
|
|
|
#include "mshtmcid.h"
|
2006-07-05 20:38:15 +00:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "mshtml_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
|
|
|
|
|
2007-09-12 21:17:31 +00:00
|
|
|
static const WCHAR brW[] = {'b','r',0};
|
2008-01-10 22:51:25 +00:00
|
|
|
static const WCHAR hrW[] = {'h','r',0};
|
2007-09-12 21:17:31 +00:00
|
|
|
|
2006-07-05 20:38:15 +00:00
|
|
|
typedef struct {
|
2014-11-11 09:55:34 +00:00
|
|
|
DispatchEx dispex;
|
2010-12-29 01:52:48 +00:00
|
|
|
IHTMLTxtRange IHTMLTxtRange_iface;
|
2010-12-27 00:44:54 +00:00
|
|
|
IOleCommandTarget IOleCommandTarget_iface;
|
2006-07-05 20:38:15 +00:00
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
2007-05-09 22:32:48 +00:00
|
|
|
nsIDOMRange *nsrange;
|
2009-09-16 20:11:43 +00:00
|
|
|
HTMLDocumentNode *doc;
|
2007-08-17 00:37:01 +00:00
|
|
|
|
|
|
|
struct list entry;
|
2006-07-05 20:38:15 +00:00
|
|
|
} HTMLTxtRange;
|
|
|
|
|
2007-09-12 21:17:31 +00:00
|
|
|
typedef struct {
|
|
|
|
WCHAR *buf;
|
|
|
|
DWORD len;
|
|
|
|
DWORD size;
|
|
|
|
} wstrbuf_t;
|
|
|
|
|
2014-12-29 14:49:31 +00:00
|
|
|
typedef struct {
|
|
|
|
UINT16 type;
|
|
|
|
nsIDOMNode *node;
|
|
|
|
UINT32 off;
|
|
|
|
} rangepoint_t;
|
|
|
|
|
2007-09-12 21:32:46 +00:00
|
|
|
typedef enum {
|
|
|
|
RU_UNKNOWN,
|
|
|
|
RU_CHAR,
|
|
|
|
RU_WORD,
|
|
|
|
RU_SENTENCE,
|
|
|
|
RU_TEXTEDIT
|
|
|
|
} range_unit_t;
|
|
|
|
|
2009-09-16 20:11:43 +00:00
|
|
|
static HTMLTxtRange *get_range_object(HTMLDocumentNode *doc, IHTMLTxtRange *iface)
|
2007-08-17 00:40:33 +00:00
|
|
|
{
|
|
|
|
HTMLTxtRange *iter;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(iter, &doc->range_list, HTMLTxtRange, entry) {
|
2010-12-29 01:52:48 +00:00
|
|
|
if(&iter->IHTMLTxtRange_iface == iface)
|
2007-08-17 00:40:33 +00:00
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR("Could not find range in document\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-09-12 21:32:46 +00:00
|
|
|
static range_unit_t string_to_unit(LPCWSTR str)
|
|
|
|
{
|
|
|
|
static const WCHAR characterW[] =
|
|
|
|
{'c','h','a','r','a','c','t','e','r',0};
|
|
|
|
static const WCHAR wordW[] =
|
|
|
|
{'w','o','r','d',0};
|
|
|
|
static const WCHAR sentenceW[] =
|
|
|
|
{'s','e','n','t','e','n','c','e',0};
|
|
|
|
static const WCHAR texteditW[] =
|
|
|
|
{'t','e','x','t','e','d','i','t',0};
|
|
|
|
|
|
|
|
if(!strcmpiW(str, characterW)) return RU_CHAR;
|
|
|
|
if(!strcmpiW(str, wordW)) return RU_WORD;
|
|
|
|
if(!strcmpiW(str, sentenceW)) return RU_SENTENCE;
|
|
|
|
if(!strcmpiW(str, texteditW)) return RU_TEXTEDIT;
|
|
|
|
|
|
|
|
return RU_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2007-08-17 00:40:33 +00:00
|
|
|
static int string_to_nscmptype(LPCWSTR str)
|
|
|
|
{
|
|
|
|
static const WCHAR seW[] = {'S','t','a','r','t','T','o','E','n','d',0};
|
|
|
|
static const WCHAR ssW[] = {'S','t','a','r','t','T','o','S','t','a','r','t',0};
|
|
|
|
static const WCHAR esW[] = {'E','n','d','T','o','S','t','a','r','t',0};
|
|
|
|
static const WCHAR eeW[] = {'E','n','d','T','o','E','n','d',0};
|
|
|
|
|
|
|
|
if(!strcmpiW(str, seW)) return NS_START_TO_END;
|
|
|
|
if(!strcmpiW(str, ssW)) return NS_START_TO_START;
|
|
|
|
if(!strcmpiW(str, esW)) return NS_END_TO_START;
|
|
|
|
if(!strcmpiW(str, eeW)) return NS_END_TO_END;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-01-23 17:43:55 +00:00
|
|
|
static UINT16 get_node_type(nsIDOMNode *node)
|
2007-09-09 18:17:54 +00:00
|
|
|
{
|
2013-01-23 17:43:55 +00:00
|
|
|
UINT16 type = 0;
|
2007-09-09 18:17:54 +00:00
|
|
|
|
|
|
|
if(node)
|
|
|
|
nsIDOMNode_GetNodeType(node, &type);
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:49:31 +00:00
|
|
|
static void get_text_node_data(nsIDOMNode *node, nsAString *nsstr, const PRUnichar **str)
|
|
|
|
{
|
|
|
|
nsIDOMText *nstext;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMText, (void**)&nstext);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
nsAString_Init(nsstr, NULL);
|
|
|
|
nsres = nsIDOMText_GetData(nstext, nsstr);
|
|
|
|
nsIDOMText_Release(nstext);
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
ERR("GetData failed: %08x\n", nsres);
|
|
|
|
|
|
|
|
nsAString_GetData(nsstr, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsIDOMNode *get_child_node(nsIDOMNode *node, UINT32 off)
|
|
|
|
{
|
|
|
|
nsIDOMNodeList *node_list;
|
|
|
|
nsIDOMNode *ret = NULL;
|
|
|
|
|
|
|
|
nsIDOMNode_GetChildNodes(node, &node_list);
|
|
|
|
nsIDOMNodeList_Item(node_list, off, &ret);
|
|
|
|
nsIDOMNodeList_Release(node_list);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is very inefficient, but there is no faster way to compute index in
|
|
|
|
* child node list using public API. Gecko has internal nsINode::IndexOf
|
|
|
|
* function that we could consider exporting and use instead. */
|
|
|
|
static int get_child_index(nsIDOMNode *parent, nsIDOMNode *child)
|
|
|
|
{
|
|
|
|
nsIDOMNodeList *node_list;
|
|
|
|
nsIDOMNode *node;
|
|
|
|
int ret = 0;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
nsres = nsIDOMNode_GetChildNodes(parent, &node_list);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
nsres = nsIDOMNodeList_Item(node_list, ret, &node);
|
|
|
|
assert(nsres == NS_OK && node);
|
|
|
|
if(node == child) {
|
|
|
|
nsIDOMNode_Release(node);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsIDOMNode_Release(node);
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMNodeList_Release(node_list);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void init_rangepoint(rangepoint_t *rangepoint, nsIDOMNode *node, UINT32 off)
|
|
|
|
{
|
|
|
|
nsIDOMNode_AddRef(node);
|
|
|
|
|
|
|
|
rangepoint->type = get_node_type(node);
|
|
|
|
rangepoint->node = node;
|
|
|
|
rangepoint->off = off;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void free_rangepoint(rangepoint_t *rangepoint)
|
|
|
|
{
|
|
|
|
nsIDOMNode_Release(rangepoint->node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline BOOL rangepoint_cmp(const rangepoint_t *point1, const rangepoint_t *point2)
|
|
|
|
{
|
|
|
|
return point1->node == point2->node && point1->off == point2->off;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL rangepoint_next_node(rangepoint_t *iter)
|
|
|
|
{
|
|
|
|
nsIDOMNode *node;
|
|
|
|
UINT32 off;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
/* Try to move to the child node. */
|
|
|
|
node = get_child_node(iter->node, iter->off);
|
|
|
|
if(node) {
|
|
|
|
free_rangepoint(iter);
|
|
|
|
init_rangepoint(iter, node, 0);
|
|
|
|
nsIDOMNode_Release(node);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There are no more children in the node. Move to parent. */
|
|
|
|
nsres = nsIDOMNode_GetParentNode(iter->node, &node);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
if(!node)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
off = get_child_index(node, iter->node)+1;
|
|
|
|
free_rangepoint(iter);
|
|
|
|
init_rangepoint(iter, node, off);
|
|
|
|
nsIDOMNode_Release(node);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:49:47 +00:00
|
|
|
static UINT32 get_child_count(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
nsIDOMNodeList *node_list;
|
|
|
|
UINT32 ret;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
nsres = nsIDOMNode_GetChildNodes(node, &node_list);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
nsres = nsIDOMNodeList_GetLength(node_list, &ret);
|
|
|
|
nsIDOMNodeList_Release(node_list);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UINT32 get_text_length(nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
nsIDOMText *nstext;
|
|
|
|
UINT32 ret;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMText, (void**)&nstext);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
nsres = nsIDOMText_GetLength(nstext, &ret);
|
|
|
|
nsIDOMText_Release(nstext);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL rangepoint_prev_node(rangepoint_t *iter)
|
|
|
|
{
|
|
|
|
nsIDOMNode *node;
|
|
|
|
UINT32 off;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
/* Try to move to the child node. */
|
|
|
|
if(iter->off) {
|
|
|
|
node = get_child_node(iter->node, iter->off-1);
|
|
|
|
assert(node != NULL);
|
|
|
|
|
|
|
|
off = get_node_type(node) == TEXT_NODE ? get_text_length(node) : get_child_count(node);
|
|
|
|
free_rangepoint(iter);
|
|
|
|
init_rangepoint(iter, node, off);
|
|
|
|
nsIDOMNode_Release(node);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There are no more children in the node. Move to parent. */
|
|
|
|
nsres = nsIDOMNode_GetParentNode(iter->node, &node);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
if(!node)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
off = get_child_index(node, iter->node);
|
|
|
|
free_rangepoint(iter);
|
|
|
|
init_rangepoint(iter, node, off);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:49:31 +00:00
|
|
|
static void get_start_point(HTMLTxtRange *This, rangepoint_t *ret)
|
|
|
|
{
|
|
|
|
nsIDOMNode *node;
|
|
|
|
LONG off;
|
|
|
|
|
|
|
|
nsIDOMRange_GetStartContainer(This->nsrange, &node);
|
|
|
|
nsIDOMRange_GetStartOffset(This->nsrange, &off);
|
|
|
|
|
|
|
|
init_rangepoint(ret, node, off);
|
|
|
|
|
|
|
|
nsIDOMNode_Release(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void get_end_point(HTMLTxtRange *This, rangepoint_t *ret)
|
|
|
|
{
|
|
|
|
nsIDOMNode *node;
|
|
|
|
LONG off;
|
|
|
|
|
|
|
|
nsIDOMRange_GetEndContainer(This->nsrange, &node);
|
|
|
|
nsIDOMRange_GetEndOffset(This->nsrange, &off);
|
|
|
|
|
|
|
|
init_rangepoint(ret, node, off);
|
|
|
|
|
|
|
|
nsIDOMNode_Release(node);
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:49:47 +00:00
|
|
|
static void set_start_point(HTMLTxtRange *This, const rangepoint_t *start)
|
|
|
|
{
|
|
|
|
nsresult nsres = nsIDOMRange_SetStart(This->nsrange, start->node, start->off);
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
ERR("failed: %08x\n", nsres);
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:50:03 +00:00
|
|
|
static void set_end_point(HTMLTxtRange *This, const rangepoint_t *end)
|
|
|
|
{
|
|
|
|
nsresult nsres = nsIDOMRange_SetEnd(This->nsrange, end->node, end->off);
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
ERR("failed: %08x\n", nsres);
|
|
|
|
}
|
|
|
|
|
2008-01-10 22:51:25 +00:00
|
|
|
static BOOL is_elem_tag(nsIDOMNode *node, LPCWSTR istag)
|
2007-09-12 21:17:31 +00:00
|
|
|
{
|
|
|
|
nsIDOMElement *elem;
|
|
|
|
nsAString tag_str;
|
|
|
|
const PRUnichar *tag;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
nsres = nsIDOMNode_QueryInterface(node, &IID_nsIDOMElement, (void**)&elem);
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
nsAString_Init(&tag_str, NULL);
|
|
|
|
nsIDOMElement_GetTagName(elem, &tag_str);
|
|
|
|
nsIDOMElement_Release(elem);
|
2007-12-17 00:38:30 +00:00
|
|
|
nsAString_GetData(&tag_str, &tag);
|
2007-09-12 21:17:31 +00:00
|
|
|
|
2008-01-10 22:51:25 +00:00
|
|
|
ret = !strcmpiW(tag, istag);
|
|
|
|
|
|
|
|
nsAString_Finish(&tag_str);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-12-01 22:28:50 +00:00
|
|
|
static inline BOOL wstrbuf_init(wstrbuf_t *buf)
|
2007-09-12 21:17:31 +00:00
|
|
|
{
|
|
|
|
buf->len = 0;
|
|
|
|
buf->size = 16;
|
2007-12-05 20:52:31 +00:00
|
|
|
buf->buf = heap_alloc(buf->size * sizeof(WCHAR));
|
2009-12-01 22:28:50 +00:00
|
|
|
if (!buf->buf) return FALSE;
|
2007-09-12 21:17:31 +00:00
|
|
|
*buf->buf = 0;
|
2009-12-01 22:28:50 +00:00
|
|
|
return TRUE;
|
2007-09-12 21:17:31 +00:00
|
|
|
}
|
|
|
|
|
2007-09-14 16:03:44 +00:00
|
|
|
static inline void wstrbuf_finish(wstrbuf_t *buf)
|
2007-09-12 21:17:31 +00:00
|
|
|
{
|
2007-12-05 20:52:31 +00:00
|
|
|
heap_free(buf->buf);
|
2007-09-12 21:17:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void wstrbuf_append_len(wstrbuf_t *buf, LPCWSTR str, int len)
|
|
|
|
{
|
|
|
|
if(buf->len+len >= buf->size) {
|
2008-10-13 19:50:13 +00:00
|
|
|
buf->size = 2*buf->size+len;
|
2007-12-05 20:52:31 +00:00
|
|
|
buf->buf = heap_realloc(buf->buf, buf->size * sizeof(WCHAR));
|
2007-09-12 21:17:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(buf->buf+buf->len, str, len*sizeof(WCHAR));
|
|
|
|
buf->len += len;
|
|
|
|
buf->buf[buf->len] = 0;
|
|
|
|
}
|
|
|
|
|
2007-10-21 13:47:53 +00:00
|
|
|
static void wstrbuf_append_nodetxt(wstrbuf_t *buf, LPCWSTR str, int len)
|
|
|
|
{
|
|
|
|
const WCHAR *s = str;
|
|
|
|
WCHAR *d;
|
|
|
|
|
2007-11-05 20:45:46 +00:00
|
|
|
TRACE("%s\n", debugstr_wn(str, len));
|
|
|
|
|
2007-10-21 13:47:53 +00:00
|
|
|
if(buf->len+len >= buf->size) {
|
2008-10-13 19:50:13 +00:00
|
|
|
buf->size = 2*buf->size+len;
|
2007-12-05 20:52:31 +00:00
|
|
|
buf->buf = heap_realloc(buf->buf, buf->size * sizeof(WCHAR));
|
2007-10-21 13:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(buf->len && isspaceW(buf->buf[buf->len-1])) {
|
|
|
|
while(s < str+len && isspaceW(*s))
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
|
|
|
|
d = buf->buf+buf->len;
|
|
|
|
while(s < str+len) {
|
|
|
|
if(isspaceW(*s)) {
|
|
|
|
*d++ = ' ';
|
|
|
|
s++;
|
|
|
|
while(s < str+len && isspaceW(*s))
|
|
|
|
s++;
|
|
|
|
}else {
|
|
|
|
*d++ = *s++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buf->len = d - buf->buf;
|
|
|
|
*d = 0;
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:49:31 +00:00
|
|
|
static void wstrbuf_append_node(wstrbuf_t *buf, nsIDOMNode *node, BOOL ignore_text)
|
2007-09-12 21:17:31 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch(get_node_type(node)) {
|
|
|
|
case TEXT_NODE: {
|
|
|
|
nsIDOMText *nstext;
|
|
|
|
nsAString data_str;
|
|
|
|
const PRUnichar *data;
|
|
|
|
|
2014-12-29 14:49:31 +00:00
|
|
|
if(ignore_text)
|
|
|
|
break;
|
|
|
|
|
2007-09-12 21:17:31 +00:00
|
|
|
nsIDOMNode_QueryInterface(node, &IID_nsIDOMText, (void**)&nstext);
|
|
|
|
|
|
|
|
nsAString_Init(&data_str, NULL);
|
|
|
|
nsIDOMText_GetData(nstext, &data_str);
|
2007-12-17 00:38:30 +00:00
|
|
|
nsAString_GetData(&data_str, &data);
|
2007-10-21 13:47:53 +00:00
|
|
|
wstrbuf_append_nodetxt(buf, data, strlenW(data));
|
2007-09-12 21:17:31 +00:00
|
|
|
nsAString_Finish(&data_str);
|
|
|
|
|
2008-10-13 19:49:58 +00:00
|
|
|
nsIDOMText_Release(nstext);
|
2007-09-12 21:17:31 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ELEMENT_NODE:
|
2008-01-10 22:51:25 +00:00
|
|
|
if(is_elem_tag(node, brW)) {
|
2007-09-12 21:17:31 +00:00
|
|
|
static const WCHAR endlW[] = {'\r','\n'};
|
|
|
|
wstrbuf_append_len(buf, endlW, 2);
|
2008-01-10 22:51:25 +00:00
|
|
|
}else if(is_elem_tag(node, hrW)) {
|
|
|
|
static const WCHAR endl2W[] = {'\r','\n','\r','\n'};
|
|
|
|
wstrbuf_append_len(buf, endl2W, 4);
|
2007-09-12 21:17:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-13 19:49:58 +00:00
|
|
|
static void wstrbuf_append_node_rec(wstrbuf_t *buf, nsIDOMNode *node)
|
|
|
|
{
|
|
|
|
nsIDOMNode *iter, *tmp;
|
|
|
|
|
2014-12-29 14:49:31 +00:00
|
|
|
wstrbuf_append_node(buf, node, FALSE);
|
2008-10-13 19:49:58 +00:00
|
|
|
|
|
|
|
nsIDOMNode_GetFirstChild(node, &iter);
|
|
|
|
while(iter) {
|
|
|
|
wstrbuf_append_node_rec(buf, iter);
|
|
|
|
nsIDOMNode_GetNextSibling(iter, &tmp);
|
|
|
|
nsIDOMNode_Release(iter);
|
|
|
|
iter = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-12 21:17:31 +00:00
|
|
|
static void range_to_string(HTMLTxtRange *This, wstrbuf_t *buf)
|
|
|
|
{
|
2014-12-29 14:49:31 +00:00
|
|
|
rangepoint_t end_pos, iter;
|
2012-03-15 10:55:01 +00:00
|
|
|
cpp_bool collapsed;
|
2007-09-12 21:17:31 +00:00
|
|
|
|
|
|
|
nsIDOMRange_GetCollapsed(This->nsrange, &collapsed);
|
|
|
|
if(collapsed) {
|
|
|
|
wstrbuf_finish(buf);
|
|
|
|
buf->buf = NULL;
|
|
|
|
buf->size = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:49:31 +00:00
|
|
|
get_end_point(This, &end_pos);
|
|
|
|
get_start_point(This, &iter);
|
2007-09-12 21:17:31 +00:00
|
|
|
|
2014-12-29 14:49:31 +00:00
|
|
|
do {
|
|
|
|
if(iter.type == TEXT_NODE) {
|
|
|
|
const PRUnichar *str;
|
|
|
|
nsAString nsstr;
|
2007-09-12 21:17:31 +00:00
|
|
|
|
2014-12-29 14:49:31 +00:00
|
|
|
get_text_node_data(iter.node, &nsstr, &str);
|
2007-09-12 21:17:31 +00:00
|
|
|
|
2014-12-29 14:49:31 +00:00
|
|
|
if(iter.node == end_pos.node) {
|
|
|
|
wstrbuf_append_nodetxt(buf, str+iter.off, end_pos.off-iter.off);
|
|
|
|
nsAString_Finish(&nsstr);
|
|
|
|
break;
|
|
|
|
}
|
2007-09-12 21:17:31 +00:00
|
|
|
|
2014-12-29 14:49:31 +00:00
|
|
|
wstrbuf_append_nodetxt(buf, str+iter.off, strlenW(str+iter.off));
|
|
|
|
nsAString_Finish(&nsstr);
|
|
|
|
}else {
|
|
|
|
nsIDOMNode *node;
|
|
|
|
|
|
|
|
node = get_child_node(iter.node, iter.off);
|
|
|
|
if(node) {
|
|
|
|
wstrbuf_append_node(buf, node, TRUE);
|
|
|
|
nsIDOMNode_Release(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!rangepoint_next_node(&iter)) {
|
|
|
|
ERR("End of document?\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}while(!rangepoint_cmp(&iter, &end_pos));
|
2007-09-12 21:17:31 +00:00
|
|
|
|
2014-12-29 14:49:31 +00:00
|
|
|
free_rangepoint(&iter);
|
|
|
|
free_rangepoint(&end_pos);
|
2007-10-21 13:47:53 +00:00
|
|
|
|
|
|
|
if(buf->len) {
|
|
|
|
WCHAR *p;
|
|
|
|
|
|
|
|
for(p = buf->buf+buf->len-1; p >= buf->buf && isspaceW(*p); p--);
|
|
|
|
|
|
|
|
p = strchrW(p, '\r');
|
|
|
|
if(p)
|
|
|
|
*p = 0;
|
|
|
|
}
|
2007-09-12 21:17:31 +00:00
|
|
|
}
|
|
|
|
|
2008-10-13 19:49:58 +00:00
|
|
|
HRESULT get_node_text(HTMLDOMNode *node, BSTR *ret)
|
|
|
|
{
|
|
|
|
wstrbuf_t buf;
|
|
|
|
HRESULT hres = S_OK;
|
|
|
|
|
2009-12-01 22:28:50 +00:00
|
|
|
if (!wstrbuf_init(&buf))
|
|
|
|
return E_OUTOFMEMORY;
|
2008-10-13 19:49:58 +00:00
|
|
|
wstrbuf_append_node_rec(&buf, node->nsnode);
|
|
|
|
if(buf.buf) {
|
|
|
|
*ret = SysAllocString(buf.buf);
|
|
|
|
if(!*ret)
|
|
|
|
hres = E_OUTOFMEMORY;
|
2009-12-01 22:28:50 +00:00
|
|
|
} else {
|
2008-10-13 19:49:58 +00:00
|
|
|
*ret = NULL;
|
|
|
|
}
|
|
|
|
wstrbuf_finish(&buf);
|
|
|
|
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
TRACE("ret %s\n", debugstr_w(*ret));
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:49:47 +00:00
|
|
|
static WCHAR move_next_char(rangepoint_t *iter)
|
|
|
|
{
|
|
|
|
rangepoint_t last_space;
|
|
|
|
nsIDOMNode *node;
|
|
|
|
WCHAR cspace = 0;
|
|
|
|
const WCHAR *p;
|
|
|
|
|
|
|
|
do {
|
|
|
|
switch(iter->type) {
|
|
|
|
case TEXT_NODE: {
|
|
|
|
const PRUnichar *str;
|
|
|
|
nsAString nsstr;
|
|
|
|
WCHAR c;
|
|
|
|
|
|
|
|
get_text_node_data(iter->node, &nsstr, &str);
|
|
|
|
p = str+iter->off;
|
|
|
|
if(!*p) {
|
|
|
|
nsAString_Finish(&nsstr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
c = *p;
|
|
|
|
if(isspaceW(c)) {
|
|
|
|
while(isspaceW(*p))
|
|
|
|
p++;
|
|
|
|
|
|
|
|
if(cspace)
|
|
|
|
free_rangepoint(&last_space);
|
|
|
|
else
|
|
|
|
cspace = ' ';
|
|
|
|
|
|
|
|
iter->off = p-str;
|
|
|
|
c = *p;
|
|
|
|
nsAString_Finish(&nsstr);
|
|
|
|
if(!c) { /* continue to skip spaces */
|
|
|
|
init_rangepoint(&last_space, iter->node, iter->off);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cspace;
|
|
|
|
}else {
|
|
|
|
nsAString_Finish(&nsstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we have a non-space char and we're skipping spaces, stop and return the last found space. */
|
|
|
|
if(cspace) {
|
|
|
|
free_rangepoint(iter);
|
|
|
|
*iter = last_space;
|
|
|
|
return cspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter->off++;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
case ELEMENT_NODE:
|
|
|
|
node = get_child_node(iter->node, iter->off);
|
|
|
|
if(!node)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(is_elem_tag(node, brW)) {
|
|
|
|
if(cspace) {
|
|
|
|
nsIDOMNode_Release(node);
|
|
|
|
free_rangepoint(iter);
|
|
|
|
*iter = last_space;
|
|
|
|
return cspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
cspace = '\n';
|
|
|
|
init_rangepoint(&last_space, iter->node, iter->off+1);
|
|
|
|
}else if(is_elem_tag(node, hrW)) {
|
|
|
|
nsIDOMNode_Release(node);
|
|
|
|
if(cspace) {
|
|
|
|
free_rangepoint(iter);
|
|
|
|
*iter = last_space;
|
|
|
|
return cspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter->off++;
|
|
|
|
return '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMNode_Release(node);
|
|
|
|
}
|
|
|
|
}while(rangepoint_next_node(iter));
|
|
|
|
|
|
|
|
return cspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
static WCHAR move_prev_char(rangepoint_t *iter)
|
|
|
|
{
|
|
|
|
rangepoint_t last_space;
|
|
|
|
nsIDOMNode *node;
|
|
|
|
WCHAR cspace = 0;
|
|
|
|
const WCHAR *p;
|
|
|
|
|
|
|
|
do {
|
|
|
|
switch(iter->type) {
|
|
|
|
case TEXT_NODE: {
|
|
|
|
const PRUnichar *str;
|
|
|
|
nsAString nsstr;
|
|
|
|
WCHAR c;
|
|
|
|
|
|
|
|
if(!iter->off)
|
|
|
|
break;
|
|
|
|
|
|
|
|
get_text_node_data(iter->node, &nsstr, &str);
|
|
|
|
|
|
|
|
p = str+iter->off-1;
|
|
|
|
c = *p;
|
|
|
|
|
|
|
|
if(isspaceW(c)) {
|
|
|
|
while(p > str && isspaceW(*(p-1)))
|
|
|
|
p--;
|
|
|
|
|
|
|
|
if(cspace)
|
|
|
|
free_rangepoint(&last_space);
|
|
|
|
else
|
|
|
|
cspace = ' ';
|
|
|
|
|
|
|
|
iter->off = p-str;
|
|
|
|
nsAString_Finish(&nsstr);
|
|
|
|
if(p == str) { /* continue to skip spaces */
|
|
|
|
init_rangepoint(&last_space, iter->node, iter->off);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cspace;
|
|
|
|
}else {
|
|
|
|
nsAString_Finish(&nsstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we have a non-space char and we're skipping spaces, stop and return the last found space. */
|
|
|
|
if(cspace) {
|
|
|
|
free_rangepoint(iter);
|
|
|
|
*iter = last_space;
|
|
|
|
return cspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter->off--;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
case ELEMENT_NODE:
|
|
|
|
if(!iter->off)
|
|
|
|
break;
|
|
|
|
|
|
|
|
node = get_child_node(iter->node, iter->off-1);
|
|
|
|
if(!node)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(is_elem_tag(node, brW)) {
|
|
|
|
if(cspace)
|
|
|
|
free_rangepoint(&last_space);
|
|
|
|
cspace = '\n';
|
|
|
|
init_rangepoint(&last_space, iter->node, iter->off-1);
|
|
|
|
}else if(is_elem_tag(node, hrW)) {
|
|
|
|
nsIDOMNode_Release(node);
|
|
|
|
if(cspace) {
|
|
|
|
free_rangepoint(iter);
|
|
|
|
*iter = last_space;
|
|
|
|
return cspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter->off--;
|
|
|
|
return '\n';
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMNode_Release(node);
|
|
|
|
}
|
|
|
|
}while(rangepoint_prev_node(iter));
|
|
|
|
|
|
|
|
if(cspace) {
|
|
|
|
free_rangepoint(iter);
|
|
|
|
*iter = last_space;
|
|
|
|
return cspace;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LONG move_by_chars(rangepoint_t *iter, LONG cnt)
|
|
|
|
{
|
|
|
|
LONG ret = 0;
|
|
|
|
|
|
|
|
if(cnt >= 0) {
|
|
|
|
while(ret < cnt && move_next_char(iter))
|
|
|
|
ret++;
|
|
|
|
}else {
|
|
|
|
while(ret > cnt && move_prev_char(iter))
|
|
|
|
ret--;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:50:03 +00:00
|
|
|
static LONG find_prev_space(rangepoint_t *iter, BOOL first_space)
|
|
|
|
{
|
|
|
|
rangepoint_t prev;
|
|
|
|
WCHAR c;
|
|
|
|
|
|
|
|
init_rangepoint(&prev, iter->node, iter->off);
|
|
|
|
c = move_prev_char(&prev);
|
|
|
|
if(!c || (first_space && isspaceW(c)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
do {
|
|
|
|
free_rangepoint(iter);
|
|
|
|
init_rangepoint(iter, prev.node, prev.off);
|
|
|
|
c = move_prev_char(&prev);
|
|
|
|
}while(c && !isspaceW(c));
|
|
|
|
|
|
|
|
free_rangepoint(&prev);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL find_word_end(rangepoint_t *iter, BOOL is_collapsed)
|
|
|
|
{
|
|
|
|
rangepoint_t prev_iter;
|
|
|
|
WCHAR c;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if(!is_collapsed) {
|
|
|
|
init_rangepoint(&prev_iter, iter->node, iter->off);
|
|
|
|
c = move_prev_char(&prev_iter);
|
|
|
|
free_rangepoint(&prev_iter);
|
|
|
|
if(isspaceW(c))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
init_rangepoint(&prev_iter, iter->node, iter->off);
|
|
|
|
c = move_next_char(iter);
|
|
|
|
if(c == '\n') {
|
|
|
|
free_rangepoint(iter);
|
|
|
|
*iter = prev_iter;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
if(!c) {
|
|
|
|
if(!ret)
|
|
|
|
ret = !rangepoint_cmp(iter, &prev_iter);
|
|
|
|
}else {
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
free_rangepoint(&prev_iter);
|
|
|
|
}while(c && !isspaceW(c));
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-12-29 14:50:22 +00:00
|
|
|
static LONG move_by_words(rangepoint_t *iter, LONG cnt)
|
2007-09-12 21:32:46 +00:00
|
|
|
{
|
2009-06-03 07:44:46 +00:00
|
|
|
LONG ret = 0;
|
2007-10-13 23:14:08 +00:00
|
|
|
|
2014-12-29 14:50:22 +00:00
|
|
|
if(cnt >= 0) {
|
|
|
|
WCHAR c;
|
2007-09-12 21:35:11 +00:00
|
|
|
|
2014-12-29 14:50:22 +00:00
|
|
|
while(ret < cnt && (c = move_next_char(iter))) {
|
|
|
|
if(isspaceW(c))
|
2007-09-12 21:35:11 +00:00
|
|
|
ret++;
|
2007-11-05 20:45:46 +00:00
|
|
|
}
|
|
|
|
}else {
|
2014-12-29 14:50:22 +00:00
|
|
|
while(ret > cnt && find_prev_space(iter, FALSE))
|
|
|
|
ret--;
|
2007-09-12 21:36:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-12-29 01:52:48 +00:00
|
|
|
static inline HTMLTxtRange *impl_from_IHTMLTxtRange(IHTMLTxtRange *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, HTMLTxtRange, IHTMLTxtRange_iface);
|
|
|
|
}
|
2006-07-05 20:38:15 +00:00
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_QueryInterface(IHTMLTxtRange *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
|
2014-11-11 09:55:34 +00:00
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
|
2006-07-05 20:38:15 +00:00
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
2010-12-29 01:52:48 +00:00
|
|
|
*ppv = &This->IHTMLTxtRange_iface;
|
2006-07-05 20:38:15 +00:00
|
|
|
}else if(IsEqualGUID(&IID_IHTMLTxtRange, riid)) {
|
2010-12-29 01:52:48 +00:00
|
|
|
*ppv = &This->IHTMLTxtRange_iface;
|
2007-11-25 18:16:04 +00:00
|
|
|
}else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
|
2010-12-27 00:44:54 +00:00
|
|
|
*ppv = &This->IOleCommandTarget_iface;
|
2014-11-11 09:55:34 +00:00
|
|
|
}else if(dispex_query_interface(&This->dispex, riid, ppv)) {
|
|
|
|
return *ppv ? S_OK : E_NOINTERFACE;
|
|
|
|
}else {
|
|
|
|
*ppv = NULL;
|
|
|
|
WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
return E_NOINTERFACE;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
2014-11-11 09:55:34 +00:00
|
|
|
IUnknown_AddRef((IUnknown*)*ppv);
|
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HTMLTxtRange_AddRef(IHTMLTxtRange *iface)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-05 21:50:39 +00:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2006-07-05 20:38:15 +00:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HTMLTxtRange_Release(IHTMLTxtRange *iface)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2006-10-05 21:50:39 +00:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2006-07-05 20:38:15 +00:00
|
|
|
|
|
|
|
if(!ref) {
|
2007-05-09 22:32:48 +00:00
|
|
|
if(This->nsrange)
|
2012-07-26 09:37:48 +00:00
|
|
|
nsIDOMRange_Release(This->nsrange);
|
2007-08-17 00:37:01 +00:00
|
|
|
if(This->doc)
|
|
|
|
list_remove(&This->entry);
|
2014-11-11 09:55:34 +00:00
|
|
|
release_dispex(&This->dispex);
|
2007-12-05 20:52:31 +00:00
|
|
|
heap_free(This);
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_GetTypeInfoCount(IHTMLTxtRange *iface, UINT *pctinfo)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2014-11-11 09:55:34 +00:00
|
|
|
|
|
|
|
return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_GetTypeInfo(IHTMLTxtRange *iface, UINT iTInfo,
|
|
|
|
LCID lcid, ITypeInfo **ppTInfo)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2014-11-11 09:55:34 +00:00
|
|
|
|
|
|
|
return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_GetIDsOfNames(IHTMLTxtRange *iface, REFIID riid,
|
|
|
|
LPOLESTR *rgszNames, UINT cNames,
|
|
|
|
LCID lcid, DISPID *rgDispId)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2014-11-11 09:55:34 +00:00
|
|
|
|
|
|
|
return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames,
|
|
|
|
cNames, lcid, rgDispId);
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_Invoke(IHTMLTxtRange *iface, DISPID dispIdMember,
|
|
|
|
REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
|
|
|
|
VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2014-11-11 09:55:34 +00:00
|
|
|
|
|
|
|
return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid,
|
|
|
|
lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_get_htmlText(IHTMLTxtRange *iface, BSTR *p)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2007-05-09 22:34:05 +00:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
|
|
|
|
|
|
|
*p = NULL;
|
|
|
|
|
|
|
|
if(This->nsrange) {
|
|
|
|
nsIDOMDocumentFragment *fragment;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_CloneContents(This->nsrange, &fragment);
|
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
const PRUnichar *nstext;
|
|
|
|
nsAString nsstr;
|
|
|
|
|
|
|
|
nsAString_Init(&nsstr, NULL);
|
|
|
|
nsnode_to_nsstring((nsIDOMNode*)fragment, &nsstr);
|
|
|
|
nsIDOMDocumentFragment_Release(fragment);
|
|
|
|
|
2007-12-17 00:38:30 +00:00
|
|
|
nsAString_GetData(&nsstr, &nstext);
|
2007-05-09 22:34:05 +00:00
|
|
|
*p = SysAllocString(nstext);
|
|
|
|
|
|
|
|
nsAString_Finish(&nsstr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!*p) {
|
|
|
|
const WCHAR emptyW[] = {0};
|
|
|
|
*p = SysAllocString(emptyW);
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("return %s\n", debugstr_w(*p));
|
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_put_text(IHTMLTxtRange *iface, BSTR v)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2007-08-17 00:38:00 +00:00
|
|
|
nsIDOMText *text_node;
|
|
|
|
nsAString text_str;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_w(v));
|
|
|
|
|
|
|
|
if(!This->doc)
|
|
|
|
return MSHTML_E_NODOC;
|
|
|
|
|
2010-01-28 22:56:31 +00:00
|
|
|
nsAString_InitDepend(&text_str, v);
|
2009-10-21 19:27:42 +00:00
|
|
|
nsres = nsIDOMHTMLDocument_CreateTextNode(This->doc->nsdoc, &text_str, &text_node);
|
2007-08-17 00:38:00 +00:00
|
|
|
nsAString_Finish(&text_str);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("CreateTextNode failed: %08x\n", nsres);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
nsres = nsIDOMRange_DeleteContents(This->nsrange);
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
ERR("DeleteContents failed: %08x\n", nsres);
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_InsertNode(This->nsrange, (nsIDOMNode*)text_node);
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
ERR("InsertNode failed: %08x\n", nsres);
|
|
|
|
|
2007-10-12 09:11:24 +00:00
|
|
|
nsres = nsIDOMRange_SetEndAfter(This->nsrange, (nsIDOMNode*)text_node);
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
ERR("SetEndAfter failed: %08x\n", nsres);
|
|
|
|
|
2010-12-29 01:52:48 +00:00
|
|
|
return IHTMLTxtRange_collapse(&This->IHTMLTxtRange_iface, VARIANT_FALSE);
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_get_text(IHTMLTxtRange *iface, BSTR *p)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2007-09-12 21:17:31 +00:00
|
|
|
wstrbuf_t buf;
|
2006-07-05 20:38:20 +00:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, p);
|
|
|
|
|
2007-09-19 11:33:03 +00:00
|
|
|
*p = NULL;
|
|
|
|
if(!This->nsrange)
|
|
|
|
return S_OK;
|
|
|
|
|
2009-12-01 22:28:50 +00:00
|
|
|
if (!wstrbuf_init(&buf))
|
|
|
|
return E_OUTOFMEMORY;
|
2007-09-12 21:17:31 +00:00
|
|
|
range_to_string(This, &buf);
|
2009-12-01 22:28:50 +00:00
|
|
|
if (buf.buf)
|
2007-09-12 21:17:31 +00:00
|
|
|
*p = SysAllocString(buf.buf);
|
|
|
|
wstrbuf_finish(&buf);
|
2006-07-05 20:38:20 +00:00
|
|
|
|
2007-09-12 21:17:31 +00:00
|
|
|
TRACE("ret %s\n", debugstr_w(*p));
|
2006-07-05 20:38:20 +00:00
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_parentElement(IHTMLTxtRange *iface, IHTMLElement **parent)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2007-09-09 18:17:54 +00:00
|
|
|
nsIDOMNode *nsnode, *tmp;
|
|
|
|
HTMLDOMNode *node;
|
2010-12-01 11:52:08 +00:00
|
|
|
HRESULT hres;
|
2007-09-09 18:17:54 +00:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, parent);
|
|
|
|
|
|
|
|
nsIDOMRange_GetCommonAncestorContainer(This->nsrange, &nsnode);
|
|
|
|
while(nsnode && get_node_type(nsnode) != ELEMENT_NODE) {
|
|
|
|
nsIDOMNode_GetParentNode(nsnode, &tmp);
|
|
|
|
nsIDOMNode_Release(nsnode);
|
|
|
|
nsnode = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!nsnode) {
|
|
|
|
*parent = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-12-01 11:52:08 +00:00
|
|
|
hres = get_node(This->doc, nsnode, TRUE, &node);
|
2007-09-09 18:17:54 +00:00
|
|
|
nsIDOMNode_Release(nsnode);
|
2010-12-01 11:52:08 +00:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
2007-09-09 18:17:54 +00:00
|
|
|
|
2012-06-25 12:04:40 +00:00
|
|
|
hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)parent);
|
|
|
|
node_release(node);
|
|
|
|
return hres;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_duplicate(IHTMLTxtRange *iface, IHTMLTxtRange **Duplicate)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2007-08-12 15:43:30 +00:00
|
|
|
nsIDOMRange *nsrange = NULL;
|
2009-09-16 20:11:43 +00:00
|
|
|
HRESULT hres;
|
2007-08-12 15:43:30 +00:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, Duplicate);
|
|
|
|
|
|
|
|
nsIDOMRange_CloneRange(This->nsrange, &nsrange);
|
2009-09-16 20:11:43 +00:00
|
|
|
hres = HTMLTxtRange_Create(This->doc, nsrange, Duplicate);
|
2007-08-12 15:43:30 +00:00
|
|
|
nsIDOMRange_Release(nsrange);
|
|
|
|
|
2009-09-16 20:11:43 +00:00
|
|
|
return hres;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_inRange(IHTMLTxtRange *iface, IHTMLTxtRange *Range,
|
|
|
|
VARIANT_BOOL *InRange)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2007-09-09 18:18:14 +00:00
|
|
|
HTMLTxtRange *src_range;
|
2013-01-18 13:06:09 +00:00
|
|
|
short nsret = 0;
|
2007-09-09 18:18:14 +00:00
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", This, Range, InRange);
|
|
|
|
|
|
|
|
*InRange = VARIANT_FALSE;
|
|
|
|
|
|
|
|
src_range = get_range_object(This->doc, Range);
|
|
|
|
if(!src_range)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_START_TO_START,
|
|
|
|
src_range->nsrange, &nsret);
|
|
|
|
if(NS_SUCCEEDED(nsres) && nsret <= 0) {
|
|
|
|
nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_END_TO_END,
|
|
|
|
src_range->nsrange, &nsret);
|
|
|
|
if(NS_SUCCEEDED(nsres) && nsret >= 0)
|
|
|
|
*InRange = VARIANT_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
ERR("CompareBoundaryPoints failed: %08x\n", nsres);
|
|
|
|
|
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_isEqual(IHTMLTxtRange *iface, IHTMLTxtRange *Range,
|
|
|
|
VARIANT_BOOL *IsEqual)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2007-09-09 18:18:28 +00:00
|
|
|
HTMLTxtRange *src_range;
|
2013-01-18 13:06:09 +00:00
|
|
|
short nsret = 0;
|
2007-09-09 18:18:28 +00:00
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", This, Range, IsEqual);
|
|
|
|
|
|
|
|
*IsEqual = VARIANT_FALSE;
|
|
|
|
|
|
|
|
src_range = get_range_object(This->doc, Range);
|
|
|
|
if(!src_range)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_START_TO_START,
|
|
|
|
src_range->nsrange, &nsret);
|
|
|
|
if(NS_SUCCEEDED(nsres) && !nsret) {
|
|
|
|
nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, NS_END_TO_END,
|
|
|
|
src_range->nsrange, &nsret);
|
|
|
|
if(NS_SUCCEEDED(nsres) && !nsret)
|
|
|
|
*IsEqual = VARIANT_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
ERR("CompareBoundaryPoints failed: %08x\n", nsres);
|
|
|
|
|
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_scrollIntoView(IHTMLTxtRange *iface, VARIANT_BOOL fStart)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
FIXME("(%p)->(%x)\n", This, fStart);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_collapse(IHTMLTxtRange *iface, VARIANT_BOOL Start)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2007-08-12 15:44:19 +00:00
|
|
|
|
|
|
|
TRACE("(%p)->(%x)\n", This, Start);
|
|
|
|
|
|
|
|
nsIDOMRange_Collapse(This->nsrange, Start != VARIANT_FALSE);
|
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_expand(IHTMLTxtRange *iface, BSTR Unit, VARIANT_BOOL *Success)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2007-09-12 21:32:46 +00:00
|
|
|
range_unit_t unit;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_w(Unit), Success);
|
|
|
|
|
|
|
|
unit = string_to_unit(Unit);
|
|
|
|
if(unit == RU_UNKNOWN)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-10-19 13:14:35 +00:00
|
|
|
*Success = VARIANT_FALSE;
|
|
|
|
|
2007-09-12 21:32:46 +00:00
|
|
|
switch(unit) {
|
|
|
|
case RU_WORD: {
|
2014-12-29 14:50:03 +00:00
|
|
|
rangepoint_t end, start;
|
|
|
|
cpp_bool is_collapsed;
|
2007-11-05 20:45:46 +00:00
|
|
|
|
2014-12-29 14:50:03 +00:00
|
|
|
get_start_point(This, &start);
|
|
|
|
get_end_point(This, &end);
|
2007-09-12 21:32:46 +00:00
|
|
|
|
2014-12-29 14:50:03 +00:00
|
|
|
nsIDOMRange_GetCollapsed(This->nsrange, &is_collapsed);
|
2007-10-21 13:47:53 +00:00
|
|
|
|
2014-12-29 14:50:03 +00:00
|
|
|
if(find_word_end(&end, is_collapsed)) {
|
|
|
|
set_end_point(This, &end);
|
2007-11-05 20:45:46 +00:00
|
|
|
*Success = VARIANT_TRUE;
|
2007-09-12 21:32:46 +00:00
|
|
|
}
|
|
|
|
|
2014-12-29 14:50:03 +00:00
|
|
|
if(find_prev_space(&start, TRUE)) {
|
|
|
|
set_start_point(This, &start);
|
|
|
|
*Success = VARIANT_TRUE;
|
2007-09-12 21:32:46 +00:00
|
|
|
}
|
|
|
|
|
2014-12-29 14:50:03 +00:00
|
|
|
free_rangepoint(&end);
|
|
|
|
free_rangepoint(&start);
|
2007-09-12 21:32:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-10-19 13:14:35 +00:00
|
|
|
|
|
|
|
case RU_TEXTEDIT: {
|
|
|
|
nsIDOMHTMLElement *nsbody = NULL;
|
|
|
|
nsresult nsres;
|
|
|
|
|
2009-10-21 19:27:42 +00:00
|
|
|
nsres = nsIDOMHTMLDocument_GetBody(This->doc->nsdoc, &nsbody);
|
2007-10-19 13:14:35 +00:00
|
|
|
if(NS_FAILED(nsres) || !nsbody) {
|
|
|
|
ERR("Could not get body: %08x\n", nsres);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_SelectNodeContents(This->nsrange, (nsIDOMNode*)nsbody);
|
|
|
|
nsIDOMHTMLElement_Release(nsbody);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("Collapse failed: %08x\n", nsres);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*Success = VARIANT_TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-09-12 21:32:46 +00:00
|
|
|
default:
|
|
|
|
FIXME("Unimplemented unit %s\n", debugstr_w(Unit));
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_move(IHTMLTxtRange *iface, BSTR Unit,
|
2009-03-12 00:43:31 +00:00
|
|
|
LONG Count, LONG *ActualCount)
|
2006-07-05 20:38:15 +00:00
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2007-09-12 21:35:11 +00:00
|
|
|
range_unit_t unit;
|
|
|
|
|
2009-03-12 00:43:31 +00:00
|
|
|
TRACE("(%p)->(%s %d %p)\n", This, debugstr_w(Unit), Count, ActualCount);
|
2007-09-12 21:35:11 +00:00
|
|
|
|
|
|
|
unit = string_to_unit(Unit);
|
|
|
|
if(unit == RU_UNKNOWN)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(!Count) {
|
|
|
|
*ActualCount = 0;
|
2010-12-29 01:52:48 +00:00
|
|
|
return IHTMLTxtRange_collapse(&This->IHTMLTxtRange_iface, TRUE);
|
2007-09-12 21:35:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(unit) {
|
|
|
|
case RU_CHAR: {
|
2014-12-29 14:50:22 +00:00
|
|
|
rangepoint_t start;
|
2007-09-12 21:35:11 +00:00
|
|
|
|
2014-12-29 14:50:22 +00:00
|
|
|
get_start_point(This, &start);
|
2007-11-05 20:45:46 +00:00
|
|
|
|
2014-12-29 14:50:22 +00:00
|
|
|
*ActualCount = move_by_chars(&start, Count);
|
2007-09-12 21:35:11 +00:00
|
|
|
|
2014-12-29 14:50:22 +00:00
|
|
|
set_start_point(This, &start);
|
|
|
|
IHTMLTxtRange_collapse(&This->IHTMLTxtRange_iface, TRUE);
|
|
|
|
free_rangepoint(&start);
|
2007-09-12 21:35:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-09-12 21:36:48 +00:00
|
|
|
case RU_WORD: {
|
2014-12-29 14:50:22 +00:00
|
|
|
rangepoint_t start;
|
2007-09-12 21:36:48 +00:00
|
|
|
|
2014-12-29 14:50:22 +00:00
|
|
|
get_start_point(This, &start);
|
2007-09-12 21:36:48 +00:00
|
|
|
|
2014-12-29 14:50:22 +00:00
|
|
|
*ActualCount = move_by_words(&start, Count);
|
2007-09-12 21:36:48 +00:00
|
|
|
|
2014-12-29 14:50:22 +00:00
|
|
|
set_start_point(This, &start);
|
|
|
|
IHTMLTxtRange_collapse(&This->IHTMLTxtRange_iface, TRUE);
|
|
|
|
free_rangepoint(&start);
|
2007-09-12 21:36:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-09-12 21:35:11 +00:00
|
|
|
default:
|
|
|
|
FIXME("unimplemented unit %s\n", debugstr_w(Unit));
|
|
|
|
}
|
|
|
|
|
2009-03-12 00:43:31 +00:00
|
|
|
TRACE("ret %d\n", *ActualCount);
|
2007-09-12 21:35:11 +00:00
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_moveStart(IHTMLTxtRange *iface, BSTR Unit,
|
2009-03-12 00:43:31 +00:00
|
|
|
LONG Count, LONG *ActualCount)
|
2006-07-05 20:38:15 +00:00
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2007-10-13 23:14:40 +00:00
|
|
|
range_unit_t unit;
|
|
|
|
|
2009-03-12 00:43:31 +00:00
|
|
|
TRACE("(%p)->(%s %d %p)\n", This, debugstr_w(Unit), Count, ActualCount);
|
2007-10-13 23:14:40 +00:00
|
|
|
|
|
|
|
unit = string_to_unit(Unit);
|
|
|
|
if(unit == RU_UNKNOWN)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(!Count) {
|
|
|
|
*ActualCount = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(unit) {
|
|
|
|
case RU_CHAR: {
|
2014-12-29 14:49:47 +00:00
|
|
|
rangepoint_t start;
|
2007-10-13 23:14:40 +00:00
|
|
|
|
2014-12-29 14:49:47 +00:00
|
|
|
get_start_point(This, &start);
|
2007-10-13 23:14:40 +00:00
|
|
|
|
2014-12-29 14:49:47 +00:00
|
|
|
*ActualCount = move_by_chars(&start, Count);
|
2007-10-13 23:14:40 +00:00
|
|
|
|
2014-12-29 14:49:47 +00:00
|
|
|
set_start_point(This, &start);
|
|
|
|
free_rangepoint(&start);
|
2007-10-13 23:14:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented unit %s\n", debugstr_w(Unit));
|
2014-12-29 14:49:47 +00:00
|
|
|
return E_NOTIMPL;
|
2007-10-13 23:14:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_moveEnd(IHTMLTxtRange *iface, BSTR Unit,
|
2009-03-12 00:43:31 +00:00
|
|
|
LONG Count, LONG *ActualCount)
|
2006-07-05 20:38:15 +00:00
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2007-09-12 21:36:04 +00:00
|
|
|
range_unit_t unit;
|
|
|
|
|
2009-03-12 00:43:31 +00:00
|
|
|
TRACE("(%p)->(%s %d %p)\n", This, debugstr_w(Unit), Count, ActualCount);
|
2007-09-12 21:36:04 +00:00
|
|
|
|
|
|
|
unit = string_to_unit(Unit);
|
|
|
|
if(unit == RU_UNKNOWN)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(!Count) {
|
|
|
|
*ActualCount = 0;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(unit) {
|
|
|
|
case RU_CHAR: {
|
2014-12-29 14:50:22 +00:00
|
|
|
rangepoint_t end;
|
2007-09-12 21:36:04 +00:00
|
|
|
|
2014-12-29 14:50:22 +00:00
|
|
|
get_end_point(This, &end);
|
2007-09-12 21:36:04 +00:00
|
|
|
|
2014-12-29 14:50:22 +00:00
|
|
|
*ActualCount = move_by_chars(&end, Count);
|
2007-10-13 23:14:08 +00:00
|
|
|
|
2014-12-29 14:50:22 +00:00
|
|
|
set_end_point(This, &end);
|
|
|
|
free_rangepoint(&end);
|
2007-09-12 21:36:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("unimplemented unit %s\n", debugstr_w(Unit));
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_select(IHTMLTxtRange *iface)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2009-09-16 20:08:57 +00:00
|
|
|
nsISelection *nsselection;
|
|
|
|
nsresult nsres;
|
2007-08-17 00:39:56 +00:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2009-09-16 20:11:43 +00:00
|
|
|
nsres = nsIDOMWindow_GetSelection(This->doc->basedoc.window->nswindow, &nsselection);
|
2009-09-16 20:08:57 +00:00
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("GetSelection failed: %08x\n", nsres);
|
|
|
|
return E_FAIL;
|
2007-08-17 00:39:56 +00:00
|
|
|
}
|
|
|
|
|
2009-09-16 20:08:57 +00:00
|
|
|
nsISelection_RemoveAllRanges(nsselection);
|
|
|
|
nsISelection_AddRange(nsselection, This->nsrange);
|
|
|
|
nsISelection_Release(nsselection);
|
2007-08-17 00:39:56 +00:00
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_pasteHTML(IHTMLTxtRange *iface, BSTR html)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2014-11-12 15:25:31 +00:00
|
|
|
nsIDOMDocumentFragment *doc_frag;
|
|
|
|
nsAString nsstr;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s)\n", This, debugstr_w(html));
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_Collapse(This->nsrange, TRUE);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
nsAString_InitDepend(&nsstr, html);
|
|
|
|
nsres = nsIDOMRange_CreateContextualFragment(This->nsrange, &nsstr, &doc_frag);
|
|
|
|
nsAString_Finish(&nsstr);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("CreateContextualFragment failed: %08x\n", nsres);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_InsertNode(This->nsrange, (nsIDOMNode*)doc_frag);
|
|
|
|
nsIDOMDocumentFragment_Release(doc_frag);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("InsertNode failed: %08x\n", nsres);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_Collapse(This->nsrange, FALSE);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_moveToElementText(IHTMLTxtRange *iface, IHTMLElement *element)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2014-11-12 15:25:13 +00:00
|
|
|
HTMLElement *elem;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, element);
|
|
|
|
|
|
|
|
elem = unsafe_impl_from_IHTMLElement(element);
|
|
|
|
if(!elem)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_SelectNodeContents(This->nsrange, elem->node.nsnode);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("SelectNodeContents failed: %08x\n", nsres);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_setEndPoint(IHTMLTxtRange *iface, BSTR how,
|
|
|
|
IHTMLTxtRange *SourceRange)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2014-11-24 17:47:41 +00:00
|
|
|
HTMLTxtRange *src_range;
|
|
|
|
nsIDOMNode *ref_node;
|
|
|
|
INT32 ref_offset;
|
|
|
|
BOOL set_start;
|
|
|
|
int how_type;
|
|
|
|
INT16 cmp;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_w(how), SourceRange);
|
|
|
|
|
|
|
|
how_type = string_to_nscmptype(how);
|
|
|
|
if(how_type == -1)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
src_range = get_range_object(This->doc, SourceRange);
|
|
|
|
if(!src_range)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
switch(how_type) {
|
|
|
|
case NS_START_TO_START:
|
|
|
|
case NS_END_TO_START:
|
|
|
|
nsres = nsIDOMRange_GetStartContainer(src_range->nsrange, &ref_node);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_GetStartOffset(src_range->nsrange, &ref_offset);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
set_start = how_type == NS_START_TO_START;
|
|
|
|
break;
|
|
|
|
case NS_END_TO_END:
|
|
|
|
case NS_START_TO_END:
|
|
|
|
nsres = nsIDOMRange_GetEndContainer(src_range->nsrange, &ref_node);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_GetEndOffset(src_range->nsrange, &ref_offset);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
set_start = how_type == NS_START_TO_END;
|
|
|
|
break;
|
|
|
|
DEFAULT_UNREACHABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_ComparePoint(This->nsrange, ref_node, ref_offset, &cmp);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
if(set_start) {
|
|
|
|
if(cmp <= 0) {
|
|
|
|
nsres = nsIDOMRange_SetStart(This->nsrange, ref_node, ref_offset);
|
|
|
|
}else {
|
|
|
|
nsres = nsIDOMRange_Collapse(This->nsrange, FALSE);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_SetEnd(This->nsrange, ref_node, ref_offset);
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
if(cmp >= 0) {
|
|
|
|
nsres = nsIDOMRange_SetEnd(This->nsrange, ref_node, ref_offset);
|
|
|
|
}else {
|
|
|
|
nsres = nsIDOMRange_Collapse(This->nsrange, TRUE);
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_SetStart(This->nsrange, ref_node, ref_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(nsres == NS_OK);
|
|
|
|
|
|
|
|
nsIDOMNode_Release(ref_node);
|
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_compareEndPoints(IHTMLTxtRange *iface, BSTR how,
|
2009-03-12 00:43:31 +00:00
|
|
|
IHTMLTxtRange *SourceRange, LONG *ret)
|
2006-07-05 20:38:15 +00:00
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2007-08-17 00:40:33 +00:00
|
|
|
HTMLTxtRange *src_range;
|
2013-01-18 13:06:09 +00:00
|
|
|
short nsret = 0;
|
2007-08-17 00:40:33 +00:00
|
|
|
int nscmpt;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(how), SourceRange, ret);
|
|
|
|
|
|
|
|
nscmpt = string_to_nscmptype(how);
|
|
|
|
if(nscmpt == -1)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
src_range = get_range_object(This->doc, SourceRange);
|
|
|
|
if(!src_range)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
nsres = nsIDOMRange_CompareBoundaryPoints(This->nsrange, nscmpt, src_range->nsrange, &nsret);
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
ERR("CompareBoundaryPoints failed: %08x\n", nsres);
|
|
|
|
|
|
|
|
*ret = nsret;
|
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_findText(IHTMLTxtRange *iface, BSTR String,
|
2009-03-12 00:43:31 +00:00
|
|
|
LONG count, LONG Flags, VARIANT_BOOL *Success)
|
2006-07-05 20:38:15 +00:00
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2009-03-12 00:43:31 +00:00
|
|
|
FIXME("(%p)->(%s %d %08x %p)\n", This, debugstr_w(String), count, Flags, Success);
|
2006-07-05 20:38:15 +00:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2009-03-12 00:43:31 +00:00
|
|
|
static HRESULT WINAPI HTMLTxtRange_moveToPoint(IHTMLTxtRange *iface, LONG x, LONG y)
|
2006-07-05 20:38:15 +00:00
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2009-03-12 00:43:31 +00:00
|
|
|
FIXME("(%p)->(%d %d)\n", This, x, y);
|
2006-07-05 20:38:15 +00:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_getBookmark(IHTMLTxtRange *iface, BSTR *Bookmark)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
FIXME("(%p)->(%p)\n", This, Bookmark);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_moveToBookmark(IHTMLTxtRange *iface, BSTR Bookmark,
|
|
|
|
VARIANT_BOOL *Success)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
FIXME("(%p)->(%s %p)\n", This, debugstr_w(Bookmark), Success);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_queryCommandSupported(IHTMLTxtRange *iface, BSTR cmdID,
|
|
|
|
VARIANT_BOOL *pfRet)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_queryCommandEnabled(IHTMLTxtRange *iface, BSTR cmdID,
|
|
|
|
VARIANT_BOOL *pfRet)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_queryCommandState(IHTMLTxtRange *iface, BSTR cmdID,
|
|
|
|
VARIANT_BOOL *pfRet)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_queryCommandIndeterm(IHTMLTxtRange *iface, BSTR cmdID,
|
|
|
|
VARIANT_BOOL *pfRet)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_queryCommandText(IHTMLTxtRange *iface, BSTR cmdID,
|
|
|
|
BSTR *pcmdText)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pcmdText);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_queryCommandValue(IHTMLTxtRange *iface, BSTR cmdID,
|
|
|
|
VARIANT *pcmdValue)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pcmdValue);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_execCommand(IHTMLTxtRange *iface, BSTR cmdID,
|
|
|
|
VARIANT_BOOL showUI, VARIANT value, VARIANT_BOOL *pfRet)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
FIXME("(%p)->(%s %x v %p)\n", This, debugstr_w(cmdID), showUI, pfRet);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HTMLTxtRange_execCommandShowHelp(IHTMLTxtRange *iface, BSTR cmdID,
|
|
|
|
VARIANT_BOOL *pfRet)
|
|
|
|
{
|
2010-12-29 01:52:48 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IHTMLTxtRange(iface);
|
2006-07-05 20:38:15 +00:00
|
|
|
FIXME("(%p)->(%s %p)\n", This, debugstr_w(cmdID), pfRet);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IHTMLTxtRangeVtbl HTMLTxtRangeVtbl = {
|
|
|
|
HTMLTxtRange_QueryInterface,
|
|
|
|
HTMLTxtRange_AddRef,
|
|
|
|
HTMLTxtRange_Release,
|
|
|
|
HTMLTxtRange_GetTypeInfoCount,
|
|
|
|
HTMLTxtRange_GetTypeInfo,
|
|
|
|
HTMLTxtRange_GetIDsOfNames,
|
|
|
|
HTMLTxtRange_Invoke,
|
|
|
|
HTMLTxtRange_get_htmlText,
|
|
|
|
HTMLTxtRange_put_text,
|
|
|
|
HTMLTxtRange_get_text,
|
|
|
|
HTMLTxtRange_parentElement,
|
|
|
|
HTMLTxtRange_duplicate,
|
|
|
|
HTMLTxtRange_inRange,
|
|
|
|
HTMLTxtRange_isEqual,
|
|
|
|
HTMLTxtRange_scrollIntoView,
|
|
|
|
HTMLTxtRange_collapse,
|
|
|
|
HTMLTxtRange_expand,
|
|
|
|
HTMLTxtRange_move,
|
|
|
|
HTMLTxtRange_moveStart,
|
|
|
|
HTMLTxtRange_moveEnd,
|
|
|
|
HTMLTxtRange_select,
|
|
|
|
HTMLTxtRange_pasteHTML,
|
|
|
|
HTMLTxtRange_moveToElementText,
|
|
|
|
HTMLTxtRange_setEndPoint,
|
|
|
|
HTMLTxtRange_compareEndPoints,
|
|
|
|
HTMLTxtRange_findText,
|
|
|
|
HTMLTxtRange_moveToPoint,
|
|
|
|
HTMLTxtRange_getBookmark,
|
|
|
|
HTMLTxtRange_moveToBookmark,
|
|
|
|
HTMLTxtRange_queryCommandSupported,
|
|
|
|
HTMLTxtRange_queryCommandEnabled,
|
|
|
|
HTMLTxtRange_queryCommandState,
|
|
|
|
HTMLTxtRange_queryCommandIndeterm,
|
|
|
|
HTMLTxtRange_queryCommandText,
|
|
|
|
HTMLTxtRange_queryCommandValue,
|
|
|
|
HTMLTxtRange_execCommand,
|
|
|
|
HTMLTxtRange_execCommandShowHelp
|
|
|
|
};
|
|
|
|
|
2010-12-27 00:44:54 +00:00
|
|
|
static inline HTMLTxtRange *impl_from_IOleCommandTarget(IOleCommandTarget *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, HTMLTxtRange, IOleCommandTarget_iface);
|
|
|
|
}
|
2007-11-25 18:16:04 +00:00
|
|
|
|
|
|
|
static HRESULT WINAPI RangeCommandTarget_QueryInterface(IOleCommandTarget *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2010-12-27 00:44:54 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IOleCommandTarget(iface);
|
2010-12-29 01:52:48 +00:00
|
|
|
return IHTMLTxtRange_QueryInterface(&This->IHTMLTxtRange_iface, riid, ppv);
|
2007-11-25 18:16:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI RangeCommandTarget_AddRef(IOleCommandTarget *iface)
|
|
|
|
{
|
2010-12-27 00:44:54 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IOleCommandTarget(iface);
|
2010-12-29 01:52:48 +00:00
|
|
|
return IHTMLTxtRange_AddRef(&This->IHTMLTxtRange_iface);
|
2007-11-25 18:16:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI RangeCommandTarget_Release(IOleCommandTarget *iface)
|
|
|
|
{
|
2010-12-27 00:44:54 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IOleCommandTarget(iface);
|
2010-12-29 01:52:48 +00:00
|
|
|
return IHTMLTxtRange_Release(&This->IHTMLTxtRange_iface);
|
2007-11-25 18:16:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI RangeCommandTarget_QueryStatus(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
|
|
|
|
ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
|
|
|
|
{
|
2010-12-27 00:44:54 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IOleCommandTarget(iface);
|
2007-11-25 18:16:04 +00:00
|
|
|
FIXME("(%p)->(%s %d %p %p)\n", This, debugstr_guid(pguidCmdGroup), cCmds, prgCmds, pCmdText);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2007-12-06 11:23:22 +00:00
|
|
|
static HRESULT exec_indent(HTMLTxtRange *This, VARIANT *in, VARIANT *out)
|
|
|
|
{
|
2009-10-19 21:05:20 +00:00
|
|
|
nsIDOMHTMLElement *blockquote_elem, *p_elem;
|
2007-12-06 11:23:22 +00:00
|
|
|
nsIDOMDocumentFragment *fragment;
|
|
|
|
nsIDOMNode *tmp;
|
|
|
|
|
|
|
|
static const PRUnichar blockquoteW[] = {'B','L','O','C','K','Q','U','O','T','E',0};
|
|
|
|
static const PRUnichar pW[] = {'P',0};
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", This, in, out);
|
|
|
|
|
2009-10-21 19:27:42 +00:00
|
|
|
if(!This->doc->nsdoc) {
|
2008-10-09 20:25:23 +00:00
|
|
|
WARN("NULL nsdoc\n");
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2007-12-06 11:23:22 +00:00
|
|
|
|
2009-10-19 21:05:20 +00:00
|
|
|
create_nselem(This->doc, blockquoteW, &blockquote_elem);
|
|
|
|
create_nselem(This->doc, pW, &p_elem);
|
2007-12-06 11:23:22 +00:00
|
|
|
|
|
|
|
nsIDOMRange_ExtractContents(This->nsrange, &fragment);
|
2012-07-26 09:37:48 +00:00
|
|
|
nsIDOMHTMLElement_AppendChild(p_elem, (nsIDOMNode*)fragment, &tmp);
|
2007-12-06 11:23:22 +00:00
|
|
|
nsIDOMDocumentFragment_Release(fragment);
|
|
|
|
nsIDOMNode_Release(tmp);
|
|
|
|
|
2012-07-26 09:37:48 +00:00
|
|
|
nsIDOMHTMLElement_AppendChild(blockquote_elem, (nsIDOMNode*)p_elem, &tmp);
|
|
|
|
nsIDOMHTMLElement_Release(p_elem);
|
2007-12-06 11:23:22 +00:00
|
|
|
nsIDOMNode_Release(tmp);
|
|
|
|
|
|
|
|
nsIDOMRange_InsertNode(This->nsrange, (nsIDOMNode*)blockquote_elem);
|
2012-07-26 09:37:48 +00:00
|
|
|
nsIDOMHTMLElement_Release(blockquote_elem);
|
2007-12-06 11:23:22 +00:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2007-11-25 18:16:04 +00:00
|
|
|
static HRESULT WINAPI RangeCommandTarget_Exec(IOleCommandTarget *iface, const GUID *pguidCmdGroup,
|
|
|
|
DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
|
|
|
|
{
|
2010-12-27 00:44:54 +00:00
|
|
|
HTMLTxtRange *This = impl_from_IOleCommandTarget(iface);
|
2007-12-06 11:23:22 +00:00
|
|
|
|
2007-11-25 18:16:04 +00:00
|
|
|
TRACE("(%p)->(%s %d %x %p %p)\n", This, debugstr_guid(pguidCmdGroup), nCmdID,
|
|
|
|
nCmdexecopt, pvaIn, pvaOut);
|
|
|
|
|
|
|
|
if(pguidCmdGroup && IsEqualGUID(&CGID_MSHTML, pguidCmdGroup)) {
|
2007-12-06 11:23:22 +00:00
|
|
|
switch(nCmdID) {
|
|
|
|
case IDM_INDENT:
|
|
|
|
return exec_indent(This, pvaIn, pvaOut);
|
|
|
|
default:
|
|
|
|
FIXME("Unsupported cmdid %d of CGID_MSHTML\n", nCmdID);
|
|
|
|
}
|
2007-11-25 18:16:04 +00:00
|
|
|
}else {
|
|
|
|
FIXME("Unsupported cmd %d of group %s\n", nCmdID, debugstr_guid(pguidCmdGroup));
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IOleCommandTargetVtbl OleCommandTargetVtbl = {
|
|
|
|
RangeCommandTarget_QueryInterface,
|
|
|
|
RangeCommandTarget_AddRef,
|
|
|
|
RangeCommandTarget_Release,
|
|
|
|
RangeCommandTarget_QueryStatus,
|
|
|
|
RangeCommandTarget_Exec
|
|
|
|
};
|
|
|
|
|
2014-11-11 09:55:34 +00:00
|
|
|
static const tid_t HTMLTxtRange_iface_tids[] = {
|
|
|
|
IHTMLTxtRange_tid,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
static dispex_static_data_t HTMLTxtRange_dispex = {
|
|
|
|
NULL,
|
|
|
|
IHTMLTxtRange_tid,
|
|
|
|
NULL,
|
|
|
|
HTMLTxtRange_iface_tids
|
|
|
|
};
|
|
|
|
|
2009-09-16 20:11:43 +00:00
|
|
|
HRESULT HTMLTxtRange_Create(HTMLDocumentNode *doc, nsIDOMRange *nsrange, IHTMLTxtRange **p)
|
2006-07-05 20:38:15 +00:00
|
|
|
{
|
2009-09-16 20:11:43 +00:00
|
|
|
HTMLTxtRange *ret;
|
|
|
|
|
|
|
|
ret = heap_alloc(sizeof(HTMLTxtRange));
|
|
|
|
if(!ret)
|
|
|
|
return E_OUTOFMEMORY;
|
2006-07-05 20:38:15 +00:00
|
|
|
|
2014-11-11 09:55:34 +00:00
|
|
|
init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLTxtRange_iface, &HTMLTxtRange_dispex);
|
|
|
|
|
2010-12-29 01:52:48 +00:00
|
|
|
ret->IHTMLTxtRange_iface.lpVtbl = &HTMLTxtRangeVtbl;
|
2010-12-27 00:44:54 +00:00
|
|
|
ret->IOleCommandTarget_iface.lpVtbl = &OleCommandTargetVtbl;
|
2006-07-05 20:38:15 +00:00
|
|
|
ret->ref = 1;
|
|
|
|
|
2007-05-09 22:32:48 +00:00
|
|
|
if(nsrange)
|
|
|
|
nsIDOMRange_AddRef(nsrange);
|
|
|
|
ret->nsrange = nsrange;
|
2006-07-05 20:38:15 +00:00
|
|
|
|
2007-08-17 00:37:01 +00:00
|
|
|
ret->doc = doc;
|
|
|
|
list_add_head(&doc->range_list, &ret->entry);
|
|
|
|
|
2010-12-29 01:52:48 +00:00
|
|
|
*p = &ret->IHTMLTxtRange_iface;
|
2009-09-16 20:11:43 +00:00
|
|
|
return S_OK;
|
2006-07-05 20:38:15 +00:00
|
|
|
}
|
2007-08-17 00:37:01 +00:00
|
|
|
|
2009-09-16 20:11:43 +00:00
|
|
|
void detach_ranges(HTMLDocumentNode *This)
|
2007-08-17 00:37:01 +00:00
|
|
|
{
|
|
|
|
HTMLTxtRange *iter;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY(iter, &This->range_list, HTMLTxtRange, entry) {
|
|
|
|
iter->doc = NULL;
|
|
|
|
}
|
|
|
|
}
|