File indexing completed on 2024-04-21 11:29:46

0001 /*
0002  *  This file is part of the KDE libraries
0003  *  Copyright (C) 2004 Apple Computer, Inc.
0004  *  Copyright (C) 2005 Zack Rusin <zack@kde.org>
0005  *  Copyright (C) 2007, 2008 Maksim Orlovich <maksim@kde.org>
0006  *
0007  *  This library is free software; you can redistribute it and/or
0008  *  modify it under the terms of the GNU Lesser General Public
0009  *  License as published by the Free Software Foundation; either
0010  *  version 2 of the License, or (at your option) any later version.
0011  *
0012  *  This library is distributed in the hope that it will be useful,
0013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  *  Lesser General Public License for more details.
0016  *
0017  *  You should have received a copy of the GNU Lesser General Public
0018  *  License along with this library; if not, write to the Free Software
0019  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0020  */
0021 #ifndef KJS_CONTEXT2D_H
0022 #define KJS_CONTEXT2D_H
0023 
0024 #include "kjs_dom.h"
0025 #include "kjs_binding.h"
0026 #include "kjs_html.h"
0027 #include <kjs/object.h>
0028 
0029 #include "misc/loader_client.h"
0030 #include "html/html_canvasimpl.h"
0031 
0032 #include <QPainterPath>
0033 
0034 namespace DOM
0035 {
0036 class HTMLElementImpl;
0037 }
0038 
0039 namespace KJS
0040 {
0041 
0042 ////////////////////// Context2D Object ////////////////////////
0043 DEFINE_PSEUDO_CONSTRUCTOR(Context2DPseudoCtor)
0044 
0045 class Context2D : public DOMWrapperObject<DOM::CanvasContext2DImpl>
0046 {
0047     friend class Context2DFunction;
0048 public:
0049     Context2D(ExecState *exec, DOM::CanvasContext2DImpl *ctx);
0050 
0051     using KJS::JSObject::getOwnPropertySlot;
0052     bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override;
0053     JSValue *getValueProperty(ExecState *exec, int token) const;
0054     using KJS::JSObject::put;
0055     void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None) override;
0056     void putValueProperty(ExecState *exec, int token, JSValue *value, int /*attr*/);
0057 
0058     const ClassInfo *classInfo() const override
0059     {
0060         return &info;
0061     }
0062     static const ClassInfo info;
0063 
0064     enum {
0065         Canvas,
0066         Save, Restore, // state
0067         Scale, Rotate, Translate, Transform, SetTransform, // transformations
0068         GlobalAlpha, GlobalCompositeOperation,             // compositing
0069         StrokeStyle, FillStyle, CreateLinearGradient, CreateRadialGradient, CreatePattern, // colors and styles.
0070         LineWidth, LineCap, LineJoin, MiterLimit, // line properties
0071         ShadowOffsetX, ShadowOffsetY, ShadowBlur, ShadowColor, // shadow properties
0072         ClearRect, FillRect, StrokeRect,          // rectangle ops
0073         BeginPath, ClosePath, MoveTo, LineTo, QuadraticCurveTo, BezierCurveTo, ArcTo, Rect, Arc,
0074         Fill, Stroke, Clip, IsPointInPath,        // paths
0075         DrawImage,  // do we want backwards compat for drawImageFromRect?
0076         GetImageData, PutImageData, CreateImageData // pixel ops. ewww.
0077     };
0078 };
0079 
0080 class CanvasGradient : public DOMWrapperObject<DOM::CanvasGradientImpl>
0081 {
0082 public:
0083     CanvasGradient(ExecState *exec, DOM::CanvasGradientImpl *impl);
0084 
0085     const ClassInfo *classInfo() const override
0086     {
0087         return &info;
0088     }
0089     static const ClassInfo info;
0090 
0091     enum {
0092         AddColorStop
0093     };
0094 };
0095 
0096 class CanvasPattern : public DOMWrapperObject<DOM::CanvasPatternImpl>
0097 {
0098 public:
0099     CanvasPattern(ExecState *exec, DOM::CanvasPatternImpl *i);
0100 
0101     const ClassInfo *classInfo() const override
0102     {
0103         return &info;
0104     }
0105     static const ClassInfo info;
0106 };
0107 
0108 // Return 0 if conversion failed
0109 DOM::CanvasImageDataImpl *toCanvasImageData(ExecState *exec, JSValue *val);
0110 
0111 class CanvasImageDataArray;
0112 class CanvasImageData : public DOMWrapperObject<DOM::CanvasImageDataImpl>
0113 {
0114 public:
0115     CanvasImageData(ExecState *exec, DOM::CanvasImageDataImpl *i);
0116 
0117     const ClassInfo *classInfo() const override
0118     {
0119         return &info;
0120     }
0121     static const ClassInfo info;
0122 
0123     JSObject *valueClone(Interpreter *targetCtx) const override;
0124 
0125     void mark() override;
0126 private:
0127     CanvasImageDataArray *data;
0128 };
0129 
0130 class CanvasImageDataArray : public JSObject
0131 {
0132 public:
0133     CanvasImageDataArray(ExecState *exec, CanvasImageData *p);
0134 
0135     const ClassInfo *classInfo() const override
0136     {
0137         return &info;
0138     }
0139     static const ClassInfo info;
0140 
0141     void mark() override;
0142 
0143     // Performs conversion/claming/rounding of color components as specified in HTML5 spec.
0144     static unsigned char decodeComponent(ExecState *exec, JSValue *val);
0145 
0146     bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
0147     bool getOwnPropertySlot(ExecState *exec, unsigned index, PropertySlot &slot) override;
0148     void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr) override;
0149     void put(ExecState *exec, unsigned index, JSValue *value, int attr) override;
0150 
0151     JSValue *indexGetter(ExecState *exec, unsigned index);
0152 private:
0153     unsigned size;
0154     CanvasImageData *parent;
0155 };
0156 
0157 DEFINE_PSEUDO_CONSTRUCTOR(SVGAnglePseudoCtor)
0158 
0159 } // namespace
0160 
0161 #endif