chromium/third_party/blink/renderer/core/css/css_gradient_value.cc

/*
 * Copyright (C) 2008 Apple Inc.  All rights reserved.
 * Copyright (C) 2015 Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/core/css/css_gradient_value.h"

#include <algorithm>
#include <tuple>
#include <utility>

#include "base/memory/values_equivalent.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "third_party/blink/renderer/core/css/css_color.h"
#include "third_party/blink/renderer/core/css/css_identifier_value.h"
#include "third_party/blink/renderer/core/css/css_math_expression_node.h"
#include "third_party/blink/renderer/core/css/css_math_function_value.h"
#include "third_party/blink/renderer/core/css/css_numeric_literal_value.h"
#include "third_party/blink/renderer/core/css/css_to_length_conversion_data.h"
#include "third_party/blink/renderer/core/css/css_value_pair.h"
#include "third_party/blink/renderer/core/css/properties/computed_style_utils.h"
#include "third_party/blink/renderer/core/css/properties/longhands.h"
#include "third_party/blink/renderer/core/css/resolver/style_builder_converter.h"
#include "third_party/blink/renderer/core/css_value_keywords.h"
#include "third_party/blink/renderer/core/dom/node_computed_style.h"
#include "third_party/blink/renderer/core/dom/text_link_colors.h"
#include "third_party/blink/renderer/platform/graphics/color.h"
#include "third_party/blink/renderer/platform/graphics/gradient.h"
#include "third_party/blink/renderer/platform/graphics/gradient_generated_image.h"
#include "third_party/blink/renderer/platform/graphics/image.h"
#include "third_party/blink/renderer/platform/graphics/skia/skia_utils.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/wtf/text/string_builder.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "ui/gfx/geometry/size.h"

namespace blink::cssvalue {

namespace {

bool ColorIsDerivedFromElement(const CSSIdentifierValue& value) {}

bool AppendPosition(StringBuilder& result,
                    const CSSValue* x,
                    const CSSValue* y,
                    bool wrote_something) {}

}  // namespace

bool CSSGradientColorStop::IsCacheable() const {}

void CSSGradientColorStop::Trace(Visitor* visitor) const {}

scoped_refptr<Image> CSSGradientValue::GetImage(
    const ImageResourceObserver& client,
    const Document& document,
    const ComputedStyle& style,
    const ContainerSizes& container_sizes,
    const gfx::SizeF& size) const {}

// Should only ever be called for deprecated gradients.
static inline bool CompareStops(
    const CSSGradientColorStop& a,
    const CSSGradientColorStop& b,
    const CSSToLengthConversionData& conversion_data) {}

struct GradientStop {};

struct CSSGradientValue::GradientDesc {};

static void ReplaceColorHintsWithColorStops(
    Vector<GradientStop>& stops,
    const HeapVector<CSSGradientColorStop, 2>& css_gradient_stops,
    Color::ColorSpace color_interpolation_space,
    Color::HueInterpolationMethod hue_interpolation_method) {}

static Color ResolveStopColor(const CSSValue& stop_color,
                              const Document& document,
                              const ComputedStyle& style) {}

void CSSGradientValue::AddDeprecatedStops(
    GradientDesc& desc,
    const Document& document,
    const ComputedStyle& style,
    const CSSToLengthConversionData& conversion_data) const {}

// NOTE: The difference between this and ResolveStopColor() is that
// ResolveStopColor() returns a Color, whereas this returns a CSSValue.
static const CSSValue* GetComputedStopColor(const CSSValue& color,
                                            const ComputedStyle& style,
                                            bool allow_visited_style,
                                            CSSValuePhase value_phase) {}

void CSSGradientValue::AddComputedStops(
    const ComputedStyle& style,
    bool allow_visited_style,
    const HeapVector<CSSGradientColorStop, 2>& stops,
    CSSValuePhase value_phase) {}

namespace {

bool RequiresStopsNormalization(const Vector<GradientStop>& stops,
                                CSSGradientValue::GradientDesc& desc) {}

// Redistribute the stops such that they fully cover [0 , 1] and add them to the
// gradient.
bool NormalizeAndAddStops(const Vector<GradientStop>& stops,
                          CSSGradientValue::GradientDesc& desc) {}

// Collapse all negative-offset stops to 0 and compute an interpolated color
// value for that point.
void ClampNegativeOffsets(
    Vector<GradientStop>& stops,
    Color::ColorSpace color_interpolation_space,
    Color::HueInterpolationMethod hue_interpolation_method) {}

// Used in AdjustedGradientDomainForOffsetRange when the type of v1 - v0 is
// gfx::Vector2dF.
gfx::Vector2dF operator*(const gfx::Vector2dF& v, float scale) {}

template <typename T>
std::tuple<T, T> AdjustedGradientDomainForOffsetRange(const T& v0,
                                                      const T& v1,
                                                      float first_offset,
                                                      float last_offset) {}

// Update the radial gradient radii to align with the given offset range.
void AdjustGradientRadiiForOffsetRange(CSSGradientValue::GradientDesc& desc,
                                       float first_offset,
                                       float last_offset) {}

}  // namespace

void CSSGradientValue::AddStops(
    CSSGradientValue::GradientDesc& desc,
    const CSSToLengthConversionData& conversion_data,
    const Document& document,
    const ComputedStyle& style) const {}

static float PositionFromValue(const CSSValue* value,
                               const CSSToLengthConversionData& conversion_data,
                               const gfx::SizeF& size,
                               bool is_horizontal) {}

// Resolve points/radii to front end values.
static gfx::PointF ComputeEndPoint(
    const CSSValue* horizontal,
    const CSSValue* vertical,
    const CSSToLengthConversionData& conversion_data,
    const gfx::SizeF& size) {}

bool CSSGradientValue::KnownToBeOpaque(const Document& document,
                                       const ComputedStyle& style) const {}

CSSGradientValue* CSSGradientValue::ComputedCSSValue(
    const ComputedStyle& style,
    bool allow_visited_style,
    CSSValuePhase value_phase) const {}

Vector<Color> CSSGradientValue::GetStopColors(
    const Document& document,
    const ComputedStyle& style) const {}

void CSSGradientValue::TraceAfterDispatch(blink::Visitor* visitor) const {}

bool CSSGradientValue::ShouldSerializeColorSpace() const {}

String CSSLinearGradientValue::CustomCSSText() const {}

// Compute the endpoints so that a gradient of the given angle covers a box of
// the given size.
static void EndPointsFromAngle(float angle_deg,
                               const gfx::SizeF& size,
                               gfx::PointF& first_point,
                               gfx::PointF& second_point,
                               CSSGradientType type) {}

scoped_refptr<Gradient> CSSLinearGradientValue::CreateGradient(
    const CSSToLengthConversionData& conversion_data,
    const gfx::SizeF& size,
    const Document& document,
    const ComputedStyle& style) const {}

bool CSSLinearGradientValue::Equals(const CSSLinearGradientValue& other) const {}

CSSLinearGradientValue* CSSLinearGradientValue::ComputedCSSValue(
    const ComputedStyle& style,
    bool allow_visited_style,
    CSSValuePhase value_phase) const {}

static bool IsUsingCurrentColor(
    const HeapVector<CSSGradientColorStop, 2>& stops) {}

static bool IsUsingContainerRelativeUnits(const CSSValue* value) {}

static bool IsUsingContainerRelativeUnits(
    const HeapVector<CSSGradientColorStop, 2>& stops) {}

bool CSSLinearGradientValue::IsUsingCurrentColor() const {}

bool CSSLinearGradientValue::IsUsingContainerRelativeUnits() const {}

void CSSLinearGradientValue::TraceAfterDispatch(blink::Visitor* visitor) const {}

void CSSGradientValue::AppendCSSTextForColorStops(
    StringBuilder& result,
    bool requires_separator) const {}

void CSSGradientValue::AppendCSSTextForDeprecatedColorStops(
    StringBuilder& result) const {}

bool CSSGradientValue::Equals(const CSSGradientValue& other) const {}

String CSSRadialGradientValue::CustomCSSText() const {}

namespace {

// Resolve points/radii to front end values.
float ResolveRadius(const CSSPrimitiveValue* radius,
                    const CSSToLengthConversionData& conversion_data,
                    float* width_or_height = nullptr) {}

enum EndShapeType {};

// Compute the radius to the closest/farthest side (depending on the compare
// functor).
gfx::SizeF RadiusToSide(const gfx::PointF& point,
                        const gfx::SizeF& size,
                        EndShapeType shape,
                        bool (*compare)(float, float)) {}

// Compute the radius of an ellipse which passes through a point at
// |offset_from_center|, and has width/height given by aspectRatio.
inline gfx::SizeF EllipseRadius(const gfx::Vector2dF& offset_from_center,
                                float aspect_ratio) {}

// Compute the radius to the closest/farthest corner (depending on the compare
// functor).
gfx::SizeF RadiusToCorner(const gfx::PointF& point,
                          const gfx::SizeF& size,
                          EndShapeType shape,
                          bool (*compare)(float, float)) {}

}  // anonymous namespace

scoped_refptr<Gradient> CSSRadialGradientValue::CreateGradient(
    const CSSToLengthConversionData& conversion_data,
    const gfx::SizeF& size,
    const Document& document,
    const ComputedStyle& style) const {}

namespace {

bool EqualIdentifiersWithDefault(const CSSIdentifierValue* id_a,
                                 const CSSIdentifierValue* id_b,
                                 CSSValueID default_id) {}

}  // namespace

bool CSSRadialGradientValue::Equals(const CSSRadialGradientValue& other) const {}

CSSRadialGradientValue* CSSRadialGradientValue::ComputedCSSValue(
    const ComputedStyle& style,
    bool allow_visited_style,
    CSSValuePhase value_phase) const {}

bool CSSRadialGradientValue::IsUsingCurrentColor() const {}

bool CSSRadialGradientValue::IsUsingContainerRelativeUnits() const {}

void CSSRadialGradientValue::TraceAfterDispatch(blink::Visitor* visitor) const {}

String CSSConicGradientValue::CustomCSSText() const {}

scoped_refptr<Gradient> CSSConicGradientValue::CreateGradient(
    const CSSToLengthConversionData& conversion_data,
    const gfx::SizeF& size,
    const Document& document,
    const ComputedStyle& style) const {}

bool CSSConicGradientValue::Equals(const CSSConicGradientValue& other) const {}

CSSConicGradientValue* CSSConicGradientValue::ComputedCSSValue(
    const ComputedStyle& style,
    bool allow_visited_style,
    CSSValuePhase value_phase) const {}

bool CSSConicGradientValue::IsUsingCurrentColor() const {}

bool CSSConicGradientValue::IsUsingContainerRelativeUnits() const {}

void CSSConicGradientValue::TraceAfterDispatch(blink::Visitor* visitor) const {}

bool CSSConstantGradientValue::Equals(
    const CSSConstantGradientValue& other) const {}

void CSSConstantGradientValue::TraceAfterDispatch(
    blink::Visitor* visitor) const {}

bool CSSConstantGradientValue::KnownToBeOpaque(
    const Document& document,
    const ComputedStyle& style) const {}

scoped_refptr<Gradient> CSSConstantGradientValue::CreateGradient(
    const CSSToLengthConversionData& conversion_data,
    const gfx::SizeF& size,
    const Document& document,
    const ComputedStyle& style) const {}

CSSConstantGradientValue* CSSConstantGradientValue::ComputedCSSValue(
    const ComputedStyle& style,
    bool allow_visited_style,
    CSSValuePhase value_phase) const {}

}  // namespace blink::cssvalue