1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 21:57:35 +00:00

LibCore: Remove Core::Object::is_widget() in favor of RTTI

This commit is contained in:
Andreas Kling 2021-01-01 16:02:16 +01:00
parent 42179715c3
commit 7841528cd4
4 changed files with 7 additions and 11 deletions

View file

@ -40,9 +40,8 @@ IntrusiveList<Object, &Object::m_all_objects_list_node>& Object::all_objects()
return objects; return objects;
} }
Object::Object(Object* parent, bool is_widget) Object::Object(Object* parent)
: m_parent(parent) : m_parent(parent)
, m_widget(is_widget)
{ {
all_objects().append(*this); all_objects().append(*this);
if (m_parent) if (m_parent)

View file

@ -117,8 +117,6 @@ public:
void deferred_invoke(Function<void(Object&)>); void deferred_invoke(Function<void(Object&)>);
bool is_widget() const { return m_widget; }
void save_to(AK::JsonObject&); void save_to(AK::JsonObject&);
bool set_property(const StringView& name, const JsonValue& value); bool set_property(const StringView& name, const JsonValue& value);
@ -151,7 +149,7 @@ public:
void decrement_inspector_count(Badge<RPCClient>); void decrement_inspector_count(Badge<RPCClient>);
protected: protected:
explicit Object(Object* parent = nullptr, bool is_widget = false); explicit Object(Object* parent = nullptr);
void register_property(const String& name, Function<JsonValue()> getter, Function<bool(const JsonValue&)> setter = nullptr); void register_property(const String& name, Function<JsonValue()> getter, Function<bool(const JsonValue&)> setter = nullptr);
@ -169,7 +167,6 @@ private:
String m_name; String m_name;
int m_timer_id { 0 }; int m_timer_id { 0 };
unsigned m_inspector_count { 0 }; unsigned m_inspector_count { 0 };
bool m_widget { false };
HashMap<String, NonnullOwnPtr<Property>> m_properties; HashMap<String, NonnullOwnPtr<Property>> m_properties;
NonnullRefPtrVector<Object> m_children; NonnullRefPtrVector<Object> m_children;
}; };

View file

@ -37,10 +37,10 @@ void ToolBarContainer::child_event(Core::ChildEvent& event)
Frame::child_event(event); Frame::child_event(event);
if (event.type() == Core::Event::ChildAdded) { if (event.type() == Core::Event::ChildAdded) {
if (event.child() && event.child()->is_widget()) if (event.child() && is<Widget>(event.child()))
did_add_toolbar((Widget&)*event.child()); did_add_toolbar((Widget&)*event.child());
} else if (event.type() == Core::Event::ChildRemoved) { } else if (event.type() == Core::Event::ChildRemoved) {
if (event.child() && event.child()->is_widget()) { if (event.child() && is<Widget>(event.child())) {
did_remove_toolbar((Widget&)*event.child()); did_remove_toolbar((Widget&)*event.child());
} }
} }

View file

@ -130,7 +130,7 @@ const WidgetClassRegistration* WidgetClassRegistration::find(const String& class
} }
Widget::Widget() Widget::Widget()
: Core::Object(nullptr, true) : Core::Object(nullptr)
, m_background_role(Gfx::ColorRole::Window) , m_background_role(Gfx::ColorRole::Window)
, m_foreground_role(Gfx::ColorRole::WindowText) , m_foreground_role(Gfx::ColorRole::WindowText)
, m_font(Gfx::FontDatabase::default_font()) , m_font(Gfx::FontDatabase::default_font())
@ -197,7 +197,7 @@ void Widget::child_event(Core::ChildEvent& event)
{ {
if (event.type() == Event::ChildAdded) { if (event.type() == Event::ChildAdded) {
if (event.child() && is<Widget>(*event.child()) && layout()) { if (event.child() && is<Widget>(*event.child()) && layout()) {
if (event.insertion_before_child() && event.insertion_before_child()->is_widget()) if (event.insertion_before_child() && is<Widget>(event.insertion_before_child()))
layout()->insert_widget_before(downcast<Widget>(*event.child()), downcast<Widget>(*event.insertion_before_child())); layout()->insert_widget_before(downcast<Widget>(*event.child()), downcast<Widget>(*event.insertion_before_child()));
else else
layout()->add_widget(downcast<Widget>(*event.child())); layout()->add_widget(downcast<Widget>(*event.child()));
@ -853,7 +853,7 @@ Vector<Widget*> Widget::child_widgets() const
Vector<Widget*> widgets; Vector<Widget*> widgets;
widgets.ensure_capacity(children().size()); widgets.ensure_capacity(children().size());
for (auto& child : const_cast<Widget*>(this)->children()) { for (auto& child : const_cast<Widget*>(this)->children()) {
if (child.is_widget()) if (is<Widget>(child))
widgets.append(static_cast<Widget*>(&child)); widgets.append(static_cast<Widget*>(&child));
} }
return widgets; return widgets;