mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-03 15:16:14 +00:00
LibHTML: Add load(URL) and reload() functions to HtmlView
You can now pass a file:/// URL to HtmlView and it will take care of the loading logic for you. Each Document remembers the URL it was loaded from, which allows us to also have reload(). This patch also adds a very simple function for resolving relative URL's into absolute ones.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
#include <AK/FileSystemPath.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibHTML/CSS/StyleResolver.h>
|
||||
#include <LibHTML/DOM/Document.h>
|
||||
#include <LibHTML/DOM/Element.h>
|
||||
@@ -99,3 +101,27 @@ Color Document::background_color() const
|
||||
|
||||
return background_color.value()->to_color();
|
||||
}
|
||||
|
||||
URL Document::complete_url(const String& string) const
|
||||
{
|
||||
URL url(string);
|
||||
if (url.is_valid())
|
||||
return url;
|
||||
|
||||
FileSystemPath fspath(m_url.path());
|
||||
StringBuilder builder;
|
||||
builder.append('/');
|
||||
for (int i = 0; i < fspath.parts().size(); ++i) {
|
||||
if (i == fspath.parts().size() - 1)
|
||||
break;
|
||||
builder.append(fspath.parts()[i]);
|
||||
builder.append('/');
|
||||
}
|
||||
builder.append(string);
|
||||
auto built = builder.to_string();
|
||||
fspath = FileSystemPath(built);
|
||||
|
||||
url = m_url;
|
||||
url.set_path(fspath.string());
|
||||
return url;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user