For issue 3048, make toggle buttons (and other custom buttons) have the
"aria-pressed" WAI-ARIA state when they get toggled.

patch by: ajr
review by: rdayal (desk review)



git-svn-id: https://google-web-toolkit.googlecode.com/svn/releases/1.6@4254 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/Accessibility.java b/user/src/com/google/gwt/user/client/ui/Accessibility.java
index e6cf056..b523f17 100644
--- a/user/src/com/google/gwt/user/client/ui/Accessibility.java
+++ b/user/src/com/google/gwt/user/client/ui/Accessibility.java
@@ -59,6 +59,7 @@
   public static final String STATE_EXPANDED = "aria-expanded";
   public static final String STATE_LEVEL = "aria-level";
   public static final String STATE_HASPOPUP = "aria-haspopup";
+  public static final String STATE_PRESSED = "aria-pressed";
   
   private static final String ATTR_NAME_ROLE = "role";
 
diff --git a/user/src/com/google/gwt/user/client/ui/CustomButton.java b/user/src/com/google/gwt/user/client/ui/CustomButton.java
index 35b4817..89efb9b 100644
--- a/user/src/com/google/gwt/user/client/ui/CustomButton.java
+++ b/user/src/com/google/gwt/user/client/ui/CustomButton.java
@@ -681,6 +681,9 @@
       super.setEnabled(enabled);
       if (!enabled) {
         cleanupCaptureState();
+        Accessibility.removeState(getElement(), Accessibility.STATE_PRESSED);
+      } else {
+        setAriaPressed(getCurrentFace());
       }
     }
   }
@@ -837,6 +840,10 @@
       curFace = newFace;
       setCurrentFaceElement(newFace.getFace());
       addStyleDependentName(curFace.getName());
+
+      if (isEnabled()) {
+        setAriaPressed(newFace);
+      }
     }
   }
 
@@ -906,6 +913,12 @@
     }
   }
 
+  private void setAriaPressed(Face newFace) {
+    boolean pressed = (newFace.getFaceID() & DOWN_ATTRIBUTE) == 1;
+    Accessibility.setState(getElement(), Accessibility.STATE_PRESSED,
+        pressed ? "true" : "false");
+  }
+
   /**
    * Sets the current face based on the faceID.
    *