return ilbs;
}
ViewModelInfo infoFromPoint(MouseEvent e) {
checkDocument();
Range r = docRange.createRange();
InlineText fndTxt = null;
Box box = panel.getRootLayer().find(panel.getLayoutContext(), e.getX(), e.getY(), true);
if (box == null) {
return null;
}
Element elt = null;
int offset = 0;
InlineLayoutBox ilb = null;
boolean containsWholeIlb = false;
if (box instanceof InlineLayoutBox) {
ilb = (InlineLayoutBox) box;
} else {
for (; ilb == null;) {
List ilbs = getInlineLayoutBoxes(box, false);
for (int i = ilbs.size() - 1; i >= 0; i--) {
InlineLayoutBox ilbt = (InlineLayoutBox) ilbs.get(i);
if (ilbt.getAbsY() <= e.getY() && ilbt.getAbsX() <= e.getX()) {
if (ilb == null || (ilbt.getAbsY() > ilb.getAbsY())
|| (ilbt.getAbsY() == ilb.getAbsY() && ilbt.getX() > ilb.getX())) {
if (ilbt.isContainsVisibleContent()) {
boolean hasDecentTextNode = false;
int x = ilbt.getAbsX();
for (Iterator it = ilbt.getInlineChildren().iterator(); it
.hasNext();) {
Object o = it.next();
if (o instanceof InlineText) {
InlineText txt = (InlineText) o;
if (txt.getTextNode() != null) {
hasDecentTextNode = true;
break;
}
}
}
if (hasDecentTextNode) {
ilb = ilbt;
}
}
}
containsWholeIlb = true;
}
}
if (ilb == null) {
if (box.getParent() == null) {
return null;
}
box = box.getParent();
}
}
}
int x = ilb.getAbsX();
InlineText lastItxt = null;
for (Iterator it = ilb.getInlineChildren().iterator(); it.hasNext();) {
Object o = it.next();
if (o instanceof InlineText) {
InlineText txt = (InlineText) o;
if (txt.getTextNode() != null) {
if ((e.getX() >= x + txt.getX() && e.getX() < x + txt.getX() + txt.getWidth())
|| containsWholeIlb) {
fndTxt = txt;
break;
} else {
if (e.getX() < x + txt.getX()) {
// assume inline image or somesuch
if (lastItxt != null) {
fndTxt = lastItxt;
break;
}
}
}
}
lastItxt = txt;
}
}
LayoutContext lc = panel.getLayoutContext();
if (fndTxt == null) {
// TODO: need general debug flag here; not sure if this is an error condition and if the logging is necessary
if (false) {
XRLog.general(Level.FINE, ilb.dump(lc, "", Box.DUMP_RENDER));
XRLog.general(Level.FINE, ilb.getParent().dump(lc, "", Box.DUMP_RENDER));
XRLog.general(Level.FINE, ilb.getParent().getParent().dump(lc, "", Box.DUMP_RENDER));
}
return null;
}
String txt = fndTxt.getMasterText();
CalculatedStyle style = ilb.getStyle();
if (containsWholeIlb) {
offset = fndTxt.getEnd();
} else {
for (offset = fndTxt.getStart(); offset < fndTxt.getEnd(); offset++) {
int w = getTextWidth(lc, style, txt.substring(fndTxt.getStart(), offset + 1));
if (w + x + fndTxt.getX() > e.getX()) {
break;
}
}
}
Node node = fndTxt.getTextNode();
try {
r.setStart(node, offset);
} catch (Exception ex) {
// maybe differs for dom impl? anyway, fix for issue 216
r.setStart(node, ((Text) node).getLength() - 1);
}
return new ViewModelInfo(r, fndTxt);
}