1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:47:35 +00:00

LibGUI: Put all classes in the GUI namespace and remove the leading G

This took me a moment. Welcome to the new world of GUI::Widget! :^)
This commit is contained in:
Andreas Kling 2020-02-02 15:07:41 +01:00
parent 2d39da5405
commit c5bd9d4ed1
337 changed files with 5400 additions and 4816 deletions

View file

@ -49,9 +49,9 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties*)
ASSERT(frame.html_view());
auto& html_view = const_cast<HtmlView&>(*frame.html_view());
RefPtr<GWidget> widget;
RefPtr<GUI::Widget> widget;
if (type() == "submit") {
auto button = GButton::construct(value(), &html_view);
auto button = GUI::Button::construct(value(), &html_view);
int text_width = Font::default_font().width(value());
button->set_relative_rect(0, 0, text_width + 20, 20);
button->on_click = [this](auto&) {
@ -62,11 +62,11 @@ RefPtr<LayoutNode> HTMLInputElement::create_layout_node(const StyleProperties*)
};
widget = button;
} else {
auto text_box = GTextBox::construct(&html_view);
auto text_box = GUI::TextBox::construct(&html_view);
text_box->set_text(value());
text_box->on_change = [this] {
auto& widget = to<LayoutWidget>(layout_node())->widget();
const_cast<HTMLInputElement*>(this)->set_attribute("value", static_cast<const GTextBox&>(widget).text());
const_cast<HTMLInputElement*>(this)->set_attribute("value", static_cast<const GUI::TextBox&>(widget).text());
};
int text_width = Font::default_font().width(value());
text_box->set_relative_rect(0, 0, text_width + 20, 20);

View file

@ -44,7 +44,7 @@ DOMTreeModel::~DOMTreeModel()
{
}
GModelIndex DOMTreeModel::index(int row, int column, const GModelIndex& parent) const
GUI::ModelIndex DOMTreeModel::index(int row, int column, const GUI::ModelIndex& parent) const
{
if (!parent.is_valid()) {
return create_index(row, column, m_document.ptr());
@ -53,7 +53,7 @@ GModelIndex DOMTreeModel::index(int row, int column, const GModelIndex& parent)
return create_index(row, column, parent_node.child_at_index(row));
}
GModelIndex DOMTreeModel::parent_index(const GModelIndex& index) const
GUI::ModelIndex DOMTreeModel::parent_index(const GUI::ModelIndex& index) const
{
if (!index.is_valid())
return {};
@ -67,7 +67,7 @@ GModelIndex DOMTreeModel::parent_index(const GModelIndex& index) const
}
// Walk the grandparent's children to find the index of node's parent in its parent.
// (This is needed to produce the row number of the GModelIndex corresponding to node's parent.)
// (This is needed to produce the row number of the GUI::ModelIndex corresponding to node's parent.)
int grandparent_child_index = 0;
for (auto* grandparent_child = node.parent()->parent()->first_child(); grandparent_child; grandparent_child = grandparent_child->next_sibling()) {
if (grandparent_child == node.parent())
@ -79,7 +79,7 @@ GModelIndex DOMTreeModel::parent_index(const GModelIndex& index) const
return {};
}
int DOMTreeModel::row_count(const GModelIndex& index) const
int DOMTreeModel::row_count(const GUI::ModelIndex& index) const
{
if (!index.is_valid())
return 1;
@ -87,7 +87,7 @@ int DOMTreeModel::row_count(const GModelIndex& index) const
return node.child_count();
}
int DOMTreeModel::column_count(const GModelIndex&) const
int DOMTreeModel::column_count(const GUI::ModelIndex&) const
{
return 1;
}
@ -113,7 +113,7 @@ static String with_whitespace_collapsed(const StringView& string)
return builder.to_string();
}
GVariant DOMTreeModel::data(const GModelIndex& index, Role role) const
GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, Role role) const
{
auto& node = *static_cast<Node*>(index.internal_data());
if (role == Role::Icon) {

View file

@ -30,7 +30,7 @@
class Document;
class DOMTreeModel final : public GModel {
class DOMTreeModel final : public GUI::Model {
public:
static NonnullRefPtr<DOMTreeModel> create(Document& document)
{
@ -39,11 +39,11 @@ public:
virtual ~DOMTreeModel() override;
virtual int row_count(const GModelIndex& = GModelIndex()) const override;
virtual int column_count(const GModelIndex& = GModelIndex()) const override;
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
virtual GModelIndex index(int row, int column, const GModelIndex& parent = GModelIndex()) const override;
virtual GModelIndex parent_index(const GModelIndex&) const override;
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
virtual GUI::ModelIndex index(int row, int column, const GUI::ModelIndex& parent = GUI::ModelIndex()) const override;
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override;
virtual void update() override;
private:

View file

@ -46,9 +46,9 @@
#include <LibHTML/ResourceLoader.h>
#include <stdio.h>
HtmlView::HtmlView(GWidget* parent)
: GScrollableWidget(parent)
, m_main_frame(Frame::create(*this))
HtmlView::HtmlView(GUI::Widget* parent)
: GUI::ScrollableWidget(parent)
, m_main_frame(::Frame::create(*this))
{
main_frame().on_set_needs_display = [this](auto& content_rect) {
if (content_rect.is_empty()) {
@ -129,17 +129,17 @@ void HtmlView::layout_and_sync_size()
#endif
}
void HtmlView::resize_event(GResizeEvent& event)
void HtmlView::resize_event(GUI::ResizeEvent& event)
{
GScrollableWidget::resize_event(event);
GUI::ScrollableWidget::resize_event(event);
layout_and_sync_size();
}
void HtmlView::paint_event(GPaintEvent& event)
void HtmlView::paint_event(GUI::PaintEvent& event)
{
GFrame::paint_event(event);
GUI::Frame::paint_event(event);
GPainter painter(*this);
GUI::Painter painter(*this);
painter.add_clip_rect(widget_inner_rect());
painter.add_clip_rect(event.rect());
@ -163,10 +163,10 @@ void HtmlView::paint_event(GPaintEvent& event)
layout_root()->render(context);
}
void HtmlView::mousemove_event(GMouseEvent& event)
void HtmlView::mousemove_event(GUI::MouseEvent& event)
{
if (!layout_root())
return GScrollableWidget::mousemove_event(event);
return GUI::ScrollableWidget::mousemove_event(event);
bool hovered_node_changed = false;
bool is_hovering_link = false;
@ -193,15 +193,15 @@ void HtmlView::mousemove_event(GMouseEvent& event)
}
}
if (window())
window()->set_override_cursor(is_hovering_link ? GStandardCursor::Hand : GStandardCursor::None);
window()->set_override_cursor(is_hovering_link ? GUI::StandardCursor::Hand : GUI::StandardCursor::None);
if (hovered_node_changed) {
update();
auto* hovered_html_element = document()->hovered_node() ? document()->hovered_node()->enclosing_html_element() : nullptr;
if (hovered_html_element && !hovered_html_element->title().is_null()) {
auto screen_position = screen_relative_rect().location().translated(event.position());
GApplication::the().show_tooltip(hovered_html_element->title(), screen_position.translated(4, 4));
GUI::Application::the().show_tooltip(hovered_html_element->title(), screen_position.translated(4, 4));
} else {
GApplication::the().hide_tooltip();
GUI::Application::the().hide_tooltip();
}
}
if (is_hovering_link != was_hovering_link) {
@ -212,10 +212,10 @@ void HtmlView::mousemove_event(GMouseEvent& event)
event.accept();
}
void HtmlView::mousedown_event(GMouseEvent& event)
void HtmlView::mousedown_event(GUI::MouseEvent& event)
{
if (!layout_root())
return GScrollableWidget::mousemove_event(event);
return GUI::ScrollableWidget::mousemove_event(event);
bool hovered_node_changed = false;
auto result = layout_root()->hit_test(to_content_position(event.position()));
@ -229,7 +229,7 @@ void HtmlView::mousedown_event(GMouseEvent& event)
if (on_link_click)
on_link_click(link->href());
} else {
if (event.button() == GMouseButton::Left) {
if (event.button() == GUI::MouseButton::Left) {
layout_root()->selection().set({ result.layout_node, result.index_in_node }, {});
dump_selection("MouseDown");
m_in_mouse_selection = true;
@ -242,18 +242,18 @@ void HtmlView::mousedown_event(GMouseEvent& event)
event.accept();
}
void HtmlView::mouseup_event(GMouseEvent& event)
void HtmlView::mouseup_event(GUI::MouseEvent& event)
{
if (!layout_root())
return GScrollableWidget::mouseup_event(event);
return GUI::ScrollableWidget::mouseup_event(event);
if (event.button() == GMouseButton::Left) {
if (event.button() == GUI::MouseButton::Left) {
dump_selection("MouseUp");
m_in_mouse_selection = false;
}
}
void HtmlView::keydown_event(GKeyEvent& event)
void HtmlView::keydown_event(GUI::KeyEvent& event)
{
if (event.modifiers() == 0) {
switch (event.key()) {
@ -327,7 +327,7 @@ void HtmlView::load(const URL& url)
dbg() << "HtmlView::load: " << url;
if (window())
window()->set_override_cursor(GStandardCursor::None);
window()->set_override_cursor(GUI::StandardCursor::None);
if (on_load_start)
on_load_start(url);
@ -390,7 +390,7 @@ void HtmlView::scroll_to_anchor(const StringView& name)
auto& layout_node = *element->layout_node();
FloatRect float_rect { layout_node.box_type_agnostic_position(), { (float)visible_content_rect().width(), (float)visible_content_rect().height() } };
scroll_into_view(enclosing_int_rect(float_rect), true, true);
window()->set_override_cursor(GStandardCursor::None);
window()->set_override_cursor(GUI::StandardCursor::None);
}
Document* HtmlView::document()

View file

@ -23,7 +23,6 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <AK/URL.h>
@ -32,7 +31,7 @@
class Frame;
class HtmlView : public GScrollableWidget {
class HtmlView : public GUI::ScrollableWidget {
C_OBJECT(HtmlView)
public:
virtual ~HtmlView() override;
@ -44,8 +43,8 @@ public:
const LayoutDocument* layout_root() const;
LayoutDocument* layout_root();
Frame& main_frame() { return *m_main_frame; }
const Frame& main_frame() const { return *m_main_frame; }
::Frame& main_frame() { return *m_main_frame; }
const ::Frame& main_frame() const { return *m_main_frame; }
void reload();
void load(const URL&);
@ -63,14 +62,14 @@ public:
virtual bool accepts_focus() const override { return true; }
protected:
HtmlView(GWidget* parent = nullptr);
HtmlView(GUI::Widget* parent = nullptr);
virtual void resize_event(GResizeEvent&) override;
virtual void paint_event(GPaintEvent&) override;
virtual void mousemove_event(GMouseEvent&) override;
virtual void mousedown_event(GMouseEvent&) override;
virtual void mouseup_event(GMouseEvent&) override;
virtual void keydown_event(GKeyEvent&) override;
virtual void resize_event(GUI::ResizeEvent&) override;
virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousemove_event(GUI::MouseEvent&) override;
virtual void mousedown_event(GUI::MouseEvent&) override;
virtual void mouseup_event(GUI::MouseEvent&) override;
virtual void keydown_event(GUI::KeyEvent&) override;
private:
virtual void did_scroll() override;
@ -78,7 +77,7 @@ private:
void layout_and_sync_size();
void dump_selection(const char* event_name);
RefPtr<Frame> m_main_frame;
RefPtr<::Frame> m_main_frame;
bool m_should_show_line_box_borders { false };
bool m_in_mouse_selection { false };

View file

@ -30,7 +30,7 @@
#include <LibGUI/GWidget.h>
#include <LibHTML/Layout/LayoutWidget.h>
LayoutWidget::LayoutWidget(const Element& element, GWidget& widget)
LayoutWidget::LayoutWidget(const Element& element, GUI::Widget& widget)
: LayoutReplaced(element, StyleProperties::create())
, m_widget(widget)
{

View file

@ -28,25 +28,27 @@
#include <LibHTML/Layout/LayoutReplaced.h>
class GWidget;
namespace GUI {
class Widget;
}
class LayoutWidget : public LayoutReplaced {
public:
LayoutWidget(const Element&, GWidget&);
LayoutWidget(const Element&, GUI::Widget&);
virtual ~LayoutWidget() override;
virtual void layout() override;
virtual void render(RenderingContext&) override;
GWidget& widget() { return m_widget; }
const GWidget& widget() const { return m_widget; }
GUI::Widget& widget() { return m_widget; }
const GUI::Widget& widget() const { return m_widget; }
virtual bool is_widget() const final { return true; }
private:
virtual const char* class_name() const override { return "LayoutWidget"; }
NonnullRefPtr<GWidget> m_widget;
NonnullRefPtr<GUI::Widget> m_widget;
};
template<>

View file

@ -29,17 +29,19 @@
#include <LibDraw/Palette.h>
#include <LibDraw/Rect.h>
class GPainter;
namespace GUI {
class Painter;
}
class RenderingContext {
public:
explicit RenderingContext(GPainter& painter, const Palette& palette)
explicit RenderingContext(GUI::Painter& painter, const Palette& palette)
: m_painter(painter)
, m_palette(palette)
{
}
GPainter& painter() const { return m_painter; }
GUI::Painter& painter() const { return m_painter; }
const Palette& palette() const { return m_palette; }
bool should_show_line_box_borders() const { return m_should_show_line_box_borders; }
@ -49,7 +51,7 @@ public:
void set_viewport_rect(const Rect& rect) { m_viewport_rect = rect; }
private:
GPainter& m_painter;
GUI::Painter& m_painter;
Palette m_palette;
Rect m_viewport_rect;
bool m_should_show_line_box_borders { false };

View file

@ -40,7 +40,7 @@ StylePropertiesModel::StylePropertiesModel(const StyleProperties& properties)
});
}
int StylePropertiesModel::row_count(const GModelIndex&) const
int StylePropertiesModel::row_count(const GUI::ModelIndex&) const
{
return m_values.size();
}
@ -56,7 +56,7 @@ String StylePropertiesModel::column_name(int column_index) const
ASSERT_NOT_REACHED();
}
}
GVariant StylePropertiesModel::data(const GModelIndex& index, Role role) const
GUI::Variant StylePropertiesModel::data(const GUI::ModelIndex& index, Role role) const
{
auto& value = m_values[index.row()];
if (role == Role::Display) {

View file

@ -29,7 +29,7 @@
class StyleProperties;
class StylePropertiesModel final : public GModel {
class StylePropertiesModel final : public GUI::Model {
public:
enum Column {
PropertyName,
@ -39,10 +39,10 @@ public:
static NonnullRefPtr<StylePropertiesModel> create(const StyleProperties& properties) { return adopt(*new StylePropertiesModel(properties)); }
virtual int row_count(const GModelIndex& = GModelIndex()) const override;
virtual int column_count(const GModelIndex& = GModelIndex()) const override { return Column::__Count; }
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override;
virtual int column_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return Column::__Count; }
virtual String column_name(int) const override;
virtual GVariant data(const GModelIndex&, Role = Role::Display) const override;
virtual GUI::Variant data(const GUI::ModelIndex&, Role = Role::Display) const override;
virtual void update() override;
private: