diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-16 05:11:05 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-16 05:11:05 +0000 |
commit | 05158051ea881677c03a22ddf38a3e6779cebb9e (patch) | |
tree | 95c6756227e0bbea55da3c4b19abdf99d7eb3ebe /chrome/renderer | |
parent | 6c14b76fede6abc592d9d65965fbdf4626e83efe (diff) | |
download | chromium_src-05158051ea881677c03a22ddf38a3e6779cebb9e.zip chromium_src-05158051ea881677c03a22ddf38a3e6779cebb9e.tar.gz chromium_src-05158051ea881677c03a22ddf38a3e6779cebb9e.tar.bz2 |
Use WebWidget from the WebKit API. This change also makes
use of WebKitClient (replacing WebWidgetDelegate from glue).
The ripple effects of this change are rather large, but most
of the impact is mechanical.
The more interesting changes include:
1- Removing the WebWidget parameter from WebWidgetClient methods. This didn't
matter at all to RenderWidget or RenderView, but it did cause some changes to
be made to TestWebViewDelegate. Now, it is not possible to share a delegate
implementation for both the WebView and a popup menu, so I have a second
instance of the delegate owned by TestShell for use with popup menus.
2- Plumbing WebNavigationPolicy in place of WindowOpenDisposition was getting
to be a pretty large change, so I stopped short of deleting WindowOpenDisposition.
That way the Chrome side can remain mostly unmodified. I then added a mapping
function to convert from WebNavigationPolicy to WindowOpenDisposition.
3- The IME methods on WebWidget were renamed (reviewed separately by hbono), and
there is now an enum to specify the composition command (WebCompositionCommand).
4- I added IPC serialization for WebCompositionCommand and WebTextDirection,
which cleaned up some code that was just using ints in IPC messages.
R=jam
BUG=16234
TEST=none
Review URL: http://codereview.chromium.org/149620
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/print_web_view_helper.cc | 37 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper.h | 35 | ||||
-rw-r--r-- | chrome/renderer/render_view.cc | 55 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 27 | ||||
-rw-r--r-- | chrome/renderer/render_view_unittest.cc | 30 | ||||
-rw-r--r-- | chrome/renderer/render_widget.cc | 131 | ||||
-rw-r--r-- | chrome/renderer/render_widget.h | 57 |
7 files changed, 192 insertions, 180 deletions
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc index aac98ac..115fc12 100644 --- a/chrome/renderer/print_web_view_helper.cc +++ b/chrome/renderer/print_web_view_helper.cc @@ -13,6 +13,7 @@ #include "printing/native_metafile.h" #include "printing/units.h" #include "webkit/api/public/WebConsoleMessage.h" +#include "webkit/api/public/WebRect.h" #include "webkit/api/public/WebScreenInfo.h" #include "webkit/api/public/WebSize.h" #include "webkit/api/public/WebURL.h" @@ -24,6 +25,8 @@ #endif using WebKit::WebConsoleMessage; +using WebKit::WebRect; +using WebKit::WebScreenInfo; using WebKit::WebString; using WebKit::WebURLRequest; @@ -62,9 +65,9 @@ class PrepareFrameAndViewForPrint { print_layout_size.set_height(static_cast<int>( static_cast<double>(print_layout_size.height()) * 1.25)); - prev_view_size_ = web_view->GetSize(); + prev_view_size_ = web_view->size(); - web_view->Resize(print_layout_size); + web_view->resize(print_layout_size); expected_pages_count_ = frame->PrintBegin(print_canvas_size_); } @@ -79,7 +82,7 @@ class PrepareFrameAndViewForPrint { ~PrepareFrameAndViewForPrint() { frame_->PrintEnd(); - web_view_->Resize(prev_view_size_); + web_view_->resize(prev_view_size_); } private: @@ -230,7 +233,7 @@ void PrintWebViewHelper::DidFinishPrinting(bool success) { } if (print_web_view_.get()) { - print_web_view_->Close(); + print_web_view_->close(); print_web_view_.release(); // Close deletes object. print_pages_params_.reset(); } @@ -411,24 +414,28 @@ int32 PrintWebViewHelper::routing_id() { return render_view_->routing_id(); } -void PrintWebViewHelper::DidStopLoading(WebView* webview) { - DCHECK(print_pages_params_.get() != NULL); - DCHECK_EQ(webview, print_web_view_.get()); - PrintPages(*print_pages_params_.get(), print_web_view_->GetMainFrame()); +WebRect PrintWebViewHelper::windowRect() { + NOTREACHED(); + return WebRect(); } -void PrintWebViewHelper::GetWindowRect(WebWidget* webwidget, - WebKit::WebRect* rect) { +WebRect PrintWebViewHelper::windowResizerRect() { NOTREACHED(); + return WebRect(); } -WebKit::WebScreenInfo PrintWebViewHelper::GetScreenInfo(WebWidget* webwidget) { - WebKit::WebScreenInfo info; +WebRect PrintWebViewHelper::rootWindowRect() { NOTREACHED(); - return info; + return WebRect(); } -bool PrintWebViewHelper::IsHidden(WebWidget* webwidget) { +WebScreenInfo PrintWebViewHelper::screenInfo() { NOTREACHED(); - return true; + return WebScreenInfo(); +} + +void PrintWebViewHelper::DidStopLoading(WebView* webview) { + DCHECK(print_pages_params_.get() != NULL); + DCHECK_EQ(webview, print_web_view_.get()); + PrintPages(*print_pages_params_.get(), print_web_view_->GetMainFrame()); } diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h index 11e16fd..13d0747 100644 --- a/chrome/renderer/print_web_view_helper.h +++ b/chrome/renderer/print_web_view_helper.h @@ -66,29 +66,20 @@ class PrintWebViewHelper : public WebViewDelegate { int32 routing_id(); // WebViewDeletegate + virtual void didInvalidateRect(const WebKit::WebRect&) {} + virtual void didScrollRect(int dx, int dy, const WebKit::WebRect& clipRect) {} + virtual void didFocus() {} + virtual void didBlur() {} + virtual void didChangeCursor(const WebKit::WebCursorInfo&) {} + virtual void closeWidgetSoon() {} + virtual void show(WebKit::WebNavigationPolicy) {} + virtual void runModal() {} + virtual WebKit::WebRect windowRect(); + virtual void setWindowRect(const WebKit::WebRect&) {} + virtual WebKit::WebRect windowResizerRect(); + virtual WebKit::WebRect rootWindowRect(); + virtual WebKit::WebScreenInfo screenInfo(); virtual void DidStopLoading(WebView* webview); - virtual void DidInvalidateRect(WebWidget* webwidget, - const WebKit::WebRect& rect) {} - virtual void DidScrollRect(WebWidget* webwidget, int dx, int dy, - const WebKit::WebRect& clip_rect) {} - virtual void Show(WebWidget* webwidget, WindowOpenDisposition disposition) {} - virtual void CloseWidgetSoon(WebWidget* webwidget) {} - virtual void Focus(WebWidget* webwidget) {} - virtual void Blur(WebWidget* webwidget) {} - virtual void SetCursor(WebWidget* webwidget, - const WebKit::WebCursorInfo& cursor) {} - virtual void GetWindowRect(WebWidget* webwidget, WebKit::WebRect* rect); - virtual void SetWindowRect(WebWidget* webwidget, - const WebKit::WebRect& rect) {} - virtual void GetRootWindowRect(WebWidget* webwidget, WebKit::WebRect* rect) {} - virtual void GetRootWindowResizerRect(WebWidget* webwidget, - WebKit::WebRect* rect) {} - virtual void DidMove(WebWidget* webwidget, const WebPluginGeometry& move) {} - virtual void RunModal(WebWidget* webwidget) {} - virtual void AddRef() {} - virtual void Release() {} - virtual bool IsHidden(WebWidget* webwidget); - virtual WebKit::WebScreenInfo GetScreenInfo(WebWidget* webwidget); private: RenderView* render_view_; diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index 15d7771..96cf524a 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -106,6 +106,7 @@ using WebKit::WebDataSource; using WebKit::WebDragData; using WebKit::WebForm; using WebKit::WebHistoryItem; +using WebKit::WebNavigationPolicy; using WebKit::WebNavigationType; using WebKit::WebPopupMenuInfo; using WebKit::WebRect; @@ -116,9 +117,10 @@ using WebKit::WebURL; using WebKit::WebURLError; using WebKit::WebURLRequest; using WebKit::WebURLResponse; +using WebKit::WebVector; +using WebKit::WebWidget; using WebKit::WebWorker; using WebKit::WebWorkerClient; -using WebKit::WebVector; //----------------------------------------------------------------------------- @@ -560,13 +562,13 @@ bool RenderView::CaptureThumbnail(WebView* view, double begin = time_util::GetHighResolutionTimeNow(); #endif - view->Layout(); - const WebSize& size = view->GetSize(); + view->layout(); + const WebSize& size = view->size(); skia::PlatformCanvas canvas; if (!canvas.initialize(size.width, size.height, true)) return false; - view->Paint(&canvas, WebRect(0, 0, size.width, size.height)); + view->paint(&canvas, WebRect(0, 0, size.width, size.height)); skia::BitmapPlatformDevice& device = static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); @@ -1474,12 +1476,12 @@ void RenderView::DidCreateIsolatedScriptContext(WebFrame* webframe) { EventBindings::HandleContextCreated(webframe); } -WindowOpenDisposition RenderView::DispositionForNavigationAction( +WebNavigationPolicy RenderView::PolicyForNavigationAction( WebView* webview, WebFrame* frame, const WebURLRequest& request, WebNavigationType type, - WindowOpenDisposition disposition, + WebNavigationPolicy default_policy, bool is_redirect) { // A content initiated navigation may have originated from a link-click, // script, drag-n-drop operation, etc. @@ -1496,8 +1498,9 @@ WindowOpenDisposition RenderView::DispositionForNavigationAction( // to, for example, opening a new window). // But we sometimes navigate to about:blank to clear a tab, and we want to // still allow that. - if (disposition == CURRENT_TAB && is_content_initiated && - frame->GetParent() == NULL && !url.SchemeIs(chrome::kAboutScheme)) { + if (default_policy == WebKit::WebNavigationPolicyCurrentTab && + is_content_initiated && frame->GetParent() == NULL && + !url.SchemeIs(chrome::kAboutScheme)) { // When we received such unsolicited navigations, we sometimes want to // punt them up to the browser to handle. if (BindingsPolicy::is_dom_ui_enabled(enabled_bindings_) || @@ -1505,8 +1508,8 @@ WindowOpenDisposition RenderView::DispositionForNavigationAction( frame->GetInViewSourceMode() || url.SchemeIs(chrome::kViewSourceScheme) || url.SchemeIs(chrome::kPrintScheme)) { - OpenURL(webview, url, GURL(), disposition); - return IGNORE_ACTION; // Suppress the load here. + OpenURL(webview, url, GURL(), default_policy); + return WebKit::WebNavigationPolicyIgnore; // Suppress the load here. } } @@ -1535,16 +1538,16 @@ WindowOpenDisposition RenderView::DispositionForNavigationAction( // Must not have issued the request from this page. is_content_initiated && // Must be targeted at the current tab. - disposition == CURRENT_TAB && + default_policy == WebKit::WebNavigationPolicyCurrentTab && // Must be a JavaScript navigation, which appears as "other". type == WebKit::WebNavigationTypeOther; if (is_fork) { // Open the URL via the browser, not via WebKit. - OpenURL(webview, url, GURL(), disposition); - return IGNORE_ACTION; + OpenURL(webview, url, GURL(), default_policy); + return WebKit::WebNavigationPolicyIgnore; } - return disposition; + return default_policy; } void RenderView::RunJavaScriptAlert(WebFrame* webframe, @@ -1884,8 +1887,9 @@ WebWorker* RenderView::CreateWebWorker(WebWorkerClient* client) { void RenderView::OpenURL(WebView* webview, const GURL& url, const GURL& referrer, - WindowOpenDisposition disposition) { - Send(new ViewHostMsg_OpenURL(routing_id_, url, referrer, disposition)); + WebNavigationPolicy policy) { + Send(new ViewHostMsg_OpenURL( + routing_id_, url, referrer, NavigationPolicyToDisposition(policy))); } void RenderView::DidContentsSizeChange(WebWidget* webwidget, @@ -1918,7 +1922,7 @@ void RenderView::DidContentsSizeChange(WebWidget* webwidget, // This method provides us with the information about how to display the newly // created RenderView (i.e., as a constrained popup or as a new tab). // -void RenderView::Show(WebWidget* webwidget, WindowOpenDisposition disposition) { +void RenderView::show(WebNavigationPolicy policy) { DCHECK(!did_show_) << "received extraneous Show call"; DCHECK(opener_id_ != MSG_ROUTING_NONE); @@ -1929,17 +1933,18 @@ void RenderView::Show(WebWidget* webwidget, WindowOpenDisposition disposition) { // NOTE: initial_pos_ may still have its default values at this point, but // that's okay. It'll be ignored if disposition is not NEW_POPUP, or the // browser process will impose a default position otherwise. - Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, disposition, - initial_pos_, opened_by_user_gesture_, creator_url_)); + Send(new ViewHostMsg_ShowView(opener_id_, routing_id_, + NavigationPolicyToDisposition(policy), initial_pos_, + opened_by_user_gesture_, creator_url_)); SetPendingWindowRect(initial_pos_); } -void RenderView::CloseWidgetSoon(WebWidget* webwidget) { +void RenderView::closeWidgetSoon() { if (!popup_notification_visible_) - RenderWidget::CloseWidgetSoon(webwidget); + RenderWidget::closeWidgetSoon(); } -void RenderView::RunModal(WebWidget* webwidget) { +void RenderView::runModal() { DCHECK(did_show_) << "should already have shown the view"; IPC::SyncMessage* msg = new ViewHostMsg_RunModal(routing_id_); @@ -2732,7 +2737,7 @@ void RenderView::OnThemeChanged() { #if defined(OS_WIN) gfx::NativeTheme::instance()->CloseHandles(); gfx::Rect view_rect(0, 0, size_.width(), size_.height()); - DidInvalidateRect(webwidget_, view_rect); + didInvalidateRect(view_rect); #else // defined(OS_WIN) // TODO(port): we don't support theming on non-Windows platforms yet NOTIMPLEMENTED(); @@ -3018,6 +3023,10 @@ void RenderView::FocusAccessibilityObject( #endif } +void RenderView::DidMovePlugin(const WebPluginGeometry& move) { + SchedulePluginMove(move); +} + void RenderView::SendPasswordForms(WebFrame* frame) { std::vector<WebForm> forms; frame->GetForms(&forms); diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 0b1a38a..c8afcd2 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -35,8 +35,8 @@ #include "webkit/glue/webview.h" #if defined(OS_WIN) -// RenderView is a diamond-shaped hierarchy, with WebWidgetDelegate at the root. -// VS warns when we inherit the WebWidgetDelegate method implementations from +// RenderView is a diamond-shaped hierarchy, with WebWidgetClient at the root. +// VS warns when we inherit the WebWidgetClient method implementations from // RenderWidget. It's safe to ignore that warning. #pragma warning(disable: 4250) #endif @@ -202,7 +202,7 @@ class RenderView : public RenderWidget, virtual void DidChangeLocationWithinPageForFrame(WebView* webview, WebFrame* frame, bool is_new_navigation); - virtual void DidContentsSizeChange(WebWidget* webwidget, + virtual void DidContentsSizeChange(WebKit::WebWidget* webwidget, int new_width, int new_height); @@ -222,19 +222,21 @@ class RenderView : public RenderWidget, virtual void DidDestroyScriptContextForFrame(WebFrame* webframe); virtual void DidCreateIsolatedScriptContext(WebFrame* webframe); - virtual WindowOpenDisposition DispositionForNavigationAction( + virtual WebKit::WebNavigationPolicy PolicyForNavigationAction( WebView* webview, WebFrame* frame, const WebKit::WebURLRequest& request, WebKit::WebNavigationType type, - WindowOpenDisposition disposition, + WebKit::WebNavigationPolicy default_policy, bool is_redirect); virtual WebView* CreateWebView(WebView* webview, bool user_gesture, const GURL& creator_url); - virtual WebWidget* CreatePopupWidget(WebView* webview, bool activatable); - virtual WebWidget* CreatePopupWidgetWithInfo( + virtual WebKit::WebWidget* CreatePopupWidget( + WebView* webview, + bool activatable); + virtual WebKit::WebWidget* CreatePopupWidgetWithInfo( WebView* webview, const WebKit::WebPopupMenuInfo& info); virtual WebPluginDelegate* CreatePluginDelegate( @@ -249,7 +251,7 @@ class RenderView : public RenderWidget, virtual void OnMissingPluginStatus(WebPluginDelegate* delegate, int status); virtual void OpenURL(WebView* webview, const GURL& url, const GURL& referrer, - WindowOpenDisposition disposition); + WebKit::WebNavigationPolicy policy); virtual void DidDownloadImage(int id, const GURL& image_url, bool errored, @@ -301,6 +303,7 @@ class RenderView : public RenderWidget, const WebKit::WebRect& selection); virtual bool WasOpenedByUserGesture() const; virtual void FocusAccessibilityObject(WebCore::AccessibilityObject* acc_obj); + virtual void DidMovePlugin(const WebPluginGeometry& move); virtual void SpellCheck(const std::wstring& word, int* misspell_location, int* misspell_length); virtual std::wstring GetAutoCorrectWord(const std::wstring& word); @@ -313,11 +316,11 @@ class RenderView : public RenderWidget, virtual void DidSerializeDataForFrame(const GURL& frame_url, const std::string& data, PageSavingSerializationStatus status); - // WebWidgetDelegate + // WebKit::WebWidgetClient // Most methods are handled by RenderWidget. - virtual void Show(WebWidget* webwidget, WindowOpenDisposition disposition); - virtual void CloseWidgetSoon(WebWidget* webwidget); - virtual void RunModal(WebWidget* webwidget); + virtual void show(WebKit::WebNavigationPolicy policy); + virtual void closeWidgetSoon(); + virtual void runModal(); // Do not delete directly. This class is reference counted. virtual ~RenderView(); diff --git a/chrome/renderer/render_view_unittest.cc b/chrome/renderer/render_view_unittest.cc index ab27ec0..4b4ed60 100644 --- a/chrome/renderer/render_view_unittest.cc +++ b/chrome/renderer/render_view_unittest.cc @@ -10,8 +10,23 @@ #include "testing/gtest/include/gtest/gtest.h" #include "webkit/api/public/WebURLError.h" +using WebKit::WebCompositionCommand; +using WebKit::WebTextDirection; using WebKit::WebURLError; +static WebCompositionCommand ToCompositionCommand(int string_type) { + switch (string_type) { + default: + NOTREACHED(); + case -1: + return WebKit::WebCompositionCommandDiscard; + case 0: + return WebKit::WebCompositionCommandSet; + case 1: + return WebKit::WebCompositionCommandConfirm; + } +} + TEST_F(RenderViewTest, OnLoadAlternateHTMLText) { // Test a new navigation. GURL test_url("http://www.google.com/some_test_url"); @@ -210,11 +225,12 @@ TEST_F(RenderViewTest, ImeComposition) { break; case IME_SETCOMPOSITION: - view_->OnImeSetComposition(ime_message->string_type, - ime_message->cursor_position, - ime_message->target_start, - ime_message->target_end, - ime_message->ime_string); + view_->OnImeSetComposition( + ToCompositionCommand(ime_message->string_type), + ime_message->cursor_position, + ime_message->target_start, + ime_message->target_end, + WideToUTF16Hack(ime_message->ime_string)); break; } @@ -257,8 +273,8 @@ TEST_F(RenderViewTest, OnSetTextDirection) { WebTextDirection direction; const wchar_t* expected_result; } kTextDirection[] = { - {WEB_TEXT_DIRECTION_RTL, L"\x000A" L"rtl,rtl"}, - {WEB_TEXT_DIRECTION_LTR, L"\x000A" L"ltr,ltr"}, + { WebKit::WebTextDirectionRightToLeft, L"\x000A" L"rtl,rtl" }, + { WebKit::WebTextDirectionLeftToRight, L"\x000A" L"ltr,ltr" }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTextDirection); ++i) { // Set the text direction of the <textarea> element. diff --git a/chrome/renderer/render_widget.cc b/chrome/renderer/render_widget.cc index 7ff612f..e6ac408 100644 --- a/chrome/renderer/render_widget.cc +++ b/chrome/renderer/render_widget.cc @@ -16,6 +16,7 @@ #include "skia/ext/platform_canvas.h" #include "third_party/skia/include/core/SkShader.h" #include "webkit/api/public/WebCursorInfo.h" +#include "webkit/api/public/WebPopupMenu.h" #include "webkit/api/public/WebPopupMenuInfo.h" #include "webkit/api/public/WebRect.h" #include "webkit/api/public/WebScreenInfo.h" @@ -26,15 +27,18 @@ #include "third_party/skia/include/core/SkMallocPixelRef.h" #endif // defined(OS_POSIX) -#include "webkit/glue/webtextdirection.h" -#include "webkit/glue/webwidget.h" +#include "webkit/api/public/WebWidget.h" +using WebKit::WebCompositionCommand; using WebKit::WebCursorInfo; using WebKit::WebInputEvent; +using WebKit::WebNavigationPolicy; +using WebKit::WebPopupMenu; using WebKit::WebPopupMenuInfo; using WebKit::WebRect; using WebKit::WebScreenInfo; using WebKit::WebSize; +using WebKit::WebTextDirection; RenderWidget::RenderWidget(RenderThreadBase* render_thread, bool activatable) : routing_id_(MSG_ROUTING_NONE), @@ -102,7 +106,7 @@ void RenderWidget::Init(int32 opener_id) { if (opener_id != MSG_ROUTING_NONE) opener_id_ = opener_id; - webwidget_ = WebWidget::Create(this); + webwidget_ = WebPopupMenu::create(this); bool result = render_thread_->Send( new ViewHostMsg_CreateWidget(opener_id, activatable_, &routing_id_)); @@ -210,7 +214,7 @@ void RenderWidget::OnResize(const gfx::Size& new_size, // When resizing, we want to wait to paint before ACK'ing the resize. This // ensures that we only resize as fast as we can paint. We only need to send // an ACK if we are resized to a non-empty rect. - webwidget_->Resize(new_size); + webwidget_->resize(new_size); if (!new_size.IsEmpty()) { DCHECK(!paint_rect_.IsEmpty()); @@ -246,7 +250,7 @@ void RenderWidget::OnWasRestored(bool needs_repainting) { set_next_paint_is_restore_ack(); // Generate a full repaint. - DidInvalidateRect(webwidget_, gfx::Rect(size_.width(), size_.height())); + didInvalidateRect(gfx::Rect(size_.width(), size_.height())); } void RenderWidget::OnPaintRectAck() { @@ -295,7 +299,7 @@ void RenderWidget::OnHandleInputEvent(const IPC::Message& message) { reinterpret_cast<const WebInputEvent*>(data); bool processed = false; if (webwidget_) - processed = webwidget_->HandleInputEvent(input_event); + processed = webwidget_->handleInputEvent(*input_event); IPC::Message* response = new ViewHostMsg_HandleInputEvent_ACK(routing_id_); response->WriteInt(input_event->type); @@ -306,13 +310,13 @@ void RenderWidget::OnHandleInputEvent(const IPC::Message& message) { void RenderWidget::OnMouseCaptureLost() { if (webwidget_) - webwidget_->MouseCaptureLost(); + webwidget_->mouseCaptureLost(); } void RenderWidget::OnSetFocus(bool enable) { has_focus_ = enable; if (webwidget_) - webwidget_->SetFocus(enable); + webwidget_->setFocus(enable); if (enable) { // Force to retrieve the state of the focused widget to determine if we // should activate IMEs next time when this process calls the UpdateIME() @@ -326,7 +330,7 @@ void RenderWidget::ClearFocus() { // We may have got the focus from the browser before this gets processed, in // which case we do not want to unfocus ourself. if (!has_focus_ && webwidget_) - webwidget_->SetFocus(false); + webwidget_->setFocus(false); } void RenderWidget::PaintRect(const gfx::Rect& rect, @@ -347,7 +351,7 @@ void RenderWidget::PaintRect(const gfx::Rect& rect, canvas->drawPaint(paint); } - webwidget_->Paint(canvas, rect); + webwidget_->paint(canvas, rect); // Flush to underlying bitmap. TODO(darin): is this needed? canvas->getTopPlatformDevice().accessBitmap(false); @@ -366,7 +370,7 @@ void RenderWidget::DoDeferredPaint() { } // Layout may generate more invalidation... - webwidget_->Layout(); + webwidget_->layout(); // OK, save the current paint_rect to a local since painting may cause more // invalidation. Some WebCore rendering objects only layout when painted. @@ -420,7 +424,7 @@ void RenderWidget::DoDeferredScroll() { // Layout may generate more invalidation, so we might have to bail on // optimized scrolling... - webwidget_->Layout(); + webwidget_->layout(); if (scroll_rect_.IsEmpty()) return; @@ -493,8 +497,7 @@ void RenderWidget::DoDeferredScroll() { /////////////////////////////////////////////////////////////////////////////// // WebWidgetDelegate -void RenderWidget::DidInvalidateRect(WebWidget* webwidget, - const WebRect& rect) { +void RenderWidget::didInvalidateRect(const WebRect& rect) { // We only want one pending DoDeferredPaint call at any time... bool paint_pending = !paint_rect_.IsEmpty(); @@ -525,11 +528,10 @@ void RenderWidget::DidInvalidateRect(WebWidget* webwidget, this, &RenderWidget::DoDeferredPaint)); } -void RenderWidget::DidScrollRect(WebWidget* webwidget, int dx, int dy, - const WebRect& clip_rect) { +void RenderWidget::didScrollRect(int dx, int dy, const WebRect& clip_rect) { if (dx != 0 && dy != 0) { // We only support scrolling along one axis at a time. - DidScrollRect(webwidget, 0, dy, clip_rect); + didScrollRect(0, dy, clip_rect); dy = 0; } @@ -549,9 +551,9 @@ void RenderWidget::DidScrollRect(WebWidget* webwidget, int dx, int dy, return; } } - DidInvalidateRect(webwidget_, scroll_rect_); + didInvalidateRect(scroll_rect_); DCHECK(scroll_rect_.IsEmpty()); - DidInvalidateRect(webwidget_, clip_rect); + didInvalidateRect(clip_rect); return; } @@ -569,8 +571,7 @@ void RenderWidget::DidScrollRect(WebWidget* webwidget, int dx, int dy, this, &RenderWidget::DoDeferredScroll)); } -void RenderWidget::SetCursor(WebWidget* webwidget, - const WebCursorInfo& cursor_info) { +void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { // TODO(darin): Eliminate this temporary. WebCursor cursor(cursor_info); @@ -588,8 +589,7 @@ void RenderWidget::SetCursor(WebWidget* webwidget, // This method provides us with the information about how to display the newly // created RenderWidget (i.e., as a constrained popup or as a new tab). // -void RenderWidget::Show(WebWidget* webwidget, - WindowOpenDisposition disposition) { +void RenderWidget::show(WebNavigationPolicy) { DCHECK(!did_show_) << "received extraneous Show call"; DCHECK(routing_id_ != MSG_ROUTING_NONE); DCHECK(opener_id_ != MSG_ROUTING_NONE); @@ -610,7 +610,7 @@ void RenderWidget::Show(WebWidget* webwidget, } } -void RenderWidget::Focus(WebWidget* webwidget) { +void RenderWidget::didFocus() { // Prevent the widget from stealing the focus if it does not have focus // already. We do this by explicitely setting the focus to false again. // We only let the browser focus the renderer. @@ -620,7 +620,7 @@ void RenderWidget::Focus(WebWidget* webwidget) { } } -void RenderWidget::Blur(WebWidget* webwidget) { +void RenderWidget::didBlur() { Send(new ViewHostMsg_Blur(routing_id_)); } @@ -628,7 +628,7 @@ void RenderWidget::DoDeferredClose() { Send(new ViewHostMsg_Close(routing_id_)); } -void RenderWidget::CloseWidgetSoon(WebWidget* webwidget) { +void RenderWidget::closeWidgetSoon() { // If a page calls window.close() twice, we'll end up here twice, but that's // OK. It is safe to send multiple Close messages. @@ -642,28 +642,26 @@ void RenderWidget::CloseWidgetSoon(WebWidget* webwidget) { } void RenderWidget::GenerateFullRepaint() { - DidInvalidateRect(webwidget_, gfx::Rect(size_.width(), size_.height())); + didInvalidateRect(gfx::Rect(size_.width(), size_.height())); } void RenderWidget::Close() { if (webwidget_) { - webwidget_->Close(); + webwidget_->close(); webwidget_ = NULL; } } -void RenderWidget::GetWindowRect(WebWidget* webwidget, WebRect* result) { - if (pending_window_rect_count_) { - *result = pending_window_rect_; - return; - } +WebRect RenderWidget::windowRect() { + if (pending_window_rect_count_) + return pending_window_rect_; gfx::Rect rect; Send(new ViewHostMsg_GetWindowRect(routing_id_, host_window_, &rect)); - *result = rect; + return rect; } -void RenderWidget::SetWindowRect(WebWidget* webwidget, const WebRect& pos) { +void RenderWidget::setWindowRect(const WebRect& pos) { if (did_show_) { Send(new ViewHostMsg_RequestMove(routing_id_, pos)); SetPendingWindowRect(pos); @@ -677,25 +675,23 @@ void RenderWidget::SetPendingWindowRect(const WebRect& rect) { pending_window_rect_count_++; } -void RenderWidget::GetRootWindowRect(WebWidget* webwidget, WebRect* result) { +WebRect RenderWidget::rootWindowRect() { if (pending_window_rect_count_) { // NOTE(mbelshe): If there is a pending_window_rect_, then getting // the RootWindowRect is probably going to return wrong results since the // browser may not have processed the Move yet. There isn't really anything // good to do in this case, and it shouldn't happen - since this size is // only really needed for windowToScreen, which is only used for Popups. - *result = pending_window_rect_; - return; + return pending_window_rect_; } gfx::Rect rect; Send(new ViewHostMsg_GetRootWindowRect(routing_id_, host_window_, &rect)); - *result = rect; + return rect; } -void RenderWidget::GetRootWindowResizerRect(WebWidget* webwidget, - WebRect* rect) { - *rect = resizer_rect_; +WebRect RenderWidget::windowResizerRect() { + return resizer_rect_; } void RenderWidget::OnImeSetInputMode(bool is_active) { @@ -705,17 +701,17 @@ void RenderWidget::OnImeSetInputMode(bool is_active) { ime_is_active_ = is_active; } -void RenderWidget::OnImeSetComposition(int string_type, +void RenderWidget::OnImeSetComposition(WebCompositionCommand command, int cursor_position, int target_start, int target_end, - const std::wstring& ime_string) { - if (webwidget_) { - ime_control_busy_ = true; - webwidget_->ImeSetComposition(string_type, cursor_position, - target_start, target_end, - ime_string); - ime_control_busy_ = false; - } + const string16& ime_string) { + if (!webwidget_) + return; + ime_control_busy_ = true; + webwidget_->handleCompositionEvent(command, cursor_position, + target_start, target_end, + ime_string); + ime_control_busy_ = false; } void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { @@ -725,27 +721,19 @@ void RenderWidget::OnMsgRepaint(const gfx::Size& size_to_paint) { set_next_paint_is_repaint_ack(); gfx::Rect repaint_rect(size_to_paint.width(), size_to_paint.height()); - DidInvalidateRect(webwidget_, repaint_rect); + didInvalidateRect(repaint_rect); } -void RenderWidget::OnSetTextDirection(int direction) { +void RenderWidget::OnSetTextDirection(WebTextDirection direction) { if (!webwidget_) return; - - WebTextDirection new_direction = static_cast<WebTextDirection>(direction); - if (new_direction == WEB_TEXT_DIRECTION_DEFAULT || - new_direction == WEB_TEXT_DIRECTION_LTR || - new_direction == WEB_TEXT_DIRECTION_RTL) { - webwidget_->SetTextDirection(new_direction); - } else { - NOTREACHED(); - } + webwidget_->setTextDirection(direction); } void RenderWidget::SetBackground(const SkBitmap& background) { background_ = background; // Generate a full repaint. - DidInvalidateRect(webwidget_, gfx::Rect(size_.width(), size_.height())); + didInvalidateRect(gfx::Rect(size_.width(), size_.height())); } bool RenderWidget::next_paint_is_resize_ack() const { @@ -781,7 +769,7 @@ void RenderWidget::UpdateIME() { bool enable_ime = false; WebRect caret_rect; if (!webwidget_ || - !webwidget_->ImeUpdateStatus(&enable_ime, &caret_rect)) { + !webwidget_->queryCompositionStatus(&enable_ime, &caret_rect)) { // There are not any editable widgets attached to this process. // We should disable the IME to prevent it from sending CJK strings to // non-editable widgets. @@ -839,8 +827,13 @@ void RenderWidget::UpdateIME() { ime_control_y_ = caret_rect.y; } -void RenderWidget::DidMove(WebWidget* webwidget, - const WebPluginGeometry& move) { +WebScreenInfo RenderWidget::screenInfo() { + WebScreenInfo results; + Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results)); + return results; +} + +void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) { size_t i = 0; for (; i < plugin_window_moves_.size(); ++i) { if (plugin_window_moves_[i].window == move.window) { @@ -852,9 +845,3 @@ void RenderWidget::DidMove(WebWidget* webwidget, if (i == plugin_window_moves_.size()) plugin_window_moves_.push_back(move); } - -WebScreenInfo RenderWidget::GetScreenInfo(WebWidget* webwidget) { - WebScreenInfo results; - Send(new ViewHostMsg_GetScreenInfo(routing_id_, host_window_, &results)); - return results; -} diff --git a/chrome/renderer/render_widget.h b/chrome/renderer/render_widget.h index f1fa069..005b4b6 100644 --- a/chrome/renderer/render_widget.h +++ b/chrome/renderer/render_widget.h @@ -17,9 +17,10 @@ #include "chrome/renderer/render_process.h" #include "skia/ext/platform_canvas.h" #include "third_party/skia/include/core/SkBitmap.h" - +#include "webkit/api/public/WebCompositionCommand.h" #include "webkit/api/public/WebRect.h" -#include "webkit/glue/webwidget_delegate.h" +#include "webkit/api/public/WebTextDirection.h" +#include "webkit/api/public/WebWidgetClient.h" #include "webkit/glue/webcursor.h" class RenderThreadBase; @@ -34,7 +35,7 @@ struct WebPopupMenuInfo; // a RenderWidgetHost, the latter of which lives in a different process. class RenderWidget : public IPC::Channel::Listener, public IPC::Message::Sender, - virtual public WebWidgetDelegate, + virtual public WebKit::WebWidgetClient, public base::RefCounted<RenderWidget> { public: // Creates a new RenderWidget. The opener_id is the routing ID of the @@ -56,7 +57,7 @@ class RenderWidget : public IPC::Channel::Listener, } // May return NULL when the window is closing. - WebWidget* webwidget() const { + WebKit::WebWidget* webwidget() const { return webwidget_; } @@ -66,27 +67,24 @@ class RenderWidget : public IPC::Channel::Listener, // IPC::Message::Sender virtual bool Send(IPC::Message* msg); - // WebWidgetDelegate - virtual void DidInvalidateRect(WebWidget* webwidget, - const WebKit::WebRect& rect); - virtual void DidScrollRect(WebWidget* webwidget, int dx, int dy, - const WebKit::WebRect& clip_rect); - virtual void Show(WebWidget* webwidget, WindowOpenDisposition disposition); - virtual void CloseWidgetSoon(WebWidget* webwidget); - virtual void Focus(WebWidget* webwidget); - virtual void Blur(WebWidget* webwidget); - virtual void SetCursor(WebWidget* webwidget, - const WebKit::WebCursorInfo& cursor); - virtual void GetWindowRect(WebWidget* webwidget, WebKit::WebRect* rect); - virtual void SetWindowRect(WebWidget* webwidget, - const WebKit::WebRect& rect); - virtual void GetRootWindowRect(WebWidget* webwidget, WebKit::WebRect* rect); - virtual void GetRootWindowResizerRect(WebWidget* webwidget, - WebKit::WebRect* rect); - virtual void DidMove(WebWidget* webwidget, const WebPluginGeometry& move); - virtual void RunModal(WebWidget* webwidget) {} - virtual bool IsHidden(WebWidget* webwidget) { return is_hidden_; } - virtual WebKit::WebScreenInfo GetScreenInfo(WebWidget* webwidget); + // WebKit::WebWidgetClient + virtual void didInvalidateRect(const WebKit::WebRect&); + virtual void didScrollRect(int dx, int dy, const WebKit::WebRect& clipRect); + virtual void didFocus(); + virtual void didBlur(); + virtual void didChangeCursor(const WebKit::WebCursorInfo&); + virtual void closeWidgetSoon(); + virtual void show(WebKit::WebNavigationPolicy); + virtual void runModal() {} + virtual WebKit::WebRect windowRect(); + virtual void setWindowRect(const WebKit::WebRect&); + virtual WebKit::WebRect windowResizerRect(); + virtual WebKit::WebRect rootWindowRect(); + virtual WebKit::WebScreenInfo screenInfo(); + + // Called when a plugin is moved. These events are queued up and sent with + // the next paint or scroll message to the host. + void SchedulePluginMove(const WebPluginGeometry& move); // Invalidates entire widget rect to generate a full repaint. void GenerateFullRepaint(); @@ -138,11 +136,12 @@ class RenderWidget : public IPC::Channel::Listener, void OnMouseCaptureLost(); void OnSetFocus(bool enable); void OnImeSetInputMode(bool is_active); - void OnImeSetComposition(int string_type, int cursor_position, + void OnImeSetComposition(WebKit::WebCompositionCommand command, + int cursor_position, int target_start, int target_end, - const std::wstring& ime_string); + const string16& ime_string); void OnMsgRepaint(const gfx::Size& size_to_paint); - void OnSetTextDirection(int direction); + void OnSetTextDirection(WebKit::WebTextDirection direction); // Override point to notify that a paint has happened. This fires after the // browser side has updated the screen for a newly painted region. @@ -188,7 +187,7 @@ class RenderWidget : public IPC::Channel::Listener, int32 routing_id_; // We are responsible for destroying this object via its Close method. - WebWidget* webwidget_; + WebKit::WebWidget* webwidget_; // Set to the ID of the view that initiated creating this view, if any. When // the view was initiated by the browser (the common case), this will be |