Esempio n. 1
0
void RenderImage::caretPos(int offset, int flags, int &_x, int &_y, int &width, int &height) const
{
    RenderReplaced::caretPos(offset, flags, _x, _y, width, height);

#if 0	// doesn't work reliably
    height = intrinsicHeight();
    width = override && offset == 0 ? intrinsicWidth() : 0;
    _x = xPos();
    _y = yPos();
    if (offset > 0) _x += intrinsicWidth();

    RenderObject *cb = containingBlock();

    int absx, absy;
    if (cb && cb != this && cb->absolutePosition(absx,absy))
    {
        _x += absx;
        _y += absy;
    } else {
        // we don't know our absolute position, and there is no point returning
        // just a relative one
        _x = _y = -1;
    }
#endif
}
VisiblePosition RenderContainer::positionForCoordinates(int _x, int _y)
{
    // no children...return this render object's element, if there is one, and offset 0
    if (!firstChild())
        return VisiblePosition(element(), 0, DOWNSTREAM);

    // look for the geometrically-closest child and pass off to that child
    int min = INT_MAX;
    RenderObject *closestRenderer = 0;
    for (RenderObject *renderer = firstChild(); renderer; renderer = renderer->nextSibling()) {
        if (!renderer->firstChild() && !renderer->isInline() && !renderer->isBlockFlow())
            continue;

        int absx, absy;
        renderer->absolutePosition(absx, absy);
        
        int top = absy + borderTop() + paddingTop();
        int bottom = top + renderer->contentHeight();
        int left = absx + borderLeft() + paddingLeft();
        int right = left + renderer->contentWidth();
        
        int cmp;
        cmp = abs(_y - top);    if (cmp < min) { closestRenderer = renderer; min = cmp; }
        cmp = abs(_y - bottom); if (cmp < min) { closestRenderer = renderer; min = cmp; }
        cmp = abs(_x - left);   if (cmp < min) { closestRenderer = renderer; min = cmp; }
        cmp = abs(_x - right);  if (cmp < min) { closestRenderer = renderer; min = cmp; }
    }
    
    if (closestRenderer)
        return closestRenderer->positionForCoordinates(_x, _y);
    
    return VisiblePosition(element(), 0, DOWNSTREAM);
}
// I don't like this way of implementing the method, but I didn't find any
// other way. Lars
bool NodeBaseImpl::getUpperLeftCorner(int &xPos, int &yPos) const
{
    if (!m_render)
	return false;
    RenderObject *o = m_render;
    o->absolutePosition( xPos, yPos );
    if ( !isInline() )
	return true;

    // find the next text/image child, to get a position
    while(o) {
	if(o->firstChild())
	    o = o->firstChild();
	else if(o->nextSibling())
	    o = o->nextSibling();
	else {
	    RenderObject *next = 0;
	    while(!next) {
		o = o->parent();
		if(!o) return false;
		next = o->nextSibling();
	    }
	    o = next;
	}
	if(o->isText() || o->isReplaced()) {
	    if (o->isText())
		xPos += static_cast<RenderText *>(o)->minXPos();
	    else
		xPos += o->xPos();
	    yPos += o->yPos();
	    return true;
	}
    }
    return true;
}
Esempio n. 4
0
int HTMLImageElement::y() const
{
    RenderObject* r = renderer();
    if (!r)
        return 0;
    int x, y;
    r->absolutePosition(x, y);
    return y;
}
Esempio n. 5
0
static QRect enclosingPositionedRect (RenderObject *n)
{
    RenderObject *enclosingParent =  n->containingBlock();
    QRect rect(0,0,0,0);
    if (enclosingParent) {
        int ox, oy;
        enclosingParent->absolutePosition(ox, oy);
        int off = 0;
        if (!enclosingParent->hasOverflowClip()) {
            ox += enclosingParent->overflowLeft();
            oy += enclosingParent->overflowTop();
        }
        rect.setX(ox);
        rect.setY(oy);
        rect.setWidth(enclosingParent->effectiveWidth());
        rect.setHeight(enclosingParent->effectiveHeight());
    }
    return rect;
}
bool NodeBaseImpl::getLowerRightCorner(int &xPos, int &yPos) const
{
    if (!m_render)
	return false;

    RenderObject *o = m_render;
    o->absolutePosition( xPos, yPos );
    if (!isInline())
    {
	xPos += o->width();
	yPos += o->height();
	return true;
    }
    // find the last text/image child, to get a position
    while(o) {
	if(o->lastChild())
	    o = o->lastChild();
	else if(o->previousSibling())
	    o = o->previousSibling();
	else {
	    RenderObject *prev = 0;
	    while(!prev) {
		o = o->parent();
		if(!o) return false;
		prev = o->previousSibling();
	    }
	    o = prev;
	}
	if(o->isText() || o->isReplaced()) {
	    if (o->isText())
		xPos += static_cast<RenderText *>(o)->minXPos() + o->width();
	    else
		xPos += o->xPos()+o->intrinsicWidth();
	    yPos += o->yPos()+o->height();
	    return true;
	}
    }
    return true;
}