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

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: revise for xianzhu's comment 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 1594 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 if (body) { 1605 if (body) {
1606 bodyStyle = body->mutableComputedStyle(); 1606 bodyStyle = body->mutableComputedStyle();
1607 if (didRecalcDocumentElement) 1607 if (didRecalcDocumentElement)
1608 body->clearAnimationStyleChange(); 1608 body->clearAnimationStyleChange();
1609 if (!bodyStyle || body->needsStyleRecalc() || didRecalcDocumentElement) 1609 if (!bodyStyle || body->needsStyleRecalc() || didRecalcDocumentElement)
1610 bodyStyle = ensureStyleResolver().styleForElement(body, documentElem entStyle.get()); 1610 bodyStyle = ensureStyleResolver().styleForElement(body, documentElem entStyle.get());
1611 rootWritingMode = bodyStyle->writingMode(); 1611 rootWritingMode = bodyStyle->writingMode();
1612 rootDirection = bodyStyle->direction(); 1612 rootDirection = bodyStyle->direction();
1613 } 1613 }
1614 1614
1615 RefPtr<ComputedStyle> overflowStyle; 1615 const ComputedStyle* backgroundStyle = documentElementStyle.get();
1616 if (isHTMLHtmlElement(documentElement()) && isHTMLBodyElement(body) && !back groundStyle->hasBackground())
chrishtr 2015/06/03 18:15:15 Comment why you are doing this conditional overrid
trchen 2015/06/03 23:15:24 Acknowledged.
1617 backgroundStyle = bodyStyle.get();
1618 Color backgroundColor = backgroundStyle->visitedDependentColor(CSSPropertyBa ckgroundColor);
1619 FillLayer backgroundLayers = backgroundStyle->backgroundLayers();
1620 for (auto currentLayer = &backgroundLayers; currentLayer; currentLayer = cur rentLayer->next()) {
1621 // http://www.w3.org/TR/css3-background/#root-background
1622 // The root element background always have painting area of the whole ca nvas.
1623 currentLayer->setClip(BorderFillBox);
1624
1625 // The root element doesn't scroll. It always propagates its layout over flow
1626 // to the viewport. Positioning background against either box is equival ent to
1627 // positioning against the scrolled box of the viewport.
1628 if (currentLayer->attachment() == ScrollBackgroundAttachment)
1629 currentLayer->setAttachment(LocalBackgroundAttachment);
chrishtr 2015/06/03 18:15:15 This looks a little hacky. Is there a way to never
trchen 2015/06/03 23:15:24 They do behave like background-attachment:local on
1630 }
1631 EImageRendering imageRendering = backgroundStyle->imageRendering();
1632
1633 const ComputedStyle* overflowStyle = nullptr;
1616 if (Element* element = viewportDefiningElement(documentElementStyle.get())) { 1634 if (Element* element = viewportDefiningElement(documentElementStyle.get())) {
1617 if (element == body) { 1635 if (element == body) {
1618 overflowStyle = bodyStyle; 1636 overflowStyle = bodyStyle.get();
1619 } else { 1637 } else {
1620 ASSERT(element == documentElement()); 1638 ASSERT(element == documentElement());
1621 overflowStyle = documentElementStyle; 1639 overflowStyle = documentElementStyle.get();
1622 } 1640 }
1623 } 1641 }
1624 1642
1625 // Resolved rem units are stored in the matched properties cache so we need to make sure to 1643 // Resolved rem units are stored in the matched properties cache so we need to make sure to
1626 // invalidate the cache if the documentElement needed to reattach or the fon t size changed 1644 // invalidate the cache if the documentElement needed to reattach or the fon t size changed
1627 // and then trigger a full document recalc. We also need to clear it here si nce the 1645 // and then trigger a full document recalc. We also need to clear it here si nce the
1628 // call to styleForElement on the body above can cache bad values for rem un its if the 1646 // call to styleForElement on the body above can cache bad values for rem un its if the
1629 // documentElement's style was dirty. We could keep track of which elements depend on 1647 // documentElement's style was dirty. We could keep track of which elements depend on
1630 // rem units like we do for viewport styles, but we assume root font size ch anges are 1648 // rem units like we do for viewport styles, but we assume root font size ch anges are
1631 // rare and just invalidate the cache for now. 1649 // rare and just invalidate the cache for now.
(...skipping 16 matching lines...) Expand all
1648 // Column-gap is (ab)used by the current paged overflow implementation ( in lack of other 1666 // Column-gap is (ab)used by the current paged overflow implementation ( in lack of other
1649 // ways to specify gaps between pages), so we have to propagate it too. 1667 // ways to specify gaps between pages), so we have to propagate it too.
1650 columnGap = overflowStyle->columnGap(); 1668 columnGap = overflowStyle->columnGap();
1651 } 1669 }
1652 1670
1653 WebScrollBlocksOn scrollBlocksOn = documentElementStyle->scrollBlocksOn(); 1671 WebScrollBlocksOn scrollBlocksOn = documentElementStyle->scrollBlocksOn();
1654 1672
1655 RefPtr<ComputedStyle> documentStyle = layoutView()->mutableStyle(); 1673 RefPtr<ComputedStyle> documentStyle = layoutView()->mutableStyle();
1656 if (documentStyle->writingMode() != rootWritingMode 1674 if (documentStyle->writingMode() != rootWritingMode
1657 || documentStyle->direction() != rootDirection 1675 || documentStyle->direction() != rootDirection
1676 || documentStyle->visitedDependentColor(CSSPropertyBackgroundColor) != b ackgroundColor
1677 || documentStyle->backgroundLayers() != backgroundLayers
1678 || documentStyle->imageRendering() != imageRendering
1658 || documentStyle->overflowX() != overflowX 1679 || documentStyle->overflowX() != overflowX
1659 || documentStyle->overflowY() != overflowY 1680 || documentStyle->overflowY() != overflowY
1660 || documentStyle->columnGap() != columnGap 1681 || documentStyle->columnGap() != columnGap
1661 || documentStyle->scrollBlocksOn() != scrollBlocksOn) { 1682 || documentStyle->scrollBlocksOn() != scrollBlocksOn) {
1662 RefPtr<ComputedStyle> newStyle = ComputedStyle::clone(*documentStyle); 1683 RefPtr<ComputedStyle> newStyle = ComputedStyle::clone(*documentStyle);
1663 newStyle->setWritingMode(rootWritingMode); 1684 newStyle->setWritingMode(rootWritingMode);
1664 newStyle->setDirection(rootDirection); 1685 newStyle->setDirection(rootDirection);
1665 newStyle->setColumnGap(columnGap); 1686 newStyle->setBackgroundColor(backgroundColor);
1687 newStyle->accessBackgroundLayers() = backgroundLayers;
1688 newStyle->setImageRendering(imageRendering);
1666 newStyle->setOverflowX(overflowX); 1689 newStyle->setOverflowX(overflowX);
1667 newStyle->setOverflowY(overflowY); 1690 newStyle->setOverflowY(overflowY);
1691 newStyle->setColumnGap(columnGap);
1668 newStyle->setScrollBlocksOn(scrollBlocksOn); 1692 newStyle->setScrollBlocksOn(scrollBlocksOn);
1669 layoutView()->setStyle(newStyle); 1693 layoutView()->setStyle(newStyle);
1670 setupFontBuilder(*newStyle); 1694 setupFontBuilder(*newStyle);
1671 } 1695 }
1672 1696
1673 if (body) { 1697 if (body) {
1674 if (const ComputedStyle* style = body->computedStyle()) { 1698 if (const ComputedStyle* style = body->computedStyle()) {
1675 if (style->direction() != rootDirection || style->writingMode() != r ootWritingMode) 1699 if (style->direction() != rootDirection || style->writingMode() != r ootWritingMode)
1676 body->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonF orTracing::create(StyleChangeReason::WritingModeChange)); 1700 body->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonF orTracing::create(StyleChangeReason::WritingModeChange));
1677 } 1701 }
(...skipping 4002 matching lines...) Expand 10 before | Expand all | Expand 10 after
5680 #ifndef NDEBUG 5704 #ifndef NDEBUG
5681 using namespace blink; 5705 using namespace blink;
5682 void showLiveDocumentInstances() 5706 void showLiveDocumentInstances()
5683 { 5707 {
5684 WeakDocumentSet& set = liveDocumentSet(); 5708 WeakDocumentSet& set = liveDocumentSet();
5685 fprintf(stderr, "There are %u documents currently alive:\n", set.size()); 5709 fprintf(stderr, "There are %u documents currently alive:\n", set.size());
5686 for (Document* document : set) 5710 for (Document* document : set)
5687 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data()); 5711 fprintf(stderr, "- Document %p URL: %s\n", document, document->url().str ing().utf8().data());
5688 } 5712 }
5689 #endif 5713 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698