mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 20:47:45 +00:00
Ladybird+LibWeb: Add basic select element support
This commit is contained in:
parent
b439431488
commit
466153e680
28 changed files with 641 additions and 4 deletions
|
@ -226,6 +226,22 @@ Tab::Tab(BrowserWindow* window, WebContentOptions const& web_content_options, St
|
|||
m_dialog = nullptr;
|
||||
};
|
||||
|
||||
m_select_dropdown = new QMenu("Select Dropdown", this);
|
||||
QObject::connect(m_select_dropdown, &QMenu::aboutToHide, this, [this]() {
|
||||
if (!m_select_dropdown->activeAction())
|
||||
view().select_dropdown_closed({});
|
||||
});
|
||||
|
||||
view().on_request_select_dropdown = [this](Gfx::IntPoint content_position, i32 minimum_width, Vector<Web::HTML::SelectItem> items) {
|
||||
m_select_dropdown->clear();
|
||||
m_select_dropdown->setMinimumWidth(minimum_width);
|
||||
for (auto const& item : items) {
|
||||
select_dropdown_add_item(m_select_dropdown, item);
|
||||
}
|
||||
|
||||
m_select_dropdown->exec(mapToGlobal(QPoint(content_position.x(), content_position.y())));
|
||||
};
|
||||
|
||||
QObject::connect(focus_location_editor_action, &QAction::triggered, this, &Tab::focus_location_editor);
|
||||
|
||||
view().on_received_source = [this](auto const& url, auto const& source) {
|
||||
|
@ -569,6 +585,37 @@ Tab::~Tab()
|
|||
close_sub_widgets();
|
||||
}
|
||||
|
||||
void Tab::select_dropdown_add_item(QMenu* menu, Web::HTML::SelectItem const& item)
|
||||
{
|
||||
if (item.type == Web::HTML::SelectItem::Type::OptionGroup) {
|
||||
QAction* subtitle = new QAction(qstring_from_ak_string(item.label.value_or(""_string)), this);
|
||||
subtitle->setDisabled(true);
|
||||
menu->addAction(subtitle);
|
||||
|
||||
for (auto const& item : *item.items) {
|
||||
select_dropdown_add_item(menu, item);
|
||||
}
|
||||
}
|
||||
if (item.type == Web::HTML::SelectItem::Type::Option) {
|
||||
QAction* action = new QAction(qstring_from_ak_string(item.label.value_or(""_string)), this);
|
||||
action->setCheckable(true);
|
||||
action->setChecked(item.selected);
|
||||
action->setData(QVariant(qstring_from_ak_string(item.value.value_or(""_string))));
|
||||
QObject::connect(action, &QAction::triggered, this, &Tab::select_dropdown_action);
|
||||
menu->addAction(action);
|
||||
}
|
||||
if (item.type == Web::HTML::SelectItem::Type::Separator) {
|
||||
menu->addSeparator();
|
||||
}
|
||||
}
|
||||
|
||||
void Tab::select_dropdown_action()
|
||||
{
|
||||
QAction* action = qobject_cast<QAction*>(sender());
|
||||
auto value = action->data().value<QString>();
|
||||
view().select_dropdown_closed(ak_string_from_qstring(value));
|
||||
}
|
||||
|
||||
void Tab::update_reset_zoom_button()
|
||||
{
|
||||
auto zoom_level = view().zoom_level();
|
||||
|
|
|
@ -54,12 +54,15 @@ public:
|
|||
public slots:
|
||||
void focus_location_editor();
|
||||
void location_edit_return_pressed();
|
||||
void select_dropdown_action();
|
||||
|
||||
signals:
|
||||
void title_changed(int id, QString);
|
||||
void favicon_changed(int id, QIcon);
|
||||
|
||||
private:
|
||||
void select_dropdown_add_item(QMenu* menu, Web::HTML::SelectItem const& item);
|
||||
|
||||
virtual void resizeEvent(QResizeEvent*) override;
|
||||
virtual bool event(QEvent*) override;
|
||||
|
||||
|
@ -106,6 +109,8 @@ private:
|
|||
QAction* m_media_context_menu_loop_action { nullptr };
|
||||
URL m_media_context_menu_url;
|
||||
|
||||
QMenu* m_select_dropdown { nullptr };
|
||||
|
||||
int tab_index();
|
||||
|
||||
bool m_is_history_navigation { false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue