}
void SelectionControllerEfl::ShowContextMenu() {
- WebContentsImpl* wci = static_cast<WebContentsImpl*>(&web_contents_);
- RenderWidgetHostViewEfl* rwhv =
- static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
- RenderViewHost* rvh = static_cast<RenderViewHost*>(wci->GetRenderViewHost());
-
- content::ContextMenuParams convertedParams = *(selection_data_->GetContextMenuParams());
-
// If there is no handles on screen, do not show context
// menu, but also do not leave selection mode.
if (!IsAnyHandleOnScreen())
return;
+ content::ContextMenuParams convertedParams = *(selection_data_->GetContextMenuParams());
+
int blinkX, blinkY;
+ RenderWidgetHostViewEfl* rwhv =
+ static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
if (rwhv)
rwhv->EvasToBlinkCords(convertedParams.x, convertedParams.y, &blinkX, &blinkY);
convertedParams.x = blinkX;
// TODO(a1.gomes): In case of EWK apps, the call below end up calling
// EWebView::ShowContextMenu. We have to make sure parameters
// are correct.
+ WebContentsImpl* wci = static_cast<WebContentsImpl*>(&web_contents_);
WebContentsViewEfl* wcve = static_cast<WebContentsViewEfl*>(wci->GetView());
- wcve->ShowContextMenu(rvh->GetMainFrame(), convertedParams);
+ wcve->ShowContextMenu(convertedParams);
}
void SelectionControllerEfl::CancelContextMenu(int request_id) {
delegate_->ShowContextMenu(render_frame_host, params);
}
+// Note: This is a EFL specific extension to WebContentsView responsible
+// for actually displaying a context menu UI.
+// On the other side, its overload method (above) is called by chromium
+// in response to a long press gesture. It is up to the embedder to define
+// how this long press gesture will be
+// handled, e.g. showing context menu right away or afte user lifts up his
+// finger.
+void WebContentsViewEfl::ShowContextMenu(const ContextMenuParams& params) {
+ if (efl_delegate_)
+ efl_delegate_->ShowContextMenu(params);
+}
+
void WebContentsViewEfl::QuerySelectionStyle() {
if (efl_delegate_)
efl_delegate_->QuerySelectionStyle();
// content::RenderViewHostDelegateView implementation.
void ShowContextMenu(RenderFrameHost* render_frame_host,
const ContextMenuParams& params) override;
+ void ShowContextMenu(const ContextMenuParams& params);
void ShowPopupMenu(RenderFrameHost* render_frame_host,
const gfx::Rect& bounds,
int item_height,
#include <vector>
#include "content/common/content_export.h"
+#include "content/public/common/context_menu_params.h"
#include "content/public/common/menu_item.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "ui/gfx/geometry/rect.h"
virtual void HandleZoomGesture(blink::WebGestureEvent& event) = 0;
virtual bool UseKeyPadWithoutUserAction() = 0;
+
+ virtual void ShowContextMenu(const ContextMenuParams& params) = 0;
};
} // namespace content
return true;
}
-void EWebView::ShowContextMenu(const content::ContextMenuParams& params) {
+void EWebView::HandleLongPressGesture(const content::ContextMenuParams& params) {
// This menu is created in renderer process and it does not now anything about
// view scaling factor and it has another calling sequence, so coordinates is not updated.
content::ContextMenuParams convertedParams = params;
convertedParams.x = convertedPoint.x();
convertedParams.y = convertedPoint.y();
- context_menu_.reset(new content::ContextMenuControllerEfl(this, *web_contents_.get()));
+ Evas_Coord x, y;
+ evas_object_geometry_get(evas_object(), &x, &y, 0, 0);
+ convertedParams.x += x;
+ convertedParams.y += y;
+
+ if (GetSelectionController() && GetSelectionController()->GetLongPressed()) {
+ bool show_context_menu_now =
+ !GetSelectionController()->HandleLongPressEvent(convertedPoint, convertedParams);
+ if (show_context_menu_now)
+ ShowContextMenuInternal(convertedParams);
+ }
+}
+
+void EWebView::ShowContextMenu(const content::ContextMenuParams& params) {
+ // This menu is created in renderer process and it does not now anything about
+ // view scaling factor and it has another calling sequence, so coordinates is not updated.
+ content::ContextMenuParams convertedParams = params;
+ gfx::Point convertedPoint = rwhv()->ConvertPointInViewPix(gfx::Point(params.x, params.y));
+ convertedParams.x = convertedPoint.x();
+ convertedParams.y = convertedPoint.y();
Evas_Coord x, y;
evas_object_geometry_get(evas_object(), &x, &y, 0, 0);
context_menu_position_ = gfx::Point(convertedParams.x, convertedParams.y);
- if (GetSelectionController()) {
- bool handled = false;
- if (GetSelectionController()->GetLongPressed())
- handled = GetSelectionController()->HandleLongPressEvent(convertedPoint, convertedParams);
-
- if (!handled) {
- if (!context_menu_->PopulateAndShowContextMenu(convertedParams)) {
- context_menu_.reset();
- GetSelectionController()->HideHandles();
- }
- }
+ ShowContextMenuInternal(convertedParams);
+}
+
+void EWebView::ShowContextMenuInternal(const content::ContextMenuParams& params) {
+ context_menu_.reset(new content::ContextMenuControllerEfl(this, *web_contents_.get()));
+ if (!context_menu_->PopulateAndShowContextMenu(params)) {
+ context_menu_.reset();
+ GetSelectionController()->HideHandles();
}
}
Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
Eina_Bool PopupMenuClose();
+ void HandleLongPressGesture(const content::ContextMenuParams&);
void ShowContextMenu(const content::ContextMenuParams&);
void CancelContextMenu(int request_id);
void SetScale(double scale_factor, int x, int y);
void ReleasePopupMenuList();
+ void ShowContextMenuInternal(const content::ContextMenuParams&);
+
scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
scoped_refptr<Ewk_Context> context_;
scoped_refptr<Ewk_Context> old_context_;
: web_view_(wv) {
}
+// Note: WebContentsViewDelegate::ShowContextMenu is the hook called
+// by chromium in response to a long press gesture.
+// However, in EWK apps, browser enters in selection mode in response
+// to it.
void WebContentsViewDelegateEwk::ShowContextMenu(
content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params) {
- web_view_->ShowContextMenu(params);
+ web_view_->HandleLongPressGesture(params);
}
bool WebContentsViewEflDelegateEwk::UseKeyPadWithoutUserAction() {
return web_view_->GetSettings()->useKeyPadWithoutUserAction();
}
+
+void WebContentsViewEflDelegateEwk::ShowContextMenu(
+ const content::ContextMenuParams& params) {
+ web_view_->ShowContextMenu(params);
+}
bool UseKeyPadWithoutUserAction() override;
+ void ShowContextMenu(const content::ContextMenuParams& params) override;
+
private:
EWebView* web_view_;
};