Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: Source/core/dom/Document.cpp

Issue 1145993002: Refactor root element background painting (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase, adding back TestExpectation Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 if (body) { 1606 if (body) {
1607 bodyStyle = body->mutableComputedStyle(); 1607 bodyStyle = body->mutableComputedStyle();
1608 if (didRecalcDocumentElement) 1608 if (didRecalcDocumentElement)
1609 body->clearAnimationStyleChange(); 1609 body->clearAnimationStyleChange();
1610 if (!bodyStyle || body->needsStyleRecalc() || didRecalcDocumentElement) 1610 if (!bodyStyle || body->needsStyleRecalc() || didRecalcDocumentElement)
1611 bodyStyle = ensureStyleResolver().styleForElement(body, documentElem entStyle.get()); 1611 bodyStyle = ensureStyleResolver().styleForElement(body, documentElem entStyle.get());
1612 rootWritingMode = bodyStyle->writingMode(); 1612 rootWritingMode = bodyStyle->writingMode();
1613 rootDirection = bodyStyle->direction(); 1613 rootDirection = bodyStyle->direction();
1614 } 1614 }
1615 1615
1616 RefPtr<ComputedStyle> overflowStyle; 1616 const ComputedStyle* backgroundStyle = documentElementStyle.get();
1617 // http://www.w3.org/TR/css3-background/#body-background
1618 // <html> root element with no background steals background from its first < body> child.
1619 // Also see LayoutBoxModelObject::backgroundStolenForBeingBody()
1620 if (isHTMLHtmlElement(documentElement()) && isHTMLBodyElement(body) && !back groundStyle->hasBackground())
1621 backgroundStyle = bodyStyle.get();
1622 Color backgroundColor = backgroundStyle->visitedDependentColor(CSSPropertyBa ckgroundColor);
1623 FillLayer backgroundLayers = backgroundStyle->backgroundLayers();
1624 for (auto currentLayer = &backgroundLayers; currentLayer; currentLayer = cur rentLayer->next()) {
1625 // http://www.w3.org/TR/css3-background/#root-background
1626 // The root element background always have painting area of the whole ca nvas.
1627 currentLayer->setClip(BorderFillBox);
1628
1629 // The root element doesn't scroll. It always propagates its layout over flow
1630 // to the viewport. Positioning background against either box is equival ent to
1631 // positioning against the scrolled box of the viewport.
1632 if (currentLayer->attachment() == ScrollBackgroundAttachment)
1633 currentLayer->setAttachment(LocalBackgroundAttachment);
1634 }
1635 EImageRendering imageRendering = backgroundStyle->imageRendering();
1636
1637 const ComputedStyle* overflowStyle = nullptr;
1617 if (Element* element = viewportDefiningElement(documentElementStyle.get())) { 1638 if (Element* element = viewportDefiningElement(documentElementStyle.get())) {
1618 if (element == body) { 1639 if (element == body) {
1619 overflowStyle = bodyStyle; 1640 overflowStyle = bodyStyle.get();
1620 } else { 1641 } else {
1621 ASSERT(element == documentElement()); 1642 ASSERT(element == documentElement());
1622 overflowStyle = documentElementStyle; 1643 overflowStyle = documentElementStyle.get();
1623 } 1644 }
1624 } 1645 }
1625 1646
1626 // Resolved rem units are stored in the matched properties cache so we need to make sure to 1647 // Resolved rem units are stored in the matched properties cache so we need to make sure to
1627 // invalidate the cache if the documentElement needed to reattach or the fon t size changed 1648 // invalidate the cache if the documentElement needed to reattach or the fon t size changed
1628 // and then trigger a full document recalc. We also need to clear it here si nce the 1649 // and then trigger a full document recalc. We also need to clear it here si nce the
1629 // call to styleForElement on the body above can cache bad values for rem un its if the 1650 // call to styleForElement on the body above can cache bad values for rem un its if the
1630 // documentElement's style was dirty. We could keep track of which elements depend on 1651 // documentElement's style was dirty. We could keep track of which elements depend on
1631 // rem units like we do for viewport styles, but we assume root font size ch anges are 1652 // rem units like we do for viewport styles, but we assume root font size ch anges are
1632 // rare and just invalidate the cache for now. 1653 // rare and just invalidate the cache for now.
(...skipping 16 matching lines...) Expand all
1649 // Column-gap is (ab)used by the current paged overflow implementation ( in lack of other 1670 // Column-gap is (ab)used by the current paged overflow implementation ( in lack of other
1650 // ways to specify gaps between pages), so we have to propagate it too. 1671 // ways to specify gaps between pages), so we have to propagate it too.
1651 columnGap = overflowStyle->columnGap(); 1672 columnGap = overflowStyle->columnGap();
1652 } 1673 }
1653 1674
1654 WebScrollBlocksOn scrollBlocksOn = documentElementStyle->scrollBlocksOn(); 1675 WebScrollBlocksOn scrollBlocksOn = documentElementStyle->scrollBlocksOn();
1655 1676
1656 RefPtr<ComputedStyle> documentStyle = layoutView()->mutableStyle(); 1677 RefPtr<ComputedStyle> documentStyle = layoutView()->mutableStyle();
1657 if (documentStyle->writingMode() != rootWritingMode 1678 if (documentStyle->writingMode() != rootWritingMode
1658 || documentStyle->direction() != rootDirection 1679 || documentStyle->direction() != rootDirection
1680 || documentStyle->visitedDependentColor(CSSPropertyBackgroundColor) != b ackgroundColor
1681 || documentStyle->backgroundLayers() != backgroundLayers
1682 || documentStyle->imageRendering() != imageRendering
1659 || documentStyle->overflowX() != overflowX 1683 || documentStyle->overflowX() != overflowX
1660 || documentStyle->overflowY() != overflowY 1684 || documentStyle->overflowY() != overflowY
1661 || documentStyle->columnGap() != columnGap 1685 || documentStyle->columnGap() != columnGap
1662 || documentStyle->scrollBlocksOn() != scrollBlocksOn) { 1686 || documentStyle->scrollBlocksOn() != scrollBlocksOn) {
1663 RefPtr<ComputedStyle> newStyle = ComputedStyle::clone(*documentStyle); 1687 RefPtr<ComputedStyle> newStyle = ComputedStyle::clone(*documentStyle);
1664 newStyle->setWritingMode(rootWritingMode); 1688 newStyle->setWritingMode(rootWritingMode);
1665 newStyle->setDirection(rootDirection); 1689 newStyle->setDirection(rootDirection);
1666 newStyle->setColumnGap(columnGap); 1690 newStyle->setBackgroundColor(backgroundColor);
1691 newStyle->accessBackgroundLayers() = backgroundLayers;
1692 newStyle->setImageRendering(imageRendering);
1667 newStyle->setOverflowX(overflowX); 1693 newStyle->setOverflowX(overflowX);
1668 newStyle->setOverflowY(overflowY); 1694 newStyle->setOverflowY(overflowY);
1695 newStyle->setColumnGap(columnGap);
1669 newStyle->setScrollBlocksOn(scrollBlocksOn); 1696 newStyle->setScrollBlocksOn(scrollBlocksOn);
1670 layoutView()->setStyle(newStyle); 1697 layoutView()->setStyle(newStyle);
1671 setupFontBuilder(*newStyle); 1698 setupFontBuilder(*newStyle);
1672 } 1699 }
1673 1700
1674 if (body) { 1701 if (body) {
1675 if (const ComputedStyle* style = body->computedStyle()) { 1702 if (const ComputedStyle* style = body->computedStyle()) {
1676 if (style->direction() != rootDirection || style->writingMode() != r ootWritingMode) 1703 if (style->direction() != rootDirection || style->writingMode() != r ootWritingMode)
1677 body->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonF orTracing::create(StyleChangeReason::WritingModeChange)); 1704 body->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonF orTracing::create(StyleChangeReason::WritingModeChange));
1678 } 1705 }
(...skipping 4033 matching lines...) Expand 10 before | Expand all | Expand 10 after
5712 #ifndef NDEBUG 5739 #ifndef NDEBUG
5713 using namespace blink; 5740 using namespace blink;
5714 void showLiveDocumentInstances() 5741 void showLiveDocumentInstances()
5715 { 5742 {
5716 WeakDocumentSet& set = liveDocumentSet(); 5743 WeakDocumentSet& set = liveDocumentSet();
5717 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5744 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5718 for (Document* document : set) 5745 for (Document* document : set)
5719 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data()); 5746 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data());
5720 } 5747 }
5721 #endif 5748 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698