mshtml: Added IHTMLTxtRange::move("word") implementation.

This commit is contained in:
Jacek Caban 2007-09-12 23:36:48 +02:00 committed by Alexandre Julliard
parent d6c14fba3e
commit 964479afa9
2 changed files with 114 additions and 1 deletions

View File

@ -268,6 +268,56 @@ static void test_txtrange(IHTMLDocument2 *doc)
test_range_moveend(range, characterW, 2, 2);
test_range_text(range, "123\r\ni");
hres = IHTMLTxtRange_duplicate(body_range, &range);
ok(hres == S_OK, "duplicate failed: %08x\n", hres);
test_range_move(range, wordW, 1, 1);
test_range_moveend(range, characterW, 2, 2);
test_range_text(range, "ab");
test_range_move(range, characterW, -2, -2);
test_range_moveend(range, characterW, 2, 2);
test_range_text(range, "t ");
test_range_move(range, wordW, 3, 3);
test_range_move(range, wordW, -2, -2);
test_range_moveend(range, characterW, 2, 2);
test_range_text(range, "ab");
test_range_move(range, characterW, -6, -5);
test_range_moveend(range, characterW, -1, 0);
test_range_moveend(range, characterW, -6, 0);
test_range_move(range, characterW, 2, 2);
test_range_moveend(range, characterW, 2, 2);
test_range_text(range, "st");
test_range_moveend(range, characterW, -6, -4);
test_range_moveend(range, characterW, 2, 2);
IHTMLTxtRange_Release(range);
hres = IHTMLTxtRange_duplicate(body_range, &range);
ok(hres == S_OK, "duplicate failed: %08x\n", hres);
test_range_move(range, wordW, 2, 2);
test_range_moveend(range, characterW, 2, 2);
test_range_text(range, "12");
test_range_move(range, characterW, 15, 14);
test_range_move(range, characterW, -2, -2);
test_range_moveend(range, characterW, 3, 2);
test_range_text(range, "t");
test_range_moveend(range, characterW, -1, -1);
test_range_text(range, "t");
test_range_expand(range, wordW, VARIANT_TRUE, "text");
test_range_move(range, characterW, -2, -2);
test_range_moveend(range, characterW, 2, 2);
test_range_text(range, "s ");
test_range_move(range, characterW, 100, 7);
test_range_move(range, wordW, 1, 0);
test_range_move(range, characterW, -2, -2);
test_range_moveend(range, characterW, 3, 2);
test_range_text(range, "t");
IHTMLTxtRange_Release(range);
IHTMLTxtRange_Release(body_range);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2006 Jacek Caban for CodeWeavers
* Copyright 2006-2007 Jacek Caban for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -689,6 +689,48 @@ static long find_prev_space(HTMLTxtRange *This, const dompos_t *pos, BOOL first_
return TRUE;
}
static long move_next_words(long cnt, const dompos_t *pos, dompos_t *new_pos)
{
dompos_t iter, tmp;
long ret = 0;
iter = *pos;
dompos_addref(&iter);
while(ret < cnt) {
if(!find_next_space(&iter, FALSE, &tmp))
break;
ret++;
dompos_release(&iter);
iter = tmp;
}
*new_pos = iter;
return ret;
}
static long move_prev_words(HTMLTxtRange *This, long cnt, const dompos_t *pos, dompos_t *new_pos)
{
dompos_t iter, tmp;
long ret = 0;
iter = *pos;
dompos_addref(&iter);
while(ret < cnt) {
if(!find_prev_space(This, &iter, FALSE, &tmp))
break;
dompos_release(&iter);
iter = tmp;
ret++;
}
*new_pos = iter;
return ret;
}
#define HTMLTXTRANGE_THIS(iface) DEFINE_THIS(HTMLTxtRange, HTMLTxtRange, iface)
static HRESULT WINAPI HTMLTxtRange_QueryInterface(IHTMLTxtRange *iface, REFIID riid, void **ppv)
@ -1075,6 +1117,27 @@ static HRESULT WINAPI HTMLTxtRange_move(IHTMLTxtRange *iface, BSTR Unit,
break;
}
case RU_WORD: {
dompos_t cur_pos, new_pos;
get_cur_pos(This, TRUE, &cur_pos);
if(Count > 0) {
*ActualCount = move_next_words(Count, &cur_pos, &new_pos);
set_range_pos(This, FALSE, &new_pos);
IHTMLTxtRange_collapse(HTMLTXTRANGE(This), FALSE);
dompos_release(&new_pos);
}else {
*ActualCount = -move_prev_words(This, -Count, &cur_pos, &new_pos);
set_range_pos(This, TRUE, &new_pos);
IHTMLTxtRange_collapse(HTMLTXTRANGE(This), TRUE);
dompos_release(&new_pos);
}
dompos_release(&cur_pos);
break;
}
default:
FIXME("unimplemented unit %s\n", debugstr_w(Unit));
}