mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:38:11 +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:
parent
d64c054d25
commit
78d65c1c64
4 changed files with 69 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue