Change copyrights from Nokia to Digia
[profile/ivi/qtdeclarative.git] / src / qml / qml / v8 / qv8bindings_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QV8BINDINGS_P_H
43 #define QV8BINDINGS_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include <private/qpointervaluepair_p.h>
57 #include <private/qqmlpropertycache_p.h>
58 #include <private/qqmlinstruction_p.h>
59 #include <private/qqmlexpression_p.h>
60 #include <private/qqmlcompiler_p.h>
61 #include <private/qflagpointer_p.h>
62 #include <private/qqmlbinding_p.h>
63
64 QT_BEGIN_HEADER
65
66 QT_BEGIN_NAMESPACE
67
68 class QQmlCompiledData;
69
70 class QV8BindingsPrivate;
71 class QV8Bindings : public QQmlAbstractExpression
72 {
73 public:
74     QV8Bindings(QQmlCompiledData::V8Program *,
75                 quint16 line,
76                 QQmlContextData *context);
77     virtual ~QV8Bindings();
78
79     QQmlAbstractBinding *configBinding(QObject *target, QObject *scope,
80                                                const QQmlInstruction::instr_assignBinding *);
81
82     // Inherited from QQmlAbstractExpression
83     virtual void refresh();
84
85     struct Binding : public QQmlJavaScriptExpression,
86                      public QQmlAbstractBinding {
87         Binding();
88
89         void update() { QQmlAbstractBinding::update(); }
90         void refresh();
91
92         // "Inherited" from QQmlJavaScriptExpression
93         static QString expressionIdentifier(QQmlJavaScriptExpression *);
94         static void expressionChanged(QQmlJavaScriptExpression *);
95
96         // "Inherited" from QQmlAbstractBinding
97         static void destroy(QQmlAbstractBinding *, QQmlAbstractBinding::DestroyMode mode);
98         static int propertyIndex(const QQmlAbstractBinding *);
99         static QObject *object(const QQmlAbstractBinding *);
100         static void setEnabled(QQmlAbstractBinding *, bool, QQmlPropertyPrivate::WriteFlags);
101         static void update(QQmlAbstractBinding *, QQmlPropertyPrivate::WriteFlags);
102         static void retargetBinding(QQmlAbstractBinding *, QObject *, int);
103
104         QObject *object() const;
105         void update(QQmlPropertyPrivate::WriteFlags flags);
106
107         void dump();
108
109         QV8Bindings *parent;
110
111         struct Retarget {
112             QObject *target;
113             int targetProperty;
114         };
115
116         // To save memory, we store flags inside the instruction pointer.
117         //    target.flag1: destroyed
118         //    instruction.flag1: enabled
119         //    instruction.flag2: updating
120         QPointerValuePair<QObject, Retarget> target;
121         QFlagPointer<const QQmlInstruction::instr_assignBinding> instruction;
122
123         inline bool destroyedFlag() const { return target.flag(); }
124         inline void setDestroyedFlag(bool v) { return target.setFlagValue(v); }
125         inline bool enabledFlag() const { return instruction.flag(); }
126         inline void setEnabledFlag(bool v) { instruction.setFlagValue(v); }
127         inline bool updatingFlag() const { return instruction.flag2(); }
128         inline void setUpdatingFlag(bool v) { instruction.setFlag2Value(v); }
129     };
130
131     inline void addref();
132     inline void release();
133
134     QQmlAbstractBinding *binding(int index) const { return bindings + index; }
135
136 private:
137     Q_DISABLE_COPY(QV8Bindings)
138
139     const QUrl &url() const;
140     const QString &urlString() const;
141     v8::Persistent<v8::Array> &functions() const;
142
143     QQmlCompiledData::V8Program *program;
144     Binding *bindings;
145     int refCount;
146 };
147
148 void QV8Bindings::addref()
149 {
150     ++refCount;
151 }
152
153 void QV8Bindings::release()
154 {
155     if (0 == --refCount)
156         delete this;
157 }
158
159 QT_END_NAMESPACE
160
161 QT_END_HEADER
162
163 #endif // QV8BINDINGS_P_H
164
165