aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout_2020/wrapper.rs
blob: 635889dc92ea3996fbe6e6ca3a859d5b2ba57e1f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

#![allow(unsafe_code)]

use crate::data::StyleAndLayoutData;
use script_layout_interface::wrapper_traits::GetStyleAndOpaqueLayoutData;

pub trait GetStyleAndLayoutData<'dom> {
    fn get_style_and_layout_data(self) -> Option<StyleAndLayoutData<'dom>>;
}

impl<'dom, T> GetStyleAndLayoutData<'dom> for T
where
    T: GetStyleAndOpaqueLayoutData<'dom>,
{
    fn get_style_and_layout_data(self) -> Option<StyleAndLayoutData<'dom>> {
        self.get_style_and_opaque_layout_data()
            .map(|data| StyleAndLayoutData {
                style_data: &data.style_data,
                layout_data: data.generic_data.downcast_ref().unwrap(),
            })
    }
}