From kfm-devel Mon Mar 27 18:36:40 2000 From: Lars Knoll Date: Mon, 27 Mar 2000 18:36:40 +0000 To: kfm-devel Subject: Re: khtml, kbackpage stuff X-MARC-Message: https://marc.info/?l=kfm-devel&m=95418225526682 On Mon, 27 Mar 2000, Frederik Holljen wrote: > Hi, > > I'm having some trouble positioning the cursor in our editor. Positioning > within the text node seems to work fine, so the problem is getting the correct > x, y position of the surrounding block.(cursor inside a

seems to work, but > in lists and tables it misses the text completely) So, I have a couple of > questions (to try and sort this out in my head :) > > 1. How does a

get rendered. (what sort of rendering object) Allmost all regular elements (including

) get mapped to a RenderFlow in the rendering tree. > 2. The x, y position of the texts containingBlock() are they absolute, or > relative to something else? (another more toplevel containgBlock perhaps) The x and y positions are always relative to the objects parent, except for the root object (RenderRoot). This makes it possible to move a subtree around in the scrollview, without needing a relayout. If you need the absolute position, there's a method absolutePosition(int &x, int&y) in RenderObject. > 3. Any special treatments that have to be done for text inside tables? No. > I've included the current code (at least on my computer) in case you wanted to > look at it. And for those who are interested: the kbackpage code can now be > found in kdenonbeta (it should even compile :D ) > > Cheers, > Frederik > > > void RenderText::cursorPos(int offset, int &_x, int &_y, int &height) > { > //FIXME! This is possibly incorrect.... - _x = ( (RenderBox*)containingBlock() )->xPos(); - _y = ( (RenderBox*)containingBlock() )->yPos(); + absolutePosition(x, y); ... and things should be working ;-) Lars > > TextSlave *s = m_first; > int off = s->len; > int y = s->y; > > while(offset > off) > { > s=s->next(); > off += s->len; > if( s->y != y ) // ugly hack to fix problem with space removal on line wrap > { > y = s->y; > offset--; > } > } // we are now in the correct text slave > > int pos = s->len - (off - offset ); > _y += s->y; > height = s->m_height; > > QString tekst(s->m_text, s->len); > _x += s->x + (fm->boundingRect(tekst, pos)).right(); > if(pos) > _x += fm->rightBearing( *(s->m_text + pos - 1 ) ); > } > > -- Lars Knoll knoll@mpi-hd.mpg.de PGP pub key [6DADF3D5]: finger knoll@pluto.mpi-hd.mpg.de