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

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

Issue 2387393003: Revert of 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. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc.
7 * All rights reserved. 7 * All rights reserved.
8 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 if (isOrthogonalWritingModeRoot()) 256 if (isOrthogonalWritingModeRoot())
257 markOrthogonalWritingModeRoot(); 257 markOrthogonalWritingModeRoot();
258 else 258 else
259 unmarkOrthogonalWritingModeRoot(); 259 unmarkOrthogonalWritingModeRoot();
260 } 260 }
261 261
262 clearPercentHeightDescendants(); 262 clearPercentHeightDescendants();
263 } 263 }
264 264
265 // If our zoom factor changes and we have a defined scrollLeft/Top, we need to 265 // If our zoom factor changes and we have a defined scrollLeft/Top, we need to
266 // adjust that value into the new zoomed coordinate space. Note that the new 266 // adjust that value into the new zoomed coordinate space.
267 // scroll position may be outside the normal min/max range of the scrollable
268 // area, which is weird but OK, because the scrollable area will update its
269 // min/max in updateAfterLayout().
270 if (hasOverflowClip() && oldStyle && 267 if (hasOverflowClip() && oldStyle &&
271 oldStyle->effectiveZoom() != newStyle.effectiveZoom()) { 268 oldStyle->effectiveZoom() != newStyle.effectiveZoom()) {
272 PaintLayerScrollableArea* scrollableArea = this->getScrollableArea(); 269 PaintLayerScrollableArea* scrollableArea = this->getScrollableArea();
273 ASSERT(scrollableArea); 270 ASSERT(scrollableArea);
274 // We use scrollPosition() rather than adjustedScrollPosition(), because 271 if (int left = scrollableArea->scrollXOffset()) {
275 // scrollPosition is the distance from the beginning of flow for the box, 272 left = (left / oldStyle->effectiveZoom()) * newStyle.effectiveZoom();
276 // which is the dimension we want to preserve. 273 scrollableArea->scrollToXOffset(left);
277 DoublePoint oldPosition = scrollableArea->scrollPositionDouble(); 274 }
278 if (oldPosition.x() || oldPosition.y()) { 275 if (int top = scrollableArea->scrollYOffset()) {
279 DoublePoint newPosition = oldPosition.scaledBy(newStyle.effectiveZoom() / 276 top = (top / oldStyle->effectiveZoom()) * newStyle.effectiveZoom();
280 oldStyle->effectiveZoom()); 277 scrollableArea->scrollToYOffset(top);
281 scrollableArea->setScrollPositionUnconditionally(newPosition);
282 } 278 }
283 } 279 }
284 280
285 // Our opaqueness might have changed without triggering layout. 281 // Our opaqueness might have changed without triggering layout.
286 if (diff.needsPaintInvalidation()) { 282 if (diff.needsPaintInvalidation()) {
287 LayoutObject* parentToInvalidate = parent(); 283 LayoutObject* parentToInvalidate = parent();
288 for (unsigned i = 0; 284 for (unsigned i = 0;
289 i < backgroundObscurationTestMaxDepth && parentToInvalidate; ++i) { 285 i < backgroundObscurationTestMaxDepth && parentToInvalidate; ++i) {
290 parentToInvalidate->invalidateBackgroundObscurationStatus(); 286 parentToInvalidate->invalidateBackgroundObscurationStatus();
291 parentToInvalidate = parentToInvalidate->parent(); 287 parentToInvalidate = parentToInvalidate->parent();
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 515
520 LayoutUnit LayoutBox::scrollHeight() const { 516 LayoutUnit LayoutBox::scrollHeight() const {
521 if (hasOverflowClip()) 517 if (hasOverflowClip())
522 return getScrollableArea()->scrollHeight(); 518 return getScrollableArea()->scrollHeight();
523 // For objects with visible overflow, this matches IE. 519 // For objects with visible overflow, this matches IE.
524 // FIXME: Need to work right with writing modes. 520 // FIXME: Need to work right with writing modes.
525 return std::max(clientHeight(), layoutOverflowRect().maxY() - borderTop()); 521 return std::max(clientHeight(), layoutOverflowRect().maxY() - borderTop());
526 } 522 }
527 523
528 LayoutUnit LayoutBox::scrollLeft() const { 524 LayoutUnit LayoutBox::scrollLeft() const {
529 return hasOverflowClip() 525 return hasOverflowClip() ? LayoutUnit(getScrollableArea()->scrollXOffset())
530 ? LayoutUnit(getScrollableArea()->adjustedScrollOffset().width()) 526 : LayoutUnit();
531 : LayoutUnit();
532 } 527 }
533 528
534 LayoutUnit LayoutBox::scrollTop() const { 529 LayoutUnit LayoutBox::scrollTop() const {
535 return hasOverflowClip() 530 return hasOverflowClip() ? LayoutUnit(getScrollableArea()->scrollYOffset())
536 ? LayoutUnit(getScrollableArea()->adjustedScrollOffset().height()) 531 : LayoutUnit();
537 : LayoutUnit();
538 } 532 }
539 533
540 int LayoutBox::pixelSnappedScrollWidth() const { 534 int LayoutBox::pixelSnappedScrollWidth() const {
541 return snapSizeToPixel(scrollWidth(), location().x() + clientLeft()); 535 return snapSizeToPixel(scrollWidth(), location().x() + clientLeft());
542 } 536 }
543 537
544 int LayoutBox::pixelSnappedScrollHeight() const { 538 int LayoutBox::pixelSnappedScrollHeight() const {
545 if (hasOverflowClip()) 539 if (hasOverflowClip())
546 return snapSizeToPixel(getScrollableArea()->scrollHeight(), 540 return snapSizeToPixel(getScrollableArea()->scrollHeight(),
547 location().y() + clientTop()); 541 location().y() + clientTop());
548 // For objects with visible overflow, this matches IE. 542 // For objects with visible overflow, this matches IE.
549 // FIXME: Need to work right with writing modes. 543 // FIXME: Need to work right with writing modes.
550 return snapSizeToPixel(scrollHeight(), location().y() + clientTop()); 544 return snapSizeToPixel(scrollHeight(), location().y() + clientTop());
551 } 545 }
552 546
553 void LayoutBox::setScrollLeft(LayoutUnit newLeft) { 547 void LayoutBox::setScrollLeft(LayoutUnit newLeft) {
554 // This doesn't hit in any tests, but since the equivalent code in 548 // This doesn't hit in any tests, but since the equivalent code in
555 // setScrollTop does, presumably this code does as well. 549 // setScrollTop does, presumably this code does as well.
556 DisableCompositingQueryAsserts disabler; 550 DisableCompositingQueryAsserts disabler;
557 551
558 if (hasOverflowClip()) { 552 if (hasOverflowClip())
559 PaintLayerScrollableArea* scrollableArea = getScrollableArea(); 553 getScrollableArea()->scrollToXOffset(newLeft, ScrollOffsetClamped,
560 scrollableArea->scrollToOffset( 554 ScrollBehaviorAuto);
561 DoubleSize(newLeft, scrollableArea->adjustedScrollOffset().height()),
562 ScrollBehaviorAuto);
563 }
564 } 555 }
565 556
566 void LayoutBox::setScrollTop(LayoutUnit newTop) { 557 void LayoutBox::setScrollTop(LayoutUnit newTop) {
567 // Hits in 558 // Hits in
568 // compositing/overflow/do-not-assert-on-invisible-composited-layers.html 559 // compositing/overflow/do-not-assert-on-invisible-composited-layers.html
569 DisableCompositingQueryAsserts disabler; 560 DisableCompositingQueryAsserts disabler;
570 561
571 if (hasOverflowClip()) { 562 if (hasOverflowClip())
572 PaintLayerScrollableArea* scrollableArea = getScrollableArea(); 563 getScrollableArea()->scrollToYOffset(newTop, ScrollOffsetClamped,
573 scrollableArea->scrollToOffset( 564 ScrollBehaviorAuto);
574 DoubleSize(scrollableArea->adjustedScrollOffset().width(), newTop),
575 ScrollBehaviorAuto);
576 }
577 } 565 }
578 566
579 void LayoutBox::scrollToOffset(const DoubleSize& offset, 567 void LayoutBox::scrollToOffset(const DoubleSize& offset,
580 ScrollBehavior scrollBehavior) { 568 ScrollBehavior scrollBehavior) {
581 // This doesn't hit in any tests, but since the equivalent code in 569 // This doesn't hit in any tests, but since the equivalent code in
582 // setScrollTop does, presumably this code does as well. 570 // setScrollTop does, presumably this code does as well.
583 DisableCompositingQueryAsserts disabler; 571 DisableCompositingQueryAsserts disabler;
584 572
585 if (hasOverflowClip()) 573 if (hasOverflowClip())
586 getScrollableArea()->scrollToOffset(offset, scrollBehavior); 574 getScrollableArea()->scrollToOffset(offset, ScrollOffsetClamped,
575 scrollBehavior);
587 } 576 }
588 577
589 // Returns true iff we are attempting an autoscroll inside an iframe with 578 // Returns true iff we are attempting an autoscroll inside an iframe with
590 // scrolling="no". 579 // scrolling="no".
591 static bool isDisallowedAutoscroll(HTMLFrameOwnerElement* ownerElement, 580 static bool isDisallowedAutoscroll(HTMLFrameOwnerElement* ownerElement,
592 FrameView* frameView) { 581 FrameView* frameView) {
593 if (ownerElement && isHTMLFrameElementBase(*ownerElement)) { 582 if (ownerElement && isHTMLFrameElementBase(*ownerElement)) {
594 HTMLFrameElementBase* frameElementBase = 583 HTMLFrameElementBase* frameElementBase =
595 toHTMLFrameElementBase(ownerElement); 584 toHTMLFrameElementBase(ownerElement);
596 if (Page* page = frameView->frame().page()) { 585 if (Page* page = frameView->frame().page()) {
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 1086
1098 // at the center we let the space for the icon. 1087 // at the center we let the space for the icon.
1099 if (abs(delta.width()) <= AutoscrollController::noMiddleClickAutoscrollRadius) 1088 if (abs(delta.width()) <= AutoscrollController::noMiddleClickAutoscrollRadius)
1100 delta.setWidth(0); 1089 delta.setWidth(0);
1101 if (abs(delta.height()) <= 1090 if (abs(delta.height()) <=
1102 AutoscrollController::noMiddleClickAutoscrollRadius) 1091 AutoscrollController::noMiddleClickAutoscrollRadius)
1103 delta.setHeight(0); 1092 delta.setHeight(0);
1104 scroll(ScrollByPixel, FloatSize(adjustedScrollDelta(delta))); 1093 scroll(ScrollByPixel, FloatSize(adjustedScrollDelta(delta)));
1105 } 1094 }
1106 1095
1107 void LayoutBox::scrollByRecursively(const DoubleSize& delta) { 1096 void LayoutBox::scrollByRecursively(const DoubleSize& delta,
1097 ScrollOffsetClamping clamp) {
1108 if (delta.isZero()) 1098 if (delta.isZero())
1109 return; 1099 return;
1110 1100
1111 bool restrictedByLineClamp = false; 1101 bool restrictedByLineClamp = false;
1112 if (parent()) 1102 if (parent())
1113 restrictedByLineClamp = !parent()->style()->lineClamp().isNone(); 1103 restrictedByLineClamp = !parent()->style()->lineClamp().isNone();
1114 1104
1115 if (hasOverflowClip() && !restrictedByLineClamp) { 1105 if (hasOverflowClip() && !restrictedByLineClamp) {
1116 PaintLayerScrollableArea* scrollableArea = this->getScrollableArea(); 1106 PaintLayerScrollableArea* scrollableArea = this->getScrollableArea();
1117 ASSERT(scrollableArea); 1107 ASSERT(scrollableArea);
1118 1108
1119 DoubleSize newScrollOffset = scrollableArea->adjustedScrollOffset() + delta; 1109 DoubleSize newScrollOffset = scrollableArea->adjustedScrollOffset() + delta;
1120 scrollableArea->scrollToOffset(newScrollOffset); 1110 scrollableArea->scrollToOffset(newScrollOffset, clamp);
1121 1111
1122 // If this layer can't do the scroll we ask the next layer up that can 1112 // If this layer can't do the scroll we ask the next layer up that can
1123 // scroll to try. 1113 // scroll to try.
1124 DoubleSize remainingScrollOffset = 1114 DoubleSize remainingScrollOffset =
1125 newScrollOffset - scrollableArea->adjustedScrollOffset(); 1115 newScrollOffset - scrollableArea->adjustedScrollOffset();
1126 if (!remainingScrollOffset.isZero() && parent()) { 1116 if (!remainingScrollOffset.isZero() && parent()) {
1127 if (LayoutBox* scrollableBox = enclosingScrollableBox()) 1117 if (LayoutBox* scrollableBox = enclosingScrollableBox())
1128 scrollableBox->scrollByRecursively(remainingScrollOffset); 1118 scrollableBox->scrollByRecursively(remainingScrollOffset, clamp);
1129 1119
1130 LocalFrame* frame = this->frame(); 1120 LocalFrame* frame = this->frame();
1131 if (frame && frame->page()) 1121 if (frame && frame->page())
1132 frame->page()->autoscrollController().updateAutoscrollLayoutObject(); 1122 frame->page()->autoscrollController().updateAutoscrollLayoutObject();
1133 } 1123 }
1134 } else if (view()->frameView()) { 1124 } else if (view()->frameView()) {
1135 // If we are here, we were called on a layoutObject that can be 1125 // If we are here, we were called on a layoutObject that can be
1136 // programmatically scrolled, but doesn't have an overflow clip. Which means 1126 // programmatically scrolled, but doesn't have an overflow clip. Which means
1137 // that it is a document node that can be scrolled. 1127 // that it is a document node that can be scrolled.
1138 // FIXME: Pass in DoubleSize. crbug.com/414283. 1128 // FIXME: Pass in DoubleSize. crbug.com/414283.
(...skipping 4493 matching lines...) Expand 10 before | Expand all | Expand 10 after
5632 LayoutRect rect = frameRect(); 5622 LayoutRect rect = frameRect();
5633 5623
5634 LayoutBlock* block = containingBlock(); 5624 LayoutBlock* block = containingBlock();
5635 if (block) 5625 if (block)
5636 block->adjustChildDebugRect(rect); 5626 block->adjustChildDebugRect(rect);
5637 5627
5638 return rect; 5628 return rect;
5639 } 5629 }
5640 5630
5641 } // namespace blink 5631 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutBox.h ('k') | third_party/WebKit/Source/core/layout/LayoutBoxModelObjectTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698