1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383
|
/*
* Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
*
* Portions are Copyright (C) 1998 Netscape Communications Corporation.
*
* Other contributors:
* Robert O'Callahan <roc+@cs.cmu.edu>
* David Baron <dbaron@fas.harvard.edu>
* Christian Biesinger <cbiesinger@web.de>
* Randall Jesup <rjesup@wgate.com>
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
* Josh Soref <timeless@mac.com>
* Boris Zbarsky <bzbarsky@mit.edu>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Alternatively, the contents of this file may be used under the terms
* of either the Mozilla Public License Version 1.1, found at
* http://www.mozilla.org/MPL/ (the "MPL") or the GNU General Public
* License Version 2.0, found at http://www.fsf.org/copyleft/gpl.html
* (the "GPL"), in which case the provisions of the MPL or the GPL are
* applicable instead of those above. If you wish to allow use of your
* version of this file only under the terms of one of those two
* licenses (the MPL or the GPL) and not to allow others to use your
* version of this file under the LGPL, indicate your decision by
* deletingthe provisions above and replace them with the notice and
* other provisions required by the MPL or the GPL, as the case may be.
* If you do not delete the provisions above, a recipient may use your
* version of this file under any of the LGPL, the MPL or the GPL.
*/
#include "config.h"
#include "core/rendering/RenderLayer.h"
#include "core/css/PseudoStyleRequest.h"
#include "core/dom/AXObjectCache.h"
#include "core/dom/Node.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/editing/FrameSelection.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Settings.h"
#include "core/html/HTMLFrameOwnerElement.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "core/page/Chrome.h"
#include "core/page/EventHandler.h"
#include "core/page/FocusController.h"
#include "core/page/Page.h"
#include "core/page/scrolling/ScrollingCoordinator.h"
#include "core/rendering/RenderGeometryMap.h"
#include "core/rendering/RenderScrollbar.h"
#include "core/rendering/RenderScrollbarPart.h"
#include "core/rendering/RenderTheme.h"
#include "core/rendering/RenderView.h"
#include "core/rendering/compositing/CompositedLayerMapping.h"
#include "core/rendering/compositing/RenderLayerCompositor.h"
#include "platform/PlatformGestureEvent.h"
#include "platform/PlatformMouseEvent.h"
#include "platform/graphics/GraphicsContextStateSaver.h"
#include "platform/graphics/GraphicsLayer.h"
#include "platform/graphics/paint/DrawingRecorder.h"
#include "platform/scroll/ScrollAnimator.h"
#include "platform/scroll/ScrollbarTheme.h"
#include "public/platform/Platform.h"
namespace blink {
const int ResizerControlExpandRatioForTouch = 2;
RenderLayerScrollableArea::RenderLayerScrollableArea(RenderLayer& layer)
: m_layer(layer)
, m_inResizeMode(false)
, m_scrollsOverflow(false)
, m_scrollDimensionsDirty(true)
, m_inOverflowRelayout(false)
, m_nextTopmostScrollChild(0)
, m_topmostScrollChild(0)
, m_needsCompositedScrolling(false)
, m_scrollCorner(nullptr)
, m_resizer(nullptr)
{
ScrollableArea::setConstrainsScrollingToContentEdge(false);
Node* node = box().node();
if (node && node->isElementNode()) {
// We save and restore only the scrollOffset as the other scroll values are recalculated.
Element* element = toElement(node);
m_scrollOffset = element->savedLayerScrollOffset();
if (!m_scrollOffset.isZero())
scrollAnimator()->setCurrentPosition(FloatPoint(m_scrollOffset.width(), m_scrollOffset.height()));
element->setSavedLayerScrollOffset(IntSize());
}
updateResizerAreaSet();
}
RenderLayerScrollableArea::~RenderLayerScrollableArea()
{
if (inResizeMode() && !box().documentBeingDestroyed()) {
if (LocalFrame* frame = box().frame())
frame->eventHandler().resizeScrollableAreaDestroyed();
}
if (LocalFrame* frame = box().frame()) {
if (FrameView* frameView = frame->view()) {
frameView->removeScrollableArea(this);
frameView->removeAnimatingScrollableArea(this);
}
}
if (box().frame() && box().frame()->page()) {
if (ScrollingCoordinator* scrollingCoordinator = box().frame()->page()->scrollingCoordinator())
scrollingCoordinator->willDestroyScrollableArea(this);
}
if (!box().documentBeingDestroyed()) {
Node* node = box().node();
// FIXME: Make setSavedLayerScrollOffset take DoubleSize. crbug.com/414283.
if (node && node->isElementNode())
toElement(node)->setSavedLayerScrollOffset(flooredIntSize(m_scrollOffset));
}
if (LocalFrame* frame = box().frame()) {
if (FrameView* frameView = frame->view())
frameView->removeResizerArea(box());
}
destroyScrollbar(HorizontalScrollbar);
destroyScrollbar(VerticalScrollbar);
if (m_scrollCorner)
m_scrollCorner->destroy();
if (m_resizer)
m_resizer->destroy();
}
HostWindow* RenderLayerScrollableArea::hostWindow() const
{
if (Page* page = box().frame()->page())
return &page->chrome();
return nullptr;
}
GraphicsLayer* RenderLayerScrollableArea::layerForScrolling() const
{
return layer()->hasCompositedLayerMapping() ? layer()->compositedLayerMapping()->scrollingContentsLayer() : 0;
}
GraphicsLayer* RenderLayerScrollableArea::layerForHorizontalScrollbar() const
{
// See crbug.com/343132.
DisableCompositingQueryAsserts disabler;
return layer()->hasCompositedLayerMapping() ? layer()->compositedLayerMapping()->layerForHorizontalScrollbar() : 0;
}
GraphicsLayer* RenderLayerScrollableArea::layerForVerticalScrollbar() const
{
// See crbug.com/343132.
DisableCompositingQueryAsserts disabler;
return layer()->hasCompositedLayerMapping() ? layer()->compositedLayerMapping()->layerForVerticalScrollbar() : 0;
}
GraphicsLayer* RenderLayerScrollableArea::layerForScrollCorner() const
{
// See crbug.com/343132.
DisableCompositingQueryAsserts disabler;
return layer()->hasCompositedLayerMapping() ? layer()->compositedLayerMapping()->layerForScrollCorner() : 0;
}
void RenderLayerScrollableArea::invalidateScrollbarRect(Scrollbar* scrollbar, const IntRect& rect)
{
// See crbug.com/343132.
DisableCompositingQueryAsserts disabler;
if (scrollbar == m_vBar.get()) {
if (GraphicsLayer* layer = layerForVerticalScrollbar()) {
layer->setNeedsDisplayInRect(rect, PaintInvalidationScroll);
return;
}
} else {
if (GraphicsLayer* layer = layerForHorizontalScrollbar()) {
layer->setNeedsDisplayInRect(rect, PaintInvalidationScroll);
return;
}
}
IntRect scrollRect = rect;
// If we are not yet inserted into the tree, there is no need to issue paint invaldiations.
if (!box().isRenderView() && !box().parent())
return;
if (scrollbar == m_vBar.get())
scrollRect.move(verticalScrollbarStart(0, box().size().width()), box().borderTop());
else
scrollRect.move(horizontalScrollbarStart(0), box().size().height() - box().borderBottom() - scrollbar->height());
if (scrollRect.isEmpty())
return;
LayoutRect paintInvalidationRect = scrollRect;
box().flipForWritingMode(paintInvalidationRect);
IntRect intRect = pixelSnappedIntRect(paintInvalidationRect);
if (box().frameView()->isInPerformLayout())
addScrollbarDamage(scrollbar, intRect);
else
box().invalidatePaintRectangle(intRect);
}
void RenderLayerScrollableArea::invalidateScrollCornerRect(const IntRect& rect)
{
if (GraphicsLayer* layer = layerForScrollCorner()) {
layer->setNeedsDisplayInRect(rect, PaintInvalidationScroll);
return;
}
if (m_scrollCorner)
m_scrollCorner->invalidatePaintRectangle(rect);
if (m_resizer)
m_resizer->invalidatePaintRectangle(rect);
}
bool RenderLayerScrollableArea::shouldUseIntegerScrollOffset() const
{
Frame* frame = box().frame();
if (frame->settings() && !frame->settings()->preferCompositingToLCDTextEnabled())
return true;
return false;
}
bool RenderLayerScrollableArea::isActive() const
{
Page* page = box().frame()->page();
return page && page->focusController().isActive();
}
bool RenderLayerScrollableArea::isScrollCornerVisible() const
{
return !scrollCornerRect().isEmpty();
}
static int cornerStart(const RenderStyle* style, int minX, int maxX, int thickness)
{
if (style->shouldPlaceBlockDirectionScrollbarOnLogicalLeft())
return minX + style->borderLeftWidth();
return maxX - thickness - style->borderRightWidth();
}
static IntRect cornerRect(const RenderStyle* style, const Scrollbar* horizontalScrollbar, const Scrollbar* verticalScrollbar, const IntRect& bounds)
{
int horizontalThickness;
int verticalThickness;
if (!verticalScrollbar && !horizontalScrollbar) {
// FIXME: This isn't right. We need to know the thickness of custom scrollbars
// even when they don't exist in order to set the resizer square size properly.
horizontalThickness = ScrollbarTheme::theme()->scrollbarThickness();
verticalThickness = horizontalThickness;
} else if (verticalScrollbar && !horizontalScrollbar) {
horizontalThickness = verticalScrollbar->width();
verticalThickness = horizontalThickness;
} else if (horizontalScrollbar && !verticalScrollbar) {
verticalThickness = horizontalScrollbar->height();
horizontalThickness = verticalThickness;
} else {
horizontalThickness = verticalScrollbar->width();
verticalThickness = horizontalScrollbar->height();
}
return IntRect(cornerStart(style, bounds.x(), bounds.maxX(), horizontalThickness),
bounds.maxY() - verticalThickness - style->borderBottomWidth(),
horizontalThickness, verticalThickness);
}
IntRect RenderLayerScrollableArea::scrollCornerRect() const
{
// We have a scrollbar corner when a scrollbar is visible and not filling the entire length of the box.
// This happens when:
// (a) A resizer is present and at least one scrollbar is present
// (b) Both scrollbars are present.
bool hasHorizontalBar = horizontalScrollbar();
bool hasVerticalBar = verticalScrollbar();
bool hasResizer = box().style()->resize() != RESIZE_NONE;
if ((hasHorizontalBar && hasVerticalBar) || (hasResizer && (hasHorizontalBar || hasVerticalBar)))
return cornerRect(box().style(), horizontalScrollbar(), verticalScrollbar(), box().pixelSnappedBorderBoxRect());
return IntRect();
}
IntRect RenderLayerScrollableArea::convertFromScrollbarToContainingView(const Scrollbar* scrollbar, const IntRect& scrollbarRect) const
{
RenderView* view = box().view();
if (!view)
return scrollbarRect;
IntRect rect = scrollbarRect;
rect.move(scrollbarOffset(scrollbar));
return view->frameView()->convertFromRenderer(box(), rect);
}
IntRect RenderLayerScrollableArea::convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntRect& parentRect) const
{
RenderView* view = box().view();
if (!view)
return parentRect;
IntRect rect = view->frameView()->convertToRenderer(box(), parentRect);
rect.move(-scrollbarOffset(scrollbar));
return rect;
}
IntPoint RenderLayerScrollableArea::convertFromScrollbarToContainingView(const Scrollbar* scrollbar, const IntPoint& scrollbarPoint) const
{
RenderView* view = box().view();
if (!view)
return scrollbarPoint;
IntPoint point = scrollbarPoint;
point.move(scrollbarOffset(scrollbar));
return view->frameView()->convertFromRenderer(box(), point);
}
IntPoint RenderLayerScrollableArea::convertFromContainingViewToScrollbar(const Scrollbar* scrollbar, const IntPoint& parentPoint) const
{
RenderView* view = box().view();
if (!view)
return parentPoint;
IntPoint point = view->frameView()->convertToRenderer(box(), parentPoint);
point.move(-scrollbarOffset(scrollbar));
return point;
}
int RenderLayerScrollableArea::scrollSize(ScrollbarOrientation orientation) const
{
IntSize scrollDimensions = maximumScrollPosition() - minimumScrollPosition();
return (orientation == HorizontalScrollbar) ? scrollDimensions.width() : scrollDimensions.height();
}
void RenderLayerScrollableArea::setScrollOffset(const IntPoint& newScrollOffset)
{
setScrollOffset(DoublePoint(newScrollOffset));
}
void RenderLayerScrollableArea::setScrollOffset(const DoublePoint& newScrollOffset)
{
// Ensure that the dimensions will be computed if they need to be (for overflow:hidden blocks).
if (m_scrollDimensionsDirty)
computeScrollDimensions();
if (scrollOffset() == toDoubleSize(newScrollOffset))
return;
m_scrollOffset = toDoubleSize(newScrollOffset);
LocalFrame* frame = box().frame();
ASSERT(frame);
RefPtrWillBeRawPtr<FrameView> frameView = box().frameView();
TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "ScrollLayer", "data", InspectorScrollLayerEvent::data(&box()));
// FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeline migrates to tracing.
InspectorInstrumentation::willScrollLayer(&box());
// Update the positions of our child layers (if needed as only fixed layers should be impacted by a scroll).
// We don't update compositing layers, because we need to do a deep update from the compositing ancestor.
if (!frameView->isInPerformLayout()) {
// If we're in the middle of layout, we'll just update layers once layout has finished.
layer()->updateLayerPositionsAfterOverflowScroll();
// Update regions, scrolling may change the clip of a particular region.
frameView->updateAnnotatedRegions();
frameView->setNeedsUpdateWidgetPositions();
updateCompositingLayersAfterScroll();
}
const RenderLayerModelObject* paintInvalidationContainer = box().containerForPaintInvalidation();
// The caret rect needs to be invalidated after scrolling
frame->selection().setCaretRectNeedsUpdate();
FloatQuad quadForFakeMouseMoveEvent = FloatQuad(layer()->renderer()->previousPaintInvalidationRect());
quadForFakeMouseMoveEvent = paintInvalidationContainer->localToAbsoluteQuad(quadForFakeMouseMoveEvent);
frame->eventHandler().dispatchFakeMouseMoveEventSoonInQuad(quadForFakeMouseMoveEvent);
bool requiresPaintInvalidation = true;
{
// FIXME(420741): Since scrolling depends on compositing state, the scroll should be
// deferred until after the compositing update.
DisableCompositingQueryAsserts disabler;
if (box().view()->compositor()->inCompositingMode()) {
bool onlyScrolledCompositedLayers = scrollsOverflow()
&& !layer()->hasVisibleNonLayerContent()
&& !layer()->hasNonCompositedChild()
&& !layer()->hasBlockSelectionGapBounds()
&& box().style()->backgroundLayers().attachment() != LocalBackgroundAttachment;
if (usesCompositedScrolling() || onlyScrolledCompositedLayers)
requiresPaintInvalidation = false;
}
}
// Just schedule a full paint invalidation of our object.
if (requiresPaintInvalidation)
box().setShouldDoFullPaintInvalidation();
// Schedule the scroll DOM event.
if (box().node())
box().node()->document().enqueueScrollEventForNode(box().node());
if (AXObjectCache* cache = box().document().existingAXObjectCache())
cache->handleScrollPositionChanged(&box());
InspectorInstrumentation::didScrollLayer(&box());
}
IntPoint RenderLayerScrollableArea::scrollPosition() const
{
return IntPoint(flooredIntSize(m_scrollOffset));
}
DoublePoint RenderLayerScrollableArea::scrollPositionDouble() const
{
return DoublePoint(m_scrollOffset);
}
IntPoint RenderLayerScrollableArea::minimumScrollPosition() const
{
return -scrollOrigin();
}
IntPoint RenderLayerScrollableArea::maximumScrollPosition() const
{
if (!box().hasOverflowClip())
return -scrollOrigin();
return -scrollOrigin() + IntPoint(pixelSnappedScrollWidth(), pixelSnappedScrollHeight()) - enclosingIntRect(box().clientBoxRect()).size();
}
IntRect RenderLayerScrollableArea::visibleContentRect(IncludeScrollbarsInRect scrollbarInclusion) const
{
int verticalScrollbarWidth = 0;
int horizontalScrollbarHeight = 0;
if (scrollbarInclusion == IncludeScrollbars) {
verticalScrollbarWidth = (verticalScrollbar() && !verticalScrollbar()->isOverlayScrollbar()) ? verticalScrollbar()->width() : 0;
horizontalScrollbarHeight = (horizontalScrollbar() && !horizontalScrollbar()->isOverlayScrollbar()) ? horizontalScrollbar()->height() : 0;
}
return IntRect(IntPoint(scrollXOffset(), scrollYOffset()),
IntSize(max(0, layer()->size().width() - verticalScrollbarWidth), max(0, layer()->size().height() - horizontalScrollbarHeight)));
}
int RenderLayerScrollableArea::visibleHeight() const
{
return layer()->size().height();
}
int RenderLayerScrollableArea::visibleWidth() const
{
return layer()->size().width();
}
IntSize RenderLayerScrollableArea::contentsSize() const
{
return IntSize(scrollWidth(), scrollHeight());
}
IntSize RenderLayerScrollableArea::overhangAmount() const
{
return IntSize();
}
IntPoint RenderLayerScrollableArea::lastKnownMousePosition() const
{
return box().frame() ? box().frame()->eventHandler().lastKnownMousePosition() : IntPoint();
}
bool RenderLayerScrollableArea::shouldSuspendScrollAnimations() const
{
RenderView* view = box().view();
if (!view)
return true;
return view->frameView()->shouldSuspendScrollAnimations();
}
bool RenderLayerScrollableArea::scrollbarsCanBeActive() const
{
RenderView* view = box().view();
if (!view)
return false;
return view->frameView()->scrollbarsCanBeActive();
}
IntRect RenderLayerScrollableArea::scrollableAreaBoundingBox() const
{
return box().absoluteBoundingBoxRect();
}
void RenderLayerScrollableArea::registerForAnimation()
{
if (LocalFrame* frame = box().frame()) {
if (FrameView* frameView = frame->view())
frameView->addAnimatingScrollableArea(this);
}
}
void RenderLayerScrollableArea::deregisterForAnimation()
{
if (LocalFrame* frame = box().frame()) {
if (FrameView* frameView = frame->view())
frameView->removeAnimatingScrollableArea(this);
}
}
bool RenderLayerScrollableArea::userInputScrollable(ScrollbarOrientation orientation) const
{
if (box().isIntristicallyScrollable(orientation))
return true;
EOverflow overflowStyle = (orientation == HorizontalScrollbar) ?
box().style()->overflowX() : box().style()->overflowY();
return (overflowStyle == OSCROLL || overflowStyle == OAUTO || overflowStyle == OOVERLAY);
}
bool RenderLayerScrollableArea::shouldPlaceVerticalScrollbarOnLeft() const
{
return box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft();
}
int RenderLayerScrollableArea::pageStep(ScrollbarOrientation orientation) const
{
int length = (orientation == HorizontalScrollbar) ?
box().pixelSnappedClientWidth() : box().pixelSnappedClientHeight();
int minPageStep = static_cast<float>(length) * ScrollableArea::minFractionToStepWhenPaging();
int pageStep = max(minPageStep, length - ScrollableArea::maxOverlapBetweenPages());
return max(pageStep, 1);
}
RenderBox& RenderLayerScrollableArea::box() const
{
return *m_layer.renderBox();
}
RenderLayer* RenderLayerScrollableArea::layer() const
{
return &m_layer;
}
LayoutUnit RenderLayerScrollableArea::scrollWidth() const
{
if (m_scrollDimensionsDirty)
const_cast<RenderLayerScrollableArea*>(this)->computeScrollDimensions();
return m_overflowRect.width();
}
LayoutUnit RenderLayerScrollableArea::scrollHeight() const
{
if (m_scrollDimensionsDirty)
const_cast<RenderLayerScrollableArea*>(this)->computeScrollDimensions();
return m_overflowRect.height();
}
int RenderLayerScrollableArea::pixelSnappedScrollWidth() const
{
return snapSizeToPixel(scrollWidth(), box().clientLeft() + box().location().x());
}
int RenderLayerScrollableArea::pixelSnappedScrollHeight() const
{
return snapSizeToPixel(scrollHeight(), box().clientTop() + box().location().y());
}
void RenderLayerScrollableArea::computeScrollDimensions()
{
m_scrollDimensionsDirty = false;
m_overflowRect = box().layoutOverflowRect();
box().flipForWritingMode(m_overflowRect);
int scrollableLeftOverflow = m_overflowRect.x() - box().borderLeft() - (box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ? box().verticalScrollbarWidth() : 0);
int scrollableTopOverflow = m_overflowRect.y() - box().borderTop();
setScrollOrigin(IntPoint(-scrollableLeftOverflow, -scrollableTopOverflow));
}
void RenderLayerScrollableArea::scrollToOffset(const DoubleSize& scrollOffset, ScrollOffsetClamping clamp, ScrollBehavior scrollBehavior)
{
cancelProgrammaticScrollAnimation();
DoubleSize newScrollOffset = clamp == ScrollOffsetClamped ? clampScrollOffset(scrollOffset) : scrollOffset;
if (newScrollOffset != adjustedScrollOffset()) {
if (scrollBehavior == ScrollBehaviorAuto)
scrollBehavior = box().style()->scrollBehavior();
DoublePoint origin(scrollOrigin());
if (scrollBehavior == ScrollBehaviorSmooth) {
// FIXME: Make programmaticallyScrollSmoothlyToOffset take DoublePoint. crbug.com/243871.
programmaticallyScrollSmoothlyToOffset(toFloatPoint(-origin + newScrollOffset));
} else {
// FIXME: Make scrollToOffsetWithoutAnimation take DoublePoint. crbug.com/414283.
scrollToOffsetWithoutAnimation(toFloatPoint(-origin + newScrollOffset));
}
}
}
void RenderLayerScrollableArea::updateAfterLayout()
{
m_scrollDimensionsDirty = true;
DoubleSize originalScrollOffset = adjustedScrollOffset();
computeScrollDimensions();
// Layout may cause us to be at an invalid scroll position. In this case we need
// to pull our scroll offsets back to the max (or push them up to the min).
DoubleSize clampedScrollOffset = clampScrollOffset(adjustedScrollOffset());
if (clampedScrollOffset != adjustedScrollOffset())
scrollToOffset(clampedScrollOffset);
if (originalScrollOffset != adjustedScrollOffset()) {
DoublePoint origin(scrollOrigin());
scrollToOffsetWithoutAnimation(toFloatPoint(-origin + adjustedScrollOffset()));
}
bool hasHorizontalOverflow = this->hasHorizontalOverflow();
bool hasVerticalOverflow = this->hasVerticalOverflow();
{
// Hits in compositing/overflow/automatically-opt-into-composited-scrolling-after-style-change.html.
DisableCompositingQueryAsserts disabler;
// overflow:scroll should just enable/disable.
if (box().style()->overflowX() == OSCROLL && horizontalScrollbar())
horizontalScrollbar()->setEnabled(hasHorizontalOverflow);
if (box().style()->overflowY() == OSCROLL && verticalScrollbar())
verticalScrollbar()->setEnabled(hasVerticalOverflow);
}
if (hasOverlayScrollbars()) {
if (!scrollSize(HorizontalScrollbar))
setHasHorizontalScrollbar(false);
if (!scrollSize(VerticalScrollbar))
setHasVerticalScrollbar(false);
}
// overflow:auto may need to lay out again if scrollbars got added/removed.
bool autoHorizontalScrollBarChanged = box().hasAutoHorizontalScrollbar() && (hasHorizontalScrollbar() != hasHorizontalOverflow);
bool autoVerticalScrollBarChanged = box().hasAutoVerticalScrollbar() && (hasVerticalScrollbar() != hasVerticalOverflow);
if (autoHorizontalScrollBarChanged || autoVerticalScrollBarChanged) {
if (box().hasAutoHorizontalScrollbar())
setHasHorizontalScrollbar(hasHorizontalOverflow);
if (box().hasAutoVerticalScrollbar())
setHasVerticalScrollbar(hasVerticalOverflow);
if (hasVerticalOverflow || hasHorizontalOverflow)
updateScrollCornerStyle();
layer()->updateSelfPaintingLayer();
// Force an update since we know the scrollbars have changed things.
if (box().document().hasAnnotatedRegions())
box().document().setAnnotatedRegionsDirty(true);
if (box().style()->overflowX() == OAUTO || box().style()->overflowY() == OAUTO) {
if (!m_inOverflowRelayout) {
// Our proprietary overflow: overlay value doesn't trigger a layout.
m_inOverflowRelayout = true;
SubtreeLayoutScope layoutScope(box());
layoutScope.setNeedsLayout(&box());
if (box().isRenderBlock()) {
RenderBlock& block = toRenderBlock(box());
block.scrollbarsChanged(autoHorizontalScrollBarChanged, autoVerticalScrollBarChanged);
block.layoutBlock(true);
} else {
box().layout();
}
m_inOverflowRelayout = false;
}
}
}
{
// Hits in compositing/overflow/automatically-opt-into-composited-scrolling-after-style-change.html.
DisableCompositingQueryAsserts disabler;
// Set up the range (and page step/line step).
if (Scrollbar* horizontalScrollbar = this->horizontalScrollbar()) {
int clientWidth = box().pixelSnappedClientWidth();
horizontalScrollbar->setProportion(clientWidth, overflowRect().width());
}
if (Scrollbar* verticalScrollbar = this->verticalScrollbar()) {
int clientHeight = box().pixelSnappedClientHeight();
verticalScrollbar->setProportion(clientHeight, overflowRect().height());
}
}
bool hasOverflow = hasScrollableHorizontalOverflow() || hasScrollableVerticalOverflow();
updateScrollableAreaSet(hasOverflow);
if (hasOverflow) {
DisableCompositingQueryAsserts disabler;
positionOverflowControls(IntSize());
}
}
bool RenderLayerScrollableArea::hasHorizontalOverflow() const
{
ASSERT(!m_scrollDimensionsDirty);
return pixelSnappedScrollWidth() > box().pixelSnappedClientWidth();
}
bool RenderLayerScrollableArea::hasVerticalOverflow() const
{
ASSERT(!m_scrollDimensionsDirty);
return pixelSnappedScrollHeight() > box().pixelSnappedClientHeight();
}
bool RenderLayerScrollableArea::hasScrollableHorizontalOverflow() const
{
return hasHorizontalOverflow() && box().scrollsOverflowX();
}
bool RenderLayerScrollableArea::hasScrollableVerticalOverflow() const
{
return hasVerticalOverflow() && box().scrollsOverflowY();
}
static bool overflowRequiresScrollbar(EOverflow overflow)
{
return overflow == OSCROLL;
}
static bool overflowDefinesAutomaticScrollbar(EOverflow overflow)
{
return overflow == OAUTO || overflow == OOVERLAY;
}
// This function returns true if the given box requires overflow scrollbars (as
// opposed to the 'viewport' scrollbars managed by the RenderLayerCompositor).
// FIXME: we should use the same scrolling machinery for both the viewport and
// overflow. Currently, we need to avoid producing scrollbars here if they'll be
// handled externally in the RLC.
static bool canHaveOverflowScrollbars(const RenderBox& box)
{
return !box.isRenderView() && box.document().viewportDefiningElement() != box.node();
}
void RenderLayerScrollableArea::updateAfterStyleChange(const RenderStyle* oldStyle)
{
if (!canHaveOverflowScrollbars(box()))
return;
if (!m_scrollDimensionsDirty)
updateScrollableAreaSet(hasScrollableHorizontalOverflow() || hasScrollableVerticalOverflow());
EOverflow overflowX = box().style()->overflowX();
EOverflow overflowY = box().style()->overflowY();
// To avoid doing a relayout in updateScrollbarsAfterLayout, we try to keep any automatic scrollbar that was already present.
bool needsHorizontalScrollbar = (hasHorizontalScrollbar() && overflowDefinesAutomaticScrollbar(overflowX)) || overflowRequiresScrollbar(overflowX);
bool needsVerticalScrollbar = (hasVerticalScrollbar() && overflowDefinesAutomaticScrollbar(overflowY)) || overflowRequiresScrollbar(overflowY);
setHasHorizontalScrollbar(needsHorizontalScrollbar);
setHasVerticalScrollbar(needsVerticalScrollbar);
// With overflow: scroll, scrollbars are always visible but may be disabled.
// When switching to another value, we need to re-enable them (see bug 11985).
if (needsHorizontalScrollbar && oldStyle && oldStyle->overflowX() == OSCROLL && overflowX != OSCROLL) {
ASSERT(hasHorizontalScrollbar());
m_hBar->setEnabled(true);
}
if (needsVerticalScrollbar && oldStyle && oldStyle->overflowY() == OSCROLL && overflowY != OSCROLL) {
ASSERT(hasVerticalScrollbar());
m_vBar->setEnabled(true);
}
// FIXME: Need to detect a swap from custom to native scrollbars (and vice versa).
if (m_hBar)
m_hBar->styleChanged();
if (m_vBar)
m_vBar->styleChanged();
updateScrollCornerStyle();
updateResizerAreaSet();
updateResizerStyle();
}
bool RenderLayerScrollableArea::updateAfterCompositingChange()
{
layer()->updateScrollingStateAfterCompositingChange();
const bool layersChanged = m_topmostScrollChild != m_nextTopmostScrollChild;
m_topmostScrollChild = m_nextTopmostScrollChild;
m_nextTopmostScrollChild = nullptr;
return layersChanged;
}
void RenderLayerScrollableArea::updateAfterOverflowRecalc()
{
computeScrollDimensions();
if (Scrollbar* horizontalScrollbar = this->horizontalScrollbar()) {
int clientWidth = box().pixelSnappedClientWidth();
horizontalScrollbar->setProportion(clientWidth, overflowRect().width());
}
if (Scrollbar* verticalScrollbar = this->verticalScrollbar()) {
int clientHeight = box().pixelSnappedClientHeight();
verticalScrollbar->setProportion(clientHeight, overflowRect().height());
}
bool hasHorizontalOverflow = this->hasHorizontalOverflow();
bool hasVerticalOverflow = this->hasVerticalOverflow();
bool autoHorizontalScrollBarChanged = box().hasAutoHorizontalScrollbar() && (hasHorizontalScrollbar() != hasHorizontalOverflow);
bool autoVerticalScrollBarChanged = box().hasAutoVerticalScrollbar() && (hasVerticalScrollbar() != hasVerticalOverflow);
if (autoHorizontalScrollBarChanged || autoVerticalScrollBarChanged)
box().setNeedsLayoutAndFullPaintInvalidation();
}
DoubleSize RenderLayerScrollableArea::clampScrollOffset(const DoubleSize& scrollOffset) const
{
int maxX = scrollWidth() - box().pixelSnappedClientWidth();
int maxY = scrollHeight() - box().pixelSnappedClientHeight();
double x = std::max(std::min(scrollOffset.width(), static_cast<double>(maxX)), 0.0);
double y = std::max(std::min(scrollOffset.height(), static_cast<double>(maxY)), 0.0);
return DoubleSize(x, y);
}
IntRect RenderLayerScrollableArea::rectForHorizontalScrollbar(const IntRect& borderBoxRect) const
{
if (!m_hBar)
return IntRect();
const IntRect& scrollCorner = scrollCornerRect();
return IntRect(horizontalScrollbarStart(borderBoxRect.x()),
borderBoxRect.maxY() - box().borderBottom() - m_hBar->height(),
borderBoxRect.width() - (box().borderLeft() + box().borderRight()) - scrollCorner.width(),
m_hBar->height());
}
IntRect RenderLayerScrollableArea::rectForVerticalScrollbar(const IntRect& borderBoxRect) const
{
if (!m_vBar)
return IntRect();
const IntRect& scrollCorner = scrollCornerRect();
return IntRect(verticalScrollbarStart(borderBoxRect.x(), borderBoxRect.maxX()),
borderBoxRect.y() + box().borderTop(),
m_vBar->width(),
borderBoxRect.height() - (box().borderTop() + box().borderBottom()) - scrollCorner.height());
}
LayoutUnit RenderLayerScrollableArea::verticalScrollbarStart(int minX, int maxX) const
{
if (box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft())
return minX + box().borderLeft();
return maxX - box().borderRight() - m_vBar->width();
}
LayoutUnit RenderLayerScrollableArea::horizontalScrollbarStart(int minX) const
{
int x = minX + box().borderLeft();
if (box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft())
x += m_vBar ? m_vBar->width() : resizerCornerRect(box().pixelSnappedBorderBoxRect(), ResizerForPointer).width();
return x;
}
IntSize RenderLayerScrollableArea::scrollbarOffset(const Scrollbar* scrollbar) const
{
if (scrollbar == m_vBar.get())
return IntSize(verticalScrollbarStart(0, box().size().width()), box().borderTop());
if (scrollbar == m_hBar.get())
return IntSize(horizontalScrollbarStart(0), box().size().height() - box().borderBottom() - scrollbar->height());
ASSERT_NOT_REACHED();
return IntSize();
}
static inline RenderObject* rendererForScrollbar(RenderObject& renderer)
{
if (Node* node = renderer.node()) {
if (ShadowRoot* shadowRoot = node->containingShadowRoot()) {
if (shadowRoot->type() == ShadowRoot::UserAgentShadowRoot)
return shadowRoot->host()->renderer();
}
}
return &renderer;
}
PassRefPtrWillBeRawPtr<Scrollbar> RenderLayerScrollableArea::createScrollbar(ScrollbarOrientation orientation)
{
RefPtrWillBeRawPtr<Scrollbar> widget = nullptr;
RenderObject* actualRenderer = rendererForScrollbar(box());
bool hasCustomScrollbarStyle = actualRenderer->isBox() && actualRenderer->style()->hasPseudoStyle(SCROLLBAR);
if (hasCustomScrollbarStyle) {
widget = RenderScrollbar::createCustomScrollbar(this, orientation, actualRenderer->node());
} else {
ScrollbarControlSize scrollbarSize = RegularScrollbar;
if (actualRenderer->style()->hasAppearance())
scrollbarSize = RenderTheme::theme().scrollbarControlSizeForPart(actualRenderer->style()->appearance());
widget = Scrollbar::create(this, orientation, scrollbarSize);
if (orientation == HorizontalScrollbar)
didAddScrollbar(widget.get(), HorizontalScrollbar);
else
didAddScrollbar(widget.get(), VerticalScrollbar);
}
box().document().view()->addChild(widget.get());
return widget.release();
}
void RenderLayerScrollableArea::destroyScrollbar(ScrollbarOrientation orientation)
{
RefPtrWillBePersistent<Scrollbar>& scrollbar = orientation == HorizontalScrollbar ? m_hBar : m_vBar;
if (!scrollbar)
return;
if (!scrollbar->isCustomScrollbar())
willRemoveScrollbar(scrollbar.get(), orientation);
toFrameView(scrollbar->parent())->removeChild(scrollbar.get());
scrollbar->disconnectFromScrollableArea();
scrollbar = nullptr;
}
void RenderLayerScrollableArea::setHasHorizontalScrollbar(bool hasScrollbar)
{
if (hasScrollbar == hasHorizontalScrollbar())
return;
if (hasScrollbar) {
// This doesn't hit in any tests, but since the equivalent code in setHasVerticalScrollbar
// does, presumably this code does as well.
DisableCompositingQueryAsserts disabler;
m_hBar = createScrollbar(HorizontalScrollbar);
} else {
if (!layerForHorizontalScrollbar())
m_hBar->invalidate();
// Otherwise we will remove the layer and just need recompositing.
destroyScrollbar(HorizontalScrollbar);
}
// Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style.
if (m_hBar)
m_hBar->styleChanged();
if (m_vBar)
m_vBar->styleChanged();
// Force an update since we know the scrollbars have changed things.
if (box().document().hasAnnotatedRegions())
box().document().setAnnotatedRegionsDirty(true);
}
void RenderLayerScrollableArea::setHasVerticalScrollbar(bool hasScrollbar)
{
if (hasScrollbar == hasVerticalScrollbar())
return;
if (hasScrollbar) {
// Hits in compositing/overflow/automatically-opt-into-composited-scrolling-after-style-change.html
DisableCompositingQueryAsserts disabler;
m_vBar = createScrollbar(VerticalScrollbar);
} else {
if (!layerForVerticalScrollbar())
m_vBar->invalidate();
// Otherwise we will remove the layer and just need recompositing.
destroyScrollbar(VerticalScrollbar);
}
// Destroying or creating one bar can cause our scrollbar corner to come and go. We need to update the opposite scrollbar's style.
if (m_hBar)
m_hBar->styleChanged();
if (m_vBar)
m_vBar->styleChanged();
// Force an update since we know the scrollbars have changed things.
if (box().document().hasAnnotatedRegions())
box().document().setAnnotatedRegionsDirty(true);
}
int RenderLayerScrollableArea::verticalScrollbarWidth(OverlayScrollbarSizeRelevancy relevancy) const
{
if (!m_vBar || (m_vBar->isOverlayScrollbar() && (relevancy == IgnoreOverlayScrollbarSize || !m_vBar->shouldParticipateInHitTesting())))
return 0;
return m_vBar->width();
}
int RenderLayerScrollableArea::horizontalScrollbarHeight(OverlayScrollbarSizeRelevancy relevancy) const
{
if (!m_hBar || (m_hBar->isOverlayScrollbar() && (relevancy == IgnoreOverlayScrollbarSize || !m_hBar->shouldParticipateInHitTesting())))
return 0;
return m_hBar->height();
}
void RenderLayerScrollableArea::positionOverflowControls(const IntSize& offsetFromRoot)
{
if (!hasScrollbar() && !box().canResize())
return;
const IntRect borderBox = box().pixelSnappedBorderBoxRect();
if (Scrollbar* verticalScrollbar = this->verticalScrollbar()) {
IntRect vBarRect = rectForVerticalScrollbar(borderBox);
vBarRect.move(offsetFromRoot);
verticalScrollbar->setFrameRect(vBarRect);
}
if (Scrollbar* horizontalScrollbar = this->horizontalScrollbar()) {
IntRect hBarRect = rectForHorizontalScrollbar(borderBox);
hBarRect.move(offsetFromRoot);
horizontalScrollbar->setFrameRect(hBarRect);
}
const IntRect& scrollCorner = scrollCornerRect();
if (m_scrollCorner)
m_scrollCorner->setFrameRect(scrollCorner);
if (m_resizer)
m_resizer->setFrameRect(resizerCornerRect(borderBox, ResizerForPointer));
// FIXME, this should eventually be removed, once we are certain that composited
// controls get correctly positioned on a compositor update. For now, conservatively
// leaving this unchanged.
if (layer()->hasCompositedLayerMapping())
layer()->compositedLayerMapping()->positionOverflowControlsLayers(offsetFromRoot);
}
void RenderLayerScrollableArea::updateScrollCornerStyle()
{
if (!m_scrollCorner && !hasScrollbar())
return;
if (!m_scrollCorner && hasOverlayScrollbars())
return;
RenderObject* actualRenderer = rendererForScrollbar(box());
RefPtr<RenderStyle> corner = box().hasOverflowClip() ? actualRenderer->getUncachedPseudoStyle(PseudoStyleRequest(SCROLLBAR_CORNER), actualRenderer->style()) : PassRefPtr<RenderStyle>(nullptr);
if (corner) {
if (!m_scrollCorner) {
m_scrollCorner = RenderScrollbarPart::createAnonymous(&box().document());
m_scrollCorner->setParent(&box());
}
m_scrollCorner->setStyle(corner.release());
} else if (m_scrollCorner) {
m_scrollCorner->destroy();
m_scrollCorner = nullptr;
}
}
bool RenderLayerScrollableArea::hitTestOverflowControls(HitTestResult& result, const IntPoint& localPoint)
{
if (!hasScrollbar() && !box().canResize())
return false;
IntRect resizeControlRect;
if (box().style()->resize() != RESIZE_NONE) {
resizeControlRect = resizerCornerRect(box().pixelSnappedBorderBoxRect(), ResizerForPointer);
if (resizeControlRect.contains(localPoint))
return true;
}
int resizeControlSize = max(resizeControlRect.height(), 0);
if (m_vBar && m_vBar->shouldParticipateInHitTesting()) {
LayoutRect vBarRect(verticalScrollbarStart(0, box().size().width()),
box().borderTop(),
m_vBar->width(),
box().size().height() - (box().borderTop() + box().borderBottom()) - (m_hBar ? m_hBar->height() : resizeControlSize));
if (vBarRect.contains(localPoint)) {
result.setScrollbar(m_vBar.get());
return true;
}
}
resizeControlSize = max(resizeControlRect.width(), 0);
if (m_hBar && m_hBar->shouldParticipateInHitTesting()) {
LayoutRect hBarRect(horizontalScrollbarStart(0),
box().size().height() - box().borderBottom() - m_hBar->height(),
box().size().width() - (box().borderLeft() + box().borderRight()) - (m_vBar ? m_vBar->width() : resizeControlSize),
m_hBar->height());
if (hBarRect.contains(localPoint)) {
result.setScrollbar(m_hBar.get());
return true;
}
}
// FIXME: We should hit test the m_scrollCorner and pass it back through the result.
return false;
}
IntRect RenderLayerScrollableArea::resizerCornerRect(const IntRect& bounds, ResizerHitTestType resizerHitTestType) const
{
if (box().style()->resize() == RESIZE_NONE)
return IntRect();
IntRect corner = cornerRect(box().style(), horizontalScrollbar(), verticalScrollbar(), bounds);
if (resizerHitTestType == ResizerForTouch) {
// We make the resizer virtually larger for touch hit testing. With the
// expanding ratio k = ResizerControlExpandRatioForTouch, we first move
// the resizer rect (of width w & height h), by (-w * (k-1), -h * (k-1)),
// then expand the rect by new_w/h = w/h * k.
int expandRatio = ResizerControlExpandRatioForTouch - 1;
corner.move(-corner.width() * expandRatio, -corner.height() * expandRatio);
corner.expand(corner.width() * expandRatio, corner.height() * expandRatio);
}
return corner;
}
IntRect RenderLayerScrollableArea::scrollCornerAndResizerRect() const
{
IntRect scrollCornerAndResizer = scrollCornerRect();
if (scrollCornerAndResizer.isEmpty())
scrollCornerAndResizer = resizerCornerRect(box().pixelSnappedBorderBoxRect(), ResizerForPointer);
return scrollCornerAndResizer;
}
bool RenderLayerScrollableArea::isPointInResizeControl(const IntPoint& absolutePoint, ResizerHitTestType resizerHitTestType) const
{
if (!box().canResize())
return false;
IntPoint localPoint = roundedIntPoint(box().absoluteToLocal(absolutePoint, UseTransforms));
IntRect localBounds(0, 0, box().pixelSnappedWidth(), box().pixelSnappedHeight());
return resizerCornerRect(localBounds, resizerHitTestType).contains(localPoint);
}
bool RenderLayerScrollableArea::hitTestResizerInFragments(const LayerFragments& layerFragments, const HitTestLocation& hitTestLocation) const
{
if (!box().canResize())
return false;
if (layerFragments.isEmpty())
return false;
for (int i = layerFragments.size() - 1; i >= 0; --i) {
const LayerFragment& fragment = layerFragments.at(i);
if (fragment.backgroundRect.intersects(hitTestLocation) && resizerCornerRect(pixelSnappedIntRect(fragment.layerBounds), ResizerForPointer).contains(hitTestLocation.roundedPoint()))
return true;
}
return false;
}
void RenderLayerScrollableArea::updateResizerAreaSet()
{
LocalFrame* frame = box().frame();
if (!frame)
return;
FrameView* frameView = frame->view();
if (!frameView)
return;
if (box().canResize())
frameView->addResizerArea(box());
else
frameView->removeResizerArea(box());
}
void RenderLayerScrollableArea::updateResizerStyle()
{
if (!m_resizer && !box().canResize())
return;
RenderObject* actualRenderer = rendererForScrollbar(box());
RefPtr<RenderStyle> resizer = box().hasOverflowClip() ? actualRenderer->getUncachedPseudoStyle(PseudoStyleRequest(RESIZER), actualRenderer->style()) : PassRefPtr<RenderStyle>(nullptr);
if (resizer) {
if (!m_resizer) {
m_resizer = RenderScrollbarPart::createAnonymous(&box().document());
m_resizer->setParent(&box());
}
m_resizer->setStyle(resizer.release());
} else if (m_resizer) {
m_resizer->destroy();
m_resizer = nullptr;
}
}
IntSize RenderLayerScrollableArea::offsetFromResizeCorner(const IntPoint& absolutePoint) const
{
// Currently the resize corner is either the bottom right corner or the bottom left corner.
// FIXME: This assumes the location is 0, 0. Is this guaranteed to always be the case?
IntSize elementSize = layer()->size();
if (box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft())
elementSize.setWidth(0);
IntPoint resizerPoint = IntPoint(elementSize);
IntPoint localPoint = roundedIntPoint(box().absoluteToLocal(absolutePoint, UseTransforms));
return localPoint - resizerPoint;
}
void RenderLayerScrollableArea::resize(const PlatformEvent& evt, const LayoutSize& oldOffset)
{
// FIXME: This should be possible on generated content but is not right now.
if (!inResizeMode() || !box().canResize() || !box().node())
return;
ASSERT(box().node()->isElementNode());
Element* element = toElement(box().node());
Document& document = element->document();
IntPoint pos;
const PlatformGestureEvent* gevt = 0;
switch (evt.type()) {
case PlatformEvent::MouseMoved:
if (!document.frame()->eventHandler().mousePressed())
return;
pos = static_cast<const PlatformMouseEvent*>(&evt)->position();
break;
case PlatformEvent::GestureScrollUpdate:
pos = static_cast<const PlatformGestureEvent*>(&evt)->position();
gevt = static_cast<const PlatformGestureEvent*>(&evt);
pos = gevt->position();
pos.move(gevt->deltaX(), gevt->deltaY());
break;
default:
ASSERT_NOT_REACHED();
}
float zoomFactor = box().style()->effectiveZoom();
IntSize newOffset = offsetFromResizeCorner(document.view()->windowToContents(pos));
newOffset.setWidth(newOffset.width() / zoomFactor);
newOffset.setHeight(newOffset.height() / zoomFactor);
LayoutSize currentSize = box().size();
currentSize.scale(1 / zoomFactor);
LayoutSize minimumSize = element->minimumSizeForResizing().shrunkTo(currentSize);
element->setMinimumSizeForResizing(minimumSize);
LayoutSize adjustedOldOffset = LayoutSize(oldOffset.width() / zoomFactor, oldOffset.height() / zoomFactor);
if (box().style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft()) {
newOffset.setWidth(-newOffset.width());
adjustedOldOffset.setWidth(-adjustedOldOffset.width());
}
LayoutSize difference((currentSize + newOffset - adjustedOldOffset).expandedTo(minimumSize) - currentSize);
bool isBoxSizingBorder = box().style()->boxSizing() == BORDER_BOX;
EResize resize = box().style()->resize();
if (resize != RESIZE_VERTICAL && difference.width()) {
if (element->isFormControlElement()) {
// Make implicit margins from the theme explicit (see <http://bugs.webkit.org/show_bug.cgi?id=9547>).
element->setInlineStyleProperty(CSSPropertyMarginLeft, box().marginLeft() / zoomFactor, CSSPrimitiveValue::CSS_PX);
element->setInlineStyleProperty(CSSPropertyMarginRight, box().marginRight() / zoomFactor, CSSPrimitiveValue::CSS_PX);
}
LayoutUnit baseWidth = box().size().width() - (isBoxSizingBorder ? LayoutUnit() : box().borderAndPaddingWidth());
baseWidth = baseWidth / zoomFactor;
element->setInlineStyleProperty(CSSPropertyWidth, roundToInt(baseWidth + difference.width()), CSSPrimitiveValue::CSS_PX);
}
if (resize != RESIZE_HORIZONTAL && difference.height()) {
if (element->isFormControlElement()) {
// Make implicit margins from the theme explicit (see <http://bugs.webkit.org/show_bug.cgi?id=9547>).
element->setInlineStyleProperty(CSSPropertyMarginTop, box().marginTop() / zoomFactor, CSSPrimitiveValue::CSS_PX);
element->setInlineStyleProperty(CSSPropertyMarginBottom, box().marginBottom() / zoomFactor, CSSPrimitiveValue::CSS_PX);
}
LayoutUnit baseHeight = box().size().height() - (isBoxSizingBorder ? LayoutUnit() : box().borderAndPaddingHeight());
baseHeight = baseHeight / zoomFactor;
element->setInlineStyleProperty(CSSPropertyHeight, roundToInt(baseHeight + difference.height()), CSSPrimitiveValue::CSS_PX);
}
document.updateLayout();
// FIXME (Radar 4118564): We should also autoscroll the window as necessary to keep the point under the cursor in view.
}
LayoutRect RenderLayerScrollableArea::exposeRect(const LayoutRect& rect, const ScrollAlignment& alignX, const ScrollAlignment& alignY)
{
LayoutRect localExposeRect(box().absoluteToLocalQuad(FloatQuad(FloatRect(rect)), UseTransforms).boundingBox());
localExposeRect.move(-box().borderLeft(), -box().borderTop());
LayoutRect layerBounds(0, 0, box().clientWidth(), box().clientHeight());
LayoutRect r = ScrollAlignment::getRectToExpose(layerBounds, localExposeRect, alignX, alignY);
DoubleSize clampedScrollOffset = clampScrollOffset(adjustedScrollOffset() + roundedIntSize(r.location()));
if (clampedScrollOffset == adjustedScrollOffset())
return rect;
DoubleSize oldScrollOffset = adjustedScrollOffset();
scrollToOffset(clampedScrollOffset);
DoubleSize scrollOffsetDifference = adjustedScrollOffset() - oldScrollOffset;
localExposeRect.move(-LayoutSize(scrollOffsetDifference));
return LayoutRect(box().localToAbsoluteQuad(FloatQuad(FloatRect(localExposeRect)), UseTransforms).boundingBox());
}
void RenderLayerScrollableArea::updateScrollableAreaSet(bool hasOverflow)
{
LocalFrame* frame = box().frame();
if (!frame)
return;
FrameView* frameView = frame->view();
if (!frameView)
return;
// FIXME: Does this need to be fixed later for OOPI?
bool isVisibleToHitTest = box().visibleToHitTesting();
if (HTMLFrameOwnerElement* owner = frame->deprecatedLocalOwner())
isVisibleToHitTest &= owner->renderer() && owner->renderer()->visibleToHitTesting();
bool didScrollOverflow = m_scrollsOverflow;
m_scrollsOverflow = hasOverflow && isVisibleToHitTest;
if (didScrollOverflow == scrollsOverflow())
return;
if (m_scrollsOverflow)
frameView->addScrollableArea(this);
else
frameView->removeScrollableArea(this);
}
void RenderLayerScrollableArea::updateCompositingLayersAfterScroll()
{
DisableCompositingQueryAsserts disabler;
RenderLayerCompositor* compositor = box().view()->compositor();
if (compositor->inCompositingMode()) {
if (usesCompositedScrolling()) {
ASSERT(layer()->hasCompositedLayerMapping());
layer()->compositedLayerMapping()->setNeedsGraphicsLayerUpdate(GraphicsLayerUpdateSubtree);
compositor->setNeedsCompositingUpdate(CompositingUpdateAfterGeometryChange);
} else {
layer()->setNeedsCompositingInputsUpdate();
}
}
}
bool RenderLayerScrollableArea::usesCompositedScrolling() const
{
// Scroll form controls on the main thread so they exhibit correct touch scroll event bubbling
if (box().isIntristicallyScrollable(VerticalScrollbar) || box().isIntristicallyScrollable(HorizontalScrollbar))
return false;
// See https://codereview.chromium.org/176633003/ for the tests that fail without this disabler.
DisableCompositingQueryAsserts disabler;
return layer()->hasCompositedLayerMapping() && layer()->compositedLayerMapping()->scrollingLayer();
}
static bool layerNeedsCompositedScrolling(RenderLayerScrollableArea::LCDTextMode mode, const RenderLayer* layer)
{
if (mode == RenderLayerScrollableArea::ConsiderLCDText && !layer->compositor()->preferCompositingToLCDTextEnabled())
return false;
return layer->scrollsOverflow()
&& !layer->hasDescendantWithClipPath()
&& !layer->hasAncestorWithClipPath()
&& !layer->renderer()->style()->hasBorderRadius();
}
void RenderLayerScrollableArea::updateNeedsCompositedScrolling(LCDTextMode mode)
{
const bool needsCompositedScrolling = layerNeedsCompositedScrolling(mode, layer());
if (static_cast<bool>(m_needsCompositedScrolling) != needsCompositedScrolling) {
m_needsCompositedScrolling = needsCompositedScrolling;
layer()->didUpdateNeedsCompositedScrolling();
}
}
void RenderLayerScrollableArea::setTopmostScrollChild(RenderLayer* scrollChild)
{
// We only want to track the topmost scroll child for scrollable areas with
// overlay scrollbars.
if (!hasOverlayScrollbars())
return;
m_nextTopmostScrollChild = scrollChild;
}
} // namespace blink
|