Auto merge of #18085 - dadaa:make-content-animatable, r=hiro

Make content animatable

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors

<!-- Either: -->
- [X] There are tests for these changes. The test codes are patch part 3 and 4 in https://bugzilla.mozilla.org/show_bug.cgi?id=1382136

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18085)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-08-15 05:50:15 -05:00 committed by GitHub
commit 41fb10c589
4 changed files with 94 additions and 16 deletions

View file

@ -919,3 +919,16 @@ impl<T> Rect<T> where T: GeckoStyleCoordConvertible {
)
}
}
/// Convert to String from given chars pointer.
pub unsafe fn string_from_chars_pointer(p: *const u16) -> String {
use std::slice;
let mut length = 0;
let mut iter = p;
while *iter != 0 {
length += 1;
iter = iter.offset(1);
}
let char_vec = slice::from_raw_parts(p, length as usize);
String::from_utf16_lossy(char_vec)
}

View file

@ -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))
}