// Copyright 2019 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/css_math_function_value.h" #include "third_party/blink/renderer/core/css/css_math_expression_node.h" #include "third_party/blink/renderer/platform/geometry/calculation_expression_node.h" #include "third_party/blink/renderer/platform/geometry/length.h" #include "third_party/blink/renderer/platform/wtf/size_assertions.h" #include "third_party/blink/renderer/platform/wtf/text/string_builder.h" namespace blink { struct SameSizeAsCSSMathFunctionValue : CSSPrimitiveValue { Member expression; }; ASSERT_SIZE(CSSMathFunctionValue, SameSizeAsCSSMathFunctionValue); void CSSMathFunctionValue::TraceAfterDispatch(blink::Visitor* visitor) const { visitor->Trace(expression_); CSSPrimitiveValue::TraceAfterDispatch(visitor); } CSSMathFunctionValue::CSSMathFunctionValue( const CSSMathExpressionNode* expression, ValueRange range) : CSSPrimitiveValue(kMathFunctionClass), expression_(expression) { is_non_negative_math_function_ = range == kValueRangeNonNegative; } // static CSSMathFunctionValue* CSSMathFunctionValue::Create( const CSSMathExpressionNode* expression, ValueRange range) { if (!expression) return nullptr; return MakeGarbageCollected(expression, range); } // static CSSMathFunctionValue* CSSMathFunctionValue::Create(const Length& length, float zoom) { DCHECK(length.IsCalculated()); auto calc = length.GetCalculationValue().Zoom(1.0 / zoom); return Create(CSSMathExpressionNode::Create(*calc), calc->GetValueRange()); } bool CSSMathFunctionValue::MayHaveRelativeUnit() const { UnitType resolved_type = expression_->ResolvedUnitType(); return IsRelativeUnit(resolved_type) || resolved_type == UnitType::kUnknown; } double CSSMathFunctionValue::DoubleValue() const { #if DCHECK_IS_ON() if (IsPercentage()) { DCHECK(!AllowsNegativePercentageReference() || !expression_->InvolvesPercentageComparisons()); } #endif return ClampToPermittedRange(expression_->DoubleValue()); } double CSSMathFunctionValue::ComputeSeconds() const { DCHECK_EQ(kCalcTime, expression_->Category()); // TODO(crbug.com/984372): We currently use 'ms' as the canonical unit of //