1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "InterfaceInitFuncs.h"
9 #include "AccessibleWrap.h"
11 #include "RemoteAccessible.h"
12 #include "mozilla/FloatingPoint.h"
13 #include "mozilla/Likely.h"
15 using namespace mozilla
;
16 using namespace mozilla::a11y
;
20 static void getCurrentValueCB(AtkValue
* obj
, GValue
* value
) {
21 Accessible
* acc
= GetInternalObj(ATK_OBJECT(obj
));
26 memset(value
, 0, sizeof(GValue
));
27 double accValue
= acc
->CurValue();
28 if (std::isnan(accValue
)) return;
30 g_value_init(value
, G_TYPE_DOUBLE
);
31 g_value_set_double(value
, accValue
);
34 static void getMaximumValueCB(AtkValue
* obj
, GValue
* value
) {
35 Accessible
* acc
= GetInternalObj(ATK_OBJECT(obj
));
40 memset(value
, 0, sizeof(GValue
));
41 double accValue
= acc
->MaxValue();
42 if (std::isnan(accValue
)) return;
44 g_value_init(value
, G_TYPE_DOUBLE
);
45 g_value_set_double(value
, accValue
);
48 static void getMinimumValueCB(AtkValue
* obj
, GValue
* value
) {
49 Accessible
* acc
= GetInternalObj(ATK_OBJECT(obj
));
54 memset(value
, 0, sizeof(GValue
));
55 double accValue
= acc
->MinValue();
56 if (std::isnan(accValue
)) return;
58 g_value_init(value
, G_TYPE_DOUBLE
);
59 g_value_set_double(value
, accValue
);
62 static void getMinimumIncrementCB(AtkValue
* obj
, GValue
* minimumIncrement
) {
63 Accessible
* acc
= GetInternalObj(ATK_OBJECT(obj
));
68 memset(minimumIncrement
, 0, sizeof(GValue
));
69 double accValue
= acc
->Step();
70 if (std::isnan(accValue
)) {
71 accValue
= 0; // zero if the minimum increment is undefined
74 g_value_init(minimumIncrement
, G_TYPE_DOUBLE
);
75 g_value_set_double(minimumIncrement
, accValue
);
78 static gboolean
setCurrentValueCB(AtkValue
* obj
, const GValue
* value
) {
79 Accessible
* acc
= GetInternalObj(ATK_OBJECT(obj
));
84 double accValue
= g_value_get_double(value
);
85 return acc
->SetCurValue(accValue
);
88 void valueInterfaceInitCB(AtkValueIface
* aIface
) {
89 NS_ASSERTION(aIface
, "Invalid aIface");
90 if (MOZ_UNLIKELY(!aIface
)) return;
92 aIface
->get_current_value
= getCurrentValueCB
;
93 aIface
->get_maximum_value
= getMaximumValueCB
;
94 aIface
->get_minimum_value
= getMinimumValueCB
;
95 aIface
->get_minimum_increment
= getMinimumIncrementCB
;
96 aIface
->set_current_value
= setCurrentValueCB
;