1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/css/properties/longhands/clip.h"
#include "third_party/blink/renderer/core/css/css_quad_value.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_context.h"
#include "third_party/blink/renderer/core/css/parser/css_property_parser_helpers.h"
#include "third_party/blink/renderer/core/css/properties/computed_style_utils.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
namespace blink {
namespace {
CSSValue* ConsumeClipComponent(CSSParserTokenRange& range,
CSSParserMode css_parser_mode) {
if (range.Peek().Id() == CSSValueAuto)
return CSSPropertyParserHelpers::ConsumeIdent(range);
return CSSPropertyParserHelpers::ConsumeLength(
range, css_parser_mode, kValueRangeAll,
CSSPropertyParserHelpers::UnitlessQuirk::kAllow);
}
} // namespace
namespace CSSLonghand {
const CSSValue* Clip::ParseSingleValue(CSSParserTokenRange& range,
const CSSParserContext& context,
const CSSParserLocalContext&) const {
if (range.Peek().Id() == CSSValueAuto)
return CSSPropertyParserHelpers::ConsumeIdent(range);
if (range.Peek().FunctionId() != CSSValueRect)
return nullptr;
CSSParserTokenRange args = CSSPropertyParserHelpers::ConsumeFunction(range);
// rect(t, r, b, l) || rect(t r b l)
CSSValue* top = ConsumeClipComponent(args, context.Mode());
if (!top)
return nullptr;
bool needs_comma =
CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args);
CSSValue* right = ConsumeClipComponent(args, context.Mode());
if (!right ||
(needs_comma &&
!CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)))
return nullptr;
CSSValue* bottom = ConsumeClipComponent(args, context.Mode());
if (!bottom ||
(needs_comma &&
!CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)))
return nullptr;
CSSValue* left = ConsumeClipComponent(args, context.Mode());
if (!left || !args.AtEnd())
return nullptr;
return CSSQuadValue::Create(top, right, bottom, left,
CSSQuadValue::kSerializeAsRect);
}
const CSSValue* Clip::CSSValueFromComputedStyleInternal(
const ComputedStyle& style,
const SVGComputedStyle&,
const LayoutObject*,
Node* styled_node,
bool allow_visited_style) const {
if (style.HasAutoClip())
return CSSIdentifierValue::Create(CSSValueAuto);
CSSValue* top = ComputedStyleUtils::ZoomAdjustedPixelValueOrAuto(
style.Clip().Top(), style);
CSSValue* right = ComputedStyleUtils::ZoomAdjustedPixelValueOrAuto(
style.Clip().Right(), style);
CSSValue* bottom = ComputedStyleUtils::ZoomAdjustedPixelValueOrAuto(
style.Clip().Bottom(), style);
CSSValue* left = ComputedStyleUtils::ZoomAdjustedPixelValueOrAuto(
style.Clip().Left(), style);
return CSSQuadValue::Create(top, right, bottom, left,
CSSQuadValue::kSerializeAsRect);
}
} // namespace CSSLonghand
} // namespace blink
|