mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Implement clone_content method
This commit is contained in:
parent
e0b834033d
commit
c05baa2327
3 changed files with 93 additions and 15 deletions
|
@ -14,7 +14,7 @@ use font_metrics::get_metrics_provider_for_product;
|
|||
use gecko::values::convert_nscolor_to_rgba;
|
||||
use gecko_bindings::bindings;
|
||||
use gecko_bindings::structs;
|
||||
use gecko_bindings::structs::{nsCSSKeyword, nsCSSProps_KTableEntry, nsCSSValue, nsCSSUnit, nsStringBuffer};
|
||||
use gecko_bindings::structs::{nsCSSKeyword, nsCSSProps_KTableEntry, nsCSSValue, nsCSSUnit};
|
||||
use gecko_bindings::structs::{nsMediaExpression_Range, nsMediaFeature};
|
||||
use gecko_bindings::structs::{nsMediaFeature_ValueType, nsMediaFeature_RangeType, nsMediaFeature_RequirementFlags};
|
||||
use gecko_bindings::structs::{nsPresContext, RawGeckoPresContextOwned};
|
||||
|
@ -294,19 +294,6 @@ impl ToCss for Resolution {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe fn string_from_ns_string_buffer(buffer: *const nsStringBuffer) -> String {
|
||||
use std::slice;
|
||||
debug_assert!(!buffer.is_null());
|
||||
let data = buffer.offset(1) as *const u16;
|
||||
let mut length = 0;
|
||||
let mut iter = data;
|
||||
while *iter != 0 {
|
||||
length += 1;
|
||||
iter = iter.offset(1);
|
||||
}
|
||||
String::from_utf16_lossy(slice::from_raw_parts(data, length))
|
||||
}
|
||||
|
||||
/// A value found or expected in a media expression.
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
pub enum MediaExpressionValue {
|
||||
|
@ -334,6 +321,8 @@ pub enum MediaExpressionValue {
|
|||
|
||||
impl MediaExpressionValue {
|
||||
fn from_css_value(for_expr: &Expression, css_value: &nsCSSValue) -> Option<Self> {
|
||||
use gecko::conversions::string_from_chars_pointer;
|
||||
|
||||
// NB: If there's a null value, that means that we don't support the
|
||||
// feature.
|
||||
if css_value.mUnit == nsCSSUnit::eCSSUnit_Null {
|
||||
|
@ -372,7 +361,9 @@ impl MediaExpressionValue {
|
|||
nsMediaFeature_ValueType::eIdent => {
|
||||
debug_assert!(css_value.mUnit == nsCSSUnit::eCSSUnit_Ident);
|
||||
let string = unsafe {
|
||||
string_from_ns_string_buffer(*css_value.mValue.mString.as_ref())
|
||||
let buffer = *css_value.mValue.mString.as_ref();
|
||||
debug_assert!(!buffer.is_null());
|
||||
string_from_chars_pointer(buffer.offset(1) as *const u16)
|
||||
};
|
||||
Some(MediaExpressionValue::Ident(string))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue