Page Speed Optimization Libraries  1.12.34.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Enumerations | Functions
net_instaweb::css_util Namespace Reference

Classes

class  StyleExtractor
 

Enumerations

enum  DimensionState {
  kNoDimensions, kHasHeightOnly, kHasWidthOnly, kHasBothDimensions,
  kNotParsable
}
 

Functions

DimensionState GetDimensions (Css::Declarations *decls, int *width, int *height)
 
void VectorizeMediaAttribute (const StringPiece &input_media, StringVector *output_vector)
 
GoogleString StringifyMediaVector (const StringVector &import_media)
 
bool IsComplexMediaQuery (const Css::MediaQuery &query)
 
bool ConvertMediaQueriesToStringVector (const Css::MediaQueries &in_vector, StringVector *out_vector)
 
void ConvertStringVectorToMediaQueries (const StringVector &in_vector, Css::MediaQueries *out_vector)
 
void ClearVectorIfContainsMediaAll (StringVector *media)
 
bool CanMediaAffectScreen (const StringPiece &media)
 Can this media attribute include some kind of screen?
 
GoogleString JsDetectableSelector (const Css::Selector &selector)
 
template<typename T >
void EliminateElementsNotIn (std::vector< T > *sorted_inner, const std::vector< T > &sorted_outer)
 

Detailed Description

Todo:
TODO(nforman): remove this namespace and put everything into the StyleExtractor class.

Enumeration Type Documentation

Enumerator
kNoDimensions 

No dimensions found.

kHasHeightOnly 

Found height only.

kHasWidthOnly 

Found width only.

kHasBothDimensions 

Found both width and height.

kNotParsable 

Found a dimension, but couldn't extract a value.

Function Documentation

void net_instaweb::css_util::ClearVectorIfContainsMediaAll ( StringVector *  media)

Clear the given vector if it contains the media 'all'. This is required because Css::Parser doesn't treat 'all' specially but we do for efficiency.

bool net_instaweb::css_util::ConvertMediaQueriesToStringVector ( const Css::MediaQueries &  in_vector,
StringVector *  out_vector 
)

Convert a set of MediaQueries to a vector of UTF-8 GoogleString's for use of the above functions. Elements are trimmed and any empty elements are ignored.

Only simple media queries are accepted, returns false for complex queries.

void net_instaweb::css_util::ConvertStringVectorToMediaQueries ( const StringVector &  in_vector,
Css::MediaQueries *  out_vector 
)

Convert a vector of UTF-8 GoogleString's to MediaQueries. Elements are trimmed and any empty elements are ignored. The strings are interpreted as simple media types (no complex media query syntax like "not screen" or "(max-width: 200px)").

template<typename T >
void net_instaweb::css_util::EliminateElementsNotIn ( std::vector< T > *  sorted_inner,
const std::vector< T > &  sorted_outer 
)

Eliminate all elements from the first vector that are not in the second vector, with the caveat that an empty vector (first or second) means 'the set of all possible values', meaning that if the second vector is empty then no elements are removed from the first vector, and if the first vector is empty then the second vector is copied into it. Both vectors must be sorted on entry.

No more outer elements => delete all remaining inner elements.

This inner element is in the outer => keep it and move on.

This outer element isn't in the inner => skip it, try the next.

This inner element isn't in the outer => delete it, move on.

DimensionState net_instaweb::css_util::GetDimensions ( Css::Declarations *  decls,
int *  width,
int *  height 
)

Extract the width and height values out of a list of declarations. If a value was not found, it will be populated with kNoValue. This is "safe" because even if someone specifies a width:-1; it will be ignored: "If a negative length value is set on a property that does not allow negative length values, the declaration is ignored." http://www.w3.org/TR/CSS2/syndata.html#value-def-length

bool net_instaweb::css_util::IsComplexMediaQuery ( const Css::MediaQuery &  query)

Checks if query is not simply a media type. In other words, whether it has a qualifier ("not" or "only") or media expressions (like "and (color)").

GoogleString net_instaweb::css_util::JsDetectableSelector ( const Css::Selector &  selector)

Strip a parsed selector down to a string that can be used by a querySelectorAll call in the browser to select DOM elements.

GoogleString net_instaweb::css_util::StringifyMediaVector ( const StringVector &  import_media)

Convert a vector of media types to a media string. If the input vector is empty then the answer is 'all', the inverse of the vectorizing function above; if you want the empty string then test the vector yourself. Otherwise the answer is a comma-separated list of media types.

void net_instaweb::css_util::VectorizeMediaAttribute ( const StringPiece &  input_media,
StringVector *  output_vector 
)

Utility functions for handling CSS media types as vectors of strings. There is an argument to use StringPiece's rather than GoogleString's here, but CssFilter::FlattenImportsContext cannot use StringPiece's because it doesn't keep the original strings, so copies in GoogleString's are required. Convert a media string, from either a media attribute or after , to a vector of media types. If any of the input media types are 'all' then an empty vector is returned: 'all' means all media types are accepted so it subsumes all other types, and an empty vector representation is most useful.