Skip to content

Commit

Permalink
2011-05-29 Andreas Kling <kling@webkit.org>
Browse files Browse the repository at this point in the history
        Reviewed by Kenneth Rohde Christiansen.

        Element: Micro-cleanup of scroll methods.
        https://bugs.webkit.org/show_bug.cgi?id=61705

        Do an early return without calculating element boundaries when asked
        to scroll an element without a renderer().

        * dom/Element.cpp:
        (WebCore::Element::scrollIntoView):
        (WebCore::Element::scrollIntoViewIfNeeded):
        (WebCore::Element::scrollByUnits):


Canonical link: https://commits.webkit.org/77146@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@87645 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Andreas Kling committed May 29, 2011
1 parent cda835e commit 6e9551b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 22 deletions.
15 changes: 15 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,18 @@
2011-05-29 Andreas Kling <kling@webkit.org>

Reviewed by Kenneth Rohde Christiansen.

Element: Micro-cleanup of scroll methods.
https://bugs.webkit.org/show_bug.cgi?id=61705

Do an early return without calculating element boundaries when asked
to scroll an element without a renderer().

* dom/Element.cpp:
(WebCore::Element::scrollIntoView):
(WebCore::Element::scrollIntoViewIfNeeded):
(WebCore::Element::scrollByUnits):

2011-05-29 Darin Adler <darin@apple.com>

Reviewed by Dan Bernstein.
Expand Down
51 changes: 29 additions & 22 deletions Source/WebCore/dom/Element.cpp
Expand Up @@ -275,41 +275,48 @@ const AtomicString& Element::getAttribute(const QualifiedName& name) const
void Element::scrollIntoView(bool alignToTop)
{
document()->updateLayoutIgnorePendingStylesheets();

if (!renderer())
return;

IntRect bounds = getRect();
if (renderer()) {
// Align to the top / bottom and to the closest edge.
if (alignToTop)
renderer()->enclosingLayer()->scrollRectToVisible(bounds, false, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignTopAlways);
else
renderer()->enclosingLayer()->scrollRectToVisible(bounds, false, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignBottomAlways);
}
// Align to the top / bottom and to the closest edge.
if (alignToTop)
renderer()->enclosingLayer()->scrollRectToVisible(bounds, false, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignTopAlways);
else
renderer()->enclosingLayer()->scrollRectToVisible(bounds, false, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignBottomAlways);
}

void Element::scrollIntoViewIfNeeded(bool centerIfNeeded)
{
document()->updateLayoutIgnorePendingStylesheets();

if (!renderer())
return;

IntRect bounds = getRect();
if (renderer()) {
if (centerIfNeeded)
renderer()->enclosingLayer()->scrollRectToVisible(bounds, false, ScrollAlignment::alignCenterIfNeeded, ScrollAlignment::alignCenterIfNeeded);
else
renderer()->enclosingLayer()->scrollRectToVisible(bounds, false, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignToEdgeIfNeeded);
}
if (centerIfNeeded)
renderer()->enclosingLayer()->scrollRectToVisible(bounds, false, ScrollAlignment::alignCenterIfNeeded, ScrollAlignment::alignCenterIfNeeded);
else
renderer()->enclosingLayer()->scrollRectToVisible(bounds, false, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignToEdgeIfNeeded);
}

void Element::scrollByUnits(int units, ScrollGranularity granularity)
{
document()->updateLayoutIgnorePendingStylesheets();
if (RenderObject *rend = renderer()) {
if (rend->hasOverflowClip()) {
ScrollDirection direction = ScrollDown;
if (units < 0) {
direction = ScrollUp;
units = -units;
}
toRenderBox(rend)->layer()->scroll(direction, granularity, units);
}

if (!renderer())
return;

if (!renderer()->hasOverflowClip())
return;

ScrollDirection direction = ScrollDown;
if (units < 0) {
direction = ScrollUp;
units = -units;
}
toRenderBox(renderer())->layer()->scroll(direction, granularity, units);
}

void Element::scrollByLines(int lines)
Expand Down

0 comments on commit 6e9551b

Please sign in to comment.