OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Portions are Copyright (C) 1998 Netscape Communications Corporation. | 4 * Portions are Copyright (C) 1998 Netscape Communications Corporation. |
5 * | 5 * |
6 * Other contributors: | 6 * Other contributors: |
7 * Robert O'Callahan <roc+@cs.cmu.edu> | 7 * Robert O'Callahan <roc+@cs.cmu.edu> |
8 * David Baron <dbaron@fas.harvard.edu> | 8 * David Baron <dbaron@fas.harvard.edu> |
9 * Christian Biesinger <cbiesinger@web.de> | 9 * Christian Biesinger <cbiesinger@web.de> |
10 * Randall Jesup <rjesup@wgate.com> | 10 * Randall Jesup <rjesup@wgate.com> |
(...skipping 24 matching lines...) Expand all Loading... |
35 * version of this file only under the terms of one of those two | 35 * version of this file only under the terms of one of those two |
36 * licenses (the MPL or the GPL) and not to allow others to use your | 36 * licenses (the MPL or the GPL) and not to allow others to use your |
37 * version of this file under the LGPL, indicate your decision by | 37 * version of this file under the LGPL, indicate your decision by |
38 * deletingthe provisions above and replace them with the notice and | 38 * deletingthe provisions above and replace them with the notice and |
39 * other provisions required by the MPL or the GPL, as the case may be. | 39 * other provisions required by the MPL or the GPL, as the case may be. |
40 * If you do not delete the provisions above, a recipient may use your | 40 * If you do not delete the provisions above, a recipient may use your |
41 * version of this file under any of the LGPL, the MPL or the GPL. | 41 * version of this file under any of the LGPL, the MPL or the GPL. |
42 */ | 42 */ |
43 | 43 |
44 #include "config.h" | 44 #include "config.h" |
45 #include "core/rendering/ScrollBehavior.h" | 45 #include "core/rendering/ScrollAlignment.h" |
46 | 46 |
47 #include "platform/geometry/LayoutRect.h" | 47 #include "platform/geometry/LayoutRect.h" |
48 | 48 |
49 namespace WebCore { | 49 namespace WebCore { |
50 | 50 |
51 const ScrollAlignment ScrollAlignment::alignCenterIfNeeded = { noScroll, alignCe
nter, alignToClosestEdge }; | 51 const ScrollAlignment ScrollAlignment::alignCenterIfNeeded = { ScrollAlignmentNo
Scroll, ScrollAlignmentCenter, ScrollAlignmentClosestEdge }; |
52 const ScrollAlignment ScrollAlignment::alignToEdgeIfNeeded = { noScroll, alignTo
ClosestEdge, alignToClosestEdge }; | 52 const ScrollAlignment ScrollAlignment::alignToEdgeIfNeeded = { ScrollAlignmentNo
Scroll, ScrollAlignmentClosestEdge, ScrollAlignmentClosestEdge }; |
53 const ScrollAlignment ScrollAlignment::alignCenterAlways = { alignCenter, alignC
enter, alignCenter }; | 53 const ScrollAlignment ScrollAlignment::alignCenterAlways = { ScrollAlignmentCent
er, ScrollAlignmentCenter, ScrollAlignmentCenter }; |
54 const ScrollAlignment ScrollAlignment::alignTopAlways = { alignTop, alignTop, al
ignTop }; | 54 const ScrollAlignment ScrollAlignment::alignTopAlways = { ScrollAlignmentTop, Sc
rollAlignmentTop, ScrollAlignmentTop }; |
55 const ScrollAlignment ScrollAlignment::alignBottomAlways = { alignBottom, alignB
ottom, alignBottom }; | 55 const ScrollAlignment ScrollAlignment::alignBottomAlways = { ScrollAlignmentBott
om, ScrollAlignmentBottom, ScrollAlignmentBottom }; |
56 | 56 |
57 #define MIN_INTERSECT_FOR_REVEAL 32 | 57 #define MIN_INTERSECT_FOR_REVEAL 32 |
58 | 58 |
59 LayoutRect ScrollAlignment::getRectToExpose(const LayoutRect& visibleRect, const
LayoutRect& exposeRect, const ScrollAlignment& alignX, const ScrollAlignment& a
lignY) | 59 LayoutRect ScrollAlignment::getRectToExpose(const LayoutRect& visibleRect, const
LayoutRect& exposeRect, const ScrollAlignment& alignX, const ScrollAlignment& a
lignY) |
60 { | 60 { |
61 // Determine the appropriate X behavior. | 61 // Determine the appropriate X behavior. |
62 ScrollBehavior scrollX; | 62 ScrollAlignmentBehavior scrollX; |
63 LayoutRect exposeRectX(exposeRect.x(), visibleRect.y(), exposeRect.width(),
visibleRect.height()); | 63 LayoutRect exposeRectX(exposeRect.x(), visibleRect.y(), exposeRect.width(),
visibleRect.height()); |
64 LayoutUnit intersectWidth = intersection(visibleRect, exposeRectX).width(); | 64 LayoutUnit intersectWidth = intersection(visibleRect, exposeRectX).width(); |
65 if (intersectWidth == exposeRect.width() || intersectWidth >= MIN_INTERSECT_
FOR_REVEAL) { | 65 if (intersectWidth == exposeRect.width() || intersectWidth >= MIN_INTERSECT_
FOR_REVEAL) { |
66 // If the rectangle is fully visible, use the specified visible behavior
. | 66 // If the rectangle is fully visible, use the specified visible behavior
. |
67 // If the rectangle is partially visible, but over a certain threshold, | 67 // If the rectangle is partially visible, but over a certain threshold, |
68 // then treat it as fully visible to avoid unnecessary horizontal scroll
ing | 68 // then treat it as fully visible to avoid unnecessary horizontal scroll
ing |
69 scrollX = getVisibleBehavior(alignX); | 69 scrollX = getVisibleBehavior(alignX); |
70 } else if (intersectWidth == visibleRect.width()) { | 70 } else if (intersectWidth == visibleRect.width()) { |
71 // If the rect is bigger than the visible area, don't bother trying to c
enter. Other alignments will work. | 71 // If the rect is bigger than the visible area, don't bother trying to c
enter. Other alignments will work. |
72 scrollX = getVisibleBehavior(alignX); | 72 scrollX = getVisibleBehavior(alignX); |
73 if (scrollX == alignCenter) | 73 if (scrollX == ScrollAlignmentCenter) |
74 scrollX = noScroll; | 74 scrollX = ScrollAlignmentNoScroll; |
75 } else if (intersectWidth > 0) { | 75 } else if (intersectWidth > 0) { |
76 // If the rectangle is partially visible, but not above the minimum thre
shold, use the specified partial behavior | 76 // If the rectangle is partially visible, but not above the minimum thre
shold, use the specified partial behavior |
77 scrollX = getPartialBehavior(alignX); | 77 scrollX = getPartialBehavior(alignX); |
78 } else { | 78 } else { |
79 scrollX = getHiddenBehavior(alignX); | 79 scrollX = getHiddenBehavior(alignX); |
80 } | 80 } |
81 | 81 |
82 if (scrollX == alignToClosestEdge) { | 82 if (scrollX == ScrollAlignmentClosestEdge) { |
83 // Closest edge is the right in two cases: | 83 // Closest edge is the right in two cases: |
84 // (1) exposeRect to the right of and smaller than visibleRect | 84 // (1) exposeRect to the right of and smaller than visibleRect |
85 // (2) exposeRect to the left of and larger than visibleRect | 85 // (2) exposeRect to the left of and larger than visibleRect |
86 if ((exposeRect.maxX() > visibleRect.maxX() && exposeRect.width() < visi
bleRect.width()) | 86 if ((exposeRect.maxX() > visibleRect.maxX() && exposeRect.width() < visi
bleRect.width()) |
87 || (exposeRect.maxX() < visibleRect.maxX() && exposeRect.width() > v
isibleRect.width())) { | 87 || (exposeRect.maxX() < visibleRect.maxX() && exposeRect.width() > v
isibleRect.width())) { |
88 scrollX = alignRight; | 88 scrollX = ScrollAlignmentRight; |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 // Given the X behavior, compute the X coordinate. | 92 // Given the X behavior, compute the X coordinate. |
93 LayoutUnit x; | 93 LayoutUnit x; |
94 if (scrollX == noScroll) | 94 if (scrollX == ScrollAlignmentNoScroll) |
95 x = visibleRect.x(); | 95 x = visibleRect.x(); |
96 else if (scrollX == alignRight) | 96 else if (scrollX == ScrollAlignmentRight) |
97 x = exposeRect.maxX() - visibleRect.width(); | 97 x = exposeRect.maxX() - visibleRect.width(); |
98 else if (scrollX == alignCenter) | 98 else if (scrollX == ScrollAlignmentCenter) |
99 x = exposeRect.x() + (exposeRect.width() - visibleRect.width()) / 2; | 99 x = exposeRect.x() + (exposeRect.width() - visibleRect.width()) / 2; |
100 else | 100 else |
101 x = exposeRect.x(); | 101 x = exposeRect.x(); |
102 | 102 |
103 // Determine the appropriate Y behavior. | 103 // Determine the appropriate Y behavior. |
104 ScrollBehavior scrollY; | 104 ScrollAlignmentBehavior scrollY; |
105 LayoutRect exposeRectY(visibleRect.x(), exposeRect.y(), visibleRect.width(),
exposeRect.height()); | 105 LayoutRect exposeRectY(visibleRect.x(), exposeRect.y(), visibleRect.width(),
exposeRect.height()); |
106 LayoutUnit intersectHeight = intersection(visibleRect, exposeRectY).height()
; | 106 LayoutUnit intersectHeight = intersection(visibleRect, exposeRectY).height()
; |
107 if (intersectHeight == exposeRect.height()) { | 107 if (intersectHeight == exposeRect.height()) { |
108 // If the rectangle is fully visible, use the specified visible behavior
. | 108 // If the rectangle is fully visible, use the specified visible behavior
. |
109 scrollY = getVisibleBehavior(alignY); | 109 scrollY = getVisibleBehavior(alignY); |
110 } else if (intersectHeight == visibleRect.height()) { | 110 } else if (intersectHeight == visibleRect.height()) { |
111 // If the rect is bigger than the visible area, don't bother trying to c
enter. Other alignments will work. | 111 // If the rect is bigger than the visible area, don't bother trying to c
enter. Other alignments will work. |
112 scrollY = getVisibleBehavior(alignY); | 112 scrollY = getVisibleBehavior(alignY); |
113 if (scrollY == alignCenter) | 113 if (scrollY == ScrollAlignmentCenter) |
114 scrollY = noScroll; | 114 scrollY = ScrollAlignmentNoScroll; |
115 } else if (intersectHeight > 0) { | 115 } else if (intersectHeight > 0) { |
116 // If the rectangle is partially visible, use the specified partial beha
vior | 116 // If the rectangle is partially visible, use the specified partial beha
vior |
117 scrollY = getPartialBehavior(alignY); | 117 scrollY = getPartialBehavior(alignY); |
118 } else { | 118 } else { |
119 scrollY = getHiddenBehavior(alignY); | 119 scrollY = getHiddenBehavior(alignY); |
120 } | 120 } |
121 | 121 |
122 if (scrollY == alignToClosestEdge) { | 122 if (scrollY == ScrollAlignmentClosestEdge) { |
123 // Closest edge is the bottom in two cases: | 123 // Closest edge is the bottom in two cases: |
124 // (1) exposeRect below and smaller than visibleRect | 124 // (1) exposeRect below and smaller than visibleRect |
125 // (2) exposeRect above and larger than visibleRect | 125 // (2) exposeRect above and larger than visibleRect |
126 if ((exposeRect.maxY() > visibleRect.maxY() && exposeRect.height() < vis
ibleRect.height()) | 126 if ((exposeRect.maxY() > visibleRect.maxY() && exposeRect.height() < vis
ibleRect.height()) |
127 || (exposeRect.maxY() < visibleRect.maxY() && exposeRect.height() >
visibleRect.height())) { | 127 || (exposeRect.maxY() < visibleRect.maxY() && exposeRect.height() >
visibleRect.height())) { |
128 scrollY = alignBottom; | 128 scrollY = ScrollAlignmentBottom; |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 // Given the Y behavior, compute the Y coordinate. | 132 // Given the Y behavior, compute the Y coordinate. |
133 LayoutUnit y; | 133 LayoutUnit y; |
134 if (scrollY == noScroll) | 134 if (scrollY == ScrollAlignmentNoScroll) |
135 y = visibleRect.y(); | 135 y = visibleRect.y(); |
136 else if (scrollY == alignBottom) | 136 else if (scrollY == ScrollAlignmentBottom) |
137 y = exposeRect.maxY() - visibleRect.height(); | 137 y = exposeRect.maxY() - visibleRect.height(); |
138 else if (scrollY == alignCenter) | 138 else if (scrollY == ScrollAlignmentCenter) |
139 y = exposeRect.y() + (exposeRect.height() - visibleRect.height()) / 2; | 139 y = exposeRect.y() + (exposeRect.height() - visibleRect.height()) / 2; |
140 else | 140 else |
141 y = exposeRect.y(); | 141 y = exposeRect.y(); |
142 | 142 |
143 return LayoutRect(LayoutPoint(x, y), visibleRect.size()); | 143 return LayoutRect(LayoutPoint(x, y), visibleRect.size()); |
144 } | 144 } |
145 | 145 |
146 }; // namespace WebCore | 146 }; // namespace WebCore |
OLD | NEW |