mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Auto merge of #13086 - Manishearth:shadowarray, r=emilio
Add bindings for nsCSSShadowArray, use for text-shadow and box-shadow <!-- 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/13086) <!-- Reviewable:end -->
This commit is contained in:
commit
fb9c36c833
7 changed files with 172 additions and 8 deletions
|
@ -1210,13 +1210,107 @@ fn static_assert() {
|
||||||
|
|
||||||
</%self:impl_trait>
|
</%self:impl_trait>
|
||||||
|
|
||||||
|
<%self:impl_trait style_struct_name="Effects"
|
||||||
|
skip_longhands="box-shadow">
|
||||||
|
pub fn set_box_shadow(&mut self, v: longhands::box_shadow::computed_value::T) {
|
||||||
|
use cssparser::Color;
|
||||||
|
|
||||||
|
self.gecko.mBoxShadow.replace_with_new(v.0.len() as u32);
|
||||||
|
|
||||||
|
for (servo, gecko_shadow) in v.0.into_iter()
|
||||||
|
.zip(self.gecko.mBoxShadow.iter_mut()) {
|
||||||
|
|
||||||
|
gecko_shadow.mXOffset = servo.offset_x.0;
|
||||||
|
gecko_shadow.mYOffset = servo.offset_y.0;
|
||||||
|
gecko_shadow.mRadius = servo.blur_radius.0;
|
||||||
|
gecko_shadow.mSpread = servo.spread_radius.0;
|
||||||
|
gecko_shadow.mSpread = servo.spread_radius.0;
|
||||||
|
gecko_shadow.mInset = servo.inset;
|
||||||
|
gecko_shadow.mColor = match servo.color {
|
||||||
|
Color::RGBA(rgba) => {
|
||||||
|
gecko_shadow.mHasColor = true;
|
||||||
|
convert_rgba_to_nscolor(&rgba)
|
||||||
|
},
|
||||||
|
// TODO handle currentColor
|
||||||
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=760345
|
||||||
|
Color::CurrentColor => 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn copy_box_shadow_from(&mut self, other: &Self) {
|
||||||
|
self.gecko.mBoxShadow.copy_from(&other.gecko.mBoxShadow);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clone_box_shadow(&self) -> longhands::box_shadow::computed_value::T {
|
||||||
|
use cssparser::Color;
|
||||||
|
|
||||||
|
let buf = self.gecko.mBoxShadow.iter().map(|shadow| {
|
||||||
|
longhands::box_shadow::single_value::computed_value::T {
|
||||||
|
offset_x: Au(shadow.mXOffset),
|
||||||
|
offset_y: Au(shadow.mYOffset),
|
||||||
|
blur_radius: Au(shadow.mRadius),
|
||||||
|
spread_radius: Au(shadow.mSpread),
|
||||||
|
inset: shadow.mInset,
|
||||||
|
color: Color::RGBA(convert_nscolor_to_rgba(shadow.mColor)),
|
||||||
|
}
|
||||||
|
}).collect();
|
||||||
|
longhands::box_shadow::computed_value::T(buf)
|
||||||
|
}
|
||||||
|
</%self:impl_trait>
|
||||||
|
|
||||||
|
|
||||||
<%self:impl_trait style_struct_name="InheritedText"
|
<%self:impl_trait style_struct_name="InheritedText"
|
||||||
skip_longhands="text-align line-height word-spacing">
|
skip_longhands="text-align text-shadow line-height word-spacing">
|
||||||
|
|
||||||
<% text_align_keyword = Keyword("text-align", "start end left right center justify -moz-center -moz-left " +
|
<% text_align_keyword = Keyword("text-align", "start end left right center justify -moz-center -moz-left " +
|
||||||
"-moz-right match-parent") %>
|
"-moz-right match-parent") %>
|
||||||
${impl_keyword('text_align', 'mTextAlign', text_align_keyword, need_clone=False)}
|
${impl_keyword('text_align', 'mTextAlign', text_align_keyword, need_clone=False)}
|
||||||
|
|
||||||
|
pub fn set_text_shadow(&mut self, v: longhands::text_shadow::computed_value::T) {
|
||||||
|
use cssparser::Color;
|
||||||
|
self.gecko.mTextShadow.replace_with_new(v.0.len() as u32);
|
||||||
|
|
||||||
|
for (servo, gecko_shadow) in v.0.into_iter()
|
||||||
|
.zip(self.gecko.mTextShadow.iter_mut()) {
|
||||||
|
|
||||||
|
gecko_shadow.mXOffset = servo.offset_x.0;
|
||||||
|
gecko_shadow.mYOffset = servo.offset_y.0;
|
||||||
|
gecko_shadow.mRadius = servo.blur_radius.0;
|
||||||
|
gecko_shadow.mHasColor = false;
|
||||||
|
gecko_shadow.mColor = match servo.color {
|
||||||
|
Color::RGBA(rgba) => {
|
||||||
|
gecko_shadow.mHasColor = true;
|
||||||
|
convert_rgba_to_nscolor(&rgba)
|
||||||
|
},
|
||||||
|
// TODO handle currentColor
|
||||||
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=760345
|
||||||
|
Color::CurrentColor => 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn copy_text_shadow_from(&mut self, other: &Self) {
|
||||||
|
self.gecko.mTextShadow.copy_from(&other.gecko.mTextShadow);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clone_text_shadow(&self) -> longhands::text_shadow::computed_value::T {
|
||||||
|
use cssparser::Color;
|
||||||
|
|
||||||
|
let buf = self.gecko.mTextShadow.iter().map(|shadow| {
|
||||||
|
longhands::text_shadow::computed_value::TextShadow {
|
||||||
|
offset_x: Au(shadow.mXOffset),
|
||||||
|
offset_y: Au(shadow.mYOffset),
|
||||||
|
blur_radius: Au(shadow.mRadius),
|
||||||
|
color: Color::RGBA(convert_nscolor_to_rgba(shadow.mColor)),
|
||||||
|
}
|
||||||
|
|
||||||
|
}).collect();
|
||||||
|
longhands::text_shadow::computed_value::T(buf)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_line_height(&mut self, v: longhands::line_height::computed_value::T) {
|
pub fn set_line_height(&mut self, v: longhands::line_height::computed_value::T) {
|
||||||
use properties::longhands::line_height::computed_value::T;
|
use properties::longhands::line_height::computed_value::T;
|
||||||
// FIXME: Align binary representations and ditch |match| for cast + static_asserts
|
// FIXME: Align binary representations and ditch |match| for cast + static_asserts
|
||||||
|
|
|
@ -145,7 +145,7 @@ COMPILATION_TARGETS = {
|
||||||
"nsChangeHint", "SheetParsingMode", "nsMainThreadPtrHandle",
|
"nsChangeHint", "SheetParsingMode", "nsMainThreadPtrHandle",
|
||||||
"nsMainThreadPtrHolder", "nscolor", "nsFont", "FontFamilyList",
|
"nsMainThreadPtrHolder", "nscolor", "nsFont", "FontFamilyList",
|
||||||
"FontFamilyType", "nsIAtom", "nsStyleContext", "StyleClipPath",
|
"FontFamilyType", "nsIAtom", "nsStyleContext", "StyleClipPath",
|
||||||
"StyleBasicShapeType", "StyleBasicShape"
|
"StyleBasicShapeType", "StyleBasicShape", "nsCSSShadowArray",
|
||||||
],
|
],
|
||||||
"void_types": [
|
"void_types": [
|
||||||
"nsINode", "nsIDocument", "nsIPrincipal", "nsIURI",
|
"nsINode", "nsIDocument", "nsIPrincipal", "nsIURI",
|
||||||
|
|
|
@ -157,6 +157,7 @@ impl HeapSizeOf for nsStyleContext { fn heap_size_of_children(&self) -> usize {
|
||||||
use structs::StyleClipPath;
|
use structs::StyleClipPath;
|
||||||
use structs::StyleBasicShapeType;
|
use structs::StyleBasicShapeType;
|
||||||
use structs::StyleBasicShape;
|
use structs::StyleBasicShape;
|
||||||
|
use structs::nsCSSShadowArray;
|
||||||
|
|
||||||
pub type RawGeckoNode = nsINode;
|
pub type RawGeckoNode = nsINode;
|
||||||
pub enum Element { }
|
pub enum Element { }
|
||||||
|
@ -345,6 +346,11 @@ extern "C" {
|
||||||
max_len: u32);
|
max_len: u32);
|
||||||
pub fn Gecko_AddRefCalcArbitraryThread(aPtr: *mut Calc);
|
pub fn Gecko_AddRefCalcArbitraryThread(aPtr: *mut Calc);
|
||||||
pub fn Gecko_ReleaseCalcArbitraryThread(aPtr: *mut Calc);
|
pub fn Gecko_ReleaseCalcArbitraryThread(aPtr: *mut Calc);
|
||||||
|
pub fn Gecko_NewCSSShadowArray(len: u32) -> *mut nsCSSShadowArray;
|
||||||
|
pub fn Gecko_AddRefCSSShadowArrayArbitraryThread(aPtr:
|
||||||
|
*mut nsCSSShadowArray);
|
||||||
|
pub fn Gecko_ReleaseCSSShadowArrayArbitraryThread(aPtr:
|
||||||
|
*mut nsCSSShadowArray);
|
||||||
pub fn Gecko_Construct_nsStyleFont(ptr: *mut nsStyleFont);
|
pub fn Gecko_Construct_nsStyleFont(ptr: *mut nsStyleFont);
|
||||||
pub fn Gecko_CopyConstruct_nsStyleFont(ptr: *mut nsStyleFont,
|
pub fn Gecko_CopyConstruct_nsStyleFont(ptr: *mut nsStyleFont,
|
||||||
other: *const nsStyleFont);
|
other: *const nsStyleFont);
|
||||||
|
|
|
@ -5917,14 +5917,13 @@ fn bindgen_test_layout_nsCSSShadowItem() {
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct nsCSSShadowArray {
|
pub struct nsCSSShadowArray {
|
||||||
pub mRefCnt: nsAutoRefCnt,
|
pub mRefCnt: ThreadSafeAutoRefCnt,
|
||||||
pub _mOwningThread: nsAutoOwningThread,
|
|
||||||
pub mLength: u32,
|
pub mLength: u32,
|
||||||
pub mArray: [nsCSSShadowItem; 1usize],
|
pub mArray: [nsCSSShadowItem; 1usize],
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn bindgen_test_layout_nsCSSShadowArray() {
|
fn bindgen_test_layout_nsCSSShadowArray() {
|
||||||
assert_eq!(::std::mem::size_of::<nsCSSShadowArray>() , 48usize);
|
assert_eq!(::std::mem::size_of::<nsCSSShadowArray>() , 40usize);
|
||||||
assert_eq!(::std::mem::align_of::<nsCSSShadowArray>() , 8usize);
|
assert_eq!(::std::mem::align_of::<nsCSSShadowArray>() , 8usize);
|
||||||
}
|
}
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|
|
@ -5895,14 +5895,13 @@ fn bindgen_test_layout_nsCSSShadowItem() {
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct nsCSSShadowArray {
|
pub struct nsCSSShadowArray {
|
||||||
pub mRefCnt: nsAutoRefCnt,
|
pub mRefCnt: ThreadSafeAutoRefCnt,
|
||||||
pub _mOwningThread: nsAutoOwningThread,
|
|
||||||
pub mLength: u32,
|
pub mLength: u32,
|
||||||
pub mArray: [nsCSSShadowItem; 1usize],
|
pub mArray: [nsCSSShadowItem; 1usize],
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn bindgen_test_layout_nsCSSShadowArray() {
|
fn bindgen_test_layout_nsCSSShadowArray() {
|
||||||
assert_eq!(::std::mem::size_of::<nsCSSShadowArray>() , 48usize);
|
assert_eq!(::std::mem::size_of::<nsCSSShadowArray>() , 40usize);
|
||||||
assert_eq!(::std::mem::align_of::<nsCSSShadowArray>() , 8usize);
|
assert_eq!(::std::mem::align_of::<nsCSSShadowArray>() , 8usize);
|
||||||
}
|
}
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
mod ns_css_shadow_array;
|
||||||
mod ns_style_auto_array;
|
mod ns_style_auto_array;
|
||||||
pub mod ns_style_coord;
|
pub mod ns_style_coord;
|
||||||
mod ns_t_array;
|
mod ns_t_array;
|
||||||
|
|
65
ports/geckolib/gecko_bindings/sugar/ns_css_shadow_array.rs
Normal file
65
ports/geckolib/gecko_bindings/sugar/ns_css_shadow_array.rs
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/* 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 http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use bindings::Gecko_AddRefCSSShadowArrayArbitraryThread;
|
||||||
|
use bindings::Gecko_NewCSSShadowArray;
|
||||||
|
use bindings::Gecko_ReleaseCSSShadowArrayArbitraryThread;
|
||||||
|
use std::ops::{Deref, DerefMut};
|
||||||
|
use std::{ptr, slice};
|
||||||
|
use structs::{nsCSSShadowArray, nsCSSShadowItem, RefPtr};
|
||||||
|
|
||||||
|
impl RefPtr<nsCSSShadowArray> {
|
||||||
|
pub fn replace_with_new(&mut self, len: u32) {
|
||||||
|
unsafe {
|
||||||
|
if !self.mRawPtr.is_null() {
|
||||||
|
Gecko_ReleaseCSSShadowArrayArbitraryThread(self.mRawPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.mRawPtr = if len == 0 {
|
||||||
|
ptr::null_mut()
|
||||||
|
} else {
|
||||||
|
Gecko_NewCSSShadowArray(len)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn copy_from(&mut self, other: &Self) {
|
||||||
|
unsafe {
|
||||||
|
if !self.mRawPtr.is_null() {
|
||||||
|
Gecko_ReleaseCSSShadowArrayArbitraryThread(self.mRawPtr);
|
||||||
|
}
|
||||||
|
if !other.mRawPtr.is_null() {
|
||||||
|
Gecko_AddRefCSSShadowArrayArbitraryThread(other.mRawPtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.mRawPtr = other.mRawPtr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Deref for RefPtr<nsCSSShadowArray> {
|
||||||
|
type Target = [nsCSSShadowItem];
|
||||||
|
fn deref(&self) -> &[nsCSSShadowItem] {
|
||||||
|
if self.mRawPtr.is_null() {
|
||||||
|
&[]
|
||||||
|
} else {
|
||||||
|
unsafe {
|
||||||
|
slice::from_raw_parts((*self.mRawPtr).mArray.as_ptr(),
|
||||||
|
(*self.mRawPtr).mLength as usize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DerefMut for RefPtr<nsCSSShadowArray> {
|
||||||
|
fn deref_mut(&mut self) -> &mut [nsCSSShadowItem] {
|
||||||
|
if self.mRawPtr.is_null() {
|
||||||
|
&mut []
|
||||||
|
} else {
|
||||||
|
unsafe {
|
||||||
|
slice::from_raw_parts_mut((*self.mRawPtr).mArray.as_mut_ptr(),
|
||||||
|
(*self.mRawPtr).mLength as usize)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue