From: darin Date: Fri, 22 Apr 2005 16:29:51 +0000 (+0000) Subject: Reviewed by John. X-Git-Url: https://git.webkit.org/?p=WebKit-https.git;a=commitdiff_plain;h=549618cc15a16407016869a219efa3804cb53905 Reviewed by John. - a small editing-related code cleanup * khtml/rendering/render_text.h: Added positionForOffset and made offsetForPosition const. * khtml/rendering/render_text.cpp: (InlineTextBox::offsetForPosition): Made const. (InlineTextBox::positionForOffset): Added. Moved code here from caretRect. (RenderText::caretRect): Call positionForOffset instead of doing the work here. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@9037 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23 index 29aa31c8c125..ebefa8317bb6 100644 --- a/WebCore/ChangeLog-2005-08-23 +++ b/WebCore/ChangeLog-2005-08-23 @@ -1,3 +1,15 @@ +2005-04-22 Darin Adler + + Reviewed by John. + + - a small editing-related code cleanup + + * khtml/rendering/render_text.h: Added positionForOffset and made offsetForPosition const. + * khtml/rendering/render_text.cpp: + (InlineTextBox::offsetForPosition): Made const. + (InlineTextBox::positionForOffset): Added. Moved code here from caretRect. + (RenderText::caretRect): Call positionForOffset instead of doing the work here. + 2005-04-21 David Hyatt Fix for 4095839, wrong background image used on flechtwerk.de. Make sure that the global mapped diff --git a/WebCore/khtml/rendering/render_text.cpp b/WebCore/khtml/rendering/render_text.cpp index b66f61cd8c43..778e5758df1c 100644 --- a/WebCore/khtml/rendering/render_text.cpp +++ b/WebCore/khtml/rendering/render_text.cpp @@ -739,15 +739,32 @@ long RenderText::nextOffset (long current) const return current + 1; } -#define LOCAL_WIDTH_BUF_SIZE 1024 - -int InlineTextBox::offsetForPosition(int _x, bool includePartialGlyphs) +int InlineTextBox::offsetForPosition(int _x, bool includePartialGlyphs) const { RenderText* text = static_cast(m_object); const Font* f = text->htmlFont(m_firstLine); return f->checkSelectionPoint(text->str->s, text->str->l, m_start, m_len, m_toAdd, _x - m_x, m_reversed, includePartialGlyphs); } +int InlineTextBox::positionForOffset(int offset) const +{ + RenderText *text = static_cast(m_object); + const QFontMetrics &fm = text->metrics(m_firstLine); + + int left; + if (m_reversed) { + long len = m_start + m_len - offset; + QString string(text->str->s + offset, len); + left = m_x + fm.boundingRect(string, len).right(); + } else { + long len = offset - m_start; + QString string(text->str->s + m_start, len); + left = m_x + fm.boundingRect(string, len).right(); + } + // FIXME: Do we need to add rightBearing here? + return left; +} + // ------------------------------------------------------------------------------------- RenderText::RenderText(DOM::NodeImpl* node, DOMStringImpl *_str) @@ -1063,17 +1080,7 @@ QRect RenderText::caretRect(int offset, EAffinity affinity, int *extraWidthToEnd int height = box->root()->bottomOverflow() - box->root()->topOverflow(); int top = box->root()->topOverflow(); - const QFontMetrics &fm = metrics(box->isFirstLineStyle()); - int left; - if (box->m_reversed) { - long len = box->m_start+box->m_len-offset; - QString string(str->s +offset,len); - left = box->m_x + fm.boundingRect(string,len).right(); - } else { - long len = offset - box->m_start; // the number of characters we are into the string - QString string(str->s + box->m_start,len); - left = box->m_x + fm.boundingRect(string,len).right(); - } + int left = box->positionForOffset(offset); // FIXME: should we use the width of the root inline box or the // width of the containing block for this? diff --git a/WebCore/khtml/rendering/render_text.h b/WebCore/khtml/rendering/render_text.h index 2e833615d8cb..d3d2ad38ceda 100644 --- a/WebCore/khtml/rendering/render_text.h +++ b/WebCore/khtml/rendering/render_text.h @@ -124,7 +124,8 @@ public: virtual long caretMaxOffset() const; virtual unsigned long caretMaxRenderedOffset() const; - int offsetForPosition(int _x, bool includePartialGlyphs = true); + int offsetForPosition(int _x, bool includePartialGlyphs = true) const; + int positionForOffset(int offset) const; /** * if this text run was rendered @ref _ty pixels below the upper edge