bool isTableStructureNode(const Node *node) { RenderObject *r = node->renderer(); return (r && (r->isTableCell() || r->isTableRow() || r->isTableSection() || r->isTableCol())); }
void SVGRenderSupport::layoutChildren(RenderObject* start, bool selfNeedsLayout) { bool layoutSizeChanged = layoutSizeOfNearestViewportChanged(start); bool transformChanged = transformToRootChanged(start); HashSet<RenderObject*> notlayoutedObjects; for (RenderObject* child = start->firstChild(); child; child = child->nextSibling()) { bool needsLayout = selfNeedsLayout; bool childEverHadLayout = child->everHadLayout(); if (transformChanged) { // If the transform changed we need to update the text metrics (note: this also happens for layoutSizeChanged=true). if (child->isSVGText()) toRenderSVGText(child)->setNeedsTextMetricsUpdate(); needsLayout = true; } if (layoutSizeChanged) { // When selfNeedsLayout is false and the layout size changed, we have to check whether this child uses relative lengths if (SVGElement* element = child->node()->isSVGElement() ? toSVGElement(child->node()) : 0) { if (element->hasRelativeLengths()) { // When the layout size changed and when using relative values tell the RenderSVGShape to update its shape object if (child->isSVGShape()) toRenderSVGShape(child)->setNeedsShapeUpdate(); else if (child->isSVGText()) { toRenderSVGText(child)->setNeedsTextMetricsUpdate(); toRenderSVGText(child)->setNeedsPositioningValuesUpdate(); } needsLayout = true; } } } SubtreeLayoutScope layoutScope(*child); // Resource containers are nasty: they can invalidate clients outside the current SubtreeLayoutScope. // Since they only care about viewport size changes (to resolve their relative lengths), we trigger // their invalidation directly from SVGSVGElement::svgAttributeChange() or at a higher // SubtreeLayoutScope (in RenderView::layout()). if (needsLayout && !child->isSVGResourceContainer()) layoutScope.setNeedsLayout(child); layoutResourcesIfNeeded(child); if (child->needsLayout()) { child->layout(); // Renderers are responsible for repainting themselves when changing, except // for the initial paint to avoid potential double-painting caused by non-sensical "old" bounds. // We could handle this in the individual objects, but for now it's easier to have // parent containers call repaint(). (RenderBlock::layout* has similar logic.) if (!childEverHadLayout && !RuntimeEnabledFeatures::repaintAfterLayoutEnabled()) child->repaint(); } else if (layoutSizeChanged) notlayoutedObjects.add(child); } if (!layoutSizeChanged) { ASSERT(notlayoutedObjects.isEmpty()); return; } // If the layout size changed, invalidate all resources of all children that didn't go through the layout() code path. HashSet<RenderObject*>::iterator end = notlayoutedObjects.end(); for (HashSet<RenderObject*>::iterator it = notlayoutedObjects.begin(); it != end; ++it) invalidateResourcesOfChildren(*it); }
void writeSVGResourceContainer(TextStream& ts, const RenderObject& object, int indent) { writeStandardPrefix(ts, object, indent); Element* element = toElement(object.node()); const AtomicString& id = element->getIdAttribute(); writeNameAndQuotedValue(ts, "id", id); RenderSVGResourceContainer* resource = const_cast<RenderObject&>(object).toRenderSVGResourceContainer(); ASSERT(resource); if (resource->resourceType() == MaskerResourceType) { RenderSVGResourceMasker* masker = static_cast<RenderSVGResourceMasker*>(resource); writeNameValuePair(ts, "maskUnits", masker->maskUnits()); writeNameValuePair(ts, "maskContentUnits", masker->maskContentUnits()); ts << "\n"; #if ENABLE(FILTERS) } else if (resource->resourceType() == FilterResourceType) { RenderSVGResourceFilter* filter = static_cast<RenderSVGResourceFilter*>(resource); writeNameValuePair(ts, "filterUnits", filter->filterUnits()); writeNameValuePair(ts, "primitiveUnits", filter->primitiveUnits()); ts << "\n"; // Creating a placeholder filter which is passed to the builder. FloatRect dummyRect; RefPtr<SVGFilter> dummyFilter = SVGFilter::create(AffineTransform(), dummyRect, dummyRect, dummyRect, true); if (auto builder = filter->buildPrimitives(dummyFilter.get())) { if (FilterEffect* lastEffect = builder->lastEffect()) lastEffect->externalRepresentation(ts, indent + 1); } #endif } else if (resource->resourceType() == ClipperResourceType) { RenderSVGResourceClipper* clipper = static_cast<RenderSVGResourceClipper*>(resource); writeNameValuePair(ts, "clipPathUnits", clipper->clipPathUnits()); ts << "\n"; } else if (resource->resourceType() == MarkerResourceType) { RenderSVGResourceMarker* marker = static_cast<RenderSVGResourceMarker*>(resource); writeNameValuePair(ts, "markerUnits", marker->markerUnits()); ts << " [ref at " << marker->referencePoint() << "]"; ts << " [angle="; if (marker->angle() == -1) ts << "auto" << "]\n"; else ts << marker->angle() << "]\n"; } else if (resource->resourceType() == PatternResourceType) { RenderSVGResourcePattern* pattern = static_cast<RenderSVGResourcePattern*>(resource); // Dump final results that are used for rendering. No use in asking SVGPatternElement for its patternUnits(), as it may // link to other patterns using xlink:href, we need to build the full inheritance chain, aka. collectPatternProperties() PatternAttributes attributes; pattern->patternElement().collectPatternAttributes(attributes); writeNameValuePair(ts, "patternUnits", attributes.patternUnits()); writeNameValuePair(ts, "patternContentUnits", attributes.patternContentUnits()); AffineTransform transform = attributes.patternTransform(); if (!transform.isIdentity()) ts << " [patternTransform=" << transform << "]"; ts << "\n"; } else if (resource->resourceType() == LinearGradientResourceType) { RenderSVGResourceLinearGradient* gradient = static_cast<RenderSVGResourceLinearGradient*>(resource); // Dump final results that are used for rendering. No use in asking SVGGradientElement for its gradientUnits(), as it may // link to other gradients using xlink:href, we need to build the full inheritance chain, aka. collectGradientProperties() LinearGradientAttributes attributes; gradient->linearGradientElement().collectGradientAttributes(attributes); writeCommonGradientProperties(ts, attributes.spreadMethod(), attributes.gradientTransform(), attributes.gradientUnits()); ts << " [start=" << gradient->startPoint(attributes) << "] [end=" << gradient->endPoint(attributes) << "]\n"; } else if (resource->resourceType() == RadialGradientResourceType) { RenderSVGResourceRadialGradient* gradient = static_cast<RenderSVGResourceRadialGradient*>(resource); // Dump final results that are used for rendering. No use in asking SVGGradientElement for its gradientUnits(), as it may // link to other gradients using xlink:href, we need to build the full inheritance chain, aka. collectGradientProperties() RadialGradientAttributes attributes; gradient->radialGradientElement().collectGradientAttributes(attributes); writeCommonGradientProperties(ts, attributes.spreadMethod(), attributes.gradientTransform(), attributes.gradientUnits()); FloatPoint focalPoint = gradient->focalPoint(attributes); FloatPoint centerPoint = gradient->centerPoint(attributes); float radius = gradient->radius(attributes); float focalRadius = gradient->focalRadius(attributes); ts << " [center=" << centerPoint << "] [focal=" << focalPoint << "] [radius=" << radius << "] [focalRadius=" << focalRadius << "]\n"; } else ts << "\n"; writeChildren(ts, object, indent); }
void RenderRubyAsBlock::addChild(RenderObject* child, RenderObject* beforeChild) { // Insert :before and :after content before/after the RenderRubyRun(s) if (child->isBeforeContent()) { if (child->isInline()) { // Add generated inline content normally RenderBlockFlow::addChild(child, firstChild()); } else { // Wrap non-inline content with an anonymous inline-block. RenderBlock* beforeBlock = rubyBeforeBlock(this); if (!beforeBlock) { beforeBlock = createAnonymousRubyInlineBlock(this); RenderBlockFlow::addChild(beforeBlock, firstChild()); } beforeBlock->addChild(child); } return; } if (child->isAfterContent()) { if (child->isInline()) { // Add generated inline content normally RenderBlockFlow::addChild(child); } else { // Wrap non-inline content with an anonymous inline-block. RenderBlock* afterBlock = rubyAfterBlock(this); if (!afterBlock) { afterBlock = createAnonymousRubyInlineBlock(this); RenderBlockFlow::addChild(afterBlock); } afterBlock->addChild(child); } return; } // If the child is a ruby run, just add it normally. if (child->isRubyRun()) { RenderBlockFlow::addChild(child, beforeChild); return; } if (beforeChild && !isAfterContent(beforeChild)) { // insert child into run ASSERT(!beforeChild->isRubyRun()); RenderObject* run = beforeChild; while (run && !run->isRubyRun()) run = run->parent(); if (run) { run->addChild(child, beforeChild); return; } ASSERT_NOT_REACHED(); // beforeChild should always have a run as parent! // Emergency fallback: fall through and just append. } // If the new child would be appended, try to add the child to the previous run // if possible, or create a new run otherwise. // (The RenderRubyRun object will handle the details) RenderRubyRun* lastRun = lastRubyRun(this); if (!lastRun || lastRun->hasRubyText()) { lastRun = RenderRubyRun::staticCreateRubyRun(this); RenderBlockFlow::addChild(lastRun, beforeChild); } lastRun->addChild(child); }
void RenderTableRow::addChild(RenderObject* child, RenderObject* beforeChild) { // Make sure we don't append things after :after-generated content if we have it. if (!beforeChild) beforeChild = afterPseudoElementRenderer(); if (!child->isTableCell()) { RenderObject* last = beforeChild; if (!last) last = lastChild(); if (last && last->isAnonymous() && last->isTableCell() && !last->isBeforeOrAfterContent()) { if (beforeChild == last) beforeChild = last->firstChild(); last->addChild(child, beforeChild); return; } if (beforeChild && !beforeChild->isAnonymous() && beforeChild->parent() == this) { RenderObject* cell = beforeChild->previousSibling(); if (cell && cell->isTableCell() && cell->isAnonymous()) { cell->addChild(child); return; } } // If beforeChild is inside an anonymous cell, insert into the cell. if (last && !last->isTableCell() && last->parent() && last->parent()->isAnonymous() && !last->parent()->isBeforeOrAfterContent()) { last->parent()->addChild(child, beforeChild); return; } RenderTableCell* cell = new (renderArena()) RenderTableCell(document() /* anonymous object */); RefPtr<RenderStyle> newStyle = RenderStyle::create(); newStyle->inheritFrom(style()); newStyle->setDisplay(TABLE_CELL); cell->setStyle(newStyle.release()); addChild(cell, beforeChild); cell->addChild(child); return; } // If the next renderer is actually wrapped in an anonymous table cell, we need to go up and find that. while (beforeChild && beforeChild->parent() != this) beforeChild = beforeChild->parent(); RenderTableCell* cell = toRenderTableCell(child); // Generated content can result in us having a null section so make sure to null check our parent. if (parent()) section()->addCell(cell, this); ASSERT(!beforeChild || beforeChild->isTableCell()); RenderBox::addChild(cell, beforeChild); if (beforeChild || nextSibling()) section()->setNeedsCellRecalc(); }
void RenderTableRow::addChild(RenderObject* child, RenderObject* beforeChild) { // Make sure we don't append things after :after-generated content if we have it. if (!beforeChild) beforeChild = afterPseudoElementRenderer(); if (!child->isTableCell()) { RenderObject* last = beforeChild; if (!last) last = lastChild(); if (last && last->isAnonymous() && last->isTableCell() && !last->isBeforeOrAfterContent()) { if (beforeChild == last) beforeChild = last->firstChild(); last->addChild(child, beforeChild); return; } if (beforeChild && !beforeChild->isAnonymous() && beforeChild->parent() == this) { RenderObject* cell = beforeChild->previousSibling(); if (cell && cell->isTableCell() && cell->isAnonymous()) { cell->addChild(child); return; } } // If beforeChild is inside an anonymous cell, insert into the cell. if (last && !last->isTableCell() && last->parent() && last->parent()->isAnonymous() && !last->parent()->isBeforeOrAfterContent()) { last->parent()->addChild(child, beforeChild); return; } RenderTableCell* cell = RenderTableCell::createAnonymousWithParentRenderer(this); addChild(cell, beforeChild); cell->addChild(child); return; } if (beforeChild && beforeChild->parent() != this) beforeChild = splitAnonymousBoxesAroundChild(beforeChild); RenderTableCell* cell = toRenderTableCell(child); // Generated content can result in us having a null section so make sure to null check our parent. if (parent()) section()->addCell(cell, this); ASSERT(!beforeChild || beforeChild->isTableCell()); RenderBox::addChild(cell, beforeChild); if (beforeChild || nextSibling()) section()->setNeedsCellRecalc(); }
void RenderTheme::paintSliderTicks(RenderObject* o, const PaintInfo& paintInfo, const IntRect& rect) { Node* node = o->node(); if (!node) return; HTMLInputElement* input = node->toInputElement(); if (!input) return; HTMLDataListElement* dataList = static_cast<HTMLDataListElement*>(input->list()); if (!dataList) return; double min = input->minimum(); double max = input->maximum(); ControlPart part = o->style()->appearance(); // We don't support ticks on alternate sliders like MediaVolumeSliders. if (part != SliderHorizontalPart && part != SliderVerticalPart) return; bool isHorizontal = part == SliderHorizontalPart; IntSize thumbSize; RenderObject* thumbRenderer = input->sliderThumbElement()->renderer(); if (thumbRenderer) { RenderStyle* thumbStyle = thumbRenderer->style(); int thumbWidth = thumbStyle->width().intValue(); int thumbHeight = thumbStyle->height().intValue(); thumbSize.setWidth(isHorizontal ? thumbWidth : thumbHeight); thumbSize.setHeight(isHorizontal ? thumbHeight : thumbWidth); } IntSize tickSize = sliderTickSize(); float zoomFactor = o->style()->effectiveZoom(); FloatRect tickRect; int tickRegionSideMargin = 0; int tickRegionWidth = 0; IntRect trackBounds; RenderObject* trackRenderer = input->sliderTrackElement()->renderer(); // We can ignoring transforms because transform is handled by the graphics context. if (trackRenderer) trackBounds = trackRenderer->absoluteBoundingBoxRectIgnoringTransforms(); IntRect sliderBounds = o->absoluteBoundingBoxRectIgnoringTransforms(); // Make position relative to the transformed ancestor element. trackBounds.setX(trackBounds.x() - sliderBounds.x() + rect.x()); trackBounds.setY(trackBounds.y() - sliderBounds.y() + rect.y()); if (isHorizontal) { tickRect.setWidth(floor(tickSize.width() * zoomFactor)); tickRect.setHeight(floor(tickSize.height() * zoomFactor)); tickRect.setY(floor(rect.y() + rect.height() / 2.0 + sliderTickOffsetFromTrackCenter() * zoomFactor)); tickRegionSideMargin = trackBounds.x() + (thumbSize.width() - tickSize.width() * zoomFactor) / 2.0; tickRegionWidth = trackBounds.width() - thumbSize.width(); } else { tickRect.setWidth(floor(tickSize.height() * zoomFactor)); tickRect.setHeight(floor(tickSize.width() * zoomFactor)); tickRect.setX(floor(rect.x() + rect.width() / 2.0 + sliderTickOffsetFromTrackCenter() * zoomFactor)); tickRegionSideMargin = trackBounds.y() + (thumbSize.width() - tickSize.width() * zoomFactor) / 2.0; tickRegionWidth = trackBounds.height() - thumbSize.width(); } RefPtr<HTMLCollection> options = dataList->options(); GraphicsContextStateSaver stateSaver(*paintInfo.context); paintInfo.context->setFillColor(o->style()->visitedDependentColor(CSSPropertyColor), ColorSpaceDeviceRGB); for (unsigned i = 0; Node* node = options->item(i); i++) { ASSERT(node->hasTagName(optionTag)); HTMLOptionElement* optionElement = toHTMLOptionElement(node); String value = optionElement->value(); if (!input->isValidValue(value)) continue; double parsedValue = parseToDoubleForNumberType(input->sanitizeValue(value)); double tickFraction = (parsedValue - min) / (max - min); double tickRatio = isHorizontal && o->style()->isLeftToRightDirection() ? tickFraction : 1.0 - tickFraction; double tickPosition = round(tickRegionSideMargin + tickRegionWidth * tickRatio); if (isHorizontal) tickRect.setX(tickPosition); else tickRect.setY(tickPosition); paintInfo.context->fillRect(tickRect); } }
void SVGResourcesCycleSolver::resolveCycles() { ASSERT(m_allResources.isEmpty()); #if DEBUG_CYCLE_DETECTION > 0 fprintf(stderr, "\nBefore cycle detection:\n"); m_resources->dump(m_renderer); #endif // Stash all resources into a HashSet for the ease of traversing. HashSet<RenderSVGResourceContainer*> localResources; m_resources->buildSetOfResources(localResources); ASSERT(!localResources.isEmpty()); // Add all parent resource containers to the HashSet. HashSet<RenderSVGResourceContainer*> parentResources; RenderObject* parent = m_renderer->parent(); while (parent) { if (parent->isSVGResourceContainer()) parentResources.add(toRenderSVGResourceContainer(parent)); parent = parent->parent(); } #if DEBUG_CYCLE_DETECTION > 0 fprintf(stderr, "\nDetecting wheter any resources references any of following objects:\n"); { fprintf(stderr, "Local resources:\n"); HashSet<RenderSVGResourceContainer*>::iterator end = localResources.end(); for (HashSet<RenderSVGResourceContainer*>::iterator it = localResources.begin(); it != end; ++it) fprintf(stderr, "|> %s: object=%p (node=%p)\n", (*it)->renderName(), *it, (*it)->node()); fprintf(stderr, "Parent resources:\n"); end = parentResources.end(); for (HashSet<RenderSVGResourceContainer*>::iterator it = parentResources.begin(); it != end; ++it) fprintf(stderr, "|> %s: object=%p (node=%p)\n", (*it)->renderName(), *it, (*it)->node()); } #endif // Build combined set of local and parent resources. m_allResources = localResources; HashSet<RenderSVGResourceContainer*>::iterator end = parentResources.end(); for (HashSet<RenderSVGResourceContainer*>::iterator it = parentResources.begin(); it != end; ++it) m_allResources.add(*it); // If we're a resource, add ourselves to the HashSet. if (m_renderer->isSVGResourceContainer()) m_allResources.add(toRenderSVGResourceContainer(m_renderer)); ASSERT(!m_allResources.isEmpty()); // The job of this function is to determine wheter any of the 'resources' associated with the given 'renderer' // references us (or wheter any of its kids references us) -> that's a cycle, we need to find and break it. end = localResources.end(); for (HashSet<RenderSVGResourceContainer*>::iterator it = localResources.begin(); it != end; ++it) { RenderSVGResourceContainer* resource = *it; if (parentResources.contains(resource) || resourceContainsCycles(resource)) breakCycle(resource); } #if DEBUG_CYCLE_DETECTION > 0 fprintf(stderr, "\nAfter cycle detection:\n"); m_resources->dump(m_renderer); #endif m_allResources.clear(); }
bool RenderThemeGtk::paintCapsLockIndicator(const RenderObject& renderObject, const PaintInfo& paintInfo, const IntRect& rect) { // The other paint methods don't need to check whether painting is disabled because RenderTheme already checks it // before calling them, but paintCapsLockIndicator() is called by RenderTextControlSingleLine which doesn't check it. if (paintInfo.context->paintingDisabled()) return true; int iconSize = std::min(rect.width(), rect.height()); GRefPtr<GdkPixbuf> icon = getStockIconForWidgetType(GTK_TYPE_ENTRY, GTK_STOCK_CAPS_LOCK_WARNING, gtkTextDirection(renderObject.style().direction()), 0, getIconSizeForPixelSize(iconSize)); // Only re-scale the icon when it's smaller than the minimum icon size. if (iconSize >= gtkIconSizeMenu) iconSize = gdk_pixbuf_get_height(icon.get()); // GTK+ locates the icon right aligned in the entry. The given rectangle is already // centered vertically by RenderTextControlSingleLine. IntRect iconRect(rect.x() + rect.width() - iconSize, rect.y() + (rect.height() - iconSize) / 2, iconSize, iconSize); paintGdkPixbuf(paintInfo.context, icon.get(), iconRect); return true; }
RenderRubyBase* RenderRubyRun::rubyBase() const { RenderObject* child = lastChild(); return child && child->isRubyBase() ? static_cast<RenderRubyBase*>(child) : 0; }
void RenderNamedFlowThread::getRanges(Vector<RefPtr<Range> >& rangeObjects, const RenderRegion* region) const { LayoutUnit logicalTopForRegion; LayoutUnit logicalBottomForRegion; // extend the first region top to contain everything up to its logical height if (region->isFirstRegion()) logicalTopForRegion = LayoutUnit::min(); else logicalTopForRegion = region->logicalTopForFlowThreadContent(); // extend the last region to contain everything above its y() if (region->isLastRegion()) logicalBottomForRegion = LayoutUnit::max(); else logicalBottomForRegion = region->logicalBottomForFlowThreadContent(); Vector<Element*> elements; // eliminate the contentElements that are descendants of other contentElements for (auto it = contentElements().begin(), end = contentElements().end(); it != end; ++it) { Element* element = *it; if (!isContainedInElements(elements, element)) elements.append(element); } for (size_t i = 0; i < elements.size(); i++) { Element* contentElement = elements.at(i); if (!contentElement->renderer()) continue; RefPtr<Range> range = Range::create(&contentElement->document()); bool foundStartPosition = false; bool startsAboveRegion = true; bool endsBelowRegion = true; bool skipOverOutsideNodes = false; Node* lastEndNode = 0; for (Node* node = contentElement; node; node = nextNodeInsideContentElement(node, contentElement)) { RenderObject* renderer = node->renderer(); if (!renderer) continue; LayoutRect boundingBox; if (renderer->isRenderInline()) boundingBox = toRenderInline(renderer)->linesBoundingBox(); else if (renderer->isText()) boundingBox = toRenderText(renderer)->linesBoundingBox(); else { boundingBox = toRenderBox(renderer)->frameRect(); if (toRenderBox(renderer)->isRelPositioned()) boundingBox.move(toRenderBox(renderer)->relativePositionLogicalOffset()); } LayoutUnit offsetTop = renderer->containingBlock()->offsetFromLogicalTopOfFirstPage(); const LayoutPoint logicalOffsetFromTop(isHorizontalWritingMode() ? LayoutUnit() : offsetTop, isHorizontalWritingMode() ? offsetTop : LayoutUnit()); boundingBox.moveBy(logicalOffsetFromTop); LayoutUnit logicalTopForRenderer = region->logicalTopOfFlowThreadContentRect(boundingBox); LayoutUnit logicalBottomForRenderer = region->logicalBottomOfFlowThreadContentRect(boundingBox); // if the bounding box of the current element doesn't intersect the region box // close the current range only if the start element began inside the region, // otherwise just move the start position after this node and keep skipping them until we found a proper start position. if (!boxIntersectsRegion(logicalTopForRenderer, logicalBottomForRenderer, logicalTopForRegion, logicalBottomForRegion)) { if (foundStartPosition) { if (!startsAboveRegion) { if (range->intersectsNode(node, IGNORE_EXCEPTION)) range->setEndBefore(node, IGNORE_EXCEPTION); rangeObjects.append(range->cloneRange(IGNORE_EXCEPTION)); range = Range::create(&contentElement->document()); startsAboveRegion = true; } else skipOverOutsideNodes = true; } if (skipOverOutsideNodes) range->setStartAfter(node, IGNORE_EXCEPTION); foundStartPosition = false; continue; } // start position if (logicalTopForRenderer < logicalTopForRegion && startsAboveRegion) { if (renderer->isText()) { // Text crosses region top // for Text elements, just find the last textbox that is contained inside the region and use its start() offset as start position RenderText* textRenderer = toRenderText(renderer); for (InlineTextBox* box = textRenderer->firstTextBox(); box; box = box->nextTextBox()) { if (offsetTop + box->logicalBottom() < logicalTopForRegion) continue; range->setStart(Position(toText(node), box->start())); startsAboveRegion = false; break; } } else { // node crosses region top // for all elements, except Text, just set the start position to be before their children startsAboveRegion = true; range->setStart(Position(node, Position::PositionIsBeforeChildren)); } } else { // node starts inside region // for elements that start inside the region, set the start position to be before them. If we found one, we will just skip the others until // the range is closed. if (startsAboveRegion) { startsAboveRegion = false; range->setStartBefore(node, IGNORE_EXCEPTION); } } skipOverOutsideNodes = false; foundStartPosition = true; // end position if (logicalBottomForRegion < logicalBottomForRenderer && (endsBelowRegion || (!endsBelowRegion && !node->isDescendantOf(lastEndNode)))) { // for Text elements, just find just find the last textbox that is contained inside the region and use its start()+len() offset as end position if (renderer->isText()) { // Text crosses region bottom RenderText* textRenderer = toRenderText(renderer); InlineTextBox* lastBox = 0; for (InlineTextBox* box = textRenderer->firstTextBox(); box; box = box->nextTextBox()) { if ((offsetTop + box->logicalTop()) < logicalBottomForRegion) { lastBox = box; continue; } ASSERT(lastBox); if (lastBox) range->setEnd(Position(toText(node), lastBox->start() + lastBox->len())); break; } endsBelowRegion = false; lastEndNode = node; } else { // node crosses region bottom // for all elements, except Text, just set the start position to be after their children range->setEnd(Position(node, Position::PositionIsAfterChildren)); endsBelowRegion = true; lastEndNode = node; } } else { // node ends inside region // for elements that ends inside the region, set the end position to be after them // allow this end position to be changed only by other elements that are not descendants of the current end node if (endsBelowRegion || (!endsBelowRegion && !node->isDescendantOf(lastEndNode))) { range->setEndAfter(node, IGNORE_EXCEPTION); endsBelowRegion = false; lastEndNode = node; } } } if (foundStartPosition || skipOverOutsideNodes) rangeObjects.append(range); } }
static RenderObject* getParentOfFirstLineBox(RenderBlock* curr, RenderObject* marker) { RenderObject* firstChild = curr->firstChild(); if (!firstChild) return 0; for (RenderObject* currChild = firstChild; currChild; currChild = currChild->nextSibling()) { if (currChild == marker) continue; if (currChild->isInline() && (!currChild->isInlineFlow() || curr->generatesLineBoxesForInlineChild(currChild))) return curr; if (currChild->isFloating() || currChild->isPositioned()) continue; if (currChild->isTable() || !currChild->isRenderBlock()) break; if (curr->isListItem() && currChild->style()->htmlHacks() && currChild->element() && (currChild->element()->hasTagName(ulTag)|| currChild->element()->hasTagName(olTag))) break; RenderObject* lineBox = getParentOfFirstLineBox(static_cast<RenderBlock*>(currChild), marker); if (lineBox) return lineBox; } return 0; }
bool Text::textRendererIsNeeded(const NodeRenderingContext& context) { if (isEditingText()) return true; if (!length()) return false; if (context.style()->display() == NONE) return false; bool onlyWS = containsOnlyWhitespace(); if (!onlyWS) return true; RenderObject* parent = context.parentRenderer(); if (parent->isTable() || parent->isTableRow() || parent->isTableSection() || parent->isRenderTableCol() || parent->isFrameSet()) return false; if (context.style()->preserveNewline()) // pre/pre-wrap/pre-line always make renderers. return true; RenderObject* prev = context.previousRenderer(); if (prev && prev->isBR()) // <span><br/> <br/></span> return false; if (parent->isRenderInline()) { // <span><div/> <div/></span> if (prev && !prev->isInline()) return false; } else { if (parent->isRenderBlock() && !parent->childrenInline() && (!prev || !prev->isInline())) return false; RenderObject* first = parent->firstChild(); while (first && first->isFloatingOrOutOfFlowPositioned()) first = first->nextSibling(); if (!first || context.nextRenderer() == first) { // Whitespace at the start of a block just goes away. Don't even // make a render object for this text. return false; } } return true; }
int caretMinOffset(const Node* n) { RenderObject* r = n->renderer(); ASSERT(!n->isCharacterDataNode() || !r || r->isText()); // FIXME: This was a runtime check that seemingly couldn't fail; changed it to an assertion for now. return r ? r->caretMinOffset() : 0; }
void RenderInline::splitInlines(RenderBlock* fromBlock, RenderBlock* toBlock, RenderBlock* middleBlock, RenderObject* beforeChild, RenderFlow* oldCont) { // Create a clone of this inline. RenderInline* clone = cloneInline(this); clone->setContinuation(oldCont); // Now take all of the children from beforeChild to the end and remove // them from |this| and place them in the clone. RenderObject* o = beforeChild; while (o) { RenderObject* tmp = o; o = tmp->nextSibling(); clone->addChildToFlow(removeChildNode(tmp), 0); tmp->setNeedsLayoutAndPrefWidthsRecalc(); } // Hook |clone| up as the continuation of the middle block. middleBlock->setContinuation(clone); // We have been reparented and are now under the fromBlock. We need // to walk up our inline parent chain until we hit the containing block. // Once we hit the containing block we're done. RenderFlow* curr = static_cast<RenderFlow*>(parent()); RenderFlow* currChild = this; // FIXME: Because splitting is O(n^2) as tags nest pathologically, we cap the depth at which we're willing to clone. // There will eventually be a better approach to this problem that will let us nest to a much // greater depth (see bugzilla bug 13430) but for now we have a limit. This *will* result in // incorrect rendering, but the alternative is to hang forever. unsigned splitDepth = 1; const unsigned cMaxSplitDepth = 200; while (curr && curr != fromBlock) { if (splitDepth < cMaxSplitDepth) { // Create a new clone. RenderInline* cloneChild = clone; clone = cloneInline(curr); // Insert our child clone as the first child. clone->addChildToFlow(cloneChild, 0); // Hook the clone up as a continuation of |curr|. RenderFlow* oldCont = curr->continuation(); curr->setContinuation(clone); clone->setContinuation(oldCont); // Someone may have indirectly caused a <q> to split. When this happens, the :after content // has to move into the inline continuation. Call updateBeforeAfterContent to ensure that the inline's :after // content gets properly destroyed. if (document()->usesBeforeAfterRules()) curr->updateBeforeAfterContent(RenderStyle::AFTER); // Now we need to take all of the children starting from the first child // *after* currChild and append them all to the clone. o = currChild->nextSibling(); while (o) { RenderObject* tmp = o; o = tmp->nextSibling(); clone->addChildToFlow(curr->removeChildNode(tmp), 0); tmp->setNeedsLayoutAndPrefWidthsRecalc(); } } // Keep walking up the chain. currChild = curr; curr = static_cast<RenderFlow*>(curr->parent()); splitDepth++; } // Now we are at the block level. We need to put the clone into the toBlock. toBlock->appendChildNode(clone); // Now take all the children after currChild and remove them from the fromBlock // and put them in the toBlock. o = currChild->nextSibling(); while (o) { RenderObject* tmp = o; o = tmp->nextSibling(); toBlock->appendChildNode(fromBlock->removeChildNode(tmp)); } }
bool RenderThemeGtk::paintMediaSliderThumb(const RenderObject& o, const PaintInfo& paintInfo, const IntRect& r) { RenderStyle& style = o.style(); paintInfo.context->fillRoundedRect(FloatRoundedRect(r, borderRadiiFromStyle(style)), style.visitedDependentColor(CSSPropertyColor), style.colorSpace()); return false; }
static guint16 getInterfaceMaskFromObject(AccessibilityObject* coreObject) { guint16 interfaceMask = 0; // Component interface is always supported interfaceMask |= 1 << WAI_COMPONENT; AccessibilityRole role = coreObject->roleValue(); // Action // As the implementation of the AtkAction interface is a very // basic one (just relays in executing the default action for each // object, and only supports having one action per object), it is // better just to implement this interface for every instance of // the WebKitAccessible class and let WebCore decide what to do. interfaceMask |= 1 << WAI_ACTION; // Selection if (coreObject->isListBox() || coreObject->isMenuList()) interfaceMask |= 1 << WAI_SELECTION; // Get renderer if available. RenderObject* renderer = 0; if (coreObject->isAccessibilityRenderObject()) renderer = coreObject->renderer(); // Hyperlink (links and embedded objects). if (coreObject->isLink() || (renderer && renderer->isReplaced())) interfaceMask |= 1 << WAI_HYPERLINK; // Text & Editable Text if (role == StaticTextRole || coreObject->isMenuListOption()) interfaceMask |= 1 << WAI_TEXT; else { if (coreObject->isTextControl()) { interfaceMask |= 1 << WAI_TEXT; if (!coreObject->isReadOnly()) interfaceMask |= 1 << WAI_EDITABLE_TEXT; } else { if (role != TableRole) { interfaceMask |= 1 << WAI_HYPERTEXT; if ((renderer && renderer->childrenInline()) || roleIsTextType(role)) interfaceMask |= 1 << WAI_TEXT; } // Add the TEXT interface for list items whose // first accessible child has a text renderer if (role == ListItemRole) { AccessibilityObject::AccessibilityChildrenVector children = coreObject->children(); if (children.size()) { AccessibilityObject* axRenderChild = children.at(0).get(); interfaceMask |= getInterfaceMaskFromObject(axRenderChild); } } } } // Image if (coreObject->isImage()) interfaceMask |= 1 << WAI_IMAGE; // Table if (role == TableRole) interfaceMask |= 1 << WAI_TABLE; // Document if (role == WebAreaRole) interfaceMask |= 1 << WAI_DOCUMENT; // Value if (role == SliderRole || role == SpinButtonRole || role == ScrollBarRole || role == ProgressIndicatorRole) interfaceMask |= 1 << WAI_VALUE; #if ENABLE(INPUT_TYPE_COLOR) // Color type. if (role == ColorWellRole) interfaceMask |= 1 << WAI_TEXT; #endif return interfaceMask; }
bool RenderTableCol::isChildAllowed(const RenderObject& child, const RenderStyle& style) const { // We cannot use isTableColumn here as style() may return 0. return style.display() == TABLE_COLUMN && child.isRenderTableCol(); }
bool ProgressShadowElement::rendererIsNeeded(const NodeRenderingContext& context) { RenderObject* progressRenderer = progressElement()->renderer(); return progressRenderer && !progressRenderer->style()->hasAppearance() && HTMLDivElement::rendererIsNeeded(context); }
GlyphData SVGTextRunRenderingContext::glyphDataForCharacter(const Font& font, const TextRun& run, WidthIterator& iterator, UChar32 character, bool mirror, int currentCharacter, unsigned& advanceLength) { const SimpleFontData* primaryFont = font.primaryFont(); ASSERT(primaryFont); pair<GlyphData, GlyphPage*> pair = font.glyphDataAndPageForCharacter(character, mirror); GlyphData glyphData = pair.first; if (!glyphData.fontData) return glyphData; GlyphData missingGlyphData = primaryFont->missingGlyphData(); if (glyphData.glyph == missingGlyphData.glyph && glyphData.fontData == missingGlyphData.fontData) return glyphData; // Characters enclosed by an <altGlyph> element, may not be registered in the GlyphPage. if (!glyphData.fontData->isSVGFont()) { if (TextRun::RenderingContext* renderingContext = run.renderingContext()) { RenderObject* renderObject = static_cast<SVGTextRunRenderingContext*>(renderingContext)->renderer(); RenderObject* parentRenderObject = renderObject->isText() ? renderObject->parent() : renderObject; ASSERT(parentRenderObject); if (Element* parentRenderObjectElement = toElement(parentRenderObject->node())) { if (parentRenderObjectElement->hasTagName(SVGNames::altGlyphTag)) glyphData.fontData = primaryFont; } } } if (!glyphData.fontData || !glyphData.fontData->isSVGFont()) return glyphData; const SimpleFontData* fontData = glyphData.fontData; SVGFontElement* fontElement = 0; SVGFontFaceElement* fontFaceElement = 0; const SVGFontData* svgFontData = svgFontAndFontFaceElementForFontData(fontData, fontFaceElement, fontElement); if (!fontElement || !fontFaceElement) return glyphData; // If we got here, we're dealing with a glyph defined in a SVG Font. // The returned glyph by glyphDataAndPageForCharacter() is a glyph stored in the SVG Font glyph table. // This doesn't necessarily mean the glyph is suitable for rendering/measuring in this context, its // arabic-form/orientation/... may not match, we have to apply SVG Glyph selection to discover that. if (svgFontData->applySVGGlyphSelection(iterator, glyphData, mirror, currentCharacter, advanceLength)) return glyphData; GlyphPage* page = pair.second; ASSERT(page); FontFallbackList* fontList = font.fontList(); ASSERT(fontList); // No suitable glyph found that is compatible with the requirments (same language, arabic-form, orientation etc.) // Even though our GlyphPage contains an entry for eg. glyph "a", it's not compatible. So we have to temporarily // remove the glyph data information from the GlyphPage, and retry the lookup, which handles font fallbacks correctly. GlyphPageTreeNode* originalGlyphPageZero = fontList->glyphPageZero(); const FontFallbackList::GlyphPages& originalGlyphPages = fontList->glyphPages(); page->setGlyphDataForCharacter(character, glyphData.glyph, 0); // Assure that the font fallback glyph selection worked, aka. the fallbackGlyphData font data is not the same as before. GlyphData fallbackGlyphData = font.glyphDataForCharacter(character, mirror); ASSERT(fallbackGlyphData.fontData != fontData); // Restore original state of the SVG Font glyph table and the current font fallback list, // to assure the next lookup of the same glyph won't immediately return the fallback glyph. page->setGlyphDataForCharacter(character, glyphData.glyph, fontData); fontList->setGlyphPageZero(originalGlyphPageZero); fontList->setGlyphPages(originalGlyphPages); return fallbackGlyphData; }
void RenderView::setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos) { // Make sure both our start and end objects are defined. // Check www.msnbc.com and try clicking around to find the case where this happened. if ((start && !end) || (end && !start)) return; // Just return if the selection hasn't changed. if (m_selectionStart == start && m_selectionStartPos == startPos && m_selectionEnd == end && m_selectionEndPos == endPos) return; // Record the old selected objects. These will be used later // when we compare against the new selected objects. int oldStartPos = m_selectionStartPos; int oldEndPos = m_selectionEndPos; // Objects each have a single selection rect to examine. typedef HashMap<RenderObject*, SelectionInfo*> SelectedObjectMap; SelectedObjectMap oldSelectedObjects; SelectedObjectMap newSelectedObjects; // Blocks contain selected objects and fill gaps between them, either on the left, right, or in between lines and blocks. // In order to get the repaint rect right, we have to examine left, middle, and right rects individually, since otherwise // the union of those rects might remain the same even when changes have occurred. typedef HashMap<RenderBlock*, BlockSelectionInfo*> SelectedBlockMap; SelectedBlockMap oldSelectedBlocks; SelectedBlockMap newSelectedBlocks; RenderObject* os = m_selectionStart; RenderObject* stop = rendererAfterPosition(m_selectionEnd, m_selectionEndPos); while (os && os != stop) { if ((os->canBeSelectionLeaf() || os == m_selectionStart || os == m_selectionEnd) && os->selectionState() != SelectionNone) { // Blocks are responsible for painting line gaps and margin gaps. They must be examined as well. oldSelectedObjects.set(os, new SelectionInfo(os, true)); RenderBlock* cb = os->containingBlock(); while (cb && !cb->isRenderView()) { BlockSelectionInfo* blockInfo = oldSelectedBlocks.get(cb); if (blockInfo) break; oldSelectedBlocks.set(cb, new BlockSelectionInfo(cb)); cb = cb->containingBlock(); } } os = os->nextInPreOrder(); } // Now clear the selection. SelectedObjectMap::iterator oldObjectsEnd = oldSelectedObjects.end(); for (SelectedObjectMap::iterator i = oldSelectedObjects.begin(); i != oldObjectsEnd; ++i) i->first->setSelectionState(SelectionNone); // set selection start and end m_selectionStart = start; m_selectionStartPos = startPos; m_selectionEnd = end; m_selectionEndPos = endPos; // Update the selection status of all objects between m_selectionStart and m_selectionEnd if (start && start == end) start->setSelectionState(SelectionBoth); else { if (start) start->setSelectionState(SelectionStart); if (end) end->setSelectionState(SelectionEnd); } RenderObject* o = start; stop = rendererAfterPosition(end, endPos); while (o && o != stop) { if (o != start && o != end && o->canBeSelectionLeaf()) o->setSelectionState(SelectionInside); o = o->nextInPreOrder(); } // Now that the selection state has been updated for the new objects, walk them again and // put them in the new objects list. o = start; while (o && o != stop) { if ((o->canBeSelectionLeaf() || o == start || o == end) && o->selectionState() != SelectionNone) { newSelectedObjects.set(o, new SelectionInfo(o, true)); RenderBlock* cb = o->containingBlock(); while (cb && !cb->isRenderView()) { BlockSelectionInfo* blockInfo = newSelectedBlocks.get(cb); if (blockInfo) break; newSelectedBlocks.set(cb, new BlockSelectionInfo(cb)); cb = cb->containingBlock(); } } o = o->nextInPreOrder(); } if (!m_frameView) { // We built the maps, but we aren't going to use them. // We need to delete the values, otherwise they'll all leak! deleteAllValues(oldSelectedObjects); deleteAllValues(newSelectedObjects); deleteAllValues(oldSelectedBlocks); deleteAllValues(newSelectedBlocks); return; } // Have any of the old selected objects changed compared to the new selection? for (SelectedObjectMap::iterator i = oldSelectedObjects.begin(); i != oldObjectsEnd; ++i) { RenderObject* obj = i->first; SelectionInfo* newInfo = newSelectedObjects.get(obj); SelectionInfo* oldInfo = i->second; if (!newInfo || oldInfo->rect() != newInfo->rect() || oldInfo->state() != newInfo->state() || (m_selectionStart == obj && oldStartPos != m_selectionStartPos) || (m_selectionEnd == obj && oldEndPos != m_selectionEndPos)) { repaintViewRectangle(oldInfo->rect()); if (newInfo) { repaintViewRectangle(newInfo->rect()); newSelectedObjects.remove(obj); delete newInfo; } } delete oldInfo; } // Any new objects that remain were not found in the old objects dict, and so they need to be updated. SelectedObjectMap::iterator newObjectsEnd = newSelectedObjects.end(); for (SelectedObjectMap::iterator i = newSelectedObjects.begin(); i != newObjectsEnd; ++i) { SelectionInfo* newInfo = i->second; repaintViewRectangle(newInfo->rect()); delete newInfo; } // Have any of the old blocks changed? SelectedBlockMap::iterator oldBlocksEnd = oldSelectedBlocks.end(); for (SelectedBlockMap::iterator i = oldSelectedBlocks.begin(); i != oldBlocksEnd; ++i) { RenderBlock* block = i->first; BlockSelectionInfo* newInfo = newSelectedBlocks.get(block); BlockSelectionInfo* oldInfo = i->second; if (!newInfo || oldInfo->rects() != newInfo->rects() || oldInfo->state() != newInfo->state()) { repaintViewRectangle(oldInfo->rects()); if (newInfo) { repaintViewRectangle(newInfo->rects()); newSelectedBlocks.remove(block); delete newInfo; } } delete oldInfo; } // Any new blocks that remain were not found in the old blocks dict, and so they need to be updated. SelectedBlockMap::iterator newBlocksEnd = newSelectedBlocks.end(); for (SelectedBlockMap::iterator i = newSelectedBlocks.begin(); i != newBlocksEnd; ++i) { BlockSelectionInfo* newInfo = i->second; repaintViewRectangle(newInfo->rects()); delete newInfo; } }
void SVGTextRunRenderingContext::drawSVGGlyphs(GraphicsContext* context, const TextRun& run, const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const { SVGFontElement* fontElement = 0; SVGFontFaceElement* fontFaceElement = 0; const SVGFontData* svgFontData = svgFontAndFontFaceElementForFontData(fontData, fontFaceElement, fontElement); if (!fontElement || !fontFaceElement) return; // We can only paint SVGFonts if a context is available. RenderSVGResource* activePaintingResource = activePaintingResourceFromRun(run); RenderObject* renderObject = renderObjectFromRun(run); RenderObject* parentRenderObject = firstParentRendererForNonTextNode(renderObject); RenderStyle* parentRenderObjectStyle = 0; ASSERT(renderObject); if (!activePaintingResource) { // TODO: We're only supporting simple filled HTML text so far. RenderSVGResourceSolidColor* solidPaintingResource = RenderSVGResource::sharedSolidPaintingResource(); solidPaintingResource->setColor(context->fillColor()); activePaintingResource = solidPaintingResource; } bool isVerticalText = false; if (parentRenderObject) { parentRenderObjectStyle = parentRenderObject->style(); ASSERT(parentRenderObjectStyle); isVerticalText = parentRenderObjectStyle->svgStyle()->isVerticalWritingMode(); } float scale = scaleEmToUnits(fontData->platformData().size(), fontFaceElement->unitsPerEm()); ASSERT(activePaintingResource); FloatPoint glyphOrigin; glyphOrigin.setX(svgFontData->horizontalOriginX() * scale); glyphOrigin.setY(svgFontData->horizontalOriginY() * scale); FloatPoint currentPoint = point; RenderSVGResourceMode resourceMode = context->textDrawingMode() == TextModeStroke ? ApplyToStrokeMode : ApplyToFillMode; for (int i = 0; i < numGlyphs; ++i) { Glyph glyph = glyphBuffer.glyphAt(from + i); if (!glyph) continue; float advance = glyphBuffer.advanceAt(from + i); SVGGlyph svgGlyph = fontElement->svgGlyphForGlyph(glyph); ASSERT(!svgGlyph.isPartOfLigature); ASSERT(svgGlyph.tableEntry == glyph); SVGGlyphElement::inheritUnspecifiedAttributes(svgGlyph, svgFontData); // FIXME: Support arbitary SVG content as glyph (currently limited to <glyph d="..."> situations). if (svgGlyph.pathData.isEmpty()) { if (isVerticalText) currentPoint.move(0, advance); else currentPoint.move(advance, 0); continue; } context->save(); if (isVerticalText) { glyphOrigin.setX(svgGlyph.verticalOriginX * scale); glyphOrigin.setY(svgGlyph.verticalOriginY * scale); } AffineTransform glyphPathTransform; glyphPathTransform.translate(currentPoint.x() + glyphOrigin.x(), currentPoint.y() + glyphOrigin.y()); glyphPathTransform.scale(scale, -scale); Path glyphPath = svgGlyph.pathData; glyphPath.transform(glyphPathTransform); if (activePaintingResource->applyResource(parentRenderObject, parentRenderObjectStyle, context, resourceMode)) { if (renderObject && renderObject->isSVGInlineText()) { const RenderSVGInlineText* textRenderer = toRenderSVGInlineText(renderObject); context->setStrokeThickness(context->strokeThickness() * textRenderer->scalingFactor()); } activePaintingResource->postApplyResource(parentRenderObject, context, resourceMode, &glyphPath, 0); } context->restore(); if (isVerticalText) currentPoint.move(0, advance); else currentPoint.move(advance, 0); } }
bool AccessibilityTable::isDataTable() const { if (!m_renderer) return false; // Do not consider it a data table is it has an ARIA role. if (hasARIARole()) return false; // When a section of the document is contentEditable, all tables should be // treated as data tables, otherwise users may not be able to work with rich // text editors that allow creating and editing tables. if (node() && node()->rendererIsEditable()) return true; // This employs a heuristic to determine if this table should appear. // Only "data" tables should be exposed as tables. // Unfortunately, there is no good way to determine the difference // between a "layout" table and a "data" table. RenderTable* table = toRenderTable(m_renderer); Node* tableNode = table->node(); if (!tableNode || !isHTMLTableElement(tableNode)) return false; // if there is a caption element, summary, THEAD, or TFOOT section, it's most certainly a data table HTMLTableElement* tableElement = toHTMLTableElement(tableNode); if (!tableElement->summary().isEmpty() || tableElement->tHead() || tableElement->tFoot() || tableElement->caption()) return true; // if someone used "rules" attribute than the table should appear if (!tableElement->rules().isEmpty()) return true; // if there's a colgroup or col element, it's probably a data table. for (Node* child = tableElement->firstChild(); child; child = child->nextSibling()) { if (child->hasTagName(colTag) || child->hasTagName(colgroupTag)) return true; } // go through the cell's and check for tell-tale signs of "data" table status // cells have borders, or use attributes like headers, abbr, scope or axis table->recalcSectionsIfNeeded(); RenderTableSection* firstBody = table->firstBody(); if (!firstBody) return false; int numCols = firstBody->numColumns(); int numRows = firstBody->numRows(); // If there's only one cell, it's not a good AXTable candidate. if (numRows == 1 && numCols == 1) return false; // If there are at least 20 rows, we'll call it a data table. if (numRows >= 20) return true; // Store the background color of the table to check against cell's background colors. RenderStyle* tableStyle = table->style(); if (!tableStyle) return false; Color tableBGColor = tableStyle->visitedDependentColor(CSSPropertyBackgroundColor); // check enough of the cells to find if the table matches our criteria // Criteria: // 1) must have at least one valid cell (and) // 2) at least half of cells have borders (or) // 3) at least half of cells have different bg colors than the table, and there is cell spacing unsigned validCellCount = 0; unsigned borderedCellCount = 0; unsigned backgroundDifferenceCellCount = 0; unsigned cellsWithTopBorder = 0; unsigned cellsWithBottomBorder = 0; unsigned cellsWithLeftBorder = 0; unsigned cellsWithRightBorder = 0; Color alternatingRowColors[5]; int alternatingRowColorCount = 0; int headersInFirstColumnCount = 0; for (int row = 0; row < numRows; ++row) { int headersInFirstRowCount = 0; for (int col = 0; col < numCols; ++col) { RenderTableCell* cell = firstBody->primaryCellAt(row, col); if (!cell) continue; Node* cellNode = cell->node(); if (!cellNode) continue; if (cell->width() < 1 || cell->height() < 1) continue; validCellCount++; HTMLTableCellElement* cellElement = static_cast<HTMLTableCellElement*>(cellNode); bool isTHCell = cellElement->hasTagName(thTag); // If the first row is comprised of all <th> tags, assume it is a data table. if (!row && isTHCell) headersInFirstRowCount++; // If the first column is comprised of all <th> tags, assume it is a data table. if (!col && isTHCell) headersInFirstColumnCount++; // in this case, the developer explicitly assigned a "data" table attribute if (!cellElement->headers().isEmpty() || !cellElement->abbr().isEmpty() || !cellElement->axis().isEmpty() || !cellElement->scope().isEmpty()) return true; RenderStyle* renderStyle = cell->style(); if (!renderStyle) continue; // If the empty-cells style is set, we'll call it a data table. if (renderStyle->emptyCells() == HIDE) return true; // If a cell has matching bordered sides, call it a (fully) bordered cell. if ((cell->borderTop() > 0 && cell->borderBottom() > 0) || (cell->borderLeft() > 0 && cell->borderRight() > 0)) borderedCellCount++; // Also keep track of each individual border, so we can catch tables where most // cells have a bottom border, for example. if (cell->borderTop() > 0) cellsWithTopBorder++; if (cell->borderBottom() > 0) cellsWithBottomBorder++; if (cell->borderLeft() > 0) cellsWithLeftBorder++; if (cell->borderRight() > 0) cellsWithRightBorder++; // If the cell has a different color from the table and there is cell spacing, // then it is probably a data table cell (spacing and colors take the place of borders). Color cellColor = renderStyle->visitedDependentColor(CSSPropertyBackgroundColor); if (table->hBorderSpacing() > 0 && table->vBorderSpacing() > 0 && tableBGColor != cellColor && cellColor.alpha() != 1) backgroundDifferenceCellCount++; // If we've found 10 "good" cells, we don't need to keep searching. if (borderedCellCount >= 10 || backgroundDifferenceCellCount >= 10) return true; // For the first 5 rows, cache the background color so we can check if this table has zebra-striped rows. if (row < 5 && row == alternatingRowColorCount) { RenderObject* renderRow = cell->parent(); if (!renderRow || !renderRow->isBoxModelObject() || !toRenderBoxModelObject(renderRow)->isTableRow()) continue; RenderStyle* rowRenderStyle = renderRow->style(); if (!rowRenderStyle) continue; Color rowColor = rowRenderStyle->visitedDependentColor(CSSPropertyBackgroundColor); alternatingRowColors[alternatingRowColorCount] = rowColor; alternatingRowColorCount++; } } if (!row && headersInFirstRowCount == numCols && numCols > 1) return true; } if (headersInFirstColumnCount == numRows && numRows > 1) return true; // if there is less than two valid cells, it's not a data table if (validCellCount <= 1) return false; // half of the cells had borders, it's a data table unsigned neededCellCount = validCellCount / 2; if (borderedCellCount >= neededCellCount || cellsWithTopBorder >= neededCellCount || cellsWithBottomBorder >= neededCellCount || cellsWithLeftBorder >= neededCellCount || cellsWithRightBorder >= neededCellCount) return true; // half had different background colors, it's a data table if (backgroundDifferenceCellCount >= neededCellCount) return true; // Check if there is an alternating row background color indicating a zebra striped style pattern. if (alternatingRowColorCount > 2) { Color firstColor = alternatingRowColors[0]; for (int k = 1; k < alternatingRowColorCount; k++) { // If an odd row was the same color as the first row, its not alternating. if (k % 2 == 1 && alternatingRowColors[k] == firstColor) return false; // If an even row is not the same as the first row, its not alternating. if (!(k % 2) && alternatingRowColors[k] != firstColor) return false; } return true; } return false; }
void RenderLineBoxList::dirtyLinesFromChangedChild(RenderBoxModelObject& container, RenderObject& child) { ASSERT(is<RenderInline>(container) || is<RenderBlockFlow>(container)); if (!container.parent() || (is<RenderBlockFlow>(container) && container.selfNeedsLayout())) return; RenderInline* inlineContainer = is<RenderInline>(container) ? &downcast<RenderInline>(container) : nullptr; InlineBox* firstBox = inlineContainer ? inlineContainer->firstLineBoxIncludingCulling() : firstLineBox(); // If we have no first line box, then just bail early. if (!firstBox) { // For an empty inline, propagate the check up to our parent, unless the parent is already dirty. if (container.isInline() && !container.ancestorLineBoxDirty()) { container.parent()->dirtyLinesFromChangedChild(container); container.setAncestorLineBoxDirty(); // Mark the container to avoid dirtying the same lines again across multiple destroy() calls of the same subtree. } return; } // Try to figure out which line box we belong in. First try to find a previous // line box by examining our siblings. If we didn't find a line box, then use our // parent's first line box. RootInlineBox* box = nullptr; RenderObject* current; for (current = child.previousSibling(); current; current = current->previousSibling()) { if (current->isFloatingOrOutOfFlowPositioned()) continue; if (current->isReplaced()) { if (auto wrapper = downcast<RenderBox>(*current).inlineBoxWrapper()) box = &wrapper->root(); } if (is<RenderLineBreak>(*current)) { if (auto wrapper = downcast<RenderLineBreak>(*current).inlineBoxWrapper()) box = &wrapper->root(); } else if (is<RenderText>(*current)) { if (InlineTextBox* textBox = downcast<RenderText>(*current).lastTextBox()) box = &textBox->root(); } else if (is<RenderInline>(*current)) { InlineBox* lastSiblingBox = downcast<RenderInline>(*current).lastLineBoxIncludingCulling(); if (lastSiblingBox) box = &lastSiblingBox->root(); } if (box) break; } if (!box) { if (inlineContainer && !inlineContainer->alwaysCreateLineBoxes()) { // https://bugs.webkit.org/show_bug.cgi?id=60778 // We may have just removed a <br> with no line box that was our first child. In this case // we won't find a previous sibling, but firstBox can be pointing to a following sibling. // This isn't good enough, since we won't locate the root line box that encloses the removed // <br>. We have to just over-invalidate a bit and go up to our parent. if (!inlineContainer->ancestorLineBoxDirty()) { inlineContainer->parent()->dirtyLinesFromChangedChild(*inlineContainer); inlineContainer->setAncestorLineBoxDirty(); // Mark the container to avoid dirtying the same lines again across multiple destroy() calls of the same subtree. } return; } box = &firstBox->root(); } // If we found a line box, then dirty it. if (box) { box->markDirty(); // dirty the adjacent lines that might be affected // NOTE: we dirty the previous line because RootInlineBox objects cache // the address of the first object on the next line after a BR, which we may be // invalidating here. For more info, see how RenderBlock::layoutInlineChildren // calls setLineBreakInfo with the result of findNextLineBreak. findNextLineBreak, // despite the name, actually returns the first RenderObject after the BR. // <rdar://problem/3849947> "Typing after pasting line does not appear until after window resize." if (RootInlineBox* prevBox = box->prevRootBox()) prevBox->markDirty(); // FIXME: We shouldn't need to always dirty the next line. This is only strictly // necessary some of the time, in situations involving BRs. if (RootInlineBox* nextBox = box->nextRootBox()) nextBox->markDirty(); } }
void SVGRenderSupport::layoutChildren(RenderObject* start, bool selfNeedsLayout) { bool layoutSizeChanged = layoutSizeOfNearestViewportChanged(start); bool transformChanged = transformToRootChanged(start); bool hasSVGShadow = rendererHasSVGShadow(start); bool needsBoundariesUpdate = start->needsBoundariesUpdate(); HashSet<RenderObject*> notlayoutedObjects; for (RenderObject* child = start->firstChild(); child; child = child->nextSibling()) { bool needsLayout = selfNeedsLayout; bool childEverHadLayout = child->everHadLayout(); if (needsBoundariesUpdate && hasSVGShadow) { // If we have a shadow, our shadow is baked into our children's cached boundaries, // so they need to update. child->setNeedsBoundariesUpdate(); needsLayout = true; } if (transformChanged) { // If the transform changed we need to update the text metrics (note: this also happens for layoutSizeChanged=true). if (child->isSVGText()) toRenderSVGText(child)->setNeedsTextMetricsUpdate(); needsLayout = true; } if (layoutSizeChanged) { // When selfNeedsLayout is false and the layout size changed, we have to check whether this child uses relative lengths if (SVGElement* element = child->node()->isSVGElement() ? toSVGElement(child->node()) : 0) { if (element->isSVGStyledElement() && toSVGStyledElement(element)->hasRelativeLengths()) { // When the layout size changed and when using relative values tell the RenderSVGShape to update its shape object if (child->isSVGShape()) toRenderSVGShape(child)->setNeedsShapeUpdate(); else if (child->isSVGText()) { toRenderSVGText(child)->setNeedsTextMetricsUpdate(); toRenderSVGText(child)->setNeedsPositioningValuesUpdate(); } needsLayout = true; } } } if (needsLayout) child->setNeedsLayout(true, MarkOnlyThis); if (child->needsLayout()) { child->layout(); // Renderers are responsible for repainting themselves when changing, except // for the initial paint to avoid potential double-painting caused by non-sensical "old" bounds. // We could handle this in the individual objects, but for now it's easier to have // parent containers call repaint(). (RenderBlock::layout* has similar logic.) if (!childEverHadLayout) child->repaint(); } else if (layoutSizeChanged) notlayoutedObjects.add(child); ASSERT(!child->needsLayout()); } if (!layoutSizeChanged) { ASSERT(notlayoutedObjects.isEmpty()); return; } // If the layout size changed, invalidate all resources of all children that didn't go through the layout() code path. HashSet<RenderObject*>::iterator end = notlayoutedObjects.end(); for (HashSet<RenderObject*>::iterator it = notlayoutedObjects.begin(); it != end; ++it) invalidateResourcesOfChildren(*it); }
bool Text::rendererIsNeeded(RenderStyle *style) { if (!CharacterData::rendererIsNeeded(style)) return false; bool onlyWS = containsOnlyWhitespace(); if (!onlyWS) return true; RenderObject *par = parentNode()->renderer(); if (par->isTable() || par->isTableRow() || par->isTableSection() || par->isTableCol() || par->isFrameSet()) return false; if (style->preserveNewline()) // pre/pre-wrap/pre-line always make renderers. return true; RenderObject *prev = previousRenderer(); if (prev && prev->isBR()) // <span><br/> <br/></span> return false; if (par->isRenderInline()) { // <span><div/> <div/></span> if (prev && !prev->isInline()) return false; } else { if (par->isRenderBlock() && !par->childrenInline() && (!prev || !prev->isInline())) return false; RenderObject *first = par->firstChild(); while (first && first->isFloatingOrPositioned()) first = first->nextSibling(); RenderObject *next = nextRenderer(); if (!first || next == first) // Whitespace at the start of a block just goes away. Don't even // make a render object for this text. return false; } return true; }
static void writeChildren(TextStream& ts, const RenderObject& object, int indent) { for (RenderObject* child = object.firstChildSlow(); child; child = child->nextSibling()) write(ts, *child, indent + 1); }
static bool isDeletableElement(const Node* node) { if (!node || !node->isHTMLElement() || !node->inDocument() || !node->rendererIsEditable()) return false; // In general we want to only draw the UI around object of a certain area, but we still keep the min width/height to // make sure we don't end up with very thin or very short elements getting the UI. const int minimumArea = 2500; const int minimumWidth = 48; const int minimumHeight = 16; const unsigned minimumVisibleBorders = 1; RenderObject* renderer = node->renderer(); if (!renderer || !renderer->isBox()) return false; // Disallow the body element since it isn't practical to delete, and the deletion UI would be clipped. if (node->hasTagName(bodyTag)) return false; // Disallow elements with any overflow clip, since the deletion UI would be clipped as well. <rdar://problem/6840161> if (renderer->hasOverflowClip()) return false; // Disallow Mail blockquotes since the deletion UI would get in the way of editing for these. if (isMailBlockquote(node)) return false; RenderBox* box = toRenderBox(renderer); IntRect borderBoundingBox = box->borderBoundingBox(); if (borderBoundingBox.width() < minimumWidth || borderBoundingBox.height() < minimumHeight) return false; if ((borderBoundingBox.width() * borderBoundingBox.height()) < minimumArea) return false; if (renderer->isTable()) return true; if (node->hasTagName(ulTag) || node->hasTagName(olTag) || node->hasTagName(iframeTag)) return true; if (renderer->isPositioned()) return true; if (renderer->isRenderBlock() && !renderer->isTableCell()) { RenderStyle* style = renderer->style(); if (!style) return false; // Allow blocks that have background images if (style->hasBackgroundImage()) { for (const FillLayer* background = style->backgroundLayers(); background; background = background->next()) { if (background->image() && background->image()->canRender(1)) return true; } } // Allow blocks with a minimum number of non-transparent borders unsigned visibleBorders = style->borderTop().isVisible() + style->borderBottom().isVisible() + style->borderLeft().isVisible() + style->borderRight().isVisible(); if (visibleBorders >= minimumVisibleBorders) return true; // Allow blocks that have a different background from it's parent ContainerNode* parentNode = node->parentNode(); if (!parentNode) return false; RenderObject* parentRenderer = parentNode->renderer(); if (!parentRenderer) return false; RenderStyle* parentStyle = parentRenderer->style(); if (!parentStyle) return false; if (renderer->hasBackground() && (!parentRenderer->hasBackground() || style->visitedDependentColor(CSSPropertyBackgroundColor) != parentStyle->visitedDependentColor(CSSPropertyBackgroundColor))) return true; } return false; }
bool ContainerNode::getUpperLeftCorner(FloatPoint& point) const { if (!renderer()) return false; // What is this code really trying to do? RenderObject* o = renderer(); RenderObject* p = o; if (!o->isInline() || o->isReplaced()) { point = o->localToAbsolute(FloatPoint(), UseTransforms); return true; } // find the next text/image child, to get a position while (o) { p = o; if (o->firstChild()) o = o->firstChild(); else if (o->nextSibling()) o = o->nextSibling(); else { RenderObject* next = 0; while (!next && o->parent()) { o = o->parent(); next = o->nextSibling(); } o = next; if (!o) break; } ASSERT(o); if (!o->isInline() || o->isReplaced()) { point = o->localToAbsolute(FloatPoint(), UseTransforms); return true; } if (p->node() && p->node() == this && o->isText() && !o->isBR() && !toRenderText(o)->firstTextBox()) { // do nothing - skip unrendered whitespace that is a child or next sibling of the anchor } else if ((o->isText() && !o->isBR()) || o->isReplaced()) { point = FloatPoint(); if (o->isText() && toRenderText(o)->firstTextBox()) { point.move(toRenderText(o)->linesBoundingBox().x(), toRenderText(o)->firstTextBox()->root()->lineTop()); } else if (o->isBox()) { RenderBox* box = toRenderBox(o); point.moveBy(box->location()); } point = o->container()->localToAbsolute(point, UseTransforms); return true; } } // If the target doesn't have any children or siblings that could be used to calculate the scroll position, we must be // at the end of the document. Scroll to the bottom. FIXME: who said anything about scrolling? if (!o && document().view()) { point = FloatPoint(0, document().view()->contentsHeight()); return true; } return false; }
void RenderFrameSet::positionFrames() { RenderObject* child = firstChild(); if (!child) return; int rows = frameSet()->totalRows(); int cols = frameSet()->totalCols(); int yPos = 0; int borderThickness = frameSet()->border(); #ifdef FLATTEN_FRAMESET // Keep track of the maximum width of a row which will become the maximum width of the frameset. int maxWidth = 0; const Length* rowLengths = frameSet()->rowLengths(); const Length* colLengths = frameSet()->colLengths(); for (int r = 0; r < rows && child; r++) { int xPos = 0; int height = m_rows.m_sizes[r]; int rowHeight = -1; if (rowLengths) { Length l = rowLengths[r]; if (l.isFixed()) rowHeight = l.value(); } for (int c = 0; c < cols && child; c++) { child->setPos(xPos, yPos); child->setWidth(m_cols.m_sizes[c]); child->setHeight(height); int colWidth = -1; if (colLengths) { Length l = colLengths[c]; if (l.isFixed()) colWidth = l.value(); } if (colWidth && rowHeight) { child->setNeedsLayout(true); child->layout(); } else { child->layoutIfNeeded(); } ASSERT(child->width() >= m_cols.m_sizes[c]); m_cols.m_sizes[c] = child->width(); height = max(child->height(), height); xPos += child->width() + borderThickness; child = child->nextSibling(); } ASSERT(height >= m_rows.m_sizes[r]); m_rows.m_sizes[r] = height; maxWidth = max(xPos, maxWidth); yPos += height + borderThickness; } // Compute a new width and height according to the positioning of each expanded child frame. // Note: we subtract borderThickness because we only count borders between frames. int newWidth = maxWidth - borderThickness; int newHeight = yPos - borderThickness; // Distribute the extra width and height evenly across the grid. int dWidth = (m_width - newWidth) / cols; int dHeight = (m_height - newHeight) / rows; if (dWidth > 0) { int availableWidth = m_width - (cols - 1) * borderThickness; for (int c = 0; c < cols; c++) availableWidth -= m_cols.m_sizes[c] += dWidth; // If the extra width did not distribute evenly, add the remainder to // the last column. if (availableWidth) m_cols.m_sizes[cols - 1] += availableWidth; } if (dHeight > 0) { int availableHeight = m_height - (rows - 1) * borderThickness; for (int r = 0; r < rows; r++) availableHeight -= m_rows.m_sizes[r] += dHeight; // If the extra height did not distribute evenly, add the remainder to // the last row. if (availableHeight) m_rows.m_sizes[rows - 1] += availableHeight; } // Ensure the rows and columns are filled by falling through to the normal // layout m_height = max(m_height, newHeight); m_width = max(m_width, newWidth); child = firstChild(); yPos = 0; #endif // FLATTEN_FRAMESET for (int r = 0; r < rows; r++) { int xPos = 0; int height = m_rows.m_sizes[r]; for (int c = 0; c < cols; c++) { child->setPos(xPos, yPos); int width = m_cols.m_sizes[c]; // has to be resized and itself resize its contents if (width != child->width() || height != child->height()) { child->setWidth(width); child->setHeight(height); child->setNeedsLayout(true); child->layout(); } xPos += width + borderThickness; child = child->nextSibling(); if (!child) return; } yPos += height + borderThickness; } // all the remaining frames are hidden to avoid ugly spurious unflowed frames for (; child; child = child->nextSibling()) { child->setWidth(0); child->setHeight(0); child->setNeedsLayout(false); } }