Skip to content

Commit

Permalink
Auto merge of #15939 - Manishearth:stylo-content-counter, r=heycam
Browse files Browse the repository at this point in the history
stylo: support all content values

r=heycam

https://bugzilla.mozilla.org/show_bug.cgi?id=1296477

<!-- 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/15939)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo committed Mar 14, 2017
2 parents 808ffff + 2ae317f commit 628cd7d
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 86 deletions.
2 changes: 2 additions & 0 deletions components/style/build_gecko.rs
Expand Up @@ -574,6 +574,8 @@ mod bindings {
"nsStyleColor",
"nsStyleColumn",
"nsStyleContent",
"nsStyleContentData",
"nsStyleContentType",
"nsStyleContext",
"nsStyleCoord",
"nsStyleCoord_Calc",
Expand Down
27 changes: 9 additions & 18 deletions components/style/gecko/conversions.rs
Expand Up @@ -106,26 +106,17 @@ impl nsStyleImage {
self.set_gradient(gradient)
},
Image::Url(ref url) if with_url => {
let (ptr, len) = match url.as_slice_components() {
Ok(value) | Err(value) => value
};
let extra_data = url.extra_data();
unsafe {
Gecko_SetUrlImageValue(self,
ptr,
len as u32,
extra_data.base.get(),
extra_data.referrer.get(),
extra_data.principal.get());
Gecko_SetUrlImageValue(self, url.for_ffi());
// We unfortunately must make any url() value uncacheable, since
// the applicable declarations cache is not per document, but
// global, and the imgRequestProxy objects we store in the style
// structs don't like to be tracked by more than one document.
//
// FIXME(emilio): With the scoped TLS thing this is no longer
// true, remove this line in a follow-up!
*cacheable = false;
}
// We unfortunately must make any url() value uncacheable, since
// the applicable declarations cache is not per document, but
// global, and the imgRequestProxy objects we store in the style
// structs don't like to be tracked by more than one document.
//
// FIXME(emilio): With the scoped TLS thing this is no longer
// true, remove this line in a follow-up!
*cacheable = false;
},
_ => (),
}
Expand Down
46 changes: 37 additions & 9 deletions components/style/gecko_bindings/bindings.rs
Expand Up @@ -56,6 +56,12 @@ unsafe impl Sync for nsStyleColumn {}
use gecko_bindings::structs::nsStyleContent;
unsafe impl Send for nsStyleContent {}
unsafe impl Sync for nsStyleContent {}
use gecko_bindings::structs::nsStyleContentData;
unsafe impl Send for nsStyleContentData {}
unsafe impl Sync for nsStyleContentData {}
use gecko_bindings::structs::nsStyleContentType;
unsafe impl Send for nsStyleContentType {}
unsafe impl Sync for nsStyleContentType {}
use gecko_bindings::structs::nsStyleContext;
unsafe impl Send for nsStyleContext {}
unsafe impl Sync for nsStyleContext {}
Expand Down Expand Up @@ -631,10 +637,7 @@ extern "C" {
}
extern "C" {
pub fn Gecko_SetUrlImageValue(image: *mut nsStyleImage,
url_bytes: *const u8, url_length: u32,
base_uri: *mut ThreadSafeURIHolder,
referrer: *mut ThreadSafeURIHolder,
principal: *mut ThreadSafePrincipalHolder);
uri: ServoBundledURI);
}
extern "C" {
pub fn Gecko_CopyImageValueFrom(image: *mut nsStyleImage,
Expand Down Expand Up @@ -662,15 +665,20 @@ extern "C" {
}
extern "C" {
pub fn Gecko_SetCursorImage(cursor: *mut nsCursorImage,
string_bytes: *const u8, string_length: u32,
base_uri: *mut ThreadSafeURIHolder,
referrer: *mut ThreadSafeURIHolder,
principal: *mut ThreadSafePrincipalHolder);
uri: ServoBundledURI);
}
extern "C" {
pub fn Gecko_CopyCursorArrayFrom(dest: *mut nsStyleUserInterface,
src: *const nsStyleUserInterface);
}
extern "C" {
pub fn Gecko_SetContentDataImage(content_data: *mut nsStyleContentData,
uri: ServoBundledURI);
}
extern "C" {
pub fn Gecko_SetContentDataArray(content_data: *mut nsStyleContentData,
type_: nsStyleContentType, len: u32);
}
extern "C" {
pub fn Gecko_GetNodeFlags(node: RawGeckoNodeBorrowed) -> u32;
}
Expand Down Expand Up @@ -709,10 +717,26 @@ extern "C" {
pub fn Gecko_ClearAndResizeStyleContents(content: *mut nsStyleContent,
how_many: u32);
}
extern "C" {
pub fn Gecko_ClearAndResizeCounterIncrements(content: *mut nsStyleContent,
how_many: u32);
}
extern "C" {
pub fn Gecko_ClearAndResizeCounterResets(content: *mut nsStyleContent,
how_many: u32);
}
extern "C" {
pub fn Gecko_CopyStyleContentsFrom(content: *mut nsStyleContent,
other: *const nsStyleContent);
}
extern "C" {
pub fn Gecko_CopyCounterResetsFrom(content: *mut nsStyleContent,
other: *const nsStyleContent);
}
extern "C" {
pub fn Gecko_CopyCounterIncrementsFrom(content: *mut nsStyleContent,
other: *const nsStyleContent);
}
extern "C" {
pub fn Gecko_EnsureImageLayersLength(layers: *mut nsStyleImageLayers,
len: usize,
Expand Down Expand Up @@ -898,7 +922,11 @@ extern "C" {
}
extern "C" {
pub fn Gecko_CSSValue_SetString(css_value: nsCSSValueBorrowedMut,
string: nsString);
string: *const u8, len: u32);
}
extern "C" {
pub fn Gecko_CSSValue_SetIdent(css_value: nsCSSValueBorrowedMut,
string: *const u8, len: u32);
}
extern "C" {
pub fn Gecko_CSSValue_SetArray(css_value: nsCSSValueBorrowedMut,
Expand Down
61 changes: 45 additions & 16 deletions components/style/gecko_bindings/sugar/ns_css_value.rs
Expand Up @@ -5,18 +5,13 @@
//! Little helpers for `nsCSSValue`.

use app_units::Au;
use gecko_bindings::bindings::Gecko_CSSValue_Drop;
use gecko_bindings::bindings::Gecko_CSSValue_GetAbsoluteLength;
use gecko_bindings::bindings::Gecko_CSSValue_GetCalc;
use gecko_bindings::bindings::Gecko_CSSValue_GetPercentage;
use gecko_bindings::bindings::Gecko_CSSValue_SetAbsoluteLength;
use gecko_bindings::bindings::Gecko_CSSValue_SetCalc;
use gecko_bindings::bindings::Gecko_CSSValue_SetPercentage;
use gecko_bindings::bindings;
use gecko_bindings::structs::{nsCSSValue, nsCSSUnit, nsCSSValue_Array, nscolor};
use std::mem;
use std::ops::Index;
use std::ops::{Index, IndexMut};
use std::slice;
use values::computed::LengthOrPercentage;
use values::specified::url::SpecifiedUrl;

impl nsCSSValue {
/// Create a CSSValue with null unit, useful to be used as a return value.
Expand Down Expand Up @@ -77,13 +72,13 @@ impl nsCSSValue {
pub unsafe fn set_lop(&mut self, lop: LengthOrPercentage) {
match lop {
LengthOrPercentage::Length(au) => {
Gecko_CSSValue_SetAbsoluteLength(self, au.0)
bindings::Gecko_CSSValue_SetAbsoluteLength(self, au.0)
}
LengthOrPercentage::Percentage(pc) => {
Gecko_CSSValue_SetPercentage(self, pc)
bindings::Gecko_CSSValue_SetPercentage(self, pc)
}
LengthOrPercentage::Calc(calc) => {
Gecko_CSSValue_SetCalc(self, calc.into())
bindings::Gecko_CSSValue_SetCalc(self, calc.into())
}
}
}
Expand All @@ -92,27 +87,47 @@ impl nsCSSValue {
pub unsafe fn get_lop(&self) -> LengthOrPercentage {
match self.mUnit {
nsCSSUnit::eCSSUnit_Pixel => {
LengthOrPercentage::Length(Au(Gecko_CSSValue_GetAbsoluteLength(self)))
LengthOrPercentage::Length(Au(bindings::Gecko_CSSValue_GetAbsoluteLength(self)))
},
nsCSSUnit::eCSSUnit_Percent => {
LengthOrPercentage::Percentage(Gecko_CSSValue_GetPercentage(self))
LengthOrPercentage::Percentage(bindings::Gecko_CSSValue_GetPercentage(self))
},
nsCSSUnit::eCSSUnit_Calc => {
LengthOrPercentage::Calc(Gecko_CSSValue_GetCalc(self).into())
LengthOrPercentage::Calc(bindings::Gecko_CSSValue_GetCalc(self).into())
},
x => panic!("The unit should not be {:?}", x),
}
}

/// Set to a string value
pub fn set_string(&mut self, s: &str) {
unsafe { bindings::Gecko_CSSValue_SetString(self, s.as_ptr(), s.len() as u32) }
}

/// Set to an identifier value
pub fn set_ident(&mut self, s: &str) {
unsafe { bindings::Gecko_CSSValue_SetIdent(self, s.as_ptr(), s.len() as u32) }
}

/// Set to a url value
pub fn set_url(&mut self, url: &SpecifiedUrl) {
unsafe { bindings::Gecko_CSSValue_SetURL(self, url.for_ffi()) }
}

/// Set to an array of given length
pub fn set_array(&mut self, len: i32) {
unsafe { bindings::Gecko_CSSValue_SetArray(self, len) }
}
}

impl Drop for nsCSSValue {
fn drop(&mut self) {
unsafe { Gecko_CSSValue_Drop(self) };
unsafe { bindings::Gecko_CSSValue_Drop(self) };
}
}

impl nsCSSValue_Array {
/// Return the length of this `nsCSSShadowArray`
/// Return the length of this `nsCSSValue::Array`
#[inline]
pub fn len(&self) -> usize {
self.mCount
Expand All @@ -128,6 +143,12 @@ impl nsCSSValue_Array {
pub fn as_slice(&self) -> &[nsCSSValue] {
unsafe { slice::from_raw_parts(self.buffer(), self.len()) }
}

/// Get the array as a mutable slice of nsCSSValues.
#[inline]
pub fn as_mut_slice(&mut self) -> &mut [nsCSSValue] {
unsafe { slice::from_raw_parts_mut(self.buffer() as *mut _, self.len()) }
}
}

impl Index<usize> for nsCSSValue_Array {
Expand All @@ -137,3 +158,11 @@ impl Index<usize> for nsCSSValue_Array {
&self.as_slice()[i]
}
}

impl IndexMut<usize> for nsCSSValue_Array {
#[inline]
fn index_mut(&mut self, i: usize) -> &mut nsCSSValue {
&mut self.as_mut_slice()[i]
}
}

0 comments on commit 628cd7d

Please sign in to comment.