flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [2/2] git commit: [flex-falcon] [refs/heads/develop] - add media query to generated CSS
Date Mon, 25 Nov 2013 06:59:00 GMT
add media query to generated CSS


Project: http://git-wip-us.apache.org/repos/asf/flex-falcon/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-falcon/commit/4bac1cff
Tree: http://git-wip-us.apache.org/repos/asf/flex-falcon/tree/4bac1cff
Diff: http://git-wip-us.apache.org/repos/asf/flex-falcon/diff/4bac1cff

Branch: refs/heads/develop
Commit: 4bac1cfffd50a68ffba57ef6c0ba47c88792b203
Parents: 45c6be9
Author: Alex Harui <aharui@apache.org>
Authored: Fri Nov 22 09:30:09 2013 -0800
Committer: Alex Harui <aharui@apache.org>
Committed: Fri Nov 22 09:30:09 2013 -0800

----------------------------------------------------------------------
 .../internal/css/codegen/CSSReducer.java        | 46 +++++++++++++++++++-
 .../css/codegen/ICSSRuntimeConstants.java       |  3 +-
 2 files changed, 46 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4bac1cff/compiler/src/org/apache/flex/compiler/internal/css/codegen/CSSReducer.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/internal/css/codegen/CSSReducer.java b/compiler/src/org/apache/flex/compiler/internal/css/codegen/CSSReducer.java
index f41aafb..db63df3 100644
--- a/compiler/src/org/apache/flex/compiler/internal/css/codegen/CSSReducer.java
+++ b/compiler/src/org/apache/flex/compiler/internal/css/codegen/CSSReducer.java
@@ -172,8 +172,18 @@ public class CSSReducer implements ICSSCodeGenResult
      * The "factory" with which the styles will be registered.
      */
     private final Integer factory;
+    
+    /**
+     * The media query string building up for the selector
+     */
+    private String mediaQueryString;
 
     /**
+     * The map of media query to factory functions
+     */
+    private HashMap<String,ArrayList<String>> mediaQueryMap = new HashMap<String,
ArrayList<String>>();
+    
+    /**
      * Root reduction rule. It aggregates all the instructions and emit ABC code
      * of {@code StyleDateClass}.
      * 
@@ -469,7 +479,26 @@ public class CSSReducer implements ICSSCodeGenResult
     {
         // Generate anonymous function.
         final MethodInfo methodInfo = new MethodInfo();
-        methodInfo.setMethodName(((CSSRule)site).getSelectorGroup().get(0).getElementName());
+        String miName = ((CSSRule)site).getSelectorGroup().get(0).getElementName();
+        if (mediaQueryString != null)
+        {
+            pushNumericConstant(ICSSRuntimeConstants.MEDIA_QUERY, selector.arrayReduction);
+            selector.arrayReduction.addInstruction(ABCConstants.OP_pushstring, mediaQueryString);
+
+            miName = mediaQueryString + "_" + miName;
+            if (mediaQueryMap.containsKey(mediaQueryString))
+            {
+                ArrayList<String> factoryList = mediaQueryMap.get(mediaQueryString);
+                factoryList.add(miName);
+            }
+            else
+            {
+                ArrayList<String> factoryList = new ArrayList<String>();
+                factoryList.add(miName);
+                mediaQueryMap.put(mediaQueryString, factoryList);
+            }
+        }
+        methodInfo.setMethodName(miName);
         methodInfo.setParamTypes(EMPTY_PARAM_TYPES);
         final IMethodVisitor methodVisitor = abcVisitor.visitMethod(methodInfo);
         methodVisitor.visit();
@@ -488,8 +517,17 @@ public class CSSReducer implements ICSSCodeGenResult
         // Populate the closure name-body map with method info objects.
         for (final String name : selector.closureReduction.keySet())
         {
-            selector.closureReduction.put(name, methodInfo);
+            if (mediaQueryString != null)
+            {
+                selector.closureReduction.remove(name);
+                selector.closureReduction.put(mediaQueryString + "_" + name, 
+                        methodInfo);
+            }
+            else
+                selector.closureReduction.put(name, methodInfo);
         }
+        
+        mediaQueryString = null;
 
         return selector;
     }
@@ -636,6 +674,10 @@ public class CSSReducer implements ICSSCodeGenResult
     public PairOfInstructionLists reduceMediaQueryCondition(ICSSNode site)
     {
         // TODO Implement @media code generation
+        if (mediaQueryString == null)
+            mediaQueryString = site.toString();
+        else
+            mediaQueryString += "and " + site.toString();
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/flex-falcon/blob/4bac1cff/compiler/src/org/apache/flex/compiler/internal/css/codegen/ICSSRuntimeConstants.java
----------------------------------------------------------------------
diff --git a/compiler/src/org/apache/flex/compiler/internal/css/codegen/ICSSRuntimeConstants.java
b/compiler/src/org/apache/flex/compiler/internal/css/codegen/ICSSRuntimeConstants.java
index 42287ce..ef6bc8d 100644
--- a/compiler/src/org/apache/flex/compiler/internal/css/codegen/ICSSRuntimeConstants.java
+++ b/compiler/src/org/apache/flex/compiler/internal/css/codegen/ICSSRuntimeConstants.java
@@ -32,7 +32,8 @@ public interface ICSSRuntimeConstants
     static final Integer SELECTOR = 0;
     static final Integer CONDITION = 1;
     static final Integer STYLE_DECLARATION = 2;
-
+    static final Integer MEDIA_QUERY = 3;
+    
     // From CSSFactory
     static final Integer DEFAULT_FACTORY = 0;
     static final Integer FACTORY = 1;


Mime
View raw message