void StGLScrollArea::stglResize() { StGLWidget* aContent = myChildren.getStart(); StGLContext& aCtx = getContext(); if(!isScrollable() && aContent != NULL && aContent->getRectPx().top() < 0 && aContent->getCorner().v == ST_VCORNER_TOP) { const int aDelta = -aContent->getRectPx().top(); aContent->changeRectPx().top() += aDelta; aContent->changeRectPx().bottom() += aDelta; } if(isScrollable() && aContent != NULL) { const int aSizeY = stMax(getRectPx().height(), 1); const int aContSizeY = aContent->getRectPx().height(); const double aScaleY = double(aSizeY) / double(aContSizeY); const int aScrollSizeY = stMax(int(aScaleY * (double )aSizeY), myRoot->scale(4)); const double aPosY = double(-aContent->getRectPx().top()) / double(aContSizeY - aSizeY); StArray<StGLVec2> aVertices(4); StRectI_t aRectPx = getRectPxAbsolute(); aRectPx.left() = aRectPx.right() - myRoot->scale(2); aRectPx.top() += int(aPosY * double(aSizeY - aScrollSizeY)); aRectPx.bottom() = aRectPx.top() + aScrollSizeY; myRoot->getRectGl(aRectPx, aVertices); myBarVertBuf.init(aCtx, aVertices); } else { myBarVertBuf.release(aCtx); } StGLWidget::stglResize(); }
void CoordinatedGraphicsLayer::setScrollableArea(ScrollableArea* scrollableArea) { bool oldScrollable = isScrollable(); m_scrollableArea = scrollableArea; if (oldScrollable == isScrollable()) return; m_layerState.isScrollable = isScrollable(); m_layerState.flagsChanged = true; didChangeLayerState(); }
void CoordinatedGraphicsLayer::syncLayerState() { if (!m_shouldSyncLayerState) return; m_shouldSyncLayerState = false; m_layerState.childrenTransform = childrenTransform(); m_layerState.contentsRect = contentsRect(); m_layerState.mask = toCoordinatedLayerID(maskLayer()); m_layerState.opacity = opacity(); m_layerState.replica = toCoordinatedLayerID(replicaLayer()); m_layerState.transform = transform(); m_layerState.anchorPoint = m_adjustedAnchorPoint; m_layerState.pos = m_adjustedPosition; m_layerState.size = m_adjustedSize; if (m_layerState.flagsChanged) { m_layerState.drawsContent = drawsContent(); m_layerState.contentsVisible = contentsAreVisible(); m_layerState.backfaceVisible = backfaceVisibility(); m_layerState.masksToBounds = masksToBounds(); m_layerState.preserves3D = preserves3D(); m_layerState.fixedToViewport = fixedToViewport(); m_layerState.showDebugBorders = isShowingDebugBorder(); m_layerState.showRepaintCounter = isShowingRepaintCounter(); m_layerState.isScrollable = isScrollable(); } if (m_layerState.showDebugBorders) updateDebugIndicators(); }
bool Slider::mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta) { switch (evt) { case Mouse::MOUSE_WHEEL: { if (hasFocus() && !isScrollable(_parent)) { float total = _max - _min; float value = _value + (total * SCROLLWHEEL_FRACTION) * wheelDelta; if (_step > 0.0f) { int numSteps = round(value / _step); value = _step * numSteps; } setValue(value); return true; } break; } default: break; } // Return false to fall through to touch handling return false; }
static bool isScrollable(Container* container) { if (container->getScroll() != Container::SCROLL_NONE) return true; Container* parent = static_cast<Container*>(container->getParent()); return parent ? isScrollable(parent) : false; }
void CoordinatedGraphicsLayer::commitScrollOffset(const IntSize& offset) { if (!isScrollable() || offset.isZero()) return; m_scrollableArea->notifyScrollPositionChanged(m_scrollableArea->scrollPosition() + offset); m_layerState.committedScrollOffset += offset; m_layerState.committedScrollOffsetChanged = true; didChangeLayerState(); }
void TextureMapperLayer::scrollBy(const FloatSize& offset) { if (!isScrollable() || !m_scrollClient || offset.isZero()) return; FloatSize scrollOffset = mapScrollOffset(offset); m_userScrollOffset += scrollOffset; m_currentTransform.setPosition(adjustedPosition()); commitScrollOffset(scrollOffset); }
void StGLScrollArea::stglUpdate(const StPointD_t& theCursorZo) { if(!isVisible()) { StGLWidget::stglUpdate(theCursorZo); return; } if(myIsLeftClick && isScrollable()) { StPointD_t aDelta = myRoot->getCursorZo() - myClickPntZo; double aDeltaY = aDelta.y() * myRoot->getRectPx().height(); myClickPntZo = myRoot->getCursorZo(); double aTime = myDragTimer.getElapsedTime(); if(myDragTimer.isOn()) { if(aTime > 0.1) { myFlingYSpeed = 0.0; myDragYDelta = 0.0; myDragTimer.restart(); } else if(aTime > 0.0000001 && std::abs(aDeltaY) >= double(myRoot->scale(2))) { if(std::abs(myDragYDelta) < 0.001 || haveSameSign(myDragYDelta, aDeltaY)) { myFlingYSpeed = (myDragYDelta + aDeltaY) / aTime; } myDragYDelta = 0.0; myDragTimer.restart(); } else { myDragYDelta += aDeltaY; } } else { myFlingYSpeed = 0.0; myDragYDelta = 0.0; myDragTimer.restart(); } doScroll((int )aDeltaY); } else if(myFlingTimer.isOn()) { double aTime = myFlingTimer.getElapsedTime(); double anA = (myFlingYSpeed > 0.0 ? -1.0 : 1.0) * myFlingAccel; int aFullDeltaY = int(myFlingYSpeed * aTime + anA * aTime * aTime); int aDeltaY = aFullDeltaY - myFlingYDone; if(aDeltaY == 0) { // ignore zero update } else if(!haveSameSign(myFlingYSpeed, aDeltaY)) { myFlingTimer.stop(); } else { myFlingYDone += aDeltaY; doScroll(aDeltaY, true); } } StGLWidget::stglUpdate(theCursorZo); }
bool StGLScrollArea::doScroll(const int theDelta, const bool theIsFling) { if(!theIsFling) { myDragYDelta = 0.0; myFlingTimer.stop(); } if(!isScrollable()) { return false; } StGLWidget* aContent = myChildren.getStart(); const int aMinLim = 0; const int aMaxLim = getRectPx().height() - aContent->getRectPx().height(); const int aTopOld = aContent->getRectPx().top(); const int aTopNew = stMax(stMin(aMinLim, aTopOld + theDelta), aMaxLim); const int aDelta = aTopNew - aTopOld; if(aDelta == 0) { if(theIsFling) { myFlingTimer.stop(); } return false; } aContent->changeRectPx().top() += aDelta; aContent->changeRectPx().bottom() += aDelta; if(myIsLeftClick) { if(!theIsFling) { myDragYCumul += aDelta; if(std::abs(myDragYCumul) > myRoot->getClickThreshold() && !myHasDragged) { setClickedWithChildren(myChildren, ST_MOUSE_LEFT, false); myHasDragged = true; } } else { myDragYCumul = 0; } } myIsResized = true; return true; }
bool StGLScrollArea::tryClick(const StClickEvent& theEvent, bool& theIsItemClicked) { if(!isVisibleAndPointIn(StPointD_t(theEvent.PointX, theEvent.PointY))) { return false; } if( theEvent.Button == ST_MOUSE_LEFT && !theIsItemClicked && isScrollable()) { myIsLeftClick = true; myHasDragged = false; myClickPntZo = StPointD_t(theEvent.PointX, theEvent.PointY); myDragYCumul = 0; // abort flinging if(myFlingTimer.isOn()) { const double aTime = myFlingTimer.getElapsedTime(); const double anA = (myFlingYSpeed > 0.0 ? -1.0 : 1.0) * myFlingAccel; const double aSpeed = myFlingYSpeed + anA * aTime; if(std::abs(aSpeed) > myRoot->scale(300)) { setClickedWithChildren(myChildren, ST_MOUSE_LEFT, false); theIsItemClicked = true; return true; } } } else { myIsLeftClick = false; myHasDragged = false; } if(StGLWidget::tryClick(theEvent, theIsItemClicked)) { theIsItemClicked = true; return true; } return false; }
void GraphicsLayerTextureMapper::commitLayerChanges() { if (m_changeMask == NoChanges) return; if (m_changeMask & ChildrenChange) { Vector<TextureMapperLayer*> textureMapperLayerChildren; toTextureMapperLayerVector(children(), textureMapperLayerChildren); m_layer->setChildren(textureMapperLayerChildren); } if (m_changeMask & MaskLayerChange) m_layer->setMaskLayer(toTextureMapperLayer(maskLayer())); if (m_changeMask & ReplicaLayerChange) m_layer->setReplicaLayer(toTextureMapperLayer(replicaLayer())); if (m_changeMask & PositionChange) m_layer->setPosition(position()); if (m_changeMask & AnchorPointChange) m_layer->setAnchorPoint(anchorPoint()); if (m_changeMask & SizeChange) m_layer->setSize(size()); if (m_changeMask & TransformChange) m_layer->setTransform(transform()); if (m_changeMask & ChildrenTransformChange) m_layer->setChildrenTransform(childrenTransform()); if (m_changeMask & Preserves3DChange) m_layer->setPreserves3D(preserves3D()); if (m_changeMask & ContentsRectChange) m_layer->setContentsRect(contentsRect()); if (m_changeMask & MasksToBoundsChange) m_layer->setMasksToBounds(masksToBounds()); if (m_changeMask & DrawsContentChange) m_layer->setDrawsContent(drawsContent()); if (m_changeMask & ContentsVisibleChange) m_layer->setContentsVisible(contentsAreVisible()); if (m_changeMask & ContentsOpaqueChange) m_layer->setContentsOpaque(contentsOpaque()); if (m_changeMask & BackfaceVisibilityChange) m_layer->setBackfaceVisibility(backfaceVisibility()); if (m_changeMask & OpacityChange) m_layer->setOpacity(opacity()); if (m_changeMask & BackgroundColorChange) m_layer->setSolidColor(solidColor()); #if ENABLE(CSS_FILTERS) if (m_changeMask & FilterChange) m_layer->setFilters(filters()); #endif if (m_changeMask & BackingStoreChange) m_layer->setBackingStore(m_backingStore); if (m_changeMask & DebugVisualsChange) m_layer->setDebugVisuals(isShowingDebugBorder(), debugBorderColor(), debugBorderWidth(), isShowingRepaintCounter()); if (m_changeMask & RepaintCountChange) m_layer->setRepaintCount(repaintCount()); if (m_changeMask & ContentChange) m_layer->setContentsLayer(platformLayer()); if (m_changeMask & AnimationChange) m_layer->setAnimations(m_animations); if (m_changeMask & AnimationStarted) client()->notifyAnimationStarted(this, m_animationStartTime); if (m_changeMask & FixedToViewporChange) m_layer->setFixedToViewport(fixedToViewport()); if (m_changeMask & IsScrollableChange) m_layer->setIsScrollable(isScrollable()); if (m_changeMask & CommittedScrollOffsetChange) m_layer->didCommitScrollOffset(m_committedScrollOffset); m_changeMask = NoChanges; }