summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-04 05:42:51 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-04 05:42:51 +0000
commit79dbc66fba17d6b4967fe86a577b11d15548cdec (patch)
treedf2853054e47aa76cea79eb6664f4c21cb54bd9e /chrome
parentbdc66ceff07dac7b74ddea70fabdf535936d39b1 (diff)
downloadchromium_src-79dbc66fba17d6b4967fe86a577b11d15548cdec.zip
chromium_src-79dbc66fba17d6b4967fe86a577b11d15548cdec.tar.gz
chromium_src-79dbc66fba17d6b4967fe86a577b11d15548cdec.tar.bz2
Hook up WebEditingClient.
Moves the WebViewDelegate parameter back to WebView::Create and adds a second parameter for WebEditingClient. I had hoped to make the WebEditingClient NULL for RenderView on Windows and Mac, but that turned out to not be an option. I need a few methods on all platforms. The Describe* functions from EditorClientImpl are moved into the TestWebViewDelegate since they are only applicable to layout tests. R=dglazkov BUG= TEST=none Review URL: http://codereview.chromium.org/195008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25432 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/renderer/print_web_view_helper.cc4
-rw-r--r--chrome/renderer/render_view.cc146
-rw-r--r--chrome/renderer/render_view.h53
3 files changed, 137 insertions, 66 deletions
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index fdc1c9a..aa7f78f7 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -93,9 +93,9 @@ bool PrintWebViewHelper::CopyAndPrint(const ViewMsg_PrintPages_Params& params,
prefs.javascript_enabled = false;
prefs.java_enabled = false;
- print_web_view_.reset(WebView::Create());
+ print_web_view_.reset(WebView::Create(this, NULL));
prefs.Apply(print_web_view_.get());
- print_web_view_->InitializeMainFrame(this);
+ print_web_view_->InitializeMainFrame();
print_pages_params_.reset(new ViewMsg_PrintPages_Params(params));
print_pages_params_->pages.clear(); // Print all pages of selection.
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 2c32e5f..d857123 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -108,17 +108,21 @@ using WebKit::WebConsoleMessage;
using WebKit::WebData;
using WebKit::WebDataSource;
using WebKit::WebDragData;
+using WebKit::WebEditingAction;
using WebKit::WebForm;
using WebKit::WebFrame;
using WebKit::WebHistoryItem;
using WebKit::WebNavigationPolicy;
using WebKit::WebNavigationType;
+using WebKit::WebNode;
using WebKit::WebPopupMenuInfo;
+using WebKit::WebRange;
using WebKit::WebRect;
using WebKit::WebScriptSource;
using WebKit::WebSettings;
using WebKit::WebSize;
using WebKit::WebString;
+using WebKit::WebTextAffinity;
using WebKit::WebTextDirection;
using WebKit::WebURL;
using WebKit::WebURLError;
@@ -280,18 +284,12 @@ void RenderView::Init(gfx::NativeViewId parent_hwnd,
devtools_agent_.reset(new DevToolsAgent(routing_id, this));
- webwidget_ = WebView::Create();
+ webwidget_ = WebView::Create(this, this);
webkit_preferences_.Apply(webview());
- webview()->InitializeMainFrame(this);
+ webview()->InitializeMainFrame();
OnSetRendererPrefs(renderer_prefs);
-#if defined(OS_LINUX)
- // We have to enable ourselves as the editor delegate on linux so we can copy
- // text selections to the X clipboard.
- webview()->SetUseEditorDelegate(true);
-#endif
-
// Don't let WebCore keep a B/F list - we have our own.
// We let it keep 1 entry because FrameLoader::goToItem expects an item in the
// backForwardList, which is used only in ASSERTs.
@@ -1033,8 +1031,7 @@ void RenderView::UpdateSessionHistory(WebFrame* frame) {
routing_id_, page_id_, webkit_glue::HistoryItemToString(item)));
}
-///////////////////////////////////////////////////////////////////////////////
-// WebViewDelegate
+// WebViewDelegate ------------------------------------------------------------
bool RenderView::CanAcceptLoadDrops() const {
return renderer_preferences_.can_accept_load_drops;
@@ -1977,6 +1974,8 @@ void RenderView::DidContentsSizeChange(WebWidget* webwidget,
}
}
+// WebKit::WebWidgetClient ----------------------------------------------------
+
// We are supposed to get a single call to Show for a newly created RenderView
// that was created via RenderView::CreateWebView. So, we wait until this
// point to dispatch the ShowView message.
@@ -2015,6 +2014,99 @@ void RenderView::runModal() {
Send(msg);
}
+// WebKit::WebEditingClient ---------------------------------------------------
+
+bool RenderView::shouldBeginEditing(const WebRange& range) {
+ return true;
+}
+
+bool RenderView::shouldEndEditing(const WebRange& range) {
+ return true;
+}
+
+bool RenderView::shouldInsertNode(const WebNode& node, const WebRange& range,
+ WebEditingAction action) {
+ return true;
+}
+
+bool RenderView::shouldInsertText(const WebString& text, const WebRange& range,
+ WebEditingAction action) {
+ return true;
+}
+
+bool RenderView::shouldChangeSelectedRange(const WebRange& from_range,
+ const WebRange& to_range,
+ WebTextAffinity affinity,
+ bool still_selecting) {
+ return true;
+}
+
+bool RenderView::shouldDeleteRange(const WebRange& range) {
+ return true;
+}
+
+bool RenderView::shouldApplyStyle(const WebString& style,
+ const WebRange& range) {
+ return true;
+}
+
+bool RenderView::isSmartInsertDeleteEnabled() {
+ return true;
+}
+
+bool RenderView::isSelectTrailingWhitespaceEnabled() {
+#if defined(OS_WIN)
+ return true;
+#else
+ return false;
+#endif
+}
+
+void RenderView::setInputMethodEnabled(bool enabled) {
+ // Save the updated IME status and mark the input focus has been updated.
+ // The IME status is to be sent to a browser process next time when
+ // the input caret is rendered.
+ if (!ime_control_busy_) {
+ ime_control_updated_ = true;
+ ime_control_new_state_ = enabled;
+ }
+}
+
+void RenderView::didChangeSelection(bool is_empty_selection) {
+#if defined(OS_LINUX)
+ if (!handling_input_event_)
+ return;
+ // TODO(estade): investigate incremental updates to the selection so that we
+ // don't send the entire selection over IPC every time.
+ if (!is_empty_selection) {
+ // Sometimes we get repeated didChangeSelection calls from webkit when
+ // the selection hasn't actually changed. We don't want to report these
+ // because it will cause us to continually claim the X clipboard.
+ const std::string& this_selection =
+ webview()->GetFocusedFrame()->selectionAsText().utf8();
+ if (this_selection == last_selection_)
+ return;
+
+ Send(new ViewHostMsg_SelectionChanged(routing_id_,
+ this_selection));
+ last_selection_ = this_selection;
+ } else {
+ last_selection_.clear();
+ }
+#endif
+}
+
+void RenderView::didExecuteCommand(const WebString& command_name) {
+ const std::wstring& name = UTF16ToWideHack(command_name);
+ if (StartsWith(name, L"Move", true) ||
+ StartsWith(name, L"Insert", true) ||
+ StartsWith(name, L"Delete", true))
+ return;
+ UserMetricsRecordAction(name);
+}
+
+// webkit_glue::WebPluginPageDelegate -----------------------------------------
+
webkit_glue::WebPluginDelegate* RenderView::CreatePluginDelegate(
const GURL& url,
const std::string& mime_type,
@@ -2444,16 +2536,6 @@ std::wstring RenderView::GetAutoCorrectWord(
return autocorrect_word;
}
-void RenderView::SetInputMethodState(bool enabled) {
- // Save the updated IME status and mark the input focus has been updated.
- // The IME status is to be sent to a browser process next time when
- // the input caret is rendered.
- if (!ime_control_busy_) {
- ime_control_updated_ = true;
- ime_control_new_state_ = enabled;
- }
-}
-
void RenderView::ScriptedPrint(WebFrame* frame) {
DCHECK(webview());
if (webview()) {
@@ -2528,30 +2610,6 @@ void RenderView::SetTooltipText(WebView* webview,
text_direction_hint));
}
-void RenderView::DidChangeSelection(bool is_empty_selection) {
-#if defined(OS_LINUX)
- if (!handling_input_event_)
- return;
- // TODO(estade): investigate incremental updates to the selection so that we
- // don't send the entire selection over IPC every time.
- if (!is_empty_selection) {
- // Sometimes we get repeated DidChangeSelection calls from webkit when
- // the selection hasn't actually changed. We don't want to report these
- // because it will cause us to continually claim the X clipboard.
- const std::string& this_selection =
- webview()->GetFocusedFrame()->selectionAsText().utf8();
- if (this_selection == last_selection_)
- return;
-
- Send(new ViewHostMsg_SelectionChanged(routing_id_,
- this_selection));
- last_selection_ = this_selection;
- } else {
- last_selection_.clear();
- }
-#endif
-}
-
void RenderView::DownloadUrl(const GURL& url, const GURL& referrer) {
Send(new ViewHostMsg_DownloadUrl(routing_id_, url, referrer));
}
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 83518cd..7318da7 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -29,6 +29,7 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
#include "webkit/api/public/WebConsoleMessage.h"
+#include "webkit/api/public/WebEditingClient.h"
#include "webkit/api/public/WebTextDirection.h"
#include "webkit/glue/dom_serializer_delegate.h"
#include "webkit/glue/form_data.h"
@@ -99,6 +100,7 @@ typedef base::RefCountedData<int> SharedRenderViewCounter;
//
class RenderView : public RenderWidget,
public WebViewDelegate,
+ public WebKit::WebEditingClient,
public webkit_glue::WebPluginPageDelegate,
public webkit_glue::DomSerializerDelegate,
public base::SupportsWeakPtr<RenderView> {
@@ -179,7 +181,6 @@ class RenderView : public RenderWidget,
const std::wstring& message,
unsigned int line_no,
const std::wstring& source_id);
-
virtual void DidStartLoading(WebView* webview);
virtual void DidStopLoading(WebView* webview);
virtual void DidCreateDataSource(WebKit::WebFrame* frame,
@@ -212,20 +213,23 @@ class RenderView : public RenderWidget,
virtual void DidFailLoadWithError(WebView* webview,
const WebKit::WebURLError& error,
WebKit::WebFrame* forFrame);
- virtual void DidFinishDocumentLoadForFrame(WebView* webview, WebKit::WebFrame* frame);
+ virtual void DidFinishDocumentLoadForFrame(
+ WebView* webview,
+ WebKit::WebFrame* frame);
virtual bool DidLoadResourceFromMemoryCache(
WebView* webview,
const WebKit::WebURLRequest& request,
const WebKit::WebURLResponse& response,
WebKit::WebFrame* frame);
- virtual void DidHandleOnloadEventsForFrame(WebView* webview, WebKit::WebFrame* frame);
+ virtual void DidHandleOnloadEventsForFrame(
+ WebView* webview,
+ WebKit::WebFrame* frame);
virtual void DidChangeLocationWithinPageForFrame(WebView* webview,
WebKit::WebFrame* frame,
bool is_new_navigation);
virtual void DidContentsSizeChange(WebKit::WebWidget* webwidget,
int new_width,
int new_height);
-
virtual void DidCompleteClientRedirect(WebView* webview,
WebKit::WebFrame* frame,
const GURL& source);
@@ -240,13 +244,11 @@ class RenderView : public RenderWidget,
uint32 identifier,
const WebKit::WebURLResponse& response);
virtual void DidFinishLoading(WebKit::WebFrame* webframe, uint32 identifier);
-
virtual void WindowObjectCleared(WebKit::WebFrame* webframe);
virtual void DocumentElementAvailable(WebKit::WebFrame* webframe);
virtual void DidCreateScriptContextForFrame(WebKit::WebFrame* webframe);
virtual void DidDestroyScriptContextForFrame(WebKit::WebFrame* webframe);
virtual void DidCreateIsolatedScriptContext(WebKit::WebFrame* webframe);
-
virtual WebKit::WebNavigationPolicy PolicyForNavigationAction(
WebView* webview,
WebKit::WebFrame* frame,
@@ -254,7 +256,6 @@ class RenderView : public RenderWidget,
WebKit::WebNavigationType type,
WebKit::WebNavigationPolicy default_policy,
bool is_redirect);
-
virtual WebView* CreateWebView(WebView* webview,
bool user_gesture,
const GURL& creator_url);
@@ -280,7 +281,6 @@ class RenderView : public RenderWidget,
const GURL& image_url,
bool errored,
const SkBitmap& image);
-
virtual void ShowContextMenu(WebView* webview,
ContextNodeType node_type,
int x,
@@ -297,10 +297,8 @@ class RenderView : public RenderWidget,
const std::string& frame_charset);
virtual void StartDragging(WebView* webview,
const WebKit::WebDragData& drag_data);
-
virtual void TakeFocus(WebView* webview, bool reverse);
virtual void JSOutOfMemory();
-
virtual void NavigateBackForwardSoon(int offset);
virtual int GetHistoryBackListCount();
virtual int GetHistoryForwardListCount();
@@ -308,18 +306,10 @@ class RenderView : public RenderWidget,
virtual void SetTooltipText(WebView* webview,
const std::wstring& tooltip_text,
WebKit::WebTextDirection text_direction_hint);
- // Called when the text selection changed. This is only called on linux since
- // on other platforms the RenderView doesn't act as an editor client delegate.
- virtual void DidChangeSelection(bool is_empty_selection);
-
virtual void DownloadUrl(const GURL& url, const GURL& referrer);
-
virtual void UpdateInspectorSettings(const std::wstring& raw_settings);
-
virtual WebDevToolsAgentDelegate* GetWebDevToolsAgentDelegate();
-
virtual void PasteFromSelectionClipboard();
-
virtual void ReportFindInPageMatchCount(int count, int request_id,
bool final_update);
virtual void ReportFindInPageSelection(int request_id,
@@ -330,7 +320,6 @@ class RenderView : public RenderWidget,
virtual void SpellCheck(const std::wstring& word, int* misspell_location,
int* misspell_length);
virtual std::wstring GetAutoCorrectWord(const std::wstring& word);
- virtual void SetInputMethodState(bool enabled);
virtual void ScriptedPrint(WebKit::WebFrame* frame);
virtual void UserMetricsRecordAction(const std::wstring& action);
virtual void DnsPrefetch(const std::vector<std::string>& host_names);
@@ -341,7 +330,31 @@ class RenderView : public RenderWidget,
virtual void closeWidgetSoon();
virtual void runModal();
- // WebPluginPageDelegate:
+ // WebKit::WebEditingClient
+ virtual bool shouldBeginEditing(const WebKit::WebRange& range);
+ virtual bool shouldEndEditing(const WebKit::WebRange& range);
+ virtual bool shouldInsertNode(
+ const WebKit::WebNode& node, const WebKit::WebRange& range,
+ WebKit::WebEditingAction action);
+ virtual bool shouldInsertText(
+ const WebKit::WebString& text, const WebKit::WebRange& range,
+ WebKit::WebEditingAction action);
+ virtual bool shouldChangeSelectedRange(
+ const WebKit::WebRange& from, const WebKit::WebRange& to,
+ WebKit::WebTextAffinity affinity, bool still_selecting);
+ virtual bool shouldDeleteRange(const WebKit::WebRange& range);
+ virtual bool shouldApplyStyle(
+ const WebKit::WebString& style, const WebKit::WebRange& range);
+ virtual bool isSmartInsertDeleteEnabled();
+ virtual bool isSelectTrailingWhitespaceEnabled();
+ virtual void setInputMethodEnabled(bool enabled);
+ virtual void didBeginEditing() {}
+ virtual void didChangeSelection(bool is_selection_empty);
+ virtual void didChangeContents() {}
+ virtual void didExecuteCommand(const WebKit::WebString& command_name);
+ virtual void didEndEditing() {}
+
+ // webkit_glue::WebPluginPageDelegate
virtual webkit_glue::WebPluginDelegate* CreatePluginDelegate(
const GURL& url,
const std::string& mime_type,