ScrollView* Widget::root() const { const Widget* top = this; while (top->parent()) top = top->parent(); if (top->isFrameView()) return const_cast<ScrollView*>(toScrollView(top)); return nullptr; }
static IntSize widgetInputEventsOffset(const Widget* widget) { if (!widget) return IntSize(); ScrollView* rootView = toScrollView(widget->root()); if (!rootView) return IntSize(); return rootView->inputEventsOffsetForEmulation(); }
static float widgetInputEventsScaleFactor(const Widget* widget) { if (!widget) return 1; ScrollView* rootView = toScrollView(widget->root()); if (!rootView) return 1; return rootView->inputEventsScaleFactor(); }
static void moveWidgetToParentSoon(Widget* child, FrameView* parent) { if (!s_updateSuspendCount) { if (parent) parent->addChild(child); else toScrollView(child->parent())->removeChild(child); return; } widgetNewParentMap().set(child, parent); }
static void updateWebMouseEventFromWebCoreMouseEvent(const MouseRelatedEvent& event, const Widget& widget, const WebCore::RenderObject& renderObject, WebMouseEvent& webEvent) { webEvent.timeStampSeconds = event.timeStamp() / millisPerSecond; webEvent.modifiers = getWebInputModifiers(event); ScrollView* view = toScrollView(widget.parent()); IntPoint windowPoint = IntPoint(event.absoluteLocation().x(), event.absoluteLocation().y()); if (view) windowPoint = view->contentsToWindow(windowPoint); webEvent.globalX = event.screenX(); webEvent.globalY = event.screenY(); webEvent.windowX = windowPoint.x(); webEvent.windowY = windowPoint.y(); IntPoint localPoint = convertAbsoluteLocationForRenderObject(event.absoluteLocation(), renderObject); webEvent.x = localPoint.x(); webEvent.y = localPoint.y(); }
// Generate a synthetic WebMouseEvent given a TouchEvent (eg. for emulating a mouse // with touch input for plugins that don't support touch input). WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, const WebCore::RenderObject* renderObject, const TouchEvent& event) { if (!event.touches()) return; if (event.touches()->length() != 1) { if (event.touches()->length() || event.type() != EventTypeNames::touchend || !event.changedTouches() || event.changedTouches()->length() != 1) return; } const Touch* touch = event.touches()->length() == 1 ? event.touches()->item(0) : event.changedTouches()->item(0); if (touch->identifier()) return; if (event.type() == EventTypeNames::touchstart) type = MouseDown; else if (event.type() == EventTypeNames::touchmove) type = MouseMove; else if (event.type() == EventTypeNames::touchend) type = MouseUp; else return; timeStampSeconds = event.timeStamp() / millisPerSecond; modifiers = getWebInputModifiers(event); // The mouse event co-ordinates should be generated from the co-ordinates of the touch point. ScrollView* view = toScrollView(widget->parent()); IntPoint windowPoint = IntPoint(touch->absoluteLocation().x(), touch->absoluteLocation().y()); if (view) windowPoint = view->contentsToWindow(windowPoint); globalX = touch->screenX(); globalY = touch->screenY(); windowX = windowPoint.x(); windowY = windowPoint.y(); button = WebMouseEvent::ButtonLeft; modifiers |= WebInputEvent::LeftButtonDown; clickCount = (type == MouseDown || type == MouseUp); IntPoint localPoint = convertAbsoluteLocationForRenderObject(touch->absoluteLocation(), *renderObject); x = localPoint.x(); y = localPoint.y(); }
RenderWidget::UpdateSuspendScope::~UpdateSuspendScope() { ASSERT(s_updateSuspendCount > 0); if (s_updateSuspendCount == 1) { WidgetToParentMap map; widgetNewParentMap().swap(map); WidgetToParentMap::iterator end = map.end(); for (WidgetToParentMap::iterator it = map.begin(); it != end; ++it) { Widget* child = it->key.get(); ScrollView* currentParent = toScrollView(child->parent()); FrameView* newParent = it->value; if (newParent != currentParent) { if (currentParent) currentParent->removeChild(child); if (newParent) newParent->addChild(child); } } } --s_updateSuspendCount; }
void Scrollbar::removeFromParent() { if (parent()) toScrollView(parent())->removeChild(this); }
bool Scrollbar::isScrollViewScrollbar() const { return parent() && parent()->isFrameView() && toScrollView(parent())->isScrollViewScrollbar(this); }
ScrollView* Scrollbar::rootScrollView() const { return toScrollView(root()); }
ScrollView* Scrollbar::parentScrollView() const { return toScrollView(parent()); }