Skip to content

Commit

Permalink
Give proper warnings when making table elements floating or absolutel…
Browse files Browse the repository at this point in the history
…y positioned, as this is currently not supported. See #221.
  • Loading branch information
mikke89 committed Aug 17, 2021
1 parent 36fd9d7 commit 16e6a67
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Source/Core/LayoutEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,35 @@ bool LayoutEngine::FormatElement(LayoutBlockBox* block_context_box, Element* ele
case Style::Display::TableColumnGroup:
case Style::Display::TableCell:
{
// These elements should have been handled within FormatElementTable.
// See if we are located in an absolutely positioned or floating table element. Then,
// we will have issues and end up here because these properties establish a new block
// formatting context, but then tables need to be specially handled and they are not
// yet. Both FormatElement(element, containing_block) and GetShrinkToFitWidth() need
// to handle tables if we want to fix this.
Element* table_ancestor = element->GetParentNode();
while (table_ancestor && table_ancestor->GetDisplay() != Style::Display::Table)
table_ancestor = table_ancestor->GetParentNode();

if (table_ancestor)
{
const auto float_ = table_ancestor->GetFloat();
const auto position = table_ancestor->GetPosition();
const char* warning_msg = nullptr;

if (float_ != Style::Float::None)
warning_msg = "Table element cannot be floating. Instead, wrap it within a floating parent element.";
else if (position == Style::Position::Absolute || position == Style::Position::Fixed)
warning_msg = "Table element cannot be absolutely positioned. Instead, wrap it within an absolutely positioned parent element.";

if (warning_msg)
{
Log::Message(Log::LT_WARNING, "%s In element %s", warning_msg, table_ancestor->GetAddress().c_str());
return true;
}
}

// Seems like our issue isn't with the table element, instead we're encountering table parts in the wild!
const Property* display_property = element->GetProperty(PropertyId::Display);
Log::Message(Log::LT_WARNING, "Element has a display type '%s', but is not located in a table. It will not be formatted. In element %s",
display_property ? display_property->ToString().c_str() : "*unknown*",
Expand Down

0 comments on commit 16e6a67

Please sign in to comment.