summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Iacovitti <aiacovitti@libero.it>2012-06-18 05:04:37 (GMT)
committerAndrea Iacovitti <aiacovitti@libero.it>2012-06-18 05:04:37 (GMT)
commit31ce1f9365000d7c3a9c39770234aa09009a2599 (patch)
tree61f8edf98f997bc252309fe672e26a7b73587e31
parent95ccc85ae312453bf68c0fb48025c5dab21faa81 (diff)
Fix applying css text-align property on textarea widget:
- set text alignment on all textarea's paragraphs, not only the current one (aka the one at the current cursor position). - do not set at every setStyle call but only when it has changed (doing the same for lineedit widget). Also fix annoying behavior where initial content of pre-filled textarea is showed up all scrolled down to end. BUG: 302070
-rw-r--r--khtml/rendering/render_form.cpp83
-rw-r--r--khtml/rendering/render_form.h5
2 files changed, 47 insertions, 41 deletions
diff --git a/khtml/rendering/render_form.cpp b/khtml/rendering/render_form.cpp
index 0a12ba7..108845b 100644
--- a/khtml/rendering/render_form.cpp
+++ b/khtml/rendering/render_form.cpp
@@ -357,8 +357,7 @@ void RenderFormElement::layout()
setNeedsLayout(false);
}
-
-Qt::AlignmentFlag RenderFormElement::textAlignment() const
+Qt::Alignment RenderFormElement::textAlignment() const
{
switch (style()->textAlign()) {
case LEFT:
@@ -1104,7 +1103,8 @@ void RenderLineEdit::setStyle(RenderStyle* _style)
{
RenderFormElement::setStyle( _style );
- widget()->setAlignment(textAlignment());
+ if (widget()->alignment() != textAlignment())
+ widget()->setAlignment(textAlignment());
bool showClearButton = (!shouldDisableNativeBorders() && !_style->hasBackgroundImage());
@@ -2153,22 +2153,18 @@ TextAreaWidget::TextAreaWidget(int wrap, QWidget* parent)
KCursor::setAutoHideCursor(viewport(), true);
setAcceptRichText (false);
setMouseTracking(true);
+}
+TextAreaWidget::~TextAreaWidget()
+{
}
void TextAreaWidget::scrollContentsBy( int dx, int dy )
{
KTextEdit::scrollContentsBy(dx, dy);
update();
-
-}
-
-TextAreaWidget::~TextAreaWidget()
-{
}
-
-
bool TextAreaWidget::event( QEvent *e )
{
#if 0
@@ -2228,6 +2224,7 @@ RenderTextArea::RenderTextArea(HTMLTextAreaElementImpl *element)
connect(edit,SIGNAL(textChanged()),this,SLOT(slotTextChanged()));
setText(element->value().string());
+ m_textAlignment = edit->alignment();
}
RenderTextArea::~RenderTextArea()
@@ -2288,18 +2285,29 @@ void RenderTextArea::calcMinMaxWidth()
void RenderTextArea::setStyle(RenderStyle* _style)
{
- bool unsubmittedFormChange = element()->m_unsubmittedFormChange;
-
RenderFormElement::setStyle(_style);
- bool blocked = widget()->blockSignals(true);
- widget()->setAlignment(textAlignment());
- widget()->blockSignals(blocked);
+ TextAreaWidget* w = static_cast<TextAreaWidget*>(m_widget);
+
+ if (m_textAlignment != textAlignment()) {
+ m_textAlignment = textAlignment();
+ bool unsubmittedFormChange = element()->m_unsubmittedFormChange;
+ bool blocked = w->blockSignals(true);
+ int cx = w->horizontalScrollBar()->value();
+ int cy = w->verticalScrollBar()->value();
+ QTextCursor tc = w->textCursor();
+ // Set alignment on all textarea's paragraphs
+ w->selectAll();
+ w->setAlignment(m_textAlignment);
+ w->setTextCursor(tc);
+ w->horizontalScrollBar()->setValue(cx);
+ w->verticalScrollBar()->setValue(cy);
+ w->blockSignals(blocked);
+ element()->m_unsubmittedFormChange = unsubmittedFormChange;
+ }
scrollbarsStyled = false;
- element()->m_unsubmittedFormChange = unsubmittedFormChange;
- TextAreaWidget* w = static_cast<TextAreaWidget*>(m_widget);
if (style()->overflowX() == OSCROLL)
w->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
else if (style()->overflowX() == OHIDDEN)
@@ -2347,33 +2355,30 @@ void RenderTextArea::setText(const QString& newText)
// When this is called, m_value in the element must have just
// been set to new value --- see if we have any work to do
- if ( newText != text() ) {
+
+ QString oldText = text();
+ int oldTextLen = oldText.length();
+ int newTextLen = newText.length();
+ if (newTextLen != oldTextLen || newText != oldText) {
bool blocked = w->blockSignals(true);
- QTextCursor tc = w->textCursor();
- bool atEnd = tc.atEnd();
- bool atStart = tc.atStart();
int cx = w->horizontalScrollBar()->value();
int cy = w->verticalScrollBar()->value();
- QString oldText = w->toPlainText();
+ // Not using setPlaintext as it resets text alignment property
int ex = 0;
- int otl = oldText.length();
- if (otl && newText.length() > otl) {
- while (ex < otl && newText[ex] == oldText[ex])
- ++ex;
- QTextCursor tc(w->document());
- tc.setPosition( ex, QTextCursor::MoveAnchor );
- tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
- tc.insertText(newText.right( newText.length()-ex ));
- } else {
- w->setPlainText( newText );
- }
+ while (ex < oldTextLen && newText[ex] == oldText[ex])
+ ++ex;
+ QTextCursor tc = w->textCursor();
+ tc.setPosition(ex, QTextCursor::MoveAnchor);
+ tc.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
+ tc.insertText(newText.right(newTextLen - ex));
+
+ if (oldTextLen == 0)
+ tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
+ else
+ tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
w->setTextCursor(tc);
- if (atEnd)
- tc.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
- else if (atStart)
- tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
- w->horizontalScrollBar()->setValue( cx );
- w->verticalScrollBar()->setValue( cy );
+ w->horizontalScrollBar()->setValue(cx);
+ w->verticalScrollBar()->setValue(cy);
w->blockSignals(blocked);
}
}
diff --git a/khtml/rendering/render_form.h b/khtml/rendering/render_form.h
index 2d849b9..4fe90e3 100644
--- a/khtml/rendering/render_form.h
+++ b/khtml/rendering/render_form.h
@@ -96,7 +96,7 @@ public:
protected:
virtual bool isRenderButton() const { return false; }
virtual bool isEditable() const { return false; }
- Qt::AlignmentFlag textAlignment() const;
+ Qt::Alignment textAlignment() const;
virtual void setPadding();
KdeUiProxyStyle* getProxyStyle();
@@ -529,7 +529,7 @@ public:
{ return static_cast<DOM::HTMLTextAreaElementImpl*>(RenderObject::element()); }
QString text();
- void setText(const QString& text);
+ void setText(const QString& text);
void highLightWord( unsigned int length, unsigned int pos );
@@ -550,6 +550,7 @@ protected:
virtual bool canHaveBorder() const { return true; }
bool scrollbarsStyled;
+ Qt::Alignment m_textAlignment;
};
// -------------------------------------------------------------------------