[Genlist/Gengrid/List] Fix Focus
authorTae-Hwan Kim <the81.kim@samsung.com>
Tue, 11 Jun 2013 06:40:28 +0000 (15:40 +0900)
committerSungho Kwak <sungho1.kwak@samsung.com>
Wed, 12 Jun 2013 05:40:54 +0000 (14:40 +0900)
Only when focus highlight is enabled, highlight focused item.
Other cases, just move focus internaly.

Change-Id: Ia22fff5ff4dee377437eafaf545fd1111478d995

src/lib/elm_gengrid.c
src/lib/elm_genlist.c
src/lib/elm_list.c

index 938851f..f384489 100644 (file)
@@ -921,7 +921,9 @@ _item_realize(Elm_Gen_Item *it)
         if (it->selected)
           edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
 
-        if (elm_widget_focus_get(ELM_WIDGET_DATA(GG_IT(it)->wsd)->obj))
+        if (elm_widget_focus_get(ELM_WIDGET_DATA(GG_IT(it)->wsd)->obj) &&
+            elm_win_focus_highlight_enabled_get
+            (elm_widget_top_get(ELM_WIDGET_DATA(GG_IT(it)->wsd)->obj)))
           {
              if (GG_IT(it)->wsd->focused)
                 edje_object_signal_emit (VIEW(GG_IT(it)->wsd->focused), "elm,state,focused", "elm");
@@ -1779,41 +1781,45 @@ _item_single_select_right(Elm_Gengrid_Smart_Data *sd)
    return EINA_TRUE;
 }
 
-static void _gengrid_item_focused(Elm_Gen_Item *it)
+static void _gengrid_item_unfocused(Elm_Gen_Item *it)
 {
    if (!it) return;
    Elm_Gengrid_Smart_Data *sd = GG_IT(it)->wsd;
-   Evas_Coord x, y, w, h, sx, sy, sw, sh;
+   if (!sd->focused) return;
 
-   evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
-   evas_object_geometry_get(ELM_WIDGET_DATA(sd)->obj, &sx, &sy, &sw, &sh);
-   if ((x < sx) || (y < sy) || ((x + w) > (sx + sw)) || ((y + h) > (sy + sh)))
+   if (sd->focused_content)
      {
-        elm_gengrid_item_bring_in((Elm_Object_Item *)it,
-                                  ELM_GENLIST_ITEM_SCROLLTO_IN);
+        elm_object_focus_set(ELM_WIDGET_DATA(sd)->obj, EINA_FALSE);
+        elm_object_focus_set(ELM_WIDGET_DATA(sd)->obj, EINA_TRUE);
+        sd->focused_content = NULL;
      }
    edje_object_signal_emit
-      (VIEW(it), "elm,state,focused", "elm");
+      (VIEW(sd->focused), "elm,state,unfocused", "elm");
 
-   sd->focused = it;
+   if (it == sd->focused) sd->focused = NULL;
 }
 
-static void _gengrid_item_unfocused(Elm_Gen_Item *it)
+static void _gengrid_item_focused(Elm_Gen_Item *it)
 {
    if (!it) return;
    Elm_Gengrid_Smart_Data *sd = GG_IT(it)->wsd;
-   if (!sd->focused) return;
+   Evas_Coord x, y, w, h, sx, sy, sw, sh;
 
-   if (sd->focused_content)
+   if (sd->focused && (it != sd->focused)) _gengrid_item_unfocused(sd->focused);
+   evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
+   evas_object_geometry_get(ELM_WIDGET_DATA(sd)->obj, &sx, &sy, &sw, &sh);
+   if ((x < sx) || (y < sy) || ((x + w) > (sx + sw)) || ((y + h) > (sy + sh)))
      {
-        elm_object_focus_set(ELM_WIDGET_DATA(sd)->obj, EINA_FALSE);
-        elm_object_focus_set(ELM_WIDGET_DATA(sd)->obj, EINA_TRUE);
-        sd->focused_content = NULL;
+        elm_gengrid_item_bring_in((Elm_Object_Item *)it,
+                                  ELM_GENLIST_ITEM_SCROLLTO_IN);
      }
-   edje_object_signal_emit
-      (VIEW(sd->focused), "elm,state,unfocused", "elm");
 
-   if (it == sd->focused) sd->focused = NULL;
+   if (elm_win_focus_highlight_enabled_get
+       (elm_widget_top_get(ELM_WIDGET_DATA(sd)->obj)))
+     edje_object_signal_emit
+       (VIEW(it), "elm,state,focused", "elm");
+
+   sd->focused = it;
 }
 
 static Elm_Gen_Item *_gengrid_item_focusable_search(Elm_Gen_Item *it, int dir)
@@ -2231,15 +2237,8 @@ _elm_gengrid_smart_on_focus(Evas_Object *obj)
      {
         if (elm_win_focus_highlight_enabled_get(elm_widget_top_get(obj)))
           {
-             if (sd->last_selected_item)
-               {
-                  _gengrid_item_focused((Elm_Gen_Item *)sd->last_selected_item);
-               }
-             else if (sd->focused)
-               {
-                  edje_object_signal_emit
-                    (VIEW(sd->focused), "elm,state,focused", "elm");
-               }
+             if (sd->focused)
+                _gengrid_item_focused(sd->focused);
              else
                _gengrid_item_focused_next(sd, FOCUS_DIR_DOWN);
           }
@@ -2510,6 +2509,7 @@ _item_disable_hook(Elm_Object_Item *item)
 
    if (it->generation < GG_IT(it)->wsd->generation) return;
 
+   if (it == GG_IT(it)->wsd->focused) _gengrid_item_unfocused(it);
    if (it->realized)
      {
         if (elm_widget_item_disabled_get(it))
@@ -2716,6 +2716,8 @@ _item_select(Elm_Gen_Item *it)
    else if (GG_IT(it)->wsd->select_mode != ELM_OBJECT_SELECT_MODE_ALWAYS)
      return;
 
+   _gengrid_item_focused(it);
+
    evas_object_ref(obj);
    it->walking++;
    GG_IT(it)->wsd->walking++;
index abda71a..6257f84 100644 (file)
@@ -1884,11 +1884,15 @@ _item_realize(Elm_Gen_Item *it,
              edje_object_message_signal_process(it->item->deco_it_view);
           }
      }
-   if (elm_widget_focus_get(ELM_WIDGET_DATA(GL_IT(it)->wsd)->obj))
+
+   if (elm_widget_focus_get(ELM_WIDGET_DATA(GL_IT(it)->wsd)->obj) &&
+       elm_win_focus_highlight_enabled_get
+       (elm_widget_top_get(ELM_WIDGET_DATA(GL_IT(it)->wsd)->obj)))
      {
         if (GL_IT(it)->wsd->focused)
            edje_object_signal_emit (VIEW(GL_IT(it)->wsd->focused), "elm,state,focused", "elm");
      }
+
    edje_object_message_signal_process(VIEW(it));
 }
 
@@ -2586,7 +2590,7 @@ static void _item_focused(Elm_Gen_Item *it)
    Elm_Genlist_Smart_Data *sd = GL_IT(it)->wsd;
    Evas_Coord x, y, w, h, sx, sy, sw, sh;
 
-   if (sd->focused && (it == sd->focused)) _item_unfocused(sd->focused);
+   if (sd->focused && (it != sd->focused)) _item_unfocused(sd->focused);
    evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
    evas_object_geometry_get(ELM_WIDGET_DATA(sd)->obj, &sx, &sy, &sw, &sh);
    if ((x < sx) || (y < sy) || ((x + w) > (sx + sw)) || ((y + h) > (sy + sh)))
@@ -2595,12 +2599,16 @@ static void _item_focused(Elm_Gen_Item *it)
                                   ELM_GENLIST_ITEM_SCROLLTO_IN);
      }
 
-   if (it->deco_all_view)
-     edje_object_signal_emit
-       (it->deco_all_view, "elm,state,focused", "elm");
-   else
-     edje_object_signal_emit
-       (VIEW(it), "elm,state,focused", "elm");
+   if (elm_win_focus_highlight_enabled_get
+       (elm_widget_top_get(ELM_WIDGET_DATA(sd)->obj)))
+     {
+        if (it->deco_all_view)
+          edje_object_signal_emit
+            (it->deco_all_view, "elm,state,focused", "elm");
+        else
+          edje_object_signal_emit
+            (VIEW(it), "elm,state,focused", "elm");
+     }
    sd->focused = it;
 }
 
@@ -2650,7 +2658,6 @@ _item_select(Elm_Gen_Item *it)
    it->selected = EINA_TRUE;
    sd->selected = eina_list_append(sd->selected, it);
    sd->last_selected_item = (Elm_Object_Item *)it;
-   if (sd->focused) _item_unfocused(sd->focused);
    _item_focused(it);
 
    if (it->func.func) it->func.func((void *)it->func.data, obj, it);
@@ -3029,19 +3036,14 @@ _elm_genlist_smart_on_focus(Evas_Object *obj)
      sd->last_selected_item = eina_list_data_get(sd->selected);
 
    if (sd->select_on_focus_enabled) return EINA_TRUE;
-
    if (elm_widget_focus_get(obj))
      {
         if (elm_win_focus_highlight_enabled_get(elm_widget_top_get(obj)))
           {
              if (sd->focused)
-               {
-                  _item_focused(sd->focused);
-               }
+               _item_focused(sd->focused);
              else
-               {
-                  _item_focused_next(sd, FOCUS_DIR_DOWN);
-               }
+               _item_focused_next(sd, FOCUS_DIR_DOWN);
           }
      }
    else
index 926cd08..3402814 100644 (file)
@@ -221,8 +221,10 @@ static void _item_focused(Elm_List_Item *it)
         elm_list_item_bring_in((Elm_Object_Item *)it);
      }
 
-   edje_object_signal_emit
-      (VIEW(it), "elm,state,focused", "elm");
+   if (elm_win_focus_highlight_enabled_get
+       (elm_widget_top_get(ELM_WIDGET_DATA(sd)->obj)))
+     edje_object_signal_emit
+       (VIEW(it), "elm,state,focused", "elm");
 
    sd->focused = (Elm_Object_Item *)it;
 }
@@ -1000,17 +1002,10 @@ _elm_list_smart_on_focus(Evas_Object *obj)
      {
         if (elm_win_focus_highlight_enabled_get(elm_widget_top_get(obj)))
           {
-             if (sd->last_selected_item)
-               {
-                  _item_focused((Elm_List_Item *)sd->last_selected_item);
-               }
-             else if (sd->focused)
-               {
-                  edje_object_signal_emit
-                    (VIEW(sd->focused), "elm,state,focused", "elm");
-               }
+             if (sd->focused)
+               _item_focused((Elm_List_Item *)sd->focused);
              else
-                _item_focused_next(sd, FOCUS_DIR_DOWN);
+               _item_focused_next(sd, FOCUS_DIR_DOWN);
           }
      }
    else