Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.88 KB | None | 0 0
  1. commit 6ae1b00e347bb0becf7e3e8c419d4a80de16788a
  2. Author: Kenneth Rohde Christiansen <kenneth.christiansen@gmail.com>
  3. Date: Wed Feb 23 16:14:10 2011 +0100
  4.  
  5. Rename the bounded scale methods. Make the methods equal when no scaling is allowed
  6.  
  7. Reviewed by Zalan Bujtas.
  8.  
  9. diff --git a/src/WebViewState.cpp b/src/WebViewState.cpp
  10. index b675830..7e93da1 100644
  11. --- a/src/WebViewState.cpp
  12. +++ b/src/WebViewState.cpp
  13. @@ -63,17 +63,19 @@ bool WebViewState::isUserScalable() const
  14. return m_isUserScalable || m_minimumScale != m_maximumScale;
  15. }
  16.  
  17. -qreal WebViewState::softlyBoundedScale(qreal value) const
  18. +qreal WebViewState::innerBoundedScale(qreal value) const
  19. {
  20. return qBound(m_minimumScale, value, m_maximumScale);
  21. }
  22.  
  23. -qreal WebViewState::boundedScale(qreal value) const
  24. +qreal WebViewState::outerBoundedScale(qreal value) const
  25. {
  26. - qreal hardMin = qreal(0.5) * m_minimumScale;
  27. - qreal hardMax = qreal(2.0) * m_maximumScale;
  28. -
  29. - return bindToScaleLimits(qBound(hardMin, value, hardMax));
  30. + if (isUserScalable()) {
  31. + qreal hardMin = qreal(0.5) * m_minimumScale;
  32. + qreal hardMax = qreal(2.0) * m_maximumScale;
  33. + return bindToScaleLimits(qBound(hardMin, value, hardMax));
  34. + }
  35. + return innerBoundedScale(value);
  36. }
  37.  
  38. void WebViewState::setInitialScale(qreal value)
  39. diff --git a/src/WebViewState.h b/src/WebViewState.h
  40. index bc92f9c..3d0d960 100644
  41. --- a/src/WebViewState.h
  42. +++ b/src/WebViewState.h
  43. @@ -27,8 +27,8 @@ public:
  44. qreal pixelRatio() const { return m_pixelRatio; }
  45. bool isUserScalable() const;
  46.  
  47. - qreal softlyBoundedScale(qreal scale) const;
  48. - qreal boundedScale(qreal value) const;
  49. + qreal innerBoundedScale(qreal scale) const;
  50. + qreal outerBoundedScale(qreal value) const;
  51.  
  52. private:
  53. qreal m_initialScale;
  54. @@ -41,6 +41,4 @@ private:
  55. };
  56. Q_DECLARE_METATYPE(WebViewState);
  57.  
  58. -
  59. -
  60. #endif
  61. diff --git a/src/WebViewport.cpp b/src/WebViewport.cpp
  62. index fbbbb61..27bd75e 100644
  63. --- a/src/WebViewport.cpp
  64. +++ b/src/WebViewport.cpp
  65. @@ -286,11 +286,9 @@ void WebViewport::zoomAndFocusWidthChange(qreal dw)
  66.  
  67. // We need to recalc the viewport before using boundedScale.
  68. updateItemStateFromViewportMeta();
  69. - qreal newScale = dw * scale;
  70. - if (viewportItem()->state().isUserScalable())
  71. - newScale = viewportItem()->state().boundedScale(newScale);
  72. - else
  73. - newScale = viewportItem()->state().softlyBoundedScale(newScale);
  74. +
  75. + // FIXME: Why isn't inner used?
  76. + qreal newScale = viewportItem()->state().outerBoundedScale(dw * scale);
  77.  
  78. QPointF newPosition = position() * (newScale / scale);
  79.  
  80. @@ -313,7 +311,7 @@ void WebViewport::zoomAndFocusInputField()
  81. // current MeeGo Touch API's it is impossible to know before the
  82. // VKB has animated fully in. This does it for now.
  83. QPointF viewportCenter = QPointF(25, geometry().height() / 5);
  84. - qreal targetScale = viewportItem()->state().softlyBoundedScale(2.0);
  85. + qreal targetScale = viewportItem()->state().innerBoundedScale(2.0);
  86. QPointF position = positionAtTarget(hotspot, viewportCenter, targetScale);
  87.  
  88. startZoomAnimation(position, targetScale);
  89. @@ -334,7 +332,7 @@ void WebViewport::zoomToArea(const QPointF& requestedZoomPoint, const QRectF& ta
  90. int margin = 8;
  91. QRectF contentsArea = targetZoomableArea.adjusted(-margin, -margin, margin, margin);
  92.  
  93. - qreal targetScale = viewportItem()->state().softlyBoundedScale(size().width() / (contentsArea.size().width()));
  94. + qreal targetScale = viewportItem()->state().innerBoundedScale(size().width() / (contentsArea.size().width()));
  95. // We want to end up with the targetArea filling the whole width of the viewport,
  96. // and centralized vertically where the user requested zoom. Thus our hotspot
  97. // is the center of the targetArea x-wise and the requested zoom position, y-wise.
  98. @@ -345,7 +343,7 @@ void WebViewport::zoomToArea(const QPointF& requestedZoomPoint, const QRectF& ta
  99. if (isSameZoomScale(targetScale)) {
  100. // If we are requested to zoom to a similar scale.
  101. targetScale = size().width() / viewportItem()->size().width();
  102. - targetScale = viewportItem()->state().softlyBoundedScale(targetScale);
  103. + targetScale = viewportItem()->state().innerBoundedScale(targetScale);
  104. hotspot.setX(viewportItem()->size().width() / 2);
  105. hotspot.setY(requestedZoomPoint.y());
  106. }
  107. @@ -472,7 +470,7 @@ void WebViewport::endZoomScaleChange()
  108. bool WebViewport::bounceBackToViewIfNeeded()
  109. {
  110. qreal currentScale = viewportItem()->appliedZoomScale();
  111. - qreal boundedCurrentScale = viewportItem()->state().softlyBoundedScale(currentScale);
  112. + qreal boundedCurrentScale = viewportItem()->state().innerBoundedScale(currentScale);
  113.  
  114. // Bounce back and center contents point in viewport center.
  115. if (boundedCurrentScale != currentScale) {
  116. @@ -545,10 +543,7 @@ void WebViewport::updatePinchZoom(qreal scaleFactor, const QPointF& newCenterPoi
  117. qreal scale = m_pinchStartScale * scaleFactor;
  118.  
  119. // Allow zooming out beyond mimimum scale on pages that do not explicit disallow it.
  120. - if (!viewportItem()->state().isUserScalable())
  121. - scale = viewportItem()->state().softlyBoundedScale(scale);
  122. - else
  123. - scale = viewportItem()->state().boundedScale(scale);
  124. + scale = viewportItem()->state().outerBoundedScale(scale);
  125.  
  126. QPointF targetPosition = positionAtTarget(m_pinchUnscaledHotspot, m_pinchViewportHotspot, scale, /* keepContentsInView */ false) + (m_pinchViewportHotspot - newCenterPoint);
  127.  
  128. @@ -592,7 +587,7 @@ bool WebViewport::processZoomKeys(QKeyEvent* event)
  129. else
  130. scale /= 1.0 + s_zoomScaleWheelStep;
  131.  
  132. - scale = viewportItem()->state().softlyBoundedScale(scale);
  133. + scale = viewportItem()->state().innerBoundedScale(scale);
  134.  
  135. // Zoom to the center.
  136. QPointF viewportHotspot = visibleCenter();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement