Commit Graph

14 Commits

Author SHA1 Message Date
Timothy Flynn
52099ff54d LibWebView: Generate hyperlinks for attributes that represent links
On the view-source page, generate anchor tags for any 'href' or 'src'
attribute value we come across. This handles both when the attribute
contains an absolute URL and a URL relative to the page.

This requires sending the document's base URL over IPC to resolve
relative URLs.

(cherry picked from commit 1aab7b51ea9c27a6ffff8df0c8bcbec87680865c;
amended to update `on_received_source` signature in Browser too)
2024-11-17 11:03:57 -05:00
Sam Atkins
c7613b186b LibWebView+UI: Highlight CSS in the style sheet inspector
(cherry picked from commit f0dd0c51073823ad2e30041896030a2831419786)
2024-11-16 14:05:12 -05:00
Sam Atkins
c74ee65745 LibWebView: Move line-number styling into HTML_HIGHLIGHTER_STYLE
(cherry picked from commit af23f3890b1a8ecb767b956a16b2146534253139)
2024-11-16 14:05:12 -05:00
Sam Atkins
5aaec92e6c LibWebView: Preserve whitespace in view-source
(cherry picked from commit e03da0e60037e41cf1a36af6bb9eaf017d71eadd)
2024-11-16 14:05:12 -05:00
Sam Atkins
29d71d8574 LibWebView: Highlight CSS and JS in view-source
The colors and categories here could probably be better, but it works.
:^)

(cherry picked from commit bd6fdbf312bedaae4bb5d95167e4262ec37fc4eb)
2024-11-16 14:05:12 -05:00
Sam Atkins
13a3e93e08 LibWebView: Use LibSyntax to highlight document source
This has no visible effect, but internally it's also highlighting any
CSS and JS embedded in the page, which will be made use of later. We'll
also be able to use this code for highlighting CSS or JS files directly
in the future.

It's not a perfect fit - the syntax highlighters give specific styles to
their spans, which we then ignore and just use their data integer to
figure out which CSS class to give to the span. It feels cleaner to me
to produce HTML styled that way, instead of every token having
`style="color: ...; font-weight: ...; text-decoration: ...;"` set on
it.

Most of this new `to_html_string()` code is adapted from Serenity's
`TextEditor::paint_event()`, so it should be pretty solid.

(cherry picked from commit 1db243c0060c2ae74194f3c5996093b8507ba095;
amended to fix tiny conflict in CMakeLists.txt)
2024-11-16 14:05:12 -05:00
Timothy Flynn
2222b9f958 LibWebView: Properly handle new lines inside styled view-source elements
When we want to inject a CSS counter for a line, we need to be sure to
handle if we had previously opened a styled span for the current source
substring. For example, if we see a new line in the middle of a comment,
we will have previously opened the following tag:

    <span class="comment">

So when injecting a new line and the <span class="line"> element (for
CSS counters), we need to close the previous span and insert a newly
opened tag to continue using the style.

(cherry picked from commit f1395a2c3859fce1daddb385582433c072ebf052)
2024-11-09 07:29:52 -05:00
Timothy Flynn
67166d4642 LibWebView: Insert line numbers before each line in about:srcdoc
The behavior chosen here (fixed-width counters, alignment, etc.) matches
Firefox.

(cherry picked from commit c1b0e180ba64d2ea7e815e2c2e93087ae9a26500)
2024-11-07 22:15:54 -05:00
Samuel Eisenhandler
5067a040ba LibWebView: Append remaining source after consuming all tokens
Since "Character" tokens do not have an "end position", viewing source
drops the source contents following the final non-"Character" token.

By handling the EOF token and breaking out of the loop, we avoid this
issue.

(cherry picked from commit 7de669dc07956c402e0ddec76e3f214f622cf2c4)
2024-11-01 06:25:07 -04:00
Timothy Flynn
775282f9fc LibWebView: Stop tokenizing the source HTML once we hit an EOF token 2024-03-23 20:58:31 +01:00
Shannon Booth
e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00
Timothy Flynn
fcaa994d4e LibWebView: Extract CSS to highlight HTML source to a constant
We will be re-using (and extending) this style in the WebView-based DOM
inspector.
2023-11-24 08:37:19 +01:00
Shannon Booth
9303e9e76f LibWeb: Port Element::local_name and TagNames from Deprecated String
Which pretty much needs to be done together due to the amount of places
where they are compared together.

This also involves porting over StackOfOpenElements over to FlyString
from DeprecatedFly string to prevent a gazillion calls to
`.to_deprecated_fly_string` calls in HTMLParser.
2023-10-03 14:47:53 +01:00
Timothy Flynn
1e1c3e5a34 LibWebView: Create a method to syntax-highlight page source with HTML
This tokenizes a page's source to produce HTML with syntax highlighting.
The first implementation here is rather simple; we do not yet implement
code folding, line numbers, etc.

The goal is for this to be used as the View Source implementation for
all Ladybird chromes.
2023-08-29 08:11:11 -04:00