This source file includes following definitions.
- create
- m_widget
- willCloseLayerTreeView
- initialize
- handleMouseMove
- handleMouseLeave
- handleMouseDown
- handleMouseUp
- handleMouseWheel
- handleGestureEvent
- handleTouchEvent
- handleKeyEvent
- close
- willStartLiveResize
- resize
- willEndLiveResize
- animate
- layout
- enterForceCompositingMode
- didExitCompositingMode
- paintContents
- paint
- themeChanged
- handleInputEvent
- mouseCaptureLost
- setFocus
- setComposition
- confirmComposition
- confirmComposition
- confirmComposition
- compositionRange
- caretOrSelectionRange
- setTextDirection
- invalidateContentsAndRootView
- invalidateContentsForSlowScroll
- scheduleAnimation
- scroll
- rootViewToScreen
- screenInfo
- popupClosed
#include "config.h"
#include "WebPopupMenuImpl.h"
#include "PopupContainer.h"
#include "PopupMenuChromium.h"
#include "WebInputEvent.h"
#include "WebInputEventConversion.h"
#include "WebRange.h"
#include "WebViewClient.h"
#include "WebWidgetClient.h"
#include "core/frame/FrameView.h"
#include "platform/Cursor.h"
#include "platform/NotImplemented.h"
#include "platform/PlatformGestureEvent.h"
#include "platform/PlatformKeyboardEvent.h"
#include "platform/PlatformMouseEvent.h"
#include "platform/PlatformWheelEvent.h"
#include "platform/geometry/IntRect.h"
#include "platform/graphics/GraphicsContext.h"
#include "platform/graphics/skia/SkiaUtils.h"
#include "platform/scroll/FramelessScrollView.h"
#include "public/platform/Platform.h"
#include "public/platform/WebCompositorSupport.h"
#include "public/platform/WebContentLayer.h"
#include "public/platform/WebFloatRect.h"
#include "public/platform/WebLayerTreeView.h"
#include "public/platform/WebRect.h"
#include <skia/ext/platform_canvas.h>
using namespace WebCore;
namespace blink {
WebPopupMenu* WebPopupMenu::create(WebWidgetClient* client)
{
return adoptRef(new WebPopupMenuImpl(client)).leakRef();
}
WebPopupMenuImpl::WebPopupMenuImpl(WebWidgetClient* client)
: m_client(client)
, m_layerTreeView(0)
, m_isAcceleratedCompositingActive(false)
, m_lastMousePosition(WebPoint(-1, -1))
, m_widget(0)
{
}
WebPopupMenuImpl::~WebPopupMenuImpl()
{
if (m_widget)
m_widget->setClient(0);
}
void WebPopupMenuImpl::willCloseLayerTreeView()
{
enterForceCompositingMode(false);
m_layerTreeView = 0;
}
void WebPopupMenuImpl::initialize(FramelessScrollView* widget, const WebRect& bounds)
{
m_widget = widget;
m_widget->setClient(this);
if (m_client) {
m_client->setWindowRect(bounds);
m_client->show(WebNavigationPolicy());
}
}
void WebPopupMenuImpl::handleMouseMove(const WebMouseEvent& event)
{
if (event.x != m_lastMousePosition.x || event.y != m_lastMousePosition.y) {
m_lastMousePosition = WebPoint(event.x, event.y);
m_widget->handleMouseMoveEvent(PlatformMouseEventBuilder(m_widget, event));
PopupContainer* container = static_cast<PopupContainer*>(m_widget);
client()->setToolTipText(container->getSelectedItemToolTip(), container->menuStyle().textDirection() == WebCore::RTL ? WebTextDirectionRightToLeft : WebTextDirectionLeftToRight);
}
}
void WebPopupMenuImpl::handleMouseLeave(const WebMouseEvent& event)
{
m_widget->handleMouseMoveEvent(PlatformMouseEventBuilder(m_widget, event));
}
void WebPopupMenuImpl::handleMouseDown(const WebMouseEvent& event)
{
m_widget->handleMouseDownEvent(PlatformMouseEventBuilder(m_widget, event));
}
void WebPopupMenuImpl::handleMouseUp(const WebMouseEvent& event)
{
mouseCaptureLost();
m_widget->handleMouseReleaseEvent(PlatformMouseEventBuilder(m_widget, event));
}
void WebPopupMenuImpl::handleMouseWheel(const WebMouseWheelEvent& event)
{
m_widget->handleWheelEvent(PlatformWheelEventBuilder(m_widget, event));
}
bool WebPopupMenuImpl::handleGestureEvent(const WebGestureEvent& event)
{
return m_widget->handleGestureEvent(PlatformGestureEventBuilder(m_widget, event));
}
bool WebPopupMenuImpl::handleTouchEvent(const WebTouchEvent& event)
{
PlatformTouchEventBuilder touchEventBuilder(m_widget, event);
bool defaultPrevented(m_widget->handleTouchEvent(touchEventBuilder));
return defaultPrevented;
}
bool WebPopupMenuImpl::handleKeyEvent(const WebKeyboardEvent& event)
{
return m_widget->handleKeyEvent(PlatformKeyboardEventBuilder(event));
}
void WebPopupMenuImpl::close()
{
if (m_widget)
m_widget->hide();
m_client = 0;
deref();
}
void WebPopupMenuImpl::willStartLiveResize()
{
}
void WebPopupMenuImpl::resize(const WebSize& newSize)
{
if (m_size == newSize)
return;
m_size = newSize;
if (m_widget) {
IntRect newGeometry(0, 0, m_size.width, m_size.height);
m_widget->setFrameRect(newGeometry);
}
if (m_client) {
WebRect damagedRect(0, 0, m_size.width, m_size.height);
m_client->didInvalidateRect(damagedRect);
}
if (m_rootLayer)
m_rootLayer->layer()->setBounds(newSize);
}
void WebPopupMenuImpl::willEndLiveResize()
{
}
void WebPopupMenuImpl::animate(double)
{
}
void WebPopupMenuImpl::layout()
{
}
void WebPopupMenuImpl::enterForceCompositingMode(bool enter)
{
if (m_isAcceleratedCompositingActive == enter)
return;
if (!enter) {
m_isAcceleratedCompositingActive = false;
m_client->didDeactivateCompositor();
} else if (m_layerTreeView) {
m_isAcceleratedCompositingActive = true;
m_client->didActivateCompositor();
} else {
TRACE_EVENT0("webkit", "WebPopupMenuImpl::enterForceCompositingMode(true)");
m_client->initializeLayerTreeView();
m_layerTreeView = m_client->layerTreeView();
if (m_layerTreeView) {
m_layerTreeView->setVisible(true);
m_client->didActivateCompositor();
m_isAcceleratedCompositingActive = true;
m_layerTreeView->setDeviceScaleFactor(m_client->deviceScaleFactor());
m_rootLayer = adoptPtr(Platform::current()->compositorSupport()->createContentLayer(this));
m_rootLayer->layer()->setBounds(m_size);
m_layerTreeView->setRootLayer(*m_rootLayer->layer());
} else {
m_isAcceleratedCompositingActive = false;
m_client->didDeactivateCompositor();
}
}
}
void WebPopupMenuImpl::didExitCompositingMode()
{
enterForceCompositingMode(false);
m_client->didInvalidateRect(IntRect(0, 0, m_size.width, m_size.height));
}
void WebPopupMenuImpl::paintContents(WebCanvas* canvas, const WebRect& rect, bool, WebFloatRect&)
{
if (!m_widget)
return;
if (!rect.isEmpty()) {
GraphicsContext context(canvas);
m_widget->paint(&context, rect);
}
}
void WebPopupMenuImpl::paint(WebCanvas* canvas, const WebRect& rect, PaintOptions)
{
if (!m_widget)
return;
if (!rect.isEmpty()) {
GraphicsContext context(canvas);
context.applyDeviceScaleFactor(m_client->deviceScaleFactor());
m_widget->paint(&context, rect);
}
}
void WebPopupMenuImpl::themeChanged()
{
notImplemented();
}
bool WebPopupMenuImpl::handleInputEvent(const WebInputEvent& inputEvent)
{
if (!m_widget)
return false;
switch (inputEvent.type) {
case WebInputEvent::MouseMove:
handleMouseMove(*static_cast<const WebMouseEvent*>(&inputEvent));
return true;
case WebInputEvent::MouseLeave:
handleMouseLeave(*static_cast<const WebMouseEvent*>(&inputEvent));
return true;
case WebInputEvent::MouseWheel:
handleMouseWheel(*static_cast<const WebMouseWheelEvent*>(&inputEvent));
return true;
case WebInputEvent::MouseDown:
handleMouseDown(*static_cast<const WebMouseEvent*>(&inputEvent));
return true;
case WebInputEvent::MouseUp:
handleMouseUp(*static_cast<const WebMouseEvent*>(&inputEvent));
return true;
case WebInputEvent::RawKeyDown:
case WebInputEvent::KeyDown:
case WebInputEvent::KeyUp:
case WebInputEvent::Char:
return handleKeyEvent(*static_cast<const WebKeyboardEvent*>(&inputEvent));
case WebInputEvent::TouchStart:
case WebInputEvent::TouchMove:
case WebInputEvent::TouchEnd:
case WebInputEvent::TouchCancel:
return handleTouchEvent(*static_cast<const WebTouchEvent*>(&inputEvent));
case WebInputEvent::GestureScrollBegin:
case WebInputEvent::GestureScrollEnd:
case WebInputEvent::GestureScrollUpdate:
case WebInputEvent::GestureScrollUpdateWithoutPropagation:
case WebInputEvent::GestureFlingStart:
case WebInputEvent::GestureFlingCancel:
case WebInputEvent::GestureTap:
case WebInputEvent::GestureTapUnconfirmed:
case WebInputEvent::GestureTapDown:
case WebInputEvent::GestureShowPress:
case WebInputEvent::GestureTapCancel:
case WebInputEvent::GestureDoubleTap:
case WebInputEvent::GestureTwoFingerTap:
case WebInputEvent::GestureLongPress:
case WebInputEvent::GestureLongTap:
case WebInputEvent::GesturePinchBegin:
case WebInputEvent::GesturePinchEnd:
case WebInputEvent::GesturePinchUpdate:
return handleGestureEvent(*static_cast<const WebGestureEvent*>(&inputEvent));
case WebInputEvent::Undefined:
case WebInputEvent::MouseEnter:
case WebInputEvent::ContextMenu:
return false;
}
return false;
}
void WebPopupMenuImpl::mouseCaptureLost()
{
}
void WebPopupMenuImpl::setFocus(bool)
{
}
bool WebPopupMenuImpl::setComposition(const WebString&, const WebVector<WebCompositionUnderline>&, int, int)
{
return false;
}
bool WebPopupMenuImpl::confirmComposition()
{
return false;
}
bool WebPopupMenuImpl::confirmComposition(ConfirmCompositionBehavior)
{
return false;
}
bool WebPopupMenuImpl::confirmComposition(const WebString&)
{
return false;
}
bool WebPopupMenuImpl::compositionRange(size_t* location, size_t* length)
{
*location = 0;
*length = 0;
return false;
}
bool WebPopupMenuImpl::caretOrSelectionRange(size_t* location, size_t* length)
{
*location = 0;
*length = 0;
return false;
}
void WebPopupMenuImpl::setTextDirection(WebTextDirection)
{
}
void WebPopupMenuImpl::invalidateContentsAndRootView(const IntRect& paintRect)
{
if (paintRect.isEmpty())
return;
if (m_client)
m_client->didInvalidateRect(paintRect);
if (m_rootLayer)
m_rootLayer->layer()->invalidateRect(FloatRect(paintRect));
}
void WebPopupMenuImpl::invalidateContentsForSlowScroll(const IntRect& updateRect)
{
invalidateContentsAndRootView(updateRect);
}
void WebPopupMenuImpl::scheduleAnimation()
{
}
void WebPopupMenuImpl::scroll(const IntSize& scrollDelta, const IntRect& scrollRect, const IntRect& clipRect)
{
if (m_client) {
int dx = scrollDelta.width();
int dy = scrollDelta.height();
m_client->didScrollRect(dx, dy, clipRect);
}
if (m_rootLayer)
m_rootLayer->layer()->invalidateRect(FloatRect(clipRect));
}
IntRect WebPopupMenuImpl::rootViewToScreen(const IntRect& rect) const
{
notImplemented();
return IntRect();
}
WebScreenInfo WebPopupMenuImpl::screenInfo() const
{
return WebScreenInfo();
}
void WebPopupMenuImpl::popupClosed(FramelessScrollView* widget)
{
ASSERT(widget == m_widget);
if (m_widget) {
m_widget->setClient(0);
m_widget = 0;
}
if (m_client)
m_client->closeWidgetSoon();
}
}