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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBlock.cpp

Issue 1378743002: Refactor the API for setting dynamic resource load priorities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
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) 2007 David Smith (catfish.man@gmail.com) 4 * (C) 2007 David Smith (catfish.man@gmail.com)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 15 matching lines...) Expand all
26 26
27 #include "core/HTMLNames.h" 27 #include "core/HTMLNames.h"
28 #include "core/dom/AXObjectCache.h" 28 #include "core/dom/AXObjectCache.h"
29 #include "core/dom/Document.h" 29 #include "core/dom/Document.h"
30 #include "core/dom/Element.h" 30 #include "core/dom/Element.h"
31 #include "core/dom/StyleEngine.h" 31 #include "core/dom/StyleEngine.h"
32 #include "core/dom/shadow/ShadowRoot.h" 32 #include "core/dom/shadow/ShadowRoot.h"
33 #include "core/editing/EditingUtilities.h" 33 #include "core/editing/EditingUtilities.h"
34 #include "core/editing/Editor.h" 34 #include "core/editing/Editor.h"
35 #include "core/editing/FrameSelection.h" 35 #include "core/editing/FrameSelection.h"
36 #include "core/fetch/ResourceLoadPriorityOptimizer.h"
37 #include "core/frame/FrameView.h" 36 #include "core/frame/FrameView.h"
38 #include "core/frame/LocalFrame.h" 37 #include "core/frame/LocalFrame.h"
39 #include "core/frame/Settings.h" 38 #include "core/frame/Settings.h"
40 #include "core/html/HTMLMarqueeElement.h" 39 #include "core/html/HTMLMarqueeElement.h"
41 #include "core/layout/HitTestLocation.h" 40 #include "core/layout/HitTestLocation.h"
42 #include "core/layout/HitTestResult.h" 41 #include "core/layout/HitTestResult.h"
43 #include "core/layout/LayoutAnalyzer.h" 42 #include "core/layout/LayoutAnalyzer.h"
44 #include "core/layout/LayoutDeprecatedFlexibleBox.h" 43 #include "core/layout/LayoutDeprecatedFlexibleBox.h"
45 #include "core/layout/LayoutFlexibleBox.h" 44 #include "core/layout/LayoutFlexibleBox.h"
46 #include "core/layout/LayoutFlowThread.h" 45 #include "core/layout/LayoutFlowThread.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 continue; 150 continue;
152 HashSet<LayoutBlock*>* containerSet = it->value.get(); 151 HashSet<LayoutBlock*>* containerSet = it->value.get();
153 ASSERT(containerSet->contains(block)); 152 ASSERT(containerSet->contains(block));
154 containerSet->remove(block); 153 containerSet->remove(block);
155 if (containerSet->isEmpty()) 154 if (containerSet->isEmpty())
156 containerMap->remove(it); 155 containerMap->remove(it);
157 } 156 }
158 } 157 }
159 } 158 }
160 159
161 static void appendImageIfNotNull(Vector<ImageResource*>& imageResources, const S tyleImage* styleImage)
162 {
163 if (styleImage && styleImage->cachedImage()) {
164 ImageResource* imageResource = styleImage->cachedImage();
165 if (imageResource && !imageResource->isLoaded())
166 imageResources.append(styleImage->cachedImage());
167 }
168 }
169
170 static void appendLayers(Vector<ImageResource*>& images, const FillLayer& styleL ayer)
171 {
172 for (const FillLayer* layer = &styleLayer; layer; layer = layer->next())
173 appendImageIfNotNull(images, layer->image());
174 }
175
176 static void appendImagesFromStyle(Vector<ImageResource*>& images, const Computed Style& blockStyle)
177 {
178 appendLayers(images, blockStyle.backgroundLayers());
179 appendLayers(images, blockStyle.maskLayers());
180
181 const ContentData* contentData = blockStyle.contentData();
182 if (contentData && contentData->isImage())
183 appendImageIfNotNull(images, toImageContentData(contentData)->image());
184 if (blockStyle.boxReflect())
185 appendImageIfNotNull(images, blockStyle.boxReflect()->mask().image());
186 appendImageIfNotNull(images, blockStyle.listStyleImage());
187 appendImageIfNotNull(images, blockStyle.borderImageSource());
188 appendImageIfNotNull(images, blockStyle.maskBoxImageSource());
189 if (blockStyle.shapeOutside())
190 appendImageIfNotNull(images, blockStyle.shapeOutside()->image());
191 }
192
193 void LayoutBlock::removeFromGlobalMaps() 160 void LayoutBlock::removeFromGlobalMaps()
194 { 161 {
195 if (gPercentHeightDescendantsMap) 162 if (gPercentHeightDescendantsMap)
196 removeBlockFromDescendantAndContainerMaps(this, gPercentHeightDescendant sMap, gPercentHeightContainerMap); 163 removeBlockFromDescendantAndContainerMaps(this, gPercentHeightDescendant sMap, gPercentHeightContainerMap);
197 if (gPositionedDescendantsMap) 164 if (gPositionedDescendantsMap)
198 removeBlockFromDescendantAndContainerMaps(this, gPositionedDescendantsMa p, gPositionedContainerMap); 165 removeBlockFromDescendantAndContainerMaps(this, gPositionedDescendantsMa p, gPositionedContainerMap);
199 } 166 }
200 167
201 LayoutBlock::~LayoutBlock() 168 LayoutBlock::~LayoutBlock()
202 { 169 {
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 289 }
323 290
324 if (TextAutosizer* textAutosizer = document().textAutosizer()) 291 if (TextAutosizer* textAutosizer = document().textAutosizer())
325 textAutosizer->record(this); 292 textAutosizer->record(this);
326 293
327 propagateStyleToAnonymousChildren(true); 294 propagateStyleToAnonymousChildren(true);
328 295
329 // It's possible for our border/padding to change, but for the overall logic al width of the block to 296 // It's possible for our border/padding to change, but for the overall logic al width of the block to
330 // end up being the same. We keep track of this change so in layoutBlock, we can know to set relayoutChildren=true. 297 // end up being the same. We keep track of this change so in layoutBlock, we can know to set relayoutChildren=true.
331 m_widthAvailableToChildrenChanged |= oldStyle && diff.needsFullLayout() && n eedsLayout() && borderOrPaddingLogicalWidthChanged(*oldStyle, newStyle); 298 m_widthAvailableToChildrenChanged |= oldStyle && diff.needsFullLayout() && n eedsLayout() && borderOrPaddingLogicalWidthChanged(*oldStyle, newStyle);
332
333 // If the style has unloaded images, want to notify the ResourceLoadPriority Optimizer so that
334 // network priorities can be set.
335 Vector<ImageResource*> images;
336 appendImagesFromStyle(images, newStyle);
337 if (images.isEmpty())
338 ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->removeLa youtObject(this);
339 else
340 ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->addLayou tObject(this);
341 } 299 }
342 300
343 void LayoutBlock::invalidatePaintOfSubtreesIfNeeded(PaintInvalidationState& chil dPaintInvalidationState) 301 void LayoutBlock::invalidatePaintOfSubtreesIfNeeded(PaintInvalidationState& chil dPaintInvalidationState)
344 { 302 {
345 LayoutBox::invalidatePaintOfSubtreesIfNeeded(childPaintInvalidationState); 303 LayoutBox::invalidatePaintOfSubtreesIfNeeded(childPaintInvalidationState);
346 304
347 // Take care of positioned objects. This is required as PaintInvalidationSta te keeps a single clip rect. 305 // Take care of positioned objects. This is required as PaintInvalidationSta te keeps a single clip rect.
348 if (TrackedLayoutBoxListHashSet* positionedObjects = this->positionedObjects ()) { 306 if (TrackedLayoutBoxListHashSet* positionedObjects = this->positionedObjects ()) {
349 for (auto* box : *positionedObjects) { 307 for (auto* box : *positionedObjects) {
350 308
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 layoutBlock(false); 901 layoutBlock(false);
944 902
945 // It's safe to check for control clip here, since controls can never be tab le cells. 903 // It's safe to check for control clip here, since controls can never be tab le cells.
946 // If we have a lightweight clip, there can never be any overflow from child ren. 904 // If we have a lightweight clip, there can never be any overflow from child ren.
947 if (hasControlClip() && m_overflow) 905 if (hasControlClip() && m_overflow)
948 clearLayoutOverflow(); 906 clearLayoutOverflow();
949 907
950 invalidateBackgroundObscurationStatus(); 908 invalidateBackgroundObscurationStatus();
951 } 909 }
952 910
953 bool LayoutBlock::updateImageLoadingPriorities()
954 {
955 Vector<ImageResource*> images;
956 appendImagesFromStyle(images, styleRef());
957
958 if (images.isEmpty())
959 return false;
960
961 LayoutRect viewBounds = viewRect();
962 LayoutRect objectBounds(absoluteContentBox());
963 // The object bounds might be empty right now, so intersects will fail since it doesn't deal
964 // with empty rects. Use LayoutRect::contains in that case.
965 bool isVisible;
966 if (!objectBounds.isEmpty())
967 isVisible = viewBounds.intersects(objectBounds);
968 else
969 isVisible = viewBounds.contains(objectBounds);
970
971 ResourceLoadPriorityOptimizer::VisibilityStatus status = isVisible ?
972 ResourceLoadPriorityOptimizer::Visible : ResourceLoadPriorityOptimizer:: NotVisible;
973
974 LayoutRect screenArea;
975 if (!objectBounds.isEmpty()) {
976 screenArea = viewBounds;
977 screenArea.intersect(objectBounds);
978 }
979
980 for (auto* imageResource : images)
981 ResourceLoadPriorityOptimizer::resourceLoadPriorityOptimizer()->notifyIm ageResourceVisibility(imageResource, status, screenArea);
982
983 return true;
984 }
985
986 bool LayoutBlock::widthAvailableToChildrenHasChanged() 911 bool LayoutBlock::widthAvailableToChildrenHasChanged()
987 { 912 {
988 bool widthAvailableToChildrenHasChanged = m_widthAvailableToChildrenChanged; 913 bool widthAvailableToChildrenHasChanged = m_widthAvailableToChildrenChanged;
989 m_widthAvailableToChildrenChanged = false; 914 m_widthAvailableToChildrenChanged = false;
990 915
991 // If we use border-box sizing, have percentage padding, and our parent has changed width then the width available to our children has changed even 916 // If we use border-box sizing, have percentage padding, and our parent has changed width then the width available to our children has changed even
992 // though our own width has remained the same. 917 // though our own width has remained the same.
993 widthAvailableToChildrenHasChanged |= style()->boxSizing() == BORDER_BOX && needsPreferredWidthsRecalculation() && view()->layoutState()->containingBlockLog icalWidthChanged(); 918 widthAvailableToChildrenHasChanged |= style()->boxSizing() == BORDER_BOX && needsPreferredWidthsRecalculation() && view()->layoutState()->containingBlockLog icalWidthChanged();
994 919
995 return widthAvailableToChildrenHasChanged; 920 return widthAvailableToChildrenHasChanged;
(...skipping 1931 matching lines...) Expand 10 before | Expand all | Expand 10 after
2927 void LayoutBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Layout Object* obj) const 2852 void LayoutBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Layout Object* obj) const
2928 { 2853 {
2929 showLayoutObject(); 2854 showLayoutObject();
2930 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box()) 2855 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box())
2931 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1); 2856 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1);
2932 } 2857 }
2933 2858
2934 #endif 2859 #endif
2935 2860
2936 } // namespace blink 2861 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698