summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrea Iacovitti <aiacovitti@libero.it>2012-05-25 17:35:09 (GMT)
committerAndrea Iacovitti <aiacovitti@libero.it>2012-05-25 17:35:09 (GMT)
commit38ee1c13b5670458a7208be6822ec8fe5d68ed73 (patch)
tree9cb41bd4f595a561e3a15e0a0e9b769f2aa91da2
parentf3d636710dde83af20998d82a598d5faaf9b1783 (diff)
Fix rendering of css styled SELECT elements (combobox + listview).
BUG: 299934, 300227 FIXED-IN: 4.8.4
-rw-r--r--khtml/css/html4.css1
-rw-r--r--khtml/rendering/render_form.cpp79
-rw-r--r--khtml/rendering/render_form.h2
3 files changed, 76 insertions, 6 deletions
diff --git a/khtml/css/html4.css b/khtml/css/html4.css
index 9f4d17b..4960aca 100644
--- a/khtml/css/html4.css
+++ b/khtml/css/html4.css
@@ -444,6 +444,7 @@ select {
background-color: window;
-khtml-background-clip: padding;
box-sizing: border-box;
+ border: 2px -khtml-native;
}
select[multiple],
diff --git a/khtml/rendering/render_form.cpp b/khtml/rendering/render_form.cpp
index b4cf136..d49324f 100644
--- a/khtml/rendering/render_form.cpp
+++ b/khtml/rendering/render_form.cpp
@@ -127,7 +127,12 @@ using namespace DOM;
comboOpt.currentText = comboOpt.currentText.trimmed();
// by default combobox label is drawn left justified, vertical centered
// translate it to reflect padding values
- comboOpt.rect = comboOpt.rect.translated(left, (top - bottom) / 2);
+ comboOpt.rect.translate(left, (top - bottom) / 2);
+ if (noBorder) {
+ // Need to expand a bit for some styles
+ comboOpt.rect.adjust(-1, -2, 1, 2);
+ comboOpt.rect.translate(-1, 0);
+ }
return style()->drawControl(element, &comboOpt, painter, widget);
}
}
@@ -135,6 +140,51 @@ using namespace DOM;
style()->drawControl(element, option, painter, widget);
}
+ void drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt, QPainter *painter, const QWidget *widget) const
+ {
+ if ((cc == QStyle::CC_ComboBox) && noBorder) {
+ if (const QStyleOptionComboBox *cbOpt = qstyleoption_cast<const QStyleOptionComboBox*>(opt)) {
+ bool enabled = (cbOpt->state & State_Enabled);
+ QColor color = cbOpt->palette.color(QPalette::ButtonText);
+ if (color.value() < 128)
+ color = color.lighter();
+ painter->save();
+ painter->setBackgroundMode(Qt::TransparentMode);
+ painter->setPen(color);
+ // Drop down indicator
+ painter->setBrush(enabled ? QBrush(color, Qt::SolidPattern) : Qt::NoBrush);
+ QRect arrowRect = style()->subControlRect(cc, opt, SC_ComboBoxArrow, widget);
+ const int arrowDown[] = { 5,-2, 0,3, -5,-2, -4,-3, -3,-3, 0,0, 3,-3, 4,-3 };
+ QPolygon a(8);
+ a.setPoints(8, arrowDown);
+ a.translate((arrowRect.x() + (arrowRect.width() >> 1)), (arrowRect.y() + (arrowRect.height() >> 1)));
+ painter->drawPolygon(a);
+ // Focus rect
+ if (enabled && (cbOpt->state & State_HasFocus)) {
+ QRect focusRect = style()->subElementRect(SE_ComboBoxFocusRect, cbOpt, widget);
+ focusRect.adjust(0, -2, 0, 2);
+ // Begin drawing focus rect (from qcleanlooksstyle)
+ painter->setBrush(QBrush(color, Qt::Dense4Pattern));
+ painter->setBrushOrigin(focusRect.topLeft());
+ painter->setPen(Qt::NoPen);
+ const QRect rects[4] = {
+ QRect(focusRect.left(), focusRect.top(), focusRect.width(), 1), // Top
+ QRect(focusRect.left(), focusRect.bottom(), focusRect.width(), 1), // Bottom
+ QRect(focusRect.left(), focusRect.top(), 1, focusRect.height()), // Left
+ QRect(focusRect.right(), focusRect.top(), 1, focusRect.height()) // Right
+ };
+ painter->drawRects(rects, 4);
+ // End drawing focus rect
+ }
+ painter->restore();
+
+ return;
+ }
+ }
+
+ style()->drawComplexControl(cc, opt, painter, widget);
+ }
+
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex* opt, SubControl sc, const QWidget* widget) const
{
// Make sure we give combo popup's enough room to display contents;
@@ -1674,6 +1724,15 @@ void RenderSelect::clearItemFlags(int index, Qt::ItemFlags flags)
}
}
+void RenderSelect::setStyle(RenderStyle *_style)
+{
+ RenderFormElement::setStyle(_style);
+ if (!m_useListBox && shouldDisableNativeBorders()) {
+ KHTMLProxyStyle* proxyStyle = static_cast<KHTMLProxyStyle*>(getProxyStyle());
+ proxyStyle->noBorder = true;
+ }
+}
+
void RenderSelect::updateFromElement()
{
m_ignoreSelectEvents = true;
@@ -1802,9 +1861,8 @@ short RenderSelect::baselinePosition( bool f ) const
if (m_useListBox)
return RenderFormElement::baselinePosition(f);
- bool hasFrame = static_cast<KComboBox*>(widget())->hasFrame();
- int bTop = hasFrame ? 0 : borderTop();
- int bBottom = hasFrame ? 0 : borderBottom();
+ int bTop = shouldDisableNativeBorders() ? borderTop() : 0;
+ int bBottom = shouldDisableNativeBorders() ? borderBottom() : 0;
int ret = (height()-RenderWidget::paddingTop()-RenderWidget::paddingBottom()-bTop-bBottom+1)/2;
ret += marginTop() + RenderWidget::paddingTop() + bTop;
ret += ((fontMetrics( f ).ascent())/2)-2;
@@ -1897,8 +1955,17 @@ void RenderSelect::layout( )
}
else {
QSize s(m_widget->sizeHint());
- setIntrinsicWidth( s.width() );
- setIntrinsicHeight( s.height() );
+ int w = s.width();
+ int h = s.height();
+
+ if (shouldDisableNativeBorders()) {
+ const int dfw = 2 * m_widget->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, m_widget);
+ w -= dfw;
+ h -= dfw;
+ }
+
+ setIntrinsicWidth(w);
+ setIntrinsicHeight(h);
}
/// uuh, ignore the following line..
diff --git a/khtml/rendering/render_form.h b/khtml/rendering/render_form.h
index 2be4df5..2d849b9 100644
--- a/khtml/rendering/render_form.h
+++ b/khtml/rendering/render_form.h
@@ -459,6 +459,7 @@ public:
bool selectionChanged() { return m_selectionChanged; }
void setSelectionChanged(bool _selectionChanged) { m_selectionChanged = _selectionChanged; }
+ virtual void setStyle(RenderStyle* _style);
virtual void updateFromElement();
virtual short baselinePosition( bool ) const;
@@ -480,6 +481,7 @@ protected:
bool m_optionsChanged;
void clearItemFlags(int index, Qt::ItemFlags flags);
+ virtual bool canHaveBorder() const { return true; }
protected Q_SLOTS:
void slotSelected(int index);