tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsMaiInterfaceValue.cpp (2619B)


      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/. */
      6 
      7 #include "InterfaceInitFuncs.h"
      8 
      9 #include "AccessibleWrap.h"
     10 #include "nsMai.h"
     11 #include "RemoteAccessible.h"
     12 #include "mozilla/Likely.h"
     13 
     14 using namespace mozilla;
     15 using namespace mozilla::a11y;
     16 
     17 extern "C" {
     18 
     19 static void getCurrentValueCB(AtkValue* obj, GValue* value) {
     20  Accessible* acc = GetInternalObj(ATK_OBJECT(obj));
     21  if (!acc) {
     22    return;
     23  }
     24 
     25  memset(value, 0, sizeof(GValue));
     26  double accValue = acc->CurValue();
     27  if (std::isnan(accValue)) return;
     28 
     29  g_value_init(value, G_TYPE_DOUBLE);
     30  g_value_set_double(value, accValue);
     31 }
     32 
     33 static void getMaximumValueCB(AtkValue* obj, GValue* value) {
     34  Accessible* acc = GetInternalObj(ATK_OBJECT(obj));
     35  if (!acc) {
     36    return;
     37  }
     38 
     39  memset(value, 0, sizeof(GValue));
     40  double accValue = acc->MaxValue();
     41  if (std::isnan(accValue)) return;
     42 
     43  g_value_init(value, G_TYPE_DOUBLE);
     44  g_value_set_double(value, accValue);
     45 }
     46 
     47 static void getMinimumValueCB(AtkValue* obj, GValue* value) {
     48  Accessible* acc = GetInternalObj(ATK_OBJECT(obj));
     49  if (!acc) {
     50    return;
     51  }
     52 
     53  memset(value, 0, sizeof(GValue));
     54  double accValue = acc->MinValue();
     55  if (std::isnan(accValue)) return;
     56 
     57  g_value_init(value, G_TYPE_DOUBLE);
     58  g_value_set_double(value, accValue);
     59 }
     60 
     61 static void getMinimumIncrementCB(AtkValue* obj, GValue* minimumIncrement) {
     62  Accessible* acc = GetInternalObj(ATK_OBJECT(obj));
     63  if (!acc) {
     64    return;
     65  }
     66 
     67  memset(minimumIncrement, 0, sizeof(GValue));
     68  double accValue = acc->Step();
     69  if (std::isnan(accValue)) {
     70    accValue = 0;  // zero if the minimum increment is undefined
     71  }
     72 
     73  g_value_init(minimumIncrement, G_TYPE_DOUBLE);
     74  g_value_set_double(minimumIncrement, accValue);
     75 }
     76 
     77 static gboolean setCurrentValueCB(AtkValue* obj, const GValue* value) {
     78  Accessible* acc = GetInternalObj(ATK_OBJECT(obj));
     79  if (!acc) {
     80    return false;
     81  }
     82 
     83  double accValue = g_value_get_double(value);
     84  return acc->SetCurValue(accValue);
     85 }
     86 
     87 void valueInterfaceInitCB(AtkValueIface* aIface) {
     88  NS_ASSERTION(aIface, "Invalid aIface");
     89  if (MOZ_UNLIKELY(!aIface)) return;
     90 
     91  aIface->get_current_value = getCurrentValueCB;
     92  aIface->get_maximum_value = getMaximumValueCB;
     93  aIface->get_minimum_value = getMinimumValueCB;
     94  aIface->get_minimum_increment = getMinimumIncrementCB;
     95  aIface->set_current_value = setCurrentValueCB;
     96 }
     97 }