[M47_2526] Chromium upversion to m47_2526 branch
[platform/framework/web/chromium-efl.git] / tizen_src / chromium_impl / content / shell / browser / shell_web_contents_view_delegate_efl.cc
1 // Copyright 2014 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/shell/browser/shell_web_contents_view_delegate.h"
6
7 #include <Evas.h>
8 #include <Elementary.h>
9
10 #include "base/command_line.h"
11 #include "content/public/browser/render_view_host.h"
12 #include "content/shell/browser/shell.h"
13 #include "content/shell/browser/shell_browser_context.h"
14 #include "content/shell/browser/shell_content_browser_client.h"
15 #include "content/shell/browser/shell_devtools_frontend.h"
16 #include "content/shell/common/shell_switches.h"
17 #include "third_party/WebKit/public/web/WebContextMenuData.h"
18
19 using blink::WebContextMenuData;
20
21 namespace content {
22
23 namespace {
24
25 static Evas_Object* g_context_menu = NULL;
26
27 void OpenInNewWindow(void* data, Evas_Object*, void*) {
28   const ContextMenuParams* params =
29       static_cast<const ContextMenuParams*>(data);
30   ShellBrowserContext* browser_context =
31       ShellContentBrowserClient::Get()->browser_context();
32   Shell::CreateNewWindow(browser_context,
33                          params->link_url,
34                          NULL,
35                          gfx::Size());
36 }
37
38 void StartDragging(void* data, Evas_Object*, void*) {
39   WebContents* wc = static_cast<WebContents*>(data);
40   RenderViewHost* rvh = wc->GetRenderViewHost();
41 #if !defined(EWK_BRINGUP)
42   rvh->StartDragging();
43 #endif
44 }
45
46 void Cut(void* data, Evas_Object*, void*) {
47   WebContents* wc = static_cast<WebContents*>(data);
48   wc->Cut();
49 }
50
51 void Copy(void* data, Evas_Object*, void*) {
52   WebContents* wc = static_cast<WebContents*>(data);
53   wc->Copy();
54 }
55
56 void Paste(void* data, Evas_Object*, void*) {
57   WebContents* wc = static_cast<WebContents*>(data);
58   wc->Paste();
59 }
60
61 void Delete(void* data, Evas_Object*, void*) {
62   WebContents* wc = static_cast<WebContents*>(data);
63   wc->Delete();
64 }
65
66 void Forward(void* data, Evas_Object*, void*) {
67   WebContents* wc = static_cast<WebContents*>(data);
68   wc->GetController().GoToOffset(1);
69   wc->Focus();
70 }
71
72 void Back(void* data, Evas_Object*, void*) {
73   WebContents* wc = static_cast<WebContents*>(data);
74   wc->GetController().GoToOffset(-1);
75   wc->Focus();
76 }
77
78 void Reload(void* data, Evas_Object*, void*) {
79   WebContents* wc = static_cast<WebContents*>(data);
80   wc->GetController().Reload(false);
81   wc->Focus();
82 }
83
84 }
85
86 WebContentsViewDelegate* CreateShellWebContentsViewDelegate(
87     WebContents* web_contents) {
88   return new ShellWebContentsViewDelegate(web_contents);
89 }
90
91 ShellWebContentsViewDelegate::ShellWebContentsViewDelegate(
92     WebContents* web_contents)
93     : web_contents_(web_contents) {
94 }
95
96 ShellWebContentsViewDelegate::~ShellWebContentsViewDelegate() {
97 }
98
99 void ShellWebContentsViewDelegate::ShowContextMenu(
100     RenderFrameHost* render_frame_host,
101     const ContextMenuParams& params) {
102 #if !defined(EWK_BRINGUP)
103 // [M47_2526] Temporary disabling the codes for switching to new chromium
104 //            FIXME:
105   if (base::CommandLine::ForCurrentProcess()->
106           HasSwitch(switches::kDumpRenderTree))
107     return;
108 #endif
109
110   if (g_context_menu) {
111     elm_menu_close(g_context_menu);
112     evas_object_del(g_context_menu);
113   }
114
115   params_ = params;
116
117   bool has_link = !params.unfiltered_link_url.is_empty();
118   Evas_Object* parent =
119       static_cast<Evas_Object*>(web_contents_->GetContentNativeView());
120
121   Evas_Object* menu = elm_menu_add(parent);
122   Elm_Object_Item* menu_it = NULL;
123
124   if (has_link) {
125     elm_menu_item_add(menu, NULL, NULL, "Open in new window",
126         OpenInNewWindow, &params_);
127     elm_menu_item_separator_add(menu, NULL);
128   }
129
130 #if !defined(EWK_BRINGUP)
131   if (params.is_draggable) {
132     elm_menu_item_add(menu, NULL, NULL, "Start dragging",
133         StartDragging, web_contents_);
134   }
135 #endif
136
137   if (params_.is_editable) {
138     menu_it = elm_menu_item_add(menu, NULL, NULL, "Cut",
139        Cut, web_contents_);
140     elm_object_item_disabled_set(menu_it,
141         (params_.edit_flags & WebContextMenuData::CanCut) == 0);
142     menu_it = elm_menu_item_add(menu, NULL, NULL, "Copy",
143           Copy, web_contents_);
144     elm_object_item_disabled_set(menu_it,
145         (params_.edit_flags & WebContextMenuData::CanCopy) == 0);
146     menu_it = elm_menu_item_add(menu, NULL, NULL, "Paste",
147           Paste, web_contents_);
148     elm_object_item_disabled_set(menu_it,
149         (params_.edit_flags & WebContextMenuData::CanPaste) == 0);
150     menu_it = elm_menu_item_add(menu, NULL, "delete", "Delete",
151           Delete, web_contents_);
152     elm_object_item_disabled_set(menu_it,
153         (params_.edit_flags & WebContextMenuData::CanDelete) == 0);
154     elm_menu_item_separator_add(menu, NULL);
155   }
156
157   menu_it = elm_menu_item_add(menu, NULL, "back", "Back",
158       Back, web_contents_);
159   elm_object_item_disabled_set(menu_it,
160       !web_contents_->GetController().CanGoBack());
161   menu_it = elm_menu_item_add(menu, NULL, "forward", "Forward",
162         Forward, web_contents_);
163   elm_object_item_disabled_set(menu_it,
164       !web_contents_->GetController().CanGoForward());
165   elm_menu_item_add(menu, NULL, "reload", "Reload",
166       Reload, web_contents_);
167
168   g_context_menu = menu;
169   elm_menu_move(menu, params.x, params.y);
170   evas_object_show(menu);
171 }
172
173 }  // namespace content