mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add initial Linux support (issue #40).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@338 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@@ -10,25 +10,41 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "base/message_loop.h"
|
||||
#include "base/string_util.h"
|
||||
#include "net/base/net_errors.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupMenu.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDragData.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebImage.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPoint.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
|
||||
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
||||
#include "ui/gfx/native_widget_types.h"
|
||||
#include "ui/gfx/gtk_util.h"
|
||||
#include "ui/gfx/point.h"
|
||||
#include "webkit/glue/webcursor.h"
|
||||
#include "webkit/glue/webdropdata.h"
|
||||
#include "webkit/glue/webpreferences.h"
|
||||
#include "webkit/glue/webkit_glue.h"
|
||||
#include "webkit/glue/window_open_disposition.h"
|
||||
#include "webkit/plugins/npapi/gtk_plugin_container_manager.h"
|
||||
#include "webkit/plugins/npapi/plugin_list.h"
|
||||
#include "webkit/plugins/npapi/webplugin.h"
|
||||
#include "webkit/plugins/npapi/webplugin_delegate_impl.h"
|
||||
|
||||
#include "include/internal/cef_types.h"
|
||||
|
||||
using webkit::npapi::WebPluginDelegateImpl;
|
||||
using WebKit::WebContextMenuData;
|
||||
using WebKit::WebCursorInfo;
|
||||
using WebKit::WebDragData;
|
||||
using WebKit::WebDragOperationsMask;
|
||||
using WebKit::WebExternalPopupMenu;
|
||||
using WebKit::WebExternalPopupMenuClient;
|
||||
using WebKit::WebFrame;
|
||||
using WebKit::WebImage;
|
||||
using WebKit::WebNavigationPolicy;
|
||||
using WebKit::WebPoint;
|
||||
using WebKit::WebPopupMenuInfo;
|
||||
using WebKit::WebRect;
|
||||
using WebKit::WebWidget;
|
||||
@@ -59,11 +75,11 @@ void SelectionClipboardGetContents(GtkClipboard* clipboard,
|
||||
DCHECK(frame);
|
||||
|
||||
std::string selection;
|
||||
if (TEXT_HTML == info) {
|
||||
if (TEXT_HTML == info)
|
||||
selection = frame->selectionAsMarkup().utf8();
|
||||
} else {
|
||||
else
|
||||
selection = frame->selectionAsText().utf8();
|
||||
}
|
||||
|
||||
if (TEXT_HTML == info) {
|
||||
gtk_selection_data_set(selection_data,
|
||||
GetTextHtmlAtom(),
|
||||
@@ -78,17 +94,112 @@ void SelectionClipboardGetContents(GtkClipboard* clipboard,
|
||||
|
||||
} // namespace
|
||||
|
||||
// WebViewClient --------------------------------------------------------------
|
||||
// WebViewClient ----------------------------------s----------------------------
|
||||
|
||||
WebWidget* BrowserWebViewDelegate::createPopupMenu(
|
||||
const WebPopupMenuInfo& info) {
|
||||
NOTREACHED();
|
||||
WebKit::WebExternalPopupMenu* BrowserWebViewDelegate::createExternalPopupMenu(
|
||||
const WebKit::WebPopupMenuInfo& info,
|
||||
WebKit::WebExternalPopupMenuClient* client) {
|
||||
NOTIMPLEMENTED();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::showContextMenu(
|
||||
WebKit::WebFrame* frame, const WebKit::WebContextMenuData& data) {
|
||||
NOTIMPLEMENTED();
|
||||
static gboolean MenuItemHandle(GtkWidget* menu_item, gpointer data)
|
||||
{
|
||||
if (!data)
|
||||
return FALSE;
|
||||
|
||||
BrowserWebViewDelegate* webViewDelegate = (BrowserWebViewDelegate*)data;
|
||||
int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menu_item), "menu_id"));
|
||||
|
||||
webViewDelegate->HandleContextMenu(id);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static GtkWidget* MenuItemCreate(GtkWidget* parent_menu, const char* name,
|
||||
int id, bool is_enabled, BrowserWebViewDelegate* webViewDelegate)
|
||||
{
|
||||
GtkWidget* menu_item = gtk_menu_item_new_with_label(name);
|
||||
|
||||
g_object_set_data(G_OBJECT(menu_item), "menu_id", (gpointer)id);
|
||||
g_signal_connect(G_OBJECT(menu_item), "activate", G_CALLBACK(MenuItemHandle),
|
||||
(gpointer)webViewDelegate);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(parent_menu), menu_item);
|
||||
gtk_widget_set_sensitive(menu_item, is_enabled);
|
||||
|
||||
gtk_widget_show(menu_item);
|
||||
|
||||
return menu_item;
|
||||
}
|
||||
|
||||
static GtkWidget* MenuItemCreateSeperator(GtkWidget* parent_menu)
|
||||
{
|
||||
GtkWidget* menu_item = gtk_menu_item_new();
|
||||
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(parent_menu), menu_item);
|
||||
gtk_widget_show(menu_item);
|
||||
|
||||
return menu_item;
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::showContextMenu(WebKit::WebFrame* frame,
|
||||
const WebKit::WebContextMenuData& data) {
|
||||
GtkWidget* menu = NULL;
|
||||
GdkPoint mouse_pt = { data.mousePosition.x, data.mousePosition.y };
|
||||
|
||||
int edit_flags = 0;
|
||||
int type_flags = 0;
|
||||
|
||||
// Make sure events can be pumped while the menu is up.
|
||||
MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
|
||||
|
||||
// Give the client a chance to handle the menu.
|
||||
if (OnBeforeMenu(data, mouse_pt.x, mouse_pt.y, edit_flags, type_flags))
|
||||
return;
|
||||
|
||||
CefRefPtr<CefClient> client = browser_->GetClient();
|
||||
CefRefPtr<CefMenuHandler> handler;
|
||||
if (client.get())
|
||||
handler = client->GetMenuHandler();
|
||||
|
||||
// Build the correct default context menu
|
||||
if (type_flags & MENUTYPE_EDITABLE) {
|
||||
menu = gtk_menu_new();
|
||||
MenuItemCreate(menu, "Undo", MENU_ID_UNDO,
|
||||
!!(edit_flags & MENU_CAN_UNDO), this);
|
||||
MenuItemCreate(menu, "Redo", MENU_ID_REDO,
|
||||
!!(edit_flags & MENU_CAN_REDO), this);
|
||||
MenuItemCreate(menu, "Cut", MENU_ID_CUT,
|
||||
!!(edit_flags & MENU_CAN_CUT), this);
|
||||
MenuItemCreate(menu, "Copy", MENU_ID_COPY,
|
||||
!!(edit_flags & MENU_CAN_COPY), this);
|
||||
MenuItemCreate(menu, "Paste", MENU_ID_PASTE,
|
||||
!!(edit_flags & MENU_CAN_PASTE), this);
|
||||
MenuItemCreate(menu, "Delete", MENU_ID_DELETE,
|
||||
!!(edit_flags & MENU_CAN_DELETE), this);
|
||||
MenuItemCreateSeperator(menu);
|
||||
MenuItemCreate(menu, "Select All", MENU_ID_SELECTALL,
|
||||
!!(edit_flags & MENU_CAN_SELECT_ALL), this);
|
||||
} else if(type_flags & MENUTYPE_SELECTION) {
|
||||
menu = gtk_menu_new();
|
||||
MenuItemCreate(menu, "Copy", MENU_ID_COPY,
|
||||
!!(edit_flags & MENU_CAN_COPY), this);
|
||||
} else if(type_flags & (MENUTYPE_PAGE | MENUTYPE_FRAME)) {
|
||||
menu = gtk_menu_new();
|
||||
MenuItemCreate(menu, "Back", MENU_ID_NAV_BACK,
|
||||
!!(edit_flags & MENU_CAN_GO_BACK), this);
|
||||
MenuItemCreate(menu, "Forward", MENU_ID_NAV_FORWARD,
|
||||
!!(edit_flags & MENU_CAN_GO_FORWARD), this);
|
||||
MenuItemCreateSeperator(menu);
|
||||
// TODO(port): Enable the print item when supported.
|
||||
// MenuItemCreate(menu, "Print", MENU_ID_PRINT, true, this);
|
||||
MenuItemCreate(menu, "View Source", MENU_ID_VIEWSOURCE, true, this);
|
||||
}
|
||||
|
||||
if (menu) {
|
||||
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3,
|
||||
gtk_get_current_event_time());
|
||||
}
|
||||
}
|
||||
|
||||
// WebWidgetClient ------------------------------------------------------------
|
||||
@@ -123,7 +234,8 @@ void BrowserWebViewDelegate::didChangeCursor(const WebCursorInfo& cursor_info) {
|
||||
gdk_cursor = gfx::GetCursor(cursor_type);
|
||||
}
|
||||
cursor_type_ = cursor_type;
|
||||
gdk_window_set_cursor(browser_->UIT_GetWebViewWndHandle()->window, gdk_cursor);
|
||||
gdk_window_set_cursor(browser_->UIT_GetWebViewWndHandle()->window,
|
||||
gdk_cursor);
|
||||
}
|
||||
|
||||
WebRect BrowserWebViewDelegate::windowRect() {
|
||||
@@ -161,9 +273,9 @@ WebRect BrowserWebViewDelegate::rootWindowRect() {
|
||||
// window. This means the x/y is the distance from the corner of the
|
||||
// screen, and the width/height is the size of the entire browser window.
|
||||
// For example, this is used to implement window.screenX and window.screenY.
|
||||
GtkWidget* drawing_area = host->view_handle();
|
||||
GtkWidget* window =
|
||||
gtk_widget_get_parent(gtk_widget_get_parent(drawing_area));
|
||||
GtkWidget* window = gtk_widget_get_ancestor(GTK_WIDGET(host->view_handle()),
|
||||
GTK_TYPE_WINDOW);
|
||||
|
||||
gint x, y, width, height;
|
||||
gtk_window_get_position(GTK_WINDOW(window), &x, &y);
|
||||
gtk_window_get_size(GTK_WINDOW(window), &width, &height);
|
||||
@@ -222,6 +334,30 @@ void BrowserWebViewDelegate::DidMovePlugin(
|
||||
plugin_container_manager->MovePluginContainer(move);
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::HandleContextMenu(int selected_id)
|
||||
{
|
||||
if (selected_id != 0) {
|
||||
CefRefPtr<CefClient> client = browser_->GetClient();
|
||||
CefRefPtr<CefMenuHandler> handler;
|
||||
if (client.get())
|
||||
handler = client->GetMenuHandler();
|
||||
|
||||
// An action was chosen
|
||||
cef_handler_menuid_t menuId =
|
||||
static_cast<cef_handler_menuid_t>(selected_id);
|
||||
bool handled = false;
|
||||
if (handler.get()) {
|
||||
// Ask the handler if it wants to handle the action
|
||||
handled = handler->OnMenuAction(browser_, menuId);
|
||||
}
|
||||
|
||||
if(!handled) {
|
||||
// Execute the action
|
||||
browser_->UIT_HandleAction(menuId, browser_->GetFocusedFrame());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Protected methods ----------------------------------------------------------
|
||||
|
||||
void BrowserWebViewDelegate::ShowJavaScriptAlert(
|
||||
|
Reference in New Issue
Block a user