mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:07:46 +00:00
Ladybird/Qt: Use LibWebView to decide what parts of a URL to highlight
This commit is contained in:
parent
192aa0838a
commit
e7f48abb74
1 changed files with 29 additions and 37 deletions
|
@ -77,47 +77,39 @@ void LocationEdit::focusOutEvent(QFocusEvent* event)
|
||||||
|
|
||||||
void LocationEdit::highlight_location()
|
void LocationEdit::highlight_location()
|
||||||
{
|
{
|
||||||
auto url = AK::URL::create_with_url_or_path(ak_deprecated_string_from_qstring(text()));
|
auto url = MUST(ak_string_from_qstring(text()));
|
||||||
|
|
||||||
auto darkened_text_color = QPalette().color(QPalette::Text);
|
|
||||||
darkened_text_color.setAlpha(127);
|
|
||||||
|
|
||||||
QList<QInputMethodEvent::Attribute> attributes;
|
QList<QInputMethodEvent::Attribute> attributes;
|
||||||
if (url.is_valid() && !hasFocus()) {
|
|
||||||
if (url.scheme() == "http" || url.scheme() == "https" || url.scheme() == "gemini") {
|
|
||||||
int host_start = (url.scheme().bytes_as_string_view().length() + 3) - cursorPosition();
|
|
||||||
auto host_length = url.serialized_host().release_value_but_fixme_should_propagate_errors().bytes().size();
|
|
||||||
|
|
||||||
// FIXME: Maybe add a generator to use https://publicsuffix.org/list/public_suffix_list.dat
|
if (auto url_parts = WebView::break_url_into_parts(url); url_parts.has_value()) {
|
||||||
// for now just highlight the whole host
|
auto darkened_text_color = QPalette().color(QPalette::Text);
|
||||||
|
darkened_text_color.setAlpha(127);
|
||||||
|
|
||||||
QTextCharFormat defaultFormat;
|
QTextCharFormat dark_attributes;
|
||||||
defaultFormat.setForeground(darkened_text_color);
|
dark_attributes.setForeground(darkened_text_color);
|
||||||
attributes.append({
|
|
||||||
QInputMethodEvent::TextFormat,
|
|
||||||
-cursorPosition(),
|
|
||||||
static_cast<int>(text().length()),
|
|
||||||
defaultFormat,
|
|
||||||
});
|
|
||||||
|
|
||||||
QTextCharFormat hostFormat;
|
QTextCharFormat highlight_attributes;
|
||||||
hostFormat.setForeground(QPalette().color(QPalette::Text));
|
highlight_attributes.setForeground(QPalette().color(QPalette::Text));
|
||||||
attributes.append({
|
|
||||||
QInputMethodEvent::TextFormat,
|
attributes.append({
|
||||||
host_start,
|
QInputMethodEvent::TextFormat,
|
||||||
static_cast<int>(host_length),
|
-cursorPosition(),
|
||||||
hostFormat,
|
static_cast<int>(url_parts->scheme_and_subdomain.length()),
|
||||||
});
|
dark_attributes,
|
||||||
} else if (url.scheme() == "file") {
|
});
|
||||||
QTextCharFormat schemeFormat;
|
|
||||||
schemeFormat.setForeground(darkened_text_color);
|
attributes.append({
|
||||||
attributes.append({
|
QInputMethodEvent::TextFormat,
|
||||||
QInputMethodEvent::TextFormat,
|
static_cast<int>(url_parts->scheme_and_subdomain.length() - cursorPosition()),
|
||||||
-cursorPosition(),
|
static_cast<int>(url_parts->effective_tld_plus_one.length()),
|
||||||
static_cast<int>(url.scheme().bytes_as_string_view().length() + 3),
|
highlight_attributes,
|
||||||
schemeFormat,
|
});
|
||||||
});
|
|
||||||
}
|
attributes.append({
|
||||||
|
QInputMethodEvent::TextFormat,
|
||||||
|
static_cast<int>(url_parts->scheme_and_subdomain.length() + url_parts->effective_tld_plus_one.length() - cursorPosition()),
|
||||||
|
static_cast<int>(url_parts->remainder.length()),
|
||||||
|
dark_attributes,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QInputMethodEvent event(QString(), attributes);
|
QInputMethodEvent event(QString(), attributes);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue