Chromium Code Reviews| Index: content/browser/devtools/renderer_overrides_handler.cc |
| diff --git a/content/browser/devtools/renderer_overrides_handler.cc b/content/browser/devtools/renderer_overrides_handler.cc |
| index d700dee9459362adad5459477dd16d4503bf795a..3ac4f302f053d02b424005b21dd7220e0d346ae2 100644 |
| --- a/content/browser/devtools/renderer_overrides_handler.cc |
| +++ b/content/browser/devtools/renderer_overrides_handler.cc |
| @@ -22,6 +22,8 @@ |
| #include "content/browser/renderer_host/render_view_host_delegate.h" |
| #include "content/browser/renderer_host/render_view_host_impl.h" |
| #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| +#include "content/browser/web_contents/web_contents_impl.h" |
| +#include "content/common/cursors/webcursor.h" |
| #include "content/common/view_messages.h" |
| #include "content/public/browser/browser_thread.h" |
| #include "content/public/browser/content_browser_client.h" |
| @@ -40,6 +42,7 @@ |
| #include "content/public/common/referrer.h" |
| #include "ipc/ipc_sender.h" |
| #include "net/base/net_util.h" |
| +#include "third_party/WebKit/public/platform/WebCursorInfo.h" |
| #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
| #include "third_party/WebKit/public/web/WebInputEvent.h" |
| #include "ui/gfx/codec/jpeg_codec.h" |
| @@ -67,10 +70,10 @@ static int kCaptureRetryLimit = 2; |
| } // namespace |
| -RendererOverridesHandler::RendererOverridesHandler(DevToolsAgentHost* agent) |
| - : agent_(agent), |
| - has_last_compositor_frame_metadata_(false), |
| +RendererOverridesHandler::RendererOverridesHandler() |
| + : has_last_compositor_frame_metadata_(false), |
| capture_retry_count_(0), |
| + color_picker_enabled_(false), |
| weak_factory_(this) { |
| RegisterCommandHandler( |
| devtools::DOM::setFileInputFiles::kName, |
| @@ -142,19 +145,27 @@ RendererOverridesHandler::RendererOverridesHandler(DevToolsAgentHost* agent) |
| &RendererOverridesHandler::PageQueryUsageAndQuota, |
| base::Unretained(this))); |
| RegisterCommandHandler( |
| + devtools::Page::setColorPickerEnabled::kName, |
| + base::Bind( |
| + &RendererOverridesHandler::PageSetColorPickerEnabled, |
| + base::Unretained(this))); |
| + RegisterCommandHandler( |
| devtools::Input::emulateTouchFromMouseEvent::kName, |
| base::Bind( |
| &RendererOverridesHandler::InputEmulateTouchFromMouseEvent, |
| base::Unretained(this))); |
| + mouse_event_callback_ = base::Bind( |
| + &RendererOverridesHandler::HandleMouseEvent, |
| + base::Unretained(this)); |
| } |
| RendererOverridesHandler::~RendererOverridesHandler() {} |
| void RendererOverridesHandler::OnClientDetached() { |
| - RenderViewHostImpl* host = GetRenderViewHostImpl(); |
| - if (screencast_command_ && host) |
| - host->SetTouchEventEmulationEnabled(false, false); |
| + if (screencast_command_ && host_) |
| + host_->SetTouchEventEmulationEnabled(false, false); |
| screencast_command_ = NULL; |
| + SetColorPickerEnabled(false); |
| } |
| void RendererOverridesHandler::OnSwapCompositorFrame( |
| @@ -164,6 +175,8 @@ void RendererOverridesHandler::OnSwapCompositorFrame( |
| if (screencast_command_) |
| InnerSwapCompositorFrame(); |
| + if (color_picker_enabled_) |
| + UpdateColorPickerFrame(); |
| } |
| void RendererOverridesHandler::OnVisibilityChanged(bool visible) { |
| @@ -172,10 +185,19 @@ void RendererOverridesHandler::OnVisibilityChanged(bool visible) { |
| NotifyScreencastVisibility(visible); |
| } |
| -void RendererOverridesHandler::OnRenderViewHostChanged() { |
| - RenderViewHostImpl* host = GetRenderViewHostImpl(); |
| +void RendererOverridesHandler::SetRenderViewHost( |
| + RenderViewHostImpl* host) { |
| + host_ = host; |
| if (screencast_command_ && host) |
| host->SetTouchEventEmulationEnabled(true, true); |
| + if (color_picker_enabled_) |
| + host->AddMouseEventCallback(mouse_event_callback_); |
| +} |
| + |
| +void RendererOverridesHandler::ClearRenderViewHost() { |
| + if (host_) |
| + host_->RemoveMouseEventCallback(mouse_event_callback_); |
| + host_ = NULL; |
| } |
| bool RendererOverridesHandler::OnSetTouchEventEmulationEnabled() { |
| @@ -188,14 +210,13 @@ void RendererOverridesHandler::InnerSwapCompositorFrame() { |
| return; |
| } |
| - RenderViewHost* host = GetRenderViewHostImpl(); |
| - if (!host->GetView()) |
| + if (!host_ || !host_->GetView()) |
| return; |
| last_frame_time_ = base::TimeTicks::Now(); |
| RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| - host->GetView()); |
| + host_->GetView()); |
| // TODO(vkuzkokov): do not use previous frame metadata. |
| cc::CompositorFrameMetadata& metadata = last_compositor_frame_metadata_; |
| @@ -270,8 +291,7 @@ RendererOverridesHandler::GrantPermissionsForSetFileInputFiles( |
| devtools::DOM::setFileInputFiles::kParamFiles; |
| if (!params || !params->GetList(param, &file_list)) |
| return command->InvalidParamResponse(param); |
| - RenderViewHost* host = GetRenderViewHostImpl(); |
| - if (!host) |
| + if (!host_) |
| return NULL; |
| for (size_t i = 0; i < file_list->GetSize(); ++i) { |
| @@ -279,7 +299,7 @@ RendererOverridesHandler::GrantPermissionsForSetFileInputFiles( |
| if (!file_list->GetString(i, &file)) |
| return command->InvalidParamResponse(param); |
| ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadFile( |
| - host->GetProcess()->GetID(), base::FilePath(file)); |
| + host_->GetProcess()->GetID(), base::FilePath(file)); |
| } |
| return NULL; |
| } |
| @@ -290,14 +310,14 @@ RendererOverridesHandler::GrantPermissionsForSetFileInputFiles( |
| scoped_refptr<DevToolsProtocol::Response> |
| RendererOverridesHandler::ClearBrowserCache( |
| scoped_refptr<DevToolsProtocol::Command> command) { |
| - GetContentClient()->browser()->ClearCache(GetRenderViewHostImpl()); |
| + GetContentClient()->browser()->ClearCache(host_); |
| return command->SuccessResponse(NULL); |
| } |
| scoped_refptr<DevToolsProtocol::Response> |
| RendererOverridesHandler::ClearBrowserCookies( |
| scoped_refptr<DevToolsProtocol::Command> command) { |
| - GetContentClient()->browser()->ClearCookies(GetRenderViewHostImpl()); |
| + GetContentClient()->browser()->ClearCookies(host_); |
| return command->SuccessResponse(NULL); |
| } |
| @@ -307,9 +327,8 @@ RendererOverridesHandler::ClearBrowserCookies( |
| scoped_refptr<DevToolsProtocol::Response> |
| RendererOverridesHandler::PageDisable( |
| scoped_refptr<DevToolsProtocol::Command> command) { |
| - RenderViewHostImpl* host = GetRenderViewHostImpl(); |
| - if (screencast_command_ && host) |
| - host->SetTouchEventEmulationEnabled(false, false); |
| + if (screencast_command_ && host_) |
| + host_->SetTouchEventEmulationEnabled(false, false); |
| screencast_command_ = NULL; |
| return NULL; |
| } |
| @@ -331,7 +350,10 @@ RendererOverridesHandler::PageHandleJavaScriptDialog( |
| prompt_override_ptr = NULL; |
| } |
| - WebContents* web_contents = agent_->GetWebContents(); |
| + if (!host_) |
| + return command->InternalErrorResponse("Could not connect to view"); |
| + |
| + WebContents* web_contents = WebContents::FromRenderViewHost(host_); |
| if (web_contents) { |
| JavaScriptDialogManager* manager = |
| web_contents->GetDelegate()->GetJavaScriptDialogManager(); |
| @@ -356,7 +378,10 @@ RendererOverridesHandler::PageNavigate( |
| if (!gurl.is_valid()) |
| return command->InternalErrorResponse("Cannot navigate to invalid URL"); |
| - WebContents* web_contents = agent_->GetWebContents(); |
| + if (!host_) |
| + return command->InternalErrorResponse("Could not connect to view"); |
| + |
| + WebContents* web_contents = WebContents::FromRenderViewHost(host_); |
| if (web_contents) { |
| web_contents->GetController() |
| .LoadURL(gurl, Referrer(), PAGE_TRANSITION_TYPED, std::string()); |
| @@ -370,7 +395,10 @@ RendererOverridesHandler::PageNavigate( |
| scoped_refptr<DevToolsProtocol::Response> |
| RendererOverridesHandler::PageReload( |
| scoped_refptr<DevToolsProtocol::Command> command) { |
| - WebContents* web_contents = agent_->GetWebContents(); |
| + if (!host_) |
| + return command->InternalErrorResponse("Could not connect to view"); |
| + |
| + WebContents* web_contents = WebContents::FromRenderViewHost(host_); |
| if (web_contents) { |
| // Override only if it is crashed. |
| if (!web_contents->IsCrashed()) |
| @@ -385,7 +413,9 @@ RendererOverridesHandler::PageReload( |
| scoped_refptr<DevToolsProtocol::Response> |
| RendererOverridesHandler::PageGetNavigationHistory( |
| scoped_refptr<DevToolsProtocol::Command> command) { |
| - WebContents* web_contents = agent_->GetWebContents(); |
| + if (!host_) |
| + return command->InternalErrorResponse("Could not connect to view"); |
| + WebContents* web_contents = WebContents::FromRenderViewHost(host_); |
| if (web_contents) { |
| base::DictionaryValue* result = new base::DictionaryValue(); |
| NavigationController& controller = web_contents->GetController(); |
| @@ -425,7 +455,10 @@ RendererOverridesHandler::PageNavigateToHistoryEntry( |
| return command->InvalidParamResponse(param); |
| } |
| - WebContents* web_contents = agent_->GetWebContents(); |
| + if (!host_) |
| + return command->InternalErrorResponse("Could not connect to view"); |
| + |
| + WebContents* web_contents = WebContents::FromRenderViewHost(host_); |
| if (web_contents) { |
| NavigationController& controller = web_contents->GetController(); |
| for (int i = 0; i != controller.GetEntryCount(); ++i) { |
| @@ -442,11 +475,10 @@ RendererOverridesHandler::PageNavigateToHistoryEntry( |
| scoped_refptr<DevToolsProtocol::Response> |
| RendererOverridesHandler::PageCaptureScreenshot( |
| scoped_refptr<DevToolsProtocol::Command> command) { |
| - RenderViewHostImpl* host = GetRenderViewHostImpl(); |
| - if (!host->GetView()) |
| - return command->InternalErrorResponse("Unable to access the view"); |
| + if (!host_ || !host_->GetView()) |
| + return command->InternalErrorResponse("Could not connect to view"); |
| - host->GetSnapshotFromBrowser( |
| + host_->GetSnapshotFromBrowser( |
| base::Bind(&RendererOverridesHandler::ScreenshotCaptured, |
| weak_factory_.GetWeakPtr(), command)); |
| return command->AsyncResponsePromise(); |
| @@ -490,15 +522,16 @@ scoped_refptr<DevToolsProtocol::Response> |
| RendererOverridesHandler::PageStartScreencast( |
| scoped_refptr<DevToolsProtocol::Command> command) { |
| screencast_command_ = command; |
| - RenderViewHostImpl* host = GetRenderViewHostImpl(); |
| - host->SetTouchEventEmulationEnabled(true, true); |
| - bool visible = !host->is_hidden(); |
| + if (!host_) |
| + return command->InternalErrorResponse("Could not connect to view"); |
| + host_->SetTouchEventEmulationEnabled(true, true); |
| + bool visible = !host_->is_hidden(); |
| NotifyScreencastVisibility(visible); |
| if (visible) { |
| if (has_last_compositor_frame_metadata_) |
| InnerSwapCompositorFrame(); |
| else |
| - host->Send(new ViewMsg_ForceRedraw(host->GetRoutingID(), 0)); |
| + host_->Send(new ViewMsg_ForceRedraw(host_->GetRoutingID(), 0)); |
| } |
| return command->SuccessResponse(NULL); |
| } |
| @@ -508,9 +541,8 @@ RendererOverridesHandler::PageStopScreencast( |
| scoped_refptr<DevToolsProtocol::Command> command) { |
| last_frame_time_ = base::TimeTicks(); |
| screencast_command_ = NULL; |
| - RenderViewHostImpl* host = GetRenderViewHostImpl(); |
| - if (host) |
| - host->SetTouchEventEmulationEnabled(false, false); |
| + if (host_) |
| + host_->SetTouchEventEmulationEnabled(false, false); |
| return command->SuccessResponse(NULL); |
| } |
| @@ -801,10 +833,11 @@ RendererOverridesHandler::PageQueryUsageAndQuota( |
| weak_factory_.GetWeakPtr(), |
| command); |
| - scoped_refptr<quota::QuotaManager> quota_manager = GetRenderViewHostImpl() |
| - ->GetProcess() |
| - ->GetStoragePartition() |
| - ->GetQuotaManager(); |
| + if (!host_) |
| + return command->InternalErrorResponse("Could not connect to view"); |
| + |
| + scoped_refptr<quota::QuotaManager> quota_manager = |
| + host_->GetProcess()->GetStoragePartition()->GetQuotaManager(); |
| BrowserThread::PostTask( |
| BrowserThread::IO, FROM_HERE, |
| @@ -833,6 +866,253 @@ void RendererOverridesHandler::NotifyScreencastVisibility(bool visible) { |
| devtools::Page::screencastVisibilityChanged::kName, params); |
| } |
| +scoped_refptr<DevToolsProtocol::Response> |
| +RendererOverridesHandler::PageSetColorPickerEnabled( |
| + scoped_refptr<DevToolsProtocol::Command> command) { |
| + base::DictionaryValue* params = command->params(); |
| + bool color_picker_enabled; |
| + if (!params || !params->GetBoolean( |
| + devtools::Page::setColorPickerEnabled::kParamEnabled, |
| + &color_picker_enabled)) { |
| + return command->InvalidParamResponse( |
| + devtools::Page::setColorPickerEnabled::kParamEnabled); |
| + } |
| + |
| + SetColorPickerEnabled(color_picker_enabled); |
| + return command->SuccessResponse(NULL); |
| +} |
| + |
| +void RendererOverridesHandler::SetColorPickerEnabled(bool enabled) { |
| + if (color_picker_enabled_ == enabled) |
| + return; |
| + |
| + color_picker_enabled_ = enabled; |
| + |
| + if (!host_) |
| + return; |
| + |
| + if (enabled) { |
| + host_->AddMouseEventCallback(mouse_event_callback_); |
| + UpdateColorPickerFrame(); |
| + } else { |
| + host_->RemoveMouseEventCallback(mouse_event_callback_); |
| + color_picker_frame_.reset(); |
| + |
| + WebCursor pointer_cursor; |
| + WebCursor::CursorInfo cursor_info; |
| + cursor_info.type = blink::WebCursorInfo::TypePointer; |
| + pointer_cursor.InitFromCursorInfo(cursor_info); |
| + host_->SetCursor(pointer_cursor); |
| + } |
| +} |
| + |
| +void RendererOverridesHandler::UpdateColorPickerFrame() { |
| + if (!host_) |
| + return; |
| + RenderWidgetHostViewBase* view = |
| + static_cast<RenderWidgetHostViewBase*>(host_->GetView()); |
| + if (!view) |
| + return; |
| + |
| + gfx::Size size = view->GetViewBounds().size(); |
| + view->CopyFromCompositingSurface( |
| + gfx::Rect(size), size, |
| + base::Bind(&RendererOverridesHandler::ColorPickerFrameUpdated, |
| + weak_factory_.GetWeakPtr()), |
| + kN32_SkColorType); |
| +} |
| + |
| +void RendererOverridesHandler::ColorPickerFrameUpdated( |
| + bool succeeded, |
| + const SkBitmap& bitmap) { |
| + if (succeeded) |
| + color_picker_frame_ = bitmap; |
| +} |
| + |
| +bool RendererOverridesHandler::HandleMouseEvent( |
| + const blink::WebMouseEvent& event) { |
| + if (color_picker_frame_.drawsNothing()) { |
| + if (event.button == blink::WebMouseEvent::ButtonLeft) |
| + SetColorPickerEnabled(false); |
|
dgozman
2014/08/16 11:04:18
Why do you disable color picker here, but not belo
pfeldman
2014/08/16 11:17:50
I used to disable it below, now I don't for the UX
|
| + return true; |
| + } |
| + |
| + if (event.button == blink::WebMouseEvent::ButtonLeft) { |
| + color_picker_frame_.lockPixels(); |
| + SkColor color = color_picker_frame_.getColor(event.x, event.y); |
| + color_picker_frame_.unlockPixels(); |
| + base::DictionaryValue* color_dict = new base::DictionaryValue(); |
| + color_dict->SetInteger("r", SkColorGetR(color)); |
| + color_dict->SetInteger("g", SkColorGetG(color)); |
| + color_dict->SetInteger("b", SkColorGetB(color)); |
| + color_dict->SetInteger("a", SkColorGetA(color)); |
| + base::DictionaryValue* response = new base::DictionaryValue(); |
| + response->Set(devtools::Page::colorPicked::kParamColor, color_dict); |
| + SendNotification(devtools::Page::colorPicked::kName, response); |
| + } |
| + |
| + if (!host_) |
| + return true; |
| + |
| + // Due to platform limitations, we are using two different cursors |
| + // depending on the platform. Mac and Win have large cursors with two circles |
| + // for original spot and its magnified projection; Linux gets smaller (64 px) |
| + // magnified projection only with centered hotspot. |
| + // Mac Retina requires cursor to be > 120px in order to render smoothly. |
| + |
| +#if defined(OS_LINUX) |
| + const float kCursorSize = 63; |
| + const float kDiameter = 63; |
| + const float kHotspotOffset = 32; |
| + const float kHotspotRadius = 0; |
| + const float kPixelSize = 9; |
| +#else |
| + const float kCursorSize = 150; |
| + const float kDiameter = 110; |
| + const float kHotspotOffset = 25; |
| + const float kHotspotRadius = 5; |
| + const float kPixelSize = 10; |
| +#endif |
| + |
| + float padding = (kCursorSize - kDiameter) / 2; |
| + |
| + skia::RefPtr<SkCanvas> canvas = |
| + skia::AdoptRef(SkCanvas::NewRasterN32(kCursorSize, kCursorSize)); |
| + |
| + SkPaint paint; |
| + |
| + // Paint original spot. |
| + if (kHotspotRadius) { |
| + paint.setStrokeWidth(2); |
| + paint.setColor(SK_ColorDKGRAY); |
| + paint.setStyle(SkPaint::kStroke_Style); |
| + paint.setAntiAlias(true); |
| + canvas->drawCircle(kHotspotOffset, kHotspotOffset, kHotspotRadius, paint); |
| + canvas->drawLine(kHotspotOffset + kHotspotRadius - 1, |
| + kHotspotOffset + kHotspotRadius - 1, |
| + kCursorSize / 2, kCursorSize / 2, |
| + paint); |
| + } |
| + |
| + // Clip circle for magnified projection. |
| + SkPath clip_path; |
| + clip_path.addOval(SkRect::MakeXYWH(padding, padding, kDiameter, kDiameter)); |
| + clip_path.close(); |
| + canvas->clipPath(clip_path, SkRegion::kIntersect_Op, true); |
| + |
| + // Project pixels. |
| + int pixel_count = kDiameter / kPixelSize; |
| + SkRect src_rect = SkRect::MakeXYWH(event.x - pixel_count / 2, |
| + event.y - pixel_count / 2, |
| + pixel_count, pixel_count); |
| + SkRect dst_rect = SkRect::MakeXYWH(padding, padding, kDiameter, kDiameter); |
| + canvas->drawBitmapRectToRect(color_picker_frame_, &src_rect, dst_rect); |
| + |
| + // Paint outline circle. |
| + paint.setStrokeWidth(1); |
| + paint.setAntiAlias(false); |
| + paint.setColor(SK_ColorGRAY); |
| + for (int i = 0; i < pixel_count; ++i) { |
| + canvas->drawLine(padding + i * kPixelSize, padding, |
| + padding + i * kPixelSize, kCursorSize - padding, paint); |
| + canvas->drawLine(padding, padding + i * kPixelSize, |
| + kCursorSize - padding, padding + i * kPixelSize, paint); |
| + } |
| + |
| + // Paint central pixel in red. |
| + SkRect pixel = SkRect::MakeXYWH((kCursorSize - kPixelSize) / 2, |
| + (kCursorSize - kPixelSize) / 2, |
| + kPixelSize, kPixelSize); |
| + paint.setColor(SK_ColorRED); |
| + canvas->drawRect(pixel, paint); |
| + |
| + // Paint outline. |
| + paint.setStrokeWidth(2); |
| + paint.setColor(SK_ColorDKGRAY); |
| + paint.setAntiAlias(true); |
| + paint.setStyle(SkPaint::kStroke_Style); |
| + canvas->drawCircle(kCursorSize / 2, kCursorSize / 2, kDiameter / 2, paint); |
| + |
| + SkBitmap result; |
| + result.allocN32Pixels(kCursorSize, kCursorSize); |
| + canvas->readPixels(&result, 0, 0); |
| + |
| + WebCursor cursor; |
| + WebCursor::CursorInfo cursor_info; |
| + cursor_info.type = blink::WebCursorInfo::TypeCustom; |
| + cursor_info.image_scale_factor = 1; |
|
dgozman
2014/08/16 11:04:17
You need to set this to 2.0 on Retina for smoothne
pfeldman
2014/08/16 11:17:50
Yep. Will follow up with that.
|
| + cursor_info.custom_image = result; |
| + cursor_info.hotspot = |
| + gfx::Point(kHotspotOffset, kHotspotOffset); |
| +#if defined(OS_WIN) |
| + cursor_info.external_handle = 0; |
| +#endif |
| + |
| + cursor.InitFromCursorInfo(cursor_info); |
| + DCHECK(host_); |
| + host_->SetCursor(cursor); |
| + return true; |
| +} |
| + |
| +void RendererOverridesHandler::UpdateColorPickerCursorSmall(int x, int y) { |
|
dgozman
2014/08/16 11:04:17
This is not called from anywhere. Will it be used?
pfeldman
2014/08/16 11:17:50
Forgot to nuke this one (I used to have two indepe
|
| + // Linux has 64 pixel cursor limitation (see ui/base/x/x11_util.cc). |
| + const int kCursorSize = 63; |
| + const float kPixelSize = 9; |
| + |
| + skia::RefPtr<SkCanvas> canvas = |
| + skia::AdoptRef(SkCanvas::NewRasterN32(kCursorSize, kCursorSize)); |
| + |
| + SkPaint paint; |
| + paint.setStrokeWidth(1); |
| + paint.setColor(SK_ColorDKGRAY); |
| + paint.setStyle(SkPaint::kStroke_Style); |
| + paint.setAntiAlias(true); |
| + |
| + SkPath clip_path; |
| + clip_path.addOval(SkRect::MakeXYWH(0, 0, kCursorSize, kCursorSize)); |
| + clip_path.close(); |
| + canvas->clipPath(clip_path, SkRegion::kIntersect_Op, true); |
| + |
| + SkRect src_rect = SkRect::MakeXYWH(x - 3, y - 3, 7, 7); |
| + SkRect dst_rect = SkRect::MakeXYWH(0, 0, kCursorSize, kCursorSize); |
| + canvas->drawBitmapRectToRect(color_picker_frame_, &src_rect, dst_rect); |
| + |
| + paint.setStrokeWidth(1); |
| + paint.setAntiAlias(false); |
| + paint.setColor(SK_ColorGRAY); |
| + for (int i = 0; i < kCursorSize; i += kPixelSize) { |
| + canvas->drawLine(i, 0, i, kCursorSize, paint); |
| + canvas->drawLine(0, i, kCursorSize, i, paint); |
| + } |
| + |
| + SkRect pixel = SkRect::MakeXYWH(kCursorSize / 2 - kPixelSize / 2, |
| + kCursorSize / 2 - kPixelSize / 2, |
| + kPixelSize, kPixelSize); |
| + paint.setColor(SK_ColorRED); |
| + canvas->drawRect(pixel, paint); |
| + |
| + paint.setStrokeWidth(2); |
| + paint.setColor(SK_ColorDKGRAY); |
| + paint.setAntiAlias(true); |
| + canvas->drawCircle(kCursorSize / 2, kCursorSize / 2, kCursorSize / 2, paint); |
| + |
| + SkBitmap result; |
| + result.allocN32Pixels(kCursorSize, kCursorSize); |
| + canvas->readPixels(&result, 0, 0); |
| + |
| + WebCursor cursor; |
| + WebCursor::CursorInfo cursor_info; |
| + cursor_info.type = blink::WebCursorInfo::TypeCustom; |
| + cursor_info.image_scale_factor = 1; |
| + cursor_info.custom_image = result; |
| + cursor_info.hotspot = |
| + gfx::Point(kCursorSize / 2, kCursorSize / 2); |
| + |
| + cursor.InitFromCursorInfo(cursor_info); |
| + DCHECK(host_); |
| + host_->SetCursor(cursor); |
| +} |
| + |
| // Input agent handlers ------------------------------------------------------ |
| scoped_refptr<DevToolsProtocol::Response> |
| @@ -954,17 +1234,14 @@ RendererOverridesHandler::InputEmulateTouchFromMouseEvent( |
| devtools::Input::emulateTouchFromMouseEvent::kParamButton); |
| } |
| - RenderViewHost* host = GetRenderViewHostImpl(); |
| + if (!host_) |
| + return command->InternalErrorResponse("Could not connect to view"); |
| + |
| if (event->type == WebInputEvent::MouseWheel) |
| - host->ForwardWheelEvent(wheel_event); |
| + host_->ForwardWheelEvent(wheel_event); |
| else |
| - host->ForwardMouseEvent(mouse_event); |
| + host_->ForwardMouseEvent(mouse_event); |
| return command->SuccessResponse(NULL); |
| } |
| -RenderViewHostImpl* RendererOverridesHandler::GetRenderViewHostImpl() { |
| - return static_cast<RenderViewHostImpl*>( |
| - agent_->GetWebContents()->GetRenderViewHost()); |
| -} |
| - |
| } // namespace content |