dymokomi/luce-browser-engine
Source of release 0.6.1
0.6.1 / src / web / html / list_of_available_images.lucb
#==============================================================================================
#
# list_of_available_images - HTML::ListOfAvailableImages: a document's list of available images
#
# DESCRIPTION:
# Port of LibWeb/HTML/ListOfAvailableImages.cpp (lines 1-59) and ListOfAvailableImages.h:
# the key's equality and hash (AK::Traits<Key> forwards to them, generated/types_traits),
# the entries and the map from keys to entries.
#
#==============================================================================================
# mark: Key and Entry ===========================================================================
## Ported from ListOfAvailableImages.cpp:17 Web::HTML::ListOfAvailableImages::Key::operator==.
pub func html_list_of_available_images_key_eq(this: const HtmlListOfAvailableImagesKey*, other: HtmlListOfAvailableImagesKey) -> bool:
if not ak.string_equals(&this.url, &other.url) or this.mode != other.mode:
return false
# Optional<URL::Origin>::operator==: both empty, or both present and equal.
if let origin = this.origin:
if let other_origin = other.origin:
return web_url.origin_eq(&origin, other_origin)
return false
return other.origin == none
## Ported from ListOfAvailableImages.cpp:22 Web::HTML::ListOfAvailableImages::Key::hash.
## (C++ caches the hash in the key's mutable `cached_hash`; the traits hand the key over as a
## const pointer, often to a `let`, so the port computes it each time: the same value.)
pub func html_list_of_available_images_key_hash(this: const HtmlListOfAvailableImagesKey*) -> u32:
let url_hash = ak.string_base_hash(&this.url.string_base)
let mode_hash = (u32)this.mode
var origin_hash: u32 = 0
if let origin = this.origin:
origin_hash = web_url.origin_traits_hash(&origin)
return ak.pair_int_hash(url_hash, ak.pair_int_hash(mode_hash, origin_hash))
## Ported from ListOfAvailableImages.h:37 Web::HTML::ListOfAvailableImages::Entry::Entry.
pub func html_list_of_available_images_entry_construct(this: HtmlListOfAvailableImagesEntry*, image_data: HtmlDecodedImageData*, ignore_higher_layer_caching: bool):
this.image_data = image_data
this.ignore_higher_layer_caching = ignore_higher_layer_caching
# mark: ListOfAvailableImages ===================================================================
## Ported from ListOfAvailableImages.cpp:14 Web::HTML::ListOfAvailableImages::ListOfAvailableImages.
pub func html_list_of_available_images_construct(this: HtmlListOfAvailableImages*):
# = default: the map starts empty (zeroed memory is an empty HashMap).
return
## Ported from ListOfAvailableImages.cpp:34 Web::HTML::ListOfAvailableImages::visit_edges (override).
pub func html_list_of_available_images_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
let this = (HtmlListOfAvailableImages*)base
gc.cell_visit_edges_impl(base, visitor)
for it in ak.hash_map_begin(&this.m_images):
gc.cell_visitor_visit_t(visitor, it.value.image_data)
## Ported from ListOfAvailableImages.cpp:41 Web::HTML::ListOfAvailableImages::add.
pub func html_list_of_available_images_add(this: HtmlListOfAvailableImages*, key: HtmlListOfAvailableImagesKey, image_data: HtmlDecodedImageData*, ignore_higher_layer_caching: bool):
# make<Entry>(image_data, ignore_higher_layer_caching)
let entry = new HtmlListOfAvailableImagesEntry(image_data = image_data) else trap("out of memory")
html_list_of_available_images_entry_construct(entry, image_data, ignore_higher_layer_caching)
_ = ak.hash_map_set(&this.m_images, key, entry)
## Ported from ListOfAvailableImages.cpp:46 Web::HTML::ListOfAvailableImages::remove.
pub func html_list_of_available_images_remove(this: HtmlListOfAvailableImages*, key: HtmlListOfAvailableImagesKey):
_ = ak.hash_map_remove_k(&this.m_images, key)
## Ported from ListOfAvailableImages.cpp:51 Web::HTML::ListOfAvailableImages::get.
pub func html_list_of_available_images_get(this: HtmlListOfAvailableImages*, key: HtmlListOfAvailableImagesKey) -> HtmlListOfAvailableImagesEntry*?:
let entry = ak.hash_map_get_k(&this.m_images, key) else return none
return *entry