tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

conversions.rs (1979B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
      4 
      5 //! This module contains conversion helpers between Servo and Gecko types
      6 //! Ideally, it would be in geckolib itself, but coherence
      7 //! forces us to keep the traits and implementations here
      8 //!
      9 //! FIXME(emilio): This file should generally just die.
     10 
     11 #![allow(unsafe_code)]
     12 
     13 use crate::gecko_bindings::structs::{nsresult, Matrix4x4Components};
     14 use crate::stylesheets::RulesMutateError;
     15 use crate::values::computed::transform::Matrix3D;
     16 
     17 impl From<RulesMutateError> for nsresult {
     18    fn from(other: RulesMutateError) -> Self {
     19        match other {
     20            RulesMutateError::Syntax => nsresult::NS_ERROR_DOM_SYNTAX_ERR,
     21            RulesMutateError::IndexSize => nsresult::NS_ERROR_DOM_INDEX_SIZE_ERR,
     22            RulesMutateError::HierarchyRequest => nsresult::NS_ERROR_DOM_HIERARCHY_REQUEST_ERR,
     23            RulesMutateError::InvalidState => nsresult::NS_ERROR_DOM_INVALID_STATE_ERR,
     24        }
     25    }
     26 }
     27 
     28 impl<'a> From<&'a Matrix4x4Components> for Matrix3D {
     29    fn from(m: &'a Matrix4x4Components) -> Matrix3D {
     30        Matrix3D {
     31            m11: m[0],
     32            m12: m[1],
     33            m13: m[2],
     34            m14: m[3],
     35            m21: m[4],
     36            m22: m[5],
     37            m23: m[6],
     38            m24: m[7],
     39            m31: m[8],
     40            m32: m[9],
     41            m33: m[10],
     42            m34: m[11],
     43            m41: m[12],
     44            m42: m[13],
     45            m43: m[14],
     46            m44: m[15],
     47        }
     48    }
     49 }
     50 
     51 impl From<Matrix3D> for Matrix4x4Components {
     52    fn from(matrix: Matrix3D) -> Self {
     53        [
     54            matrix.m11, matrix.m12, matrix.m13, matrix.m14, matrix.m21, matrix.m22, matrix.m23,
     55            matrix.m24, matrix.m31, matrix.m32, matrix.m33, matrix.m34, matrix.m41, matrix.m42,
     56            matrix.m43, matrix.m44,
     57        ]
     58    }
     59 }