Exemplo n.º 1
0
void LayoutListMarker::updateMargins()
{
    const FontMetrics& fontMetrics = style()->fontMetrics();

    LayoutUnit marginStart = 0;
    LayoutUnit marginEnd = 0;

    if (isInside()) {
        if (isImage()) {
            marginEnd = cMarkerPaddingPx;
        } else {
            switch (listStyleCategory()) {
            case ListStyleCategory::Symbol:
                marginStart = -1;
                marginEnd = fontMetrics.ascent() - minPreferredLogicalWidth() + 1;
                break;
            default:
                break;
            }
        }
    } else {
        if (style()->isLeftToRightDirection()) {
            if (isImage()) {
                marginStart = -minPreferredLogicalWidth() - cMarkerPaddingPx;
            } else {
                int offset = fontMetrics.ascent() * 2 / 3;
                switch (listStyleCategory()) {
                case ListStyleCategory::None:
                    break;
                case ListStyleCategory::Symbol:
                    marginStart = -offset - cMarkerPaddingPx - 1;
                    break;
                default:
                    marginStart = m_text.isEmpty() ? LayoutUnit() : -minPreferredLogicalWidth();
                }
            }
            marginEnd = -marginStart - minPreferredLogicalWidth();
        } else {
            if (isImage()) {
                marginEnd = cMarkerPaddingPx;
            } else {
                int offset = fontMetrics.ascent() * 2 / 3;
                switch (listStyleCategory()) {
                case ListStyleCategory::None:
                    break;
                case ListStyleCategory::Symbol:
                    marginEnd = offset + cMarkerPaddingPx + 1 - minPreferredLogicalWidth();
                    break;
                default:
                    marginEnd = 0;
                }
            }
            marginStart = -marginEnd - minPreferredLogicalWidth();
        }

    }

    mutableStyleRef().setMarginStart(Length(marginStart, Fixed));
    mutableStyleRef().setMarginEnd(Length(marginEnd, Fixed));
}
void LayoutSliderContainer::layout()
{
    HTMLInputElement* input = toHTMLInputElement(node()->shadowHost());
    bool isVertical = hasVerticalAppearance(input);
    mutableStyleRef().setFlexDirection(isVertical ? FlowColumn : FlowRow);
    TextDirection oldTextDirection = style()->direction();
    if (isVertical) {
        // FIXME: Work around rounding issues in RTL vertical sliders. We want them to
        // render identically to LTR vertical sliders. We can remove this work around when
        // subpixel rendering is enabled on all ports.
        mutableStyleRef().setDirection(LTR);
    }

    Element* thumbElement = input->userAgentShadowRoot()->getElementById(ShadowElementNames::sliderThumb());
    Element* trackElement = input->userAgentShadowRoot()->getElementById(ShadowElementNames::sliderTrack());
    LayoutBox* thumb = thumbElement ? thumbElement->layoutBox() : 0;
    LayoutBox* track = trackElement ? trackElement->layoutBox() : 0;

    SubtreeLayoutScope layoutScope(*this);
    // Force a layout to reset the position of the thumb so the code below doesn't move the thumb to the wrong place.
    // FIXME: Make a custom layout class for the track and move the thumb positioning code there.
    if (track)
        layoutScope.setChildNeedsLayout(track);

    LayoutFlexibleBox::layout();

    mutableStyleRef().setDirection(oldTextDirection);
    // These should always exist, unless someone mutates the shadow DOM (e.g., in the inspector).
    if (!thumb || !track)
        return;

    double percentageOffset = sliderPosition(input).toDouble();
    LayoutUnit availableExtent = isVertical ? track->contentHeight() : track->contentWidth();
    availableExtent -= isVertical ? thumb->size().height() : thumb->size().width();
    LayoutUnit offset = percentageOffset * availableExtent;
    LayoutPoint thumbLocation = thumb->location();
    if (isVertical)
        thumbLocation.setY(thumbLocation.y() + track->contentHeight() - thumb->size().height() - offset);
    else if (style()->isLeftToRightDirection())
        thumbLocation.setX(thumbLocation.x() + offset);
    else
        thumbLocation.setX(thumbLocation.x() - offset);
    thumb->setLocation(thumbLocation);

    // We need one-off invalidation code here because painting of the timeline element does not go through style.
    // Instead it has a custom implementation in C++ code.
    // Therefore the style system cannot understand when it needs to be paint invalidated.
    setShouldDoFullPaintInvalidation();
}
Exemplo n.º 3
0
void LayoutSliderThumb::updateAppearance(const ComputedStyle& parentStyle) {
  if (parentStyle.appearance() == SliderVerticalPart)
    mutableStyleRef().setAppearance(SliderThumbVerticalPart);
  else if (parentStyle.appearance() == SliderHorizontalPart)
    mutableStyleRef().setAppearance(SliderThumbHorizontalPart);
  else if (parentStyle.appearance() == MediaSliderPart)
    mutableStyleRef().setAppearance(MediaSliderThumbPart);
  else if (parentStyle.appearance() == MediaVolumeSliderPart)
    mutableStyleRef().setAppearance(MediaVolumeSliderThumbPart);
  else if (parentStyle.appearance() == MediaFullscreenVolumeSliderPart)
    mutableStyleRef().setAppearance(MediaFullscreenVolumeSliderThumbPart);
  if (styleRef().hasAppearance())
    LayoutTheme::theme().adjustSliderThumbSize(mutableStyleRef());
}
Exemplo n.º 4
0
void LayoutListMarker::updateMargins() {
  const SimpleFontData* fontData = style()->font().primaryFont();
  DCHECK(fontData);
  if (!fontData)
    return;
  const FontMetrics& fontMetrics = fontData->getFontMetrics();

  LayoutUnit marginStart;
  LayoutUnit marginEnd;

  if (isInside()) {
    if (isImage()) {
      marginEnd = LayoutUnit(cMarkerPaddingPx);
    } else {
      switch (getListStyleCategory()) {
        case ListStyleCategory::Symbol:
          marginStart = LayoutUnit(-1);
          marginEnd =
              fontMetrics.ascent() - minPreferredLogicalWidth() + 1 +
              LayoutUnit(cUAMarkerMarginEm * style()->computedFontSize());
          break;
        default:
          break;
      }
    }
  } else {
    if (style()->isLeftToRightDirection()) {
      if (isImage()) {
        marginStart = -minPreferredLogicalWidth() - cMarkerPaddingPx;
      } else {
        int offset = fontMetrics.ascent() * 2 / 3;
        switch (getListStyleCategory()) {
          case ListStyleCategory::None:
            break;
          case ListStyleCategory::Symbol:
            marginStart = LayoutUnit(-offset - cMarkerPaddingPx - 1);
            break;
          default:
            marginStart =
                m_text.isEmpty() ? LayoutUnit() : -minPreferredLogicalWidth();
        }
      }
      marginEnd = -marginStart - minPreferredLogicalWidth();
    } else {
      if (isImage()) {
        marginEnd = LayoutUnit(cMarkerPaddingPx);
      } else {
        int offset = fontMetrics.ascent() * 2 / 3;
        switch (getListStyleCategory()) {
          case ListStyleCategory::None:
            break;
          case ListStyleCategory::Symbol:
            marginEnd =
                offset + cMarkerPaddingPx + 1 - minPreferredLogicalWidth();
            break;
          default:
            marginEnd = LayoutUnit();
        }
      }
      marginStart = -marginEnd - minPreferredLogicalWidth();
    }
  }

  mutableStyleRef().setMarginStart(Length(marginStart, Fixed));
  mutableStyleRef().setMarginEnd(Length(marginEnd, Fixed));
}