| Index: Source/core/dom/DOMQuad.cpp
|
| diff --git a/Source/core/dom/DOMQuad.cpp b/Source/core/dom/DOMQuad.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e6311eb5846d473d3702fdf7cc5f6984676e51dc
|
| --- /dev/null
|
| +++ b/Source/core/dom/DOMQuad.cpp
|
| @@ -0,0 +1,139 @@
|
| +// Copyright 2014 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 "config.h"
|
| +#include "core/dom/DOMQuad.h"
|
| +
|
| +namespace WebCore {
|
| +
|
| +DOMQuadPoint* DOMQuadPoint::create(DOMPointInit& point, Member<DOMQuad> quad)
|
| +{
|
| + double x = 0;
|
| + double y = 0;
|
| +
|
| + if (!DictionaryHelper::get(point, "x", x))
|
| + x = 0;
|
| + if (!DictionaryHelper::get(point, "y", y))
|
| + y = 0;
|
| +
|
| + return new DOMQuadPoint(x, y, quad);
|
| +}
|
| +
|
| +DOMQuadPoint* DOMQuadPoint::create(double x, double y, Member<DOMQuad> quad)
|
| +{
|
| + return new DOMQuadPoint(x, y, quad);
|
| +}
|
| +
|
| +DOMQuadPoint::DOMQuadPoint(double x, double y, Member<DOMQuad> quad)
|
| + : DOMPoint(x, y, 0, 1)
|
| + , m_quad(quad)
|
| +{
|
| +}
|
| +
|
| +void DOMQuadPoint::setX(double x)
|
| +{
|
| + m_x = x;
|
| + m_quad->updateHorizontalBounds();
|
| +}
|
| +
|
| +void DOMQuadPoint::setY(double y)
|
| +{
|
| + m_y = y;
|
| + m_quad->updateVerticalBounds();
|
| +}
|
| +
|
| +void DOMQuadPoint::trace(Visitor* visitor)
|
| +{
|
| + DOMPoint::trace(visitor);
|
| + visitor->trace(m_quad);
|
| +}
|
| +
|
| +DOMQuad* DOMQuad::create(DOMPointInit& p1, DOMPointInit& p2, DOMPointInit& p3, DOMPointInit& p4)
|
| +{
|
| + return new DOMQuad(p1, p2, p3, p4);
|
| +}
|
| +
|
| +DOMQuad* DOMQuad::create(DOMRectInit& rect)
|
| +{
|
| + double x = 0;
|
| + double y = 0;
|
| + double width = 0;
|
| + double height = 0;
|
| +
|
| + if (!DictionaryHelper::get(rect, "x", x))
|
| + x = 0;
|
| + if (!DictionaryHelper::get(rect, "y", y))
|
| + y = 0;
|
| + if (!DictionaryHelper::get(rect, "width", width))
|
| + width = 0;
|
| + if (!DictionaryHelper::get(rect, "height", height))
|
| + height = 0;
|
| +
|
| + return new DOMQuad(x, y, width, height);
|
| +}
|
| +
|
| +DOMQuad::DOMQuad(double x, double y, double width, double height)
|
| + : m_p1(DOMQuadPoint::create(x, y, this))
|
| + , m_p2(DOMQuadPoint::create(x + width, y, this))
|
| + , m_p3(DOMQuadPoint::create(x + width, y + height, this))
|
| + , m_p4(DOMQuadPoint::create(x, y + height, this))
|
| + , m_bounds(DOMRect::create(x, y, width, height))
|
| +{
|
| +}
|
| +
|
| +DOMQuad::DOMQuad(DOMPointInit& p1, DOMPointInit& p2,
|
| + DOMPointInit& p3, DOMPointInit& p4)
|
| + : m_p1(DOMQuadPoint::create(p1, this))
|
| + , m_p2(DOMQuadPoint::create(p2, this))
|
| + , m_p3(DOMQuadPoint::create(p3, this))
|
| + , m_p4(DOMQuadPoint::create(p4, this))
|
| + , m_bounds(DOMRect::create())
|
| +{
|
| + updateHorizontalBounds();
|
| + updateVerticalBounds();
|
| +}
|
| +
|
| +static inline double min4(double a, double b, double c, double d)
|
| +{
|
| + return std::min(std::min(a, b), std::min(c, d));
|
| +}
|
| +
|
| +static inline double max4(double a, double b, double c, double d)
|
| +{
|
| + return std::max(std::max(a, b), std::max(c, d));
|
| +}
|
| +
|
| +DOMRectReadOnly* DOMQuad::bounds() const
|
| +{
|
| + return m_bounds.get();
|
| +}
|
| +
|
| +void DOMQuad::updateHorizontalBounds()
|
| +{
|
| + double left = min4(m_p1->x(), m_p2->x(), m_p3->x(), m_p4->x());
|
| + double right = max4(m_p1->x(), m_p2->x(), m_p3->x(), m_p4->x());
|
| +
|
| + m_bounds->setX(left);
|
| + m_bounds->setWidth(right - left);
|
| +}
|
| +
|
| +void DOMQuad::updateVerticalBounds()
|
| +{
|
| + double top = min4(m_p1->y(), m_p2->y(), m_p3->y(), m_p4->y());
|
| + double bottom = max4(m_p1->y(), m_p2->y(), m_p3->y(), m_p4->y());
|
| +
|
| + m_bounds->setY(top);
|
| + m_bounds->setHeight(bottom - top);
|
| +}
|
| +
|
| +void DOMQuad::trace(Visitor* visitor)
|
| +{
|
| + visitor->trace(m_p1);
|
| + visitor->trace(m_p2);
|
| + visitor->trace(m_p3);
|
| + visitor->trace(m_p4);
|
| + visitor->trace(m_bounds);
|
| +}
|
| +
|
| +} // namespace WebCore
|
|
|