1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "webkit/child/webkitplatformsupport_child_impl.h"
7 #include "base/memory/discardable_memory.h"
8 #include "third_party/WebKit/public/web/WebInputEvent.h"
9 #include "webkit/child/fling_curve_configuration.h"
10 #include "webkit/child/web_discardable_memory_impl.h"
11 #include "webkit/child/webthread_impl.h"
12 #include "webkit/child/worker_task_runner.h"
14 #if defined(OS_ANDROID)
15 #include "webkit/child/fling_animator_impl_android.h"
18 using WebKit::WebFallbackThemeEngine;
19 using WebKit::WebThemeEngine;
21 namespace webkit_glue {
23 WebKitPlatformSupportChildImpl::WebKitPlatformSupportChildImpl()
24 : current_thread_slot_(&DestroyCurrentThread),
25 fling_curve_configuration_(new FlingCurveConfiguration) {}
27 WebKitPlatformSupportChildImpl::~WebKitPlatformSupportChildImpl() {}
29 WebThemeEngine* WebKitPlatformSupportChildImpl::themeEngine() {
30 return &native_theme_engine_;
33 WebFallbackThemeEngine* WebKitPlatformSupportChildImpl::fallbackThemeEngine() {
34 return &fallback_theme_engine_;
37 void WebKitPlatformSupportChildImpl::SetFlingCurveParameters(
38 const std::vector<float>& new_touchpad,
39 const std::vector<float>& new_touchscreen) {
40 fling_curve_configuration_->SetCurveParameters(new_touchpad, new_touchscreen);
43 WebKit::WebGestureCurve*
44 WebKitPlatformSupportChildImpl::createFlingAnimationCurve(
46 const WebKit::WebFloatPoint& velocity,
47 const WebKit::WebSize& cumulative_scroll) {
48 #if defined(OS_ANDROID)
49 return FlingAnimatorImpl::CreateAndroidGestureCurve(velocity,
53 if (device_source == WebKit::WebGestureEvent::Touchscreen)
54 return fling_curve_configuration_->CreateForTouchScreen(velocity,
57 return fling_curve_configuration_->CreateForTouchPad(velocity,
61 WebKit::WebThread* WebKitPlatformSupportChildImpl::createThread(
63 return new WebThreadImpl(name);
66 WebKit::WebThread* WebKitPlatformSupportChildImpl::currentThread() {
67 WebThreadImplForMessageLoop* thread =
68 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get());
72 scoped_refptr<base::MessageLoopProxy> message_loop =
73 base::MessageLoopProxy::current();
74 if (!message_loop.get())
77 thread = new WebThreadImplForMessageLoop(message_loop.get());
78 current_thread_slot_.Set(thread);
82 void WebKitPlatformSupportChildImpl::didStartWorkerRunLoop(
83 const WebKit::WebWorkerRunLoop& runLoop) {
84 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance();
85 worker_task_runner->OnWorkerRunLoopStarted(runLoop);
88 void WebKitPlatformSupportChildImpl::didStopWorkerRunLoop(
89 const WebKit::WebWorkerRunLoop& runLoop) {
90 WorkerTaskRunner* worker_task_runner = WorkerTaskRunner::Instance();
91 worker_task_runner->OnWorkerRunLoopStopped(runLoop);
94 WebKit::WebDiscardableMemory*
95 WebKitPlatformSupportChildImpl::allocateAndLockDiscardableMemory(size_t bytes) {
96 return WebDiscardableMemoryImpl::CreateLockedMemory(bytes).release();
100 void WebKitPlatformSupportChildImpl::DestroyCurrentThread(void* thread) {
101 WebThreadImplForMessageLoop* impl =
102 static_cast<WebThreadImplForMessageLoop*>(thread);
106 } // namespace webkit_glue