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
|
/*
* 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, NULL);
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);
}
}
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;
Ewk_Context_Menu *menu = static_cast<Ewk_Context_Menu*>(event_info);
Ewk_Context_Menu_Item *item;
Ewk_Context_Menu_Item_Tag tag;
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_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_DOWNLOAD_LINK_TO_DISK:
ewk_context_menu_item_append_as_action(menu, tag, BR_STRING_CTXMENU_DOWNLOAD_LINKED_FILE, 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_AS, 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);
ewk_context_menu_item_append_as_action(menu, CustomContextMenuItemSelectedTextShareTag, 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;
}
}
}
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 CustomContextMenuItemSelectedTextShareTag:
BROWSER_LOGD("Share selected text[%s]", selected_text);
if (selected_text && strlen(selected_text) > 0)
context_menu->_show_share_popup(selected_text);
break;
default:
break;
}
}
|