StyleResolveForDocument.cpp [plain text]
#include "config.h"
#include "StyleResolveForDocument.h"
#include "CSSFontSelector.h"
#include "Document.h"
#include "Frame.h"
#include "FrameView.h"
#include "HTMLIFrameElement.h"
#include "LocaleToScriptMapping.h"
#include "NodeRenderStyle.h"
#include "Page.h"
#include "RenderObject.h"
#include "RenderStyle.h"
#include "RenderView.h"
#include "Settings.h"
#include "StyleFontSizeFunctions.h"
#include "StyleResolver.h"
namespace WebCore {
namespace Style {
RenderStyle resolveForDocument(const Document& document)
{
ASSERT(document.hasLivingRenderTree());
RenderView& renderView = *document.renderView();
auto documentStyle = RenderStyle::create();
documentStyle.setDisplay(BLOCK);
documentStyle.setRTLOrdering(document.visuallyOrdered() ? VisualOrder : LogicalOrder);
documentStyle.setZoom(!document.printing() ? renderView.frame().pageZoomFactor() : 1);
documentStyle.setPageScaleTransform(renderView.frame().frameScaleFactor());
FontCascadeDescription documentFontDescription = documentStyle.fontDescription();
documentFontDescription.setLocale(document.contentLanguage());
documentStyle.setFontDescription(WTFMove(documentFontDescription));
documentStyle.setUserModify(document.inDesignMode() ? READ_WRITE : READ_ONLY);
#if PLATFORM(IOS)
if (document.inDesignMode())
documentStyle.setTextSizeAdjust(TextSizeAdjustment(NoTextSizeAdjustment));
#endif
Element* docElement = document.documentElement();
RenderObject* docElementRenderer = docElement ? docElement->renderer() : nullptr;
if (docElementRenderer) {
auto* body = document.bodyOrFrameset();
RenderObject* bodyRenderer = body ? body->renderer() : nullptr;
if (bodyRenderer && !docElementRenderer->style().hasExplicitlySetWritingMode())
documentStyle.setWritingMode(bodyRenderer->style().writingMode());
else
documentStyle.setWritingMode(docElementRenderer->style().writingMode());
if (bodyRenderer && !docElementRenderer->style().hasExplicitlySetDirection())
documentStyle.setDirection(bodyRenderer->style().direction());
else
documentStyle.setDirection(docElementRenderer->style().direction());
}
const Pagination& pagination = renderView.frameView().pagination();
if (pagination.mode != Pagination::Unpaginated) {
documentStyle.setColumnStylesFromPaginationMode(pagination.mode);
documentStyle.setColumnGap(pagination.gap);
if (renderView.multiColumnFlowThread())
renderView.updateColumnProgressionFromStyle(documentStyle);
if (renderView.frame().page()->paginationLineGridEnabled()) {
documentStyle.setLineGrid("-webkit-default-pagination-grid");
documentStyle.setLineSnap(LineSnapContain);
}
}
const Settings& settings = renderView.frame().settings();
FontCascadeDescription fontDescription;
fontDescription.setLocale(document.contentLanguage());
fontDescription.setRenderingMode(settings.fontRenderingMode());
fontDescription.setOneFamily(standardFamily);
fontDescription.setKeywordSizeFromIdentifier(CSSValueMedium);
int size = fontSizeForKeyword(CSSValueMedium, false, document);
fontDescription.setSpecifiedSize(size);
bool useSVGZoomRules = document.isSVGDocument();
fontDescription.setComputedSize(computedFontSizeFromSpecifiedSize(size, fontDescription.isAbsoluteSize(), useSVGZoomRules, &documentStyle, document));
FontOrientation fontOrientation;
NonCJKGlyphOrientation glyphOrientation;
std::tie(fontOrientation, glyphOrientation) = documentStyle.fontAndGlyphOrientation();
fontDescription.setOrientation(fontOrientation);
fontDescription.setNonCJKGlyphOrientation(glyphOrientation);
documentStyle.setFontDescription(fontDescription);
documentStyle.fontCascade().update(&const_cast<Document&>(document).fontSelector());
return documentStyle;
}
}
}