1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef SizesCalcParser_h
6#define SizesCalcParser_h
7
8#include "core/css/MediaValues.h"
9#include "core/css/parser/MediaQueryToken.h"
10#include "wtf/text/WTFString.h"
11
12namespace blink {
13
14struct SizesCalcValue {
15    double value;
16    bool isLength;
17    UChar operation;
18
19    SizesCalcValue()
20        : value(0)
21        , isLength(false)
22        , operation(0)
23    {
24    }
25
26    SizesCalcValue(double numericValue, bool length)
27        : value(numericValue)
28        , isLength(length)
29        , operation(0)
30    {
31    }
32};
33
34class SizesCalcParser {
35
36public:
37    SizesCalcParser(MediaQueryTokenIterator start, MediaQueryTokenIterator end, PassRefPtr<MediaValues>);
38
39    bool viewportDependant() const { return m_viewportDependant; }
40    unsigned result() const;
41    bool isValid() const { return m_isValid; }
42
43private:
44    bool calcToReversePolishNotation(MediaQueryTokenIterator start, MediaQueryTokenIterator end);
45    bool calculate();
46    void appendNumber(const MediaQueryToken&);
47    bool appendLength(const MediaQueryToken&);
48    bool handleOperator(Vector<MediaQueryToken>& stack, const MediaQueryToken&);
49    void appendOperator(const MediaQueryToken&);
50
51    Vector<SizesCalcValue> m_valueList;
52    RefPtr<MediaValues> m_mediaValues;
53    bool m_viewportDependant;
54    bool m_isValid;
55    unsigned m_result;
56};
57
58} // namespace blink
59
60#endif // SizesCalcParser_h
61
62