summaryrefslogtreecommitdiff
path: root/src/browser-view/browser-context-menu.cpp
blob: 77640240901661cfca0f35807dbe6e031986d475 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
/*
 * Copyright 2012  Samsung Electronics Co., Ltd
 *
 * Licensed under the Flora License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.tizenopensource.org/license
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */


#include "browser-context-menu.h"
#include "browser-view.h"

Browser_Context_Menu::Browser_Context_Menu(Browser_View *browser_view)
:	m_browser_view(browser_view)
	,m_ewk_view(NULL)
{
	BROWSER_LOGD("[%s]", __func__);
}

Browser_Context_Menu::~Browser_Context_Menu(void)
{
	BROWSER_LOGD("[%s]", __func__);
}

void Browser_Context_Menu::init(Evas_Object *ewk_view)
{
	BROWSER_LOGD("[%s]", __func__);

	deinit();

	m_ewk_view = ewk_view;

	evas_object_smart_callback_add(ewk_view, "contextmenu,customize", __get_context_menu_from_proposed_context_menu_cb, this);
	evas_object_smart_callback_add(ewk_view, "contextmenu,selected", __custom_context_menu_item_selected_cb, this);
}

void Browser_Context_Menu::deinit(void)
{
	BROWSER_LOGD("[%s]", __func__);
	if (m_ewk_view) {
		evas_object_smart_callback_del(m_ewk_view, "contextmenu,customize",
						__get_context_menu_from_proposed_context_menu_cb);
		evas_object_smart_callback_del(m_ewk_view, "contextmenu,selected",
						__custom_context_menu_item_selected_cb);
	}
}

Eina_Bool Browser_Context_Menu::launch_context_menu(Ewk_Context_Menu *menu)
{
	BROWSER_LOGD("[%s]", __func__);

	if (!menu)
		return EINA_FALSE;

	switch (_check_context_menu_mode(menu)) {
	case CUSTOM_CONTEXT_MENU_TEXT_ONLY_MODE:
		_append_text_only_mode_context_menu(menu);
		break;

	case CUSTOM_CONTEXT_MENU_HYPERLINK_ONLY_MODE:
		_append_hyperlink_only_mode_context_menu(menu);
		break;

	case CUSTOM_CONTEXT_MENU_TEXT_WITH_HYPERLINK_MODE:
		_append_text_with_hyperlink_mode_context_menu(menu);
		break;

	case CUSTOM_CONTEXT_MENU_IMAGE_ONLY_MODE:
		_append_image_only_mode_context_menu(menu);
		break;

	case CUSTOM_CONTEXT_MENU_IMAGE_WITH_HYPERLINK_MODE:
		_append_image_with_hyperlink_mode_context_menu(menu);
		break;

	case CUSTOM_CONTEXT_MENU_TEXT_AND_IMAGE_SELECTION_MODE:
		/* To do */
		break;

	default:
		_append_normal_mode_context_menu(menu);
		break;
	}
}

void Browser_Context_Menu::__get_context_menu_from_proposed_context_menu_cb(void *data, Evas_Object *obj, void *event_info)
{
	BROWSER_LOGD("[%s]", __func__);
	if (!event_info)
		return;

	if (!data)
		return;

	Ewk_Context_Menu *menu = static_cast<Ewk_Context_Menu*>(event_info);
	Browser_Context_Menu *context_menu = static_cast<Browser_Context_Menu *>(data);
	context_menu->launch_context_menu(menu);
}

void Browser_Context_Menu::__custom_context_menu_item_selected_cb(void *data, Evas_Object *obj, void *event_info)
{
	BROWSER_LOGD("[%s]", __func__);
	if (!event_info)
		return;

	Ewk_Context_Menu_Item* item = static_cast<Ewk_Context_Menu_Item*>(event_info);
	Browser_Context_Menu *context_menu = static_cast<Browser_Context_Menu *>(data);

	std::string link_url_string = ewk_context_menu_item_link_url_get(item);
	BROWSER_LOGD("link url=[%s]", link_url_string.c_str());
	std::string image_url_string = ewk_context_menu_item_image_url_get(item);
	BROWSER_LOGD("image url=[%s]", image_url_string.c_str());

	const char *selected_text = ewk_view_text_selection_text_get(context_menu->m_ewk_view);

	Ewk_Context_Menu_Item_Tag tag = ewk_context_menu_item_tag_get(item);
	switch (tag) {
	case CUSTOM_CONTEXT_MENU_ITEM_TEXT_SHARE_TAG:
		BROWSER_LOGD("Share selected text[%s]", selected_text);
		if (selected_text && strlen(selected_text) > 0)
			context_menu->_show_share_popup(selected_text);
		break;
	case CUSTOM_CONTEXT_MENU_ITEM_FIND_ON_TAG:
		BROWSER_LOGD("Find selected text[%s] on the page", selected_text);
		if (selected_text && strlen(selected_text) > 0)
			context_menu->find_word_with_text(selected_text);
		break;
	case CUSTOM_CONTEXT_MENU_ITEM_LINK_SHARE_TAG:
		BROWSER_LOGD("Share popup for link show");
		context_menu->_show_share_popup(link_url_string.c_str());
		break;
	case CUSTOM_CONTEXT_MENU_ITEM_IMAGE_SHARE_TAG:
		BROWSER_LOGD("Share popup for image show");
		context_menu->_show_share_popup(image_url_string.c_str());
		break;
	case CUSTOM_CONTEXT_MENU_ITEM_SELECTION_MODE_FROM_TEXT_WITH_HYPERLINK_TAG:
	{
		/* FIXME - put text selection mode activating code when it is ready */
		Evas_Object *ewk_view = context_menu->m_ewk_view;
		Ewk_View_Smart_Data *smart_data = 0;
		int pressed_x = context_menu->get_pressed_position_x();
		int pressed_y = context_menu->get_pressed_position_y();

		if (!ewk_view) {
			BROWSER_LOGD("ewk_view is NULL");
			break;
		}
		smart_data = (Ewk_View_Smart_Data *)evas_object_smart_data_get(ewk_view);
		if (!smart_data) {
			BROWSER_LOGD("smart_Data is NULL");
			break;
		}
		if (smart_data->api->text_selection_down(smart_data, pressed_x, pressed_y) == EINA_FALSE)
			BROWSER_LOGD("text_selection_down failed");

		if (smart_data->api->text_selection_up(smart_data, pressed_x, pressed_y) == EINA_FALSE)
			BROWSER_LOGD("text_selection_up failed");

		break;
	}
	case CUSTOM_CONTEXT_MENU_ITEM_SELECTION_MODE_FROM_TEXT_TAG:
	case CUSTOM_CONTEXT_MENU_ITEM_SELECTION_MODE_FROM_IMAGE_TAG:
	case CUSTOM_CONTEXT_MENU_ITEM_SELECTION_MODE_FROM_IMAGE_WITH_HYPERLINK_TAG:
		/* FIXME - put text selection mode activating code when it is ready */
		BROWSER_LOGD("Selection mode");
		break;
	default:
		break;
	}
}

Eina_Bool Browser_Context_Menu::_check_context_menu_mode(Ewk_Context_Menu *menu)
{
	BROWSER_LOGD("[%s]", __func__);

	if (!menu)
		return EINA_FALSE;

	int count = ewk_context_menu_item_count(menu);

	Eina_Bool has_text = EINA_FALSE;
	Eina_Bool has_image = EINA_FALSE;
	Eina_Bool has_hyperlink = EINA_FALSE;

	Ewk_Context_Menu_Item *item;
	Ewk_Context_Menu_Item_Tag tag;

	for (int i = 0; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, i);
		tag = ewk_context_menu_item_tag_get(item);
		BROWSER_LOGD("tag[%d]", tag);

		if ((tag == EWK_CONTEXT_MENU_ITEM_TAG_COPY)
		|| (tag == EWK_CONTEXT_MENU_ITEM_TAG_CUT)
		|| (tag == EWK_CONTEXT_MENU_ITEM_TAG_PASTE)
		|| (tag == EWK_CONTEXT_MENU_ITEM_TAG_SELECT_ALL)
		|| (tag == EWK_CONTEXT_MENU_ITEM_TAG_SEARCH_WEB)
		|| (tag == EWK_CONTEXT_MENU_ITEM_TAG_SELECT_WORD))
			has_text = EINA_TRUE;

		if ((tag == EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK)
		|| (tag == EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW)
		|| (tag == EWK_CONTEXT_MENU_ITEM_TAG_DOWNLOAD_LINK_TO_DISK)
		|| (tag == EWK_CONTEXT_MENU_ITEM_TAG_COPY_LINK_TO_CLIPBOARD))
			has_hyperlink = EINA_TRUE;

		if ((tag == EWK_CONTEXT_MENU_ITEM_TAG_COPY_IMAGE_TO_CLIPBOARD)
		|| (tag == EWK_CONTEXT_MENU_ITEM_TAG_DOWNLOAD_IMAGE_TO_DISK)
		|| (tag == EWK_CONTEXT_MENU_ITEM_TAG_OPEN_FRAME_IN_NEW_WINDOW)
		|| (tag == EWK_CONTEXT_MENU_ITEM_TAG_OPEN_IMAGE_IN_NEW_WINDOW))
			has_image = EINA_TRUE;
	}

	if (has_text == EINA_TRUE && has_hyperlink == EINA_FALSE && has_image == EINA_FALSE) {
		BROWSER_LOGD("CUSTOM_CONTEXT_MENU_TEXT_ONLY_MODE");
		return CUSTOM_CONTEXT_MENU_TEXT_ONLY_MODE;
	} else if (has_text == EINA_TRUE && has_hyperlink == EINA_FALSE && has_image == EINA_TRUE) {
		BROWSER_LOGD("CUSTOM_CONTEXT_MENU_TEXT_AND_IMAGE_SELECTION_MODE");
		return CUSTOM_CONTEXT_MENU_TEXT_AND_IMAGE_SELECTION_MODE;
	} else if (has_text == EINA_TRUE && has_hyperlink == EINA_TRUE && has_image == EINA_TRUE) {
		BROWSER_LOGD("CUSTOM_CONTEXT_MENU_TEXT_WITH_HYPERLINK_MODE");
		return CUSTOM_CONTEXT_MENU_TEXT_WITH_HYPERLINK_MODE;
	} else if (has_text == EINA_FALSE && has_hyperlink == EINA_TRUE && has_image == EINA_FALSE) {
		BROWSER_LOGD("CUSTOM_CONTEXT_MENU_HYPERLINK_ONLY_MODE");
		return CUSTOM_CONTEXT_MENU_HYPERLINK_ONLY_MODE;
	} else if (has_text == EINA_FALSE && has_hyperlink == EINA_FALSE && has_image == EINA_TRUE){
		BROWSER_LOGD("CUSTOM_CONTEXT_MENU_IMAGE_ONLY_MODE");
		return CUSTOM_CONTEXT_MENU_IMAGE_ONLY_MODE;
	} else if (has_text == EINA_FALSE && has_hyperlink == EINA_TRUE && has_image == EINA_TRUE){
		BROWSER_LOGD("CUSTOM_CONTEXT_MENU_IMAGE_WITH_HYPERLINK_MODE");
		return CUSTOM_CONTEXT_MENU_IMAGE_WITH_HYPERLINK_MODE;
	} else{
		BROWSER_LOGD("CUSTOM_CONTEXT_MENU_MODE_INDEX_END");
		return CUSTOM_CONTEXT_MENU_MODE_INDEX_END;
	}
}

Eina_Bool Browser_Context_Menu::_append_text_only_mode_context_menu(Ewk_Context_Menu *menu)
{
	BROWSER_LOGD("[%s]", __func__);

	if (!menu)
		return EINA_FALSE;

	Ewk_Context_Menu_Item *item;
	Ewk_Context_Menu_Item_Tag tag;
	int index = 0;
	int count = ewk_context_menu_item_count(menu);
	int *custom_context_menu_array = NULL;

	if (count == 0)
		return EINA_FALSE;
	custom_context_menu_array = (int *)malloc(sizeof(int) * count);
	if (!custom_context_menu_array)
		return EINA_FALSE;

	memset(custom_context_menu_array, 0x00, sizeof(int) * count);

	/* To re-arrange menu order to follow UX guideline
		: copy menu would be best if it's at the first in context menu */
	for (int i = 0; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, i);
		tag = ewk_context_menu_item_tag_get(item);

		if (tag == EWK_CONTEXT_MENU_ITEM_TAG_COPY) {
			custom_context_menu_array[index++] = EWK_CONTEXT_MENU_ITEM_TAG_COPY;
			ewk_context_menu_item_remove(menu, item);
		}
	}
#if 0
	for (int i = 0; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, i);
		tag = ewk_context_menu_item_tag_get(item);

		if (tag == EWK_CONTEXT_MENU_ITEM_TAG_CUT) {
			custom_context_menu_array[index++] = EWK_CONTEXT_MENU_ITEM_TAG_CUT;
			ewk_context_menu_item_remove(menu, item);
		}
	}
#endif

	for (int i = index; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, 0);
		tag = ewk_context_menu_item_tag_get(item);

		custom_context_menu_array[index++] = tag;
		ewk_context_menu_item_remove(menu, item);
	}

	for (int i = 0; i < count; i++) {
		tag = custom_context_menu_array[i];

		switch (tag) {
		case EWK_CONTEXT_MENU_ITEM_TAG_CUT:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_CUT, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_PASTE:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_PASTE, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_COPY:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_COPY, true);
			ewk_context_menu_item_append_as_action(menu, CUSTOM_CONTEXT_MENU_ITEM_FIND_ON_TAG, BR_STRING_CTXMENI_FIND_ON_PAGE, true);
			ewk_context_menu_item_append_as_action(menu, CUSTOM_CONTEXT_MENU_ITEM_TEXT_SHARE_TAG, BR_STRING_CTXMENU_SHARE, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_SELECT_ALL:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_SELECT_ALL, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_SELECT_WORD:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_SELECT_WORD, true);
			break;
		default:
			break;
		}
	}

	if (custom_context_menu_array)
		free(custom_context_menu_array);
	custom_context_menu_array = NULL;

	return EINA_TRUE;
}

Eina_Bool Browser_Context_Menu::_append_text_with_hyperlink_mode_context_menu(Ewk_Context_Menu *menu)
{
	BROWSER_LOGD("[%s]", __func__);

	if (!menu)
		return EINA_FALSE;

	return _append_hyperlink_only_mode_context_menu(menu);
}

Eina_Bool Browser_Context_Menu::_append_hyperlink_only_mode_context_menu(Ewk_Context_Menu *menu)
{
	BROWSER_LOGD("[%s]", __func__);

	if (!menu)
		return EINA_FALSE;

	Ewk_Context_Menu_Item *item;
	Ewk_Context_Menu_Item_Tag tag;
	int index = 0;
	int count = ewk_context_menu_item_count(menu);
	int *custom_context_menu_array = (int *)malloc(sizeof(int) * count);

	if (count == 0)
		return EINA_FALSE;

	if (!custom_context_menu_array)
		return EINA_FALSE;

	memset(custom_context_menu_array, 0x00, sizeof(int) * count);

	/* To re-arrange menu order to follow UX guideline
		: "Open in new window" menu would be best if it's at the first in context menu */
	for (int i = 0; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, i);
		tag = ewk_context_menu_item_tag_get(item);

		if (tag == EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK) {
			custom_context_menu_array[index++] = EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK;
			ewk_context_menu_item_remove(menu, item);
		}
	}

	for (int i = 0; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, i);
		tag = ewk_context_menu_item_tag_get(item);

		if (tag == EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW) {
			custom_context_menu_array[index++] = EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW;
			ewk_context_menu_item_remove(menu, item);
		}
	}

	for (int i = 0; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, i);
		tag = ewk_context_menu_item_tag_get(item);

		if (tag == EWK_CONTEXT_MENU_ITEM_TAG_COPY_LINK_TO_CLIPBOARD) {
			custom_context_menu_array[index++] = EWK_CONTEXT_MENU_ITEM_TAG_COPY_LINK_TO_CLIPBOARD;
			ewk_context_menu_item_remove(menu, item);
		}
	}

	for (int i = index; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, 0);
		tag = ewk_context_menu_item_tag_get(item);

		custom_context_menu_array[index++] = tag;
		ewk_context_menu_item_remove(menu, item);
	}

	for (int i = 0; i < count; i++) {
		tag = custom_context_menu_array[i];

		switch (tag) {

		case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_OPEN, true);
			break;

		case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_OPEN_LINK_IN_NEW_WINDOW, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_COPY_LINK_TO_CLIPBOARD:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_COPY_LINK_LOCATION, true);
			ewk_context_menu_item_append_as_action(menu, CUSTOM_CONTEXT_MENU_ITEM_LINK_SHARE_TAG, BR_STRING_CTXMENU_SHARE, true);
			ewk_context_menu_item_append_as_action(menu, CUSTOM_CONTEXT_MENU_ITEM_SELECTION_MODE_FROM_TEXT_WITH_HYPERLINK_TAG, BR_STRING_CTXMENU_SELECTION_MODE, true);
			break;
#if 0
		case EWK_CONTEXT_MENU_ITEM_TAG_DOWNLOAD_LINK_TO_DISK:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_SAVE_LINK, true);
			break;
#endif
		default:
			break;
		}
	}

	if (custom_context_menu_array)
		free(custom_context_menu_array);
	custom_context_menu_array = NULL;

	return EINA_TRUE;
}

Eina_Bool Browser_Context_Menu::_append_image_only_mode_context_menu(Ewk_Context_Menu *menu)
{
	BROWSER_LOGD("[%s]", __func__);

	if (!menu)
		return EINA_FALSE;

	Ewk_Context_Menu_Item *item;
	Ewk_Context_Menu_Item_Tag tag;
	int index = 0;
	int count = ewk_context_menu_item_count(menu);
	int *custom_context_menu_array = (int *)malloc(sizeof(int) * count);

	if (count == 0)
		return EINA_FALSE;

	if (!custom_context_menu_array)
		return EINA_FALSE;

	memset(custom_context_menu_array, 0x00, sizeof(int) * count);

	/* To re-arrange menu order to follow UX guideline
		: "Copy image" menu would be best if it's at the first in context menu */
	for (int i = 0; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, i);
		tag = ewk_context_menu_item_tag_get(item);

		if (tag == EWK_CONTEXT_MENU_ITEM_TAG_COPY_IMAGE_TO_CLIPBOARD) {
			custom_context_menu_array[index++] = EWK_CONTEXT_MENU_ITEM_TAG_COPY_IMAGE_TO_CLIPBOARD;
			ewk_context_menu_item_remove(menu, item);
		}
	}

	for (int i = index; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, 0);
		tag = ewk_context_menu_item_tag_get(item);

		custom_context_menu_array[index++] = tag;
		ewk_context_menu_item_remove(menu, item);
	}

	for (int i = 0; i < count; i++) {
		tag = custom_context_menu_array[i];

		switch (tag) {
		case EWK_CONTEXT_MENU_ITEM_TAG_COPY_IMAGE_TO_CLIPBOARD:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_COPY_IMAGE, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_IMAGE_IN_NEW_WINDOW:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_OPEN_IMAGE_IN_NEW_WINDOW, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_DOWNLOAD_IMAGE_TO_DISK:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_SAVE_IMAGE, true);
			ewk_context_menu_item_append_as_action(menu, CUSTOM_CONTEXT_MENU_ITEM_IMAGE_SHARE_TAG, BR_STRING_CTXMENU_SHARE_IMAGE, true);
			ewk_context_menu_item_append_as_action(menu, CUSTOM_CONTEXT_MENU_ITEM_SELECTION_MODE_FROM_IMAGE_TAG, BR_STRING_CTXMENU_SELECTION_MODE, true);
			break;
		default:
			break;
		}
	}

	if (custom_context_menu_array)
		free(custom_context_menu_array);
	custom_context_menu_array = NULL;

	return EINA_TRUE;
}

Eina_Bool Browser_Context_Menu::_append_image_with_hyperlink_mode_context_menu(Ewk_Context_Menu *menu)
{
	BROWSER_LOGD("[%s]", __func__);

	if (!menu)
		return EINA_FALSE;

	Ewk_Context_Menu_Item *item;
	Ewk_Context_Menu_Item_Tag tag;
	int index = 0;
	int count = ewk_context_menu_item_count(menu);
	int *custom_context_menu_array = (int *)malloc(sizeof(int) * count);

	if (count == 0)
		return EINA_FALSE;

	if (!custom_context_menu_array)
		return EINA_FALSE;

	memset(custom_context_menu_array, 0x00, sizeof(int) * count);

	/* To re-arrange menu order to follow UX guideline
		: "Open in new window" menu would be best if it's at the first in context menu */
	for (int i = 0; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, i);
		tag = ewk_context_menu_item_tag_get(item);

		if (tag == EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW) {
			custom_context_menu_array[index++] = EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW;
			ewk_context_menu_item_remove(menu, item);
		}
	}

	for (int i = 0; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, i);
		tag = ewk_context_menu_item_tag_get(item);

		if (tag == EWK_CONTEXT_MENU_ITEM_TAG_COPY_LINK_TO_CLIPBOARD) {
			custom_context_menu_array[index++] = EWK_CONTEXT_MENU_ITEM_TAG_COPY_LINK_TO_CLIPBOARD;
			ewk_context_menu_item_remove(menu, item);
		}
	}

	for (int i = 0; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, i);
		tag = ewk_context_menu_item_tag_get(item);

		if (tag == EWK_CONTEXT_MENU_ITEM_TAG_COPY_IMAGE_TO_CLIPBOARD) {
			custom_context_menu_array[index++] = EWK_CONTEXT_MENU_ITEM_TAG_COPY_IMAGE_TO_CLIPBOARD;
			ewk_context_menu_item_remove(menu, item);
		}
	}

	for (int i = index; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, 0);
		tag = ewk_context_menu_item_tag_get(item);

		custom_context_menu_array[index++] = tag;
		ewk_context_menu_item_remove(menu, item);
	}

	for (int i = 0; i < count; i++) {
		tag = custom_context_menu_array[i];

		switch (tag) {
		case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_OPEN_LINK_IN_NEW_WINDOW, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_COPY_LINK_TO_CLIPBOARD:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_COPY_LINK_LOCATION, true);
			ewk_context_menu_item_append_as_action(menu, CUSTOM_CONTEXT_MENU_ITEM_TEXT_SHARE_TAG, BR_STRING_CTXMENU_SHARE, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_COPY_IMAGE_TO_CLIPBOARD:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_COPY_IMAGE, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_IMAGE_IN_NEW_WINDOW:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_OPEN_IMAGE_IN_NEW_WINDOW, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_DOWNLOAD_IMAGE_TO_DISK:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_SAVE_IMAGE, true);
			ewk_context_menu_item_append_as_action(menu, CUSTOM_CONTEXT_MENU_ITEM_LINK_SHARE_TAG, BR_STRING_CTXMENU_SHARE_IMAGE, true);
			ewk_context_menu_item_append_as_action(menu, CUSTOM_CONTEXT_MENU_ITEM_SELECTION_MODE_FROM_IMAGE_TAG, BR_STRING_CTXMENU_SELECTION_MODE, true);
			break;
		default:
			break;
		}
	}

	if (custom_context_menu_array)
		free(custom_context_menu_array);
	custom_context_menu_array = NULL;

	return EINA_TRUE;
}

Eina_Bool Browser_Context_Menu::_append_text_and_image_selection_mode_context_menu(Ewk_Context_Menu *menu)
{
	BROWSER_LOGD("[%s]", __func__);

	if (!menu)
		return EINA_FALSE;

	return EINA_FALSE;
}

Eina_Bool Browser_Context_Menu::_append_normal_mode_context_menu(Ewk_Context_Menu *menu)
{
	BROWSER_LOGD("[%s]", __func__);

	if (!menu)
		return EINA_FALSE;

	Ewk_Context_Menu_Item *item;
	Ewk_Context_Menu_Item_Tag tag;
	bool show_hyperlink_item_flag = false;
	bool show_imagemode_flag = false;
	int count = ewk_context_menu_item_count(menu);

	for (int i = 0; i < count; i++) {
		item = ewk_context_menu_nth_item_get(menu, 0);
		tag = ewk_context_menu_item_tag_get(item);
		ewk_context_menu_item_remove(menu, item);

		switch (tag) {
		case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_OPEN, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_OPEN_LINK_IN_NEW_WINDOW, true);
			ewk_context_menu_item_append_as_action(menu, CUSTOM_CONTEXT_MENU_ITEM_LINK_SHARE_TAG, BR_STRING_CTXMENU_SHARE_LINK, true);
			show_hyperlink_item_flag = true;
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_DOWNLOAD_LINK_TO_DISK:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_SAVE_LINK, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_OPEN_IMAGE_IN_NEW_WINDOW:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_OPEN_IMAGE_IN_NEW_WINDOW, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_DOWNLOAD_IMAGE_TO_DISK:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_SAVE_IMAGE, true);
			ewk_context_menu_item_append_as_action(menu, CUSTOM_CONTEXT_MENU_ITEM_IMAGE_SHARE_TAG, BR_STRING_CTXMENU_SHARE_IMAGE_URL, true);
			show_imagemode_flag = true;
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_COPY_IMAGE_TO_CLIPBOARD:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_COPY_IMAGE, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_COPY_LINK_TO_CLIPBOARD:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_COPY_IMAGE_LOCATION, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_CUT:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_CUT, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_PASTE:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_PASTE, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_COPY:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_COPY, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_SELECT_ALL:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_SELECT_ALL, true);
			break;
		case EWK_CONTEXT_MENU_ITEM_TAG_SELECT_WORD:
			ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_SELECT_WORD, true);
			break;
		default:
			break;
	}
}

	/* if the tag is hyperlink text, show text selection mode menu */
	if ((show_hyperlink_item_flag == true) && (show_imagemode_flag == false))
		ewk_context_menu_item_append_as_action(menu, CUSTOM_CONTEXT_MENU_ITEM_SELECTION_MODE_FROM_TEXT_TAG, BR_STRING_CTXMENU_SELECTION_MODE, true);

	return EINA_TRUE;
}