void LayoutScrollbar::updateScrollbarPart(ScrollbarPart partType, bool destroy)
{
    if (partType == NoPart)
        return;

    RefPtr<ComputedStyle> partStyle = !destroy ? getScrollbarPseudoStyle(partType,  pseudoForScrollbarPart(partType)) : PassRefPtr<ComputedStyle>(nullptr);

    bool needLayoutObject = !destroy && partStyle && partStyle->display() != NONE;

    if (needLayoutObject && partStyle->display() != BLOCK) {
        // See if we are a button that should not be visible according to OS settings.
        ScrollbarButtonsPlacement buttonsPlacement = theme()->buttonsPlacement();
        switch (partType) {
        case BackButtonStartPart:
            needLayoutObject = (buttonsPlacement == ScrollbarButtonsPlacementSingle || buttonsPlacement == ScrollbarButtonsPlacementDoubleStart
                || buttonsPlacement == ScrollbarButtonsPlacementDoubleBoth);
            break;
        case ForwardButtonStartPart:
            needLayoutObject = (buttonsPlacement == ScrollbarButtonsPlacementDoubleStart || buttonsPlacement == ScrollbarButtonsPlacementDoubleBoth);
            break;
        case BackButtonEndPart:
            needLayoutObject = (buttonsPlacement == ScrollbarButtonsPlacementDoubleEnd || buttonsPlacement == ScrollbarButtonsPlacementDoubleBoth);
            break;
        case ForwardButtonEndPart:
            needLayoutObject = (buttonsPlacement == ScrollbarButtonsPlacementSingle || buttonsPlacement == ScrollbarButtonsPlacementDoubleEnd
                || buttonsPlacement == ScrollbarButtonsPlacementDoubleBoth);
            break;
        default:
            break;
        }
    }

    LayoutScrollbarPart* partLayoutObject = m_parts.get(partType);
    if (!partLayoutObject && needLayoutObject) {
        partLayoutObject = LayoutScrollbarPart::createAnonymous(&owningLayoutObject()->document(), this, partType);
        m_parts.set(partType, partLayoutObject);
    } else if (partLayoutObject && !needLayoutObject) {
        m_parts.remove(partType);
        partLayoutObject->destroy();
        partLayoutObject = 0;
    }

    if (partLayoutObject)
        partLayoutObject->setStyle(partStyle.release());
}
示例#2
0
void LayoutScrollbar::updateScrollbarPart(ScrollbarPart partType,
                                          bool destroy) {
  if (partType == NoPart)
    return;

  RefPtr<ComputedStyle> partStyle =
      !destroy
          ? getScrollbarPseudoStyle(partType, pseudoForScrollbarPart(partType))
          : PassRefPtr<ComputedStyle>(nullptr);

  bool needLayoutObject =
      !destroy && partStyle && partStyle->display() != EDisplay::None;

  if (needLayoutObject && partStyle->display() != EDisplay::Block) {
    // See if we are a button that should not be visible according to OS
    // settings.
    WebScrollbarButtonsPlacement buttonsPlacement = theme().buttonsPlacement();
    switch (partType) {
      case BackButtonStartPart:
        needLayoutObject =
            (buttonsPlacement == WebScrollbarButtonsPlacementSingle ||
             buttonsPlacement == WebScrollbarButtonsPlacementDoubleStart ||
             buttonsPlacement == WebScrollbarButtonsPlacementDoubleBoth);
        break;
      case ForwardButtonStartPart:
        needLayoutObject =
            (buttonsPlacement == WebScrollbarButtonsPlacementDoubleStart ||
             buttonsPlacement == WebScrollbarButtonsPlacementDoubleBoth);
        break;
      case BackButtonEndPart:
        needLayoutObject =
            (buttonsPlacement == WebScrollbarButtonsPlacementDoubleEnd ||
             buttonsPlacement == WebScrollbarButtonsPlacementDoubleBoth);
        break;
      case ForwardButtonEndPart:
        needLayoutObject =
            (buttonsPlacement == WebScrollbarButtonsPlacementSingle ||
             buttonsPlacement == WebScrollbarButtonsPlacementDoubleEnd ||
             buttonsPlacement == WebScrollbarButtonsPlacementDoubleBoth);
        break;
      default:
        break;
    }
  }

  LayoutScrollbarPart* partLayoutObject = m_parts.get(partType);
  if (!partLayoutObject && needLayoutObject && m_scrollableArea) {
    partLayoutObject = LayoutScrollbarPart::createAnonymous(
        &owningLayoutObject()->document(), m_scrollableArea, this, partType);
    m_parts.set(partType, partLayoutObject);
    setNeedsPaintInvalidation(partType);
  } else if (partLayoutObject && !needLayoutObject) {
    m_parts.remove(partType);
    partLayoutObject->destroy();
    partLayoutObject = nullptr;
    if (!destroy)
      setNeedsPaintInvalidation(partType);
  }

  if (partLayoutObject)
    partLayoutObject->setStyleWithWritingModeOfParent(partStyle.release());
}