2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "web/WebPluginContainerImpl.h"
34 #include "core/page/Chrome.h"
35 #include "core/page/EventHandler.h"
36 #include "platform/exported/WrappedResourceResponse.h"
37 #include "public/web/WebElement.h"
38 #include "public/web/WebInputEvent.h"
39 #include "public/web/WebPlugin.h"
40 #include "public/web/WebViewClient.h"
41 #include "web/ChromeClientImpl.h"
42 #include "web/ScrollbarGroup.h"
43 #include "web/WebDataSourceImpl.h"
44 #include "web/WebInputEventConversion.h"
45 #include "web/WebViewImpl.h"
47 #include "HTMLNames.h"
48 #include "bindings/v8/ScriptController.h"
49 #include "core/clipboard/Clipboard.h"
50 #include "core/clipboard/DataObject.h"
51 #include "core/events/GestureEvent.h"
52 #include "core/events/KeyboardEvent.h"
53 #include "core/events/MouseEvent.h"
54 #include "core/events/TouchEvent.h"
55 #include "core/events/WheelEvent.h"
56 #include "core/frame/FrameView.h"
57 #include "core/frame/LocalFrame.h"
58 #include "core/html/HTMLFormElement.h"
59 #include "core/html/HTMLPlugInElement.h"
60 #include "core/loader/FormState.h"
61 #include "core/loader/FrameLoadRequest.h"
62 #include "core/page/FocusController.h"
63 #include "core/page/Page.h"
64 #include "core/page/scrolling/ScrollingCoordinator.h"
65 #include "core/plugins/PluginOcclusionSupport.h"
66 #include "core/rendering/HitTestResult.h"
67 #include "core/rendering/RenderBox.h"
68 #include "platform/HostWindow.h"
69 #include "platform/KeyboardCodes.h"
70 #include "platform/PlatformGestureEvent.h"
71 #include "platform/UserGestureIndicator.h"
72 #include "platform/graphics/GraphicsContext.h"
73 #include "platform/graphics/GraphicsLayer.h"
74 #include "platform/scroll/ScrollAnimator.h"
75 #include "platform/scroll/ScrollView.h"
76 #include "platform/scroll/ScrollbarTheme.h"
77 #include "public/platform/Platform.h"
78 #include "public/platform/WebClipboard.h"
79 #include "public/platform/WebCompositorSupport.h"
80 #include "public/platform/WebCursorInfo.h"
81 #include "public/platform/WebDragData.h"
82 #include "public/platform/WebExternalTextureLayer.h"
83 #include "public/platform/WebRect.h"
84 #include "public/platform/WebString.h"
85 #include "public/platform/WebURL.h"
86 #include "public/platform/WebURLError.h"
87 #include "public/platform/WebURLRequest.h"
88 #include "public/platform/WebVector.h"
89 #include "public/web/WebPrintParams.h"
91 using namespace WebCore;
95 // Public methods --------------------------------------------------------------
97 void WebPluginContainerImpl::setFrameRect(const IntRect& frameRect)
99 Widget::setFrameRect(frameRect);
103 void WebPluginContainerImpl::paint(GraphicsContext* gc, const IntRect& damageRect)
105 if (gc->updatingControlTints() && m_scrollbarGroup) {
106 // See comment in FrameView::updateControlTints().
107 if (m_scrollbarGroup->horizontalScrollbar())
108 m_scrollbarGroup->horizontalScrollbar()->invalidate();
109 if (m_scrollbarGroup->verticalScrollbar())
110 m_scrollbarGroup->verticalScrollbar()->invalidate();
113 if (gc->paintingDisabled())
119 // Don't paint anything if the plugin doesn't intersect the damage rect.
120 if (!frameRect().intersects(damageRect))
125 ASSERT(parent()->isFrameView());
126 ScrollView* view = toScrollView(parent());
128 // The plugin is positioned in window coordinates, so it needs to be painted
129 // in window coordinates.
130 IntPoint origin = view->contentsToWindow(IntPoint(0, 0));
131 gc->translate(static_cast<float>(-origin.x()), static_cast<float>(-origin.y()));
133 WebCanvas* canvas = gc->canvas();
135 IntRect windowRect = view->contentsToWindow(damageRect);
136 m_webPlugin->paint(canvas, windowRect);
141 void WebPluginContainerImpl::invalidateRect(const IntRect& rect)
146 RenderBox* renderer = toRenderBox(m_element->renderer());
148 IntRect dirtyRect = rect;
149 dirtyRect.move(renderer->borderLeft() + renderer->paddingLeft(),
150 renderer->borderTop() + renderer->paddingTop());
151 renderer->repaintRectangle(dirtyRect);
154 void WebPluginContainerImpl::setFocus(bool focused)
156 Widget::setFocus(focused);
157 m_webPlugin->updateFocus(focused);
160 void WebPluginContainerImpl::show()
162 setSelfVisible(true);
163 m_webPlugin->updateVisibility(true);
168 void WebPluginContainerImpl::hide()
170 setSelfVisible(false);
171 m_webPlugin->updateVisibility(false);
176 void WebPluginContainerImpl::handleEvent(Event* event)
178 if (!m_webPlugin->acceptsInputEvents())
181 RefPtr<WebPluginContainerImpl> protector(this);
182 // The events we pass are defined at:
183 // http://devedge-temp.mozilla.org/library/manuals/2002/plugin/1.0/structures5.html#1000000
184 // Don't take the documentation as truth, however. There are many cases
185 // where mozilla behaves differently than the spec.
186 if (event->isMouseEvent())
187 handleMouseEvent(toMouseEvent(event));
188 else if (event->isWheelEvent())
189 handleWheelEvent(toWheelEvent(event));
190 else if (event->isKeyboardEvent())
191 handleKeyboardEvent(toKeyboardEvent(event));
192 else if (event->isTouchEvent())
193 handleTouchEvent(toTouchEvent(event));
194 else if (event->isGestureEvent())
195 handleGestureEvent(toGestureEvent(event));
197 // FIXME: it would be cleaner if Widget::handleEvent returned true/false and
198 // HTMLPluginElement called setDefaultHandled or defaultEventHandler.
199 if (!event->defaultHandled())
200 m_element->Node::defaultEventHandler(event);
203 void WebPluginContainerImpl::frameRectsChanged()
205 Widget::frameRectsChanged();
209 void WebPluginContainerImpl::widgetPositionsUpdated()
211 Widget::widgetPositionsUpdated();
215 void WebPluginContainerImpl::eventListenersRemoved()
217 // We're no longer registered to receive touch events, so don't try to remove
218 // the touch event handlers in our destructor.
219 m_touchEventRequestType = TouchEventRequestTypeNone;
222 void WebPluginContainerImpl::setParentVisible(bool parentVisible)
224 // We override this function to make sure that geometry updates are sent
225 // over to the plugin. For e.g. when a plugin is instantiated it does not
226 // have a valid parent. As a result the first geometry update from webkit
227 // is ignored. This function is called when the plugin eventually gets a
230 if (isParentVisible() == parentVisible)
231 return; // No change.
233 Widget::setParentVisible(parentVisible);
234 if (!isSelfVisible())
235 return; // This widget has explicitely been marked as not visible.
237 m_webPlugin->updateVisibility(isVisible());
240 void WebPluginContainerImpl::setParent(Widget* widget)
242 // We override this function so that if the plugin is windowed, we can call
243 // NPP_SetWindow at the first possible moment. This ensures that
244 // NPP_SetWindow is called before the manual load data is sent to a plugin.
245 // If this order is reversed, Flash won't load videos.
247 Widget::setParent(widget);
250 else if (m_webPlugin)
251 m_webPlugin->containerDidDetachFromParent();
254 void WebPluginContainerImpl::setPlugin(WebPlugin* plugin)
256 if (plugin != m_webPlugin) {
257 m_element->resetInstance();
258 m_webPlugin = plugin;
262 float WebPluginContainerImpl::deviceScaleFactor()
264 Page* page = m_element->document().page();
267 return page->deviceScaleFactor();
270 float WebPluginContainerImpl::pageScaleFactor()
272 Page* page = m_element->document().page();
275 return page->pageScaleFactor();
278 float WebPluginContainerImpl::pageZoomFactor()
280 LocalFrame* frame = m_element->document().frame();
283 return frame->pageZoomFactor();
286 void WebPluginContainerImpl::setWebLayer(WebLayer* layer)
288 if (m_webLayer == layer)
291 // If anyone of the layers is null we need to switch between hardware
292 // and software compositing.
293 if (!m_webLayer || !layer)
294 m_element->scheduleLayerUpdate();
296 GraphicsLayer::unregisterContentsLayer(m_webLayer);
298 GraphicsLayer::registerContentsLayer(layer);
302 bool WebPluginContainerImpl::supportsPaginatedPrint() const
304 return m_webPlugin->supportsPaginatedPrint();
307 bool WebPluginContainerImpl::isPrintScalingDisabled() const
309 return m_webPlugin->isPrintScalingDisabled();
312 int WebPluginContainerImpl::printBegin(const WebPrintParams& printParams) const
314 return m_webPlugin->printBegin(printParams);
317 bool WebPluginContainerImpl::printPage(int pageNumber,
318 WebCore::GraphicsContext* gc)
320 if (gc->paintingDisabled())
323 WebCanvas* canvas = gc->canvas();
324 bool ret = m_webPlugin->printPage(pageNumber, canvas);
329 void WebPluginContainerImpl::printEnd()
331 m_webPlugin->printEnd();
334 void WebPluginContainerImpl::copy()
336 if (!m_webPlugin->hasSelection())
339 blink::Platform::current()->clipboard()->writeHTML(m_webPlugin->selectionAsMarkup(), WebURL(), m_webPlugin->selectionAsText(), false);
342 bool WebPluginContainerImpl::executeEditCommand(const WebString& name)
344 if (m_webPlugin->executeEditCommand(name))
354 bool WebPluginContainerImpl::executeEditCommand(const WebString& name, const WebString& value)
356 return m_webPlugin->executeEditCommand(name, value);
359 WebElement WebPluginContainerImpl::element()
361 return WebElement(m_element);
364 void WebPluginContainerImpl::invalidate()
366 Widget::invalidate();
369 void WebPluginContainerImpl::invalidateRect(const WebRect& rect)
371 invalidateRect(static_cast<IntRect>(rect));
374 void WebPluginContainerImpl::scrollRect(int dx, int dy, const WebRect& rect)
376 Widget* parentWidget = parent();
377 if (parentWidget->isFrameView()) {
378 FrameView* parentFrameView = toFrameView(parentWidget);
379 if (!parentFrameView->isOverlapped()) {
380 IntRect damageRect = convertToContainingWindow(static_cast<IntRect>(rect));
381 IntSize scrollDelta(dx, dy);
382 // scroll() only uses the second rectangle, clipRect, and ignores the first
384 parent()->hostWindow()->scroll(scrollDelta, damageRect, damageRect);
389 // Use slow scrolling instead.
390 invalidateRect(rect);
393 void WebPluginContainerImpl::reportGeometry()
398 IntRect windowRect, clipRect;
399 Vector<IntRect> cutOutRects;
400 calculateGeometry(frameRect(), windowRect, clipRect, cutOutRects);
402 m_webPlugin->updateGeometry(windowRect, clipRect, cutOutRects, isVisible());
404 if (m_scrollbarGroup) {
405 m_scrollbarGroup->scrollAnimator()->contentsResized();
406 m_scrollbarGroup->setFrameRect(frameRect());
410 void WebPluginContainerImpl::allowScriptObjects()
414 void WebPluginContainerImpl::clearScriptObjects()
416 LocalFrame* frame = m_element->document().frame();
419 frame->script().cleanupScriptObjectsForPlugin(this);
422 NPObject* WebPluginContainerImpl::scriptableObjectForElement()
424 return m_element->getNPObject();
427 WebString WebPluginContainerImpl::executeScriptURL(const WebURL& url, bool popupsAllowed)
429 LocalFrame* frame = m_element->document().frame();
433 const KURL& kurl = url;
434 ASSERT(kurl.protocolIs("javascript"));
436 String script = decodeURLEscapeSequences(
437 kurl.string().substring(strlen("javascript:")));
439 UserGestureIndicator gestureIndicator(popupsAllowed ? DefinitelyProcessingNewUserGesture : PossiblyProcessingUserGesture);
440 ScriptValue result = frame->script().executeScriptInMainWorldAndReturnValue(ScriptSourceCode(script));
442 // Failure is reported as a null string.
444 result.toString(resultString);
448 void WebPluginContainerImpl::loadFrameRequest(const WebURLRequest& request, const WebString& target, bool notifyNeeded, void* notifyData)
450 LocalFrame* frame = m_element->document().frame();
451 if (!frame || !frame->loader().documentLoader())
452 return; // FIXME: send a notification in this case?
455 // FIXME: This is a bit of hack to allow us to observe completion of
456 // our frame request. It would be better to evolve FrameLoader to
457 // support a completion callback instead.
458 OwnPtr<WebPluginLoadObserver> observer = adoptPtr(new WebPluginLoadObserver(this, request.url(), notifyData));
459 // FIXME: Calling get here is dangerous! What if observer is freed?
460 m_pluginLoadObservers.append(observer.get());
461 WebDataSourceImpl::setNextPluginLoadObserver(observer.release());
464 FrameLoadRequest frameRequest(frame->document(), request.toResourceRequest(), target);
465 UserGestureIndicator gestureIndicator(request.hasUserGesture() ? DefinitelyProcessingNewUserGesture : PossiblyProcessingUserGesture);
466 frame->loader().load(frameRequest);
469 void WebPluginContainerImpl::zoomLevelChanged(double zoomLevel)
471 WebViewImpl* view = WebViewImpl::fromPage(m_element->document().frame()->page());
472 view->fullFramePluginZoomLevelChanged(zoomLevel);
475 bool WebPluginContainerImpl::isRectTopmost(const WebRect& rect)
477 LocalFrame* frame = m_element->document().frame();
481 // hitTestResultAtPoint() takes a padding rectangle.
482 // FIXME: We'll be off by 1 when the width or height is even.
483 IntRect documentRect(x() + rect.x, y() + rect.y, rect.width, rect.height);
484 LayoutPoint center = documentRect.center();
485 // Make the rect we're checking (the point surrounded by padding rects) contained inside the requested rect. (Note that -1/2 is 0.)
486 LayoutSize padding((documentRect.width() - 1) / 2, (documentRect.height() - 1) / 2);
487 HitTestResult result = frame->eventHandler().hitTestResultAtPoint(center, HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::ConfusingAndOftenMisusedDisallowShadowContent, padding);
488 const HitTestResult::NodeSet& nodes = result.rectBasedTestResult();
489 if (nodes.size() != 1)
491 return nodes.first().get() == m_element;
494 void WebPluginContainerImpl::requestTouchEventType(TouchEventRequestType requestType)
496 if (m_touchEventRequestType == requestType)
499 if (requestType != TouchEventRequestTypeNone && m_touchEventRequestType == TouchEventRequestTypeNone)
500 m_element->document().didAddTouchEventHandler(m_element);
501 else if (requestType == TouchEventRequestTypeNone && m_touchEventRequestType != TouchEventRequestTypeNone)
502 m_element->document().didRemoveTouchEventHandler(m_element);
503 m_touchEventRequestType = requestType;
506 void WebPluginContainerImpl::setWantsWheelEvents(bool wantsWheelEvents)
508 if (m_wantsWheelEvents == wantsWheelEvents)
510 m_wantsWheelEvents = wantsWheelEvents;
511 if (Page* page = m_element->document().page()) {
512 if (ScrollingCoordinator* scrollingCoordinator = page->scrollingCoordinator()) {
513 if (parent() && parent()->isFrameView())
514 scrollingCoordinator->notifyLayoutUpdated();
519 WebPoint WebPluginContainerImpl::windowToLocalPoint(const WebPoint& point)
521 ScrollView* view = toScrollView(parent());
524 WebPoint windowPoint = view->windowToContents(point);
525 return roundedIntPoint(m_element->renderer()->absoluteToLocal(LayoutPoint(windowPoint), UseTransforms));
528 WebPoint WebPluginContainerImpl::localToWindowPoint(const WebPoint& point)
530 ScrollView* view = toScrollView(parent());
533 IntPoint absolutePoint = roundedIntPoint(m_element->renderer()->localToAbsolute(LayoutPoint(point), UseTransforms));
534 return view->contentsToWindow(absolutePoint);
537 void WebPluginContainerImpl::didReceiveResponse(const ResourceResponse& response)
539 // Make sure that the plugin receives window geometry before data, or else
540 // plugins misbehave.
543 WrappedResourceResponse urlResponse(response);
544 m_webPlugin->didReceiveResponse(urlResponse);
547 void WebPluginContainerImpl::didReceiveData(const char *data, int dataLength)
549 m_webPlugin->didReceiveData(data, dataLength);
552 void WebPluginContainerImpl::didFinishLoading()
554 m_webPlugin->didFinishLoading();
557 void WebPluginContainerImpl::didFailLoading(const ResourceError& error)
559 m_webPlugin->didFailLoading(error);
562 WebLayer* WebPluginContainerImpl::platformLayer() const
567 NPObject* WebPluginContainerImpl::scriptableObject()
569 return m_webPlugin->scriptableObject();
572 bool WebPluginContainerImpl::getFormValue(String& value)
575 if (m_webPlugin->getFormValue(webValue)) {
582 bool WebPluginContainerImpl::supportsKeyboardFocus() const
584 return m_webPlugin->supportsKeyboardFocus();
587 bool WebPluginContainerImpl::supportsInputMethod() const
589 return m_webPlugin->supportsInputMethod();
592 bool WebPluginContainerImpl::canProcessDrag() const
594 return m_webPlugin->canProcessDrag();
597 bool WebPluginContainerImpl::wantsWheelEvents()
599 return m_wantsWheelEvents;
602 void WebPluginContainerImpl::willDestroyPluginLoadObserver(WebPluginLoadObserver* observer)
604 size_t pos = m_pluginLoadObservers.find(observer);
605 if (pos == kNotFound)
607 m_pluginLoadObservers.remove(pos);
610 ScrollbarGroup* WebPluginContainerImpl::scrollbarGroup()
612 if (!m_scrollbarGroup)
613 m_scrollbarGroup = adoptPtr(new ScrollbarGroup(m_element->document().frame()->view(), frameRect()));
614 return m_scrollbarGroup.get();
617 void WebPluginContainerImpl::willStartLiveResize()
619 if (m_scrollbarGroup)
620 m_scrollbarGroup->willStartLiveResize();
623 void WebPluginContainerImpl::willEndLiveResize()
625 if (m_scrollbarGroup)
626 m_scrollbarGroup->willEndLiveResize();
629 bool WebPluginContainerImpl::paintCustomOverhangArea(GraphicsContext* context, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea, const IntRect& dirtyRect)
632 context->setFillColor(Color(0xCC, 0xCC, 0xCC));
633 context->fillRect(intersection(horizontalOverhangArea, dirtyRect));
634 context->fillRect(intersection(verticalOverhangArea, dirtyRect));
639 // Private methods -------------------------------------------------------------
641 WebPluginContainerImpl::WebPluginContainerImpl(WebCore::HTMLPlugInElement* element, WebPlugin* webPlugin)
643 , m_webPlugin(webPlugin)
645 , m_touchEventRequestType(TouchEventRequestTypeNone)
646 , m_wantsWheelEvents(false)
650 WebPluginContainerImpl::~WebPluginContainerImpl()
652 if (m_touchEventRequestType != TouchEventRequestTypeNone)
653 m_element->document().didRemoveTouchEventHandler(m_element);
655 for (size_t i = 0; i < m_pluginLoadObservers.size(); ++i)
656 m_pluginLoadObservers[i]->clearPluginContainer();
657 m_webPlugin->destroy();
659 GraphicsLayer::unregisterContentsLayer(m_webLayer);
662 void WebPluginContainerImpl::handleMouseEvent(MouseEvent* event)
664 ASSERT(parent()->isFrameView());
666 if (event->isDragEvent()) {
667 if (m_webPlugin->canProcessDrag())
668 handleDragEvent(event);
672 // We cache the parent FrameView here as the plugin widget could be deleted
673 // in the call to HandleEvent. See http://b/issue?id=1362948
674 FrameView* parentView = toFrameView(parent());
676 WebMouseEventBuilder webEvent(this, m_element->renderer(), *event);
677 if (webEvent.type == WebInputEvent::Undefined)
680 if (event->type() == EventTypeNames::mousedown)
683 if (m_scrollbarGroup) {
684 // This needs to be set before the other callbacks in this scope, since
685 // the scroll animator class might query the position in response.
686 m_scrollbarGroup->setLastMousePosition(IntPoint(event->x(), event->y()));
687 if (event->type() == EventTypeNames::mousemove)
688 m_scrollbarGroup->scrollAnimator()->mouseMovedInContentArea();
689 else if (event->type() == EventTypeNames::mouseover)
690 m_scrollbarGroup->scrollAnimator()->mouseEnteredContentArea();
691 else if (event->type() == EventTypeNames::mouseout)
692 m_scrollbarGroup->scrollAnimator()->mouseExitedContentArea();
695 WebCursorInfo cursorInfo;
696 if (m_webPlugin->handleInputEvent(webEvent, cursorInfo))
697 event->setDefaultHandled();
699 // A windowless plugin can change the cursor in response to a mouse move
700 // event. We need to reflect the changed cursor in the frame view as the
701 // mouse is moved in the boundaries of the windowless plugin.
702 Page* page = parentView->frame().page();
705 toChromeClientImpl(page->chrome().client()).setCursorForPlugin(cursorInfo);
708 void WebPluginContainerImpl::handleDragEvent(MouseEvent* event)
710 ASSERT(event->isDragEvent());
712 WebDragStatus dragStatus = WebDragStatusUnknown;
713 if (event->type() == EventTypeNames::dragenter)
714 dragStatus = WebDragStatusEnter;
715 else if (event->type() == EventTypeNames::dragleave)
716 dragStatus = WebDragStatusLeave;
717 else if (event->type() == EventTypeNames::dragover)
718 dragStatus = WebDragStatusOver;
719 else if (event->type() == EventTypeNames::drop)
720 dragStatus = WebDragStatusDrop;
722 if (dragStatus == WebDragStatusUnknown)
725 Clipboard* clipboard = event->dataTransfer();
726 WebDragData dragData(clipboard->dataObject());
727 WebDragOperationsMask dragOperationMask = static_cast<WebDragOperationsMask>(clipboard->sourceOperation());
728 WebPoint dragScreenLocation(event->screenX(), event->screenY());
729 WebPoint dragLocation(event->absoluteLocation().x() - location().x(), event->absoluteLocation().y() - location().y());
731 m_webPlugin->handleDragStatusUpdate(dragStatus, dragData, dragOperationMask, dragLocation, dragScreenLocation);
734 void WebPluginContainerImpl::handleWheelEvent(WheelEvent* event)
736 WebMouseWheelEventBuilder webEvent(this, m_element->renderer(), *event);
737 if (webEvent.type == WebInputEvent::Undefined)
740 WebCursorInfo cursorInfo;
741 if (m_webPlugin->handleInputEvent(webEvent, cursorInfo))
742 event->setDefaultHandled();
745 void WebPluginContainerImpl::handleKeyboardEvent(KeyboardEvent* event)
747 WebKeyboardEventBuilder webEvent(*event);
748 if (webEvent.type == WebInputEvent::Undefined)
751 if (webEvent.type == WebInputEvent::KeyDown) {
753 if (webEvent.modifiers == WebInputEvent::MetaKey
755 if (webEvent.modifiers == WebInputEvent::ControlKey
757 && webEvent.windowsKeyCode == VKEY_C
758 // Only copy if there's a selection, so that we only ever do this
759 // for Pepper plugins that support copying. Windowless NPAPI
760 // plugins will get the event as before.
761 && m_webPlugin->hasSelection()) {
763 event->setDefaultHandled();
768 const WebInputEvent* currentInputEvent = WebViewImpl::currentInputEvent();
770 // Copy stashed info over, and only copy here in order not to interfere
771 // the ctrl-c logic above.
772 if (currentInputEvent
773 && WebInputEvent::isKeyboardEventType(currentInputEvent->type)) {
774 webEvent.modifiers |= currentInputEvent->modifiers &
775 (WebInputEvent::CapsLockOn | WebInputEvent::NumLockOn);
778 // Give the client a chance to issue edit comamnds.
779 WebViewImpl* view = WebViewImpl::fromPage(m_element->document().frame()->page());
780 if (m_webPlugin->supportsEditCommands() && view->client())
781 view->client()->handleCurrentKeyboardEvent();
783 WebCursorInfo cursorInfo;
784 if (m_webPlugin->handleInputEvent(webEvent, cursorInfo))
785 event->setDefaultHandled();
788 void WebPluginContainerImpl::handleTouchEvent(TouchEvent* event)
790 switch (m_touchEventRequestType) {
791 case TouchEventRequestTypeNone:
793 case TouchEventRequestTypeRaw: {
794 WebTouchEventBuilder webEvent(this, m_element->renderer(), *event);
795 if (webEvent.type == WebInputEvent::Undefined)
798 if (event->type() == EventTypeNames::touchstart)
801 WebCursorInfo cursorInfo;
802 if (m_webPlugin->handleInputEvent(webEvent, cursorInfo))
803 event->setDefaultHandled();
804 // FIXME: Can a plugin change the cursor from a touch-event callback?
807 case TouchEventRequestTypeSynthesizedMouse:
808 synthesizeMouseEventIfPossible(event);
813 static inline bool gestureScrollHelper(ScrollbarGroup* scrollbarGroup, ScrollDirection positiveDirection, ScrollDirection negativeDirection, float delta)
817 float absDelta = delta > 0 ? delta : -delta;
818 return scrollbarGroup->scroll(delta < 0 ? negativeDirection : positiveDirection, ScrollByPrecisePixel, absDelta);
821 void WebPluginContainerImpl::handleGestureEvent(GestureEvent* event)
823 WebGestureEventBuilder webEvent(this, m_element->renderer(), *event);
824 if (webEvent.type == WebInputEvent::Undefined)
826 WebCursorInfo cursorInfo;
827 if (m_webPlugin->handleInputEvent(webEvent, cursorInfo)) {
828 event->setDefaultHandled();
832 if (webEvent.type == WebInputEvent::GestureScrollUpdate || webEvent.type == WebInputEvent::GestureScrollUpdateWithoutPropagation) {
833 if (!m_scrollbarGroup)
835 if (gestureScrollHelper(m_scrollbarGroup.get(), ScrollLeft, ScrollRight, webEvent.data.scrollUpdate.deltaX))
836 event->setDefaultHandled();
837 if (gestureScrollHelper(m_scrollbarGroup.get(), ScrollUp, ScrollDown, webEvent.data.scrollUpdate.deltaY))
838 event->setDefaultHandled();
840 // FIXME: Can a plugin change the cursor from a touch-event callback?
843 void WebPluginContainerImpl::synthesizeMouseEventIfPossible(TouchEvent* event)
845 WebMouseEventBuilder webEvent(this, m_element->renderer(), *event);
846 if (webEvent.type == WebInputEvent::Undefined)
849 WebCursorInfo cursorInfo;
850 if (m_webPlugin->handleInputEvent(webEvent, cursorInfo))
851 event->setDefaultHandled();
854 void WebPluginContainerImpl::focusPlugin()
856 LocalFrame& containingFrame = toFrameView(parent())->frame();
857 if (Page* currentPage = containingFrame.page())
858 currentPage->focusController().setFocusedElement(m_element, &containingFrame);
860 containingFrame.document()->setFocusedElement(m_element);
863 void WebPluginContainerImpl::calculateGeometry(const IntRect& frameRect,
866 Vector<IntRect>& cutOutRects)
868 windowRect = toScrollView(parent())->contentsToWindow(frameRect);
870 // Calculate a clip-rect so that we don't overlap the scrollbars, etc.
871 clipRect = windowClipRect();
872 clipRect.move(-windowRect.x(), -windowRect.y());
874 getPluginOcclusions(m_element, this->parent(), frameRect, cutOutRects);
875 // Convert to the plugin position.
876 for (size_t i = 0; i < cutOutRects.size(); i++)
877 cutOutRects[i].move(-frameRect.x(), -frameRect.y());
880 WebCore::IntRect WebPluginContainerImpl::windowClipRect() const
882 // Start by clipping to our bounds.
884 convertToContainingWindow(IntRect(0, 0, width(), height()));
886 // document().renderer() can be 0 when we receive messages from the
887 // plugins while we are destroying a frame.
888 // FIXME: Can we just check m_element->document().isActive() ?
889 if (m_element->renderer()->document().renderer()) {
890 // Take our element and get the clip rect from the enclosing layer and
893 m_element->document().view()->windowClipRectForFrameOwner(m_element));
899 bool WebPluginContainerImpl::pluginShouldPersist() const
901 return m_webPlugin->shouldPersist();