Bug 1479508 Part 2: Change GetElementsWithGrid to use a more conservative traversal that skips subtrees without frames. r=bz

MozReview-Commit-ID: 1hTQD8LoLQw

--HG--
extra : rebase_source : e8651e1a78818a25c98cc34db2ac217756596666
This commit is contained in:
Brad Werth 2018-08-01 15:33:06 -07:00
Родитель 949df1e3d9
Коммит eea863c791
2 изменённых файлов: 20 добавлений и 37 удалений

Просмотреть файл

@ -1555,36 +1555,31 @@ Element::GetElementsByClassName(const nsAString& aClassNames)
void
Element::GetElementsWithGrid(nsTArray<RefPtr<Element>>& aElements)
{
// This helper function is passed to GetElementsByMatching()
// to identify elements with styling which will cause them to
// generate a nsGridContainerFrame during layout.
auto IsDisplayGrid = [](Element* aElement) -> bool
{
RefPtr<ComputedStyle> computedStyle =
nsComputedDOMStyle::GetComputedStyle(aElement, nullptr);
if (computedStyle) {
const nsStyleDisplay* display = computedStyle->StyleDisplay();
return (display->mDisplay == StyleDisplay::Grid ||
display->mDisplay == StyleDisplay::InlineGrid);
}
return false;
};
nsINode* cur = this;
while (cur) {
if (cur->IsElement()) {
Element* elem = cur->AsElement();
GetElementsByMatching(IsDisplayGrid, aElements);
}
if (elem->GetPrimaryFrame()) {
// See if this has a GridContainerFrame. Use the same method that
// nsGridContainerFrame uses, which deals with some edge cases.
if (nsGridContainerFrame::GetGridContainerFrame(elem->GetPrimaryFrame())) {
aElements.AppendElement(elem);
}
void
Element::GetElementsByMatching(nsElementMatchFunc aFunc,
nsTArray<RefPtr<Element>>& aElements)
{
for (nsINode* cur = this; cur; cur = cur->GetNextNode(this)) {
if (cur->IsElement() && aFunc(cur->AsElement())) {
aElements.AppendElement(cur->AsElement());
// This element has a frame, so allow the traversal to go through
// the children.
cur = cur->GetNextNode(this);
continue;
}
}
// Either this isn't an element, or it has no frame. Continue with the
// traversal but ignore all the children.
cur = cur->GetNextNonChildNode(this);
}
}
/**
* Returns the count of descendants (inclusive of aContent) in
* the uncomposed document that are explicitly set as editable.

Просмотреть файл

@ -1167,24 +1167,12 @@ public:
/**
* Return an array of all elements in the subtree rooted at this
* element that are styled as grid containers. This includes
* elements that don't actually generate any frames (by virtue of
* being in a 'display:none' subtree), but this does not include
* element that have grid container frames. This does not include
* pseudo-elements.
*/
void GetElementsWithGrid(nsTArray<RefPtr<Element>>& aElements);
private:
/**
* Define a general matching function that can be passed to
* GetElementsByMatching(). Each Element being considered is
* passed in.
*/
typedef bool (*nsElementMatchFunc)(Element* aElement);
void GetElementsByMatching(nsElementMatchFunc aFunc,
nsTArray<RefPtr<Element>>& aElements);
/**
* Implement the algorithm specified at
* https://dom.spec.whatwg.org/#insert-adjacent for both