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

Side by Side Diff: third_party/WebKit/Source/modules/accessibility/AXObject.cpp

Issue 2387883002: Use float for scroll offset. (Closed)
Patch Set: Fix README.md 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) 2008, 2009, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2008, 2009, 2011 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 1195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1206 1206
1207 bool AXObject::isScrollableContainer() const { 1207 bool AXObject::isScrollableContainer() const {
1208 return !!getScrollableAreaIfScrollable(); 1208 return !!getScrollableAreaIfScrollable();
1209 } 1209 }
1210 1210
1211 IntPoint AXObject::scrollOffset() const { 1211 IntPoint AXObject::scrollOffset() const {
1212 ScrollableArea* area = getScrollableAreaIfScrollable(); 1212 ScrollableArea* area = getScrollableAreaIfScrollable();
1213 if (!area) 1213 if (!area)
1214 return IntPoint(); 1214 return IntPoint();
1215 1215
1216 return IntPoint(area->scrollPosition().x(), area->scrollPosition().y()); 1216 return IntPoint(area->scrollOffsetInt().width(),
1217 area->scrollOffsetInt().height());
1217 } 1218 }
1218 1219
1219 IntPoint AXObject::minimumScrollOffset() const { 1220 IntPoint AXObject::minimumScrollOffset() const {
1220 ScrollableArea* area = getScrollableAreaIfScrollable(); 1221 ScrollableArea* area = getScrollableAreaIfScrollable();
1221 if (!area) 1222 if (!area)
1222 return IntPoint(); 1223 return IntPoint();
1223 1224
1224 return IntPoint(area->minimumScrollPosition().x(), 1225 return IntPoint(area->minimumScrollOffsetInt().width(),
1225 area->minimumScrollPosition().y()); 1226 area->minimumScrollOffsetInt().height());
1226 } 1227 }
1227 1228
1228 IntPoint AXObject::maximumScrollOffset() const { 1229 IntPoint AXObject::maximumScrollOffset() const {
1229 ScrollableArea* area = getScrollableAreaIfScrollable(); 1230 ScrollableArea* area = getScrollableAreaIfScrollable();
1230 if (!area) 1231 if (!area)
1231 return IntPoint(); 1232 return IntPoint();
1232 1233
1233 return IntPoint(area->maximumScrollPosition().x(), 1234 return IntPoint(area->maximumScrollOffsetInt().width(),
1234 area->maximumScrollPosition().y()); 1235 area->maximumScrollOffsetInt().height());
1235 } 1236 }
1236 1237
1237 void AXObject::setScrollOffset(const IntPoint& offset) const { 1238 void AXObject::setScrollOffset(const IntPoint& offset) const {
1238 ScrollableArea* area = getScrollableAreaIfScrollable(); 1239 ScrollableArea* area = getScrollableAreaIfScrollable();
1239 if (!area) 1240 if (!area)
1240 return; 1241 return;
1241 1242
1242 // TODO(bokan): This should potentially be a UserScroll. 1243 // TODO(bokan): This should potentially be a UserScroll.
1243 area->setScrollPosition(DoublePoint(offset.x(), offset.y()), 1244 area->setScrollOffset(ScrollOffset(offset.x(), offset.y()),
1244 ProgrammaticScroll); 1245 ProgrammaticScroll);
1245 } 1246 }
1246 1247
1247 void AXObject::getRelativeBounds(AXObject** outContainer, 1248 void AXObject::getRelativeBounds(AXObject** outContainer,
1248 FloatRect& outBoundsInContainer, 1249 FloatRect& outBoundsInContainer,
1249 SkMatrix44& outContainerTransform) const { 1250 SkMatrix44& outContainerTransform) const {
1250 *outContainer = nullptr; 1251 *outContainer = nullptr;
1251 outBoundsInContainer = FloatRect(); 1252 outBoundsInContainer = FloatRect();
1252 outContainerTransform.setIdentity(); 1253 outContainerTransform.setIdentity();
1253 1254
1254 // First check if it has explicit bounds, for example if this element is tied 1255 // First check if it has explicit bounds, for example if this element is tied
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1294 1295
1295 if (!container) 1296 if (!container)
1296 return; 1297 return;
1297 *outContainer = container; 1298 *outContainer = container;
1298 outBoundsInContainer = layoutObject->localBoundingBoxRectForAccessibility(); 1299 outBoundsInContainer = layoutObject->localBoundingBoxRectForAccessibility();
1299 1300
1300 // If the container has a scroll offset, subtract that out because we want our 1301 // If the container has a scroll offset, subtract that out because we want our
1301 // bounds to be relative to the *unscrolled* position of the container object. 1302 // bounds to be relative to the *unscrolled* position of the container object.
1302 ScrollableArea* scrollableArea = container->getScrollableAreaIfScrollable(); 1303 ScrollableArea* scrollableArea = container->getScrollableAreaIfScrollable();
1303 if (scrollableArea && !container->isWebArea()) { 1304 if (scrollableArea && !container->isWebArea()) {
1304 IntPoint scrollPosition = scrollableArea->scrollPosition(); 1305 ScrollOffset scrollOffset = scrollableArea->scrollOffset();
1305 outBoundsInContainer.move( 1306 outBoundsInContainer.move(scrollOffset);
1306 FloatSize(scrollPosition.x(), scrollPosition.y()));
1307 } 1307 }
1308 1308
1309 // Compute the transform between the container's coordinate space and this 1309 // Compute the transform between the container's coordinate space and this
1310 // object. If the transform is just a simple translation, apply that to the 1310 // object. If the transform is just a simple translation, apply that to the
1311 // bounding box, but if it's a non-trivial transformation like a rotation, 1311 // bounding box, but if it's a non-trivial transformation like a rotation,
1312 // scaling, etc. then return the full matrix instead. 1312 // scaling, etc. then return the full matrix instead.
1313 TransformationMatrix transform = layoutObject->localToAncestorTransform( 1313 TransformationMatrix transform = layoutObject->localToAncestorTransform(
1314 toLayoutBoxModelObject(containerLayoutObject)); 1314 toLayoutBoxModelObject(containerLayoutObject));
1315 if (transform.isIdentityOr2DTranslation()) { 1315 if (transform.isIdentityOr2DTranslation()) {
1316 outBoundsInContainer.move(transform.to2DTranslation()); 1316 outBoundsInContainer.move(transform.to2DTranslation());
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 while (scrollParent) { 1462 while (scrollParent) {
1463 scrollableArea = scrollParent->getScrollableAreaIfScrollable(); 1463 scrollableArea = scrollParent->getScrollableAreaIfScrollable();
1464 if (scrollableArea) 1464 if (scrollableArea)
1465 break; 1465 break;
1466 scrollParent = scrollParent->parentObject(); 1466 scrollParent = scrollParent->parentObject();
1467 } 1467 }
1468 if (!scrollParent || !scrollableArea) 1468 if (!scrollParent || !scrollableArea)
1469 return; 1469 return;
1470 1470
1471 IntRect objectRect = pixelSnappedIntRect(getBoundsInFrameCoordinates()); 1471 IntRect objectRect = pixelSnappedIntRect(getBoundsInFrameCoordinates());
1472 IntPoint scrollPosition = scrollableArea->scrollPosition(); 1472 IntSize scrollOffset = scrollableArea->scrollOffsetInt();
1473 IntRect scrollVisibleRect = scrollableArea->visibleContentRect(); 1473 IntRect scrollVisibleRect = scrollableArea->visibleContentRect();
1474 1474
1475 // Convert the object rect into local coordinates. 1475 // Convert the object rect into local coordinates.
1476 if (!scrollParent->isWebArea()) { 1476 if (!scrollParent->isWebArea()) {
1477 objectRect.moveBy(scrollPosition); 1477 objectRect.moveBy(IntPoint(scrollOffset));
1478 objectRect.moveBy( 1478 objectRect.moveBy(
1479 -pixelSnappedIntRect(scrollParent->getBoundsInFrameCoordinates()) 1479 -pixelSnappedIntRect(scrollParent->getBoundsInFrameCoordinates())
1480 .location()); 1480 .location());
1481 } 1481 }
1482 1482
1483 int desiredX = 1483 int desiredX = computeBestScrollOffset(
1484 computeBestScrollOffset(scrollPosition.x(), objectRect.x() + subfocus.x(), 1484 scrollOffset.width(), objectRect.x() + subfocus.x(),
1485 objectRect.x() + subfocus.maxX(), objectRect.x(), 1485 objectRect.x() + subfocus.maxX(), objectRect.x(), objectRect.maxX(), 0,
1486 objectRect.maxX(), 0, scrollVisibleRect.width()); 1486 scrollVisibleRect.width());
1487 int desiredY = 1487 int desiredY = computeBestScrollOffset(
1488 computeBestScrollOffset(scrollPosition.y(), objectRect.y() + subfocus.y(), 1488 scrollOffset.height(), objectRect.y() + subfocus.y(),
1489 objectRect.y() + subfocus.maxY(), objectRect.y(), 1489 objectRect.y() + subfocus.maxY(), objectRect.y(), objectRect.maxY(), 0,
1490 objectRect.maxY(), 0, scrollVisibleRect.height()); 1490 scrollVisibleRect.height());
1491 1491
1492 scrollParent->setScrollOffset(IntPoint(desiredX, desiredY)); 1492 scrollParent->setScrollOffset(IntPoint(desiredX, desiredY));
1493 1493
1494 // Convert the subfocus into the coordinates of the scroll parent. 1494 // Convert the subfocus into the coordinates of the scroll parent.
1495 IntRect newSubfocus = subfocus; 1495 IntRect newSubfocus = subfocus;
1496 IntRect newElementRect = pixelSnappedIntRect(getBoundsInFrameCoordinates()); 1496 IntRect newElementRect = pixelSnappedIntRect(getBoundsInFrameCoordinates());
1497 IntRect scrollParentRect = 1497 IntRect scrollParentRect =
1498 pixelSnappedIntRect(scrollParent->getBoundsInFrameCoordinates()); 1498 pixelSnappedIntRect(scrollParent->getBoundsInFrameCoordinates());
1499 newSubfocus.move(newElementRect.x(), newElementRect.y()); 1499 newSubfocus.move(newElementRect.x(), newElementRect.y());
1500 newSubfocus.move(-scrollParentRect.x(), -scrollParentRect.y()); 1500 newSubfocus.move(-scrollParentRect.x(), -scrollParentRect.y());
(...skipping 24 matching lines...) Expand all
1525 const AXObject* outer = objects[i]; 1525 const AXObject* outer = objects[i];
1526 const AXObject* inner = objects[i + 1]; 1526 const AXObject* inner = objects[i + 1];
1527 ScrollableArea* scrollableArea = outer->getScrollableAreaIfScrollable(); 1527 ScrollableArea* scrollableArea = outer->getScrollableAreaIfScrollable();
1528 1528
1529 IntRect innerRect = 1529 IntRect innerRect =
1530 inner->isWebArea() 1530 inner->isWebArea()
1531 ? pixelSnappedIntRect( 1531 ? pixelSnappedIntRect(
1532 inner->parentObject()->getBoundsInFrameCoordinates()) 1532 inner->parentObject()->getBoundsInFrameCoordinates())
1533 : pixelSnappedIntRect(inner->getBoundsInFrameCoordinates()); 1533 : pixelSnappedIntRect(inner->getBoundsInFrameCoordinates());
1534 IntRect objectRect = innerRect; 1534 IntRect objectRect = innerRect;
1535 IntPoint scrollPosition = scrollableArea->scrollPosition(); 1535 IntSize scrollOffset = scrollableArea->scrollOffsetInt();
1536 1536
1537 // Convert the object rect into local coordinates. 1537 // Convert the object rect into local coordinates.
1538 objectRect.move(offsetX, offsetY); 1538 objectRect.move(offsetX, offsetY);
1539 if (!outer->isWebArea()) 1539 if (!outer->isWebArea())
1540 objectRect.move(scrollPosition.x(), scrollPosition.y()); 1540 objectRect.move(scrollOffset.width(), scrollOffset.height());
1541 1541
1542 int desiredX = computeBestScrollOffset(0, objectRect.x(), objectRect.maxX(), 1542 int desiredX = computeBestScrollOffset(0, objectRect.x(), objectRect.maxX(),
1543 objectRect.x(), objectRect.maxX(), 1543 objectRect.x(), objectRect.maxX(),
1544 point.x(), point.x()); 1544 point.x(), point.x());
1545 int desiredY = computeBestScrollOffset(0, objectRect.y(), objectRect.maxY(), 1545 int desiredY = computeBestScrollOffset(0, objectRect.y(), objectRect.maxY(),
1546 objectRect.y(), objectRect.maxY(), 1546 objectRect.y(), objectRect.maxY(),
1547 point.y(), point.y()); 1547 point.y(), point.y());
1548 outer->setScrollOffset(IntPoint(desiredX, desiredY)); 1548 outer->setScrollOffset(IntPoint(desiredX, desiredY));
1549 1549
1550 if (outer->isWebArea() && !inner->isWebArea()) { 1550 if (outer->isWebArea() && !inner->isWebArea()) {
1551 // If outer object we just scrolled is a web area (frame) but the inner 1551 // If outer object we just scrolled is a web area (frame) but the inner
1552 // object is not, keep track of the coordinate transformation to apply to 1552 // object is not, keep track of the coordinate transformation to apply to
1553 // future nested calculations. 1553 // future nested calculations.
1554 scrollPosition = scrollableArea->scrollPosition(); 1554 scrollOffset = scrollableArea->scrollOffsetInt();
1555 offsetX -= (scrollPosition.x() + point.x()); 1555 offsetX -= (scrollOffset.width() + point.x());
1556 offsetY -= (scrollPosition.y() + point.y()); 1556 offsetY -= (scrollOffset.height() + point.y());
1557 point.move(scrollPosition.x() - innerRect.x(), 1557 point.move(scrollOffset.width() - innerRect.width(),
1558 scrollPosition.y() - innerRect.y()); 1558 scrollOffset.height() - innerRect.y());
1559 } else if (inner->isWebArea()) { 1559 } else if (inner->isWebArea()) {
1560 // Otherwise, if the inner object is a web area, reset the coordinate 1560 // Otherwise, if the inner object is a web area, reset the coordinate
1561 // transformation. 1561 // transformation.
1562 offsetX = 0; 1562 offsetX = 0;
1563 offsetY = 0; 1563 offsetY = 0;
1564 } 1564 }
1565 } 1565 }
1566 } 1566 }
1567 1567
1568 void AXObject::notifyIfIgnoredValueChanged() { 1568 void AXObject::notifyIfIgnoredValueChanged() {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
1733 } 1733 }
1734 1734
1735 DEFINE_TRACE(AXObject) { 1735 DEFINE_TRACE(AXObject) {
1736 visitor->trace(m_children); 1736 visitor->trace(m_children);
1737 visitor->trace(m_parent); 1737 visitor->trace(m_parent);
1738 visitor->trace(m_cachedLiveRegionRoot); 1738 visitor->trace(m_cachedLiveRegionRoot);
1739 visitor->trace(m_axObjectCache); 1739 visitor->trace(m_axObjectCache);
1740 } 1740 }
1741 1741
1742 } // namespace blink 1742 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698