~suaweb/nginx/nginx-recipe

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/third_party/css_parser/src/webutil/css/media.h

  • Committer: Frans Elliott
  • Date: 2015-06-12 21:15:13 UTC
  • Revision ID: mastergeek.elliott@gmail.com-20150612211513-un4vguj32deibvb0
Added the actual pagespeed library to the ngx_pagespeed module dir.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * Copyright 2010 Google Inc.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *      http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
// Copyright 2012 Google Inc. All Rights Reserved.
 
18
// Author: sligocki@google.com (Shawn Ligocki)
 
19
//
 
20
// Classes for storing CSS3 @media queries.
 
21
// See: http://www.w3.org/TR/css3-mediaqueries/
 
22
 
 
23
#ifndef WEBUTIL_CSS_MEDIA_H_
 
24
#define WEBUTIL_CSS_MEDIA_H_
 
25
 
 
26
#include <string>
 
27
#include <vector>
 
28
 
 
29
#include "base/css_macros.h"
 
30
#include "util/utf8/public/unicodetext.h"
 
31
 
 
32
namespace Css {
 
33
 
 
34
class Ruleset;
 
35
 
 
36
// Classes named roughly after CSS3 @media query syntax names.
 
37
// From http://www.w3.org/TR/css3-mediaqueries/#syntax
 
38
//
 
39
//  media_query_list
 
40
//   : S* [media_query [ ',' S* media_query ]* ]?
 
41
//   ;
 
42
//  media_query
 
43
//   : [ONLY | NOT]? S* media_type S* [ AND S* expression ]*
 
44
//   | expression [ AND S* expression ]*
 
45
//   ;
 
46
//  media_type
 
47
//   : IDENT
 
48
//   ;
 
49
//  expression
 
50
//   : '(' S* media_feature S* [ ':' S* expr ]? ')' S*
 
51
//   ;
 
52
//  media_feature
 
53
//   : IDENT
 
54
//   ;
 
55
 
 
56
// Ex: (max-width: 500px)
 
57
class MediaExpression {
 
58
 public:
 
59
  // Media feature without a value. Ex: (color).
 
60
  explicit MediaExpression(const UnicodeText& name)
 
61
      : name_(name), has_value_(false) {}
 
62
  // Media feature with value. Ex: (max-width: 500px).
 
63
  MediaExpression(const UnicodeText& name, const UnicodeText& value)
 
64
      : name_(name), has_value_(true), value_(value) {}
 
65
  ~MediaExpression();
 
66
 
 
67
  const UnicodeText& name() const { return name_; }
 
68
  bool has_value() const { return has_value_; }
 
69
  const UnicodeText& value() const { return value_; }
 
70
 
 
71
  MediaExpression* DeepCopy() const;
 
72
  string ToString() const;
 
73
 
 
74
 private:
 
75
  UnicodeText name_;
 
76
  bool has_value_;
 
77
  // Unparsed value. TODO(sligocki): Actually parse it?
 
78
  UnicodeText value_;
 
79
 
 
80
  DISALLOW_COPY_AND_ASSIGN(MediaExpression);
 
81
};
 
82
 
 
83
// Ex: (max-width: 500px) and (color)
 
84
class MediaExpressions : public std::vector<MediaExpression*> {
 
85
 public:
 
86
  MediaExpressions() : std::vector<MediaExpression*>() {}
 
87
  ~MediaExpressions();
 
88
 
 
89
  string ToString() const;
 
90
 
 
91
 private:
 
92
  DISALLOW_COPY_AND_ASSIGN(MediaExpressions);
 
93
};
 
94
 
 
95
// Ex: not screen and (max-width: 500px) and (color)
 
96
class MediaQuery {
 
97
 public:
 
98
  MediaQuery() : qualifier_(NO_QUALIFIER) {}
 
99
  ~MediaQuery();
 
100
 
 
101
  enum MediaQualifier { ONLY, NOT, NO_QUALIFIER };
 
102
  MediaQualifier qualifier() const { return qualifier_; }
 
103
  const UnicodeText& media_type() const { return media_type_; }
 
104
  const MediaExpressions& expressions() const { return expressions_; }
 
105
  const MediaExpression& expression(int i) const { return *expressions_[i]; }
 
106
 
 
107
  void set_qualifier(MediaQualifier q) { qualifier_ = q; }
 
108
  void set_media_type(const UnicodeText& m) { media_type_ = m; }
 
109
  // Takes ownership of |expression|.
 
110
  void add_expression(MediaExpression* expression) {
 
111
    expressions_.push_back(expression);
 
112
  }
 
113
 
 
114
  MediaQuery* DeepCopy() const;
 
115
  string ToString() const;
 
116
 
 
117
 private:
 
118
  MediaQualifier qualifier_;
 
119
  UnicodeText media_type_;
 
120
  MediaExpressions expressions_;
 
121
 
 
122
  DISALLOW_COPY_AND_ASSIGN(MediaQuery);
 
123
};
 
124
 
 
125
// Ex: not screen and (max-width: 500px), projection and (color)
 
126
class MediaQueries : public std::vector<MediaQuery*> {
 
127
 public:
 
128
  MediaQueries() : std::vector<MediaQuery*>() {}
 
129
  ~MediaQueries();
 
130
 
 
131
  // Like clear(), but takes care of memory management as well.
 
132
  void Clear();
 
133
 
 
134
  MediaQueries* DeepCopy() const;
 
135
  string ToString() const;
 
136
 
 
137
 private:
 
138
  DISALLOW_COPY_AND_ASSIGN(MediaQueries);
 
139
};
 
140
 
 
141
}  // namespace Css
 
142
 
 
143
#endif  // WEBUTIL_CSS_MEDIA_H_