widget: Use rectangle on the stack for region_show

Follow @k-s recommendation and simply use rectangles on the stack rather
than by pointer.

Ref T5363
This commit is contained in:
Jean-Philippe Andre 2017-08-30 11:29:08 +09:00
parent ed68159d34
commit 00862c3c9c
8 changed files with 67 additions and 61 deletions

View File

@ -1202,31 +1202,33 @@ _efl_ui_text_elm_widget_on_focus(Eo *obj, Efl_Ui_Text_Data *sd, Elm_Object_Item
return EINA_TRUE;
}
EOLIAN static Eina_Bool
_efl_ui_text_elm_widget_focus_region_get(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *sd, Eina_Rectangle *r)
EOLIAN static Eina_Rectangle
_efl_ui_text_elm_widget_focus_region_get(Eo *obj EINA_UNUSED, Efl_Ui_Text_Data *sd)
{
Evas_Coord edje_x, edje_y, elm_x, elm_y;
Eina_Rectangle r = {};
EINA_SAFETY_ON_NULL_RETURN_VAL(r, EINA_FALSE);
efl_text_cursor_geometry_get(obj,
efl_text_cursor_get(obj, EFL_TEXT_CURSOR_GET_MAIN),
EFL_TEXT_CURSOR_TYPE_BEFORE,
&r->x, &r->y, &r->w, &r->h,
&r.x, &r.y, &r.w, &r.h,
NULL, NULL, NULL, NULL);
if (sd->single_line)
{
evas_object_geometry_get(sd->entry_edje, NULL, NULL, NULL, &r->h);
r->y = 0;
evas_object_geometry_get(sd->entry_edje, NULL, NULL, NULL, &r.h);
r.y = 0;
}
evas_object_geometry_get(sd->entry_edje, &edje_x, &edje_y, NULL, NULL);
evas_object_geometry_get(obj, &elm_x, &elm_y, NULL, NULL);
r->x += edje_x - elm_x;
r->y += edje_y - elm_y;
r.x += edje_x - elm_x;
r.y += edje_y - elm_y;
if (r.w < 1) r.w = 1;
if (r.h < 1) r.h = 1;
return EINA_TRUE;
return r;
}
static void

View File

@ -663,9 +663,7 @@ _show_region_job(void *data)
focus_obj = elm_widget_focused_object_get(data);
if (focus_obj)
{
Eina_Rectangle r;
elm_widget_focus_region_get(focus_obj, &r);
Eina_Rectangle r = elm_widget_focus_region_get(focus_obj);
if (r.h < _elm_config->finger_size)
r.h = _elm_config->finger_size;

View File

@ -1308,14 +1308,14 @@ _elm_entry_elm_widget_on_focus(Eo *obj, Elm_Entry_Data *sd, Elm_Object_Item *ite
return EINA_TRUE;
}
EOLIAN static Eina_Bool
_elm_entry_elm_widget_focus_region_get(Eo *obj, Elm_Entry_Data *sd, Eina_Rectangle *r)
EOLIAN static Eina_Rectangle
_elm_entry_elm_widget_focus_region_get(Eo *obj, Elm_Entry_Data *sd)
{
Evas_Coord cx, cy, cw, ch;
Evas_Coord edx, edy;
Evas_Coord elx, ely, elw, elh;
Eina_Rectangle r;
EINA_SAFETY_ON_NULL_RETURN_VAL(r, EINA_FALSE);
edje_object_part_text_cursor_geometry_get
(sd->entry_edje, "elm.text", &cx, &cy, &cw, &ch);
@ -1330,14 +1330,14 @@ _elm_entry_elm_widget_focus_region_get(Eo *obj, Elm_Entry_Data *sd, Eina_Rectang
}
evas_object_geometry_get(obj, &elx, &ely, &elw, &elh);
r->x = cx + edx - elx;
if ((cw < elw) && (r->x + cw > elw)) r->x = elw - cw;
r->y = cy + edy - ely;
if ((ch < elh) && (r->y + ch > elh)) r->y = elh - ch;
r->w = cw;
r->h = ch;
r.x = cx + edx - elx;
if ((cw < elw) && (r.x + cw > elw)) r.x = elw - cw;
r.y = cy + edy - ely;
if ((ch < elh) && (r.y + ch > elh)) r.y = elh - ch;
r.w = MAX(cw, 1);
r.h = MAX(ch, 1);
return EINA_TRUE;
return r;
}
static void

View File

@ -3539,26 +3539,29 @@ _elm_gengrid_elm_widget_on_focus(Eo *obj, Elm_Gengrid_Data *sd, Elm_Object_Item
return EINA_TRUE;
}
EOLIAN static Eina_Bool
_elm_gengrid_elm_widget_focus_region_get(Eo *obj, Elm_Gengrid_Data *sd, Eina_Rectangle *r)
EOLIAN static Eina_Rectangle
_elm_gengrid_elm_widget_focus_region_get(Eo *obj, Elm_Gengrid_Data *sd)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(r, EINA_FALSE);
Eina_Rectangle r = {};
if (!sd->focused_item) goto end;
if (elm_object_focus_region_show_mode_get(obj) == ELM_FOCUS_REGION_SHOW_ITEM)
{
Evas_Coord vx, vy;
ELM_GENGRID_ITEM_DATA_GET(sd->focused_item, focus_it);
evas_object_geometry_get(VIEW(focus_it), &r->x, &r->y, &r->w, &r->h);
evas_object_geometry_get(VIEW(focus_it), &r.x, &r.y, &r.w, &r.h);
evas_object_geometry_get(obj, &vx, &vy, NULL, NULL);
r->x -= vx;
r->y -= vy;
r.x -= vx;
r.y -= vy;
if (r.w < 1) r.w = 1;
if (r.h < 1) r.h = 1;
return EINA_TRUE;
return r;
}
end:
return elm_obj_widget_focus_region_get(efl_super(obj, MY_CLASS), r);
return elm_obj_widget_focus_region_get(efl_super(obj, MY_CLASS));
}
static Eina_Bool _elm_gengrid_smart_focus_next_enable = EINA_FALSE;

View File

@ -1106,23 +1106,28 @@ _elm_panel_toggle(Eo *obj, Elm_Panel_Data *_pd EINA_UNUSED)
_panel_toggle(NULL, obj, NULL, NULL);
}
EOLIAN static Eina_Bool
_elm_panel_elm_widget_focus_region_get(Eo *obj, Elm_Panel_Data *sd, Eina_Rectangle *r)
EOLIAN static Eina_Rectangle
_elm_panel_elm_widget_focus_region_get(Eo *obj, Elm_Panel_Data *sd)
{
elm_interface_scrollable_content_pos_get(obj, &r->x, &r->y);
evas_object_geometry_get(obj, NULL, NULL, &r->w, &r->h);
Eina_Rectangle r = {};
elm_interface_scrollable_content_pos_get(obj, &r.x, &r.y);
evas_object_geometry_get(obj, NULL, NULL, &r.w, &r.h);
switch (sd->orient)
{
case ELM_PANEL_ORIENT_TOP:
case ELM_PANEL_ORIENT_BOTTOM:
r->h *= sd->content_size_ratio;
r.h *= sd->content_size_ratio;
break;
case ELM_PANEL_ORIENT_LEFT:
case ELM_PANEL_ORIENT_RIGHT:
r->w *= sd->content_size_ratio;
r.w *= sd->content_size_ratio;
break;
}
return EINA_TRUE;
if (r.w < 1) r.w = 1;
if (r.h < 1) r.h = 1;
return r;
}
static void

View File

@ -1025,8 +1025,8 @@ _propagate_event_legacy(Eo *parent, const Efl_Event *event, Eo *obj, Elm_Event_C
/**
* @internal
*
* If elm_widget_focus_region_get() returns EINA_FALSE, this function will
* ignore region show action.
* If elm_widget_focus_region_get() returns an empty rect (w or h <= 0),
* this function will ignore region show action.
*/
EOLIAN static void
_elm_widget_focus_region_show(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
@ -1038,8 +1038,8 @@ _elm_widget_focus_region_show(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
o = elm_widget_parent_get(obj);
if (!o) return;
if (!elm_widget_focus_region_get(obj, &r))
return;
r = elm_widget_focus_region_get(obj);
if (eina_rectangle_is_empty(&r)) return;
evas_object_geometry_get(obj, &ox, &oy, NULL, NULL);
@ -1070,7 +1070,7 @@ _elm_widget_focus_region_show(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
break;
}
elm_widget_focus_region_get(o, &r);
r = elm_widget_focus_region_get(o);
evas_object_geometry_get(o, &ox, &oy, NULL, NULL);
}
else
@ -3463,8 +3463,7 @@ _elm_widget_show_region_get(const Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd
*
* Get the focus region of the given widget.
*
* @return show region or not
* (@c EINA_TRUE = show region/@c EINA_FALSE = do not show region). Default is @c EINA_FALSE.
* @return The region to show. If it's not a valid rectangle it will not show.
*
* The focus region is the area of a widget that should brought into the
* visible area when the widget is focused. Mostly used to show the part of
@ -3472,22 +3471,17 @@ _elm_widget_show_region_get(const Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd
* to the object @p obj.
*
* @param obj The widget object
* @param x Where to store the x coordinate of the area
* @param y Where to store the y coordinate of the area
* @param w Where to store the width of the area
* @param h Where to store the height of the area
* @return The region to show, in relative coordinates. If it's not a valid
* rectangle (i.e. w or h <= 0) it will be ignored.
*
* @ingroup Widget
*/
EOLIAN static Eina_Bool
_elm_widget_focus_region_get(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED, Eina_Rectangle *r)
EOLIAN static Eina_Rectangle
_elm_widget_focus_region_get(Eo *obj, Elm_Widget_Smart_Data *_pd EINA_UNUSED)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(r, EINA_FALSE);
efl_gfx_size_get(obj, &r->w, &r->h);
r->x = 0;
r->y = 0;
if ((r->w <= 0) || (r->h <= 0)) return EINA_FALSE;
return EINA_TRUE;
Eina_Rectangle r = {};
efl_gfx_size_get(obj, &r.w, &r.h);
return r;
}
EOLIAN static void

View File

@ -467,6 +467,8 @@ abstract Elm.Widget (Efl.Canvas.Group, Elm.Interface.Atspi_Accessible,
scroll_hold_push {
[[Push scroll hold]]
}
/* FIXME: property with a Eina.Rectangle */
show_region_set {
[[Set show region]]
params {
@ -508,19 +510,21 @@ abstract Elm.Widget (Efl.Canvas.Group, Elm.Interface.Atspi_Accessible,
Note: The region is relative to the top-left corner of the widget,
i.e. X,Y start from 0,0 to indicate the top-left corner of the
widget.
widget. W,H must be greater or equal to 1 for this region to be
taken into account, otherwise it is ignored.
See also @.focus_region_show.
]]
get {
return: bool; [[If $false, @.focus_region_show will not do anything.]]
}
values {
region: Eina.Rectangle; [[The relative region to show.]]
region: Eina.Rectangle;
[[The relative region to show. If width or height is <= 0 it
will be ignored, and no action will be taken.]]
}
}
focus_region_show @protected {
[[Show focus region.
[[Show the region of interest inside this widget.
See also @.focus_region.
]]

View File

@ -721,7 +721,7 @@ EAPI void elm_widget_disabled_set(Evas_Object *obj, Eina_Bool disabl
EAPI Eina_Bool elm_widget_disabled_get(const Evas_Object *obj);
EAPI void elm_widget_show_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, Eina_Bool forceshow);
EAPI void elm_widget_show_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h);
EAPI Eina_Bool elm_widget_focus_region_get(const Evas_Object *obj, Eina_Rectangle *r);
EAPI Eina_Rectangle elm_widget_focus_region_get(const Evas_Object *obj);
EAPI void elm_widget_focus_region_show(Evas_Object *obj);
EAPI void elm_widget_scroll_hold_push(Evas_Object *obj);
EAPI void elm_widget_scroll_hold_pop(Evas_Object *obj);