external resource loading, window.location, tab icon fix
This commit is contained in:
@@ -56,6 +56,8 @@ class ParseResult:
|
||||
var css_parser: CSSParser = null
|
||||
var inline_styles: Dictionary = {}
|
||||
var dom_nodes: Dictionary = {}
|
||||
var external_css: Array[String] = []
|
||||
var external_scripts: Array[String] = []
|
||||
|
||||
func _init():
|
||||
root = HTMLElement.new("document")
|
||||
@@ -105,7 +107,9 @@ func handle_style_element(style_element: HTMLElement) -> void:
|
||||
# Check if it's an external stylesheet
|
||||
var src = style_element.get_attribute("src")
|
||||
if src.length() > 0:
|
||||
# TODO: Handle external CSS loading when Network module is available
|
||||
if not parse_result.external_css:
|
||||
parse_result.external_css = []
|
||||
parse_result.external_css.append(src)
|
||||
return
|
||||
|
||||
# Handle inline CSS - we'll get the text content when parsing is complete
|
||||
@@ -128,6 +132,24 @@ func process_styles() -> void:
|
||||
parse_result.css_parser.css_text = css_content
|
||||
parse_result.css_parser.parse()
|
||||
|
||||
func process_external_styles(base_url: String = "") -> void:
|
||||
if not parse_result.external_css or parse_result.external_css.is_empty():
|
||||
return
|
||||
|
||||
if not parse_result.css_parser:
|
||||
parse_result.css_parser = CSSParser.new()
|
||||
parse_result.css_parser.init()
|
||||
|
||||
var combined_css = parse_result.css_parser.css_text if parse_result.css_parser.css_text else Constants.DEFAULT_CSS
|
||||
|
||||
for css_url in parse_result.external_css:
|
||||
var css_content = await Network.fetch_external_resource(css_url, base_url)
|
||||
if not css_content.is_empty():
|
||||
combined_css += "\n" + css_content
|
||||
|
||||
parse_result.css_parser.css_text = combined_css
|
||||
parse_result.css_parser.parse()
|
||||
|
||||
func get_element_styles_with_inheritance(element: HTMLElement, event: String = "", visited_elements: Array = []) -> Dictionary:
|
||||
if !parse_result.css_parser:
|
||||
return {}
|
||||
@@ -362,11 +384,23 @@ func process_scripts(lua_api: LuaAPI, lua_vm) -> void:
|
||||
var inline_code = script_element.text_content.strip_edges()
|
||||
|
||||
if not src.is_empty():
|
||||
# TODO: add support for external Lua script
|
||||
pass
|
||||
if not parse_result.external_scripts:
|
||||
parse_result.external_scripts = []
|
||||
parse_result.external_scripts.append(src)
|
||||
elif not inline_code.is_empty():
|
||||
lua_api.execute_lua_script(inline_code, lua_vm)
|
||||
|
||||
func process_external_scripts(lua_api: LuaAPI, lua_vm, base_url: String = "") -> void:
|
||||
if not lua_api or not parse_result.external_scripts or parse_result.external_scripts.is_empty():
|
||||
return
|
||||
|
||||
lua_api.dom_parser = self
|
||||
|
||||
for script_url in parse_result.external_scripts:
|
||||
var script_content = await Network.fetch_external_resource(script_url, base_url)
|
||||
if not script_content.is_empty():
|
||||
lua_api.execute_lua_script(script_content, lua_vm)
|
||||
|
||||
func get_all_stylesheets() -> Array[String]:
|
||||
return get_attribute_values("style", "src")
|
||||
|
||||
|
||||
@@ -153,6 +153,35 @@ func _gurt_clear_interval_handler(vm: LuauVM) -> int:
|
||||
_ensure_timeout_manager()
|
||||
return timeout_manager.clear_interval_handler(vm)
|
||||
|
||||
# Location API handlers
|
||||
func _gurt_location_reload_handler(vm: LuauVM) -> int:
|
||||
call_deferred("_reload_current_page")
|
||||
return 0
|
||||
|
||||
func _gurt_location_goto_handler(vm: LuauVM) -> int:
|
||||
var url: String = vm.luaL_checkstring(1)
|
||||
call_deferred("_navigate_to_url", url)
|
||||
return 0
|
||||
|
||||
func _gurt_location_get_href_handler(vm: LuauVM) -> int:
|
||||
var main_node = Engine.get_main_loop().current_scene
|
||||
if main_node and main_node.has_method("get_current_url"):
|
||||
var current_url = main_node.get_current_url()
|
||||
vm.lua_pushstring(current_url)
|
||||
else:
|
||||
vm.lua_pushstring("")
|
||||
return 1
|
||||
|
||||
func _reload_current_page():
|
||||
var main_node = Engine.get_main_loop().current_scene
|
||||
if main_node and main_node.has_method("reload_current_page"):
|
||||
main_node.reload_current_page()
|
||||
|
||||
func _navigate_to_url(url: String):
|
||||
var main_node = Engine.get_main_loop().current_scene
|
||||
if main_node and main_node.has_method("navigate_to_url"):
|
||||
main_node.navigate_to_url(url)
|
||||
|
||||
# Event system handlers
|
||||
func _element_on_event_handler(vm: LuauVM) -> int:
|
||||
vm.luaL_checktype(1, vm.LUA_TTABLE)
|
||||
|
||||
Reference in New Issue
Block a user