Package com.google.minijoe.html.css

Examples of com.google.minijoe.html.css.Style


    if (htmlWidget.styleOutdated) {
      return;
    }

    Style previousStyle = computedStyle;
    Style style = new Style();

    Vector queue = new Vector();
    Vector childStyles = new Vector();
    Vector descendantStyles = new Vector();

    int size = applyHere.size();
    for (int i = 0; i < size; i++) {
      StyleSheet styleSheet = (StyleSheet) applyHere.elementAt(i);
      styleSheet.collectStyles(this, queue, childStyles, descendantStyles);
    }
    size = applyAnywhere.size();
    for (int i = 0; i < size; i++) {
      StyleSheet styleSheet = (StyleSheet) applyAnywhere.elementAt(i);
      descendantStyles.addElement(styleSheet);
      styleSheet.collectStyles(this, queue, childStyles, descendantStyles);
    }

    for (int i = 0; i < queue.size(); i++) {
      style.set(((Style) queue.elementAt(i)));
    }

    String styleAttr = getAttributeValue("style");
    if (styleAttr != null) {
      style.read(htmlWidget, styleAttr);
    }

    if (parent != null) {
      style.inherit(parent.computedStyle);
    }

    // handle legacy stuff

    applyHtmlAttributes(style);
View Full Code Here


    // none of which seems desirable.
    // It just peforms a sequence of steps, accessing and modifying table layout
    // information
   
    StringBuffer skipRows = new StringBuffer();
    Style style = element.getComputedStyle();
   
    int left = style.getPx(Style.MARGIN_LEFT, containerWidth) +
        style.getPx(Style.PADDING_LEFT, containerWidth) +
        style.getPx(Style.BORDER_LEFT_WIDTH, containerWidth);
    int right = style.getPx(Style.MARGIN_RIGHT, containerWidth) +
        style.getPx(Style.PADDING_RIGHT, containerWidth) +
        style.getPx(Style.BORDER_RIGHT_WIDTH, containerWidth);
    int top = style.getPx(Style.MARGIN_TOP, containerWidth) +
        style.getPx(Style.PADDING_TOP, containerWidth) +
        style.getPx(Style.BORDER_TOP_WIDTH, containerWidth);
    int bottom = style.getPx(Style.MARGIN_BOTTOM, containerWidth) +
        style.getPx(Style.PADDING_BOTTOM, containerWidth) +
        style.getPx(Style.BORDER_BOTTOM_WIDTH, containerWidth);
   
    int maxInnerWidth;
    int minInnerWidth = 0;

    if (shrinkWrap) {
      maxInnerWidth = getMaximumWidth(containerWidth);
    } else if (style.lengthIsFixed(Style.WIDTH, true)){
      maxInnerWidth = style.getPx(Style.WIDTH, containerWidth);
      minInnerWidth = maxInnerWidth;
    } else {
      maxInnerWidth = containerWidth - left - right;
    }
   
    Element currentRowElement = null;
    int column = 0;
    int row = 0;
   
    int cellCount = children.size() - rowCount;
   
    int[] cols = new int[cellCount];
    int[] rows = new int[cellCount];
    int[] colSpans = new int[cellCount];
    int[] rowSpans = new int[cellCount];
   
    // determine column, row, colSpan and rowSpan for each table cell.
    for (int i = 0; i < cellCount; i++) {
      BlockWidget cell = (BlockWidget) children.elementAt(rowCount + i);
      // TODO(haustein) move add to end
      Element cellElement = cell.getElement();
      if (currentRowElement == null) {
        currentRowElement = cellElement.getParent();
      } else if (currentRowElement != cellElement.getParent()) {
        currentRowElement = cellElement.getParent();
        column = 0;
        row++;
        for (int j = 0; j < skipRows.length(); j++) {
          int span = skipRows.charAt(j);
          if (span > 0) {
            skipRows.setCharAt(j, (char) (span - 1));
          }
        }
      }

      while (column < skipRows.length() && skipRows.charAt(column) > 0) {
        column++;
      }
     
      int rowSpan = Math.max(cellElement.getAttributeInt("rowspan", 1), 1);
      int colSpan = Math.max(cellElement.getAttributeInt("colspan", 1), 1);
     
      cols[i] = column;
      rows[i] = row;
      colSpans[i] = colSpan;
      rowSpans[i] = rowSpan;
     
      while (skipRows.length() < column + colSpan){
        skipRows.append(1);
      }
      for (int j = 0; j < colSpan; j++) {
        skipRows.setCharAt(column++, (char) rowSpan);
      }
    }

    // CSS 2.1, 17.5.2.1 - Fixed table layout
    // -- not yet supported, using auto layout
    //    (should usually deliver similar results)
   
    // CSS 2.1, 17.5.2.2 - Automatic table layout

    int colCount = skipRows.length();
   
    int[] minWidths = new int[colCount];
    int[] specWidths = new int[colCount];
    int[] maxWidths = new int[colCount];
    boolean[] isFixed = new boolean[colCount];
   
    // 1., 2.: figure out min/max widht for single colspan cells
    for (int i = 0; i < cellCount; i++) {
      if (colSpans[i] == 1) {
        BlockWidget cell = (BlockWidget) children.elementAt(rowCount + i);
        column = cols[i];
        minWidths[column] = Math.max(minWidths[column],
            cell.getMinimumWidth(maxInnerWidth));
        specWidths[column] = Math.max(specWidths[column],
            cell.getSpecifiedWidth(maxInnerWidth));
        maxWidths[column] = Math.max(maxWidths[column],
            cell.getMaximumWidth(maxInnerWidth));
        Style cellStyle = cell.getElement().getComputedStyle();
        isFixed[column] |= cellStyle.lengthIsFixed(Style.WIDTH, false);
       // ||(cellStyle.lengthIsFixed(Style.WIDTH, true) && specWidths[column]
       //< minWidths[column]);
      }
    }
   
View Full Code Here

  void addElement(Element e, boolean[] flags) {
    boolean parentUnassignedTraversal = flags[FLAG_UNASSIGNED_TRAVERSAL];
    boolean focusable = e.isFocusable();
    flags[FLAG_UNASSIGNED_TRAVERSAL] |= focusable;

    Style style = e.getComputedStyle();
    String name = e.getName();

    int labelIndex = children.size();
    int display = style.getEnum(Style.DISPLAY);

    if (display == Style.NONE) {
      // ignore
    } else if (display == Style.TABLE
        || display == Style.INLINE_TABLE
        || "table".equals(e.getName())) {
      children.addElement(new TableWidget(e));
    } else if (name.equals("input")) {
      if (!"hidden".equals(e.getAttributeValue("type"))) {
        children.addElement(new InputWidget(e));
      }
    } else if (("select".equals(name) && !e.getAttributeBoolean("multiple")) ||
        "option".equals(name) || "textarea".equals(name) || "button".equals(name)) {
      children.addElement(new InputWidget(e));
    } else {
      Object widget = ElementHandler.DEFAULT_HANDLING;
      if (element.htmlWidget.elementHandlers != null) {
      ElementHandler handler = (ElementHandler) element.htmlWidget.elementHandlers.get(e.getName());
      if (handler != null) {
        widget = handler.handle(e, true);
      }
      }
     
      if (widget == ElementHandler.DEFAULT_HANDLING) {
        if (style.isBlock(false)) {
          children.addElement(new BlockWidget(e, flags));
        } else {
          // Element does not get its own block widget, just add the element's
          // children to this block
          addChildren(e, flags);
View Full Code Here

   * @param element element containing the child elements to be added
   * @param flags flags controlling traversability and leading white space,
   *        see above.
   */
  void addChildren(Element e, boolean[] flags) {
    Style style = e.getComputedStyle();
    StringBuffer buf = new StringBuffer();
    boolean isBlock = style.isBlock(true);
    boolean preserveLeadingSpace =
      flags[FLAG_PRESERVE_LEADING_SPACE] && !isBlock;
    boolean preserveAllSpace = style.getEnum(Style.WHITE_SPACE) == Style.PRE; 

    for (int i = 0; i < e.getChildCount(); i++) {
      switch (e.getChildType(i)) {
        case Element.ELEMENT:
          Element child = e.getElement(i);
View Full Code Here

    containingWidth = outerMaxWidth;
    BlockWidget previousBlock = null;

    removeAllChildren();

    Style style = element.getComputedStyle();
    int display = style.getEnum(Style.DISPLAY);

    // Left and right margins are stored in members to avoid the auto margin
    // calculation in other places.
    marginLeft = style.getPx(Style.MARGIN_LEFT, containingWidth);
    marginRight = style.getPx(Style.MARGIN_RIGHT, containingWidth);

    int marginTop = style.getPx(Style.MARGIN_TOP, containingWidth);
    int marginBottom = style.getPx(Style.MARGIN_BOTTOM, containingWidth);

    int borderLeft = style.getPx(Style.BORDER_LEFT_WIDTH, containingWidth);
    int borderTop =  style.getPx(Style.BORDER_TOP_WIDTH, containingWidth);
    int borderBottom = style.getPx(Style.BORDER_BOTTOM_WIDTH, containingWidth);
    int borderRight = style.getPx(Style.BORDER_RIGHT_WIDTH, containingWidth);

    int paddingLeft = style.getPx(Style.PADDING_LEFT, containingWidth);
    int paddingTop = style.getPx(Style.PADDING_TOP, containingWidth);
    int paddingBottom = style.getPx(Style.PADDING_BOTTOM, containingWidth);
    int paddingRight = style.getPx(Style.PADDING_RIGHT, containingWidth);

    int left = marginLeft + borderLeft + paddingLeft;
    int right = marginRight + borderRight + paddingRight;
    int top = marginTop + borderTop + paddingTop;
    int bottom = marginBottom + borderBottom + paddingBottom;

    // ShrinkWrap means we need to calculate the width based on the contents
    // for floats, table entries etc. without a fixed width
    if (shrinkWrap) {
      outerMaxWidth = style.lengthIsFixed(Style.WIDTH, true)
      ? style.getPx(Style.WIDTH, outerMaxWidth) + left + right
          : Math.min(outerMaxWidth, getMaximumWidth(containingWidth));
      // Otherwise, if this is not a table cell and the width is fixed, we need
      // to calculate the value for auto margins here (This is typically used
      // to center the contents).
    } else if (display != Style.TABLE_CELL &&
        style.lengthIsFixed(Style.WIDTH, true)) {
      int remaining = (containingWidth -
          style.getPx(Style.WIDTH, containingWidth) - left - right);

      if (style.getEnum(Style.MARGIN_LEFT) == Style.AUTO) {
        if (style.getEnum(Style.MARGIN_RIGHT) == Style.AUTO) {
          marginLeft = marginRight = remaining / 2;
          left += marginLeft;
          right += marginRight;
        } else {
          marginLeft = remaining;
          left += marginLeft;
        }
      } else {
        right += remaining;
        marginRight += remaining;
      }
    }

    boxWidth = outerMaxWidth;

    boolean fixedHeight = isHeightFixed();
    if (fixedHeight) {
      boxHeight = top + style.getPx(Style.HEIGHT, getParent().getHeight()) + bottom;
    }

    // If this is an image element, handle image here and return
    if (image != null) {
      boolean fixedWidth = style.lengthIsFixed(Style.WIDTH, true);

      if (fixedHeight && fixedWidth) {
        int w = style.getPx(Style.WIDTH, containingWidth);
        int h = style.getPx(Style.HEIGHT, containingWidth);
        if ((w != image.getWidth() || h != image.getHeight()) && w > 0 && h > 0) {
          image = GraphicsUtils.createScaledImage(image, 0, 0, image.getWidth(),
              image.getHeight(), w, h, GraphicsUtils.SCALE_SIMPLE | GraphicsUtils.SCALE_PROCESS_ALPHA);
        }
        boxWidth = w + left + right;
      } else {
        boxWidth = image.getWidth() + left + right;
        boxHeight = image.getHeight() + top + bottom;
      }
      setWidth(boxWidth);
      setHeight(boxHeight);
      if (parentLayoutContext != null) {
        parentLayoutContext.advance(boxHeight);
      }
      return;
    }

    // calculate the maximum inner width (outerMaxWidth minus borders, padding,
    // margin) -- the maximum width available for child layout
    int innerMaxWidth = outerMaxWidth - left - right;

    // Keeps track of y-position and borders for the regular layout set by
    // floating elements. The viewport width is taken into account here.
    LayoutContext layoutContext = new LayoutContext(
        Math.min(innerMaxWidth, viewportWidth), style, parentLayoutContext,
        left, top);

    // line break positions determined when laying out TextFragmentWidget
    // are carried over from one TextFragmentWidget to another.
    int breakPosition = -1;

    // Index of first widget on a single line. Used when adjusting position
    // for top/bottom/left/right/center align
    int lineStartIndex = 0;

    // This is the position where regular in-flow widgets are inserted.
    // Positioned widget are inserted at the end so they are always on top of
    // regular widgets.
    int childInsertionIndex = 0;

    // iterate all child widgets
    for (int childIndex = 0; childIndex < children.size(); childIndex++) {
      Widget child = (Widget) children.elementAt(childIndex);
      Style childStyle;
      int childPosition;
      int childWidth;

      if (child instanceof TextFragmentWidget) {
        TextFragmentWidget fragment = (TextFragmentWidget) child;
        addChild(childInsertionIndex, fragment);
        childStyle = fragment.element.getComputedStyle();
        childPosition = childStyle.getEnum(Style.POSITION);

        fragment.setX(left);
        fragment.setY(top + layoutContext.getCurrentY());
        fragment.setWidth(innerMaxWidth);

        // line-break and size the fragment
        breakPosition = fragment.doLayout(childIndex, layoutContext,
            breakPosition, lineStartIndex, childInsertionIndex);

        // update position and status accordingly
        if (fragment.getLineCount() > 1) {      
          lineStartIndex = childInsertionIndex;
        }
        childInsertionIndex++;
        childWidth = fragment.getWidth();
      } else {
        // break positions are valid only for sequences of TextFragmentWidget
        breakPosition = -1;
        BlockWidget block = (BlockWidget) child;
        childStyle = block.element.getComputedStyle();
        int childDisplay = childStyle.getEnum(Style.DISPLAY);
        childPosition = childStyle.getEnum(Style.POSITION);
        int floating = childStyle.getEnum(Style.FLOAT);

        if (childPosition == Style.ABSOLUTE || childPosition == Style.FIXED){
          // absolute or fixed position: move block to its position; leave
          // anything else unaffected (in particular the layout context).
          addChild(block);

          block.doLayout(innerMaxWidth, viewportWidth, null, true);
          int left1 = marginLeft + borderLeft;
          int right1 = marginRight + borderRight;
          int top1 = marginTop + borderTop;
          int bottom1 = marginBottom + borderBottom;
          int iw = boxWidth - left1 - right1;

          if (childStyle.getEnum(Style.RIGHT) != Style.AUTO) {
            block.setX(boxWidth - block.boxX - right1 - block.boxWidth -
                childStyle.getPx(Style.RIGHT, iw));
          } else if (childStyle.getEnum(Style.LEFT) != Style.AUTO) {
            block.setX(left1 + childStyle.getPx(Style.LEFT, iw) - block.boxX);
          } else {
            block.setX(left1 - block.boxX);
          }
          if (childStyle.getEnum(Style.TOP) != Style.AUTO) {
            block.setY(top1 - block.boxY +
                childStyle.getPx(Style.TOP, getHeight() - top1 - bottom1));
          } else if (childStyle.getEnum(Style.BOTTOM) != Style.AUTO) {
            block.setY(top1 - block.boxY + boxHeight -
                childStyle.getPx(Style.TOP, getHeight() - top1 - bottom1));
          } else {
            block.setY(top + layoutContext.getCurrentY() - block.boxY);
          }
        } else if (floating == Style.LEFT || floating == Style.RIGHT){
          // float: easy. just call layout for the block and place it.
          // the block is added to the layout context, but the current
          // y-position remains unchanged (advance() is not called)

          addChild(block);
          block.doLayout(innerMaxWidth, viewportWidth, null, true);
          layoutContext.placeBox(block.boxWidth, block.boxHeight,
              floating, childStyle.getEnum(Style.CLEAR));
          block.setX(left + layoutContext.getBoxX() - block.boxX);
          block.setY(top + layoutContext.getBoxY() - block.boxY);
        } else if (childDisplay == Style.BLOCK ||
            childDisplay == Style.LIST_ITEM) { 
          // Blocks and list items always start a new paragraph (implying a new
          // line.

          // if there is a pending line, adjust the alignement for it
          if (layoutContext.getLineHeight() > 0) {
            if (lineStartIndex != childInsertionIndex) {
              adjustLine(lineStartIndex, childInsertionIndex, layoutContext);
            }
            layoutContext.advance(layoutContext.getLineHeight());
            previousBlock = null;
          }           

          // if the position is relative, the widget is inserted on top of
          // others. Other adjustments for relative layout are made at the end
          if (childPosition == Style.RELATIVE) {
            addChild(block);
          } else {
            addChild(childInsertionIndex++, block);
          }

          if (layoutContext.clear(childStyle.getEnum(Style.CLEAR))) {
            previousBlock = null;
          }

          // check whether we can collapse margins with the previous block
          if (previousBlock != null) {
            int m1 = previousBlock.getElement().getComputedStyle().getPx(
                Style.MARGIN_BOTTOM, outerMaxWidth);
            int m2 = childStyle.getPx(Style.MARGIN_TOP, outerMaxWidth);
            // m1 has been applied already, the difference between m1 and m2
            // still needs to be applied
            int delta;
            if (m1 < 0) {
              if (m2 < 0) {
                delta = -(m1 + m2);
              } else {
                delta = -m1;
              }
            } else if (m2 < 0) {
              delta = -m2;
            } else {
              delta = -Math.min(m1, m2);
            }
            layoutContext.advance(delta);
          }

          int saveY = layoutContext.getCurrentY();
          block.doLayout(innerMaxWidth, viewportWidth, layoutContext, false);
          block.setX(left - block.boxX);
          block.setY(top + saveY - block.boxY);
          lineStartIndex = childInsertionIndex;
          previousBlock = block;
        } else {
          // inline-block, needs to be inserted in the regular text flow
          // similar to text fragments.
          addChild(childInsertionIndex, block);
          previousBlock = null;
          block.doLayout(innerMaxWidth, viewportWidth, null, childDisplay != Style.TABLE);
          int avail = layoutContext.getHorizontalSpace(block.boxHeight);
          if (avail >= block.boxWidth) {
            layoutContext.placeBox(
                block.boxWidth, block.boxHeight, Style.NONE, 0);
          } else {
            // line break necessary
            adjustLine(lineStartIndex, childInsertionIndex, layoutContext);
            lineStartIndex = childInsertionIndex;
            layoutContext.advance(layoutContext.getLineHeight());
            layoutContext.placeBox(
                block.boxWidth, block.boxHeight, Style.NONE, 0);   
            layoutContext.advance(layoutContext.getBoxY() -
                layoutContext.getCurrentY());
            layoutContext.setLineHeight(block.boxHeight);
          }
          block.setX(left + layoutContext.getBoxX() - block.boxX);
          block.setY(top + layoutContext.getCurrentY() - block.boxY);
          childInsertionIndex++;
        }
        childWidth = block.boxWidth;
      }

      // Make adjustments for relative positioning
      if (childPosition == Style.RELATIVE) {
        if (childStyle.isSet(Style.RIGHT)) {
          child.setX(child.getX() + boxWidth - childWidth -
              childStyle.getPx(Style.RIGHT, getWidth()));
        } else {
          child.setX(child.getX() + childStyle.getPx(Style.LEFT, getWidth()));
        }
        child.setY(child.getY() + childStyle.getPx(Style.TOP, getHeight()));
      }
    }

    // Still need to adjust alignment if there is a pending line.
    if (lineStartIndex != childInsertionIndex &&
View Full Code Here

  private void adjustDimensions() { 
    int minX = 0;
    int minY = 0;
    int maxX = boxWidth;
    int maxY = boxHeight;
    Style style = element.getComputedStyle();

    if (!(this instanceof HtmlWidget) &&
        style.getEnum(Style.OVERFLOW) != Style.HIDDEN) {

      int cnt = getChildCount();
      for (int i = 0; i < cnt; i++) {
        Widget child = getChild(i);
        minX = Math.min(minX, child.getX());
View Full Code Here

   * Returns the specified width of this block including borders.
   *
   * @param containerWidth the width of the container
   */
  public int getSpecifiedWidth(int containerWidth) {
    Style style = element.getComputedStyle();
    return style.getPx(Style.WIDTH, containerWidth) +
    style.getPx(Style.BORDER_LEFT_WIDTH) +
    style.getPx(Style.BORDER_RIGHT_WIDTH) +
    style.getPx(Style.MARGIN_LEFT) +  style.getPx(Style.MARGIN_RIGHT) +
    style.getPx(Style.PADDING_LEFT) + style.getPx(Style.PADDING_RIGHT);
  }
View Full Code Here

   * the values directly, use getMinimumWidth() or getMaximumWidht() instead.
   *
   * @param containerWidth Width of the container.
   */
  protected void calculateWidth(int containerWidth) {
    Style style = element.getComputedStyle();
    int border = style.getPx(Style.BORDER_LEFT_WIDTH) +
    style.getPx(Style.BORDER_RIGHT_WIDTH) +
    style.getPx(Style.MARGIN_LEFT) +  style.getPx(Style.MARGIN_RIGHT) +
    style.getPx(Style.PADDING_LEFT) + style.getPx(Style.PADDING_RIGHT);

    int display = style.getEnum(Style.DISPLAY);

    int minW = style.getPx(Style.WIDTH);
    int maxW = minW;

    int currentLineWidth = 0;

    if (display != Style.TABLE_CELL &&
        style.lengthIsFixed(Style.WIDTH, false)) {
      minW = maxW = style.getPx(Style.WIDTH, containerWidth);
    } else if (image != null) {
      maxW = minW = image.getWidth();
    } else {

      int childContainerWidth = display == Style.TABLE_CELL
      ? style.getPx(Style.WIDTH, containerWidth) + border
          : containerWidth - border;

      for (int i = 0; i < children.size(); i++) {
        Widget child = (Widget) children.elementAt(i);
        if (child instanceof TextFragmentWidget) {
          TextFragmentWidget fragment = (TextFragmentWidget) child;
          int[] widths = fragment.element.getComputedStyle().getCharWidths();
          Font font = fragment.getFont();
          String text = fragment.text;

          char c = 160;
          int wordWidth = 0;
          for (int j = 0; j < text.length(); j++) {
            char d = text.charAt(j);
            if (Util.canBreak(c, d)) {
              minW = Math.max(minW, wordWidth);
              currentLineWidth += wordWidth;
              if (c == '\n') {
                maxW = Math.max(maxW, currentLineWidth);
                currentLineWidth = 0;
              }
              wordWidth = 0;
            }
            c = d;
            wordWidth += c < widths.length ? widths[c] : font.charWidth(c);
          }
          if (c == '\n') {
            maxW = Math.max(maxW, currentLineWidth);
            currentLineWidth = 0;
          }

          minW = Math.max(minW, wordWidth);
          currentLineWidth += wordWidth;
        } else {
          BlockWidget block = (BlockWidget) child;
          Style childStyle = block.getElement().getComputedStyle();

          int childDisplay = childStyle.getEnum(Style.DISPLAY);
          if (childStyle.getEnum(Style.FLOAT) == Style.NONE &&
              (childDisplay == Style.BLOCK || childDisplay == Style.LIST_ITEM)) {
            maxW = Math.max(maxW, currentLineWidth);
            maxW = Math.max(maxW, block.getMaximumWidth(childContainerWidth));
            currentLineWidth = 0;
          } else {
View Full Code Here

   */
  public void drawContent(Graphics g, int dx, int dy) {
    dx += boxX;
    dy += boxY;

    Style style = element.getComputedStyle();

    int marginTop = style.getPx(Style.MARGIN_TOP, containingWidth);
    int marginBottom = style.getPx(Style.MARGIN_BOTTOM, containingWidth);

    int borderTop = style.getPx(Style.BORDER_TOP_WIDTH, containingWidth);
    int borderRight = style.getPx(Style.BORDER_RIGHT_WIDTH, containingWidth);
    int borderBottom = style.getPx(Style.BORDER_BOTTOM_WIDTH, containingWidth);
    int borderLeft = style.getPx(Style.BORDER_LEFT_WIDTH, containingWidth);

    // set to first pixel on border == outside padding area
    int x0 = dx + marginLeft + borderLeft - 1;
    int x1 = dx + boxWidth - marginRight - borderRight;
    int y0 = dy + marginTop + borderTop - 1;
    int y1 = dy + boxHeight - marginBottom - borderBottom;

    int bg = style.getValue(Style.BACKGROUND_COLOR);

    if ((bg & 0x0ff000000) != 0) {
      g.setColor(bg);
      g.fillRect(x0 + 1, y0 + 1, x1 - x0 - 1, y1 - y0 - 1);
    }
    if (style.backgroundImage != null && style.backgroundImage[0] != null) {
      Image img = style.backgroundImage[0];
      int cx = g.getClipX();
      int cy = g.getClipY();
      int cw = g.getClipWidth();
      int ch = g.getClipHeight();
      int repeat = style.getEnum(Style.BACKGROUND_REPEAT);

      int bgX = repeat == Style.REPEAT_X || repeat == Style.REPEAT ? 0 :
        style.getBackgroundReferencePoint(Style.BACKGROUND_POSITION_X,
            x1 - x0 - 1, img.getWidth());
      int bgY = repeat == Style.REPEAT_Y || repeat == Style.REPEAT ? 0 :
        style.getBackgroundReferencePoint(Style.BACKGROUND_POSITION_Y,
            y1 - y0 - 1, img.getHeight());

      g.clipRect(x0 + 1, y0 + 1, x1 - x0 - 1, y1 - y0 - 1);
      if (repeat == Style.REPEAT_Y || repeat == Style.REPEAT) {
        do {
          if (repeat == Style.REPEAT) {
            do {
              g.drawImage(img, x0 + 1 + bgX, y0 + 1 + bgY, Graphics.TOP | Graphics.LEFT);
              bgX += img.getWidth();
            } while (bgX < x1 - x0);
            bgX = 0;
          } else {
            g.drawImage(img, x0 + 1 + bgX, y0 + 1 + bgY, Graphics.TOP | Graphics.LEFT);
          }
          bgY += img.getHeight();
        } while (bgY < y1 - y0);
      } else if (repeat == Style.REPEAT_X) {
        do {
          g.drawImage(img, x0 + 1 + bgX, y0 + 1 + bgY, Graphics.TOP | Graphics.LEFT);
          bgX += img.getWidth();
        } while (bgX < x1 - x0);
      } else {
        g.drawImage(img, x0 + 1 + bgX, y0 + 1 + bgY, Graphics.TOP | Graphics.LEFT);
      }
      g.setClip(cx, cy, cw, ch);
    }

    if (borderTop > 0) {
      g.setColor(style.getValue(Style.BORDER_TOP_COLOR));
      int dLeft = (borderLeft << 8) / borderTop;
      int dRight = (borderRight << 8) / borderTop;
      for (int i = 0; i < borderTop; i++) {
        g.drawLine(x0 - ((i * dLeft) >> 8), y0 - i, x1 + ((i * dRight) >> 8), y0 - i);
      }
    }
    if (borderRight > 0) {
      g.setColor(style.getValue(Style.BORDER_RIGHT_COLOR));
      int dTop = (borderTop << 8) / borderRight;
      int dBottom = (borderBottom << 8) / borderRight;
      for (int i = 0; i < borderRight; i++) {
        g.drawLine(x1 + i, y0 - ((i * dTop) >> 8), x1 + i, y1 + ((i * dBottom) >> 8));
      }
    }
    if (borderBottom > 0) {
      g.setColor(style.getValue(Style.BORDER_BOTTOM_COLOR));
      int dLeft = (borderLeft << 8) / borderBottom;
      int dRight = (borderRight << 8) / borderBottom;
      for (int i = 0; i < borderBottom; i++) {
        g.drawLine(x0 - ((i * dLeft) >> 8), y1 + i, x1 + ((i * dRight) >> 8), y1 + i);
      }
    }
    if (borderLeft > 0) {
      g.setColor(style.getValue(Style.BORDER_LEFT_COLOR));
      int dTop = (borderTop << 8) / borderLeft;
      int dBottom = (borderBottom << 8) / borderLeft;
      for (int i = 0; i < borderLeft; i++) {
        g.drawLine(x0 - i, y0 - ((i * dTop) >> 8), x0 - i, y1 + ((i * dBottom) >> 8));
      }
    }
    if (style.getEnum(Style.DISPLAY) == Style.LIST_ITEM) {
      g.setColor(style.getValue(Style.COLOR));

      Font f = style.getFont();
      // en space -- see http://en.wikipedia.org/wiki/En_%28typography%29
      // using this because on blackberry digit widths are messed up
      int en = f.getHeight() / 2;
      // round up so in doubt the dot size is a bit bigger and the pos is lower
      int size = (f.getHeight() + 2) / 3;
      int liy = y0 + 1 + style.getPx(Style.PADDING_TOP, containingWidth);

      switch (style.getValue(Style.LIST_STYLE_TYPE)) {
        case Style.SQUARE:
          g.fillRect(dx - size - en, liy + size, size, size);
          break;
        case Style.CIRCLE:
          g.drawRoundRect(dx - size - en, liy + size, size, size, size / 2, size / 2);
          break;
        case Style.DECIMAL:
          String nr = (getParent().indexOfChild(this) + 1) + ". ";
          g.setFont(f);
          g.drawString(nr, dx - f.stringWidth(nr), liy, Graphics.TOP | Graphics.LEFT);
          break;
        case Style.DISC:
          g.fillRoundRect(dx - size - en, liy + size, size, size, size / 2,
              size / 2);
          break;
      }
    }
    if (image != null) {
      g.drawImage(image, x0 + 1 + style.getPx(Style.PADDING_LEFT, containingWidth), y0 + 1 + style.getPx(Style.PADDING_TOP, containingWidth), Graphics.TOP | Graphics.LEFT);
    }
  }
View Full Code Here

      if (boxX != 0 || boxY != 0 || boxWidth != getWidth() || boxHeight != getHeight()) {
        g.setColor(0x0ff0000);
        g.drawRect(dx, dy, getWidth(), getHeight());
      }
     
      Style style = element.getComputedStyle();
      for (int i = 0; i < 3; i++) {
        int id;
        int color;
        // Colors: Yellow: margin; Purple: padding; light blue: block-level element.
        switch (i) {
        case 0:
          color = 0x88ffff00;
          id = Style.MARGIN_TOP;
          break;
        case 1:
          color = 0x88ff0000;
          id = Style.BORDER_TOP_WIDTH;
          break;
        default:
          color = 0x088ff00ff;
          id = Style.PADDING_TOP;
        }

        int top = style.getPx(id, containingWidth);
        int right = i == 0 ? marginRight : style.getPx(id + 1, containingWidth);
        int bottom = style.getPx(id + 2, containingWidth);
        int left = i == 0 ? marginLeft : style.getPx(id + 3, containingWidth);
       
        GraphicsUtils.fillRectAlpha(g, x0, y0, x1 - x0 + 1, top, color);
        GraphicsUtils.fillRectAlpha(g, x0, y1 - bottom, x1 - x0 + 1, bottom, color);

        GraphicsUtils.fillRectAlpha(g, x0, y0 + top, left, y1 - y0 + 1 - top - bottom, color);
View Full Code Here

TOP

Related Classes of com.google.minijoe.html.css.Style

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.