[Elm_ColorSelector]: Unnecessary widget creations, code execution avoided.

Summary:
Issue: Too many widgets get created during smart add itself, even if
not necessary, adding to the launch time.
Solution:
Create widgets based on mode, check for modes in generic functions
like smart theme, focus etc:-

Test Plan: elementary_test can be used to test colorselector demo.

Reviewers: cedric, raster, Hermet

Subscribers: rajeshps, govi, poornima.srinivasan

Differential Revision: https://phab.enlightenment.org/D2532
This commit is contained in:
shilpa.singh 2015-05-19 20:56:48 +09:00 committed by ChunEon Park
parent 2fd7946767
commit dde6e49e49
1 changed files with 206 additions and 150 deletions

View File

@ -402,6 +402,7 @@ _update_hsla_from_colorbar(Evas_Object *obj, Color_Type type, double x)
if (type != ALPHA && !_hsl_to_rgb(sd)) return;
_update_colorbars(sd);
if ((sd->mode == ELM_COLORSELECTOR_ALL) || (sd->mode == ELM_COLORSELECTOR_PICKER))
_color_picker_init(sd);
evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
evas_object_smart_callback_call(obj, SIG_CHANGED_USER, NULL);
@ -426,6 +427,9 @@ _colors_set(Evas_Object *obj,
sd->b = b;
sd->a = a;
if ((sd->mode == ELM_COLORSELECTOR_ALL) || (sd->mode == ELM_COLORSELECTOR_COMPONENTS)
|| (sd->mode == ELM_COLORSELECTOR_BOTH))
{
_rgb_to_hsl(sd);
edje_object_part_drag_value_get
@ -453,6 +457,8 @@ _colors_set(Evas_Object *obj,
(sd->cb_data[3]->colorbar, "elm.arrow", x, y);
_update_colorbars(sd);
}
if ((sd->mode == ELM_COLORSELECTOR_ALL) || (sd->mode == ELM_COLORSELECTOR_PICKER))
_color_picker_init(sd);
evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
}
@ -660,7 +666,7 @@ _mouse_out_canvas(void *data, Evas *e EINA_UNUSED, void *event_info EINA_UNUSED)
}
static void
_color_picker_add(Evas_Object *obj, Elm_Colorselector_Data *sd)
_create_colorpicker(Evas_Object *obj)
{
Evas_Object *ed;
Evas_Object *im;
@ -668,6 +674,9 @@ _color_picker_add(Evas_Object *obj, Elm_Colorselector_Data *sd)
Evas_Object *bx;
Eina_Stringshare *style;
int i;
ELM_COLORSELECTOR_DATA_GET(obj, sd);
if (sd->picker) return;
#ifdef HAVE_ELEMENTARY_X
Ecore_X_Window xwin;
@ -678,6 +687,14 @@ _color_picker_add(Evas_Object *obj, Elm_Colorselector_Data *sd)
ecore_x_input_raw_select(sd->grab.xroot);
}
#endif
/* setup the color picker */
sd->picker = elm_layout_add(obj);
if (!elm_layout_theme_set(sd->picker, "colorselector", "picker/base", elm_widget_style_get(obj)))
CRI("Failed to set layout!");
evas_object_size_hint_weight_set(sd->picker, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(sd->picker, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_widget_sub_object_add(obj, sd->picker);
bx = elm_box_add(sd->picker);
evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@ -742,7 +759,6 @@ _color_picker_add(Evas_Object *obj, Elm_Colorselector_Data *sd)
elm_layout_content_set(sd->picker, "elm.swallow.alpha", sd->spinners[3]);
elm_layout_text_set(sd->picker, "elm.label.alpha", E_("A:"));
evas_event_callback_add(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_IN, _mouse_in_canvas, obj);
evas_event_callback_add(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_OUT, _mouse_out_canvas, obj);
@ -1078,12 +1094,10 @@ _elm_colorselector_elm_widget_theme_apply(Eo *obj, Elm_Colorselector_Data *sd)
eo_do_super(obj, MY_CLASS, int_ret = elm_obj_widget_theme_apply());
if (!int_ret) return EINA_FALSE;
if (!sd->col_bars_area) return EINA_FALSE;
elm_widget_theme_object_set
(obj, sd->col_bars_area, "colorselector", "bg",
elm_widget_style_get(obj));
if ((sd->mode == ELM_COLORSELECTOR_PALETTE) ||
(sd->mode == ELM_COLORSELECTOR_ALL) ||
(sd->mode == ELM_COLORSELECTOR_BOTH))
{
hpadstr = edje_object_data_get
(wd->resize_obj, "horizontal_pad");
if (hpadstr) h_pad = atoi(hpadstr);
@ -1107,6 +1121,18 @@ _elm_colorselector_elm_widget_theme_apply(Eo *obj, Elm_Colorselector_Data *sd)
(obj, item->color_obj, "colorselector", "item/color",
elm_widget_style_get(obj));
}
}
if ((sd->mode == ELM_COLORSELECTOR_COMPONENTS) ||
(sd->mode == ELM_COLORSELECTOR_ALL) ||
(sd->mode == ELM_COLORSELECTOR_BOTH))
{
if (!sd->col_bars_area) return EINA_FALSE;
elm_widget_theme_object_set
(obj, sd->col_bars_area, "colorselector", "bg",
elm_widget_style_get(obj));
for (i = 0; i < 4; i++)
{
if (sd->cb_data[i])
@ -1121,7 +1147,13 @@ _elm_colorselector_elm_widget_theme_apply(Eo *obj, Elm_Colorselector_Data *sd)
ELM_SAFE_FREE(sd->cb_data[i]->touch_area, evas_object_del);
}
}
_color_bars_add(obj);
elm_colorselector_color_set(obj, sd->r, sd->g, sd->b, sd->a);
}
if ((sd->mode == ELM_COLORSELECTOR_PICKER) ||
(sd->mode == ELM_COLORSELECTOR_ALL))
{
if (!elm_layout_theme_set(sd->picker, "colorselector", "picker/base",
elm_widget_style_get(obj)))
CRI("Failed to set layout!");
@ -1132,14 +1164,10 @@ _elm_colorselector_elm_widget_theme_apply(Eo *obj, Elm_Colorselector_Data *sd)
#endif
for (i = 0; i < 4; i++)
elm_object_style_set(sd->spinners[i], style);
_color_bars_add(obj);
elm_colorselector_color_set(obj, sd->r, sd->g, sd->b, sd->a);
eina_stringshare_del(style);
}
elm_layout_sizing_eval(obj);
eina_stringshare_del(style);
return EINA_TRUE;
}
@ -1529,13 +1557,64 @@ _palette_colors_load(Evas_Object *obj)
sd->config_load = EINA_TRUE;
}
EOLIAN static void
_elm_colorselector_evas_object_smart_add(Eo *obj, Elm_Colorselector_Data *priv)
static void
_create_colorpalette(Evas_Object *obj)
{
const char *hpadstr, *vpadstr;
unsigned int h_pad = DEFAULT_HOR_PAD;
unsigned int v_pad = DEFAULT_VER_PAD;
ELM_COLORSELECTOR_DATA_GET(obj, sd);
ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
if (sd->palette_box) return;
sd->palette_box = elm_box_add(obj);
elm_box_layout_set
(sd->palette_box, evas_object_box_layout_flow_horizontal, NULL, NULL);
elm_box_horizontal_set(sd->palette_box, EINA_TRUE);
evas_object_size_hint_weight_set
(sd->palette_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set
(sd->palette_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_homogeneous_set(sd->palette_box, EINA_TRUE);
hpadstr = edje_object_data_get(wd->resize_obj, "horizontal_pad");
if (hpadstr) h_pad = atoi(hpadstr);
vpadstr = edje_object_data_get(wd->resize_obj, "vertical_pad");
if (vpadstr) v_pad = atoi(vpadstr);
elm_box_padding_set
(sd->palette_box,
(h_pad * elm_widget_scale_get(obj) * elm_config_scale_get()),
(v_pad * elm_widget_scale_get(obj) * elm_config_scale_get()));
elm_box_align_set(sd->palette_box, 0.0, 0.0);
if (!elm_layout_content_set(obj, "elm.palette", sd->palette_box))
elm_layout_content_set(obj, "palette", sd->palette_box);
sd->palette_name = eina_stringshare_add("default");
_palette_colors_load(obj);
evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _on_resize, NULL);
}
static void
_create_colorcomponents(Evas_Object *obj)
{
ELM_COLORSELECTOR_DATA_GET(obj, sd);
if (sd->col_bars_area) return;
sd->col_bars_area = edje_object_add(evas_object_evas_get(obj));
elm_widget_theme_object_set
(obj, sd->col_bars_area, "colorselector", "bg",
elm_widget_style_get(obj));
if (!elm_layout_content_set(obj, "elm.selector", sd->col_bars_area))
elm_layout_content_set(obj, "selector", sd->col_bars_area);
_hsl_to_rgb(sd);
_color_bars_add(obj);
}
EOLIAN static void
_elm_colorselector_evas_object_smart_add(Eo *obj, Elm_Colorselector_Data *priv)
{
ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd);
eo_do_super(obj, MY_CLASS, evas_obj_smart_add());
@ -1545,53 +1624,12 @@ _elm_colorselector_evas_object_smart_add(Eo *obj, Elm_Colorselector_Data *priv)
(obj, "colorselector", "palette", elm_object_style_get(obj)))
CRI("Failed to set layout!");
priv->palette_box = elm_box_add(obj);
elm_box_layout_set
(priv->palette_box, evas_object_box_layout_flow_horizontal, NULL, NULL);
elm_box_horizontal_set(priv->palette_box, EINA_TRUE);
evas_object_size_hint_weight_set
(priv->palette_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set
(priv->palette_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_homogeneous_set(priv->palette_box, EINA_TRUE);
_create_colorpalette(obj);
hpadstr = edje_object_data_get(wd->resize_obj, "horizontal_pad");
if (hpadstr) h_pad = atoi(hpadstr);
vpadstr = edje_object_data_get(wd->resize_obj, "vertical_pad");
if (vpadstr) v_pad = atoi(vpadstr);
elm_box_padding_set
(priv->palette_box,
(h_pad * elm_widget_scale_get(obj) * elm_config_scale_get()),
(v_pad * elm_widget_scale_get(obj) * elm_config_scale_get()));
elm_box_align_set(priv->palette_box, 0.0, 0.0);
if (!elm_layout_content_set(obj, "elm.palette", priv->palette_box))
elm_layout_content_set(obj, "palette", priv->palette_box);
priv->palette_name = eina_stringshare_add("default");
_palette_colors_load(obj);
evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _on_resize, NULL);
/* load background edj */
priv->col_bars_area = edje_object_add(evas_object_evas_get(obj));
elm_widget_theme_object_set
(obj, priv->col_bars_area, "colorselector", "bg",
elm_widget_style_get(obj));
if (!elm_layout_content_set(obj, "elm.selector", priv->col_bars_area))
elm_layout_content_set(obj, "selector", priv->col_bars_area);
_create_colorcomponents(obj);
elm_layout_signal_emit(obj, "elm,state,both", "elm");
/* setup the color picker */
priv->picker = elm_layout_add(obj);
if (!elm_layout_theme_set(priv->picker, "colorselector", "picker/base", elm_widget_style_get(obj)))
CRI("Failed to set layout!");
evas_object_size_hint_weight_set(priv->picker, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(priv->picker, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_widget_sub_object_add(obj, priv->picker);
priv->mode = ELM_COLORSELECTOR_BOTH;
priv->focused = ELM_COLORSELECTOR_PALETTE;
priv->sel_color_type = HUE;
@ -1610,10 +1648,6 @@ _elm_colorselector_evas_object_smart_add(Eo *obj, Elm_Colorselector_Data *priv)
#endif
priv->grab.in = EINA_TRUE;
_hsl_to_rgb(priv);
_color_bars_add(obj);
_color_picker_add(obj, priv);
elm_layout_sizing_eval(obj);
elm_widget_can_focus_set(obj, EINA_TRUE);
}
@ -1624,7 +1658,6 @@ _elm_colorselector_evas_object_smart_del(Eo *obj, Elm_Colorselector_Data *sd)
int i = 0;
void *tmp[4];
evas_event_callback_del_full(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_IN, _mouse_in_canvas, obj);
evas_event_callback_del_full(evas_object_evas_get(obj), EVAS_CALLBACK_CANVAS_FOCUS_OUT, _mouse_out_canvas, obj);
@ -1846,20 +1879,28 @@ _elm_colorselector_elm_widget_focus_next(Eo *obj, Elm_Colorselector_Data *sd, El
if (!sd) return EINA_FALSE;
if ((sd->mode == ELM_COLORSELECTOR_PALETTE) ||
(sd->mode == ELM_COLORSELECTOR_ALL)||
(sd->mode == ELM_COLORSELECTOR_BOTH))
{
if (!sd->items) return EINA_FALSE;
EINA_LIST_FOREACH(sd->items, l, eo_item)
{
Elm_Widget_Item_Data *witem = eo_data_scope_get(eo_item, ELM_WIDGET_ITEM_CLASS);
items = eina_list_append(items, witem->access_obj);
}
}
if ((sd->mode == ELM_COLORSELECTOR_COMPONENTS) ||
(sd->mode == ELM_COLORSELECTOR_ALL) ||
(sd->mode == ELM_COLORSELECTOR_BOTH))
{
for (i = 0; i < 4; i++)
{
items = eina_list_append(items, sd->cb_data[i]->lbt);
items = eina_list_append(items, sd->cb_data[i]->access_obj);
items = eina_list_append(items, sd->cb_data[i]->rbt);
}
}
return elm_widget_focus_list_next_get
(obj, items, eina_list_data_get, dir, next);
@ -1874,21 +1915,34 @@ _access_obj_process(Evas_Object *obj, Eina_Bool is_access)
ELM_COLORSELECTOR_DATA_GET(obj, sd);
if ((sd->mode == ELM_COLORSELECTOR_PALETTE) ||
(sd->mode == ELM_COLORSELECTOR_ALL) ||
(sd->mode == ELM_COLORSELECTOR_BOTH))
{
if (is_access)
{
EINA_LIST_FOREACH(sd->items, l, eo_it)
eo_do(eo_it, elm_wdg_item_access_register());
for (i = 0; i < 4; i++)
_access_colorbar_register(obj, sd->cb_data[i],
"elm.arrow_bg_access");
}
else
{
EINA_LIST_FOREACH(sd->items, l, eo_it)
eo_do(eo_it, elm_wdg_item_access_unregister());
//TODO: _elm_access_edje_object_part_object_unregister() ?
}
}
if ((sd->mode == ELM_COLORSELECTOR_COMPONENTS) ||
(sd->mode == ELM_COLORSELECTOR_ALL) ||
(sd->mode == ELM_COLORSELECTOR_BOTH))
{
for (i = 0; i < 4; i++)
{
if (is_access)
_access_colorbar_register(obj, sd->cb_data[i],
"elm.arrow_bg_access");
else
_elm_access_edje_object_part_object_unregister(obj, sd->cb_data[i]->colorbar,
"elm.arrow_bg_access");
}
}
}
@ -1982,6 +2036,7 @@ _elm_colorselector_mode_set(Eo *obj, Elm_Colorselector_Data *sd, Elm_Colorselect
break;
case ELM_COLORSELECTOR_PICKER:
_create_colorpicker(obj);
if (!elm_layout_content_set(obj, "elm.picker", sd->picker))
elm_layout_content_set(obj, "picker", sd->picker);
elm_layout_signal_emit(obj, "elm,state,picker", "elm");
@ -1989,6 +2044,7 @@ _elm_colorselector_mode_set(Eo *obj, Elm_Colorselector_Data *sd, Elm_Colorselect
break;
case ELM_COLORSELECTOR_ALL:
_create_colorpicker(obj);
if (!elm_layout_content_set(obj, "elm.palette", sd->palette_box))
elm_layout_content_set(obj, "palette", sd->palette_box);
if (!elm_layout_content_set(obj, "elm.selector", sd->col_bars_area))