void GraphicsLayerAndroid::updateFixedPosition() { RenderLayer* renderLayer = renderLayerFromClient(m_client); if (!renderLayer) return; RenderView* view = static_cast<RenderView*>(renderLayer->renderer()); if (!view) return; // We will need the Iframe flag in the LayerAndroid tree for fixed position if (view->isRenderIFrame()) m_contentLayer->setIsIframe(true); // If we are a fixed position layer, just set it if (view->isPositioned() && view->style()->position() == FixedPosition) { // We need to get the passed CSS properties for the element SkLength left, top, right, bottom; left = convertLength(view->style()->left()); top = convertLength(view->style()->top()); right = convertLength(view->style()->right()); bottom = convertLength(view->style()->bottom()); // We also need to get the margin... SkLength marginLeft, marginTop, marginRight, marginBottom; marginLeft = convertLength(view->style()->marginLeft()); marginTop = convertLength(view->style()->marginTop()); marginRight = convertLength(view->style()->marginRight()); marginBottom = convertLength(view->style()->marginBottom()); // In order to compute the fixed element's position, we need the width // and height of the element when bottom or right is defined. // And here we should use the non-overflowed value, that means, the // overflowed content (e.g. outset shadow) will not be counted into the // width and height. int w = view->width(); int h = view->height(); int paintingOffsetX = - offsetFromRenderer().width(); int paintingOffsetY = - offsetFromRenderer().height(); SkRect viewRect; viewRect.set(paintingOffsetX, paintingOffsetY, paintingOffsetX + w, paintingOffsetY + h); IntPoint renderLayerPos(renderLayer->x(), renderLayer->y()); m_contentLayer->setFixedPosition(left, top, right, bottom, marginLeft, marginTop, marginRight, marginBottom, renderLayerPos, viewRect); } }
void PrintContext::computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight, bool allowHorizontalTiling) { m_pageRects.clear(); outPageHeight = 0; if (!m_frame->document() || !m_frame->view() || !m_frame->document()->renderer()) return; if (userScaleFactor <= 0) { LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor); return; } RenderView* view = toRenderView(m_frame->document()->renderer()); bool isHorizontal = view->style()->isHorizontalWritingMode(); float pageWidth; float pageHeight; if (isHorizontal) { pageWidth = view->docWidth(); ///NOTE: if we do not reuse the previously set logical page height, /// we can end up with off-by-one erros in the page height, /// leading to rendering issues (e.g. rows overlap pagebreaks) if (view->pageLogicalHeight() == 0) { float ratio = printRect.height() / printRect.width(); pageHeight = floorf(pageWidth * ratio); } else { pageHeight = view->pageLogicalHeight(); } } else { float ratio = printRect.width() / printRect.height(); pageHeight = view->docHeight(); pageWidth = floorf(pageHeight * ratio); } outPageHeight = pageHeight; // this is the height of the page adjusted by margins pageHeight -= headerHeight + footerHeight; if (pageHeight <= 0) { LOG_ERROR("pageHeight has bad value %.2f", pageHeight); return; } computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor, pageHeight / userScaleFactor), allowHorizontalTiling); }
void PrintContext::computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight, bool allowHorizontalTiling) { m_pageRects.clear(); outPageHeight = 0; if (!m_frame->document() || !m_frame->view() || !m_frame->document()->renderer()) return; if (userScaleFactor <= 0) { LOG_ERROR("userScaleFactor has bad value %.2f", userScaleFactor); return; } RenderView* view = toRenderView(m_frame->document()->renderer()); bool isHorizontal = view->style()->isHorizontalWritingMode(); float pageWidth; float pageHeight; const IntRect& documentRect = view->documentRect(); if (isHorizontal) { float ratio = printRect.height() / printRect.width(); pageWidth = documentRect.width(); pageHeight = floorf(pageWidth * ratio); } else { float ratio = printRect.width() / printRect.height(); pageHeight = documentRect.height(); pageWidth = floorf(pageHeight * ratio); } outPageHeight = pageHeight; // this is the height of the page adjusted by margins pageHeight -= headerHeight + footerHeight; if (pageHeight <= 0) { LOG_ERROR("pageHeight has bad value %.2f", pageHeight); return; } computePageRectsWithPageSizeInternal(FloatSize(pageWidth / userScaleFactor, pageHeight / userScaleFactor), allowHorizontalTiling); }
void FrameView::performPostLayoutTasks() { if (d->m_firstLayoutCallbackPending) { d->m_firstLayoutCallbackPending = false; m_frame->loader()->didFirstLayout(); } RenderView* root = m_frame->contentRenderer(); root->updateWidgetPositions(); if (m_widgetUpdateSet && d->m_nestedLayoutCount <= 1) { Vector<RenderPartObject*> objectVector; copyToVector(*m_widgetUpdateSet, objectVector); size_t size = objectVector.size(); for (size_t i = 0; i < size; ++i) { RenderPartObject* object = objectVector[i]; object->updateWidget(false); // updateWidget() can destroy the RenderPartObject, so we need to make sure it's // alive by checking if it's still in m_widgetUpdateSet. if (m_widgetUpdateSet->contains(object)) object->updateWidgetPosition(); } m_widgetUpdateSet->clear(); } resumeScheduledEvents(); if (!root->printing()) { IntSize currentSize = IntSize(width(), height()); float currentZoomFactor = root->style()->zoom(); bool resized = !d->m_firstLayout && (currentSize != d->m_lastLayoutSize || currentZoomFactor != d->m_lastZoomFactor); d->m_lastLayoutSize = currentSize; d->m_lastZoomFactor = currentZoomFactor; if (resized) m_frame->sendResizeEvent(); } }
void PrintContext::computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowInlineDirectionTiling) { if (!m_frame->document() || !m_frame->view() || !m_frame->document()->renderView()) return; RenderView* view = m_frame->document()->renderView(); IntRect docRect = view->documentRect(); int pageWidth = pageSizeInPixels.width(); int pageHeight = pageSizeInPixels.height(); bool isHorizontal = view->style()->isHorizontalWritingMode(); int docLogicalHeight = isHorizontal ? docRect.height() : docRect.width(); int pageLogicalHeight = isHorizontal ? pageHeight : pageWidth; int pageLogicalWidth = isHorizontal ? pageWidth : pageHeight; int inlineDirectionStart; int inlineDirectionEnd; int blockDirectionStart; int blockDirectionEnd; if (isHorizontal) { if (view->style()->isFlippedBlocksWritingMode()) { blockDirectionStart = docRect.maxY(); blockDirectionEnd = docRect.y(); } else { blockDirectionStart = docRect.y(); blockDirectionEnd = docRect.maxY(); } inlineDirectionStart = view->style()->isLeftToRightDirection() ? docRect.x() : docRect.maxX(); inlineDirectionEnd = view->style()->isLeftToRightDirection() ? docRect.maxX() : docRect.x(); } else { if (view->style()->isFlippedBlocksWritingMode()) { blockDirectionStart = docRect.maxX(); blockDirectionEnd = docRect.x(); } else { blockDirectionStart = docRect.x(); blockDirectionEnd = docRect.maxX(); } inlineDirectionStart = view->style()->isLeftToRightDirection() ? docRect.y() : docRect.maxY(); inlineDirectionEnd = view->style()->isLeftToRightDirection() ? docRect.maxY() : docRect.y(); } unsigned pageCount = ceilf((float)docLogicalHeight / pageLogicalHeight); for (unsigned i = 0; i < pageCount; ++i) { int pageLogicalTop = blockDirectionEnd > blockDirectionStart ? blockDirectionStart + i * pageLogicalHeight : blockDirectionStart - (i + 1) * pageLogicalHeight; if (allowInlineDirectionTiling) { for (int currentInlinePosition = inlineDirectionStart; inlineDirectionEnd > inlineDirectionStart ? currentInlinePosition < inlineDirectionEnd : currentInlinePosition > inlineDirectionEnd; currentInlinePosition += (inlineDirectionEnd > inlineDirectionStart ? pageLogicalWidth : -pageLogicalWidth)) { int pageLogicalLeft = inlineDirectionEnd > inlineDirectionStart ? currentInlinePosition : currentInlinePosition - pageLogicalWidth; IntRect pageRect(pageLogicalLeft, pageLogicalTop, pageLogicalWidth, pageLogicalHeight); if (!isHorizontal) pageRect = pageRect.transposedRect(); m_pageRects.append(pageRect); } } else { int pageLogicalLeft = inlineDirectionEnd > inlineDirectionStart ? inlineDirectionStart : inlineDirectionStart - pageLogicalWidth; IntRect pageRect(pageLogicalLeft, pageLogicalTop, pageLogicalWidth, pageLogicalHeight); if (!isHorizontal) pageRect = pageRect.transposedRect(); m_pageRects.append(pageRect); } } }