Ejemplo n.º 1
0
 /**
  * Clear the mapping relationship between Reference and {@link WXDomObject}. The mapping info is
  * stored in {@link #mRegistry}.
  *
  * @param domObject
  */
 private void clearRegistryForDom(WXDomObject domObject) {
   int count = domObject.childCount();
   mRegistry.remove(domObject.getRef());
   for (int i = count - 1; i >= 0; --i) {
     clearRegistryForDom(domObject.getChild(i));
   }
 }
Ejemplo n.º 2
0
  /**
   * Creating the mapping between Reference to {@link WXDomObject} and store the mapping in {@link
   * #mRegistry}. Then, parse and copy style from DOM to {@link com.taobao.weex.dom.flex.CSSNode}.
   * Finally, DOM's children are also added to {@link com.taobao.weex.dom.flex.CSSNode#mChildren} if
   * added is true. The above procedure will be done recursively.
   *
   * @param dom the original DOM Object
   * @param isAdd true for adding children of {@link WXDomObject} {@link
   *     com.taobao.weex.dom.flex.CSSNode#mChildren} and parsing style, false for only parsing
   *     style.
   */
  private void transformStyle(WXDomObject dom, boolean isAdd) {
    if (dom == null) {
      return;
    }

    if (isAdd) {
      dom.young();
      mRegistry.put(dom.getRef(), dom);
    }

    WXStyle style = dom.getStyles();

    /** merge default styles * */
    Map<String, String> defaults = dom.getDefaultStyle();
    if (defaults != null) {
      Iterator<Map.Entry<String, String>> it = defaults.entrySet().iterator();
      while (it.hasNext()) {
        Map.Entry<String, String> entry = it.next();
        if (!style.containsKey(entry.getKey())) {
          style.put(entry.getKey(), entry.getValue());
        }
      }
    }

    if (dom.getStyles().size() > 0) {
      dom.applyStyleToNode();
    }

    int count = dom.childCount();
    WXDomObject child;
    for (int i = 0; i < count; ++i) {
      child = dom.getChild(i);
      transformStyle(child, isAdd);
    }
  }
Ejemplo n.º 3
0
 private void layoutAfter(WXDomObject dom) {
   if (dom == null || !dom.hasUpdate() || mDestroy) {
     return;
   }
   dom.layoutAfter();
   int count = dom.childCount();
   for (int i = 0; i < count; ++i) {
     layoutAfter(dom.getChild(i));
   }
 }
Ejemplo n.º 4
0
  /**
   * Find fixed node and tell root dom
   *
   * @param obj
   */
  void findFixed(WXDomObject obj) {
    WXDomObject rootDom = mRegistry.get(WXDomObject.ROOT);
    if (rootDom == null) {
      return;
    }
    if (obj.isFixed()) {
      rootDom.add2FixedDomList(obj.getRef());
    }

    int childrenCount = obj.childCount();
    if (childrenCount > 0) {
      for (int i = 0; i < childrenCount; i++) {
        findFixed(obj.getChild(i));
      }
    }
  }
Ejemplo n.º 5
0
  /**
   * Walk through the dom tree and create command object of re-calculating {@link
   * android.view.ViewGroup.LayoutParams} for dom that is old.
   *
   * @param dom the root dom of the walk through.
   */
  private void applyUpdate(WXDomObject dom) {
    if (dom == null) {
      return;
    }
    if (dom.hasUpdate()) {
      dom.markUpdateSeen();
      if (!dom.isYoung()) {
        final WXDomObject copy = dom.clone();
        if (copy == null) {
          return;
        }
        mNormalTasks.add(
            new IWXRenderTask() {

              @Override
              public void execute() {
                mWXRenderManager.setLayout(mInstanceId, copy.getRef(), copy);
              }

              @Override
              public String toString() {
                return "setLayout";
              }
            });
        if (dom.getExtra() != null) {
          mNormalTasks.add(
              new IWXRenderTask() {

                @Override
                public void execute() {
                  mWXRenderManager.setExtra(mInstanceId, copy.getRef(), copy.getExtra());
                }

                @Override
                public String toString() {
                  return "setExtra";
                }
              });
        }
      }
    }
    int count = dom.childCount();
    for (int i = 0; i < count; ++i) {
      applyUpdate(dom.getChild(i));
    }
  }