mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 23:48:11 +00:00
LibWeb: Port Window from ByteString
This commit is contained in:
parent
3a7fb6cf9e
commit
48f39f0555
1 changed files with 12 additions and 13 deletions
|
@ -7,7 +7,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/Base64.h>
|
#include <AK/Base64.h>
|
||||||
#include <AK/ByteString.h>
|
|
||||||
#include <AK/GenericLexer.h>
|
#include <AK/GenericLexer.h>
|
||||||
#include <AK/Utf8View.h>
|
#include <AK/Utf8View.h>
|
||||||
#include <LibIPC/File.h>
|
#include <LibIPC/File.h>
|
||||||
|
@ -133,29 +132,29 @@ void Window::visit_edges(JS::Cell::Visitor& visitor)
|
||||||
Window::~Window() = default;
|
Window::~Window() = default;
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#normalizing-the-feature-name
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#normalizing-the-feature-name
|
||||||
static StringView normalize_feature_name(StringView name)
|
static String normalize_feature_name(String const& name)
|
||||||
{
|
{
|
||||||
// For legacy reasons, there are some aliases of some feature names. To normalize a feature name name, switch on name:
|
// For legacy reasons, there are some aliases of some feature names. To normalize a feature name name, switch on name:
|
||||||
|
|
||||||
// "screenx"
|
// "screenx"
|
||||||
if (name == "screenx"sv) {
|
if (name == "screenx"sv) {
|
||||||
// Return "left".
|
// Return "left".
|
||||||
return "left"sv;
|
return "left"_string;
|
||||||
}
|
}
|
||||||
// "screeny"
|
// "screeny"
|
||||||
else if (name == "screeny"sv) {
|
else if (name == "screeny"sv) {
|
||||||
// Return "top".
|
// Return "top".
|
||||||
return "top"sv;
|
return "top"_string;
|
||||||
}
|
}
|
||||||
// "innerwidth"
|
// "innerwidth"
|
||||||
else if (name == "innerwidth"sv) {
|
else if (name == "innerwidth"sv) {
|
||||||
// Return "width".
|
// Return "width".
|
||||||
return "width"sv;
|
return "width"_string;
|
||||||
}
|
}
|
||||||
// "innerheight"
|
// "innerheight"
|
||||||
else if (name == "innerheight") {
|
else if (name == "innerheight") {
|
||||||
// Return "height".
|
// Return "height".
|
||||||
return "height"sv;
|
return "height"_string;
|
||||||
}
|
}
|
||||||
// Anything else
|
// Anything else
|
||||||
else {
|
else {
|
||||||
|
@ -165,10 +164,10 @@ static StringView normalize_feature_name(StringView name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-window-open-features-tokenize
|
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-window-open-features-tokenize
|
||||||
static OrderedHashMap<ByteString, ByteString> tokenize_open_features(StringView features)
|
static OrderedHashMap<String, String> tokenize_open_features(StringView features)
|
||||||
{
|
{
|
||||||
// 1. Let tokenizedFeatures be a new ordered map.
|
// 1. Let tokenizedFeatures be a new ordered map.
|
||||||
OrderedHashMap<ByteString, ByteString> tokenized_features;
|
OrderedHashMap<String, String> tokenized_features;
|
||||||
|
|
||||||
// 2. Let position point at the first code point of features.
|
// 2. Let position point at the first code point of features.
|
||||||
GenericLexer lexer(features);
|
GenericLexer lexer(features);
|
||||||
|
@ -181,16 +180,16 @@ static OrderedHashMap<ByteString, ByteString> tokenize_open_features(StringView
|
||||||
// 3. While position is not past the end of features:
|
// 3. While position is not past the end of features:
|
||||||
while (!lexer.is_eof()) {
|
while (!lexer.is_eof()) {
|
||||||
// 1. Let name be the empty string.
|
// 1. Let name be the empty string.
|
||||||
ByteString name;
|
String name;
|
||||||
|
|
||||||
// 2. Let value be the empty string.
|
// 2. Let value be the empty string.
|
||||||
ByteString value;
|
String value;
|
||||||
|
|
||||||
// 3. Collect a sequence of code points that are feature separators from features given position. This skips past leading separators before the name.
|
// 3. Collect a sequence of code points that are feature separators from features given position. This skips past leading separators before the name.
|
||||||
lexer.ignore_while(is_feature_separator);
|
lexer.ignore_while(is_feature_separator);
|
||||||
|
|
||||||
// 4. Collect a sequence of code points that are not feature separators from features given position. Set name to the collected characters, converted to ASCII lowercase.
|
// 4. Collect a sequence of code points that are not feature separators from features given position. Set name to the collected characters, converted to ASCII lowercase.
|
||||||
name = lexer.consume_until(is_feature_separator).to_lowercase_string();
|
name = MUST(String::from_byte_string(lexer.consume_until(is_feature_separator).to_lowercase_string()));
|
||||||
|
|
||||||
// 5. Set name to the result of normalizing the feature name name.
|
// 5. Set name to the result of normalizing the feature name name.
|
||||||
name = normalize_feature_name(name);
|
name = normalize_feature_name(name);
|
||||||
|
@ -207,7 +206,7 @@ static OrderedHashMap<ByteString, ByteString> tokenize_open_features(StringView
|
||||||
lexer.ignore_while([](auto character) { return Infra::is_ascii_whitespace(character) || character == '='; });
|
lexer.ignore_while([](auto character) { return Infra::is_ascii_whitespace(character) || character == '='; });
|
||||||
|
|
||||||
// 2. Collect a sequence of code points that are not feature separators code points from features given position. Set value to the collected code points, converted to ASCII lowercase.
|
// 2. Collect a sequence of code points that are not feature separators code points from features given position. Set value to the collected code points, converted to ASCII lowercase.
|
||||||
value = lexer.consume_until(is_feature_separator).to_lowercase_string();
|
value = MUST(String::from_byte_string(lexer.consume_until(is_feature_separator).to_lowercase_string()));
|
||||||
|
|
||||||
// 8. If name is not the empty string, then set tokenizedFeatures[name] to value.
|
// 8. If name is not the empty string, then set tokenizedFeatures[name] to value.
|
||||||
if (!name.is_empty())
|
if (!name.is_empty())
|
||||||
|
@ -246,7 +245,7 @@ static T parse_boolean_feature(StringView value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/window-object.html#popup-window-is-requested
|
// https://html.spec.whatwg.org/multipage/window-object.html#popup-window-is-requested
|
||||||
static TokenizedFeature::Popup check_if_a_popup_window_is_requested(OrderedHashMap<ByteString, ByteString> const& tokenized_features)
|
static TokenizedFeature::Popup check_if_a_popup_window_is_requested(OrderedHashMap<String, String> const& tokenized_features)
|
||||||
{
|
{
|
||||||
// 1. If tokenizedFeatures is empty, then return false.
|
// 1. If tokenizedFeatures is empty, then return false.
|
||||||
if (tokenized_features.is_empty())
|
if (tokenized_features.is_empty())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue