You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by al...@apache.org on 2011/01/28 02:02:03 UTC

svn commit: r1064394 - in /myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main: java/org/apache/myfaces/html5/behavior/ java/org/apache/myfaces/html5/component/animation/ java/org/apache/myfaces/html5/handler/ java/org/apache/myfaces/html5/r...

Author: aliok
Date: Fri Jan 28 01:02:02 2011
New Revision: 1064394

URL: http://svn.apache.org/viewvc?rev=1064394&view=rev
Log:
Html5
New animation component to support custom keyframes

Added:
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/behavior/AnimationBehavior.java
      - copied, changed from r1057905, myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/behavior/AnimationsBehavior.java
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/component/animation/AbstractAnimation.java
      - copied, changed from r1057905, myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/component/animation/AbstractAnimations.java
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/handler/AnimationHandler.java
      - copied, changed from r1060121, myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/handler/AnimationsHandler.java
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/animation/AnimationRenderer.java
      - copied, changed from r1056584, myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/animation/AnimationsRenderer.java
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/AnimationBehaviorRenderer.java
      - copied, changed from r1056122, myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/AnimationsBehaviorRenderer.java
Modified:
    myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/resources/META-INF/faces-config20.vm

Copied: myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/behavior/AnimationBehavior.java (from r1057905, myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/behavior/AnimationsBehavior.java)
URL: http://svn.apache.org/viewvc/myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/behavior/AnimationBehavior.java?p2=myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/behavior/AnimationBehavior.java&p1=myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/behavior/AnimationsBehavior.java&r1=1057905&r2=1064394&rev=1064394&view=diff
==============================================================================
--- myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/behavior/AnimationsBehavior.java (original)
+++ myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/behavior/AnimationBehavior.java Fri Jan 28 01:02:02 2011
@@ -24,7 +24,7 @@ import javax.faces.application.ResourceD
 import javax.faces.component.behavior.FacesBehavior;
 
 /**
- * Behavior for generating scripts for activating and stopping animations.
+ * Behavior for generating scripts for activating and stopping animation.
  *
  * @author Ali Ok
  */
@@ -34,11 +34,11 @@ import javax.faces.component.behavior.Fa
         @ResourceDependency(name = "common.js", library = "org.apache.myfaces.html5", target = "head"),
         @ResourceDependency(name = "effect.js", library = "org.apache.myfaces.html5", target = "head")
 })
-@FacesBehavior("org.apache.myfaces.html5.AnimationsBehavior")
-public class AnimationsBehavior extends javax.faces.component.behavior.ClientBehaviorBase {
+@FacesBehavior("org.apache.myfaces.html5.AnimationBehavior")
+public class AnimationBehavior extends javax.faces.component.behavior.ClientBehaviorBase {
 
-    public static final String ID = "org.apache.myfaces.html5.AnimationsBehavior";
-    public static final String RENDERER_ID = "org.apache.myfaces.html5.AnimationsBehavior";
+    public static final String ID = "org.apache.myfaces.html5.AnimationBehavior";
+    public static final String RENDERER_ID = "org.apache.myfaces.html5.AnimationBehavior";
 
     private String animationIdToHandle;
 

Copied: myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/component/animation/AbstractAnimation.java (from r1057905, myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/component/animation/AbstractAnimations.java)
URL: http://svn.apache.org/viewvc/myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/component/animation/AbstractAnimation.java?p2=myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/component/animation/AbstractAnimation.java&p1=myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/component/animation/AbstractAnimations.java&r1=1057905&r2=1064394&rev=1064394&view=diff
==============================================================================
--- myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/component/animation/AbstractAnimations.java (original)
+++ myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/component/animation/AbstractAnimation.java Fri Jan 28 01:02:02 2011
@@ -25,20 +25,20 @@ import org.apache.myfaces.html5.componen
 import org.apache.myfaces.html5.component.properties.effect.TransitionProperties;
 
 /**
- * Animations container for using them with the parent ClientBehaviorHolder.<br/>
- * fx:animation... components must be nested inside this component.
+ * Convenience tag to activate a keyframe animation on an event of ClientBehaviorHolder.<br/>
+ * Accepts no children.
  *
  * @author Ali Ok
  */
 @JSFComponent(
-        name = "fx:animations",
-        clazz = "org.apache.myfaces.html5.component.animation.Animations",
-        tagClass = "org.apache.myfaces.html5.tag.animation.AnimationsTag",
-        defaultRendererType = "org.apache.myfaces.html5.Animations",
-        family = "org.apache.myfaces.Animations",
-        type = "org.apache.myfaces.html5.Animations"
+        name = "fx:animation",
+        clazz = "org.apache.myfaces.html5.component.animation.Animation",
+        tagClass = "org.apache.myfaces.html5.tag.animation.AnimationTag",
+        defaultRendererType = "org.apache.myfaces.html5.Animation",
+        family = "org.apache.myfaces.Animation",
+        type = "org.apache.myfaces.html5.Animation"
 )
-public abstract class AbstractAnimations extends javax.faces.component.UIComponentBase implements TransitionProperties, EventProperty {
+public abstract class AbstractAnimation extends javax.faces.component.UIComponentBase implements TransitionProperties, EventProperty {
 
     @JSFProperty(deferredValueType = "java.lang.String")
     public abstract String getIteration();
@@ -46,4 +46,7 @@ public abstract class AbstractAnimations
     @JSFProperty(deferredValueType = "java.lang.String")
     public abstract String getDirection();
 
+    @JSFProperty(deferredValueType = "java.lang.String", required = true)
+    public abstract String getKeyFrame();
+
 }

Copied: myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/handler/AnimationHandler.java (from r1060121, myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/handler/AnimationsHandler.java)
URL: http://svn.apache.org/viewvc/myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/handler/AnimationHandler.java?p2=myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/handler/AnimationHandler.java&p1=myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/handler/AnimationsHandler.java&r1=1060121&r2=1064394&rev=1064394&view=diff
==============================================================================
--- myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/handler/AnimationsHandler.java (original)
+++ myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/handler/AnimationHandler.java Fri Jan 28 01:02:02 2011
@@ -21,8 +21,8 @@ package org.apache.myfaces.html5.handler
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFFaceletTag;
-import org.apache.myfaces.html5.behavior.AnimationsBehavior;
-import org.apache.myfaces.html5.component.animation.AbstractAnimations;
+import org.apache.myfaces.html5.behavior.AnimationBehavior;
+import org.apache.myfaces.html5.component.animation.AbstractAnimation;
 import org.apache.myfaces.html5.renderkit.util.ClientBehaviorEvents;
 
 import javax.faces.FacesException;
@@ -34,11 +34,11 @@ import javax.faces.view.facelets.Compone
 import javax.faces.view.facelets.FaceletContext;
 import javax.faces.view.facelets.TagAttribute;
 
-@JSFFaceletTag(name = "fx:animations", componentClass = "org.apache.myfaces.html5.component.animation.Animations")
-public class AnimationsHandler extends javax.faces.view.facelets.ComponentHandler {
+@JSFFaceletTag(name = "fx:animation", componentClass = "org.apache.myfaces.html5.component.animation.Animation")
+public class AnimationHandler extends javax.faces.view.facelets.ComponentHandler {
     private final TagAttribute event;
 
-    public AnimationsHandler(ComponentConfig config) {
+    public AnimationHandler(ComponentConfig config) {
         super(config);
         event = getAttribute("event");
     }
@@ -50,21 +50,16 @@ public class AnimationsHandler extends j
         String eventName = getEventName(faceletContext);
 
         if ((!(parent instanceof ClientBehaviorHolder))){
-            if(StringUtils.isNotBlank(eventName))
-                throw new FacesException("Parent component is not a ClientBehaviorHolder, however event attribute is defined.");
-            else{
-                //then only render children animations, do not attach a client behavior
-                return;
-            }
+            throw new FacesException("Parent component is not a ClientBehaviorHolder, however event attribute is defined.");
         }
 
-        if (!(uiComponent instanceof AbstractAnimations))
-            throw new FacesException("Created component is not a AbstractAnimations");
+        if (!(uiComponent instanceof AbstractAnimation))
+            throw new FacesException("Created component is not a AbstractAnimation");
 
         FacesContext context = faceletContext.getFacesContext();
         Application app = context.getApplication();
-        String behaviorId = AnimationsBehavior.ID;
-        AnimationsBehavior behavior = (AnimationsBehavior) app.createBehavior(behaviorId);
+        String behaviorId = AnimationBehavior.ID;
+        AnimationBehavior behavior = (AnimationBehavior) app.createBehavior(behaviorId);
 
         behavior.setAnimationIdToHandle(uiComponent.getClientId(faceletContext.getFacesContext()));
 

Copied: myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/animation/AnimationRenderer.java (from r1056584, myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/animation/AnimationsRenderer.java)
URL: http://svn.apache.org/viewvc/myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/animation/AnimationRenderer.java?p2=myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/animation/AnimationRenderer.java&p1=myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/animation/AnimationsRenderer.java&r1=1056584&r2=1064394&rev=1064394&view=diff
==============================================================================
--- myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/animation/AnimationsRenderer.java (original)
+++ myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/animation/AnimationRenderer.java Fri Jan 28 01:02:02 2011
@@ -21,7 +21,7 @@ package org.apache.myfaces.html5.renderk
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.annotation.JSFRenderer;
-import org.apache.myfaces.html5.component.animation.AbstractAnimations;
+import org.apache.myfaces.html5.component.animation.AbstractAnimation;
 import org.apache.myfaces.html5.renderkit.util.CSS;
 import org.apache.myfaces.html5.renderkit.util.HTML5;
 import org.apache.myfaces.html5.renderkit.util.Html5RendererUtils;
@@ -40,8 +40,8 @@ import java.io.IOException;
         @ListenerFor(systemEventClass = PostAddToViewEvent.class),
         @ListenerFor(systemEventClass = PostBuildComponentTreeOnRestoreViewEvent.class)
 })
-@JSFRenderer(renderKitId = "HTML_BASIC", family = "org.apache.myfaces.Animations", type = "org.apache.myfaces.html5.Animations")
-public class AnimationsRenderer extends HtmlRenderer implements ComponentSystemEventListener {
+@JSFRenderer(renderKitId = "HTML_BASIC", family = "org.apache.myfaces.Animation", type = "org.apache.myfaces.html5.Animation")
+public class AnimationRenderer extends HtmlRenderer implements ComponentSystemEventListener {
 
     @Override
     public boolean getRendersChildren() {
@@ -52,40 +52,26 @@ public class AnimationsRenderer extends 
     public void encodeBegin(FacesContext facesContext, UIComponent uiComponent) throws IOException {
         super.encodeBegin(facesContext, uiComponent);
 
-        RendererUtils.checkParamValidity(facesContext, uiComponent, AbstractAnimations.class);
+        RendererUtils.checkParamValidity(facesContext, uiComponent, AbstractAnimation.class);
 
-        AbstractAnimations component = (AbstractAnimations) uiComponent;
+        AbstractAnimation component = (AbstractAnimation) uiComponent;
 
         ResponseWriter writer = facesContext.getResponseWriter();
 
         writer.startElement(HTML.STYLE_ELEM, component);
-    }
-
-    @Override
-    public void encodeChildren(FacesContext facesContext, UIComponent uiComponent) throws IOException {
-        RendererUtils.checkParamValidity(facesContext, uiComponent, AbstractAnimations.class);
-
-        AbstractAnimations component = (AbstractAnimations) uiComponent;
-
-        ResponseWriter writer = facesContext.getResponseWriter();
 
-        // write id
-        final String id = component.getClientId(facesContext);
-        writer.writeAttribute(HTML5.ID_ATTR, id, null);
-
-        //TODO: what happens if id has colon? Will CSS accept it?
-        //write key frames (let child components render themselves)
-        writer.writeText("@-webkit-keyframes " + Html5RendererUtils.escapeCssSelector(id) + " { ", component, null);
-        //TODO: allow only BaseAnimation children!
-
-        super.encodeChildren(facesContext, component);
+        RendererUtils.checkParamValidity(facesContext, uiComponent, AbstractAnimation.class);
 
-        writer.writeText(" } ", component, null);
         //write CSS class definition with animation definition
         writer.writeText(getAnimationDefinition(facesContext, component),component, null);
     }
 
     @Override
+    public void encodeChildren(FacesContext context, UIComponent component) throws IOException {
+        //do nothing
+    }
+
+    @Override
     public void encodeEnd(FacesContext facesContext, UIComponent uiComponent) throws IOException {
         // just close the element
         super.encodeEnd(facesContext, uiComponent);
@@ -95,7 +81,7 @@ public class AnimationsRenderer extends 
         writer.endElement(HTML.STYLE_ELEM);
     }
 
-    protected String getAnimationDefinition(FacesContext facesContext, AbstractAnimations component){
+    protected String getAnimationDefinition(FacesContext facesContext, AbstractAnimation component){
         final String id = component.getClientId(facesContext);
         final String duration = getTimeValue(component.getDuration());
         final String iteration = component.getIteration();
@@ -107,7 +93,7 @@ public class AnimationsRenderer extends 
         builder.append(".").append(Html5RendererUtils.escapeCssSelector(id));
         builder.append(" { ");
 
-        appendIfNotNull(builder, CSS.ANIMATION_NAME_PROP, Html5RendererUtils.escapeCssSelector(id));
+        appendIfNotNull(builder, CSS.ANIMATION_NAME_PROP, component.getKeyFrame());
         appendIfNotNull(builder, CSS.ANIMATION_DURATION_PROP, duration);
         appendIfNotNull(builder, CSS.ANIMATION_ITERATION_COUNT_PROP, iteration);
         appendIfNotNull(builder, CSS.ANIMATION_TIMING_FUNCTION_PROP, timingFunction);

Copied: myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/AnimationBehaviorRenderer.java (from r1056122, myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/AnimationsBehaviorRenderer.java)
URL: http://svn.apache.org/viewvc/myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/AnimationBehaviorRenderer.java?p2=myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/AnimationBehaviorRenderer.java&p1=myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/AnimationsBehaviorRenderer.java&r1=1056122&r2=1064394&rev=1064394&view=diff
==============================================================================
--- myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/AnimationsBehaviorRenderer.java (original)
+++ myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/java/org/apache/myfaces/html5/renderkit/behavior/AnimationBehaviorRenderer.java Fri Jan 28 01:02:02 2011
@@ -16,9 +16,10 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.myfaces.html5.renderkit.behavior;
 
-import org.apache.myfaces.html5.behavior.AnimationsBehavior;
+import org.apache.myfaces.html5.behavior.AnimationBehavior;
 import org.apache.myfaces.html5.renderkit.util.ClientBehaviorEvents;
 
 import javax.faces.FacesException;
@@ -26,18 +27,18 @@ import javax.faces.component.behavior.Cl
 import javax.faces.component.behavior.ClientBehaviorContext;
 import javax.faces.render.ClientBehaviorRenderer;
 
-public class AnimationsBehaviorRenderer extends ClientBehaviorRenderer
+public class AnimationBehaviorRenderer extends ClientBehaviorRenderer
 {
 
     @Override
     public String getScript(ClientBehaviorContext behaviorContext, ClientBehavior behavior)
     {
-        if (!(behavior instanceof AnimationsBehavior))
+        if (!(behavior instanceof AnimationBehavior))
         {
-            throw new FacesException("Behavior is not a AnimationsBehavior.");
+            throw new FacesException("Behavior is not a AnimationBehavior.");
         }
 
-        AnimationsBehavior effectBehavior = (AnimationsBehavior) behavior;
+        AnimationBehavior effectBehavior = (AnimationBehavior) behavior;
 
         String strEffects = effectBehavior.getAnimationIdToHandle();
 

Modified: myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/resources/META-INF/faces-config20.vm
URL: http://svn.apache.org/viewvc/myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/resources/META-INF/faces-config20.vm?rev=1064394&r1=1064393&r2=1064394&view=diff
==============================================================================
--- myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/resources/META-INF/faces-config20.vm (original)
+++ myfaces/gsoc/html5-comp-lib/trunk/html5-comp-lib-core/src/main/resources/META-INF/faces-config20.vm Fri Jan 28 01:02:02 2011
@@ -96,6 +96,10 @@ $baseContent
         <client-behavior-renderer-class>org.apache.myfaces.html5.renderkit.behavior.AnimationsBehaviorRenderer</client-behavior-renderer-class>
       </client-behavior-renderer>
       <client-behavior-renderer>
+        <client-behavior-renderer-type>org.apache.myfaces.html5.AnimationBehavior</client-behavior-renderer-type>
+        <client-behavior-renderer-class>org.apache.myfaces.html5.renderkit.behavior.AnimationBehaviorRenderer</client-behavior-renderer-class>
+      </client-behavior-renderer>
+      <client-behavior-renderer>
         <client-behavior-renderer-type>org.apache.myfaces.html5.EffectsActivationBehaviorRenderer</client-behavior-renderer-type>
         <client-behavior-renderer-class>org.apache.myfaces.html5.renderkit.behavior.EffectsActivationBehaviorRenderer</client-behavior-renderer-class>
       </client-behavior-renderer>