mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-15 16:48:24 +03:00
47 lines
883 B
C++
47 lines
883 B
C++
#include "Object.h"
|
|
#include "Event.h"
|
|
#include <AK/Assertions.h>
|
|
|
|
Object::Object(Object* parent)
|
|
: m_parent(parent)
|
|
{
|
|
if (m_parent)
|
|
m_parent->addChild(*this);
|
|
}
|
|
|
|
Object::~Object()
|
|
{
|
|
if (m_parent)
|
|
m_parent->removeChild(*this);
|
|
auto childrenToDelete = std::move(m_children);
|
|
for (auto* child : childrenToDelete)
|
|
delete child;
|
|
}
|
|
|
|
void Object::event(Event& event)
|
|
{
|
|
switch (event.type()) {
|
|
case Event::Invalid:
|
|
ASSERT_NOT_REACHED();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void Object::addChild(Object& object)
|
|
{
|
|
m_children.append(&object);
|
|
}
|
|
|
|
void Object::removeChild(Object& object)
|
|
{
|
|
// Oh geez, Vector needs a remove() huh...
|
|
Vector<Object*> newList;
|
|
for (auto* child : m_children) {
|
|
if (child != &object)
|
|
newList.append(child);
|
|
}
|
|
m_children = std::move(newList);
|
|
}
|