KHTML-Patch - show frame around not-yet-loaded images

Helge Deller deller at gmx.de
Tue Dec 14 20:14:01 GMT 2004


Some weeks ago I filed a wish against KHTML (http://bugs.kde.org/show_bug.cgi?id=93213) that it should behave like Mozilla and IE and show frames around not-yet-loaded images in Konqueror.
This visual feedback is IMHO pretty important, since without it users (like me) might wonder why the Konqi-wheel still spins although the webpage seems completely loaded.
This is even more important when you are running on a slow internet connection or if the servicing webserver is pretty loaded.

Attached is now a (second version of my) patch which exactly adds this functionality, and it can be turned on or off in the KDE Control Center module "Web Behaviour". 
In the patch the default setting for this feature is currently "disabled", although I would like to turn it on by default depending on your feedback.

The patch applies again KDE CVS HEAD and changes the following files in kdelibs/khtml and kdebase/kcontrol/konqhtml:
- kdelibs/khtml/khtml_settings.cc
- kdelibs/khtml/khtml_settings.h
- kdelibs/khtml/rendering/render_image.cpp
- kdelibs/khtml/rendering/render_image.h
- kdebase/kcontrol/konqhtml/htmlopts.cpp
- kdebase/kcontrol/konqhtml/htmlopts.h

Ok to apply ?

Regards,
Helge
-------------- next part --------------
Index: kdelibs/khtml/khtml_settings.cc
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_settings.cc,v
retrieving revision 1.107
diff -u -p -r1.107 khtml_settings.cc
--- kdelibs/khtml/khtml_settings.cc	3 Dec 2004 14:18:21 -0000	1.107
+++ kdelibs/khtml/khtml_settings.cc	14 Dec 2004 19:55:30 -0000
@@ -72,6 +72,7 @@ public:
     bool m_bEnableJavaScriptErrorReporting : 1;
     bool enforceCharset : 1;
     bool m_bAutoLoadImages : 1;
+    bool m_bUnfinishedImageFrame : 1;
     bool m_formCompletionEnabled : 1;
     bool m_autoDelayedActionsEnabled : 1;
     bool m_jsErrorsEnabled : 1;
@@ -355,6 +356,9 @@ void KHTMLSettings::init( KConfig * conf
     if ( reset || config->hasKey( "AutoLoadImages" ) )
       d->m_bAutoLoadImages = config->readBoolEntry( "AutoLoadImages", true );
 
+    if ( reset || config->hasKey( "UnfinishedImageFrame" ) )
+      d->m_bUnfinishedImageFrame = config->readBoolEntry( "UnfinishedImageFrame", false );
+
     if ( reset || config->hasKey( "ShowAnimations" ) )
     {
       QString value = config->readEntry( "ShowAnimations").lower();
@@ -854,6 +858,11 @@ bool KHTMLSettings::autoLoadImages() con
   return d->m_bAutoLoadImages;
 }
 
+bool KHTMLSettings::unfinishedImageFrame() const
+{
+  return d->m_bUnfinishedImageFrame;
+}
+
 KHTMLSettings::KAnimationAdvice KHTMLSettings::showAnimations() const
 {
   return d->m_showAnimations;
Index: kdelibs/khtml/khtml_settings.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_settings.h,v
retrieving revision 1.42
diff -u -p -r1.42 khtml_settings.h
--- kdelibs/khtml/khtml_settings.h	3 Dec 2004 14:18:21 -0000	1.42
+++ kdelibs/khtml/khtml_settings.h	14 Dec 2004 19:55:30 -0000
@@ -156,6 +156,7 @@ public:
 
     // Autoload images
     bool autoLoadImages() const;
+    bool unfinishedImageFrame() const;
 
     bool isOpenMiddleClickEnabled();
     bool isBackRightClickEnabled();
Index: kdelibs/khtml/rendering/render_image.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/rendering/render_image.cpp,v
retrieving revision 1.138
diff -u -p -r1.138 render_image.cpp
--- kdelibs/khtml/rendering/render_image.cpp	10 Nov 2004 13:03:38 -0000	1.138
+++ kdelibs/khtml/rendering/render_image.cpp	14 Dec 2004 19:55:35 -0000
@@ -45,6 +45,8 @@
 #include "xml/dom2_eventsimpl.h"
 #include "html/html_documentimpl.h"
 #include "html/html_objectimpl.h"
+#include "khtmlview.h"
+#include "khtml_part.h"
 #include <math.h>
 
 using namespace DOM;
@@ -61,6 +63,9 @@ RenderImage::RenderImage(NodeImpl *_elem
     berrorPic = false;
     loadEventSent = false;
 
+    const KHTMLSettings *settings = _element->getDocument()->view()->part()->settings();
+    bUnfinishedImageFrame = settings->unfinishedImageFrame();
+
     setIntrinsicWidth( 0 );
     setIntrinsicHeight( 0 );
 }
@@ -231,6 +236,10 @@ void RenderImage::paint(PaintInfo& paint
     CachedImage* i = oimage && oimage->valid_rect().size() == oimage->pixmap_size()
                      ? oimage : image;
 
+    // paint frame around image as long as it is not completely loaded from web.
+    if (bUnfinishedImageFrame && paintInfo.phase == PaintActionForeground && cWidth > 2 && cHeight > 2 && !complete())
+	outlineBox(paintInfo.p, _tx, _ty, "gray");
+
     //kdDebug( 6040 ) << "    contents (" << contentWidth << "/" << contentHeight << ") border=" << borderLeft() << " padding=" << paddingLeft() << endl;
     if ( !i || berrorPic)
     {
Index: kdelibs/khtml/rendering/render_image.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/rendering/render_image.h,v
retrieving revision 1.56
diff -u -p -r1.56 render_image.h
--- kdelibs/khtml/rendering/render_image.h	10 Nov 2004 13:26:33 -0000	1.56
+++ kdelibs/khtml/rendering/render_image.h	14 Dec 2004 19:55:35 -0000
@@ -90,6 +90,7 @@ private:
 
     bool berrorPic : 1;
     bool loadEventSent : 1;
+    bool bUnfinishedImageFrame :1;
     SelectionState m_selectionState : 3; // FIXME: don't forget to enlarge this as the enum grows
 };
 
Index: kdebase/kcontrol/konqhtml/htmlopts.cpp
===================================================================
RCS file: /home/kde/kdebase/kcontrol/konqhtml/htmlopts.cpp,v
retrieving revision 1.87
diff -u -p -r1.87 htmlopts.cpp
--- kdebase/kcontrol/konqhtml/htmlopts.cpp	28 Oct 2004 18:26:57 -0000	1.87
+++ kdebase/kcontrol/konqhtml/htmlopts.cpp	14 Dec 2004 19:55:36 -0000
@@ -135,6 +135,12 @@ KMiscHTMLOptions::KMiscHTMLOptions(KConf
     lay->addMultiCellWidget( m_pAutoLoadImagesCheckBox, row, row, 0, 1 );
     row++;
 
+    m_pUnfinishedImageFrameCheckBox = new QCheckBox( i18n( "Dra&w frame around not completely loaded images"), this );
+    QWhatsThis::add( m_pUnfinishedImageFrameCheckBox, i18n( "If this box is checked, Konqueror will draw a frame as placeholder around not yet fully loaded images that are embedded in a web page.<br>Especially if you have a slow network connection, you will probably want to check this box to enhance your browsing experience." ) );
+    connect(m_pUnfinishedImageFrameCheckBox, SIGNAL(clicked()), SLOT(slotChanged()));
+    lay->addMultiCellWidget( m_pUnfinishedImageFrameCheckBox, row, row, 0, 1 );
+    row++;
+
     m_pAutoRedirectCheckBox = new QCheckBox( i18n( "Allow automatic delayed &reloading/redirecting"), this );
     QWhatsThis::add( m_pAutoRedirectCheckBox,
     i18n( "Some web pages request an automatic reload or redirection after a certain period of time. By unchecking this box Konqueror will ignore these requests." ) );
@@ -214,6 +220,7 @@ void KMiscHTMLOptions::load()
     bool underlineLinks = READ_BOOL("UnderlineLinks", DEFAULT_UNDERLINELINKS);
     bool hoverLinks = READ_BOOL("HoverLinks", true);
     bool bAutoLoadImages = READ_BOOL( "AutoLoadImages", true );
+    bool bUnfinishedImageFrame = READ_BOOL( "UnfinishedImageFrame", false );
     QString strAnimations = READ_ENTRY( "ShowAnimations" ).lower();
 
     bool bAutoRedirect = m_pConfig->readBoolEntry( "AutoDelayedActions", true );
@@ -221,6 +228,7 @@ void KMiscHTMLOptions::load()
     // *** apply to GUI ***
     m_cbCursor->setChecked( changeCursor );
     m_pAutoLoadImagesCheckBox->setChecked( bAutoLoadImages );
+    m_pUnfinishedImageFrameCheckBox->setChecked( bUnfinishedImageFrame );
     m_pAutoRedirectCheckBox->setChecked( bAutoRedirect );
     m_pOpenMiddleClick->setChecked( bOpenMiddleClick );
     m_pBackRightClick->setChecked( bBackRightClick );
@@ -278,6 +286,7 @@ void KMiscHTMLOptions::save()
     m_pConfig->setGroup( "HTML Settings" );
     m_pConfig->writeEntry( "ChangeCursor", m_cbCursor->isChecked() );
     m_pConfig->writeEntry( "AutoLoadImages", m_pAutoLoadImagesCheckBox->isChecked() );
+    m_pConfig->writeEntry( "UnfinishedImageFrame", m_pUnfinishedImageFrameCheckBox->isChecked() );
     m_pConfig->writeEntry( "AutoDelayedActions", m_pAutoRedirectCheckBox->isChecked() );
     switch(m_pUnderlineCombo->currentItem())
     {
Index: kdebase/kcontrol/konqhtml/htmlopts.h
===================================================================
RCS file: /home/kde/kdebase/kcontrol/konqhtml/htmlopts.h,v
retrieving revision 1.35
diff -u -p -r1.35 htmlopts.h
--- kdebase/kcontrol/konqhtml/htmlopts.h	22 Oct 2004 19:11:24 -0000	1.35
+++ kdebase/kcontrol/konqhtml/htmlopts.h	14 Dec 2004 19:55:36 -0000
@@ -52,6 +52,7 @@ private:
     QComboBox* m_pAnimationsCombo;
     QCheckBox* m_cbCursor;
     QCheckBox* m_pAutoLoadImagesCheckBox;
+    QCheckBox* m_pUnfinishedImageFrameCheckBox;
     QCheckBox* m_pAutoRedirectCheckBox;
     QCheckBox* m_pOpenMiddleClick;
     QCheckBox* m_pBackRightClick;


More information about the kfm-devel mailing list