Sign in

    #Scheduler Module

    ブラウザの Event Loop / Task Scheduler に相当するモジュール。 HTML評価のタスクをキュー管理し、並列実行可能性を判定する。

    #設計方針

    1. 外部委譲: ネットワーク、非同期ランタイム、スクリプト実行は外部に委譲
    2. 内部実行: スタイル計算、レイアウト計算は同期的に内部実行可能
    3. 依存グラフ: タスク間の依存関係を明示的に管理
    4. 並列性判定: 各タスクに並列実行可能かのフラグを付与

    #ブラウザとの対応

    Browser ConceptThis Module
    Event LoopScheduler
    Task QueueTaskQueue
    Task SourceTaskSource
    Microtask(未実装、必要に応じて追加)
    parser-blockingTaskConstraint::Blocking

    #ファイル構成

    scheduler/ ├── README.md # このファイル ├── moon.pkg.json # パッケージ設定 ├── pkg.generated.mbti # 生成された型定義 ├── task.mbt # Task型定義 ├── queue.mbt # TaskQueue管理 ├── scheduler.mbt # Scheduler本体 ├── html_integration.mbt # HTML Parser統合 ├── css_integration.mbt # CSS Cascade統合 ├── layout_integration.mbt # LayoutTree統合 └── task_wbtest.mbt # テスト (48テスト)

    #実装計画

    #Phase 1: 基本型定義 (task.mbt) ✅

    #Phase 2: キュー管理 (queue.mbt) ✅

    #Phase 3: スケジューラ本体 (scheduler.mbt) ✅

    #Phase 4: 統合 ✅

    #型設計

    #TaskSource

    pub(all) enum TaskSource {
    DOM // DOM操作(パース、ツリー構築)
    Styling // スタイル計算
    Layout // レイアウト計算
    Networking // リソースフェッチ(外部委譲)
    Scripting // スクリプト実行(外部委譲)
    ImageDecode // 画像デコード(外部委譲)
    }

    #TaskConstraint

    pub(all) enum TaskConstraint {
    MainThreadOnly // メインスレッド必須
    Parallel // 並列実行可能
    Blocking // 他タスクをブロック
    }

    #TaskAction

    pub(all) enum TaskAction {
    // 内部実行可能
    ParseHTMLChunk(html~ : String)
    ParseCSS(source~ : String)
    ComputeStyle(node_ids~ : Array[String])
    ComputeLayout

    // 外部委譲
    FetchResource(url~ : String, resource_type~ : ResourceType)
    DecodeImage(resource_id~ : Int)
    ExecuteScript(source~ : String)
    }

    #使用例

    // スケジューラ作成
    let scheduler = Scheduler::new()

    // HTMLパースタスクを追加
    let parse_task = scheduler.enqueue(
    ParseHTMLChunk(html="<div>...</div>"),
    MainThreadOnly,
    )

    // 発見したリソースのフェッチタスクを追加(パース完了後)
    let fetch_task = scheduler.enqueue_after(
    FetchResource(url="image.png", resource_type=Image),
    [parse_task],
    )

    // 外部ランタイムがポーリング
    loop {
    // 並列実行可能なタスクを取得
    let parallel_tasks = scheduler.poll_parallel()
    // → 外部で並列実行

    // メインスレッド専用タスクを取得
    let main_tasks = scheduler.poll_ready()
    // → 順次実行

    // 完了通知
    scheduler.complete(task_id, Ok(result))
    }

    #外部ランタイムとの連携

    ┌─────────────────────────────────────────────────────────┐ │ External Runtime │ │ (async runtime, network, script engine, image decoder) │ └─────────────────────────────┬───────────────────────────┘ │ poll_ready() │ complete() poll_parallel() │ ▼ ┌─────────────────────────────────────────────────────────┐ │ Scheduler │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │ DOM │ │ Styling │ │ Network │ │ Script │ │ │ │ Queue │ │ Queue │ │ Queue │ │ Queue │ │ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │ │ │ │ ┌───────────────┴───────────────┐ │ │ │ Dependency Graph │ │ │ └───────────────────────────────┘ │ └─────────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────────┐ │ Internal Modules (sync execution) │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │ HTML │ │ CSS │ │ Cascade │ │ Layout │ │ │ │ Parser │ │ Parser │ │ │ │ Tree │ │ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ └─────────────────────────────────────────────────────────┘

    #統合モジュール

    #HTML Parser 統合 (html_integration.mbt)

    HTMLパーサとスケジューラを統合し、リソース発見とタスク生成を行う。

    // ドキュメントパーサ
    let parser = DocumentParser::new(scheduler)
    let result = parser.on_parse_complete(html)
    // result.fetch_tasks - 外部リソースのフェッチタスク
    // result.style_tasks - インラインスタイルのパースタスク
    // result.script_tasks - スクリプト実行タスク

    主要な型:
    • DocumentParser - スケジューラ連携のHTMLパーサ
    • DiscoveredResource - 発見されたリソース(img, link, script)
    • ResourceDiscoveryResult - リソース発見結果
    • ParseCompleteResult - パース完了結果

    #CSS Cascade 統合 (css_integration.mbt)

    CSSカスケードとスケジューラを統合し、スタイル計算を管理する。

    // スタイルマネージャ
    let style_manager = StyleManager::new(scheduler)
    style_manager.add_stylesheet_source(".foo { color: red; }")
    style_manager.add_inline_style("elem1", "margin: 10px")

    // スタイル計算
    let cascaded = style_manager.compute_style(selector_elem)

    主要な型:
    • StyleManager - スタイルシートとカスケード計算を管理
    • DocumentStyleCoordinator - HTML+CSS統合調整
    • CSSParseResult - CSSパース結果

    #LayoutTree 統合 (layout_integration.mbt)

    LayoutTreeとスケジューラを統合し、レイアウト計算と画像リソースを管理する。

    // レイアウトマネージャ
    let layout_manager = LayoutManager::new(scheduler)
    layout_manager.build_tree_from_html(doc, 800.0, 600.0)

    // レイアウトスケジューリング
    let task_id = layout_manager.schedule_layout()
    let result = layout_manager.execute_layout()

    // 画像リソース管理
    let reg = layout_manager.register_and_decode_image(node_uid)
    layout_manager.on_image_decoded(reg.resource_id, 640.0, 480.0)

    主要な型:
    • LayoutManager - LayoutTreeとスケジューラを統合
    • DocumentRenderCoordinator - HTML/CSS/Layout統合パイプライン
    • LayoutComputeResult - レイアウト計算結果
    • ImageRegistration - 画像登録結果
    • LayoutStats - レイアウト統計

    #統合パイプライン

    HTML Parser → CSS Parser → Style Cascade → Layout Tree ↓ ↓ ↓ ↓ タスク生成 タスク生成 スタイル計算 レイアウト計算 ↓ ↓ ↓ ↓ Scheduler が全てのタスクを管理・依存解決・実行順序決定

    DocumentRenderCoordinator を使うと、これらを統合したパイプラインを簡単に構築できる:

    let coordinator = DocumentRenderCoordinator::new(scheduler)
    let result = coordinator.process_html(
    parse_result, discovered, viewport_width, viewport_height
    )
    // result.style_ready - スタイル計算準備完了か
    // result.layout_task - スケジュールされたレイアウトタスク
    // result.image_decode_tasks - 画像デコードタスク

    #注意事項

    • このモジュールは実際の非同期実行を行わない
    • 外部ランタイムがタスクをポーリングして実行する
    • 依存関係の解決とタスクの状態管理のみを担当

    BlockedSources

    type BlockedSources

    ブロック中のソースを追跡

    CSSParseResult

    pub(all) struct CSSParseResult {
    stylesheet :
    Stylesheet

    recompute_task : TaskId?
    rule_count : Int
    }

    CSS パース結果

    DiscoveredResource

    pub(all) struct DiscoveredResource {
    url : String
    resource_type : ResourceType
    blocking : Bool
    is_defer : Bool
    is_async : Bool
    }

    HTMLパース結果から発見されたリソース

    DocumentParser

    pub struct DocumentParser {
    scheduler : Scheduler
    parsed_root :
    Element
    ?
    discovered : ResourceDiscoveryResult?
    base_url : String
    }

    ドキュメントパーサ - スケジューラと連携してHTMLをパース

    DocumentParser::get_discovered_resources

    fn DocumentParser::get_discovered_resources(self : DocumentParser) -> ResourceDiscoveryResult?

    発見されたリソースを取得

    DocumentParser::get_root

    パース済みのルート要素を取得

    DocumentParser::new

    fn DocumentParser::new(scheduler : Scheduler, base_url? : String) -> DocumentParser

    DocumentParser::on_parse_complete

    fn DocumentParser::on_parse_complete(self : DocumentParser, html : String) -> ParseCompleteResult

    パース完了後の処理 - リソース発見とタスク生成 外部から ParseHTMLChunk タスク完了時に呼ばれる

    DocumentParser::start_parse

    fn DocumentParser::start_parse(self : DocumentParser, html : String) -> TaskId

    HTMLパースタスクを開始

    DocumentRenderCoordinator

    pub struct DocumentRenderCoordinator {
    scheduler : Scheduler
    style_coordinator : DocumentStyleCoordinator
    layout_manager : LayoutManager
    ready_for_render : Bool
    }

    ドキュメントレンダリング調整 - HTML/CSS/Layout を統合

    DocumentRenderCoordinator::get_layout_manager

    レイアウトマネージャへのアクセス

    DocumentRenderCoordinator::get_style_coordinator

    スタイルコーディネータへのアクセス

    DocumentRenderCoordinator::is_ready_for_render

    fn DocumentRenderCoordinator::is_ready_for_render(self : DocumentRenderCoordinator) -> Bool

    レンダリング準備完了か

    DocumentRenderCoordinator::new

    DocumentRenderCoordinator::on_stylesheet_fetched

    fn DocumentRenderCoordinator::on_stylesheet_fetched(self : DocumentRenderCoordinator, css_source : String) -> CSSParseResult

    スタイルシートフェッチ完了時

    DocumentRenderCoordinator::process_html

    fn DocumentRenderCoordinator::process_html(self : DocumentRenderCoordinator, parse_result : ParseCompleteResult, discovered : ResourceDiscoveryResult, viewport_width : Double, viewport_height : Double) -> RenderPipelineResult

    HTMLパース結果を処理して初期レンダリングパイプラインを開始

    DocumentStyleCoordinator

    pub struct DocumentStyleCoordinator {
    scheduler : Scheduler
    style_manager : StyleManager
    parsed_stylesheets : Int
    expected_stylesheets : Int
    ready_for_style : Bool
    }

    HTMLとCSSを統合してスタイル計算をスケジュール

    DocumentStyleCoordinator::get_style_manager

    スタイルマネージャへのアクセス

    DocumentStyleCoordinator::is_ready_for_style

    fn DocumentStyleCoordinator::is_ready_for_style(self : DocumentStyleCoordinator) -> Bool

    スタイル計算の準備ができているか

    DocumentStyleCoordinator::new

    DocumentStyleCoordinator::on_stylesheet_fetched

    fn DocumentStyleCoordinator::on_stylesheet_fetched(self : DocumentStyleCoordinator, css_source : String) -> CSSParseResult

    外部スタイルシートのフェッチ完了時

    DocumentStyleCoordinator::register_stylesheets

    fn DocumentStyleCoordinator::register_stylesheets(self : DocumentStyleCoordinator, parse_result : ParseCompleteResult, discovered : ResourceDiscoveryResult) -> Unit

    HTMLパース結果からスタイルシートを登録

    DocumentStyleCoordinator::schedule_style_computation

    fn DocumentStyleCoordinator::schedule_style_computation(self : DocumentStyleCoordinator, node_ids : Array[String]) -> TaskId

    スタイル計算をスケジュール

    FetchResult

    pub(all) enum FetchResult {
    Success(response~ : NetworkResponse)
    Redirect(location~ : String, status~ : Int)
    Failure(error~ : String)
    } derive(
    Debug
    )

    FetchResource タスクの結果
    impl Show for FetchResult

    HttpMethod

    pub(all) enum HttpMethod {
    GET
    POST
    PUT
    DELETE
    HEAD
    OPTIONS
    PATCH
    } derive(Eq,
    Debug
    )

    HTTP メソッド
    impl Show for HttpMethod

    HttpMethod::from_string

    fn HttpMethod::from_string(s : String) -> HttpMethod

    HttpMethod::to_string

    fn HttpMethod::to_string(self : HttpMethod) -> String

    ImageRegistration

    pub(all) struct ImageRegistration {
    resource_id :
    ResourceId

    decode_task : TaskId
    registered : Bool
    }

    画像登録結果

    InlineScript

    pub(all) struct InlineScript {
    source : String
    blocking : Bool
    }

    インラインスクリプト情報

    InputEvent

    pub(all) enum InputEvent {
    Mouse(MouseEvent)
    Keyboard(KeyboardEvent)
    Text(String)
    } derive(
    Debug
    )

    Input event (mouse or keyboard)
    impl Show for InputEvent

    InputManager

    pub struct InputManager {
    pending_events : Array[InputEvent]
    enabled : Bool
    }

    Input manager for handling input events

    InputManager::disable

    fn InputManager::disable(self : InputManager) -> Unit

    InputManager::enable

    fn InputManager::enable(self : InputManager) -> Unit

    InputManager::new

    InputManager::queue_event

    fn InputManager::queue_event(self : InputManager, event : InputEvent) -> Unit

    InputManager::take_events

    fn InputManager::take_events(self : InputManager) -> Array[InputEvent]

    KeyEventType

    pub(all) enum KeyEventType {
    KeyDown
    KeyUp
    RawKeyDown
    Char
    } derive(Eq,
    Debug
    )

    Keyboard event type

    KeyboardEvent

    pub(all) struct KeyboardEvent {
    event_type : KeyEventType
    key : String
    code : String
    modifiers : Int
    text : String?
    timestamp : Double
    } derive(
    Debug
    )

    Keyboard event data

    KeyboardEvent::new

    fn KeyboardEvent::new(event_type : KeyEventType, key : String) -> KeyboardEvent

    KeyboardEvent::with_code

    fn KeyboardEvent::with_code(self : KeyboardEvent, code : String) -> KeyboardEvent

    KeyboardEvent::with_modifiers

    fn KeyboardEvent::with_modifiers(self : KeyboardEvent, modifiers : Int) -> KeyboardEvent

    KeyboardEvent::with_text

    fn KeyboardEvent::with_text(self : KeyboardEvent, text : String) -> KeyboardEvent

    LayoutComputeResult

    pub(all) struct LayoutComputeResult {
    layout :
    Layout

    was_incremental : Bool
    pending_images : Int
    }

    レイアウト計算結果

    LayoutManager

    pub struct LayoutManager {
    scheduler : Scheduler
    layout_tree :
    LayoutTree
    ?
    last_layout :
    Layout
    ?
    full_layout_count : Int
    incremental_layout_count : Int
    image_tasks : Map[Int, TaskId]
    }

    レイアウト管理 - LayoutTree とスケジューラを統合

    LayoutManager::batch_update_styles

    fn LayoutManager::batch_update_styles(self : LayoutManager, updates : Array[(String,
    CascadedValues
    )]) -> Int

    複数ノードのスタイルを一括更新

    LayoutManager::build_tree

    fn LayoutManager::build_tree(self : LayoutManager, root :
    Node
    , viewport_width : Double, viewport_height : Double) -> Unit

    Node から LayoutTree を構築して設定

    LayoutManager::build_tree_from_html

    fn LayoutManager::build_tree_from_html(self : LayoutManager, doc :
    Document
    , viewport_width : Double, viewport_height : Double) -> Unit

    HTML Document から LayoutTree を構築

    LayoutManager::execute_layout

    fn LayoutManager::execute_layout(self : LayoutManager, incremental? : Bool) -> LayoutComputeResult

    レイアウト計算を実行 (タスク完了時に呼ばれる)

    LayoutManager::get_pending_images

    保留中の画像リソースを取得

    LayoutManager::get_stats

    fn LayoutManager::get_stats(self : LayoutManager) -> LayoutStats

    レイアウト統計を取得

    LayoutManager::get_tree

    LayoutTree への参照を取得

    LayoutManager::mark_node_dirty

    fn LayoutManager::mark_node_dirty(self : LayoutManager, node_uid : Int) -> Unit

    ノードを dirty としてマーク

    LayoutManager::new

    fn LayoutManager::new(scheduler : Scheduler) -> LayoutManager

    LayoutManager::on_image_decoded

    fn LayoutManager::on_image_decoded(self : LayoutManager, resource_id :
    ResourceId
    , width : Double, height : Double) -> TaskId?

    画像デコード完了時の処理

    LayoutManager::on_image_failed

    画像ロード失敗時の処理

    LayoutManager::register_and_decode_image

    fn LayoutManager::register_and_decode_image(self : LayoutManager, node_uid : Int, placeholder_width? : Double, placeholder_height? : Double) -> ImageRegistration

    画像リソースを登録してデコードタスクをスケジュール

    LayoutManager::schedule_image_decode

    fn LayoutManager::schedule_image_decode(self : LayoutManager, resource_id :
    ResourceId
    ) -> TaskId

    画像デコードタスクをスケジュール

    LayoutManager::schedule_layout

    fn LayoutManager::schedule_layout(self : LayoutManager) -> TaskId

    レイアウト計算タスクをスケジュール

    LayoutManager::schedule_layout_after

    fn LayoutManager::schedule_layout_after(self : LayoutManager, dependencies : Array[TaskId]) -> TaskId

    依存タスク完了後にレイアウトをスケジュール

    LayoutManager::schedule_layout_urgent

    fn LayoutManager::schedule_layout_urgent(self : LayoutManager) -> TaskId

    高優先度でレイアウトをスケジュール(ユーザーインタラクション時など)

    LayoutManager::schedule_resize

    fn LayoutManager::schedule_resize(self : LayoutManager, width : Double, height : Double) -> ResizeResult

    ビューポートサイズ変更タスクをスケジュール

    LayoutManager::set_tree

    LayoutTree を設定

    LayoutManager::update_node_style

    fn LayoutManager::update_node_style(self : LayoutManager, node_id : String, values :
    CascadedValues
    ) -> Bool

    ノードのスタイルを更新

    LayoutStats

    pub(all) struct LayoutStats {
    full_layout_count : Int
    incremental_layout_count : Int
    pending_images : Int
    }

    レイアウト統計

    MouseButton

    pub(all) enum MouseButton {
    None
    Left
    Middle
    Right
    Back
    Forward
    } derive(Eq,
    Debug
    )

    Mouse button type
    impl Show for MouseButton

    MouseEvent

    pub(all) struct MouseEvent {
    event_type : MouseEventType
    x : Double
    y : Double
    button : MouseButton
    buttons : Int
    click_count : Int
    modifiers : Int
    timestamp : Double
    } derive(
    Debug
    )

    Mouse event data
    impl Show for MouseEvent

    MouseEvent::new

    fn MouseEvent::new(event_type : MouseEventType, x : Double, y : Double) -> MouseEvent

    MouseEvent::with_button

    fn MouseEvent::with_button(self : MouseEvent, button : MouseButton) -> MouseEvent

    MouseEvent::with_modifiers

    fn MouseEvent::with_modifiers(self : MouseEvent, modifiers : Int) -> MouseEvent

    MouseEventType

    pub(all) enum MouseEventType {
    MousePressed
    MouseReleased
    MouseMoved
    MouseWheel
    } derive(Eq,
    Debug
    )

    Mouse event type

    NetworkEvent

    pub(all) enum NetworkEvent {
    RequestWillBeSent(NetworkRequest)
    ResponseReceived(NetworkResponse)
    LoadingFinished(request_id~ : RequestId, encoded_data_length~ : Int)
    LoadingFailed(request_id~ : RequestId, error~ : String)
    } derive(
    Debug
    )

    ネットワークイベント - CDP Network domain のイベントに対応

    NetworkEvent::request_id

    fn NetworkEvent::request_id(self : NetworkEvent) -> RequestId

    NetworkManager

    pub struct NetworkManager {
    pending_requests : Map[Int, NetworkRequest]
    pending_events : Array[NetworkEvent]
    enabled : Bool
    }

    ネットワークリクエストを管理

    NetworkManager::disable

    fn NetworkManager::disable(self : NetworkManager) -> Unit

    Network を無効化

    NetworkManager::drain_events

    fn NetworkManager::drain_events(self : NetworkManager) -> Array[NetworkEvent]

    pending イベントを取得してクリア

    NetworkManager::enable

    fn NetworkManager::enable(self : NetworkManager) -> Unit

    Network を有効化

    NetworkManager::fail_loading

    fn NetworkManager::fail_loading(self : NetworkManager, request_id : RequestId, error : String) -> Unit

    ロード失敗を記録

    NetworkManager::finish_loading

    fn NetworkManager::finish_loading(self : NetworkManager, request_id : RequestId, encoded_data_length : Int) -> Unit

    ロード完了を記録

    NetworkManager::has_pending_events

    fn NetworkManager::has_pending_events(self : NetworkManager) -> Bool

    pending イベントがあるか

    NetworkManager::new

    NetworkManager::pending_count

    fn NetworkManager::pending_count(self : NetworkManager) -> Int

    進行中のリクエスト数

    NetworkManager::receive_response

    fn NetworkManager::receive_response(self : NetworkManager, response : NetworkResponse) -> Unit

    レスポンス受信を記録

    NetworkManager::start_request

    fn NetworkManager::start_request(self : NetworkManager, request : NetworkRequest) -> Unit

    リクエスト開始を記録

    NetworkRequest

    pub(all) struct NetworkRequest {
    id : RequestId
    url : String
    http_method : HttpMethod
    resource_type : ResourceType
    headers : Map[String, String]
    document_url : String
    frame_id : String
    loader_id : String
    timestamp : Double
    } derive(
    Debug
    )

    ネットワークリクエスト

    NetworkRequest::new

    fn NetworkRequest::new(url : String, resource_type : ResourceType, document_url? : String, frame_id? : String, http_method? : HttpMethod) -> NetworkRequest

    NetworkRequest::with_headers

    fn NetworkRequest::with_headers(self : NetworkRequest, headers : Map[String, String]) -> NetworkRequest

    NetworkRequest::with_loader_id

    fn NetworkRequest::with_loader_id(self : NetworkRequest, loader_id : String) -> NetworkRequest

    NetworkRequest::with_timestamp

    fn NetworkRequest::with_timestamp(self : NetworkRequest, timestamp : Double) -> NetworkRequest

    NetworkResponse

    pub(all) struct NetworkResponse {
    request_id : RequestId
    url : String
    status : Int
    status_text : String
    mime_type : String
    headers : Map[String, String]
    body : String?
    content_length : Int
    timestamp : Double
    loader_id : String
    } derive(
    Debug
    )

    ネットワークレスポンス

    NetworkResponse::new

    fn NetworkResponse::new(request_id : RequestId, url : String, status : Int) -> NetworkResponse

    NetworkResponse::with_body

    fn NetworkResponse::with_body(self : NetworkResponse, body : String) -> NetworkResponse

    NetworkResponse::with_headers

    fn NetworkResponse::with_headers(self : NetworkResponse, headers : Map[String, String]) -> NetworkResponse

    NetworkResponse::with_loader_id

    fn NetworkResponse::with_loader_id(self : NetworkResponse, loader_id : String) -> NetworkResponse

    NetworkResponse::with_mime_type

    fn NetworkResponse::with_mime_type(self : NetworkResponse, mime_type : String) -> NetworkResponse

    NetworkResponse::with_timestamp

    fn NetworkResponse::with_timestamp(self : NetworkResponse, timestamp : Double) -> NetworkResponse

    ParseCompleteResult

    pub(all) struct ParseCompleteResult {
    root :
    Element

    fetch_tasks : Array[TaskId]
    style_tasks : Array[TaskId]
    script_tasks : Array[TaskId]
    blocking_tasks : Array[TaskId]
    resource_count : Int
    inline_style_count : Int
    inline_script_count : Int
    }

    パース完了時の結果

    RenderPipelineResult

    pub(all) struct RenderPipelineResult {
    style_ready : Bool
    layout_task : TaskId?
    image_decode_tasks : Array[TaskId]
    }

    レンダリングパイプライン結果

    RequestId

    pub(all) struct RequestId(Int) derive(Eq, Hash,
    Debug
    )

    ネットワークリクエストの一意識別子
    impl Show for RequestId

    RequestId::next

    fn RequestId::next() -> RequestId

    ResizeResult

    pub(all) struct ResizeResult {
    resized : Bool
    layout_task : TaskId?
    }

    ビューポートリサイズ結果

    ResourceDiscoveryResult

    pub(all) struct ResourceDiscoveryResult {
    resources : Array[DiscoveredResource]
    inline_styles : Array[String]
    inline_scripts : Array[InlineScript]
    }

    リソース発見結果

    ResourceDiscoveryResult::filter_by_type

    特定タイプのリソースをフィルタ

    ResourceDiscoveryResult::get_blocking

    blocking リソースのみ取得

    ResourceDiscoveryResult::get_urls

    fn ResourceDiscoveryResult::get_urls(self : ResourceDiscoveryResult) -> Array[String]

    発見されたリソースのURLリストを取得

    ResourceDiscoveryResult::new

    ResourceType

    pub(all) enum ResourceType {
    Document
    Stylesheet
    Script
    Image
    Font
    Other
    } derive(Eq,
    Debug
    )

    リソースの種類

    Scheduler

    pub struct Scheduler {
    tasks : Map[Int, Task]
    ready_queue : TaskQueue
    source_queues : SourceQueueManager
    blocked : BlockedSources
    completed_ids :
    HashSet
    [Int]
    }

    スケジューラ本体

    Scheduler::apply_blocks

    fn Scheduler::apply_blocks(self : Scheduler, task : Task) -> Unit

    タスクの Blocking 制約を適用

    Scheduler::cancel

    fn Scheduler::cancel(self : Scheduler, task_id : TaskId) -> Unit

    タスクキャンセルを通知(ショートカット)

    Scheduler::cleanup

    fn Scheduler::cleanup(self : Scheduler) -> Int

    完了したタスクをクリーンアップ

    Scheduler::complete

    fn Scheduler::complete(self : Scheduler, task_id : TaskId, result : TaskResult) -> Array[TaskId]

    タスク完了を通知(成功)

    Scheduler::enqueue

    fn Scheduler::enqueue(self : Scheduler, action : TaskAction, constraint : TaskConstraint) -> TaskId

    タスクを追加

    Scheduler::enqueue_after

    fn Scheduler::enqueue_after(self : Scheduler, action : TaskAction, constraint : TaskConstraint, dependencies : Array[TaskId]) -> TaskId

    依存関係付きでタスクを追加

    Scheduler::enqueue_with_priority

    fn Scheduler::enqueue_with_priority(self : Scheduler, action : TaskAction, constraint : TaskConstraint, priority : Int) -> TaskId

    優先度付きでタスクを追加

    Scheduler::fail

    fn Scheduler::fail(self : Scheduler, task_id : TaskId, error : String) -> Unit

    タスク失敗を通知(ショートカット)

    Scheduler::find_task

    fn Scheduler::find_task(self : Scheduler, task_id : TaskId) -> Task?

    タスクを検索

    Scheduler::is_idle

    fn Scheduler::is_idle(self : Scheduler) -> Bool

    すべての処理が完了したか確認

    Scheduler::is_source_blocked

    fn Scheduler::is_source_blocked(self : Scheduler, source : TaskSource) -> Bool

    特定のソースがブロックされているか確認

    Scheduler::new

    fn Scheduler::new() -> Scheduler

    Scheduler::pending_count

    fn Scheduler::pending_count(self : Scheduler) -> Int

    Pending 状態のタスク数を取得

    Scheduler::poll_main_thread

    fn Scheduler::poll_main_thread(self : Scheduler) -> Task?

    メインスレッド専用タスクのみ取得(1つずつ)

    Scheduler::poll_parallel

    fn Scheduler::poll_parallel(self : Scheduler) -> Array[Task]

    並列実行可能なタスクのみ取得

    Scheduler::poll_ready

    fn Scheduler::poll_ready(self : Scheduler) -> Array[Task]

    実行可能なタスクをすべて取得(状態を Running に変更)

    Scheduler::ready_count

    fn Scheduler::ready_count(self : Scheduler) -> Int

    Ready 状態のタスク数を取得

    Scheduler::resolve_dependencies

    fn Scheduler::resolve_dependencies(self : Scheduler) -> Int

    依存関係を解決して Ready 状態に昇格

    Scheduler::running_count

    fn Scheduler::running_count(self : Scheduler) -> Int

    Running 状態のタスク数を取得

    Scheduler::task_count

    fn Scheduler::task_count(self : Scheduler) -> Int

    全タスク数を取得

    SourceQueueManager

    pub struct SourceQueueManager {
    queues : Map[TaskSource, TaskQueue]
    }

    ソース別にキューを管理

    SourceQueueManager::cleanup

    fn SourceQueueManager::cleanup(self : SourceQueueManager) -> Int

    Cleanup all queues

    SourceQueueManager::find

    fn SourceQueueManager::find(self : SourceQueueManager, task_id : TaskId) -> Task?

    Find task by ID across all queues

    SourceQueueManager::get_all_ready

    fn SourceQueueManager::get_all_ready(self : SourceQueueManager) -> Array[Task]

    Get all ready tasks from all queues

    SourceQueueManager::get_queue

    fn SourceQueueManager::get_queue(self : SourceQueueManager, source : TaskSource) -> TaskQueue

    Get queue for a specific source

    SourceQueueManager::get_ready_by_source

    fn SourceQueueManager::get_ready_by_source(self : SourceQueueManager, source : TaskSource) -> Array[Task]

    Get ready tasks from a specific source

    SourceQueueManager::new

    SourceQueueManager::push

    fn SourceQueueManager::push(self : SourceQueueManager, task : Task) -> Unit

    Add task to appropriate source queue

    SourceQueueManager::remove

    fn SourceQueueManager::remove(self : SourceQueueManager, task_id : TaskId) -> Task?

    Remove task by ID from appropriate queue

    SourceQueueManager::total_count

    fn SourceQueueManager::total_count(self : SourceQueueManager) -> Int

    Get total task count across all queues

    StyleManager

    pub struct StyleManager {
    scheduler : Scheduler
    stylesheets : Array[
    Stylesheet
    ]
    inline_styles : Map[String, Array[
    Declaration
    ]]
    computed_styles : Map[String,
    CascadedValues
    ]
    source_order : Int
    }

    スタイル管理 - スタイルシートとカスケード計算を管理

    StyleManager::add_inline_style

    fn StyleManager::add_inline_style(self : StyleManager, element_id : String, style_text : String) -> Unit

    インラインスタイルを追加

    StyleManager::add_stylesheet

    fn StyleManager::add_stylesheet(self : StyleManager, stylesheet :
    Stylesheet
    ) -> Unit

    パース済みスタイルシートを追加

    StyleManager::add_stylesheet_source

    fn StyleManager::add_stylesheet_source(self : StyleManager, source : String) ->
    Stylesheet

    CSSソースからスタイルシートをパースして追加

    StyleManager::compute_style

    要素のスタイルを計算

    StyleManager::invalidate_all_styles

    fn StyleManager::invalidate_all_styles(self : StyleManager) -> Unit

    全スタイルキャッシュを無効化

    StyleManager::invalidate_style

    fn StyleManager::invalidate_style(self : StyleManager, element_id : String) -> Unit

    特定要素のスタイルを無効化

    StyleManager::new

    fn StyleManager::new(scheduler : Scheduler) -> StyleManager

    StyleManager::on_css_parsed

    fn StyleManager::on_css_parsed(self : StyleManager, source : String) -> CSSParseResult

    CSSパースタスク完了時の処理

    StyleManager::schedule_compute_style

    fn StyleManager::schedule_compute_style(self : StyleManager, node_ids : Array[String]) -> TaskId

    スタイル計算タスクを開始

    StyleManager::schedule_parse_css

    fn StyleManager::schedule_parse_css(self : StyleManager, source : String) -> TaskId

    CSSパースタスクを開始

    Task

    pub(all) struct Task {
    id : TaskId
    source : TaskSource
    constraint : TaskConstraint
    dependencies : Array[TaskId]
    action : TaskAction
    state : TaskState
    priority : Int
    }

    タスク本体

    Task::is_completed

    fn Task::is_completed(self : Task) -> Bool

    Task::is_parallel

    fn Task::is_parallel(self : Task) -> Bool

    Task::is_ready

    fn Task::is_ready(self : Task) -> Bool

    Task::is_terminal

    fn Task::is_terminal(self : Task) -> Bool

    Task::mark_cancelled

    fn Task::mark_cancelled(self : Task) -> Unit

    Task::mark_completed

    fn Task::mark_completed(self : Task) -> Unit

    Task::mark_failed

    fn Task::mark_failed(self : Task, error : String) -> Unit

    Task::mark_running

    fn Task::mark_running(self : Task) -> Unit

    Task::new

    fn Task::new(action : TaskAction, constraint : TaskConstraint, dependencies? : Array[TaskId], priority? : Int) -> Task

    TaskAction

    pub(all) enum TaskAction {
    ParseHTMLChunk(html~ : String)
    ParseCSS(source~ : String)
    ComputeStyle(node_ids~ : Array[String])
    ComputeLayout
    FetchResource(url~ : String, resource_type~ : ResourceType)
    DecodeImage(resource_id~ : Int)
    ExecuteScript(source~ : String)
    } derive(
    Debug
    )

    タスクの実行内容
    impl Show for TaskAction

    TaskAction::is_internal

    fn TaskAction::is_internal(self : TaskAction) -> Bool

    Check if action can be executed internally (synchronously)

    TaskAction::source

    fn TaskAction::source(self : TaskAction) -> TaskSource

    Get the task source for this action

    TaskConstraint

    pub(all) enum TaskConstraint {
    MainThreadOnly
    Parallel
    Blocking(Array[TaskSource])
    } derive(
    Debug
    )

    タスクの実行制約

    TaskConstraint::blocks

    fn TaskConstraint::blocks(self : TaskConstraint, source : TaskSource) -> Bool

    Check if a task blocks a specific source

    TaskConstraint::is_parallel

    fn TaskConstraint::is_parallel(self : TaskConstraint) -> Bool

    Check if a task can run in parallel

    TaskId

    pub(all) struct TaskId(Int) derive(Eq, Hash,
    Debug
    )

    Unique task identifier
    impl Show for TaskId

    TaskQueue

    pub struct TaskQueue {
    tasks : Array[Task]
    }

    基本的なタスクキュー

    TaskQueue::cleanup

    fn TaskQueue::cleanup(self : TaskQueue) -> Int

    Remove all completed/cancelled/failed tasks

    TaskQueue::find

    fn TaskQueue::find(self : TaskQueue, task_id : TaskId) -> Task?

    Find a task by ID

    TaskQueue::get_main_thread_ready

    fn TaskQueue::get_main_thread_ready(self : TaskQueue) -> Array[Task]

    Get all main-thread-only ready tasks

    TaskQueue::get_parallel_ready

    fn TaskQueue::get_parallel_ready(self : TaskQueue) -> Array[Task]

    Get all parallel-capable ready tasks

    TaskQueue::get_ready

    fn TaskQueue::get_ready(self : TaskQueue) -> Array[Task]

    Get all ready tasks (does not remove them)

    TaskQueue::is_empty

    fn TaskQueue::is_empty(self : TaskQueue) -> Bool

    Check if the queue is empty

    TaskQueue::iter

    fn TaskQueue::iter(self : TaskQueue) -> Iter[Task]

    Get all tasks (for iteration)

    TaskQueue::length

    fn TaskQueue::length(self : TaskQueue) -> Int

    Get the number of tasks in the queue

    TaskQueue::new

    fn TaskQueue::new() -> TaskQueue

    TaskQueue::push

    fn TaskQueue::push(self : TaskQueue, task : Task) -> Unit

    Add a task to the queue

    TaskQueue::remove

    fn TaskQueue::remove(self : TaskQueue, task_id : TaskId) -> Task?

    Remove a task by ID

    TaskQueue::sort_by_priority

    fn TaskQueue::sort_by_priority(self : TaskQueue) -> Unit

    Sort by priority (higher priority first)

    TaskResult

    pub(all) enum TaskResult {
    Success(new_tasks~ : Array[TaskAction])
    Failure(error~ : String)
    Cancelled
    } derive(
    Debug
    )

    タスクの実行結果
    impl Show for TaskResult

    TaskSource

    pub(all) enum TaskSource {
    DOM
    Styling
    Layout
    Networking
    Scripting
    ImageDecode
    } derive(Eq, Hash,
    Debug
    )

    タスクの発生源
    impl Show for TaskSource

    TaskState

    pub(all) enum TaskState {
    Pending
    Ready
    Running
    Completed
    Cancelled
    Failed(String)
    } derive(
    Debug
    )

    タスクの状態
    impl Show for TaskState

    TaskState::is_runnable

    fn TaskState::is_runnable(self : TaskState) -> Bool

    TaskState::is_terminal

    fn TaskState::is_terminal(self : TaskState) -> Bool

    compute_element_style

    HTMLElementのスタイルを計算

    discover_resources

    Elementからリソースを発見

    has_alt

    fn has_alt(modifiers : Int) -> Bool

    Check if Alt modifier is set

    has_ctrl

    fn has_ctrl(modifiers : Int) -> Bool

    Check if Ctrl modifier is set

    has_meta

    fn has_meta(modifiers : Int) -> Bool

    Check if Meta modifier is set

    has_shift

    fn has_shift(modifiers : Int) -> Bool

    Check if Shift modifier is set

    html_element_to_selector

    HTMLElementからselector.Elementに変換

    parse_and_schedule

    fn parse_and_schedule(scheduler : Scheduler, html : String, base_url? : String) -> ParseCompleteResult

    HTMLを解析してすべてのタスクを生成する便利関数

    reset_request_id_counter

    fn reset_request_id_counter() -> Unit

    Reset request ID counter (for testing)

    reset_task_id_counter

    fn reset_task_id_counter() -> Unit

    Reset task ID counter (for testing)