Modified: trunk/Source/WebCore/ChangeLog (87644 => 87645)
--- trunk/Source/WebCore/ChangeLog 2011-05-29 20:12:27 UTC (rev 87644)
+++ trunk/Source/WebCore/ChangeLog 2011-05-29 20:45:10 UTC (rev 87645)
@@ -1,3 +1,18 @@
+2011-05-29 Andreas Kling <[email protected]>
+
+ 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 <[email protected]>
Reviewed by Dan Bernstein.
Modified: trunk/Source/WebCore/dom/Element.cpp (87644 => 87645)
--- trunk/Source/WebCore/dom/Element.cpp 2011-05-29 20:12:27 UTC (rev 87644)
+++ trunk/Source/WebCore/dom/Element.cpp 2011-05-29 20:45:10 UTC (rev 87645)
@@ -275,41 +275,48 @@
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)