mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Support color-typed properties in geckolib.
This commit is contained in:
parent
fa4a8cb9db
commit
952459c0d4
2 changed files with 76 additions and 1 deletions
|
@ -29,7 +29,7 @@ use style::properties::longhands;
|
|||
use style::properties::make_cascade_vec;
|
||||
use style::properties::style_struct_traits::*;
|
||||
use gecko_style_structs::{nsStyleUnion, nsStyleUnit};
|
||||
use values::ToGeckoStyleCoord;
|
||||
use values::{ToGeckoStyleCoord, convert_rgba_to_nscolor, convert_nscolor_to_rgba};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GeckoComputedValues {
|
||||
|
@ -184,6 +184,59 @@ def set_gecko_property(ffi_name, expr):
|
|||
}
|
||||
</%def>
|
||||
|
||||
<%def name="clear_color_flags(color_flags_ffi_name)">
|
||||
% if color_flags_ffi_name:
|
||||
self.gecko.${color_flags_ffi_name} &= !(gecko_style_structs::BORDER_COLOR_SPECIAL as u8);
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
<%def name="set_current_color_flag(color_flags_ffi_name)">
|
||||
% if color_flags_ffi_name:
|
||||
self.gecko.${color_flags_ffi_name} |= gecko_style_structs::BORDER_COLOR_FOREGROUND as u8;
|
||||
% else:
|
||||
// FIXME(heycam): This is a Gecko property that doesn't store currentColor
|
||||
// as a computed value. These are currently handled by converting
|
||||
// currentColor to the current value of the color property at computed
|
||||
// value time, but we don't have access to the Color struct here.
|
||||
// In the longer term, Gecko should store currentColor as a computed
|
||||
// value, so that we don't need to do this:
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=760345
|
||||
unimplemented!();
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
<%def name="get_current_color_flag_from(field)">
|
||||
(${field} & (gecko_style_structs::BORDER_COLOR_FOREGROUND as u8)) != 0
|
||||
</%def>
|
||||
|
||||
<%def name="impl_color_setter(ident, gecko_ffi_name, color_flags_ffi_name=None)">
|
||||
#[allow(unreachable_code)]
|
||||
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||
use cssparser::Color;
|
||||
${clear_color_flags(color_flags_ffi_name)}
|
||||
let result = match v {
|
||||
Color::CurrentColor => {
|
||||
${set_current_color_flag(color_flags_ffi_name)}
|
||||
0
|
||||
},
|
||||
Color::RGBA(rgba) => convert_rgba_to_nscolor(&rgba),
|
||||
};
|
||||
${set_gecko_property(gecko_ffi_name, "result")}
|
||||
}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_color_copy(ident, gecko_ffi_name, color_flags_ffi_name=None)">
|
||||
fn copy_${ident}_from(&mut self, other: &Self) {
|
||||
% if color_flags_ffi_name:
|
||||
${clear_color_flags(color_flags_ffi_name)}
|
||||
if ${get_current_color_flag_from("other.gecko." + color_flags_ffi_name)} {
|
||||
${set_current_color_flag(color_flags_ffi_name)}
|
||||
}
|
||||
% endif
|
||||
self.gecko.${gecko_ffi_name} = other.gecko.${gecko_ffi_name};
|
||||
}
|
||||
</%def>
|
||||
|
||||
<%def name="impl_keyword(ident, gecko_ffi_name, keyword, need_clone)">
|
||||
<%call expr="impl_keyword_setter(ident, gecko_ffi_name, keyword)"></%call>
|
||||
<%call expr="impl_simple_copy(ident, gecko_ffi_name)"></%call>
|
||||
|
@ -197,6 +250,11 @@ def set_gecko_property(ffi_name, expr):
|
|||
<%call expr="impl_simple_copy(ident, gecko_ffi_name)"></%call>
|
||||
</%def>
|
||||
|
||||
<%def name="impl_color(ident, gecko_ffi_name, color_flags_ffi_name=None)">
|
||||
<%call expr="impl_color_setter(ident, gecko_ffi_name, color_flags_ffi_name)"></%call>
|
||||
<%call expr="impl_color_copy(ident, gecko_ffi_name, color_flags_ffi_name)"></%call>
|
||||
</%def>
|
||||
|
||||
<%def name="impl_app_units(ident, gecko_ffi_name, need_clone)">
|
||||
fn set_${ident}(&mut self, v: longhands::${ident}::computed_value::T) {
|
||||
self.gecko.${gecko_ffi_name} = v.0;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* 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 cssparser::RGBA;
|
||||
use gecko_style_structs::{nsStyleUnion, nsStyleUnit};
|
||||
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
|
||||
|
||||
|
@ -44,3 +45,19 @@ impl ToGeckoStyleCoord for LengthOrPercentageOrAuto {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
pub fn convert_rgba_to_nscolor(rgba: &RGBA) -> u32 {
|
||||
(((rgba.alpha * 255.0).round() as u32) << 24) |
|
||||
(((rgba.blue * 255.0).round() as u32) << 16) |
|
||||
(((rgba.green * 255.0).round() as u32) << 8) |
|
||||
((rgba.red * 255.0).round() as u32)
|
||||
}
|
||||
|
||||
pub fn convert_nscolor_to_rgba(color: u32) -> RGBA {
|
||||
RGBA {
|
||||
red: ((color & 0xff) as f32) / 255.0,
|
||||
green: (((color >> 8) & 0xff) as f32) / 255.0,
|
||||
blue: (((color >> 16) & 0xff) as f32) / 255.0,
|
||||
alpha: (((color >> 24) & 0xff) as f32) / 255.0,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue