Auto merge of #12815 - emilio:stylo-atoms, r=bholley

stylo: Use atoms as the pseudo-element back-end.

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

A bit of work left, and we can uber-optimize this (left comments, will fill follow-ups), but this is a decent refactor so I thought I'd rather get some feedback on it.

r? @bholley (not formally yet, maybe, but some feedback is appreciated).

---
<!-- 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] These changes do not require tests because geckolib only...

<!-- 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/12815)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-08-16 12:50:29 -05:00 committed by GitHub
commit c386a3c881
17 changed files with 11499 additions and 9875 deletions

View file

@ -12,104 +12,85 @@ use stylesheets::Stylesheet;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct GeckoSelectorImpl;
/// NOTE: The boolean field represents whether this element is an anonymous box.
///
/// This is just for convenience, instead of recomputing it. Also, note that
/// Atom is always a static atom, so if space is a concern, we can use the
/// raw pointer and use the lower bit to represent it without space overhead.
///
/// FIXME(emilio): we know all these atoms are static. Patches are starting to
/// pile up, but a further potential optimisation is generating bindings without
/// `-no-gen-bitfield-methods` (that was removed to compile on stable, but it no
/// longer depends on it), and using the raw *mut nsIAtom (properly asserting
/// we're a static atom).
///
/// This should allow us to avoid random FFI overhead when cloning/dropping
/// pseudos.
///
/// Also, we can further optimize PartialEq and hash comparing/hashing only the
/// atoms.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum PseudoElement {
Before,
After,
pub struct PseudoElement(Atom, bool);
Backdrop,
FirstLetter,
FirstLine,
MozSelection,
MozFocusInner,
MozFocusOuter,
MozListBullet,
MozListNumber,
MozMathAnonymous,
MozNumberWrapper,
MozNumberText,
MozNumberSpinBox,
MozNumberSpinUp,
MozNumberSpinDown,
MozProgressBar,
MozRangeTrack,
MozRangeProgress,
MozRangeThumb,
MozMeterBar,
MozPlaceholder,
MozColorSwatch,
impl PseudoElement {
#[inline]
fn as_atom(&self) -> &Atom {
&self.0
}
AnonBox(AnonBoxPseudoElement),
}
#[inline]
fn is_anon_box(&self) -> bool {
self.1
}
// https://mxr.mozilla.org/mozilla-central/source/layout/style/nsCSSAnonBoxList.h
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum AnonBoxPseudoElement {
MozText,
MozOtherNonElement,
MozAnonymousBlock,
MozAnonymousPositionedBlock,
MozMathMLAnonymousBlock,
MozXULAnonymousBlock,
#[inline]
pub fn from_atom_unchecked(atom: Atom, is_anon_box: bool) -> Self {
if cfg!(debug_assertions) {
// Do the check on debug regardless.
match Self::from_atom(&*atom, true) {
Some(pseudo) => {
assert_eq!(pseudo.is_anon_box(), is_anon_box);
return pseudo;
}
None => panic!("Unknown pseudo: {:?}", atom),
}
}
MozHorizontalFramesetBorder,
MozVerticalFramesetBorder,
MozLineFrame,
MozButtonContent,
MozButtonLabel,
MozCellContent,
MozDropdownList,
MozFieldsetContent,
MozFramesetBlank,
MozDisplayComboboxControlFrame,
PseudoElement(atom, is_anon_box)
}
MozHTMLCanvasContent,
MozInlineTable,
MozTable,
MozTableCell,
MozTableColumnGroup,
MozTableColumn,
MozTableWrapper,
MozTableRowGroup,
MozTableRow,
#[inline]
fn from_atom(atom: &WeakAtom, in_ua: bool) -> Option<Self> {
macro_rules! pseudo_element {
($pseudo_str_with_colon:expr, $atom:expr, $is_anon_box:expr) => {{
if atom == &*$atom {
return Some(PseudoElement($atom, $is_anon_box));
}
}}
}
MozCanvas,
MozPageBreak,
MozPage,
MozPageContent,
MozPageSequence,
MozScrolledContent,
MozScrolledCanvas,
MozScrolledPageSequence,
MozColumnContent,
MozViewport,
MozViewportScroll,
MozAnonymousFlexItem,
MozAnonymousGridItem,
include!("generated/gecko_pseudo_element_helper.rs");
MozRuby,
MozRubyBase,
MozRubyBaseContainer,
MozRubyText,
MozRubyTextContainer,
None
}
MozTreeColumn,
MozTreeRow,
MozTreeSeparator,
MozTreeCell,
MozTreeIndentation,
MozTreeLine,
MozTreeTwisty,
MozTreeImage,
MozTreeCellText,
MozTreeCheckbox,
MozTreeProgressMeter,
MozTreeDropFeedback,
#[inline]
fn from_slice(s: &str, in_ua_stylesheet: bool) -> Option<Self> {
use std::ascii::AsciiExt;
macro_rules! pseudo_element {
($pseudo_str_with_colon:expr, $atom:expr, $is_anon_box:expr) => {{
if !$is_anon_box || in_ua_stylesheet {
if s.eq_ignore_ascii_case(&$pseudo_str_with_colon[1..]) {
return Some(PseudoElement($atom, $is_anon_box))
}
}
}}
}
MozSVGMarkerAnonChild,
MozSVGOuterSVGAnonChild,
MozSVGForeignContent,
MozSVGText,
include!("generated/gecko_pseudo_element_helper.rs");
None
}
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
@ -194,211 +175,44 @@ impl SelectorImpl for GeckoSelectorImpl {
fn parse_pseudo_element(context: &ParserContext<Self>,
name: &str) -> Result<PseudoElement, ()> {
use self::AnonBoxPseudoElement::*;
use self::PseudoElement::*;
// The braces here are unfortunate, but they're needed for
// match_ignore_ascii_case! to work as expected.
match_ignore_ascii_case! { name,
"before" => { return Ok(Before) },
"after" => { return Ok(After) },
"first-line" => { return Ok(FirstLine) },
"backdrop" => { return Ok(Backdrop) },
"first-letter" => { return Ok(FirstLetter) },
"first-line" => { return Ok(FirstLine) },
"-moz-selection" => { return Ok(MozSelection) },
"-moz-focus-inner" => { return Ok(MozFocusInner) },
"-moz-focus-outer" => { return Ok(MozFocusOuter) },
"-moz-list-bullet" => { return Ok(MozListBullet) },
"-moz-list-number" => { return Ok(MozListNumber) },
"-moz-math-anonymous" => { return Ok(MozMathAnonymous) },
"-moz-number-wrapper" => { return Ok(MozNumberWrapper) },
"-moz-number-text" => { return Ok(MozNumberText) },
"-moz-number-spin-box" => { return Ok(MozNumberSpinBox) },
"-moz-number-spin-up" => { return Ok(MozNumberSpinUp) },
"-moz-number-spin-down" => { return Ok(MozNumberSpinDown) },
"-moz-progress-bar" => { return Ok(MozProgressBar) },
"-moz-range-track" => { return Ok(MozRangeTrack) },
"-moz-range-progress" => { return Ok(MozRangeProgress) },
"-moz-range-thumb" => { return Ok(MozRangeThumb) },
"-moz-metter-bar" => { return Ok(MozMeterBar) },
"-moz-placeholder" => { return Ok(MozPlaceholder) },
"-moz-color-swatch" => { return Ok(MozColorSwatch) },
_ => {}
match PseudoElement::from_slice(name, context.in_user_agent_stylesheet) {
Some(pseudo) => Ok(pseudo),
None => Err(()),
}
if !context.in_user_agent_stylesheet {
return Err(())
}
Ok(AnonBox(match_ignore_ascii_case! { name,
"-moz-text" => MozText,
"-moz-other-non-element" => MozOtherNonElement,
"-moz-anonymous-block" => MozAnonymousBlock,
"-moz-anonymous-positioned-block" => MozAnonymousPositionedBlock,
"-moz-mathml-anonymous-block" => MozMathMLAnonymousBlock,
"-moz-xul-anonymous-block" => MozXULAnonymousBlock,
"-moz-hframeset-border" => MozHorizontalFramesetBorder,
"-moz-vframeset-border" => MozVerticalFramesetBorder,
"-moz-line-frame" => MozLineFrame,
"-moz-button-content" => MozButtonContent,
"-moz-buttonlabel" => MozButtonLabel,
"-moz-cell-content" => MozCellContent,
"-moz-dropdown-list" => MozDropdownList,
"-moz-fieldset-content" => MozFieldsetContent,
"-moz-frameset-blank" => MozFramesetBlank,
"-moz-display-comboboxcontrol-frame" => MozDisplayComboboxControlFrame,
"-moz-html-canvas-content" => MozHTMLCanvasContent,
"-moz-inline-table" => MozInlineTable,
"-moz-table" => MozTable,
"-moz-table-cell" => MozTableCell,
"-moz-table-column-group" => MozTableColumnGroup,
"-moz-table-column" => MozTableColumn,
"-moz-table-wrapper" => MozTableWrapper,
"-moz-table-row-group" => MozTableRowGroup,
"-moz-table-row" => MozTableRow,
"-moz-canvas" => MozCanvas,
"-moz-pagebreak" => MozPageBreak,
"-moz-page" => MozPage,
"-moz-pagecontent" => MozPageContent,
"-moz-page-sequence" => MozPageSequence,
"-moz-scrolled-content" => MozScrolledContent,
"-moz-scrolled-canvas" => MozScrolledCanvas,
"-moz-scrolled-page-sequence" => MozScrolledPageSequence,
"-moz-column-content" => MozColumnContent,
"-moz-viewport" => MozViewport,
"-moz-viewport-scroll" => MozViewportScroll,
"-moz-anonymous-flex-item" => MozAnonymousFlexItem,
"-moz-anonymous-grid-item" => MozAnonymousGridItem,
"-moz-ruby" => MozRuby,
"-moz-ruby-base" => MozRubyBase,
"-moz-ruby-base-container" => MozRubyBaseContainer,
"-moz-ruby-text" => MozRubyText,
"-moz-ruby-text-container" => MozRubyTextContainer,
"-moz-tree-column" => MozTreeColumn,
"-moz-tree-row" => MozTreeRow,
"-moz-tree-separator" => MozTreeSeparator,
"-moz-tree-cell" => MozTreeCell,
"-moz-tree-indentation" => MozTreeIndentation,
"-moz-tree-line" => MozTreeLine,
"-moz-tree-twisty" => MozTreeTwisty,
"-moz-tree-image" => MozTreeImage,
"-moz-tree-cell-text" => MozTreeCellText,
"-moz-tree-checkbox" => MozTreeCheckbox,
"-moz-tree-progressmeter" => MozTreeProgressMeter,
"-moz-tree-drop-feedback" => MozTreeDropFeedback,
"-moz-svg-marker-anon-child" => MozSVGMarkerAnonChild,
"-moz-svg-outer-svg-anon-child" => MozSVGOuterSVGAnonChild,
"-moz-svg-foreign-content" => MozSVGForeignContent,
"-moz-svg-text" => MozSVGText,
_ => return Err(())
}))
}
}
impl GeckoSelectorImpl {
#[inline]
pub fn pseudo_element_cascade_type(pseudo: &PseudoElement) -> PseudoElementCascadeType {
match *pseudo {
PseudoElement::Before |
PseudoElement::After => PseudoElementCascadeType::Eager,
PseudoElement::AnonBox(_) => PseudoElementCascadeType::Precomputed,
_ => PseudoElementCascadeType::Lazy,
if Self::pseudo_is_before_or_after(pseudo) {
return PseudoElementCascadeType::Eager
}
if pseudo.is_anon_box() {
return PseudoElementCascadeType::Precomputed
}
PseudoElementCascadeType::Lazy
}
#[inline]
pub fn each_pseudo_element<F>(mut fun: F)
where F: FnMut(PseudoElement) {
use self::AnonBoxPseudoElement::*;
use self::PseudoElement::*;
where F: FnMut(PseudoElement)
{
macro_rules! pseudo_element {
($pseudo_str_with_colon:expr, $atom:expr, $is_anon_box:expr) => {{
fun(PseudoElement($atom, $is_anon_box));
}}
}
fun(Before);
fun(After);
fun(FirstLine);
fun(AnonBox(MozText));
fun(AnonBox(MozOtherNonElement));
fun(AnonBox(MozAnonymousBlock));
fun(AnonBox(MozAnonymousPositionedBlock));
fun(AnonBox(MozMathMLAnonymousBlock));
fun(AnonBox(MozXULAnonymousBlock));
fun(AnonBox(MozHorizontalFramesetBorder));
fun(AnonBox(MozVerticalFramesetBorder));
fun(AnonBox(MozLineFrame));
fun(AnonBox(MozButtonContent));
fun(AnonBox(MozButtonLabel));
fun(AnonBox(MozCellContent));
fun(AnonBox(MozDropdownList));
fun(AnonBox(MozFieldsetContent));
fun(AnonBox(MozFramesetBlank));
fun(AnonBox(MozDisplayComboboxControlFrame));
fun(AnonBox(MozHTMLCanvasContent));
fun(AnonBox(MozInlineTable));
fun(AnonBox(MozTable));
fun(AnonBox(MozTableCell));
fun(AnonBox(MozTableColumnGroup));
fun(AnonBox(MozTableColumn));
fun(AnonBox(MozTableWrapper));
fun(AnonBox(MozTableRowGroup));
fun(AnonBox(MozTableRow));
fun(AnonBox(MozCanvas));
fun(AnonBox(MozPageBreak));
fun(AnonBox(MozPage));
fun(AnonBox(MozPageContent));
fun(AnonBox(MozPageSequence));
fun(AnonBox(MozScrolledContent));
fun(AnonBox(MozScrolledCanvas));
fun(AnonBox(MozScrolledPageSequence));
fun(AnonBox(MozColumnContent));
fun(AnonBox(MozViewport));
fun(AnonBox(MozViewportScroll));
fun(AnonBox(MozAnonymousFlexItem));
fun(AnonBox(MozAnonymousGridItem));
fun(AnonBox(MozRuby));
fun(AnonBox(MozRubyBase));
fun(AnonBox(MozRubyBaseContainer));
fun(AnonBox(MozRubyText));
fun(AnonBox(MozRubyTextContainer));
fun(AnonBox(MozTreeColumn));
fun(AnonBox(MozTreeRow));
fun(AnonBox(MozTreeSeparator));
fun(AnonBox(MozTreeCell));
fun(AnonBox(MozTreeIndentation));
fun(AnonBox(MozTreeLine));
fun(AnonBox(MozTreeTwisty));
fun(AnonBox(MozTreeImage));
fun(AnonBox(MozTreeCellText));
fun(AnonBox(MozTreeCheckbox));
fun(AnonBox(MozTreeProgressMeter));
fun(AnonBox(MozTreeDropFeedback));
fun(AnonBox(MozSVGMarkerAnonChild));
fun(AnonBox(MozSVGOuterSVGAnonChild));
fun(AnonBox(MozSVGForeignContent));
fun(AnonBox(MozSVGText));
include!("generated/gecko_pseudo_element_helper.rs")
}
#[inline]
pub fn pseudo_is_before_or_after(pseudo: &PseudoElement) -> bool {
match *pseudo {
PseudoElement::Before |
PseudoElement::After => true,
_ => false,
}
*pseudo.as_atom() == atom!(":before") ||
*pseudo.as_atom() == atom!(":after")
}
#[inline]

View file

@ -0,0 +1,277 @@
/* 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/. */
/* Autogenerated file, DO NOT EDIT DIRECTLY */
/*
* This file contains a helper macro invocation to aid Gecko's style system
* pseudo-element integration.
*
* This file is NOT INTENDED to be compiled as a standalone module.
*
* Also, it guarantees the property that normal pseudo-elements are processed
* before anonymous boxes.
*
* Expected usage is as follows:
*
* ```
* fn have_to_use_pseudo_elements() {
* macro_rules pseudo_element! {
* ($pseudo_str_with_colon:expr, $pseudo_atom:expr, $is_anon_box:true) => {{
* // Stuff stuff stuff.
* }}
* }
* include!("path/to/helper.rs")
* }
* ```
*
*/
{
pseudo_element!(":after",
atom!(":after"),
false);
pseudo_element!(":before",
atom!(":before"),
false);
pseudo_element!(":backdrop",
atom!(":backdrop"),
false);
pseudo_element!(":first-letter",
atom!(":first-letter"),
false);
pseudo_element!(":first-line",
atom!(":first-line"),
false);
pseudo_element!(":-moz-selection",
atom!(":-moz-selection"),
false);
pseudo_element!(":-moz-focus-inner",
atom!(":-moz-focus-inner"),
false);
pseudo_element!(":-moz-focus-outer",
atom!(":-moz-focus-outer"),
false);
pseudo_element!(":-moz-list-bullet",
atom!(":-moz-list-bullet"),
false);
pseudo_element!(":-moz-list-number",
atom!(":-moz-list-number"),
false);
pseudo_element!(":-moz-math-anonymous",
atom!(":-moz-math-anonymous"),
false);
pseudo_element!(":-moz-number-wrapper",
atom!(":-moz-number-wrapper"),
false);
pseudo_element!(":-moz-number-text",
atom!(":-moz-number-text"),
false);
pseudo_element!(":-moz-number-spin-box",
atom!(":-moz-number-spin-box"),
false);
pseudo_element!(":-moz-number-spin-up",
atom!(":-moz-number-spin-up"),
false);
pseudo_element!(":-moz-number-spin-down",
atom!(":-moz-number-spin-down"),
false);
pseudo_element!(":-moz-progress-bar",
atom!(":-moz-progress-bar"),
false);
pseudo_element!(":-moz-range-track",
atom!(":-moz-range-track"),
false);
pseudo_element!(":-moz-range-progress",
atom!(":-moz-range-progress"),
false);
pseudo_element!(":-moz-range-thumb",
atom!(":-moz-range-thumb"),
false);
pseudo_element!(":-moz-meter-bar",
atom!(":-moz-meter-bar"),
false);
pseudo_element!(":-moz-placeholder",
atom!(":-moz-placeholder"),
false);
pseudo_element!(":-moz-color-swatch",
atom!(":-moz-color-swatch"),
false);
pseudo_element!(":-moz-text",
atom!(":-moz-text"),
true);
pseudo_element!(":-moz-other-non-element",
atom!(":-moz-other-non-element"),
true);
pseudo_element!(":-moz-anonymous-block",
atom!(":-moz-anonymous-block"),
true);
pseudo_element!(":-moz-anonymous-positioned-block",
atom!(":-moz-anonymous-positioned-block"),
true);
pseudo_element!(":-moz-mathml-anonymous-block",
atom!(":-moz-mathml-anonymous-block"),
true);
pseudo_element!(":-moz-xul-anonymous-block",
atom!(":-moz-xul-anonymous-block"),
true);
pseudo_element!(":-moz-hframeset-border",
atom!(":-moz-hframeset-border"),
true);
pseudo_element!(":-moz-vframeset-border",
atom!(":-moz-vframeset-border"),
true);
pseudo_element!(":-moz-line-frame",
atom!(":-moz-line-frame"),
true);
pseudo_element!(":-moz-button-content",
atom!(":-moz-button-content"),
true);
pseudo_element!(":-moz-buttonlabel",
atom!(":-moz-buttonlabel"),
true);
pseudo_element!(":-moz-cell-content",
atom!(":-moz-cell-content"),
true);
pseudo_element!(":-moz-dropdown-list",
atom!(":-moz-dropdown-list"),
true);
pseudo_element!(":-moz-fieldset-content",
atom!(":-moz-fieldset-content"),
true);
pseudo_element!(":-moz-frameset-blank",
atom!(":-moz-frameset-blank"),
true);
pseudo_element!(":-moz-display-comboboxcontrol-frame",
atom!(":-moz-display-comboboxcontrol-frame"),
true);
pseudo_element!(":-moz-html-canvas-content",
atom!(":-moz-html-canvas-content"),
true);
pseudo_element!(":-moz-inline-table",
atom!(":-moz-inline-table"),
true);
pseudo_element!(":-moz-table",
atom!(":-moz-table"),
true);
pseudo_element!(":-moz-table-cell",
atom!(":-moz-table-cell"),
true);
pseudo_element!(":-moz-table-column-group",
atom!(":-moz-table-column-group"),
true);
pseudo_element!(":-moz-table-column",
atom!(":-moz-table-column"),
true);
pseudo_element!(":-moz-table-wrapper",
atom!(":-moz-table-wrapper"),
true);
pseudo_element!(":-moz-table-row-group",
atom!(":-moz-table-row-group"),
true);
pseudo_element!(":-moz-table-row",
atom!(":-moz-table-row"),
true);
pseudo_element!(":-moz-canvas",
atom!(":-moz-canvas"),
true);
pseudo_element!(":-moz-pagebreak",
atom!(":-moz-pagebreak"),
true);
pseudo_element!(":-moz-page",
atom!(":-moz-page"),
true);
pseudo_element!(":-moz-pagecontent",
atom!(":-moz-pagecontent"),
true);
pseudo_element!(":-moz-page-sequence",
atom!(":-moz-page-sequence"),
true);
pseudo_element!(":-moz-scrolled-content",
atom!(":-moz-scrolled-content"),
true);
pseudo_element!(":-moz-scrolled-canvas",
atom!(":-moz-scrolled-canvas"),
true);
pseudo_element!(":-moz-scrolled-page-sequence",
atom!(":-moz-scrolled-page-sequence"),
true);
pseudo_element!(":-moz-column-content",
atom!(":-moz-column-content"),
true);
pseudo_element!(":-moz-viewport",
atom!(":-moz-viewport"),
true);
pseudo_element!(":-moz-viewport-scroll",
atom!(":-moz-viewport-scroll"),
true);
pseudo_element!(":-moz-anonymous-flex-item",
atom!(":-moz-anonymous-flex-item"),
true);
pseudo_element!(":-moz-anonymous-grid-item",
atom!(":-moz-anonymous-grid-item"),
true);
pseudo_element!(":-moz-ruby",
atom!(":-moz-ruby"),
true);
pseudo_element!(":-moz-ruby-base",
atom!(":-moz-ruby-base"),
true);
pseudo_element!(":-moz-ruby-base-container",
atom!(":-moz-ruby-base-container"),
true);
pseudo_element!(":-moz-ruby-text",
atom!(":-moz-ruby-text"),
true);
pseudo_element!(":-moz-ruby-text-container",
atom!(":-moz-ruby-text-container"),
true);
pseudo_element!(":-moz-tree-column",
atom!(":-moz-tree-column"),
true);
pseudo_element!(":-moz-tree-row",
atom!(":-moz-tree-row"),
true);
pseudo_element!(":-moz-tree-separator",
atom!(":-moz-tree-separator"),
true);
pseudo_element!(":-moz-tree-cell",
atom!(":-moz-tree-cell"),
true);
pseudo_element!(":-moz-tree-indentation",
atom!(":-moz-tree-indentation"),
true);
pseudo_element!(":-moz-tree-line",
atom!(":-moz-tree-line"),
true);
pseudo_element!(":-moz-tree-twisty",
atom!(":-moz-tree-twisty"),
true);
pseudo_element!(":-moz-tree-image",
atom!(":-moz-tree-image"),
true);
pseudo_element!(":-moz-tree-cell-text",
atom!(":-moz-tree-cell-text"),
true);
pseudo_element!(":-moz-tree-checkbox",
atom!(":-moz-tree-checkbox"),
true);
pseudo_element!(":-moz-tree-progressmeter",
atom!(":-moz-tree-progressmeter"),
true);
pseudo_element!(":-moz-tree-drop-feedback",
atom!(":-moz-tree-drop-feedback"),
true);
pseudo_element!(":-moz-svg-marker-anon-child",
atom!(":-moz-svg-marker-anon-child"),
true);
pseudo_element!(":-moz-svg-outer-svg-anon-child",
atom!(":-moz-svg-outer-svg-anon-child"),
true);
pseudo_element!(":-moz-svg-foreign-content",
atom!(":-moz-svg-foreign-content"),
true);
pseudo_element!(":-moz-svg-text",
atom!(":-moz-svg-text"),
true);
}

View file

@ -425,7 +425,7 @@ impl ${style_struct.gecko_struct_name} {
pub fn initial() -> Arc<Self> {
let mut result = Arc::new(${style_struct.gecko_struct_name} { gecko: unsafe { zeroed() } });
unsafe {
Gecko_Construct_${style_struct.gecko_ffi_name}(&mut Arc::make_mut(&mut result).gecko);
Gecko_Construct_${style_struct.gecko_ffi_name}(&mut Arc::get_mut(&mut result).unwrap().gecko);
}
result
}
@ -914,7 +914,6 @@ fn static_assert() {
T::left => true,
T::right => true
};
// TODO(shinglyu): Rename Gecko's struct to mPageBreakBefore
self.gecko.mBreakBefore = result;
}
@ -931,7 +930,6 @@ fn static_assert() {
T::left => true,
T::right => true
};
// TODO(shinglyu): Rename Gecko's struct to mPageBreakBefore
self.gecko.mBreakBefore = result;
}

View file

@ -15,5 +15,5 @@ ${helpers.single_keyword("ime-mode", "normal auto active disabled inactive",
${helpers.single_keyword("-moz-user-select", "auto text none all", products="gecko",
gecko_ffi_name="mUserSelect",
gecko_constant_prefix="NS_STYLE_USER_SELECT",
gecko_enum_prefix="StyleUserSelect",
animatable=False)}

View file

@ -13,6 +13,8 @@ import copy
import subprocess
import tempfile
import regen_atoms
DESCRIPTION = 'Regenerate the rust version of the structs or the bindings file.'
TOOLS_DIR = os.path.dirname(os.path.abspath(__file__))
COMMON_BUILD_KEY = "__common__"
@ -22,7 +24,7 @@ COMPILATION_TARGETS = {
COMMON_BUILD_KEY: {
"flags": [
"-x", "c++", "-std=c++14",
"-allow-unknown-types", "-no-bitfield-methods",
"-allow-unknown-types", "-no-unstable-rust",
"-no-type-renaming", "-no-namespaced-constants",
"-DTRACING=1", "-DIMPL_LIBXUL", "-DMOZ_STYLO_BINDINGS=1",
"-DMOZILLA_INTERNAL_API", "-DRUST_BINDGEN",
@ -38,9 +40,11 @@ COMPILATION_TARGETS = {
},
# Generation of style structs.
"structs": {
"target_dir": "../gecko_bindings",
"test": True,
"flags": [
"-ignore-functions",
"-ignore-methods",
],
"includes": [
"{}/dist/include/nsThemeConstants.h",
@ -108,6 +112,7 @@ COMPILATION_TARGETS = {
},
# Generation of the ffi bindings.
"bindings": {
"target_dir": "../gecko_bindings",
"raw_lines": [
"use heapsize::HeapSizeOf;",
],
@ -140,6 +145,10 @@ COMPILATION_TARGETS = {
"void_types": [
"nsINode", "nsIDocument", "nsIPrincipal", "nsIURI",
],
},
"atoms": {
"custom_build": regen_atoms.build,
}
}
@ -212,6 +221,17 @@ def build(objdir, target_name, kind_name=None,
assert ((kind_name is None and "build_kinds" not in current_target) or
(kind_name in current_target["build_kinds"]))
if "custom_build" in current_target:
print("[CUSTOM] {}::{} in \"{}\"... ".format(target_name, kind_name, objdir), end='')
sys.stdout.flush()
ret = current_target["custom_build"](objdir, verbose=True)
if ret != 0:
print("FAIL")
else:
print("OK")
return ret
if bindgen is None:
bindgen = os.path.join(TOOLS_DIR, "rust-bindgen")
@ -221,18 +241,23 @@ def build(objdir, target_name, kind_name=None,
else:
bindgen = [bindgen]
if output_filename is None:
filename = "{}.rs".format(target_name)
if kind_name is not None:
filename = "{}_{}.rs".format(target_name, kind_name)
output_filename = "{}/../{}".format(TOOLS_DIR, filename)
if kind_name is not None:
current_target = copy.deepcopy(current_target)
extend_object(current_target, current_target["build_kinds"][kind_name])
target_dir = None
if output_filename is None and "target_dir" in current_target:
target_dir = current_target["target_dir"]
if output_filename is None:
output_filename = "{}.rs".format(target_name)
if kind_name is not None:
output_filename = "{}_{}.rs".format(target_name, kind_name)
if target_dir:
output_filename = "{}/{}".format(target_dir, output_filename)
print("[BINDGEN] {}::{} in \"{}\"... ".format(target_name, kind_name, objdir), end='')
sys.stdout.flush()

View file

@ -0,0 +1,194 @@
#!/usr/bin/env python
# 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/.
import re
import os
def gnu_symbolify(source, ident):
return "_ZN" + str(len(source.CLASS)) + source.CLASS + str(len(ident)) + ident + "E"
def msvc64_symbolify(source, ident):
return "?" + ident + "@" + source.CLASS + "@@2PEAV" + source.TYPE + "@@EA"
def msvc32_symbolify(source, ident):
return "?" + ident + "@" + source.CLASS + "@@2PAV" + source.TYPE + "@@A"
class GkAtomSource:
PATTERN = re.compile('^GK_ATOM\((.+),\s*"(.*)"\)')
FILE = "dist/include/nsGkAtomList.h"
CLASS = "nsGkAtoms"
TYPE = "nsIAtom"
class CSSPseudoElementsAtomSource:
PATTERN = re.compile('^CSS_PSEUDO_ELEMENT\((.+),\s*"(.*)",')
FILE = "dist/include/nsCSSPseudoElementList.h"
CLASS = "nsCSSPseudoElements"
# NB: nsICSSPseudoElement is effectively the same as a nsIAtom, but we need
# this for MSVC name mangling.
TYPE = "nsICSSPseudoElement"
class CSSAnonBoxesAtomSource:
PATTERN = re.compile('^CSS_ANON_BOX\((.+),\s*"(.*)"\)')
FILE = "dist/include/nsCSSAnonBoxList.h"
CLASS = "nsCSSAnonBoxes"
TYPE = "nsICSSAnonBoxPseudo"
SOURCES = [
GkAtomSource,
CSSPseudoElementsAtomSource,
CSSAnonBoxesAtomSource,
]
def map_atom(ident):
if ident in {"box", "loop", "match", "mod", "ref",
"self", "type", "use", "where", "in"}:
return ident + "_"
return ident
class Atom:
def __init__(self, source, ident, value):
self.ident = "{}_{}".format(source.CLASS, ident)
self._original_ident = ident
self.value = value
self.source = source
def cpp_class(self):
return self.source.CLASS
def gnu_symbol(self):
return gnu_symbolify(self.source, self._original_ident)
def msvc32_symbol(self):
return msvc32_symbolify(self.source, self._original_ident)
def msvc64_symbol(self):
return msvc64_symbolify(self.source, self._original_ident)
def type(self):
return self.source.TYPE
def collect_atoms(objdir):
atoms = []
for source in SOURCES:
with open(os.path.join(objdir, source.FILE)) as f:
for line in f.readlines():
result = re.match(source.PATTERN, line)
if result:
atoms.append(Atom(source, result.group(1), result.group(2)))
return atoms
PRELUDE = """
/* 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/. */
/* Autogenerated file, DO NOT EDIT DIRECTLY */
"""[1:]
def write_atom_macro(atoms, file_name):
ATOM_TEMPLATE = """
#[link_name = "{link_name}"]
pub static {name}: *mut {type};
"""[1:]
def write_items(f, func):
f.write(" extern {\n")
for atom in atoms:
f.write(ATOM_TEMPLATE.format(name=atom.ident,
link_name=func(atom),
type=atom.type()))
f.write(" }\n")
with open(file_name, "wb") as f:
f.write(PRELUDE)
f.write("use gecko_bindings::structs::nsIAtom;\n\n")
f.write("use Atom;\n\n")
for source in SOURCES:
if source.TYPE != "nsIAtom":
f.write("pub enum {} {{}}\n\n".format(source.TYPE))
f.write("""
#[inline(always)] pub fn unsafe_atom_from_static(ptr: *mut nsIAtom) -> Atom {
unsafe { Atom::from_static(ptr) }
}\n\n
""")
f.write("cfg_if! {\n")
f.write(" if #[cfg(not(target_env = \"msvc\"))] {\n")
write_items(f, Atom.gnu_symbol)
f.write(" } else if #[cfg(target_pointer_width = \"64\")] {\n")
write_items(f, Atom.msvc64_symbol)
f.write(" } else {\n")
write_items(f, Atom.msvc32_symbol)
f.write(" }\n")
f.write("}\n\n")
f.write("#[macro_export]\n")
f.write("macro_rules! atom {\n")
f.writelines(['("%s") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::%s as *mut _) };\n'
% (atom.value, atom.ident) for atom in atoms])
f.write("}\n")
PSEUDO_ELEMENT_HEADER = """
/*
* This file contains a helper macro invocation to aid Gecko's style system
* pseudo-element integration.
*
* This file is NOT INTENDED to be compiled as a standalone module.
*
* Also, it guarantees the property that normal pseudo-elements are processed
* before anonymous boxes.
*
* Expected usage is as follows:
*
* ```
* fn have_to_use_pseudo_elements() {
* macro_rules pseudo_element! {
* ($pseudo_str_with_colon:expr, $pseudo_atom:expr, $is_anon_box:true) => {{
* // Stuff stuff stuff.
* }}
* }
* include!("path/to/helper.rs")
* }
* ```
*
*/
"""
PSEUDO_ELEMENT_MACRO_INVOCATION = """
pseudo_element!(\"{}\",
atom!(\"{}\"),
{});
"""[1:]
def write_pseudo_element_helper(atoms, target_filename):
with open(target_filename, "wb") as f:
f.write(PRELUDE)
f.write(PSEUDO_ELEMENT_HEADER)
f.write("{\n")
for atom in atoms:
if atom.type() == "nsICSSPseudoElement":
f.write(PSEUDO_ELEMENT_MACRO_INVOCATION.format(atom.value, atom.value, "false"))
elif atom.type() == "nsICSSAnonBoxPseudo":
f.write(PSEUDO_ELEMENT_MACRO_INVOCATION.format(atom.value, atom.value, "true"))
f.write("}\n")
def build(objdir, verbose=False):
atoms = collect_atoms(objdir)
write_atom_macro(atoms, "../string_cache/atom_macro.rs")
write_pseudo_element_helper(atoms, "../../../components/style/generated/gecko_pseudo_element_helper.rs")
return 0

View file

@ -181,6 +181,7 @@ pub const NS_ERROR_MODULE_DOM_BLUETOOTH: ::std::os::raw::c_uint = 37;
pub const NS_ERROR_MODULE_SIGNED_APP: ::std::os::raw::c_uint = 38;
pub const NS_ERROR_MODULE_DOM_ANIM: ::std::os::raw::c_uint = 39;
pub const NS_ERROR_MODULE_DOM_PUSH: ::std::os::raw::c_uint = 40;
pub const NS_ERROR_MODULE_DOM_MEDIA: ::std::os::raw::c_uint = 41;
pub const NS_ERROR_MODULE_GENERAL: ::std::os::raw::c_uint = 51;
pub const NS_ERROR_SEVERITY_SUCCESS: ::std::os::raw::c_uint = 0;
pub const NS_ERROR_SEVERITY_ERROR: ::std::os::raw::c_uint = 1;
@ -188,6 +189,12 @@ pub const NS_ERROR_MODULE_BASE_OFFSET: ::std::os::raw::c_uint = 69;
pub const MOZ_STRING_WITH_OBSOLETE_API: ::std::os::raw::c_uint = 1;
pub const NSID_LENGTH: ::std::os::raw::c_uint = 39;
pub const NS_NUMBER_OF_FLAGS_IN_REFCNT: ::std::os::raw::c_uint = 2;
pub const _STL_PAIR_H: ::std::os::raw::c_uint = 1;
pub const _GLIBCXX_UTILITY: ::std::os::raw::c_uint = 1;
pub const __cpp_lib_tuple_element_t: ::std::os::raw::c_uint = 201402;
pub const __cpp_lib_tuples_by_type: ::std::os::raw::c_uint = 201304;
pub const __cpp_lib_exchange_function: ::std::os::raw::c_uint = 201304;
pub const __cpp_lib_integer_sequence: ::std::os::raw::c_uint = 201304;
pub const NS_EVENT_STATE_HIGHEST_SERVO_BIT: ::std::os::raw::c_uint = 6;
pub const DOM_USER_DATA: ::std::os::raw::c_uint = 1;
pub const SMIL_MAPPED_ATTR_ANIMVAL: ::std::os::raw::c_uint = 2;
@ -206,17 +213,6 @@ pub const NS_CORNER_BOTTOM_RIGHT_X: ::std::os::raw::c_uint = 4;
pub const NS_CORNER_BOTTOM_RIGHT_Y: ::std::os::raw::c_uint = 5;
pub const NS_CORNER_BOTTOM_LEFT_X: ::std::os::raw::c_uint = 6;
pub const NS_CORNER_BOTTOM_LEFT_Y: ::std::os::raw::c_uint = 7;
pub const NS_STYLE_USER_SELECT_NONE: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_USER_SELECT_TEXT: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_USER_SELECT_ELEMENT: ::std::os::raw::c_uint = 2;
pub const NS_STYLE_USER_SELECT_ELEMENTS: ::std::os::raw::c_uint = 3;
pub const NS_STYLE_USER_SELECT_ALL: ::std::os::raw::c_uint = 4;
pub const NS_STYLE_USER_SELECT_TOGGLE: ::std::os::raw::c_uint = 5;
pub const NS_STYLE_USER_SELECT_TRI_STATE: ::std::os::raw::c_uint = 6;
pub const NS_STYLE_USER_SELECT_AUTO: ::std::os::raw::c_uint = 7;
pub const NS_STYLE_USER_SELECT_MOZ_ALL: ::std::os::raw::c_uint = 8;
pub const NS_STYLE_USER_SELECT_MOZ_NONE: ::std::os::raw::c_uint = 9;
pub const NS_STYLE_USER_SELECT_MOZ_TEXT: ::std::os::raw::c_uint = 10;
pub const NS_STYLE_USER_INPUT_NONE: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_USER_INPUT_ENABLED: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_USER_INPUT_DISABLED: ::std::os::raw::c_uint = 2;
@ -1237,6 +1233,7 @@ pub enum nsresult {
NS_ERROR_DOM_UNKNOWN_ERR = -2142044130,
NS_ERROR_DOM_DATA_ERR = -2142044129,
NS_ERROR_DOM_OPERATION_ERR = -2142044128,
NS_ERROR_DOM_NOT_ALLOWED_ERR = -2142044127,
NS_ERROR_DOM_SECMAN_ERR = -2142043159,
NS_ERROR_DOM_WRONG_TYPE_ERR = -2142043158,
NS_ERROR_DOM_NOT_OBJECT_ERR = -2142043157,
@ -1467,6 +1464,9 @@ pub enum nsresult {
NS_ERROR_DOM_PUSH_SERVICE_UNREACHABLE = -2140340220,
NS_ERROR_DOM_PUSH_INVALID_KEY_ERR = -2140340219,
NS_ERROR_DOM_PUSH_MISMATCHED_KEY_ERR = -2140340218,
NS_ERROR_DOM_MEDIA_ABORT_ERR = -2140274687,
NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR = -2140274686,
NS_ERROR_DOM_MEDIA_NOT_SUPPORTED_ERR = -2140274685,
NS_ERROR_DOWNLOAD_COMPLETE = -2139619327,
NS_ERROR_DOWNLOAD_NOT_PARTIAL = -2139619326,
NS_ERROR_UNORM_MOREOUTPUT = -2139619295,
@ -2172,6 +2172,32 @@ pub struct nsTArrayHeader {
pub mLength: u32,
pub _bitfield_1: u32,
}
impl nsTArrayHeader {
#[inline]
pub fn mCapacity(&self) -> u32 {
(self._bitfield_1 & (2147483647usize as u32)) >> 0usize
}
#[inline]
pub fn set_mCapacity(&mut self, val: u32) {
self._bitfield_1 &= !(2147483647usize as u32);
self._bitfield_1 |=
((val as u32) << 0usize) & (2147483647usize as u32);
}
#[inline]
pub fn mIsAutoArray(&self) -> u32 {
(self._bitfield_1 & (2147483648usize as u32)) >> 31usize
}
#[inline]
pub fn set_mIsAutoArray(&mut self, val: bool) {
self._bitfield_1 &= !(2147483648usize as u32);
self._bitfield_1 |=
((val as u32) << 31usize) & (2147483648usize as u32);
}
#[inline]
pub fn new_bitfield_1(mCapacity: u32, mIsAutoArray: bool) -> u32 {
0 | ((mCapacity as u32) << 0u32) | ((mIsAutoArray as u32) << 31u32)
}
}
impl ::std::clone::Clone for nsTArrayHeader {
fn clone(&self) -> Self { *self }
}
@ -2467,6 +2493,32 @@ pub struct nsIAtom {
pub struct _vftable_nsIAtom {
pub _base: _vftable_nsISupports,
}
impl nsIAtom {
#[inline]
pub fn mLength(&self) -> u32 {
(self._bitfield_1 & (2147483647usize as u32)) >> 0usize
}
#[inline]
pub fn set_mLength(&mut self, val: u32) {
self._bitfield_1 &= !(2147483647usize as u32);
self._bitfield_1 |=
((val as u32) << 0usize) & (2147483647usize as u32);
}
#[inline]
pub fn mIsStatic(&self) -> u32 {
(self._bitfield_1 & (2147483648usize as u32)) >> 31usize
}
#[inline]
pub fn set_mIsStatic(&mut self, val: bool) {
self._bitfield_1 &= !(2147483648usize as u32);
self._bitfield_1 |=
((val as u32) << 31usize) & (2147483648usize as u32);
}
#[inline]
pub fn new_bitfield_1(mLength: u32, mIsStatic: bool) -> u32 {
0 | ((mLength as u32) << 0u32) | ((mIsStatic as u32) << 31u32)
}
}
impl ::std::clone::Clone for nsIAtom {
fn clone(&self) -> Self { *self }
}
@ -2745,6 +2797,12 @@ impl ::std::clone::Clone for nsIExpandedPrincipal {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _Make_integer_sequence<_Tp, _ISeq> {
pub _phantom0: ::std::marker::PhantomData<_Tp>,
pub _phantom1: ::std::marker::PhantomData<_ISeq>,
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct nsIURI {
pub _base: nsISupports,
@ -2796,7 +2854,7 @@ impl ::std::clone::Clone for nsIRequest {
#[repr(C)]
#[derive(Debug, Copy)]
pub struct EventStates {
pub mStates: ::std::os::raw::c_ulonglong,
pub mStates: ::std::os::raw::c_ulong,
}
impl ::std::clone::Clone for EventStates {
fn clone(&self) -> Self { *self }
@ -2926,7 +2984,7 @@ fn bindgen_test_layout_nsMutationGuard() {
extern "C" {
#[link_name = "_ZN15nsMutationGuard11sGenerationE"]
pub static mut nsMutationGuard_consts_sGeneration:
::std::os::raw::c_ulonglong;
::std::os::raw::c_ulong;
}
pub type Float = f32;
#[repr(i8)]
@ -3980,6 +4038,20 @@ pub enum StyleUserFocus {
SelectSame = 6,
SelectMenu = 7,
}
#[repr(i8)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum StyleUserSelect {
None_ = 0,
Text = 1,
Element = 2,
Elements = 3,
All = 4,
Toggle = 5,
TriState = 6,
Auto = 7,
MozAll = 8,
MozText = 9,
}
pub const eCSSProperty_COUNT_DUMMY: nsCSSProperty =
nsCSSProperty::eCSSProperty_z_index;
pub const eCSSProperty_all: nsCSSProperty =
@ -4728,7 +4800,91 @@ pub struct nsCSSValue_nsCSSValue_h_unnamed_13 {
pub mFontFamilyList: __BindgenUnionField<*mut FontFamilyListRefCnt>,
pub _bindgen_data_: u64,
}
impl nsCSSValue_nsCSSValue_h_unnamed_13 { }
impl nsCSSValue_nsCSSValue_h_unnamed_13 {
pub unsafe fn mInt(&mut self) -> *mut i32 {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mFloat(&mut self) -> *mut f32 {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mString(&mut self) -> *mut *mut nsStringBuffer {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mColor(&mut self) -> *mut nscolor {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mArray(&mut self) -> *mut *mut Array {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mURL(&mut self) -> *mut *mut URLValue {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mImage(&mut self) -> *mut *mut ImageValue {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mGridTemplateAreas(&mut self)
-> *mut *mut GridTemplateAreasValue {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mGradient(&mut self) -> *mut *mut nsCSSValueGradient {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mTokenStream(&mut self) -> *mut *mut nsCSSValueTokenStream {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mPair(&mut self) -> *mut *mut nsCSSValuePair_heap {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mRect(&mut self) -> *mut *mut nsCSSRect_heap {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mTriplet(&mut self) -> *mut *mut nsCSSValueTriplet_heap {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mList(&mut self) -> *mut *mut nsCSSValueList_heap {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mListDependent(&mut self) -> *mut *mut nsCSSValueList {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mSharedList(&mut self) -> *mut *mut nsCSSValueSharedList {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mPairList(&mut self) -> *mut *mut nsCSSValuePairList_heap {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mPairListDependent(&mut self)
-> *mut *mut nsCSSValuePairList {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mFloatColor(&mut self) -> *mut *mut nsCSSValueFloatColor {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mFontFamilyList(&mut self)
-> *mut *mut FontFamilyListRefCnt {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsCSSValue_nsCSSValue_h_unnamed_13 {
fn clone(&self) -> Self { *self }
}
@ -5190,7 +5346,20 @@ pub struct nsStyleCoord_h_unnamed_18 {
pub mPointer: __BindgenUnionField<*mut ::std::os::raw::c_void>,
pub _bindgen_data_: u64,
}
impl nsStyleCoord_h_unnamed_18 { }
impl nsStyleCoord_h_unnamed_18 {
pub unsafe fn mInt(&mut self) -> *mut i32 {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mFloat(&mut self) -> *mut f32 {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mPointer(&mut self) -> *mut *mut ::std::os::raw::c_void {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsStyleCoord_h_unnamed_18 {
fn clone(&self) -> Self { *self }
}
@ -5468,7 +5637,21 @@ pub struct nsStyleImage_nsStyleStruct_h_unnamed_21 {
pub mElementId: __BindgenUnionField<*mut ::std::os::raw::c_ushort>,
pub _bindgen_data_: u64,
}
impl nsStyleImage_nsStyleStruct_h_unnamed_21 { }
impl nsStyleImage_nsStyleStruct_h_unnamed_21 {
pub unsafe fn mImage(&mut self) -> *mut *mut imgRequestProxy {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mGradient(&mut self) -> *mut *mut nsStyleGradient {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mElementId(&mut self)
-> *mut *mut ::std::os::raw::c_ushort {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsStyleImage_nsStyleStruct_h_unnamed_21 {
fn clone(&self) -> Self { *self }
}
@ -5821,6 +6004,30 @@ pub struct nsStyleGridTemplate {
pub mRepeatAutoIndex: i16,
pub _bitfield_1: u8,
}
impl nsStyleGridTemplate {
#[inline]
pub fn mIsAutoFill(&self) -> u8 {
(self._bitfield_1 & (1usize as u8)) >> 0usize
}
#[inline]
pub fn set_mIsAutoFill(&mut self, val: bool) {
self._bitfield_1 &= !(1usize as u8);
self._bitfield_1 |= ((val as u8) << 0usize) & (1usize as u8);
}
#[inline]
pub fn mIsSubgrid(&self) -> u8 {
(self._bitfield_1 & (2usize as u8)) >> 1usize
}
#[inline]
pub fn set_mIsSubgrid(&mut self, val: bool) {
self._bitfield_1 &= !(2usize as u8);
self._bitfield_1 |= ((val as u8) << 1usize) & (2usize as u8);
}
#[inline]
pub fn new_bitfield_1(mIsAutoFill: bool, mIsSubgrid: bool) -> u8 {
0 | ((mIsAutoFill as u8) << 0u32) | ((mIsSubgrid as u8) << 1u32)
}
}
#[test]
fn bindgen_test_layout_nsStyleGridTemplate() {
assert_eq!(::std::mem::size_of::<nsStyleGridTemplate>() , 48usize);
@ -5942,6 +6149,64 @@ pub struct nsStyleText {
pub mTextShadow: RefPtr<nsCSSShadowArray>,
pub mTextEmphasisStyleString: nsString,
}
impl nsStyleText {
#[inline]
pub fn mTextAlignTrue(&self) -> u8 {
(self._bitfield_1 & (1usize as u8)) >> 0usize
}
#[inline]
pub fn set_mTextAlignTrue(&mut self, val: bool) {
self._bitfield_1 &= !(1usize as u8);
self._bitfield_1 |= ((val as u8) << 0usize) & (1usize as u8);
}
#[inline]
pub fn mTextAlignLastTrue(&self) -> u8 {
(self._bitfield_1 & (2usize as u8)) >> 1usize
}
#[inline]
pub fn set_mTextAlignLastTrue(&mut self, val: bool) {
self._bitfield_1 &= !(2usize as u8);
self._bitfield_1 |= ((val as u8) << 1usize) & (2usize as u8);
}
#[inline]
pub fn mTextEmphasisColorForeground(&self) -> u8 {
(self._bitfield_1 & (4usize as u8)) >> 2usize
}
#[inline]
pub fn set_mTextEmphasisColorForeground(&mut self, val: bool) {
self._bitfield_1 &= !(4usize as u8);
self._bitfield_1 |= ((val as u8) << 2usize) & (4usize as u8);
}
#[inline]
pub fn mWebkitTextFillColorForeground(&self) -> u8 {
(self._bitfield_1 & (8usize as u8)) >> 3usize
}
#[inline]
pub fn set_mWebkitTextFillColorForeground(&mut self, val: bool) {
self._bitfield_1 &= !(8usize as u8);
self._bitfield_1 |= ((val as u8) << 3usize) & (8usize as u8);
}
#[inline]
pub fn mWebkitTextStrokeColorForeground(&self) -> u8 {
(self._bitfield_1 & (16usize as u8)) >> 4usize
}
#[inline]
pub fn set_mWebkitTextStrokeColorForeground(&mut self, val: bool) {
self._bitfield_1 &= !(16usize as u8);
self._bitfield_1 |= ((val as u8) << 4usize) & (16usize as u8);
}
#[inline]
pub fn new_bitfield_1(mTextAlignTrue: bool, mTextAlignLastTrue: bool,
mTextEmphasisColorForeground: bool,
mWebkitTextFillColorForeground: bool,
mWebkitTextStrokeColorForeground: bool) -> u8 {
0 | ((mTextAlignTrue as u8) << 0u32) |
((mTextAlignLastTrue as u8) << 1u32) |
((mTextEmphasisColorForeground as u8) << 2u32) |
((mWebkitTextFillColorForeground as u8) << 3u32) |
((mWebkitTextStrokeColorForeground as u8) << 4u32)
}
}
#[test]
fn bindgen_test_layout_nsStyleText() {
assert_eq!(::std::mem::size_of::<nsStyleText>() , 136usize);
@ -6019,7 +6284,20 @@ pub struct nsTimingFunction_nsStyleStruct_h_unnamed_23 {
pub nsTimingFunction_nsStyleStruct_h_unnamed_23_nsStyleStruct_h_unnamed_25: __BindgenUnionField<nsTimingFunction_nsStyleStruct_h_unnamed_23_nsStyleStruct_h_unnamed_25>,
pub _bindgen_data_: [u32; 4usize],
}
impl nsTimingFunction_nsStyleStruct_h_unnamed_23 { }
impl nsTimingFunction_nsStyleStruct_h_unnamed_23 {
pub unsafe fn mFunc(&mut self)
->
*mut nsTimingFunction_nsStyleStruct_h_unnamed_23_nsStyleStruct_h_unnamed_24 {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn nsTimingFunction_nsStyleStruct_h_unnamed_23_nsStyleStruct_h_unnamed_25(&mut self)
->
*mut nsTimingFunction_nsStyleStruct_h_unnamed_23_nsStyleStruct_h_unnamed_25 {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsTimingFunction_nsStyleStruct_h_unnamed_23 {
fn clone(&self) -> Self { *self }
}
@ -6255,7 +6533,20 @@ pub struct nsStyleContentData_nsStyleStruct_h_unnamed_27 {
pub mCounters: __BindgenUnionField<*mut Array>,
pub _bindgen_data_: u64,
}
impl nsStyleContentData_nsStyleStruct_h_unnamed_27 { }
impl nsStyleContentData_nsStyleStruct_h_unnamed_27 {
pub unsafe fn mString(&mut self) -> *mut *mut ::std::os::raw::c_ushort {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mImage(&mut self) -> *mut *mut imgRequestProxy {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mCounters(&mut self) -> *mut *mut Array {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsStyleContentData_nsStyleStruct_h_unnamed_27 {
fn clone(&self) -> Self { *self }
}
@ -6301,7 +6592,7 @@ fn bindgen_test_layout_nsStyleContent() {
#[repr(C)]
#[derive(Debug)]
pub struct nsStyleUIReset {
pub mUserSelect: u8,
pub mUserSelect: StyleUserSelect,
pub mForceBrokenImageIcon: u8,
pub mIMEMode: u8,
pub mWindowDragging: u8,
@ -6408,7 +6699,16 @@ pub struct nsStyleSVGPaint_nsStyleStruct_h_unnamed_28 {
pub mPaintServer: __BindgenUnionField<*mut FragmentOrURL>,
pub _bindgen_data_: u64,
}
impl nsStyleSVGPaint_nsStyleStruct_h_unnamed_28 { }
impl nsStyleSVGPaint_nsStyleStruct_h_unnamed_28 {
pub unsafe fn mColor(&mut self) -> *mut nscolor {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mPaintServer(&mut self) -> *mut *mut FragmentOrURL {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsStyleSVGPaint_nsStyleStruct_h_unnamed_28 {
fn clone(&self) -> Self { *self }
}
@ -6479,7 +6779,16 @@ pub struct nsStyleFilter_nsStyleStruct_h_unnamed_30 {
pub mDropShadow: __BindgenUnionField<*mut nsCSSShadowArray>,
pub _bindgen_data_: u64,
}
impl nsStyleFilter_nsStyleStruct_h_unnamed_30 { }
impl nsStyleFilter_nsStyleStruct_h_unnamed_30 {
pub unsafe fn mURL(&mut self) -> *mut *mut FragmentOrURL {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mDropShadow(&mut self) -> *mut *mut nsCSSShadowArray {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsStyleFilter_nsStyleStruct_h_unnamed_30 {
fn clone(&self) -> Self { *self }
}

View file

@ -181,6 +181,7 @@ pub const NS_ERROR_MODULE_DOM_BLUETOOTH: ::std::os::raw::c_uint = 37;
pub const NS_ERROR_MODULE_SIGNED_APP: ::std::os::raw::c_uint = 38;
pub const NS_ERROR_MODULE_DOM_ANIM: ::std::os::raw::c_uint = 39;
pub const NS_ERROR_MODULE_DOM_PUSH: ::std::os::raw::c_uint = 40;
pub const NS_ERROR_MODULE_DOM_MEDIA: ::std::os::raw::c_uint = 41;
pub const NS_ERROR_MODULE_GENERAL: ::std::os::raw::c_uint = 51;
pub const NS_ERROR_SEVERITY_SUCCESS: ::std::os::raw::c_uint = 0;
pub const NS_ERROR_SEVERITY_ERROR: ::std::os::raw::c_uint = 1;
@ -188,6 +189,12 @@ pub const NS_ERROR_MODULE_BASE_OFFSET: ::std::os::raw::c_uint = 69;
pub const MOZ_STRING_WITH_OBSOLETE_API: ::std::os::raw::c_uint = 1;
pub const NSID_LENGTH: ::std::os::raw::c_uint = 39;
pub const NS_NUMBER_OF_FLAGS_IN_REFCNT: ::std::os::raw::c_uint = 2;
pub const _STL_PAIR_H: ::std::os::raw::c_uint = 1;
pub const _GLIBCXX_UTILITY: ::std::os::raw::c_uint = 1;
pub const __cpp_lib_tuple_element_t: ::std::os::raw::c_uint = 201402;
pub const __cpp_lib_tuples_by_type: ::std::os::raw::c_uint = 201304;
pub const __cpp_lib_exchange_function: ::std::os::raw::c_uint = 201304;
pub const __cpp_lib_integer_sequence: ::std::os::raw::c_uint = 201304;
pub const NS_EVENT_STATE_HIGHEST_SERVO_BIT: ::std::os::raw::c_uint = 6;
pub const DOM_USER_DATA: ::std::os::raw::c_uint = 1;
pub const SMIL_MAPPED_ATTR_ANIMVAL: ::std::os::raw::c_uint = 2;
@ -206,17 +213,6 @@ pub const NS_CORNER_BOTTOM_RIGHT_X: ::std::os::raw::c_uint = 4;
pub const NS_CORNER_BOTTOM_RIGHT_Y: ::std::os::raw::c_uint = 5;
pub const NS_CORNER_BOTTOM_LEFT_X: ::std::os::raw::c_uint = 6;
pub const NS_CORNER_BOTTOM_LEFT_Y: ::std::os::raw::c_uint = 7;
pub const NS_STYLE_USER_SELECT_NONE: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_USER_SELECT_TEXT: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_USER_SELECT_ELEMENT: ::std::os::raw::c_uint = 2;
pub const NS_STYLE_USER_SELECT_ELEMENTS: ::std::os::raw::c_uint = 3;
pub const NS_STYLE_USER_SELECT_ALL: ::std::os::raw::c_uint = 4;
pub const NS_STYLE_USER_SELECT_TOGGLE: ::std::os::raw::c_uint = 5;
pub const NS_STYLE_USER_SELECT_TRI_STATE: ::std::os::raw::c_uint = 6;
pub const NS_STYLE_USER_SELECT_AUTO: ::std::os::raw::c_uint = 7;
pub const NS_STYLE_USER_SELECT_MOZ_ALL: ::std::os::raw::c_uint = 8;
pub const NS_STYLE_USER_SELECT_MOZ_NONE: ::std::os::raw::c_uint = 9;
pub const NS_STYLE_USER_SELECT_MOZ_TEXT: ::std::os::raw::c_uint = 10;
pub const NS_STYLE_USER_INPUT_NONE: ::std::os::raw::c_uint = 0;
pub const NS_STYLE_USER_INPUT_ENABLED: ::std::os::raw::c_uint = 1;
pub const NS_STYLE_USER_INPUT_DISABLED: ::std::os::raw::c_uint = 2;
@ -1237,6 +1233,7 @@ pub enum nsresult {
NS_ERROR_DOM_UNKNOWN_ERR = -2142044130,
NS_ERROR_DOM_DATA_ERR = -2142044129,
NS_ERROR_DOM_OPERATION_ERR = -2142044128,
NS_ERROR_DOM_NOT_ALLOWED_ERR = -2142044127,
NS_ERROR_DOM_SECMAN_ERR = -2142043159,
NS_ERROR_DOM_WRONG_TYPE_ERR = -2142043158,
NS_ERROR_DOM_NOT_OBJECT_ERR = -2142043157,
@ -1467,6 +1464,9 @@ pub enum nsresult {
NS_ERROR_DOM_PUSH_SERVICE_UNREACHABLE = -2140340220,
NS_ERROR_DOM_PUSH_INVALID_KEY_ERR = -2140340219,
NS_ERROR_DOM_PUSH_MISMATCHED_KEY_ERR = -2140340218,
NS_ERROR_DOM_MEDIA_ABORT_ERR = -2140274687,
NS_ERROR_DOM_MEDIA_NOT_ALLOWED_ERR = -2140274686,
NS_ERROR_DOM_MEDIA_NOT_SUPPORTED_ERR = -2140274685,
NS_ERROR_DOWNLOAD_COMPLETE = -2139619327,
NS_ERROR_DOWNLOAD_NOT_PARTIAL = -2139619326,
NS_ERROR_UNORM_MOREOUTPUT = -2139619295,
@ -2172,6 +2172,32 @@ pub struct nsTArrayHeader {
pub mLength: u32,
pub _bitfield_1: u32,
}
impl nsTArrayHeader {
#[inline]
pub fn mCapacity(&self) -> u32 {
(self._bitfield_1 & (2147483647usize as u32)) >> 0usize
}
#[inline]
pub fn set_mCapacity(&mut self, val: u32) {
self._bitfield_1 &= !(2147483647usize as u32);
self._bitfield_1 |=
((val as u32) << 0usize) & (2147483647usize as u32);
}
#[inline]
pub fn mIsAutoArray(&self) -> u32 {
(self._bitfield_1 & (2147483648usize as u32)) >> 31usize
}
#[inline]
pub fn set_mIsAutoArray(&mut self, val: bool) {
self._bitfield_1 &= !(2147483648usize as u32);
self._bitfield_1 |=
((val as u32) << 31usize) & (2147483648usize as u32);
}
#[inline]
pub fn new_bitfield_1(mCapacity: u32, mIsAutoArray: bool) -> u32 {
0 | ((mCapacity as u32) << 0u32) | ((mIsAutoArray as u32) << 31u32)
}
}
impl ::std::clone::Clone for nsTArrayHeader {
fn clone(&self) -> Self { *self }
}
@ -2468,6 +2494,32 @@ pub struct nsIAtom {
pub struct _vftable_nsIAtom {
pub _base: _vftable_nsISupports,
}
impl nsIAtom {
#[inline]
pub fn mLength(&self) -> u32 {
(self._bitfield_1 & (2147483647usize as u32)) >> 0usize
}
#[inline]
pub fn set_mLength(&mut self, val: u32) {
self._bitfield_1 &= !(2147483647usize as u32);
self._bitfield_1 |=
((val as u32) << 0usize) & (2147483647usize as u32);
}
#[inline]
pub fn mIsStatic(&self) -> u32 {
(self._bitfield_1 & (2147483648usize as u32)) >> 31usize
}
#[inline]
pub fn set_mIsStatic(&mut self, val: bool) {
self._bitfield_1 &= !(2147483648usize as u32);
self._bitfield_1 |=
((val as u32) << 31usize) & (2147483648usize as u32);
}
#[inline]
pub fn new_bitfield_1(mLength: u32, mIsStatic: bool) -> u32 {
0 | ((mLength as u32) << 0u32) | ((mIsStatic as u32) << 31u32)
}
}
impl ::std::clone::Clone for nsIAtom {
fn clone(&self) -> Self { *self }
}
@ -2724,6 +2776,12 @@ impl ::std::clone::Clone for nsIExpandedPrincipal {
fn clone(&self) -> Self { *self }
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct _Make_integer_sequence<_Tp, _ISeq> {
pub _phantom0: ::std::marker::PhantomData<_Tp>,
pub _phantom1: ::std::marker::PhantomData<_ISeq>,
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct nsIURI {
pub _base: nsISupports,
@ -2775,7 +2833,7 @@ impl ::std::clone::Clone for nsIRequest {
#[repr(C)]
#[derive(Debug, Copy)]
pub struct EventStates {
pub mStates: ::std::os::raw::c_ulonglong,
pub mStates: ::std::os::raw::c_ulong,
}
impl ::std::clone::Clone for EventStates {
fn clone(&self) -> Self { *self }
@ -2905,7 +2963,7 @@ fn bindgen_test_layout_nsMutationGuard() {
extern "C" {
#[link_name = "_ZN15nsMutationGuard11sGenerationE"]
pub static mut nsMutationGuard_consts_sGeneration:
::std::os::raw::c_ulonglong;
::std::os::raw::c_ulong;
}
pub type Float = f32;
#[repr(i8)]
@ -3959,6 +4017,20 @@ pub enum StyleUserFocus {
SelectSame = 6,
SelectMenu = 7,
}
#[repr(i8)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub enum StyleUserSelect {
None_ = 0,
Text = 1,
Element = 2,
Elements = 3,
All = 4,
Toggle = 5,
TriState = 6,
Auto = 7,
MozAll = 8,
MozText = 9,
}
pub const eCSSProperty_COUNT_DUMMY: nsCSSProperty =
nsCSSProperty::eCSSProperty_z_index;
pub const eCSSProperty_all: nsCSSProperty =
@ -4707,7 +4779,91 @@ pub struct nsCSSValue_nsCSSValue_h_unnamed_13 {
pub mFontFamilyList: __BindgenUnionField<*mut FontFamilyListRefCnt>,
pub _bindgen_data_: u64,
}
impl nsCSSValue_nsCSSValue_h_unnamed_13 { }
impl nsCSSValue_nsCSSValue_h_unnamed_13 {
pub unsafe fn mInt(&mut self) -> *mut i32 {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mFloat(&mut self) -> *mut f32 {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mString(&mut self) -> *mut *mut nsStringBuffer {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mColor(&mut self) -> *mut nscolor {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mArray(&mut self) -> *mut *mut Array {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mURL(&mut self) -> *mut *mut URLValue {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mImage(&mut self) -> *mut *mut ImageValue {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mGridTemplateAreas(&mut self)
-> *mut *mut GridTemplateAreasValue {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mGradient(&mut self) -> *mut *mut nsCSSValueGradient {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mTokenStream(&mut self) -> *mut *mut nsCSSValueTokenStream {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mPair(&mut self) -> *mut *mut nsCSSValuePair_heap {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mRect(&mut self) -> *mut *mut nsCSSRect_heap {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mTriplet(&mut self) -> *mut *mut nsCSSValueTriplet_heap {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mList(&mut self) -> *mut *mut nsCSSValueList_heap {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mListDependent(&mut self) -> *mut *mut nsCSSValueList {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mSharedList(&mut self) -> *mut *mut nsCSSValueSharedList {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mPairList(&mut self) -> *mut *mut nsCSSValuePairList_heap {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mPairListDependent(&mut self)
-> *mut *mut nsCSSValuePairList {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mFloatColor(&mut self) -> *mut *mut nsCSSValueFloatColor {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mFontFamilyList(&mut self)
-> *mut *mut FontFamilyListRefCnt {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsCSSValue_nsCSSValue_h_unnamed_13 {
fn clone(&self) -> Self { *self }
}
@ -5169,7 +5325,20 @@ pub struct nsStyleCoord_h_unnamed_18 {
pub mPointer: __BindgenUnionField<*mut ::std::os::raw::c_void>,
pub _bindgen_data_: u64,
}
impl nsStyleCoord_h_unnamed_18 { }
impl nsStyleCoord_h_unnamed_18 {
pub unsafe fn mInt(&mut self) -> *mut i32 {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mFloat(&mut self) -> *mut f32 {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mPointer(&mut self) -> *mut *mut ::std::os::raw::c_void {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsStyleCoord_h_unnamed_18 {
fn clone(&self) -> Self { *self }
}
@ -5446,7 +5615,21 @@ pub struct nsStyleImage_nsStyleStruct_h_unnamed_21 {
pub mElementId: __BindgenUnionField<*mut ::std::os::raw::c_ushort>,
pub _bindgen_data_: u64,
}
impl nsStyleImage_nsStyleStruct_h_unnamed_21 { }
impl nsStyleImage_nsStyleStruct_h_unnamed_21 {
pub unsafe fn mImage(&mut self) -> *mut *mut imgRequestProxy {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mGradient(&mut self) -> *mut *mut nsStyleGradient {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mElementId(&mut self)
-> *mut *mut ::std::os::raw::c_ushort {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsStyleImage_nsStyleStruct_h_unnamed_21 {
fn clone(&self) -> Self { *self }
}
@ -5799,6 +5982,30 @@ pub struct nsStyleGridTemplate {
pub mRepeatAutoIndex: i16,
pub _bitfield_1: u8,
}
impl nsStyleGridTemplate {
#[inline]
pub fn mIsAutoFill(&self) -> u8 {
(self._bitfield_1 & (1usize as u8)) >> 0usize
}
#[inline]
pub fn set_mIsAutoFill(&mut self, val: bool) {
self._bitfield_1 &= !(1usize as u8);
self._bitfield_1 |= ((val as u8) << 0usize) & (1usize as u8);
}
#[inline]
pub fn mIsSubgrid(&self) -> u8 {
(self._bitfield_1 & (2usize as u8)) >> 1usize
}
#[inline]
pub fn set_mIsSubgrid(&mut self, val: bool) {
self._bitfield_1 &= !(2usize as u8);
self._bitfield_1 |= ((val as u8) << 1usize) & (2usize as u8);
}
#[inline]
pub fn new_bitfield_1(mIsAutoFill: bool, mIsSubgrid: bool) -> u8 {
0 | ((mIsAutoFill as u8) << 0u32) | ((mIsSubgrid as u8) << 1u32)
}
}
#[test]
fn bindgen_test_layout_nsStyleGridTemplate() {
assert_eq!(::std::mem::size_of::<nsStyleGridTemplate>() , 48usize);
@ -5920,6 +6127,64 @@ pub struct nsStyleText {
pub mTextShadow: RefPtr<nsCSSShadowArray>,
pub mTextEmphasisStyleString: nsString,
}
impl nsStyleText {
#[inline]
pub fn mTextAlignTrue(&self) -> u8 {
(self._bitfield_1 & (1usize as u8)) >> 0usize
}
#[inline]
pub fn set_mTextAlignTrue(&mut self, val: bool) {
self._bitfield_1 &= !(1usize as u8);
self._bitfield_1 |= ((val as u8) << 0usize) & (1usize as u8);
}
#[inline]
pub fn mTextAlignLastTrue(&self) -> u8 {
(self._bitfield_1 & (2usize as u8)) >> 1usize
}
#[inline]
pub fn set_mTextAlignLastTrue(&mut self, val: bool) {
self._bitfield_1 &= !(2usize as u8);
self._bitfield_1 |= ((val as u8) << 1usize) & (2usize as u8);
}
#[inline]
pub fn mTextEmphasisColorForeground(&self) -> u8 {
(self._bitfield_1 & (4usize as u8)) >> 2usize
}
#[inline]
pub fn set_mTextEmphasisColorForeground(&mut self, val: bool) {
self._bitfield_1 &= !(4usize as u8);
self._bitfield_1 |= ((val as u8) << 2usize) & (4usize as u8);
}
#[inline]
pub fn mWebkitTextFillColorForeground(&self) -> u8 {
(self._bitfield_1 & (8usize as u8)) >> 3usize
}
#[inline]
pub fn set_mWebkitTextFillColorForeground(&mut self, val: bool) {
self._bitfield_1 &= !(8usize as u8);
self._bitfield_1 |= ((val as u8) << 3usize) & (8usize as u8);
}
#[inline]
pub fn mWebkitTextStrokeColorForeground(&self) -> u8 {
(self._bitfield_1 & (16usize as u8)) >> 4usize
}
#[inline]
pub fn set_mWebkitTextStrokeColorForeground(&mut self, val: bool) {
self._bitfield_1 &= !(16usize as u8);
self._bitfield_1 |= ((val as u8) << 4usize) & (16usize as u8);
}
#[inline]
pub fn new_bitfield_1(mTextAlignTrue: bool, mTextAlignLastTrue: bool,
mTextEmphasisColorForeground: bool,
mWebkitTextFillColorForeground: bool,
mWebkitTextStrokeColorForeground: bool) -> u8 {
0 | ((mTextAlignTrue as u8) << 0u32) |
((mTextAlignLastTrue as u8) << 1u32) |
((mTextEmphasisColorForeground as u8) << 2u32) |
((mWebkitTextFillColorForeground as u8) << 3u32) |
((mWebkitTextStrokeColorForeground as u8) << 4u32)
}
}
#[test]
fn bindgen_test_layout_nsStyleText() {
assert_eq!(::std::mem::size_of::<nsStyleText>() , 136usize);
@ -5997,7 +6262,20 @@ pub struct nsTimingFunction_nsStyleStruct_h_unnamed_23 {
pub nsTimingFunction_nsStyleStruct_h_unnamed_23_nsStyleStruct_h_unnamed_25: __BindgenUnionField<nsTimingFunction_nsStyleStruct_h_unnamed_23_nsStyleStruct_h_unnamed_25>,
pub _bindgen_data_: [u32; 4usize],
}
impl nsTimingFunction_nsStyleStruct_h_unnamed_23 { }
impl nsTimingFunction_nsStyleStruct_h_unnamed_23 {
pub unsafe fn mFunc(&mut self)
->
*mut nsTimingFunction_nsStyleStruct_h_unnamed_23_nsStyleStruct_h_unnamed_24 {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn nsTimingFunction_nsStyleStruct_h_unnamed_23_nsStyleStruct_h_unnamed_25(&mut self)
->
*mut nsTimingFunction_nsStyleStruct_h_unnamed_23_nsStyleStruct_h_unnamed_25 {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsTimingFunction_nsStyleStruct_h_unnamed_23 {
fn clone(&self) -> Self { *self }
}
@ -6232,7 +6510,20 @@ pub struct nsStyleContentData_nsStyleStruct_h_unnamed_27 {
pub mCounters: __BindgenUnionField<*mut Array>,
pub _bindgen_data_: u64,
}
impl nsStyleContentData_nsStyleStruct_h_unnamed_27 { }
impl nsStyleContentData_nsStyleStruct_h_unnamed_27 {
pub unsafe fn mString(&mut self) -> *mut *mut ::std::os::raw::c_ushort {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mImage(&mut self) -> *mut *mut imgRequestProxy {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mCounters(&mut self) -> *mut *mut Array {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsStyleContentData_nsStyleStruct_h_unnamed_27 {
fn clone(&self) -> Self { *self }
}
@ -6278,7 +6569,7 @@ fn bindgen_test_layout_nsStyleContent() {
#[repr(C)]
#[derive(Debug)]
pub struct nsStyleUIReset {
pub mUserSelect: u8,
pub mUserSelect: StyleUserSelect,
pub mForceBrokenImageIcon: u8,
pub mIMEMode: u8,
pub mWindowDragging: u8,
@ -6385,7 +6676,16 @@ pub struct nsStyleSVGPaint_nsStyleStruct_h_unnamed_28 {
pub mPaintServer: __BindgenUnionField<*mut FragmentOrURL>,
pub _bindgen_data_: u64,
}
impl nsStyleSVGPaint_nsStyleStruct_h_unnamed_28 { }
impl nsStyleSVGPaint_nsStyleStruct_h_unnamed_28 {
pub unsafe fn mColor(&mut self) -> *mut nscolor {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mPaintServer(&mut self) -> *mut *mut FragmentOrURL {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsStyleSVGPaint_nsStyleStruct_h_unnamed_28 {
fn clone(&self) -> Self { *self }
}
@ -6456,7 +6756,16 @@ pub struct nsStyleFilter_nsStyleStruct_h_unnamed_30 {
pub mDropShadow: __BindgenUnionField<*mut nsCSSShadowArray>,
pub _bindgen_data_: u64,
}
impl nsStyleFilter_nsStyleStruct_h_unnamed_30 { }
impl nsStyleFilter_nsStyleStruct_h_unnamed_30 {
pub unsafe fn mURL(&mut self) -> *mut *mut FragmentOrURL {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
pub unsafe fn mDropShadow(&mut self) -> *mut *mut nsCSSShadowArray {
let raw: *mut u8 = ::std::mem::transmute(&self._bindgen_data_);
::std::mem::transmute(raw.offset(0))
}
}
impl ::std::clone::Clone for nsStyleFilter_nsStyleStruct_h_unnamed_30 {
fn clone(&self) -> Self { *self }
}

View file

@ -16,6 +16,7 @@ use gecko_bindings::ptr::{GeckoArcPrincipal, GeckoArcURI};
use gecko_bindings::structs::ServoElementSnapshot;
use gecko_bindings::structs::nsRestyleHint;
use gecko_bindings::structs::{SheetParsingMode, nsIAtom};
use gecko_string_cache::Atom;
use snapshot::GeckoElementSnapshot;
use std::mem::transmute;
use std::ptr;
@ -39,29 +40,6 @@ use traversal::RecalcStyleOnly;
use url::Url;
use wrapper::{DUMMY_BASE_URL, GeckoDocument, GeckoElement, GeckoNode, NonOpaqueStyleData};
// TODO: This is ugly and should go away once we get an atom back-end.
pub fn pseudo_element_from_atom(pseudo: *mut nsIAtom,
in_ua_stylesheet: bool) -> Result<PseudoElement, String> {
use gecko_bindings::bindings::Gecko_GetAtomAsUTF16;
use selectors::parser::{ParserContext, SelectorImpl};
let pseudo_string = unsafe {
let mut length = 0;
let mut buff = Gecko_GetAtomAsUTF16(pseudo, &mut length);
// Handle the annoying preceding colon in front of everything in nsCSSAnonBoxList.h.
debug_assert!(length >= 2 && *buff == ':' as u16 && *buff.offset(1) != ':' as u16);
buff = buff.offset(1);
length -= 1;
String::from_utf16(slice::from_raw_parts(buff, length as usize)).unwrap()
};
let mut context = ParserContext::new();
context.in_user_agent_stylesheet = in_ua_stylesheet;
GeckoSelectorImpl::parse_pseudo_element(&context, &pseudo_string).map_err(|_| pseudo_string)
}
/*
* For Gecko->Servo function calls, we need to redeclare the same signature that was declared in
* the C header in Gecko. In order to catch accidental mismatches, we run rust-bindgen against
@ -286,13 +264,8 @@ pub extern "C" fn Servo_GetComputedValuesForAnonymousBox(parent_style_or_null: *
let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data);
data.flush_stylesheets();
let pseudo = match pseudo_element_from_atom(pseudo_tag, /* ua_stylesheet = */ true) {
Ok(pseudo) => pseudo,
Err(pseudo) => {
warn!("stylo: Unable to parse anonymous-box pseudo-element: {}", pseudo);
return ptr::null_mut();
}
};
let atom = Atom::from(pseudo_tag);
let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ true);
type Helpers = ArcHelpers<ServoComputedValues, ComputedValues>;
@ -320,14 +293,8 @@ pub extern "C" fn Servo_GetComputedValuesForPseudoElement(parent_style: *mut Ser
}
};
let pseudo = match pseudo_element_from_atom(pseudo_tag, /* ua_stylesheet = */ true) {
Ok(pseudo) => pseudo,
Err(pseudo) => {
warn!("stylo: Unable to parse anonymous-box pseudo-element: {}", pseudo);
return parent_or_null();
}
};
let atom = Atom::from(pseudo_tag);
let pseudo = PseudoElement::from_atom_unchecked(atom, /* anon_box = */ false);
// The stylist consumes stylesheets lazily.
let data = PerDocumentStyleData::borrow_mut_from_raw(raw_data);

View file

@ -42,3 +42,28 @@ fn assert_restyle_hints_match() {
check_enum_value_non_static!(nsRestyleHint::eRestyle_SomeDescendants, RESTYLE_DESCENDANTS.bits());
check_enum_value_non_static!(nsRestyleHint::eRestyle_LaterSiblings, RESTYLE_LATER_SIBLINGS.bits());
}
// Note that we can't call each_pseudo_element, parse_pseudo_element, or
// similar, because we'd need the foreign atom symbols to link.
#[test]
fn assert_basic_pseudo_elements() {
let mut saw_before = false;
let mut saw_after = false;
macro_rules! pseudo_element {
(":before", $atom:expr, false) => {
saw_before = true;
};
(":after", $atom:expr, false) => {
saw_after = true;
};
($pseudo_str_with_colon:expr, $atom:expr, $is_anon_box:expr) => {
// Do nothing
};
}
include!("../../components/style/generated/gecko_pseudo_element_helper.rs");
assert!(saw_before);
assert!(saw_after);
}

File diff suppressed because it is too large Load diff

View file

@ -89,6 +89,7 @@ impl WeakAtom {
Atom::from(self.as_ptr())
}
#[inline]
pub fn get_hash(&self) -> u32 {
self.0.mHash
}
@ -101,28 +102,46 @@ impl WeakAtom {
}
}
pub fn chars(&self) -> DecodeUtf16<Cloned<slice::Iter<u16>>> {
// NOTE: don't expose this, since it's slow, and easy to be misused.
fn chars(&self) -> DecodeUtf16<Cloned<slice::Iter<u16>>> {
char::decode_utf16(self.as_slice().iter().cloned())
}
pub fn with_str<F, Output>(&self, cb: F) -> Output
where F: FnOnce(&str) -> Output {
where F: FnOnce(&str) -> Output
{
// FIXME(bholley): We should measure whether it makes more sense to
// cache the UTF-8 version in the Gecko atom table somehow.
let owned = String::from_utf16(self.as_slice()).unwrap();
cb(&owned)
}
#[inline]
pub fn eq_str_ignore_ascii_case(&self, s: &str) -> bool {
unsafe {
Gecko_AtomEqualsUTF8IgnoreCase(self.as_ptr(), s.as_ptr() as *const _, s.len() as u32)
}
}
#[inline]
pub fn to_string(&self) -> String {
String::from_utf16(self.as_slice()).unwrap()
}
#[inline]
pub fn is_static(&self) -> bool {
unsafe {
(*self.as_ptr()).mIsStatic() != 0
}
}
#[inline]
pub fn len(&self) -> u32 {
unsafe {
(*self.as_ptr()).mLength()
}
}
#[inline]
pub fn as_ptr(&self) -> *mut nsIAtom {
let const_ptr: *const nsIAtom = &self.0;
@ -130,12 +149,41 @@ impl WeakAtom {
}
}
impl fmt::Debug for WeakAtom {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
write!(w, "Gecko WeakAtom({:p}, {})", self, self)
}
}
impl fmt::Display for WeakAtom {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
for c in self.chars() {
try!(write!(w, "{}", c.unwrap_or(char::REPLACEMENT_CHARACTER)))
}
Ok(())
}
}
impl Atom {
pub unsafe fn with<F>(ptr: *mut nsIAtom, callback: &mut F) where F: FnMut(&Atom) {
let atom = Atom(WeakAtom::new(ptr));
callback(&atom);
mem::forget(atom);
}
}
/// Creates an atom from an static atom pointer without checking in release
/// builds.
///
/// Right now it's only used by the atom macro, and ideally it should keep
/// that way, now we have sugar for is_static, creating atoms using
/// Atom::from should involve almost no overhead.
#[inline]
unsafe fn from_static(ptr: *mut nsIAtom) -> Self {
let atom = Atom(ptr as *mut WeakAtom);
debug_assert!(atom.is_static(),
"Called from_static for a non-static atom!");
atom
}
}
impl BloomHash for Atom {
@ -174,8 +222,10 @@ impl Clone for Atom {
impl Drop for Atom {
#[inline]
fn drop(&mut self) {
unsafe {
Gecko_ReleaseAtom(self.as_ptr());
if !self.is_static() {
unsafe {
Gecko_ReleaseAtom(self.as_ptr());
}
}
}
}
@ -208,23 +258,22 @@ impl Deserialize for Atom {
impl fmt::Debug for Atom {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
write!(w, "Gecko Atom {:p}", self.0)
write!(w, "Gecko Atom({:p}, {})", self.0, self)
}
}
impl fmt::Display for Atom {
fn fmt(&self, w: &mut fmt::Formatter) -> fmt::Result {
for c in char::decode_utf16(self.as_slice().iter().cloned()) {
try!(write!(w, "{}", c.unwrap_or(char::REPLACEMENT_CHARACTER)))
unsafe {
(&*self.0).fmt(w)
}
Ok(())
}
}
impl<'a> From<&'a str> for Atom {
#[inline]
fn from(string: &str) -> Atom {
assert!(string.len() <= u32::max_value() as usize);
debug_assert!(string.len() <= u32::max_value() as usize);
unsafe {
Atom(WeakAtom::new(
Gecko_Atomize(string.as_ptr() as *const _, string.len() as u32)
@ -257,8 +306,11 @@ impl From<String> for Atom {
impl From<*mut nsIAtom> for Atom {
#[inline]
fn from(ptr: *mut nsIAtom) -> Atom {
debug_assert!(!ptr.is_null());
unsafe {
Gecko_AddRefAtom(ptr);
if (*ptr).mIsStatic() == 0 {
Gecko_AddRefAtom(ptr);
}
Atom(WeakAtom::new(ptr))
}
}

View file

@ -1,71 +0,0 @@
# 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/.
import re
import sys
if len(sys.argv) != 2:
print "usage: ./%s PATH/TO/OBJDIR" % sys.argv[0]
objdir_path = sys.argv[1]
def line_to_atom(line):
result = re.match('^GK_ATOM\((.+),\s*"(.*)"\)', line)
return (result.group(1), result.group(2))
def map_atom(ident):
if ident in {"box", "loop", "match", "mod", "ref",
"self", "type", "use", "where", "in"}:
return ident + "_"
return ident
def gnu_symbolify(ident):
return "_ZN9nsGkAtoms" + str(len(ident)) + ident + "E"
def msvc64_symbolify(ident):
return "?" + ident + "@nsGkAtoms@@2PEAVnsIAtom@@EA"
def msvc32_symbolify(ident):
return "?" + ident + "@nsGkAtoms@@2PAVnsIAtom@@A"
def write_items(f, func):
f.write(" extern {\n")
for atom in atoms:
f.write(TEMPLATE.format(name=map_atom(atom[0]),
link_name=func(atom[0])))
f.write(" }\n")
with open(objdir_path + "/dist/include/nsGkAtomList.h") as f:
lines = [line for line in f.readlines() if line.startswith("GK_ATOM")]
atoms = [line_to_atom(line) for line in lines]
TEMPLATE = """
#[link_name = "{link_name}"]
pub static {name}: *mut nsIAtom;
"""[1:]
with open("atom_macro.rs", "wb") as f:
f.write("use gecko_bindings::structs::nsIAtom;\n\n")
f.write("use Atom;\n\n")
f.write("pub fn unsafe_atom_from_static(ptr: *mut nsIAtom) -> Atom { unsafe { Atom::from_static(ptr) } }\n\n")
f.write("cfg_if! {\n")
f.write(" if #[cfg(not(target_env = \"msvc\"))] {\n")
write_items(f, gnu_symbolify)
f.write(" } else if #[cfg(target_pointer_width = \"64\")] {\n")
write_items(f, msvc64_symbolify)
f.write(" } else {\n")
write_items(f, msvc32_symbolify)
f.write(" }\n")
f.write("}\n\n")
f.write("#[macro_export]\n")
f.write("macro_rules! atom {\n")
f.writelines(['("%s") => { $crate::atom_macro::unsafe_atom_from_static($crate::atom_macro::%s) };\n'
% (atom[1], map_atom(atom[0])) for atom in atoms])
f.write("}\n")