Skip to content

Commit 7961f94

Browse files
committed
avoid usage of range - this is not supported on android
1 parent bc488cd commit 7961f94

8 files changed

Lines changed: 213 additions & 205 deletions

File tree

src/main/java/org/htmlunit/html/HtmlPage.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
import org.w3c.dom.Element;
111111
import org.w3c.dom.EntityReference;
112112
import org.w3c.dom.ProcessingInstruction;
113-
import org.w3c.dom.ranges.Range;
114113

115114
/**
116115
* A representation of an HTML page returned from a server.
@@ -182,7 +181,7 @@ public class HtmlPage extends SgmlPage {
182181
private List<AutoCloseable> autoCloseableList_;
183182
private ElementFromPointHandler elementFromPointHandler_;
184183
private DomElement elementWithFocus_;
185-
private List<Range> selectionRanges_ = new ArrayList<>(3);
184+
private List<SimpleRange> selectionRanges_ = new ArrayList<>(3);
186185

187186
private transient ComputedStylesCache computedStylesCache_;
188187

@@ -2520,7 +2519,7 @@ public boolean setFocusedElement(final DomElement newElement, final boolean wind
25202519
if (newElement instanceof SelectableTextInput
25212520
&& hasFeature(PAGE_SELECTION_RANGE_FROM_SELECTABLE_TEXT_INPUT)) {
25222521
final SelectableTextInput sti = (SelectableTextInput) newElement;
2523-
setSelectionRange(new SimpleRange(sti, sti.getSelectionStart(), sti, sti.getSelectionEnd()));
2522+
setSelectionRange(new SimpleRange(newElement, sti.getSelectionStart(), newElement, sti.getSelectionEnd()));
25242523
}
25252524

25262525
if (newElement != null) {
@@ -2574,7 +2573,7 @@ public void setElementWithFocus(final DomElement elementWithFocus) {
25742573
*
25752574
* @return the page's current selection ranges
25762575
*/
2577-
public List<Range> getSelectionRanges() {
2576+
public List<SimpleRange> getSelectionRanges() {
25782577
return selectionRanges_;
25792578
}
25802579

@@ -2585,7 +2584,7 @@ public List<Range> getSelectionRanges() {
25852584
*
25862585
* @param selectionRange the selection range
25872586
*/
2588-
public void setSelectionRange(final Range selectionRange) {
2587+
public void setSelectionRange(final SimpleRange selectionRange) {
25892588
selectionRanges_.clear();
25902589
selectionRanges_.add(selectionRange);
25912590
}

src/main/java/org/htmlunit/html/impl/SelectableTextSelectionDelegate.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import static org.htmlunit.BrowserVersionFeatures.JS_INPUT_IGNORE_NEGATIVE_SELECTION_START;
1818

19-
import org.w3c.dom.ranges.Range;
19+
import org.htmlunit.html.DomNode;
2020

2121
/**
2222
* Contains standard selection-related functionality used by various input elements.
@@ -36,15 +36,15 @@ public class SelectableTextSelectionDelegate implements SelectionDelegate {
3636
private final SelectableTextInput element_;
3737

3838
/** The field selection, which is independent of the browsing context's selection. */
39-
private final Range selection_;
39+
private final SimpleRange selection_;
4040

4141
/**
4242
* Creates a new instance for the specified element.
4343
* @param element the owner element
4444
*/
4545
public SelectableTextSelectionDelegate(final SelectableTextInput element) {
4646
element_ = element;
47-
selection_ = new SimpleRange(element, 0);
47+
selection_ = new SimpleRange((DomNode) element, 0);
4848
}
4949

5050
/**
@@ -85,9 +85,9 @@ public void setSelectionStart(int selectionStart) {
8585

8686
final int length = element_.getText().length();
8787
selectionStart = Math.max(0, Math.min(selectionStart, length));
88-
selection_.setStart(element_, selectionStart);
88+
selection_.setStart((DomNode) element_, selectionStart);
8989
if (selection_.getEndOffset() < selectionStart) {
90-
selection_.setEnd(element_, selectionStart);
90+
selection_.setEnd((DomNode) element_, selectionStart);
9191
}
9292
}
9393

@@ -106,9 +106,9 @@ public int getSelectionEnd() {
106106
public void setSelectionEnd(int selectionEnd) {
107107
final int length = element_.getText().length();
108108
selectionEnd = Math.min(length, Math.max(selectionEnd, 0));
109-
selection_.setEnd(element_, selectionEnd);
109+
selection_.setEnd((DomNode) element_, selectionEnd);
110110
if (selection_.getStartOffset() > selectionEnd) {
111-
selection_.setStart(element_, selectionEnd);
111+
selection_.setStart((DomNode) element_, selectionEnd);
112112
}
113113
}
114114
}

0 commit comments

Comments
 (0)