Bug 56830 - The background color of input fields of type "file" is wrong
Summary: The background color of input fields of type "file" is wrong
Status: RESOLVED FIXED
Alias: None
Product: konqueror
Classification: Applications
Component: khtml (show other bugs)
Version: 3.1
Platform: Slackware Linux
: NOR minor
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-04 11:45 UTC by Simon Ejsing
Modified: 2003-05-15 01:01 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
A screenshot showing the bug (108.84 KB, image/png)
2003-04-04 11:47 UTC, Simon Ejsing
Details
Patch, plus testing how it works on the upload form here (4.51 KB, patch)
2003-05-14 03:44 UTC, Maksim Orlovich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Ejsing 2003-04-04 11:45:10 UTC
Version:           3.1 (using KDE KDE 3.1)
Installed from:    Slackware Packages
OS:          Linux

The problem with the background color of input type "file" is that it uses my system colour instead of the bgcolor tag of the body, I'm using "Digital CDE" as colour sheme and a body tag as: 
<body bgcolor="#ffffff">

Everything else renders with the correct background colour (white), besides the file input field.

By background colour I mean the color _around_ the input field, not the colour of the text area.
Comment 1 Simon Ejsing 2003-04-04 11:47:16 UTC
Created attachment 1301 [details]
A screenshot showing the bug

Look for the file browse input field
Comment 2 Maksim Orlovich 2003-05-14 03:44:26 UTC
Created attachment 1567 [details]
Patch, plus testing how it works on the upload form here

The following is my attempt at fixing this.

Note that the event filter stuff is really mostly correctness paranoia, and if
it's omitted, no one will notice. That would only matter if a style were to
shape buttons differently 
if they were pressed or focused (the former of which can't be done ATM due to 
Qt not updating the mask on mouse releases).  No Qt or KDE style I know of does
that. (Not sure about Aqua or XP styles, though)
Comment 3 Maksim Orlovich 2003-05-15 01:01:37 UTC
Subject: kdelibs/khtml/rendering

CVS commit by orlovich: 


Calculate a mask for <input type="file"> elements, so they don't get a 
grey or other such weird background

CCMAIL: 56830-done@bugs.kde.org


  M +53 -4     render_form.cpp   1.228
  M +3 -2      render_form.h   1.93


--- kdelibs/khtml/rendering/render_form.h  #1.92:1.93
@@ -305,4 +305,5 @@ public:
 
     KLineEdit* lineEdit() const { return m_edit; }
+    const QPushButton* pushButton() const { return m_button; }
 
 public slots:

--- kdelibs/khtml/rendering/render_form.cpp  #1.227:1.228
@@ -47,4 +47,5 @@
 
 #include <qpopupmenu.h>
+#include <qbitmap.h>
 
 using namespace khtml;
@@ -710,9 +711,55 @@ void RenderFieldset::paintBorderMinusLeg
 // -------------------------------------------------------------------------
 
+//A helper widget that generates a mask
+class TransHBox:public QHBox
+{
+public:
+    TransHBox(RenderFileButton* owner, QWidget* parent):QHBox(parent), m_owner(owner)
+    {
+        setAutoMask(true);
+    }
+
+    virtual void updateMask()
+    {
+        QBitmap  mask(size());
+        QPainter p(&mask);
+        
+        const QPushButton* push     = m_owner->pushButton();
+        const QLineEdit*   lineEdit = m_owner->lineEdit();
+        
+        //If we have the button & line edit, make a proper mask
+        if (push && lineEdit)
+        {
+           //Mask everything off
+           p.fillRect(0, 0, width(), height(), Qt::color0);
+           
+           //Draw button mask
+           QRect buttonRect = QRect(push->pos(), push->size());           
+           parentWidget()->style().drawControlMask(QStyle::CE_PushButton,
+                                             &p, push, buttonRect);
+                                             
+           //Draw line edit mask
+           QRect lineEditRect = QRect(lineEdit->pos(), lineEdit->size());
+           p.fillRect(lineEditRect, Qt::color1);
+        }
+        else //Fall back everything visible.
+            p.fillRect(0, 0, width(), height(), Qt::color1);
+                
+        p.end();
+        setMask(mask);
+    }
+        
+private:
+    RenderFileButton* m_owner;
+};
+
 RenderFileButton::RenderFileButton(HTMLInputElementImpl *element)
     : RenderFormElement(element)
 {
-    // this sucks, it creates a grey background
-    QHBox *w = new QHBox(view()->viewport());
+    m_edit   = 0; //For the benefit of the transhbox.
+    m_button = 0; 
+    
+    // this sucks, we need to use a custom widget to get a proper background
+    TransHBox *w = new TransHBox(this, view()->viewport());
 
     m_edit = new LineEditWidget(element, view(), w);
@@ -729,4 +776,6 @@ RenderFileButton::RenderFileButton(HTMLI
     w->setStretchFactor(m_edit, 2);
     w->setFocusProxy(m_edit);
+    
+    w->updateMask();
 
     setQWidget(w);