Open Bug 1941443 Opened 1 year ago Updated 1 year ago

Add an API that returns whether an element is a block container

Categories

(Core :: Layout, enhancement)

enhancement

Tracking

()

People

(Reporter: sebo, Unassigned)

References

Details

Some of the tests within the DevTools' Inactive CSS feature like bug 1583902 require to check whether an element is a block container.

Therefore, a new InspectorUtils API should be created that returns that info. Copying over from bug 1583902 comment 8, this API may look like

nsIFrame* f = aElement.GetPrimaryFrame(FlushType::Frames);
if (!f) { return false; }
if (f->IsBlockFrameOrSubclass()) { return true; }
if (nsIFrame* inner = f->GetContentInsertionFrame()) {
  return inner->IsBlockFrameOrSubclass();
}
return false;

Sebastian

Emilio, Daniel, the suggested code works fine in many cases like table cells or buttons, though it fails on some form control cases like these ones:

  • data:text/html,<input style="display:inline;min-width:0;max-width:100px;overflow:hidden;text-overflow:ellipsis" value="abcdefghijklmnop">
  • data:text/html,<select style="display:inline;max-width:100px;overflow:hidden;text-overflow:ellipsis"><option>abcdefghijklmnopqrstuv
  • data:text/html,<textarea style="display:inline;min-width:0;max-width:100px;overflow:hidden;text-wrap:nowrap;text-overflow:ellipsis">abcdefghijklmnop
  • data:text/html,<fieldset style="display:inline;min-width:0;max-width:50px;overflow:hidden;text-overflow:ellipsis">abcdefghijklmnopqrstuv

I expected the GetContentInsertionFrame() to get the correct frame in those cases but it looks like there's something missing.
I could add a manual check for the different elements like this:

if (aElement.IsHTMLElement(nsGkAtoms::input) ||
    aElement.IsHTMLElement(nsGkAtoms::select) ||
    aElement.IsHTMLElement(nsGkAtoms::textarea) ||
    aElement.IsHTMLElement(nsGkAtoms::fieldset)) {
    return true;
}

Though I am sure you can show me a smarter way to detect whether those elements contain a block frame/are actually a block container.

Sebastian

Flags: needinfo?(emilio)
Flags: needinfo?(dholbert)

Those are not block containers, though we make those properties work by inserting in an inner block. So, yeah, probably something like:

nsIFrame* f = aElement.GetPrimaryFrame(FlushType::Frames);
if (!f) { return false; }
if (f->IsTextControlFrame() || f->IsComboboxControlFrame()) {
  // These always contain an inner block.
  return true;
}
if (nsFieldSetFrame* fieldset = do_QueryFrame(f)) {
  f = fieldset->GetInner();
}
if (f->IsBlockFrameOrSubclass()) {
  return true;
}
if (nsIFrame* inner = f->GetContentInsertionFrame()) {
  return inner->IsBlockFrameOrSubclass();
}

Or so.

Flags: needinfo?(emilio)
Flags: needinfo?(dholbert)
You need to log in before you can comment on or make changes to this bug.