PassRefPtr<ComputedStyle> LayoutScrollbar::getScrollbarPseudoStyle(ScrollbarPart partType, PseudoId pseudoId) { if (!owningLayoutObject()) return nullptr; RefPtr<ComputedStyle> result = owningLayoutObject()->getUncachedPseudoStyle(PseudoStyleRequest(pseudoId, this, partType), owningLayoutObject()->style()); // Scrollbars for root frames should always have background color // unless explicitly specified as transparent. So we force it. // This is because WebKit assumes scrollbar to be always painted and missing background // causes visual artifact like non-paint invalidated dirty region. if (result && m_owningFrame && m_owningFrame->view() && !m_owningFrame->view()->isTransparent() && !result->hasBackground()) result->setBackgroundColor(StyleColor(Color::white)); return result; }
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()); }
void LayoutScrollbar::updateScrollbarParts(bool destroy) { updateScrollbarPart(ScrollbarBGPart, destroy); updateScrollbarPart(BackButtonStartPart, destroy); updateScrollbarPart(ForwardButtonStartPart, destroy); updateScrollbarPart(BackTrackPart, destroy); updateScrollbarPart(ThumbPart, destroy); updateScrollbarPart(ForwardTrackPart, destroy); updateScrollbarPart(BackButtonEndPart, destroy); updateScrollbarPart(ForwardButtonEndPart, destroy); updateScrollbarPart(TrackBGPart, destroy); if (destroy) return; // See if the scrollbar's thickness changed. If so, we need to mark our owning object as needing a layout. bool isHorizontal = orientation() == HorizontalScrollbar; int oldThickness = isHorizontal ? height() : width(); int newThickness = 0; LayoutScrollbarPart* part = m_parts.get(ScrollbarBGPart); if (part) { part->layout(); newThickness = isHorizontal ? part->size().height() : part->size().width(); } if (newThickness != oldThickness) { setFrameRect(IntRect(location(), IntSize(isHorizontal ? width() : newThickness, isHorizontal ? newThickness : height()))); if (LayoutBox* box = owningLayoutObject()) { if (box->isLayoutBlock()) toLayoutBlock(box)->notifyScrollbarThicknessChanged(); box->setChildNeedsLayout(); if (RuntimeEnabledFeatures::slimmingPaintEnabled() && m_scrollableArea) m_scrollableArea->invalidateScrollCorner(m_scrollableArea->scrollCornerRect()); } } }
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()); }
LayoutBox* LayoutScrollbar::owningLayoutObjectWithinFrame() const { if (m_owningFrame) return m_owningFrame->contentLayoutObject(); return owningLayoutObject(); }