Bug 641517 (2/2) - Add the animated glow for progress bars on Windows Vista/7. r=jimm
authorMounir Lamouri <mounir.lamouri@gmail.com>
Wed, 04 May 2011 16:57:04 +0200
changeset 69396 4a7b8019b83f46156bbe070baf99a565d2276d1d
parent 69395 f8ab655d503c95e9e8ae00d3b7ef7b16dea95622
child 69397 ddfa8bef5859dbf31966d19c61020a3c9c9c9acb
push id76
push userbzbarsky@mozilla.com
push dateTue, 05 Jul 2011 17:00:57 +0000
treeherdermozilla-beta@d3a2732c35f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs641517
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 641517 (2/2) - Add the animated glow for progress bars on Windows Vista/7. r=jimm
layout/reftests/bugs/474336-1-ref.xul
layout/reftests/bugs/474336-1.xul
layout/reftests/native-theme/reftest.list
widget/src/windows/nsNativeThemeWin.cpp
widget/src/windows/nsUXThemeConstants.h
--- a/layout/reftests/bugs/474336-1-ref.xul
+++ b/layout/reftests/bugs/474336-1-ref.xul
@@ -5,16 +5,17 @@
         >
 
 <html:style>
     #prog {
         -moz-appearance: none;
         background-color: blue;
     }
     #prog .progress-bar {
+        -moz-appearance: none;
         border-radius: 3px 3px;
         background-color: red;
     }
 </html:style>
 
 <progressmeter id="prog" value="50" max="200"/>
 
 </window>
--- a/layout/reftests/bugs/474336-1.xul
+++ b/layout/reftests/bugs/474336-1.xul
@@ -5,16 +5,17 @@
         class="reftest-wait">
 
 <html:style>
     #prog {
         -moz-appearance: none;
         background-color: blue;
     }
     #prog .progress-bar {
+        -moz-appearance: none;
         border-radius: 3px 3px;
         background-color: red;
     }
 </html:style>
 
 <progressmeter id="prog" value="50"/>
 
 <script>
--- a/layout/reftests/native-theme/reftest.list
+++ b/layout/reftests/native-theme/reftest.list
@@ -60,10 +60,13 @@ skip-if(gtk2Widget) random-if(d2d) == re
 # Windows-only, depends on native scrollbar metrics
 skip-if(!winWidget) == scroll-thumb-minimum-size-notheme.html scroll-thumb-minimum-size-notheme-ref.html
 # skip-if(!winWidget) == scroll-thumb-minimum-size-theme.html scroll-thumb-minimum-size-theme-ref.html # Bug 512206
 
 == border-radius.html border-radius-ref.html
 
 == checkbox-dynamic-1.html checkbox-dynamic-1-ref.html
 
-== progress-overflow.html progress-overflow-ref.html
-fails-if(cocoaWidget) != progress-overflow-small.html progress-nobar.html
+# These tests have been written to test the overflow of the window widget
+# (bug 568825) but we can't test it on Windows and Cocoa because they have
+# animated progress bars.
+skip-if(cocoaWidget) skip-if(winWidget) == progress-overflow.html progress-overflow-ref.html
+skip-if(cocoaWidget) skip-if(winWidget) != progress-overflow-small.html progress-nobar.html
--- a/widget/src/windows/nsNativeThemeWin.cpp
+++ b/widget/src/windows/nsNativeThemeWin.cpp
@@ -55,16 +55,17 @@
 #include "nsINameSpaceManager.h"
 #include "nsILookAndFeel.h"
 #include "nsIDOMHTMLInputElement.h"
 #include "nsIMenuFrame.h"
 #include "nsWidgetAtoms.h"
 #include <malloc.h>
 #include "nsWindow.h"
 #include "nsIComboboxControlFrame.h"
+#include "prinrval.h"
 
 #include "gfxPlatform.h"
 #include "gfxContext.h"
 #include "gfxMatrix.h"
 #include "gfxWindowsPlatform.h"
 #include "gfxWindowsSurface.h"
 #include "gfxWindowsNativeDrawing.h"
 
@@ -340,22 +341,28 @@ static CaptionButtonPadding buttonData[3
   },
   { 
     { { 0, 2, 0, 2 }, { 0, 2, 1, 2 }, { 1, 2, 2, 2 } }
   }
 };
 
 /**
  * Progress bar related constants.
+ * These values are found by experimenting and comparing against native widgets
+ * used by the system. They are very unlikely exact but try to not be too wrong.
  */
 // PP_CHUNK is overflowing on the bottom for no appearant reasons.
 // This is a fix around this issue.
 static const PRInt32 kProgressDeterminedXPOverflow = 11;
 // Same thing but for PP_FILL.
 static const PRInt32 kProgressDeterminedVistaOverflow = 4;
+// The width of the overlay used to animate the progress bar (Vista and later).
+static const PRInt32 kProgressVistaOverlayWidth = 120;
+// Speed of the animation for determined Vista and later progress bars.
+static const double kProgressDeterminedVistaSpeed = 0.3;
 
 // Adds "hot" caption button padding to minimum widget size.
 static void AddPaddingRect(nsIntSize* aSize, CaptionButton button) {
   if (!aSize)
     return;
   RECT offset;
   if (!nsUXThemeData::IsAppThemed())
     offset = buttonData[CAPTION_CLASSIC].hotPadding[button];
@@ -1531,16 +1538,40 @@ RENDER_AGAIN:
     ctx->Fill();
 
     ctx->NewPath();
     ctx->Rectangle(buttonbox3, PR_TRUE);
     ctx->Fill();
 
     ctx->Restore();
     ctx->SetOperator(currentOp);
+  } else if (aWidgetType == NS_THEME_PROGRESSBAR_CHUNK &&
+             nsUXThemeData::sIsVistaOrLater) {
+    if (!QueueAnimatedContentForRefresh(aFrame->GetContent(), 60)) {
+      NS_WARNING("unable to animate progress widget!");
+    }
+
+    // Add the animated glow.
+    const PRInt32 frameWidth = widgetRect.right - widgetRect.left;
+    static const PRInt32 overlayWidth = kProgressVistaOverlayWidth;
+    static const double pixelsPerMillisecond = kProgressDeterminedVistaSpeed;
+
+    PRInt32 animationWidth = frameWidth + overlayWidth;
+    double interval = animationWidth / pixelsPerMillisecond;
+    // We have to pass a double* to modf and we can't pass NULL.
+    double tempValue;
+    double ratio = modf(PR_IntervalToMilliseconds(PR_IntervalNow())/interval,
+                        &tempValue);
+    PRInt32 dx = static_cast<PRInt32>(animationWidth * ratio) - overlayWidth;
+
+    RECT overlayRect = widgetRect;
+    overlayRect.left += dx;
+    overlayRect.right = overlayRect.left + overlayWidth;
+    nsUXThemeData::drawThemeBG(theme, hdc, PP_MOVEOVERLAY, state, &overlayRect,
+                               &clipRect);
   }
 
 
   nativeDrawing.EndNativeDrawing();
 
   if (nativeDrawing.ShouldRenderAgain())
     goto RENDER_AGAIN;
 
--- a/widget/src/windows/nsUXThemeConstants.h
+++ b/widget/src/windows/nsUXThemeConstants.h
@@ -112,16 +112,17 @@
 #define SPNP_DOWN          2
 
 // Progress bar constants
 #define PP_BAR             1
 #define PP_BARVERT         2
 #define PP_CHUNK           3
 #define PP_CHUNKVERT       4
 #define PP_FILL            5
+#define PP_MOVEOVERLAY     8
 
 // Tab constants
 #define TABP_TAB             4
 #define TABP_TAB_SELECTED    5
 #define TABP_PANELS          9
 #define TABP_PANEL           10
 
 // Tooltip constants