8166594: Taskbar.setWindowProgressValue() spec does not specify expected visual behavior of setWindowProgressValue()
authorazvegint
Tue, 08 Nov 2016 13:45:06 +0300
changeset 42202 31974f43ef4a
parent 42201 cdf51b0d0361
child 42203 64f91947fa52
8166594: Taskbar.setWindowProgressValue() spec does not specify expected visual behavior of setWindowProgressValue() Reviewed-by: serb, ssadetsky
jdk/src/java.desktop/share/classes/java/awt/Taskbar.java
jdk/src/java.desktop/windows/native/libawt/windows/awt_Taskbar.cpp
--- a/jdk/src/java.desktop/share/classes/java/awt/Taskbar.java	Mon Nov 07 14:35:21 2016 +0530
+++ b/jdk/src/java.desktop/share/classes/java/awt/Taskbar.java	Tue Nov 08 13:45:06 2016 +0300
@@ -407,10 +407,21 @@
     }
 
     /**
-     * Displays progress for specified window.
+     * Displays a determinate progress bar in the task area for the specified
+     * window.
+     * <br>
+     * The visual behavior is platform and {@link State} dependent.
+     * <br>
+     * This call cancels the {@link State#INDETERMINATE INDETERMINATE} state
+     * of the window.
+     * <br>
+     * Note that when multiple windows is grouped in the task area
+     * the behavior is platform specific.
      *
      * @param w window to update
-     * @param value from 0 to 100, other to disable progress indication
+     * @param value from 0 to 100, other to switch to {@link State#OFF} state
+     *              and disable progress indication
+     * @see #setWindowProgressState(java.awt.Window, State)
      * @throws SecurityException if a security manager exists and it denies the
      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
@@ -426,14 +437,21 @@
 
     /**
      * Sets a progress state for a specified window.
+     * <br>
+     * Each state displays a progress in a platform-dependent way.
+     * <br>
+     * Note than switching from {@link State#INDETERMINATE INDETERMINATE} state
+     * to any of determinate states may reset value set by
+     * {@link #setWindowProgressValue(java.awt.Window, int) setWindowProgressValue}
      *
      * @param w window
      * @param state to change to
      * @see State#OFF
      * @see State#NORMAL
      * @see State#PAUSED
+     * @see State#ERROR
      * @see State#INDETERMINATE
-     * @see State#ERROR
+     * @see #setWindowProgressValue(java.awt.Window, int)
      * @throws SecurityException if a security manager exists and it denies the
      * {@code RuntimePermission("canProcessApplicationEvents")} permission.
      * @throws UnsupportedOperationException if the current platform
--- a/jdk/src/java.desktop/windows/native/libawt/windows/awt_Taskbar.cpp	Mon Nov 07 14:35:21 2016 +0530
+++ b/jdk/src/java.desktop/windows/native/libawt/windows/awt_Taskbar.cpp	Tue Nov 08 13:45:06 2016 +0300
@@ -58,7 +58,11 @@
 JNIEXPORT void JNICALL Java_sun_awt_windows_WTaskbarPeer_setProgressValue
   (JNIEnv *, jobject, jlong window, jint value)
 {
-    m_Taskbar->SetProgressValue((HWND)window, value, 100);
+    if (value < 0 || value > 100) {
+        m_Taskbar->SetProgressState((HWND)window, TBPF_NOPROGRESS);
+    } else {
+        m_Taskbar->SetProgressValue((HWND)window, value, 100);
+    }
 }
 
 
@@ -88,6 +92,9 @@
             flag = TBPF_NOPROGRESS;
         } else if (strcmp(valueNative, "NORMAL") == 0) {
             flag = TBPF_NORMAL;
+
+            // Switching from TBPF_INDETERMINATE to TBPF_NORMAL has no effect
+            m_Taskbar->SetProgressState((HWND)window, TBPF_PAUSED);
         } else if (strcmp(valueNative, "PAUSED") == 0) {
             flag = TBPF_PAUSED;
         } else if (strcmp(valueNative, "INDETERMINATE") == 0) {