IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect) const { LayoutBlock* caretPainter = caretLayoutObject(node); if (!caretPainter) return IntRect(); LayoutRect localRect(rect); caretPainter->flipForWritingMode(localRect); return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoundingBox(); }
// TODO(yoichio): |node| is FrameSelection::m_previousCaretNode and this is bad // design. We should use only previous layoutObject or Rectangle to invalidate // old caret. void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect) { LayoutBlock* caretLayoutBlock = caretLayoutObject(node); if (!caretLayoutBlock) return; // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. // https://bugs.webkit.org/show_bug.cgi?id=108283 LayoutRect inflatedRect = rect; inflatedRect.inflate(LayoutUnit(1)); // FIXME: We should not allow paint invalidation out of paint invalidation // state. crbug.com/457415 DisablePaintInvalidationStateAsserts disabler; m_visualRect = node->layoutObject()->invalidatePaintRectangle(inflatedRect, this); }
void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect) { LayoutBlock* caretPainter = caretLayoutObject(node); if (!caretPainter) return; // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. // https://bugs.webkit.org/show_bug.cgi?id=108283 LayoutRect inflatedRect = rect; inflatedRect.inflate(1); // FIXME: We should use mapLocalToContainer() since we know we're not un-rooted. mapCaretRectToCaretPainter(node->layoutObject(), caretPainter, inflatedRect); // FIXME: We should not allow paint invalidation out of paint invalidation state. crbug.com/457415 DisablePaintInvalidationStateAsserts disabler; caretPainter->invalidatePaintRectangle(inflatedRect); }
void CaretBase::paintCaret(Node* node, GraphicsContext& context, const LayoutPoint& paintOffset, DisplayItem::Type displayItemType) const { if (DrawingRecorder::useCachedDrawingIfPossible(context, *this, displayItemType)) return; LayoutRect drawingRect = localCaretRectWithoutUpdate(); if (LayoutBlock* layoutObject = caretLayoutObject(node)) layoutObject->flipForWritingMode(drawingRect); drawingRect.moveBy(paintOffset); const Color caretColor = node->layoutObject()->resolveColor(CSSPropertyColor); IntRect paintRect = pixelSnappedIntRect(drawingRect); DrawingRecorder drawingRecorder(context, *this, DisplayItem::kCaret, paintRect); context.fillRect(paintRect, caretColor); }
void CaretBase::updateCaretRect(const PositionWithAffinity& caretPosition) { m_caretLocalRect = LayoutRect(); if (caretPosition.isNull()) return; DCHECK(caretPosition.anchorNode()->layoutObject()); // First compute a rect local to the layoutObject at the selection start. LayoutObject* layoutObject; m_caretLocalRect = localCaretRectOfPosition(caretPosition, layoutObject); // Get the layoutObject that will be responsible for painting the caret // (which is either the layoutObject we just found, or one of its containers). LayoutBlockItem caretPainterItem = LayoutBlockItem(caretLayoutObject(caretPosition.anchorNode())); mapCaretRectToCaretPainter(LayoutItem(layoutObject), caretPainterItem, m_caretLocalRect); }
bool CaretBase::updateCaretRect(const PositionWithAffinity& caretPosition) { m_caretLocalRect = LayoutRect(); if (caretPosition.position().isNull()) return false; ASSERT(caretPosition.position().anchorNode()->layoutObject()); // First compute a rect local to the layoutObject at the selection start. LayoutObject* layoutObject; m_caretLocalRect = localCaretRectOfPosition(caretPosition, layoutObject); // Get the layoutObject that will be responsible for painting the caret // (which is either the layoutObject we just found, or one of its containers). LayoutBlock* caretPainter = caretLayoutObject(caretPosition.position().anchorNode()); mapCaretRectToCaretPainter(layoutObject, caretPainter, m_caretLocalRect); return true; }
void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoint& paintOffset) const { if (m_caretVisibility == Hidden) return; LayoutRect drawingRect = localCaretRectWithoutUpdate(); if (LayoutBlock* layoutObject = caretLayoutObject(node)) layoutObject->flipForWritingMode(drawingRect); drawingRect.moveBy(roundedIntPoint(paintOffset)); Color caretColor = Color::black; Element* element; if (node->isElementNode()) element = toElement(node); else element = node->parentElement(); if (element && element->layoutObject()) caretColor = element->layoutObject()->resolveColor(CSSPropertyColor); context->fillRect(FloatRect(drawingRect), caretColor); }