Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: Source/core/rendering/ScrollBehavior.cpp

Issue 132043002: Rename WebCore::ScrollBehavior to ScrollAlignmentBehavior (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase and fix another #inlcude Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/ScrollBehavior.h ('k') | Source/web/TextFinder.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 *
4 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
5 *
6 * Other contributors:
7 * Robert O'Callahan <roc+@cs.cmu.edu>
8 * David Baron <dbaron@fas.harvard.edu>
9 * Christian Biesinger <cbiesinger@web.de>
10 * Randall Jesup <rjesup@wgate.com>
11 * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
12 * Josh Soref <timeless@mac.com>
13 * Boris Zbarsky <bzbarsky@mit.edu>
14 *
15 * This library is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 US A
28 *
29 * Alternatively, the contents of this file may be used under the terms
30 * of either the Mozilla Public License Version 1.1, found at
31 * http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
32 * License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
33 * (the "GPL"), in which case the provisions of the MPL or the GPL are
34 * applicable instead of those above. If you wish to allow use of your
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
37 * version of this file under the LGPL, indicate your decision by
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.
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.
42 */
43
44 #include "config.h"
45 #include "core/rendering/ScrollBehavior.h"
46
47 #include "platform/geometry/LayoutRect.h"
48
49 namespace WebCore {
50
51 const ScrollAlignment ScrollAlignment::alignCenterIfNeeded = { noScroll, alignCe nter, alignToClosestEdge };
52 const ScrollAlignment ScrollAlignment::alignToEdgeIfNeeded = { noScroll, alignTo ClosestEdge, alignToClosestEdge };
53 const ScrollAlignment ScrollAlignment::alignCenterAlways = { alignCenter, alignC enter, alignCenter };
54 const ScrollAlignment ScrollAlignment::alignTopAlways = { alignTop, alignTop, al ignTop };
55 const ScrollAlignment ScrollAlignment::alignBottomAlways = { alignBottom, alignB ottom, alignBottom };
56
57 #define MIN_INTERSECT_FOR_REVEAL 32
58
59 LayoutRect ScrollAlignment::getRectToExpose(const LayoutRect& visibleRect, const LayoutRect& exposeRect, const ScrollAlignment& alignX, const ScrollAlignment& a lignY)
60 {
61 // Determine the appropriate X behavior.
62 ScrollBehavior scrollX;
63 LayoutRect exposeRectX(exposeRect.x(), visibleRect.y(), exposeRect.width(), visibleRect.height());
64 LayoutUnit intersectWidth = intersection(visibleRect, exposeRectX).width();
65 if (intersectWidth == exposeRect.width() || intersectWidth >= MIN_INTERSECT_ FOR_REVEAL) {
66 // If the rectangle is fully visible, use the specified visible behavior .
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
69 scrollX = getVisibleBehavior(alignX);
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.
72 scrollX = getVisibleBehavior(alignX);
73 if (scrollX == alignCenter)
74 scrollX = noScroll;
75 } else if (intersectWidth > 0) {
76 // If the rectangle is partially visible, but not above the minimum thre shold, use the specified partial behavior
77 scrollX = getPartialBehavior(alignX);
78 } else {
79 scrollX = getHiddenBehavior(alignX);
80 }
81
82 if (scrollX == alignToClosestEdge) {
83 // Closest edge is the right in two cases:
84 // (1) exposeRect to the right of and smaller than visibleRect
85 // (2) exposeRect to the left of and larger than visibleRect
86 if ((exposeRect.maxX() > visibleRect.maxX() && exposeRect.width() < visi bleRect.width())
87 || (exposeRect.maxX() < visibleRect.maxX() && exposeRect.width() > v isibleRect.width())) {
88 scrollX = alignRight;
89 }
90 }
91
92 // Given the X behavior, compute the X coordinate.
93 LayoutUnit x;
94 if (scrollX == noScroll)
95 x = visibleRect.x();
96 else if (scrollX == alignRight)
97 x = exposeRect.maxX() - visibleRect.width();
98 else if (scrollX == alignCenter)
99 x = exposeRect.x() + (exposeRect.width() - visibleRect.width()) / 2;
100 else
101 x = exposeRect.x();
102
103 // Determine the appropriate Y behavior.
104 ScrollBehavior scrollY;
105 LayoutRect exposeRectY(visibleRect.x(), exposeRect.y(), visibleRect.width(), exposeRect.height());
106 LayoutUnit intersectHeight = intersection(visibleRect, exposeRectY).height() ;
107 if (intersectHeight == exposeRect.height()) {
108 // If the rectangle is fully visible, use the specified visible behavior .
109 scrollY = getVisibleBehavior(alignY);
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.
112 scrollY = getVisibleBehavior(alignY);
113 if (scrollY == alignCenter)
114 scrollY = noScroll;
115 } else if (intersectHeight > 0) {
116 // If the rectangle is partially visible, use the specified partial beha vior
117 scrollY = getPartialBehavior(alignY);
118 } else {
119 scrollY = getHiddenBehavior(alignY);
120 }
121
122 if (scrollY == alignToClosestEdge) {
123 // Closest edge is the bottom in two cases:
124 // (1) exposeRect below and smaller than visibleRect
125 // (2) exposeRect above and larger than visibleRect
126 if ((exposeRect.maxY() > visibleRect.maxY() && exposeRect.height() < vis ibleRect.height())
127 || (exposeRect.maxY() < visibleRect.maxY() && exposeRect.height() > visibleRect.height())) {
128 scrollY = alignBottom;
129 }
130 }
131
132 // Given the Y behavior, compute the Y coordinate.
133 LayoutUnit y;
134 if (scrollY == noScroll)
135 y = visibleRect.y();
136 else if (scrollY == alignBottom)
137 y = exposeRect.maxY() - visibleRect.height();
138 else if (scrollY == alignCenter)
139 y = exposeRect.y() + (exposeRect.height() - visibleRect.height()) / 2;
140 else
141 y = exposeRect.y();
142
143 return LayoutRect(LayoutPoint(x, y), visibleRect.size());
144 }
145
146 }; // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/ScrollBehavior.h ('k') | Source/web/TextFinder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698