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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBox.cpp

Issue 2383113003: Refactor ScrollableArea::setScrollPosition. (Closed)
Patch Set: Created 4 years, 2 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 7 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 if (isOrthogonalWritingModeRoot()) 249 if (isOrthogonalWritingModeRoot())
250 markOrthogonalWritingModeRoot(); 250 markOrthogonalWritingModeRoot();
251 else 251 else
252 unmarkOrthogonalWritingModeRoot(); 252 unmarkOrthogonalWritingModeRoot();
253 } 253 }
254 254
255 clearPercentHeightDescendants(); 255 clearPercentHeightDescendants();
256 } 256 }
257 257
258 // If our zoom factor changes and we have a defined scrollLeft/Top, we need to adjust that value into the 258 // If our zoom factor changes and we have a defined scrollLeft/Top, we need to adjust that value into the
259 // new zoomed coordinate space. 259 // new zoomed coordinate space. Note that the new scroll position may be outs ide the normal min/max
260 // range of the scrollable area, which is weird but OK, because the scrollable area will update its
261 // min/max in updateAfterLayout().
260 if (hasOverflowClip() && oldStyle && 262 if (hasOverflowClip() && oldStyle &&
261 oldStyle->effectiveZoom() != newStyle.effectiveZoom()) { 263 oldStyle->effectiveZoom() != newStyle.effectiveZoom()) {
262 PaintLayerScrollableArea* scrollableArea = this->getScrollableArea(); 264 PaintLayerScrollableArea* scrollableArea = this->getScrollableArea();
263 ASSERT(scrollableArea); 265 ASSERT(scrollableArea);
264 if (int left = scrollableArea->scrollXOffset()) { 266 // We use scrollPosition() rather than offsetFromOrigin(), because scrollPos ition is the distance
265 left = (left / oldStyle->effectiveZoom()) * newStyle.effectiveZoom(); 267 // from the beginning of flow for the box, which is the dimension we want to preserve.
266 scrollableArea->scrollToXOffset(left); 268 DoublePoint oldPosition = scrollableArea->scrollPositionDouble();
267 } 269 if (oldPosition.x() || oldPosition.y()) {
268 if (int top = scrollableArea->scrollYOffset()) { 270 DoublePoint newPosition = oldPosition.scaledBy(newStyle.effectiveZoom() /
269 top = (top / oldStyle->effectiveZoom()) * newStyle.effectiveZoom(); 271 oldStyle->effectiveZoom());
270 scrollableArea->scrollToYOffset(top); 272 scrollableArea->setScrollPositionUnconditionally(newPosition);
271 } 273 }
272 } 274 }
273 275
274 // Our opaqueness might have changed without triggering layout. 276 // Our opaqueness might have changed without triggering layout.
275 if (diff.needsPaintInvalidation()) { 277 if (diff.needsPaintInvalidation()) {
276 LayoutObject* parentToInvalidate = parent(); 278 LayoutObject* parentToInvalidate = parent();
277 for (unsigned i = 0; 279 for (unsigned i = 0;
278 i < backgroundObscurationTestMaxDepth && parentToInvalidate; ++i) { 280 i < backgroundObscurationTestMaxDepth && parentToInvalidate; ++i) {
279 parentToInvalidate->invalidateBackgroundObscurationStatus(); 281 parentToInvalidate->invalidateBackgroundObscurationStatus();
280 parentToInvalidate = parentToInvalidate->parent(); 282 parentToInvalidate = parentToInvalidate->parent();
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 507
506 LayoutUnit LayoutBox::scrollHeight() const { 508 LayoutUnit LayoutBox::scrollHeight() const {
507 if (hasOverflowClip()) 509 if (hasOverflowClip())
508 return getScrollableArea()->scrollHeight(); 510 return getScrollableArea()->scrollHeight();
509 // For objects with visible overflow, this matches IE. 511 // For objects with visible overflow, this matches IE.
510 // FIXME: Need to work right with writing modes. 512 // FIXME: Need to work right with writing modes.
511 return std::max(clientHeight(), layoutOverflowRect().maxY() - borderTop()); 513 return std::max(clientHeight(), layoutOverflowRect().maxY() - borderTop());
512 } 514 }
513 515
514 LayoutUnit LayoutBox::scrollLeft() const { 516 LayoutUnit LayoutBox::scrollLeft() const {
515 return hasOverflowClip() ? LayoutUnit(getScrollableArea()->scrollXOffset()) 517 return hasOverflowClip()
516 : LayoutUnit(); 518 ? LayoutUnit(getScrollableArea()->offsetFromOrigin().width())
519 : LayoutUnit();
517 } 520 }
518 521
519 LayoutUnit LayoutBox::scrollTop() const { 522 LayoutUnit LayoutBox::scrollTop() const {
520 return hasOverflowClip() ? LayoutUnit(getScrollableArea()->scrollYOffset()) 523 return hasOverflowClip()
521 : LayoutUnit(); 524 ? LayoutUnit(getScrollableArea()->offsetFromOrigin().height())
525 : LayoutUnit();
522 } 526 }
523 527
524 int LayoutBox::pixelSnappedScrollWidth() const { 528 int LayoutBox::pixelSnappedScrollWidth() const {
525 return snapSizeToPixel(scrollWidth(), location().x() + clientLeft()); 529 return snapSizeToPixel(scrollWidth(), location().x() + clientLeft());
526 } 530 }
527 531
528 int LayoutBox::pixelSnappedScrollHeight() const { 532 int LayoutBox::pixelSnappedScrollHeight() const {
529 if (hasOverflowClip()) 533 if (hasOverflowClip())
530 return snapSizeToPixel(getScrollableArea()->scrollHeight(), 534 return snapSizeToPixel(getScrollableArea()->scrollHeight(),
531 location().y() + clientTop()); 535 location().y() + clientTop());
532 // For objects with visible overflow, this matches IE. 536 // For objects with visible overflow, this matches IE.
533 // FIXME: Need to work right with writing modes. 537 // FIXME: Need to work right with writing modes.
534 return snapSizeToPixel(scrollHeight(), location().y() + clientTop()); 538 return snapSizeToPixel(scrollHeight(), location().y() + clientTop());
535 } 539 }
536 540
537 void LayoutBox::setScrollLeft(LayoutUnit newLeft) { 541 void LayoutBox::setScrollLeft(LayoutUnit newLeft) {
538 // This doesn't hit in any tests, but since the equivalent code in setScrollTo p 542 // This doesn't hit in any tests, but since the equivalent code in setScrollTo p
539 // does, presumably this code does as well. 543 // does, presumably this code does as well.
540 DisableCompositingQueryAsserts disabler; 544 DisableCompositingQueryAsserts disabler;
541 545
542 if (hasOverflowClip()) 546 if (!hasOverflowClip())
543 getScrollableArea()->scrollToXOffset(newLeft, ScrollOffsetClamped, 547 return;
544 ScrollBehaviorAuto); 548
549 PaintLayerScrollableArea* scrollableArea = getScrollableArea();
550 DoubleSize newOffset(newLeft, scrollableArea->offsetFromOrigin().height());
551 scrollableArea->scrollToOffsetFromOrigin(newOffset, ScrollBehaviorAuto);
545 } 552 }
546 553
547 void LayoutBox::setScrollTop(LayoutUnit newTop) { 554 void LayoutBox::setScrollTop(LayoutUnit newTop) {
548 // Hits in compositing/overflow/do-not-assert-on-invisible-composited-layers.h tml 555 // Hits in compositing/overflow/do-not-assert-on-invisible-composited-layers.h tml
549 DisableCompositingQueryAsserts disabler; 556 DisableCompositingQueryAsserts disabler;
550 557
551 if (hasOverflowClip()) 558 if (!hasOverflowClip())
552 getScrollableArea()->scrollToYOffset(newTop, ScrollOffsetClamped, 559 return;
553 ScrollBehaviorAuto); 560
561 PaintLayerScrollableArea* scrollableArea = getScrollableArea();
562 DoubleSize newOffset(scrollableArea->offsetFromOrigin().width(), newTop);
563 scrollableArea->scrollToOffsetFromOrigin(newOffset, ScrollBehaviorAuto);
554 } 564 }
555 565
556 void LayoutBox::scrollToOffset(const DoubleSize& offset, 566 void LayoutBox::scrollToOffset(const DoubleSize& offset,
557 ScrollBehavior scrollBehavior) { 567 ScrollBehavior scrollBehavior) {
558 // This doesn't hit in any tests, but since the equivalent code in setScrollTo p 568 // This doesn't hit in any tests, but since the equivalent code in setScrollTo p
559 // does, presumably this code does as well. 569 // does, presumably this code does as well.
560 DisableCompositingQueryAsserts disabler; 570 DisableCompositingQueryAsserts disabler;
561 571
562 if (hasOverflowClip()) 572 if (!hasOverflowClip())
563 getScrollableArea()->scrollToOffset(offset, ScrollOffsetClamped, 573 return;
564 scrollBehavior); 574
575 getScrollableArea()->scrollToOffsetFromOrigin(offset, scrollBehavior);
565 } 576 }
566 577
567 // Returns true iff we are attempting an autoscroll inside an iframe with scroll ing="no". 578 // Returns true iff we are attempting an autoscroll inside an iframe with scroll ing="no".
568 static bool isDisallowedAutoscroll(HTMLFrameOwnerElement* ownerElement, 579 static bool isDisallowedAutoscroll(HTMLFrameOwnerElement* ownerElement,
569 FrameView* frameView) { 580 FrameView* frameView) {
570 if (ownerElement && isHTMLFrameElementBase(*ownerElement)) { 581 if (ownerElement && isHTMLFrameElementBase(*ownerElement)) {
571 HTMLFrameElementBase* frameElementBase = 582 HTMLFrameElementBase* frameElementBase =
572 toHTMLFrameElementBase(ownerElement); 583 toHTMLFrameElementBase(ownerElement);
573 if (Page* page = frameView->frame().page()) { 584 if (Page* page = frameView->frame().page()) {
574 return page->autoscrollController().autoscrollInProgress() && 585 return page->autoscrollController().autoscrollInProgress() &&
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 if (abs(delta.width()) <= 1080 if (abs(delta.width()) <=
1070 AutoscrollController:: 1081 AutoscrollController::
1071 noMiddleClickAutoscrollRadius) // at the center we let the space for the icon 1082 noMiddleClickAutoscrollRadius) // at the center we let the space for the icon
1072 delta.setWidth(0); 1083 delta.setWidth(0);
1073 if (abs(delta.height()) <= 1084 if (abs(delta.height()) <=
1074 AutoscrollController::noMiddleClickAutoscrollRadius) 1085 AutoscrollController::noMiddleClickAutoscrollRadius)
1075 delta.setHeight(0); 1086 delta.setHeight(0);
1076 scroll(ScrollByPixel, FloatSize(adjustedScrollDelta(delta))); 1087 scroll(ScrollByPixel, FloatSize(adjustedScrollDelta(delta)));
1077 } 1088 }
1078 1089
1079 void LayoutBox::scrollByRecursively(const DoubleSize& delta, 1090 void LayoutBox::scrollByRecursively(const DoubleSize& delta) {
1080 ScrollOffsetClamping clamp) {
1081 if (delta.isZero()) 1091 if (delta.isZero())
1082 return; 1092 return;
1083 1093
1084 bool restrictedByLineClamp = false; 1094 bool restrictedByLineClamp = false;
1085 if (parent()) 1095 if (parent())
1086 restrictedByLineClamp = !parent()->style()->lineClamp().isNone(); 1096 restrictedByLineClamp = !parent()->style()->lineClamp().isNone();
1087 1097
1088 if (hasOverflowClip() && !restrictedByLineClamp) { 1098 if (hasOverflowClip() && !restrictedByLineClamp) {
1089 PaintLayerScrollableArea* scrollableArea = this->getScrollableArea(); 1099 PaintLayerScrollableArea* scrollableArea = this->getScrollableArea();
1090 ASSERT(scrollableArea); 1100 ASSERT(scrollableArea);
1091 1101
1092 DoubleSize newScrollOffset = scrollableArea->adjustedScrollOffset() + delta; 1102 DoubleSize newScrollOffset = scrollableArea->offsetFromOrigin() + delta;
1093 scrollableArea->scrollToOffset(newScrollOffset, clamp); 1103 scrollableArea->scrollToOffsetFromOrigin(newScrollOffset);
1094 1104
1095 // If this layer can't do the scroll we ask the next layer up that can scrol l to try 1105 // If this layer can't do the scroll we ask the next layer up that can scrol l to try
1096 DoubleSize remainingScrollOffset = 1106 DoubleSize remainingScrollOffset =
1097 newScrollOffset - scrollableArea->adjustedScrollOffset(); 1107 newScrollOffset - scrollableArea->offsetFromOrigin();
1098 if (!remainingScrollOffset.isZero() && parent()) { 1108 if (!remainingScrollOffset.isZero() && parent()) {
1099 if (LayoutBox* scrollableBox = enclosingScrollableBox()) 1109 if (LayoutBox* scrollableBox = enclosingScrollableBox())
1100 scrollableBox->scrollByRecursively(remainingScrollOffset, clamp); 1110 scrollableBox->scrollByRecursively(remainingScrollOffset);
1101 1111
1102 LocalFrame* frame = this->frame(); 1112 LocalFrame* frame = this->frame();
1103 if (frame && frame->page()) 1113 if (frame && frame->page())
1104 frame->page()->autoscrollController().updateAutoscrollLayoutObject(); 1114 frame->page()->autoscrollController().updateAutoscrollLayoutObject();
1105 } 1115 }
1106 } else if (view()->frameView()) { 1116 } else if (view()->frameView()) {
1107 // If we are here, we were called on a layoutObject that can be programmatic ally scrolled, but doesn't 1117 // If we are here, we were called on a layoutObject that can be programmatic ally scrolled, but doesn't
1108 // have an overflow clip. Which means that it is a document node that can be scrolled. 1118 // have an overflow clip. Which means that it is a document node that can be scrolled.
1109 // FIXME: Pass in DoubleSize. crbug.com/414283. 1119 // FIXME: Pass in DoubleSize. crbug.com/414283.
1110 view()->frameView()->scrollBy(flooredIntSize(delta), UserScroll); 1120 view()->frameView()->scrollBy(flooredIntSize(delta), UserScroll);
(...skipping 17 matching lines...) Expand all
1128 size.expand(adjustmentWidth, 0); 1138 size.expand(adjustmentWidth, 0);
1129 } 1139 }
1130 return size; 1140 return size;
1131 } 1141 }
1132 1142
1133 IntSize LayoutBox::scrolledContentOffset() const { 1143 IntSize LayoutBox::scrolledContentOffset() const {
1134 ASSERT(hasOverflowClip()); 1144 ASSERT(hasOverflowClip());
1135 ASSERT(hasLayer()); 1145 ASSERT(hasLayer());
1136 // FIXME: Return DoubleSize here. crbug.com/414283. 1146 // FIXME: Return DoubleSize here. crbug.com/414283.
1137 PaintLayerScrollableArea* scrollableArea = getScrollableArea(); 1147 PaintLayerScrollableArea* scrollableArea = getScrollableArea();
1138 IntSize result = flooredIntSize(scrollableArea->scrollOffset()) + 1148 IntSize result = flooredIntSize(scrollableArea->scrollPosition()) +
1139 originAdjustmentForScrollbars(); 1149 originAdjustmentForScrollbars();
1140 if (isHorizontalWritingMode() && 1150 if (isHorizontalWritingMode() &&
1141 shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) 1151 shouldPlaceBlockDirectionScrollbarOnLogicalLeft())
1142 result.expand(-verticalScrollbarWidth(), 0); 1152 result.expand(-verticalScrollbarWidth(), 0);
1143 return result; 1153 return result;
1144 } 1154 }
1145 1155
1146 LayoutRect LayoutBox::clippingRect() const { 1156 LayoutRect LayoutBox::clippingRect() const {
1147 LayoutRect result = LayoutRect(LayoutRect::infiniteIntRect()); 1157 LayoutRect result = LayoutRect(LayoutRect::infiniteIntRect());
1148 if (hasOverflowClip() || style()->containsPaint()) 1158 if (hasOverflowClip() || style()->containsPaint())
(...skipping 4315 matching lines...) Expand 10 before | Expand all | Expand 10 after
5464 LayoutRect rect = frameRect(); 5474 LayoutRect rect = frameRect();
5465 5475
5466 LayoutBlock* block = containingBlock(); 5476 LayoutBlock* block = containingBlock();
5467 if (block) 5477 if (block)
5468 block->adjustChildDebugRect(rect); 5478 block->adjustChildDebugRect(rect);
5469 5479
5470 return rect; 5480 return rect;
5471 } 5481 }
5472 5482
5473 } // namespace blink 5483 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698