⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 194410 in webkit


Ignore:
Timestamp:
Dec 23, 2015, 7:43:23 PM (11 years ago)
Author:
Simon Fraser
Message:

Use "constrainedBetween" in more places
https://bugs.webkit.org/show_bug.cgi?id=152543

Reviewed by Zalan Bujtas.

Replace code that contrains points via shrunkTo/expandedTo() with calls
to constrainedBetween(), and implement constrainedBetween() on IntPoint,
FloatPoint and LayoutPoint.

Convert some functions that return points to more modern syntax.

Source/WebCore:

  • page/scrolling/ScrollingTreeFrameScrollingNode.cpp:

(WebCore::ScrollingTreeFrameScrollingNode::setScrollPosition):

  • page/scrolling/ScrollingTreeScrollingNode.cpp:

(WebCore::ScrollingTreeScrollingNode::setScrollPosition):

  • platform/ScrollView.cpp:

(WebCore::ScrollView::adjustScrollPositionWithinRange):

  • platform/graphics/FloatPoint.cpp:

(WebCore::FloatPoint::constrainedBetween):

  • platform/graphics/FloatPoint.h:

(WebCore::FloatPoint::shrunkTo):
(WebCore::FloatPoint::expandedTo):
(WebCore::FloatPoint::transposedPoint):

  • platform/graphics/IntPoint.cpp:
  • platform/graphics/LayoutPoint.cpp:

(WebCore::LayoutPoint::constrainedBetween):

  • platform/graphics/LayoutPoint.h:

(WebCore::LayoutPoint::expandedTo):
(WebCore::LayoutPoint::shrunkTo):
(WebCore::LayoutPoint::transposedPoint):
(WebCore::LayoutPoint::fraction):
(WebCore::LayoutPoint::operator FloatPoint):

Source/WebKit2:

  • UIProcess/API/Cocoa/WKWebView.mm:

(constrainContentOffset):

Location:
trunk/Source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r194405 r194410  
     12015-12-23  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Use "constrainedBetween" in more places
     4        https://bugs.webkit.org/show_bug.cgi?id=152543
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Replace code that contrains points via shrunkTo/expandedTo() with calls
     9        to constrainedBetween(), and implement constrainedBetween() on IntPoint,
     10        FloatPoint and LayoutPoint.
     11
     12        Convert some functions that return points to more modern syntax.
     13
     14        * page/scrolling/ScrollingTreeFrameScrollingNode.cpp:
     15        (WebCore::ScrollingTreeFrameScrollingNode::setScrollPosition):
     16        * page/scrolling/ScrollingTreeScrollingNode.cpp:
     17        (WebCore::ScrollingTreeScrollingNode::setScrollPosition):
     18        * platform/ScrollView.cpp:
     19        (WebCore::ScrollView::adjustScrollPositionWithinRange):
     20        * platform/graphics/FloatPoint.cpp:
     21        (WebCore::FloatPoint::constrainedBetween):
     22        * platform/graphics/FloatPoint.h:
     23        (WebCore::FloatPoint::shrunkTo):
     24        (WebCore::FloatPoint::expandedTo):
     25        (WebCore::FloatPoint::transposedPoint):
     26        * platform/graphics/IntPoint.cpp:
     27        * platform/graphics/LayoutPoint.cpp:
     28        (WebCore::LayoutPoint::constrainedBetween):
     29        * platform/graphics/LayoutPoint.h:
     30        (WebCore::LayoutPoint::expandedTo):
     31        (WebCore::LayoutPoint::shrunkTo):
     32        (WebCore::LayoutPoint::transposedPoint):
     33        (WebCore::LayoutPoint::fraction):
     34        (WebCore::LayoutPoint::operator FloatPoint):
     35
    1362015-12-23  Simon Fraser  <simon.fraser@apple.com>
    237
  • trunk/Source/WebCore/page/scrolling/ScrollingTreeFrameScrollingNode.cpp

    r194004 r194410  
    8383void ScrollingTreeFrameScrollingNode::setScrollPosition(const FloatPoint& scrollPosition)
    8484{
    85     FloatPoint newScrollPosition = scrollPosition;
    86     newScrollPosition = newScrollPosition.shrunkTo(maximumScrollPosition());
    87     newScrollPosition = newScrollPosition.expandedTo(minimumScrollPosition());
    88 
     85    FloatPoint newScrollPosition = scrollPosition.constrainedBetween(minimumScrollPosition(), maximumScrollPosition());
    8986    setScrollPositionWithoutContentEdgeConstraints(newScrollPosition);
    9087}
  • trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.cpp

    r185762 r194410  
    104104void ScrollingTreeScrollingNode::setScrollPosition(const FloatPoint& scrollPosition)
    105105{
    106     FloatPoint newScrollPosition = scrollPosition;
    107     newScrollPosition = newScrollPosition.shrunkTo(maximumScrollPosition());
    108     newScrollPosition = newScrollPosition.expandedTo(minimumScrollPosition());
    109 
     106    FloatPoint newScrollPosition = scrollPosition.constrainedBetween(minimumScrollPosition(), maximumScrollPosition());
    110107    setScrollPositionWithoutContentEdgeConstraints(newScrollPosition);
    111108}
  • trunk/Source/WebCore/platform/ScrollView.cpp

    r194405 r194410  
    404404        return scrollPoint;
    405405
    406     IntPoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPosition());
    407     newScrollPosition = newScrollPosition.expandedTo(minimumScrollPosition());
    408     return newScrollPosition;
     406    return scrollPoint.constrainedBetween(minimumScrollPosition(), maximumScrollPosition());
    409407}
    410408
  • trunk/Source/WebCore/platform/graphics/FloatPoint.cpp

    r191216 r194410  
    4040FloatPoint::FloatPoint(const IntPoint& p) : m_x(p.x()), m_y(p.y())
    4141{
     42}
     43
     44FloatPoint FloatPoint::constrainedBetween(const FloatPoint& min, const FloatPoint& max) const
     45{
     46    return {
     47        std::max(min.x(), std::min(max.x(), m_x)),
     48        std::max(min.y(), std::min(max.y(), m_y))
     49    };
    4250}
    4351
  • trunk/Source/WebCore/platform/graphics/FloatPoint.h

    r191216 r194410  
    122122    }
    123123
     124    WEBCORE_EXPORT FloatPoint constrainedBetween(const FloatPoint& min, const FloatPoint& max) const;
     125
    124126    FloatPoint shrunkTo(const FloatPoint& other) const
    125127    {
    126         return FloatPoint(std::min(m_x, other.m_x), std::min(m_y, other.m_y));
     128        return { std::min(m_x, other.m_x), std::min(m_y, other.m_y) };
    127129    }
    128130
    129131    FloatPoint expandedTo(const FloatPoint& other) const
    130132    {
    131         return FloatPoint(std::max(m_x, other.m_x), std::max(m_y, other.m_y));
     133        return { std::max(m_x, other.m_x), std::max(m_y, other.m_y) };
    132134    }
    133135
    134136    FloatPoint transposedPoint() const
    135137    {
    136         return FloatPoint(m_y, m_x);
     138        return { m_y, m_x };
    137139    }
    138140
  • trunk/Source/WebCore/platform/graphics/IntPoint.cpp

    r194405 r194410  
    4646}
    4747
    48 
    4948TextStream& operator<<(TextStream& ts, const IntPoint& p)
    5049{
  • trunk/Source/WebCore/platform/graphics/LayoutPoint.cpp

    r191216 r194410  
    3131namespace WebCore {
    3232
     33LayoutPoint LayoutPoint::constrainedBetween(const LayoutPoint& min, const LayoutPoint& max) const
     34{
     35    return {
     36        std::max(min.x(), std::min(max.x(), m_x)),
     37        std::max(min.y(), std::min(max.y(), m_y))
     38    };
     39}
     40
    3341TextStream& operator<<(TextStream& ts, const LayoutPoint& p)
    3442{
  • trunk/Source/WebCore/platform/graphics/LayoutPoint.h

    r191216 r194410  
    6161        m_y *= sy;
    6262    }
    63    
     63
     64    LayoutPoint constrainedBetween(const LayoutPoint& min, const LayoutPoint& max) const;
     65
    6466    LayoutPoint expandedTo(const LayoutPoint& other) const
    6567    {
    66         return LayoutPoint(std::max(m_x, other.m_x), std::max(m_y, other.m_y));
     68        return { std::max(m_x, other.m_x), std::max(m_y, other.m_y) };
    6769    }
    6870
    6971    LayoutPoint shrunkTo(const LayoutPoint& other) const
    7072    {
    71         return LayoutPoint(std::min(m_x, other.m_x), std::min(m_y, other.m_y));
     73        return { std::min(m_x, other.m_x), std::min(m_y, other.m_y) };
    7274    }
    7375
     
    7981    LayoutPoint transposedPoint() const
    8082    {
    81         return LayoutPoint(m_y, m_x);
     83        return { m_y, m_x };
    8284    }
    8385
    8486    LayoutPoint fraction() const
    8587    {
    86         return LayoutPoint(m_x.fraction(), m_y.fraction());
    87     }
    88 
    89     operator FloatPoint() const { return FloatPoint(m_x, m_y); }
     88        return { m_x.fraction(), m_y.fraction() };
     89    }
     90
     91    operator FloatPoint() const { return { m_x, m_y }; }
    9092
    9193private:
  • trunk/Source/WebKit2/ChangeLog

    r194384 r194410  
     12015-12-23  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Use "constrainedBetween" in more places
     4        https://bugs.webkit.org/show_bug.cgi?id=152543
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Replace code that contrains points via shrunkTo/expandedTo() with calls
     9        to constrainedBetween(), and implement constrainedBetween() on IntPoint,
     10        FloatPoint and LayoutPoint.
     11
     12        Convert some functions that return points to more modern syntax.
     13
     14        * UIProcess/API/Cocoa/WKWebView.mm:
     15        (constrainContentOffset):
     16
    1172015-12-22  Hunseop Jeong  <hs85.jeong@samsung.com>
    218
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r194318 r194410  
    12601260{
    12611261    WebCore::FloatSize maximumContentOffset = contentSize - unobscuredContentSize;
    1262     contentOffset = contentOffset.shrunkTo(WebCore::FloatPoint(maximumContentOffset.width(), maximumContentOffset.height()));
    1263     contentOffset = contentOffset.expandedTo(WebCore::FloatPoint());
    1264     return contentOffset;
     1262    return contentOffset.constrainedBetween(WebCore::FloatPoint(), WebCore::FloatPoint(maximumContentOffset));
    12651263}
    12661264
Note: See TracChangeset for help on using the changeset viewer.