2
* Copyright 2010 Google Inc.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
// Copyright 2007 Google Inc. All Rights Reserved.
18
// Author: yian@google.com (Yian Huang)
19
// Author: dpeng@google.com (Daniel Peng)
21
#ifndef WEBUTIL_CSS_UTIL_H__
22
#define WEBUTIL_CSS_UTIL_H__
27
#include "strings/stringpiece.h"
28
#include "webutil/css/string.h"
40
enum COLOR_ATTR {ORIGINAL, TRANSPARENT, UNKNOWN, INHERIT};
42
// Parses CSS color value (may be a string, identifier or a color) into
43
// HtmlColor. returns def if the color is invalid. set attr to one of the
44
// following attributes: ORIGINAL if the color is valid, INHERIT if it is the
45
// keyword inherit, UNKNOWN if it is the keywoard unknown, TRANSPARENT
46
// if it is invalid otherwise.
47
HtmlColor GetCssColor(const Css::Value* val, const HtmlColor& def,
50
// Converts length or percentage string to absolute px units. Refer to
51
// parent_size when seeing 10% (invalid if parent_size is -1). Refer to
52
// font_size when seeing 1.2EM or 1.2EX. Invalid if val is NULL or it is not
53
// a number. It can also be invalid if can_negative is set and the value is
54
// negative, can_unitless works similarly. Returns if parsing succeeds, and
55
// if so, size stores the result.
56
bool GetCssLength(const Css::Value* val, double parent_size,
57
double font_size, double unit, bool can_negative,
58
bool can_unitless, double* size);
60
// Updates color with system color specified in colorstr. The change is only
61
// done only when the conversion succeeds, indicated by the return value.
62
// For a list of system colors, please see
63
// http://www.w3.org/TR/CSS21/ui.html#system-colors
64
// Actual system colors depend on OS's graphic environment. For the purpose
65
// of hidden text detection, we assume a typical setting based on Windows XP
67
bool GetSystemColor(const string& colorstr, HtmlColor* color);
69
// Whether a media string (comma separated list of media) is compatible with
70
// screen-oriented applications. It is valid if no media is specified or some
71
// medium has the name "screen" or "all".
72
bool MediaAppliesToScreen(const StringPiece& media);
74
// Whether a media list is compatible with screen-oriented applications. It
75
// is valid if no media is specified or some medium has the name "screen" or
77
bool MediaAppliesToScreen(const std::vector<UnicodeText>& media);
79
// Note: Operates like a naive CSS2 parser, only returning true if media type
80
// is "screen" or "all" and there are no qualifiers. Media expressions are
82
bool MediaAppliesToScreen(const Css::MediaQueries& media);
87
#endif // WEBUTIL_CSS_UTIL_H__