elementary : Partly rollback for about the feature "focus movement by

arrow keys". There is a better way to support this feature, so
implementing it now.


SVN revision: 62168
This commit is contained in:
WooHyun Jung 2011-08-06 07:39:31 +00:00
parent ad320ca015
commit cf9f98b706
4 changed files with 54 additions and 311 deletions

View File

@ -320,11 +320,7 @@ extern "C" {
typedef enum _Elm_Focus_Direction
{
ELM_FOCUS_PREVIOUS,
ELM_FOCUS_NEXT,
ELM_FOCUS_UP,
ELM_FOCUS_DOWN,
ELM_FOCUS_LEFT,
ELM_FOCUS_RIGHT
ELM_FOCUS_NEXT
} Elm_Focus_Direction;
typedef enum _Elm_Text_Format

View File

@ -53,7 +53,6 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
if (type != EVAS_CALLBACK_KEY_DOWN) return EINA_FALSE;
Evas_Event_Key_Down *ev = event_info;
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return EINA_FALSE;
if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
if (elm_widget_disabled_get(obj)) return EINA_FALSE;
@ -68,131 +67,27 @@ _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type ty
Evas_Coord v_h = 0;
Evas_Coord page_x = 0;
Evas_Coord page_y = 0;
Evas_Coord c_x = 0;
Evas_Coord c_y = 0;
elm_smart_scroller_child_pos_get(wd->scr, &x, &y);
elm_smart_scroller_step_size_get(wd->scr, &step_x, &step_y);
elm_smart_scroller_page_size_get(wd->scr, &page_x, &page_y);
elm_smart_scroller_child_viewport_size_get(wd->scr, &v_w, &v_h);
evas_object_geometry_get(wd->content, &c_x, &c_y, &max_x, &max_y);
if ((!strcmp(ev->keyname, "Left")) ||
(!strcmp(ev->keyname, "KP_Left")) ||
(!strcmp(ev->keyname, "Right")) ||
(!strcmp(ev->keyname, "KP_Right")) ||
(!strcmp(ev->keyname, "Up")) ||
(!strcmp(ev->keyname, "KP_Up")) ||
(!strcmp(ev->keyname, "Down")) ||
(!strcmp(ev->keyname, "KP_Down")))
{
Evas_Object *current_focus = NULL;
Evas_Object *new_focus = NULL;
Eina_List *can_focus_list = NULL;
Evas_Coord f_x = 0;
Evas_Coord f_y = 0;
Evas_Coord f_w = 0;
Evas_Coord f_h = 0;
current_focus = elm_widget_focused_object_get(obj);
evas_object_geometry_get(current_focus, &f_x, &f_y, &f_w, &f_h);
can_focus_list = elm_widget_can_focus_child_list_get(obj);
if ((current_focus == obj) ||
(!ELM_RECTS_INTERSECT(x, y, v_w, v_h,
(f_x - c_x), (f_y - c_y), f_w, f_h)))
{
Evas_Object *cur;
Eina_List *l;
double weight = 0.0;
EINA_LIST_FOREACH(can_focus_list, l, cur)
{
double cur_weight = 0.0;
evas_object_geometry_get(cur, &f_x, &f_y, &f_w, &f_h);
if (ELM_RECTS_INTERSECT(x, y, v_w, v_h,
(f_x - c_x), (f_y - c_y), f_w, f_h))
{
if ((f_x - c_x) > x)
cur_weight += ((f_x - c_x) - x) * ((f_x - c_x) - x);
if ((f_y - c_y) > y)
cur_weight += ((f_y - c_y) - y) * ((f_y - c_y) - y);
if (cur_weight == 0.0)
{
elm_widget_focus_steal(cur);
return EINA_TRUE;
}
cur_weight = 1.0 / cur_weight;
if (cur_weight > weight)
{
new_focus = cur;
weight = cur_weight;
}
}
}
if (new_focus)
{
elm_widget_focus_steal(new_focus);
return EINA_TRUE;
}
}
else
{
Evas_Object *tmp = NULL;
Elm_Focus_Direction dir = ELM_FOCUS_PREVIOUS;
void *(*list_data_get) (const Eina_List *list);
list_data_get = eina_list_data_get;
if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
dir = ELM_FOCUS_LEFT;
else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
dir = ELM_FOCUS_RIGHT;
else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
dir = ELM_FOCUS_UP;
else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
dir = ELM_FOCUS_DOWN;
if (elm_widget_focus_list_next_get(obj, can_focus_list, list_data_get, dir, &tmp))
new_focus = tmp;
if (new_focus)
{
Evas_Coord l_x = 0;
Evas_Coord l_y = 0;
Evas_Coord l_w = 0;
Evas_Coord l_h = 0;
evas_object_geometry_get(new_focus, &f_x, &f_y, &f_w, &f_h);
l_x = f_x - c_x - step_x;
l_y = f_y - c_y - step_y;
l_w = f_w + (step_x * 2);
l_h = f_h + (step_y * 2);
if (ELM_RECTS_INTERSECT(x, y, v_w, v_h, l_x, l_y, l_w, l_h))
{
elm_widget_focus_steal(new_focus);
return EINA_TRUE;
}
}
}
}
elm_scroller_child_size_get(obj, &max_x, &max_y);
if ((!strcmp(ev->keyname, "Left")) || (!strcmp(ev->keyname, "KP_Left")))
{
if (x <= 0) return EINA_FALSE;
x -= step_x;
}
else if ((!strcmp(ev->keyname, "Right")) || (!strcmp(ev->keyname, "KP_Right")))
{
if (x >= (max_x - v_w)) return EINA_FALSE;
x += step_x;
}
else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
{
if (y == 0) return EINA_FALSE;
y -= step_y;
}
else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
{
if (y >= (max_y - v_h)) return EINA_FALSE;
y += step_y;
}
else if ((!strcmp(ev->keyname, "Home")) || (!strcmp(ev->keyname, "KP_Home")))

View File

@ -158,10 +158,6 @@ static void _if_focused_revert(Evas_Object *obj,
static Evas_Object *_newest_focus_order_get(Evas_Object *obj,
unsigned int *newest_focus_order,
Eina_Bool can_focus_only);
static Eina_Bool _focus_list_direction_nearest_get(Evas_Object *obj,
Eina_List *list,
Elm_Focus_Direction dir,
Evas_Object **nearest);
/* local subsystem globals */
static Evas_Smart *_e_smart = NULL;
@ -403,96 +399,6 @@ _elm_widget_focus_region_show(const Evas_Object *obj)
}
}
static Eina_Bool
_focus_list_direction_nearest_get(Evas_Object *obj,
Eina_List *list,
Elm_Focus_Direction dir,
Evas_Object **nearest)
{
Evas_Object *cur, *next = NULL;
Eina_List *l;
double weight = 0.0;
Evas_Coord x, y, w, h, cx, cy;
if (!nearest) return EINA_FALSE;
*nearest = NULL;
evas_object_geometry_get(obj, &x, &y, &w, &h);
cx = x + (w / 2);
cy = y + (h / 2);
EINA_LIST_FOREACH(list, l, cur)
{
if (obj == cur) continue;
Evas_Coord cur_x, cur_y, cur_w, cur_h;
int w_gap = 0, h_gap = 0;
double cur_weight = 0.0;
evas_object_geometry_get(cur, &cur_x, &cur_y, &cur_w, &cur_h);
if (dir == ELM_FOCUS_LEFT)
{
if (x < (cur_x + cur_w)) continue;
w_gap = x - (cur_x + cur_w);
if ((cy >= cur_y) && (cy <= (cur_y + cur_h)))
h_gap = 0;
else if (cy > (cur_y + cur_h))
h_gap = cy - (cur_y + cur_h);
else if (cy < (cur_y))
h_gap = cur_y - cy;
}
else if (dir == ELM_FOCUS_RIGHT)
{
if ((x + w) > cur_x) continue;
w_gap = cur_x - (x + w);
if ((cy >= cur_y) && (cy <= (cur_y + cur_h)))
h_gap = 0;
else if (cy > (cur_y + cur_h))
h_gap = cy - (cur_y + cur_h);
else if (cy < (cur_y))
h_gap = cur_y - cy;
}
else if (dir == ELM_FOCUS_UP)
{
if (y < (cur_y + cur_h)) continue;
h_gap = y - (cur_y + cur_h);
if ((cx >= cur_x) && (cx <= (cur_x + cur_w)))
w_gap = 0;
else if (cx < cur_x)
w_gap = cur_x - cx;
else if (cx > (cur_x + cur_w))
w_gap = cur_x + cur_w - cx;
}
else if (dir == ELM_FOCUS_DOWN)
{
if ((y + h) > cur_y) continue;
h_gap = cur_y - (y + h);
if ((cx >= cur_x) && (cx <= (cur_x + cur_w))) w_gap = 0;
else if (cx < cur_x)
w_gap = cur_x - cx;
else if (cx > (cur_x + cur_w))
w_gap = cur_x + cur_w - cx;
}
cur_weight = (w_gap * w_gap) + (h_gap * h_gap);
if (cur_weight == 0.0)
{
*nearest = cur;
return EINA_TRUE;
}
cur_weight = 1.0 / cur_weight;
if (cur_weight > weight)
{
weight = cur_weight;
next = cur;
}
}
if (!next) return EINA_FALSE;
*nearest = next;
return EINA_TRUE;
}
/**
* @defgroup Widget Widget
*
@ -1752,110 +1658,64 @@ elm_widget_focus_list_next_get(const Evas_Object *obj,
list_next = eina_list_prev;
}
else if (dir == ELM_FOCUS_NEXT)
{
list_next = eina_list_next;
}
else if ((dir == ELM_FOCUS_LEFT) || (dir == ELM_FOCUS_RIGHT) ||
(dir == ELM_FOCUS_UP) || (dir == ELM_FOCUS_DOWN))
{
list_next = eina_list_next;
}
list_next = eina_list_next;
else
return EINA_FALSE;
if ((dir == ELM_FOCUS_PREVIOUS) || (dir == ELM_FOCUS_NEXT))
const Eina_List *l = items;
/* Recovery last focused sub item */
if (elm_widget_focus_get(obj))
for (; l; l = list_next(l))
{
Evas_Object *cur = list_data_get(l);
if (elm_widget_focus_get(cur)) break;
}
const Eina_List *start = l;
Evas_Object *to_focus = NULL;
/* Interate sub items */
/* Go to end of list */
for (; l; l = list_next(l))
{
const Eina_List *l = items;
/* Recovery last focused sub item */
if (elm_widget_focus_get(obj))
for (; l; l = list_next(l))
{
Evas_Object *cur = list_data_get(l);
if (elm_widget_focus_get(cur)) break;
}
const Eina_List *start = l;
Evas_Object *to_focus = NULL;
/* Interate sub items */
/* Go to end of list */
for (; l; l = list_next(l))
{
Evas_Object *tmp = NULL;
Evas_Object *cur = list_data_get(l);
if (elm_widget_parent_get(cur) != obj)
continue;
/* Try Focus cycle in subitem */
if (elm_widget_focus_next_get(cur, dir, &tmp))
{
*next = tmp;
return EINA_TRUE;
}
else if ((tmp) && (!to_focus))
to_focus = tmp;
}
l = items;
/* Get First possible */
for (; l != start; l = list_next(l))
{
Evas_Object *tmp = NULL;
Evas_Object *cur = list_data_get(l);
if (elm_widget_parent_get(cur) != obj)
continue;
/* Try Focus cycle in subitem */
elm_widget_focus_next_get(cur, dir, &tmp);
if (tmp)
{
*next = tmp;
return EINA_FALSE;
}
}
*next = to_focus;
return EINA_FALSE;
}
else if ((dir == ELM_FOCUS_LEFT) || (dir == ELM_FOCUS_RIGHT) ||
(dir == ELM_FOCUS_UP) || (dir == ELM_FOCUS_DOWN))
{
Eina_List *can_focus_list;
Evas_Object *tmp = NULL;
Evas_Object *cur;
Evas_Object *cur = list_data_get(l);
can_focus_list = elm_widget_can_focus_child_list_get(obj);
if (can_focus_list)
if (elm_widget_parent_get(cur) != obj)
continue;
/* Try Focus cycle in subitem */
if (elm_widget_focus_next_get(cur, dir, &tmp))
{
Eina_List *l;
EINA_LIST_FOREACH(can_focus_list, l, cur)
{
if (elm_widget_focus_get(cur))
{
if (_focus_list_direction_nearest_get(cur, can_focus_list, dir, &tmp))
{
*next = tmp;
return EINA_TRUE;
}
else
{
*next = cur;
return EINA_FALSE;
}
}
}
if (elm_widget_focus_get(obj))
{
*next = list_data_get(can_focus_list);
return EINA_FALSE;
}
*next = tmp;
return EINA_TRUE;
}
else if ((tmp) && (!to_focus))
to_focus = tmp;
}
l = items;
/* Get First possible */
for (; l != start; l = list_next(l))
{
Evas_Object *tmp = NULL;
Evas_Object *cur = list_data_get(l);
if (elm_widget_parent_get(cur) != obj)
continue;
/* Try Focus cycle in subitem */
elm_widget_focus_next_get(cur, dir, &tmp);
if (tmp)
{
*next = tmp;
return EINA_FALSE;
}
}
*next = to_focus;
return EINA_FALSE;
}

View File

@ -400,30 +400,22 @@ _elm_win_event_cb(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_T
else if ((!strcmp(ev->keyname, "Left")) ||
(!strcmp(ev->keyname, "KP_Left")))
{
elm_widget_focus_cycle(obj, ELM_FOCUS_LEFT);
ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
return EINA_TRUE;
//TODO : woohyun jung
}
else if ((!strcmp(ev->keyname, "Right")) ||
(!strcmp(ev->keyname, "KP_Right")))
{
elm_widget_focus_cycle(obj, ELM_FOCUS_RIGHT);
ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
return EINA_TRUE;
//TODO : woohyun jung
}
else if ((!strcmp(ev->keyname, "Up")) ||
(!strcmp(ev->keyname, "KP_Up")))
{
elm_widget_focus_cycle(obj, ELM_FOCUS_UP);
ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
return EINA_TRUE;
//TODO : woohyun jung
}
else if ((!strcmp(ev->keyname, "Down")) ||
(!strcmp(ev->keyname, "KP_Down")))
{
elm_widget_focus_cycle(obj, ELM_FOCUS_DOWN);
ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
return EINA_TRUE;
//TODO : woohyun jung
}
}