Commit Graph

902 Commits

Author SHA1 Message Date
Andreas Kling
01022eb5d6 LibWeb: Allow focusing individual (focusable) elements with Tab key
You can now cycle through focusable elements (currently only hyperlinks
are focusable) with the Tab key.

The focus outline is rendered in a new FocusOutline paint phase.
2020-08-15 00:05:45 +02:00
Andreas Kling
5939af14d4 LibWeb: Pass non-accepted keydown events to PageView's base class
This will allow LibGUI's normal mechanisms to take over if the web
engine is not interested in the event right now.
2020-08-15 00:05:45 +02:00
Andreas Kling
7698feb8ce LibWeb: Add NonDocumentTypeChildNode::next_element_in_pre_order()
This is handy for traversing only the elements in a document.
2020-08-15 00:05:45 +02:00
Andreas Kling
bbe2d4a2d9 LibJS+LibWeb: Clear exceptions after call'ing JavaScript functions
Decorated Interpreter::call() with [[nodiscard]] to provoke thinking
about the returned value at each call site. This is definitely not
perfect and we should really start thinking about slimming down the
public-facing LibJS interpreter API.

Fixes #3136.
2020-08-14 17:31:07 +02:00
Andreas Kling
9bdd8ec3f3 LibWeb: Don't paint a text cursor in unfocused frames 2020-08-14 12:15:11 +02:00
Andreas Kling
be76abfdb3 LibWeb: Send keydown events to the focused frame 2020-08-14 12:15:11 +02:00
Andreas Kling
6b4a7d1ee3 LibWeb: Add "focused frame" concept, one focused Frame per Page
Focus currently only moves when doing a mousedown in a frame.
2020-08-14 12:15:11 +02:00
Ben Wiederhake
e050f21f36 LibWeb: Mark compilation-unit-only functions as static
This enables a nice warning in case a function becomes dead code. Also, in the
case of {Event,Node}WrapperFactory.cpp, the corresponding header was forgotten.
This would cause an issue later when we enable -Wmissing-declarations.

Is my clang-format misconfigured? Why is the diff for NodeWrapperFactory.cpp
so large?
2020-08-12 20:40:59 +02:00
Linus Groh
7390098adc LibWeb: Fix #include <LibWeb/{DOM => HTML}/AttributeNames.h>
This file has been moved from DOM/ to HTML/ in
a784090b91.
2020-08-12 15:37:42 +02:00
Andreas Kling
305e2ef69c LibWeb: Until an image has loaded or failed, don't occupy layout size
This patch makes images have an implicit zero intrinsic size before
they have either loaded or failed to load. This is tracked by the
ImageLoader object.

This fixes a long-standing issue with images occupying empty 150x150
rectangles of space.
2020-08-12 13:49:43 +02:00
Andreas Kling
a784090b91 LibWeb: Move HTML::AttributeNames file into HTML/ directory 2020-08-12 13:22:59 +02:00
Andreas Kling
40f4ccc3ea LibWeb: Initialize tag/attribute name globals in init-time constructors 2020-08-12 11:27:44 +02:00
Linus Groh
1d728af5c4 LibWeb: Clear exceptions in each Document::run_javascript() call
We don't want to carry over exceptions across multiple
Document::run_javascript() calls as Interpreter::run() and every of its
exception checks will get confused - in this case there would be an
exception, but not because a certain action failed.

Real-life example:

<script>var a = {}; a.test()</script>
<script>alert("It worked!")</script>

The above HTML will invoke Document::run_javascript() twice, the first
call will result in a TypeError, which is still stored during the second
call. The interpreter will eventually call the following functions (in
order) for the alert() invocation:

- Identifier::execute()
- Interpreter::get_variable()
- Object::get() (on the global object)

That last Object::get() call has an exception check which is triggered
as we still carry around the exception from earlier - and eventually
returns an empty value.

Long story short, the second script will wrongly fail with
"ReferenceError, 'alert' is not defined".

Fixes #3091.
2020-08-11 21:08:30 +02:00
Andreas Kling
eaf7e68408 LibWeb: Move tree iteration helpers from Node/LayoutNode to TreeNode
Since these are generally useful in our trees, let's just keep them
in TreeNode instead of duplicating the helpers in subclasses.
2020-08-10 15:21:23 +02:00
Luke
5724ac8e72 LibWeb: Add HTML elements to factories, add missing tags and attributes
This is mostly to get the grunt work of the way. This is split up into
multiple commits to hopefully make it more manageable to review.

Note that these are not full implementations, and the bindings mostly
get the low hanging fruit.

Also implements some attributes that I kept out because they had
dashes in them. Therefore, this closes #2905.
2020-08-09 21:14:51 +02:00
Luke
be5a62d5d7 LibWeb: Add all HTML elements between S and V 2020-08-09 21:14:51 +02:00
Luke
1fbe4b2a2f LibWeb: Add all HTML elements between L and Q 2020-08-09 21:14:51 +02:00
Luke
b90a91da4a LibWeb: Add all HTML elements between A and F 2020-08-09 21:14:51 +02:00
Luke
a86ce7eaca LibWeb: Make all existing HTML elements "final" 2020-08-09 21:14:51 +02:00
Andreas Kling
72347205c4 LibWeb: Always add line boxes through LayoutBlock::add_line_box()
Let's not append directly to the line box vector all over the place.
2020-08-09 15:21:09 +02:00
Andreas Kling
62ec42c112 LibWeb: Remove some unnecessary throwaway strings in the CSS parser
We've had StringView::ends_with(..., CaseSensitivity) for a while,
so let's use it to avoid creating a bunch of unnecessary strings here.
2020-08-07 20:35:05 +02:00
Andreas Kling
498845ea2f LibWeb: Handle CSS "ex" lengths (relative to font x-height)
These are pretty rare, but they do come up in some places and it's not
hard to support. The Gfx::Font information is approximate (and bad)
but we can fix that separately.
2020-08-07 20:30:59 +02:00
Andreas Kling
379e6f5817 LibWeb: Remove unused LayoutPosition comparison operators 2020-08-07 09:17:34 +02:00
Andreas Kling
1c7faa8965 LibWeb: Move text selection serialization from PageView to Frame
This logic doesn't depend on anything at the widget layer, so it can
move down to the frame layer.
2020-08-06 19:59:24 +02:00
asynts
b3d1a05261 Refactor: Expose const_cast by removing ByteBuffer::warp(const void*, size_t)
This function did a const_cast internally which made the call side look
"safe". This method is removed completely and call sites are replaced
with ByteBuffer::wrap(const_cast<void*>(data), size) which makes the
behaviour obvious.
2020-08-06 10:33:16 +02:00
Nico Weber
ce95628b7f Unicode: Try s/codepoint/code_point/g again
This time, without trailing 's'. Ran:

    git grep -l 'codepoint' | xargs sed -ie 's/codepoint/code_point/g
2020-08-05 22:33:42 +02:00
Nico Weber
19ac1f6368 Revert "Unicode: s/codepoint/code_point/g"
This reverts commit ea9ac3155d.
It replaced "codepoint" with "code_points", not "code_point".
2020-08-05 22:33:42 +02:00
Andreas Kling
e2b4fef6c7 LibWeb: Specialize hit testing for text cursor purposes
The text cursor follows slightly different "intuitive" rules than the
regular hit testing. Clicking past the right edge of a text box should
still "hit" the text box, and place the cursor at its end, for example.

We solve this by adding a HitTestType enum that is passed to hit_test()
and determines whether past-the-edge candidates are considered.
2020-08-05 16:57:51 +02:00
Nico Weber
d8b6314018 Build: Support make's and ninja's restat optimization
After running a build command, make by default stat()s the command's
output, and if it wasn't touched, then it cancels all build steps
that were scheduled only because this command was expected to change
the output.

Ninja has the same feature, but it's opt-in behind the per-command
"restat = 1" setting. However, CMake enables it by default for all
custom commands.

Use Meta/write-only-on-difference.sh to write the output to a temporary
file, and then copy the temporary file only to the final location if the
contents of the output have changed since last time.
write-only-on-difference.sh automatically creates the output's parent
directory, so stop doing that in CMake.

Reduces the number of build steps that run after touching a file
in LibCore from 522 to 312.

Since we now no longer trigger the CMake special case "If COMMAND
specifies an executable target name (created by the add_executable()
command), it will automatically be replaced by the location of the
executable created at build time", we now need to use qualified paths to
the generators.

Somewhat related to #2877.
2020-08-04 15:58:08 +02:00
Luke
567845c480 LibWeb: Make sure that head and body always get the HTML element
Now that document element returns a generic DOM element, we need to
make sure head and body get a html element. 

The spec just says to check if the document element is a html element,
so let's do that.
2020-08-04 11:05:14 +02:00
Andreas Kling
99d81a5d49 LibWeb: Add a very basic test for Text node APIs ("data" and "length") 2020-08-03 20:53:26 +02:00
Andreas Kling
73645e11c4 LibWeb: Add CharacterData and Text IDL interfaces 2020-08-03 20:50:45 +02:00
Andreas Kling
354f9aafd5 LibWeb: Reorganize tests into DOM/ and HTML/ 2020-08-03 20:50:20 +02:00
Andreas Kling
2dc08d259e LibWeb: Add Element.{next,previous}ElementSibling IDL attributes 2020-08-03 20:32:06 +02:00
Andreas Kling
d367044e67 LibWeb: Move "element sibling" getters to NonDocumentTypeChildNode
Here's another CRTP mixin since that's the best we can do with C++.
This prepares exposing these via IDL on Element and CharacterData.
2020-08-03 20:30:02 +02:00
Andreas Kling
6e221adade LibWeb: Send key events to the WebContent process
This makes contenteditable work in multi-process mode. :^)
2020-08-03 19:58:59 +02:00
Andreas Kling
ea9ac3155d Unicode: s/codepoint/code_point/g
Unicode calls them "code points" so let's follow their style.
2020-08-03 19:06:41 +02:00
Andreas Kling
e27726dc92 LibWeb: Add the Document.documentElement API
Also change DOM::Document::document_element() to return an Element*
and not an HTML::HTMLHtmlElement since that's not the only kind of
documentElement we might encounter.
2020-08-03 13:30:18 +02:00
Luke
bc15144972 LibWeb: Move contentEditable from Element to HTMLElement
HTMLElement is the only interface that includes ElementContentEditable
in the HTML specification. This makes sense, as Element is also a base
class for elements in other specifications such as SVG,
which definitely shouldn't be editable.

Also adds a test for the attribute based on what Andreas did in the
video that added it.
2020-08-03 12:47:58 +02:00
Matthew Olsson
81187c4ead LibWeb: Fix some SVG crashes/hangs
- parse_flag now only parses one digit instead of consuming an entirely
valid number
- match_number => match_coordinate
- match_coordinate now returns true if `ch()` is '.'
- parse_number no longer matches a +/-
- Don't crash when encountering one of the three unsupported path
commands. Instead, just skip them. No reason to crash the browser over a
silly SVG element :)
2020-08-02 19:16:40 +02:00
AnotherTest
97256ad977 ProtocolServer+LibTLS: Pipe certificate requests from LibTLS to clients
This makes gemini.circumlunar.space (and some more gemini pages) work
again :^)
2020-08-02 18:57:51 +02:00
Andreas Kling
7811cf3520 LibWeb: Implement the Element.contentEditable IDL attribute 2020-08-02 17:34:50 +02:00
Andreas Kling
07e13e9868 LibWeb: Only allow editing of elements with contenteditable="true"
We now respect the contenteditable HTML attribute and only let you
edit content inside explicitly editable elements.
2020-08-02 17:34:50 +02:00
Andreas Kling
8b16c61ff8 LibWeb: Add very basic backspace support to content editing 2020-08-02 17:34:50 +02:00
Andreas Kling
bc299754f6 LibWeb: Allow inserting text at the cursor by typing characters :^)
This works everywhere right now, but it's obviously not going to stay
that way forever. :^)

Note that this does not advance the cursor correctly for whitespace
since the cursor is DOM-based and doesn't take whitespace collapsing
into account yet.
2020-08-02 17:34:50 +02:00
Andreas Kling
2c679d0c8b LibWeb: Add a blinking text cursor :^)
Each Web::Frame now has a cursor that sits at a DOM::Position. It will
blink and look like a nice regular text cursor.

It doesn't really do anything yet, but it will eventually.
2020-08-02 17:34:50 +02:00
Andreas Kling
e496a74bb3 LibWeb: Add a basic DOM::Position class
This will be used for editable content. :^)
2020-08-02 17:34:50 +02:00
AnotherTest
1df9293ea4 LibWeb: Complete the redirect URL before loading it
the "Location" header is allowed to be a relative URL (as is the case in
our very own WebServer!)
2020-07-30 16:56:15 +02:00
Andreas Kling
fffc5896d8 LibWeb: Make layout tree have non-const pointers to the DOM
Const pointers into the DOM was a nice idea, but in practice, there are
too many situations where the layout tree wants to some non-const thing
to the DOM.
2020-07-28 19:48:57 +02:00
Andreas Kling
a4eadeb80d LibWeb: Oops, provide the correct WrapperType for UIEvent 2020-07-28 19:40:11 +02:00
Andreas Kling
c95a1fe3a3 LibWeb: Add UIEvent class (base of MouseEvent, and others) 2020-07-28 19:39:17 +02:00
Andreas Kling
ef711f501e LibWeb: Move the Page/Frame/EventHandler classes into Page/ 2020-07-28 19:28:29 +02:00
Andreas Kling
481e838054 LibWeb: Fix bad #include in CSSParser.cpp 2020-07-28 19:28:29 +02:00
Andreas Kling
7daeddb9e9 LibWeb: Move the CSS parser into CSS/Parser/ 2020-07-28 19:23:18 +02:00
Andreas Kling
cc4109c03b LibWeb: Move the HTML parser into HTML/Parser/ 2020-07-28 19:23:18 +02:00
Andreas Kling
c46439f240 LibWeb: Move HTML classes into the Web::HTML namespace 2020-07-28 18:55:48 +02:00
Andreas Kling
8b55d3d86e LibWeb: Move MouseEvent into the UIEvents namespace
Named after the UIEvents specification that houses MouseEvent.
2020-07-28 18:55:47 +02:00
asynts
abe925e4b0 AK: Change the signature of AK::encode_base64() to use Span. 2020-07-27 19:58:09 +02:00
Andreas Kling
78518d230c LibCore+LibWeb: Move guess-mimetype-based-on-filename logic to LibCore
This could be useful in more places.
2020-07-27 19:57:20 +02:00
Luke
a2b40de0cc LibWeb: Add a whole bunch of HTML DOM bindings
Note that these aren't full implementations of the bindings. This
mostly implements the low hanging fruit (namely, basic reflections)

There are some attributes that should be USVString instead of
DOMString. However, USVString is a slightly different definition
of DOMString, so it should suffice for now.
2020-07-27 19:51:45 +02:00
Matthew Olsson
335916d8db LibGfx: Templatize Point, Size, and Rect 2020-07-27 01:06:26 +02:00
Andreas Kling
1f008c95b6 LibWeb: Move CSS classes into the Web::CSS namespace 2020-07-26 20:05:15 +02:00
Andreas Kling
11ff9d0f17 LibWeb: Move DOM classes into the Web::DOM namespace
LibWeb keeps growing and the Web namespace is filling up fast.
Let's put DOM stuff into Web::DOM, just like we already started doing
with SVG stuff in Web::SVG.
2020-07-26 20:05:15 +02:00
Andreas Kling
eabd43d31a LibWeb: Make SVGElement and SVGGeometryElement constructors protected 2020-07-26 17:51:00 +02:00
Andreas Kling
1b1537c5a6 LibWeb: Simplify type traits for SVGGraphicsElement 2020-07-26 17:51:00 +02:00
Andreas Kling
71556e39a4 LibWeb: Switch to using AK::is and AK::downcast 2020-07-26 17:51:00 +02:00
Andreas Kling
a565121793 LibWeb: Move HTML object model stuff into LibWeb/HTML/
Take a hint from SVG and more all the HTML classes into HTML instead of
mixing them with the DOM classes.
2020-07-26 17:51:00 +02:00
Andreas Kling
d43ddd6eb7 LibWeb: LayoutSVG should not claim to be a LayoutCanvas :^)
Also make the class_name() match the actual class name.
2020-07-26 14:59:43 +02:00
Matthew Olsson
b1299f972c LibWeb: Refactor SVG files into their own directory; follow spec layout 2020-07-26 14:53:43 +02:00
Matthew Olsson
943e4f8bf1 LibWeb: Abstract common operations of graphical SVG elements 2020-07-26 14:53:43 +02:00
Matthew Olsson
9cce7f57dd LibGfx: Add FloatPoint methods
Adds some conversion constructors, as well as the missing arithmetic
operations.
2020-07-26 14:53:43 +02:00
Matthew Olsson
5985eac81d LibWeb: Add elliptical curve support to svg path elements 2020-07-26 14:53:43 +02:00
Matthew Olsson
22f0953fe2 LibWeb: Begin SVG element support
This commit starts adding a basic SVG element. Currently, svg elements
have support for the width and height properties, as well as the stroke,
stroke-width, and fill properties. The only child element supported
is the path element, as most other graphical elements are just shorthand
for paths.
2020-07-26 14:53:43 +02:00
Luke
08221139a5 test-web: Add ability to change page mid-test
This allows you to not have to write a separate test file
for the same thing but in a different situation.

This doesn't handle when you change the page with location.href
however.

Changes the name of the page load handlers to prevent confusion
with this.
2020-07-25 12:35:15 +02:00
Andreas Kling
d1fdc1a2cf LibWeb: Use [Reflect] for Element.id and Element.className :^) 2020-07-24 13:25:42 +02:00
Andreas Kling
8f31331e68 LibWeb: Allow specifying a custom attribute name for [Reflect]
Sometimes the IDL attribute and the DOM attribute don't have the same
exact name. In those cases, we can now do this:

    [Reflect=foobar] attribute DOMString fooBar;
2020-07-24 13:23:47 +02:00
Andreas Kling
cb35a8ea83 LibWeb: Add HTMLElement.lang (and make HTMLElement.title reflecting) 2020-07-24 13:16:11 +02:00
Andreas Kling
ea451cea6a LibWeb: Add HTMLImageElement.src and HTMLImageElement.alt
These are reflecting attributes! :^)
2020-07-24 13:12:14 +02:00
Andreas Kling
3eff6024b1 LibWeb: Add code generation for reflecting IDL attributes
You can now tag reflecting attributes with [Reflect] to generate code
that does basic DOM element attribute get/set.

(This patch also makes it easy to add more extended attributes like
that going forward.)

From the HTML spec:

"Some IDL attributes are defined to reflect a particular content
attribute. This means that on getting, the IDL attribute returns
the current value of the content attribute, and on setting,
the IDL attribute changes the value of the content attribute
to the given value."
2020-07-24 13:06:02 +02:00
Andreas Kling
3cb50a4714 LibWeb: Rename Element::tag_name() => local_name()
To prepare for fully qualified tag names, let's call this local_name.
Note that we still keep an Element::tag_name() around since that's what
the JS bindings end up calling into for the Element.tagName property.
2020-07-23 18:18:13 +02:00
Andreas Kling
6e02ef19d1 LibWeb: Add a helper for creating a fake (start tag) HTML token
Sometimes the parsing rules say we need to insert a fake HTML token.
Let's have a convenient way of doing that!
2020-07-23 17:31:08 +02:00
Andreas Kling
aaf6014ae1 LibJS: Simplify Cell::initialize()
Remove the Interpreter& argument and pass only GlobalObject&. We can
find everything we need via the global object anyway.
2020-07-23 17:31:08 +02:00
Nico Weber
a92f7aea7a LibWeb: Add tests for atob() and btoa() 2020-07-23 15:18:25 +02:00
Luke
60599d03dd LibWeb+test-web: Create test-web program, add doctype test
LibWeb currently has no test suite or program. Let's change that :^)

test-web is mostly a copy of test-js, but modified for LibWeb.
test-web imports both LibJS/Tests/test-common.js and
LibWeb/Test/test-common.js

LibWeb's suite provides the ability to specify the page to load,
what to do before the page is loaded, and what to do after it's
loaded.

This also provides a test of document.doctype and its close sibling
document.compatMode.

Currently, this isn't added to Lagom because of CodeGenerators.
2020-07-23 13:11:41 +02:00
Nico Weber
b9ce56aee6 LibWeb: Make btoa() and atob() correctly handle values between 128 and 255
btoa() takes a byte string, so it must decode the UTF-8 argument into
a Vector<u8> before calling encode_base64.

Likewise, in atob() decode_base64 returns a byte string, so that needs
to be converted to UTF-8.

With this, `btoa(String.fromCharCode(255))` is '/w==' as it should
be, and `atob(btoa(String.fromCharCode(255))) == String.fromCharCode(255)`
remains true.
2020-07-22 19:22:00 +02:00
Nico Weber
5ba8aba197 AK: Make encode_base64 take a ByteBuffer and return a String
That makes the interface symmetric with decode_base64 and it's
what all current callers want (except for one, which is buggy).
2020-07-22 19:22:00 +02:00
Nico Weber
248b79d687 LibJS: Add FIXMEs to a few functions that need UTF-16 handling 2020-07-22 17:26:34 +02:00
Andreas Kling
7230b7aad7 LibWeb: Replaced elements had backwards application of intrinsic ratio
If we know the width, but not the height, we have to *divide* with the
intrinsic ratio to get the height (not multiply.) :^)

This makes things like <img width=300 src=image.png> work right.
2020-07-22 01:47:36 +02:00
Andreas Kling
f43590f534 LibWeb: Set the intrinsic width/height of <img> instead of hacking it
Images were added before replaced element layout knew about intrinsic
sizes, so this was a bit backwards. We now instead transfer the known
intrinsic sizes from the ImageLoader to the LayoutImage.
2020-07-22 01:39:51 +02:00
Andreas Kling
a3feb46ad7 LibWeb: Parse "width" and "height" presentation attributes on <img>
These are HTML lengths that map to CSS width and height respectively.
2020-07-22 01:16:27 +02:00
Andreas Kling
5a7e57457e LibWeb: Add a dedicated function for parsing HTML length values
Presentation attribute lengths (width, height, etc.) can always be
unit-less (e.g "400") so going via the normal CSS parsing path only
works when the document is in quirks mode.

Add a separate parse_html_length() that always allows unit-less values.
2020-07-22 01:13:18 +02:00
Luke
201cc1bfcc LibWeb: Assert we're parsing a fragment on fragment cases
The specification says that parts labelled as a "fragment case" will
only occur when parsing a fragment. It says that if it occurs when
not parsing a fragment, then it is a specification error.

We should probably assume at this point that it's an implementation
error. This fixes a few little mistakes that were caught out by this.

Also moves the context element outside insertion mode reset,
as other (unimplemented) parts refer to it, such as
"adjusted current node".

Also cleans up insertion mode reset.
2020-07-22 00:02:40 +02:00
Andreas Kling
685e006e27 LibWeb: Use "namespace Web::Foo {" since C++20 allows it :^)
Thanks @nico for teaching me about this!
2020-07-21 16:23:08 +02:00
Luke
19d6884529 LibWeb: Implement quirks mode detection
This allows us to determine which mode to render the page in.

Exposes "doctype" and "compatMode" on Document.
Exposes "name", "publicId" and "systemId" on DocumentType.
2020-07-21 01:08:32 +02:00
Tom
27bd2eab22 LibWeb: Require parent window argument for MessageBox
Since the vast majority of message boxes should be modal, require
the parent window to be passed in, which can be nullptr for the
rare case that they don't. By it being the first argument, the
default arguments also don't need to be explicitly stated in most
cases, and it encourages passing in a parent window handle.

Fix up several message boxes that should have been modal.
2020-07-16 16:10:21 +02:00
Kevin Meyer
7b5ffe67cf LibWeb: Check if layout node is still present after dispatch_event
Fixes https://github.com/SerenityOS/serenity/issues/2638

Dispatching an event can change the document. Therefore another check
for the layout_root needs to be done.
2020-07-11 11:34:59 +02:00
Kevin Meyer
821043d798 LibWeb: Remove some unnecessary casts 2020-07-11 11:34:59 +02:00
Kevin Meyer
d5d732cc87 LibWeb: Fix EVENT_DEBUG dump compilation 2020-07-11 11:34:59 +02:00
Kevin Meyer
5b6920a18a LibWeb: Don't call did_layout in non-main frame documents
Fixes https://github.com/SerenityOS/serenity/issues/2649

Loading a page with iframes could lead to a scenario, where the iframe
document finished layout prior to the main frame beeing laid out
initially. This caused a crash/assertion of the browser.
2020-07-08 23:45:12 +02:00
Kevin Meyer
a5b8cc2d0b LibWeb: Add type for FrameLoader::load
This should enable to destinguish between IFrame, Reload and Navigation
motivated loads in order to call the appropriate hooks.

This change is motivated as loading the IFrame test page causes the
IFrame url to be added to the history and shows up as the current
browser location bar.
2020-07-08 23:45:12 +02:00
Andreas Kling
5975a425bd LibWeb: Turn floated display:inline elements into block-level elements 2020-07-07 17:10:12 +02:00
Andreas Kling
92374fc942 LibWeb: Make context menus work in WebContentView
As usual, this was just a matter of plumbing the PageClient calls from
the WebContent side over to the WebContentView side. :^)
2020-07-07 12:24:29 +02:00
Kevin Meyer
7974279a5d LibWeb: Fix PageView::url() null-check 2020-07-07 11:07:44 +02:00
Andreas Kling
c43afe71b7 LibWeb: Make WebContentView show the hover hand over links :^) 2020-07-06 23:32:12 +02:00
Andreas Kling
56126d7a45 LibWeb: Don't show unnecessary scrollbars in WebContentView
This behaves a little weird right now, and will probably require more
coordination between the widget and the WebContent process.
2020-07-06 22:02:38 +02:00
Andreas Kling
9169c8ca94 LibWeb: Make the WebContentView::on_load_start hook actually work :^) 2020-07-06 21:58:16 +02:00
Andreas Kling
d8be535579 Browser+LibWeb: Pave the way for using WebContentView in Browser
This commit sets everything up, but we still always instantiate a plain
Web::PageView in Browser::Tab..
2020-07-06 21:46:37 +02:00
Andreas Kling
49b9a0a665 LibWeb: Add a shared WebViewHooks base class for both web view widgets
This will make it easier for Browser to share code between both views.
2020-07-06 21:19:03 +02:00
Andreas Kling
7a7e39c7af LibWeb: Move WebContentView from Demos/WebView into LibWeb 2020-07-06 20:36:34 +02:00
Andreas Kling
fd65a24834 LibWeb: Make the link context menu hook include the destination URL 2020-07-06 20:00:56 +02:00
Andreas Kling
02c5e22f06 LibWeb: Make the link click hooks include the destination URL
We have all the context needed for relative URL resolution inside the
engine, so let's not make embedders worry about this.
2020-07-06 19:41:10 +02:00
Nico Weber
e9d18e35d6 LibWeb: Move "Stop parsing!" behind PARSER_DEBUG
This makes SerenityOS's IRC client a lot less chatty.
2020-07-06 17:03:26 +02:00
Andreas Kling
244fe1089c LibWeb: Use LayoutTableRowGroup for display:table-{header,footer}-group 2020-07-05 19:51:49 +02:00
Andreas Kling
d4fe3e8009 LibWeb: Always fire the link hover hooks when moving between links
Some broken logic was preventing us from firing the hover hooks when
the cursor jumped directly from one link to another.
2020-07-05 17:05:23 +02:00
Andreas Kling
63d796312d LibWeb: Tweak PageView::on_link_hover hook
Change: on_link_hover(String) -> on_link_hover(URL)

Also, we now fire the hook when a link is unhovered as well, allowing
the embedder to react to nothing being hovered anymore.
2020-07-05 17:02:44 +02:00
Andreas Kling
56d14d5701 LibWeb: Move fragment link handling to Frame
Activating a "#foo" fragment link will now be handled internally by
the Frame instead of involving the widget layer.

If the viewport needs to be scrolled as a result, we will simply ask
the PageClient to scroll a new rect into view.
2020-07-05 15:57:07 +02:00
Andreas Kling
ca93c22ae2 LibGUI: Turn GUI::Application::the() into a pointer
During app teardown, the Application object may be destroyed before
something else, and so having Application::the() return a reference was
obscuring the truth about its lifetime.

This patch makes the API more honest by returning a pointer. While
this makes call sites look a bit more sketchy, do note that the global
Application pointer only becomes null during app teardown.
2020-07-04 16:54:55 +02:00
Andreas Kling
ccdaa1bea9 LibWeb: Insert newlines at <br> and block boundaries in copied text :^)
To make the plain text we copy out from LibWeb look at least somewhat
like its original form, let's insert newlines at <br> elements and when
we exit a block-level element.

This is far from perfect, but seems to work pretty okay.
2020-07-03 21:34:12 +02:00
Andreas Kling
f7ef6c65b4 LibWeb: Add a "select all" action to the Web::PageView
This works by finding the very first and very last LayoutText nodes
in the layout tree and then setting the selection bounds to those two
nodes. For some reason it gets glitchy if we set the very first and
very last *LayoutNode* as the selection bounds, but I didn't feel like
investigating that too closely right now.
2020-07-03 21:34:12 +02:00
Andreas Kling
f87881e198 LibWeb: Implement basic text copying :^)
You can now press Ctrl+C to copy the selected text in a Web::PageView
to the system clipboard. Very cool!
2020-07-03 21:34:12 +02:00
Andreas Kling
392b055806 LibWeb: Use the StackingContext tree for hit testing
This makes it possible to click links that are above other content due
to stacking context order (e.g via CSS z-index.)
2020-07-01 19:10:58 +02:00
Andreas Kling
f7a900367f LibWeb: StackingContext was sorting the wrong list of children
Oops, we're supposed to sort the *parent's* children, not our own.
2020-07-01 18:35:50 +02:00
Matthew Olsson
bda39ef7ab LibJS: Explicitly pass a "Function& new_target" to Function::construct
This allows the proxy handler to pass the proper new.target to construct
handlers.
2020-07-01 11:16:37 +02:00
Andreas Kling
53573f6fb1 LibWeb: Clamp text fragment selection to the fragment
Also add 1px of width to partial fragment selections, since that ends
up looking nicer during interactive mouse selection.
2020-06-29 12:47:21 +02:00
Andreas Kling
301ac3c7e5 LibWeb: Improve hit testing on the right of line boxes
We now remember the last candidate fragment when hit testing past the
right end of text and use that as the fallback result if nothing else
matches. This makes it possible to drag-select outside the line boxes
in a way that feels mostly natural. :^)
2020-06-29 00:39:51 +02:00
Andreas Kling
9177eea8fe LibWeb: Add LayoutRange::normalized()
We use this to ensure that we're always working with a selection where
the start() is before the end() in document order. That simplifies all
the logic around this.
2020-06-29 00:39:51 +02:00
Andreas Kling
706fc3d1aa LibWeb: Paint the text selection :^)
Text selection currently works at the LayoutNode level. The root of the
layout tree has a LayoutRange selection() which in turn has two
LayoutPosition objects: start() and end().

A LayoutPosition is a LayoutNode + a text offset into that node.

We handle the selection painting in LayoutText::paint_fragment(), after
the normal painting is finished. The basic mechanism is that each
LayoutFragment is queried for its selection_rect(), and if a non-empty
rect is returned, we clip to it and paint the text once more.
2020-06-29 00:39:51 +02:00
Andreas Kling
2762e3d80a LibWeb: Rename LineBoxFragment::render() => paint()
Also LayoutText::render_fragment() => render(). This matches the names
in the rest of LibWeb.
2020-06-28 23:07:44 +02:00
Andreas Kling
dcc25f7d7a LibWeb: Layout table-cell contents once again once final width is known
This makes centered and right-aligned table-cell contents position
itself correctly.
2020-06-28 20:54:45 +02:00
Luke
2df69317f1 LibWeb: Implement almost all missing tokenizer cases 2020-06-28 16:56:26 +02:00
Andreas Kling
f270f1f274 LibWeb: Give the <blockquote> element some margins in the UA style 2020-06-28 15:26:05 +02:00
Andreas Kling
7d3c8d066f LibWeb: Support "pt" length units :^) 2020-06-28 15:25:32 +02:00
Andreas Kling
7fc988b919 LibWeb: Start working on supporting fixed table layouts
Sometimes people make tables with a specific width. In those cases,
we can't just use the auto-sizing algorithm, but instead have to
respect whatever width the content specifies.

This is a bit rickety right now, since we don't implement generation
of anonymous table boxes.

The basic mechanism here is that block layout (which table-cell uses)
now has a virtual way of asking for the width of the logical containing
block. This is necessary as table-row does not produce a block-level
element and so was previously unable to provide a containing block
width for table-cell layout.

If the table has a non-auto specified width, we now interpret that as
a request to use fixed table layout. This will evolve over time. :^)
2020-06-28 15:13:56 +02:00
Andreas Kling
daa88448e1 LibWeb: Add Length::is_undefined_or_auto()
Quite often, we want the same behavior in both cases. This allows us
to express that with a single method.
2020-06-28 15:08:37 +02:00
Andreas Kling
b8dc1fc195 LibWeb: Turn <td width> into a CSS width property 2020-06-28 14:30:37 +02:00
Andreas Kling
38d6cc8598 LibWeb: Convert uppercase selector tag names to lowercase internally
This is necessary for some older content to work correctly. There's
probably a nicer (and correct-er) way to do this. Deferring to the
new CSS parser.
2020-06-28 12:58:04 +02:00
Andreas Kling
fd32f24753 LibWeb: Tweak default style for <hr> to use em units for margin values 2020-06-28 12:57:42 +02:00
Andreas Kling
9e642827fc LibWeb: Don't tolerate unit-less lengths (except 0) in standards mode
"width: 500" is not a valid CSS property in standards mode and should
be ignored.

To plumb the quirks-mode flag into CSS parsing, this patch adds a new
CSS::ParsingContext object that must be passed to the CSS parser.
Currently it only allows you to check the quirks-mode flag. In the
future it will be a good place to put additional information needed
for things like relative URL resolution, etc.

This narrows <div class=parser> on ACID2 to the correct width. :^)
2020-06-28 12:46:40 +02:00
Andreas Kling
c1acf67715 LibWeb: Use length units and shorthands in the default UA style sheet 2020-06-28 12:12:01 +02:00
Andreas Kling
9576f6b1d4 LibWeb: Collapse top and bottom margin of empty sibling blocks
Margin collapsing is a bit confusing, but if I understand correctly,
when collapsing a box's top margin with the vertically adjacent
sibling box above, we should "skip over" empty (0-height) boxes and
collapse their margin with *their* vertically adjacent sibling box
above, etc. Iterating until we hit the first non-empty in-flow block.

This pulls up the bottom part of the face on ACID2. :^)
2020-06-28 11:20:15 +02:00
Andrew Kaster
cc675cbe24 LibWeb: Add Page context menu request
Pages can request a context menu on right click. This is plumbed
through the PageClient.
2020-06-28 00:05:08 +02:00
Andreas Kling
8d2194bdbd LibWeb: Make DOM timers cancellable and stop leaking them
This patch adds a Web::Timer object that represents a single timer
registration made with window.setTimeout() or window.setInterval().
All live timers are owned by the DOM Window object.

The timers can be stopped via clearTimeout() or clearInterval().
Note that those API's are actually interchangeable, but we have to
support both.
2020-06-27 20:02:04 +02:00
Kevin Meyer
22b20c381f LibWeb: Implement remaining missing tokenizer EOF cases 2020-06-27 13:27:10 +02:00
Hüseyin ASLITÜRK
0f7a651adc LibWeb: Add "image/x‑portable‑graymap" mime type for pgm file extension 2020-06-27 13:01:27 +02:00
Andreas Kling
8e6522d034 LibWeb: Implement some missing tokenizer cases for EOF handling 2020-06-26 22:47:07 +02:00
Andreas Kling
9d8565cf9a LibWeb: Add CanvasRenderingContext2D.rotate()
This is pretty limited since we don't have wholesale mapping through
the context transform, but we have to start somewhere. :^)
2020-06-26 18:27:12 +02:00
Andreas Kling
ba76a72422 LibWeb: Skip over floating elements when collapsing margins
Two sibling blocks are not vertically adjacent if one is float:left
and the other is float:none. Respect this when collapsing margins.
2020-06-26 18:27:12 +02:00
Andreas Kling
62daa6f73c LibWeb: Add the 'float' CSS property to LayoutStyle
Note that we don't use the property for anything yet, as I'm still
wrapping my head around how to implement floats.
2020-06-26 18:27:12 +02:00
theazgra
6a401a9bde LibWeb: Remove duplicate if branch in fragment parsing.
I noticed in the video the duplicate `if` check. This commit removes
the duplicated branch.
2020-06-26 11:58:53 +02:00
Andreas Kling
6293d1a13c LibWeb+Browser: Remove old HTML parser :^)
The new parser is now used everywhere and it's working pretty well!
2020-06-26 00:53:25 +02:00
Andreas Kling
92d831c25b LibWeb: Implement fragment parsing and use it for Element.innerHTML
This patch implements most of the HTML fragment parsing algorithm and
ports Element::set_inner_html() to it. This was the last remaining user
of the old HTML parser. :^)
2020-06-26 00:53:25 +02:00
Andreas Kling
eb33021d65 LibWeb: Tolerate quoted HTTP Content-Type encodings 2020-06-26 00:53:25 +02:00
Andreas Kling
edf0aacda4 LibWeb: Add Document.getElementsByTagName() 2020-06-26 00:53:25 +02:00
Andreas Kling
ee4cf0bc69 LibWeb: Let's not pass "%u" to String() and expect something to happen 2020-06-26 00:53:25 +02:00
Andreas Kling
ebf326a98c LibWeb: Fix build after Specificity.h removal 2020-06-25 20:59:00 +02:00
Andreas Kling
4f7c7bbb09 LibWeb: Treat all HTTP 4xx codes as errors 2020-06-25 17:19:29 +02:00
Andreas Kling
505b133fda LibWeb: Don't allow more than one color sub-value in CSS 'background' 2020-06-25 16:55:43 +02:00
Andreas Kling
3fefc7f3e9 LibWeb: Tweak CSS parser to swallow backslash-escaped characters
This isn't the correct way of doing this, but at least it allows the
parsing to progress a bit further in some cases.
2020-06-25 16:52:38 +02:00
Andreas Kling
49dd4b7e8a LibWeb: Compress specificity into a 32-bit unsigned int
Instead of storing the three-part specificy for every selector,
just mash them together into a 32-bit value instead.
This saves both space and time, and matches the behavior of other
browser engines.
2020-06-25 16:43:49 +02:00
Andreas Kling
8be74ea65c LibWeb: Percentage 'height' should sometimes behave as 'auto'
Something like "height: 50%" is equivalent to "height: auto" unless the
containing block has explicitly specified height.
2020-06-25 16:04:57 +02:00
Andreas Kling
afebbd1cd7 LibWeb: Serialize Length::Type::Percentage with a "%" suffix
"10 percentage" looked rather silly. :^)
2020-06-25 15:53:23 +02:00
Andreas Kling
f650f18bd2 LibWeb: Make scroll-to-anchor zone in on the element's padding box
That seems to be what other engines do. This is a bit hackish but we'll
soon have to redo scroll-to-anchor anyway for the multi-process model.
2020-06-25 15:53:23 +02:00
Andreas Kling
bab0143bb2 LibWeb: Place normal-flow blocks relative to non-absolute siblings
We could previously place a box next to a preceding sibling with
position:fixed, which is wrong since fixed-position elements are taken
out of the normal flow.
2020-06-25 15:53:23 +02:00
Andreas Kling
b2f54be514 LibWeb: Draw the margin and padding boxes around the inspected node
When highlighting a node in the inspector, we now paint three overlays:

- The content box (magenta)
- The padding box (cyan)
- The margin box (yellow)

This makes it a lot easier to debug layout issues.
2020-06-25 15:53:23 +02:00
Andreas Kling
8f92ed957b LibWeb: Iterating more on placement of absolutely positioned elements 2020-06-25 15:53:23 +02:00
Andreas Kling
ee1c241be9 LibWeb: Update the border metrics of absolutely positioned boxes
We were neglecting to populate the border parts of BoxModelMetrics for
absolutely positioned block descendants.
2020-06-25 15:53:23 +02:00
Andreas Kling
232e41a238 LibWeb: Remove empty trailing line boxes
Sometimes we end up with an empty line box at the bottom of a block.
Instead of worrying about this in all the places we split into lines,
just remove the trailing box (if any) after splitting is finshed.
2020-06-25 15:53:23 +02:00
Andreas Kling
58f76ed11f LibWeb: Avoid some redundant resolution of padding values during layout
Padding is not affected by the width constraining algorithm, so we can
just resolve it up front.
2020-06-25 15:53:23 +02:00
Andreas Kling
8960c6f8fe LibWeb: Use the cached white-space from LayoutStyle in text_for_style() 2020-06-24 21:44:11 +02:00
Andreas Kling
440b4ece22 LibWeb: Move border width and color into LayoutStyle
To make this possible, I also had to give each LayoutNode a Document&
so it can resolve document-specific colors correctly. There's probably
ways to avoid having this extra member by resolving colors later, but
this works for now.
2020-06-24 19:43:27 +02:00
Andreas Kling
4b2ac34725 LibWeb: Move the offset, margin and padding boxes into LayoutStyle 2020-06-24 18:06:21 +02:00
Andreas Kling
6b334e02e6 LibWeb: Move white-space into LayoutStyle 2020-06-24 18:06:21 +02:00
Andreas Kling
bc178ee743 LibWeb: Add CSS::Display enum and StyleProperties::display()
The display property is not interesting after we've built the layout
tree, so we don't have to move it into LayoutStyle.
2020-06-24 18:06:21 +02:00
Andreas Kling
5d86305a72 LibWeb: Move height, min-height and max-height into LayoutStyle 2020-06-24 16:49:51 +02:00
Andreas Kling
ec466c0385 LibWeb: Move min-width and max-width into LayoutStyle 2020-06-24 16:49:51 +02:00
Andreas Kling
ecacab8618 LibWeb: Move width into LayoutStyle
This patch also adds the ability for Length to contain percentage
values. This is a little off-spec, but will make storing and dealing
with lengths a lot easier.

To resolve a Length to a px-or-auto Length, there are now helpers
for that. After calling them, you no longer have to think about
em, rem, %, and such things.
2020-06-24 16:49:51 +02:00
Andreas Kling
959464fce4 LibWeb: Move position and text-align to LayoutStyle 2020-06-24 16:49:51 +02:00
Andreas Kling
6f28f08096 LibWeb: Add LayoutStyle, a place to store style info for layout & paint
StyleProperties is really only the specified "input" to what eventually
becomes the used/computed style we use for layout and painting.

Unlike StyleProperties, LayoutStyle will have strongly typed values for
everything it contains (i.e no CSS::ValueID or strings, etc.)

This first patch moves z-index into LayoutStyle.
2020-06-24 16:49:51 +02:00
Andreas Kling
5e83a97fa2 LibWeb: Rename LayoutNode::style() => specified_style()
Let's make way for a slightly-more-cooked style() that will eventually
replace the raw specified_style() for layout and paint purposes.
2020-06-24 13:54:31 +02:00
Andreas Kling
90edaabc4b LibWeb: Add an "undefined" state to Length
A default-constructed Length now gives you an undefined length value,
which can be used to signify the absence of a value.
2020-06-24 11:24:00 +02:00
Andreas Kling
f742b245b7 LibWeb: Turn BoxModelMetrics into a simple struct
Using getters for this thing was just cumbersome and didn't achieve
anything of value so just turn it into a plain struct.
2020-06-24 11:22:34 +02:00
Andreas Kling
5744dd43c5 LibWeb: Remove default Length constructor and add make_auto()/make_px()
To prepare for adding an undefined/empty state for Length, let's first
move away from Length() creating an auto value.
2020-06-24 11:08:46 +02:00
Andreas Kling
26eef65017 LibWeb: Use the cached text-align value in LineBox::add_fragment() 2020-06-24 00:09:45 +02:00
Andreas Kling
f4ecb5362f LibWeb: Cache the used CSS text-align property on LayoutNodeWithStyle 2020-06-23 23:28:40 +02:00
Andreas Kling
ae181e1573 LibWeb: Always inline absolute Length to_px() conversion
Only do the relative Length units out of line.
2020-06-23 23:21:58 +02:00
Andreas Kling
5f0a1ef21b LibWeb: Always inline is<LayoutBox>() and is<LayoutBlock>() 2020-06-23 23:21:39 +02:00
Andreas Kling
9b8464f455 LibWeb: Cache the used CSS 'position' value on LayoutNodeWithStyle
This avoids having to query the StyleProperties hash map whenever we
need to know if an element is absolutely positioned. This was extremely
hot in interactive window resize profiles.
2020-06-23 23:15:23 +02:00
Andreas Kling
d0312f6208 LibWeb: Handle empty inputs to the CSS parser
Empty inputs -> empty outputs.
2020-06-23 20:06:45 +02:00
Andreas Kling
86098505ec LibWeb: Handle position:absolute with both left and right specified
In this case, we need to undo the right-side offsetting, since the
width computation algorithm will already have stretched the width to
accomodate both the side constraints.
2020-06-23 20:05:35 +02:00
Andreas Kling
8d235d0e2f LibWeb: Make sure BoxModelMetrics are set for position:absolute boxes
This is all very redundant and we should find a way to share this code
between at least some of the positioning modes.
2020-06-23 19:21:04 +02:00
Andreas Kling
7c848645c3 LibWeb: Take margin into account when positioning absolute descendants 2020-06-23 19:20:06 +02:00
Andreas Kling
aeeaf33638 LibWeb: Respect specified width when computing shrink-to-fit candidates
Previously we would always just use the combined content width as the
shrunken width in shrink-to-fit width calculations, but if the element
has a non-auto specified width, we should just let that take over.

This is far from perfect and doesn't take stuff like min/max-width
into account. Will need more work, this just covers the basic case.
2020-06-23 18:55:25 +02:00
Andreas Kling
78f10942ba LibWeb: Update PageView content size on page relayout
If the layout changes and the page becomes taller or shorter for some
reason, we need to update the PageView's scrollable content size.
2020-06-23 18:02:08 +02:00
Andreas Kling
ba641e97d9 LibJS: Clarify Object (base class) construction somewhat
Divide the Object constructor into three variants:

- The regular one (takes an Object& prototype)
- One for use by GlobalObject
- One for use by objects without a prototype (e.g ObjectPrototype)
2020-06-23 17:21:53 +02:00
Andreas Kling
fc4ed8d444 LibWeb: Make wrapper factory functions take JS::GlobalObject&
Instead of taking the JS::Heap&. This allows us to get rid of some
calls to JS::Interpreter::global_object(). We're getting closer and
closer to multiple global objects. :^)
2020-06-23 16:57:39 +02:00
Andreas Kling
c24f5585b2 LibWeb: Let HTMLScriptElement call Document::run_javascript()
The fewer places we invoke the JS parser the better. Unless we have
some specific reason to parse manually, we can just call Document.
2020-06-23 16:45:01 +02:00
Andreas Kling
3a5af6ef61 LibWeb: Remove hacky old ways of running <script> element contents
Now that we're using the new HTML parser, we don't have to do the weird
"run the script when inserted into the document, uhh, or when the text
content of the script element changes" dance.

Instead, we just follow the spec, and scripts run the way they should.
2020-06-23 16:45:01 +02:00
Andreas Kling
c33d17d363 LibWeb: Fix tokenization of attributes with URL query strings in them
<a href="/foo&amp=bar"> was being tokenized into <a href="/foo&=bar">.
The spec mentions this but I had overlooked it. The bug happens because
we interpreted the "&amp" as a named character reference.
2020-06-23 16:45:01 +02:00
Andreas Kling
fbd760379a LibWeb: Remove Gfx::ImageDecoder from ImageLoader
We still use a Gfx::ImageDecoder for GIF images, but there's no need
for the ImageLoader object to have its own pointer to it. Just grab
the ImageDecoder from the ImageResource when needed.
2020-06-23 14:28:45 +02:00
Andreas Kling
9ef5d46277 LibWeb: Use ImageLoader::has_image() in HTMLObjectElement
This makes ACID2 load the eyes image again. :^)
2020-06-23 14:28:45 +02:00