navigator: refactor slider code 59/244059/4 accepted/tizen/unified/20200923.024100 submit/tizen/20200920.213436
authorKamil Konieczny <k.konieczny@samsung.com>
Mon, 14 Sep 2020 11:00:57 +0000 (13:00 +0200)
committerLukasz Oleksak <l.oleksak@samsung.com>
Fri, 18 Sep 2020 13:06:52 +0000 (13:06 +0000)
Refactor functions _value_inc an _value_dec, which
are called after OneFingerFlickUp or Down on slider.
Also while at this, add check for minimum increase
value, if it is zero then calculate increase value
to be 5 percent.

This commit needs fix 1d2dbed4c8cbd1ef80e636ed96d45f0a9fe2fa2d
"elm_slider: add A11Y value interface"

Change-Id: I26f4d2d229ac971a6966348c503f8427bdc3e1e1

src/navigator.c

index 7a3c0568b1c793b5c09b2136474bfc09a0b51155..8264b7d83c5dd9740744c4893e5311e3f5da8151 100644 (file)
@@ -1156,70 +1156,125 @@ TIZEN_PROD_STATIC void _caret_move_backward(NavigatorData *nd)
        return;
 }
 
-TIZEN_PROD_STATIC void _value_inc(NavigatorData *nd, int diff)
+TIZEN_PROD_STATIC AtspiValue *_get_value_interface(NavigatorData *nd)
 {
        AtspiAccessible *current_widget = NULL;
-       GError *err = NULL;
 
        if (!nd || !nd->current_obj)
-               return;
+               return NULL;
 
        current_widget = _get_currently_controlled_accessible(nd->current_obj);
        AtspiValue *value_interface = atspi_accessible_get_value_iface(current_widget);
        g_object_unref(current_widget);
 
-       if (value_interface) {
-               DEBUG("Value interface supported!\n");
-               gdouble current_val = atspi_value_get_current_value(value_interface, &err);
-               GERROR_CHECK(err)
-               DEBUG("Current value: %f\n ", (double)current_val);
-               gdouble minimum_inc = atspi_value_get_minimum_increment(value_interface, &err);
-               DEBUG("Minimum increment: %f\n ", (double)minimum_inc);
-               GERROR_CHECK(err)
-               gdouble maximum_val = atspi_value_get_maximum_value(value_interface, &err);
-               GERROR_CHECK(err)
-               if (diff)
-                       atspi_value_set_current_value(value_interface, ((current_val + diff * nd->slider_offset) > maximum_val) ? maximum_val : (current_val + diff * nd->slider_offset), &err);
-               else
-                       atspi_value_set_current_value(value_interface, current_val + minimum_inc, &err);
+       return value_interface;
+}
+
+TIZEN_PROD_STATIC void _value_inc(NavigatorData *nd, int diff)
+{
+       AtspiValue *value_interface = _get_value_interface(nd);
+       GError *err = NULL;
+
+       if (!value_interface) {
+               ERROR("No value interface supported!\n");
+               return;
+       }
+
+       DEBUG("Value interface supported!\n");
+       gdouble current_val = atspi_value_get_current_value(value_interface, &err);
+       if (err) {
                GERROR_CHECK(err)
                g_object_unref(value_interface);
                return;
        }
-       ERROR("No value interface supported!\n");
+
+       DEBUG("Current value: %f\n ", (double)current_val);
+       gdouble minimum_inc = atspi_value_get_minimum_increment(value_interface, &err);
+       GERROR_CHECK(err)
+       DEBUG("Minimum increment: %f\n ", (double)minimum_inc);
+       gdouble maximum_val = atspi_value_get_maximum_value(value_interface, &err);
+       GERROR_CHECK(err)
+       DEBUG("Maximum value: %f\n ", (double)maximum_val);
+
+       gdouble val = current_val;
+       if (diff){
+               val += diff * nd->slider_offset;
+               DEBUG("new value slide %f", (double)val);
+       } else {
+               if (minimum_inc <= 0.001) {
+                       gdouble minimum_val = atspi_value_get_minimum_value(value_interface, &err);
+                       GERROR_CHECK(err)
+                       minimum_inc = (maximum_val - minimum_val) / 20.0; // 5%
+                       DEBUG("adjust min inc %f", (double)minimum_inc);
+               }
+
+               val += minimum_inc;
+               DEBUG("new value %f", (double)val);
+       }
+
+       if (val > maximum_val) {
+               val = maximum_val;
+               DEBUG("max value %f", (double)val);
+       }
+
+       if (val != current_val) {
+               atspi_value_set_current_value(value_interface, val, &err);
+               GERROR_CHECK(err)
+       }
+       g_object_unref(value_interface);
+
+       return;
 }
 
 TIZEN_PROD_STATIC void _value_dec(NavigatorData *nd, int diff)
 {
-       AtspiAccessible *current_widget = NULL;
+       AtspiValue *value_interface = _get_value_interface(nd);
        GError *err = NULL;
 
-       if (nd->current_obj == NULL)
+       if (!value_interface) {
+               ERROR("No value interface supported!\n");
                return;
+       }
 
-       current_widget = _get_currently_controlled_accessible(nd->current_obj);
-       AtspiValue *value_interface = atspi_accessible_get_value_iface(current_widget);
-       g_object_unref(current_widget);
+       DEBUG("Value interface supported!\n");
 
-       if (value_interface) {
-               DEBUG("Value interface supported!\n");
-               gdouble current_val = atspi_value_get_current_value(value_interface, &err);
-               GERROR_CHECK(err)
-               DEBUG("Current value: %f\n ", (double)current_val);
-               gdouble minimum_inc = atspi_value_get_minimum_increment(value_interface, &err);
-               GERROR_CHECK(err)
-               DEBUG("Minimum increment: %f\n ", (double)minimum_inc);
-               gdouble minimum_val = atspi_value_get_minimum_value(value_interface, &err);
-               GERROR_CHECK(err)
-               if (diff)
-                       atspi_value_set_current_value(value_interface, ((current_val - diff * nd->slider_offset) < minimum_val) ? minimum_val : (current_val - diff * nd->slider_offset), &err);
-               else
-                       atspi_value_set_current_value(value_interface, current_val - minimum_inc, &err);
+       gdouble current_val = atspi_value_get_current_value(value_interface, &err);
+       GERROR_CHECK(err)
+       DEBUG("Current value: %f\n ", (double)current_val);
+       gdouble minimum_inc = atspi_value_get_minimum_increment(value_interface, &err);
+       GERROR_CHECK(err)
+       DEBUG("Minimum increment: %f\n ", (double)minimum_inc);
+       gdouble minimum_val = atspi_value_get_minimum_value(value_interface, &err);
+       GERROR_CHECK(err)
+       DEBUG("Minimum value: %f\n ", (double)minimum_val);
+
+       gdouble val = current_val;
+       if (diff){
+               val -= diff * nd->slider_offset;
+               DEBUG("new value slide %f", (double)val);
+       } else {
+               if (minimum_inc <= 0.001) {
+                       gdouble maximum_val = atspi_value_get_maximum_value(value_interface, &err);
+                       GERROR_CHECK(err)
+                       minimum_inc = (maximum_val - minimum_val) / 20.0; // 5%
+                       DEBUG("adjust min inc %f", (double)minimum_inc);
+               }
+
+               val -= minimum_inc;
+               DEBUG("new value %f", (double)val);
+       }
+
+       if (val < minimum_val) {
+               val = minimum_val;
+               DEBUG("min value %f", (double)val);
+       }
+
+       if (val != current_val) {
+               atspi_value_set_current_value(value_interface, val, &err);
                GERROR_CHECK(err)
-               g_object_unref(value_interface);
-               return;
        }
-       ERROR("No value interface supported!\n");
+       g_object_unref(value_interface);
+       return;
 }
 
 TIZEN_PROD_STATIC void _activate_widget(NavigatorData *nd)