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

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

Issue 1121473004: Expose scroll containers via accessibility APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Move scrolling logic from ScrollView to WebArea Created 5 years, 7 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
« no previous file with comments | « Source/modules/accessibility/AXObject.h ('k') | Source/modules/accessibility/AXScrollView.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1016 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 if (!elementNode) 1027 if (!elementNode)
1028 return nullAtom; 1028 return nullAtom;
1029 1029
1030 if (!elementNode->isElementNode()) 1030 if (!elementNode->isElementNode())
1031 return nullAtom; 1031 return nullAtom;
1032 1032
1033 Element* element = toElement(elementNode); 1033 Element* element = toElement(elementNode);
1034 return element->fastGetAttribute(attribute); 1034 return element->fastGetAttribute(attribute);
1035 } 1035 }
1036 1036
1037 //
1038 // Scrollable containers.
1039 //
1040
1041 //
dglazkov 2015/05/07 18:59:08 Do we need both of these comments?
dmazzoni 2015/05/13 22:07:38 Done.
1042 // Scrollable containers.
1043 //
1044
1045 bool AXObject::isScrollableContainer() const
1046 {
1047 return !!getScrollableAreaIfScrollable();
1048 }
1049
1050 IntPoint AXObject::scrollOffset() const
1051 {
1052 ScrollableArea* area = getScrollableAreaIfScrollable();
1053 if (!area)
1054 return IntPoint();
1055
1056 return IntPoint(area->scrollPosition().x(), area->scrollPosition().y());
1057 }
1058
1059 IntPoint AXObject::minimumScrollOffset() const
1060 {
1061 ScrollableArea* area = getScrollableAreaIfScrollable();
1062 if (!area)
1063 return IntPoint();
1064
1065 return IntPoint(area->minimumScrollPosition().x(), area->minimumScrollPositi on().y());
1066 }
1067
1068 IntPoint AXObject::maximumScrollOffset() const
1069 {
1070 ScrollableArea* area = getScrollableAreaIfScrollable();
1071 if (!area)
1072 return IntPoint();
1073
1074 return IntPoint(area->maximumScrollPosition().x(), area->maximumScrollPositi on().y());
1075 }
1076
1077 void AXObject::setScrollOffset(const IntPoint& offset) const
1078 {
1079 ScrollableArea* area = getScrollableAreaIfScrollable();
1080 if (!area)
1081 return;
1082
1083 area->setScrollPosition(DoublePoint(offset.x(), offset.y()));
1084 }
1085
1086 //
1087 // Modify or take an action on an object.
1088 //
1089
1037 bool AXObject::press() const 1090 bool AXObject::press() const
1038 { 1091 {
1039 Element* actionElem = actionElement(); 1092 Element* actionElem = actionElement();
1040 if (!actionElem) 1093 if (!actionElem)
1041 return false; 1094 return false;
1042 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture); 1095 UserGestureIndicator gestureIndicator(DefinitelyProcessingNewUserGesture);
1043 actionElem->accessKeyAction(true); 1096 actionElem->accessKeyAction(true);
1044 return true; 1097 return true;
1045 } 1098 }
1046 1099
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 return (objectMin + objectMax - viewportMin - viewportMax) / 2; 1195 return (objectMin + objectMax - viewportMin - viewportMax) / 2;
1143 } 1196 }
1144 1197
1145 void AXObject::scrollToMakeVisibleWithSubFocus(const IntRect& subfocus) const 1198 void AXObject::scrollToMakeVisibleWithSubFocus(const IntRect& subfocus) const
1146 { 1199 {
1147 // Search up the parent chain until we find the first one that's scrollable. 1200 // Search up the parent chain until we find the first one that's scrollable.
1148 AXObject* scrollParent = parentObject(); 1201 AXObject* scrollParent = parentObject();
1149 ScrollableArea* scrollableArea = 0; 1202 ScrollableArea* scrollableArea = 0;
1150 while (scrollParent) { 1203 while (scrollParent) {
1151 scrollableArea = scrollParent->getScrollableAreaIfScrollable(); 1204 scrollableArea = scrollParent->getScrollableAreaIfScrollable();
1152 if (scrollableArea) 1205 if (scrollableArea && !scrollParent->isAXScrollView())
1153 break; 1206 break;
1154 scrollParent = scrollParent->parentObject(); 1207 scrollParent = scrollParent->parentObject();
1155 } 1208 }
1156 if (!scrollParent || !scrollableArea) 1209 if (!scrollParent || !scrollableArea)
1157 return; 1210 return;
1158 1211
1159 IntRect objectRect = pixelSnappedIntRect(elementRect()); 1212 IntRect objectRect = pixelSnappedIntRect(elementRect());
1160 IntPoint scrollPosition = scrollableArea->scrollPosition(); 1213 IntPoint scrollPosition = scrollableArea->scrollPosition();
1161 IntRect scrollVisibleRect = scrollableArea->visibleContentRect(); 1214 IntRect scrollVisibleRect = scrollableArea->visibleContentRect();
1162 1215
1163 // Convert the object rect into local coordinates. 1216 // Convert the object rect into local coordinates.
1164 if (!scrollParent->isAXScrollView()) { 1217 if (!scrollParent->isWebArea()) {
1165 objectRect.moveBy(scrollPosition); 1218 objectRect.moveBy(scrollPosition);
1166 objectRect.moveBy(-pixelSnappedIntRect(scrollParent->elementRect()).loca tion()); 1219 objectRect.moveBy(-pixelSnappedIntRect(scrollParent->elementRect()).loca tion());
1167 } 1220 }
1168 1221
1169 int desiredX = computeBestScrollOffset( 1222 int desiredX = computeBestScrollOffset(
1170 scrollPosition.x(), 1223 scrollPosition.x(),
1171 objectRect.x() + subfocus.x(), objectRect.x() + subfocus.maxX(), 1224 objectRect.x() + subfocus.x(), objectRect.x() + subfocus.maxX(),
1172 objectRect.x(), objectRect.maxX(), 1225 objectRect.x(), objectRect.maxX(),
1173 0, scrollVisibleRect.width()); 1226 0, scrollVisibleRect.width());
1174 int desiredY = computeBestScrollOffset( 1227 int desiredY = computeBestScrollOffset(
1175 scrollPosition.y(), 1228 scrollPosition.y(),
1176 objectRect.y() + subfocus.y(), objectRect.y() + subfocus.maxY(), 1229 objectRect.y() + subfocus.y(), objectRect.y() + subfocus.maxY(),
1177 objectRect.y(), objectRect.maxY(), 1230 objectRect.y(), objectRect.maxY(),
1178 0, scrollVisibleRect.height()); 1231 0, scrollVisibleRect.height());
1179 1232
1180 scrollParent->scrollTo(IntPoint(desiredX, desiredY)); 1233 scrollParent->setScrollOffset(IntPoint(desiredX, desiredY));
1181 1234
1182 // Convert the subfocus into the coordinates of the scroll parent. 1235 // Convert the subfocus into the coordinates of the scroll parent.
1183 IntRect newSubfocus = subfocus; 1236 IntRect newSubfocus = subfocus;
1184 IntRect newElementRect = pixelSnappedIntRect(elementRect()); 1237 IntRect newElementRect = pixelSnappedIntRect(elementRect());
1185 IntRect scrollParentRect = pixelSnappedIntRect(scrollParent->elementRect()); 1238 IntRect scrollParentRect = pixelSnappedIntRect(scrollParent->elementRect());
1186 newSubfocus.move(newElementRect.x(), newElementRect.y()); 1239 newSubfocus.move(newElementRect.x(), newElementRect.y());
1187 newSubfocus.move(-scrollParentRect.x(), -scrollParentRect.y()); 1240 newSubfocus.move(-scrollParentRect.x(), -scrollParentRect.y());
1188 1241
1189 // Recursively make sure the scroll parent itself is visible. 1242 // Recursively make sure the scroll parent itself is visible.
1190 if (scrollParent->parentObject()) 1243 if (scrollParent->parentObject())
1191 scrollParent->scrollToMakeVisibleWithSubFocus(newSubfocus); 1244 scrollParent->scrollToMakeVisibleWithSubFocus(newSubfocus);
1192 } 1245 }
1193 1246
1194 void AXObject::scrollToGlobalPoint(const IntPoint& globalPoint) const 1247 void AXObject::scrollToGlobalPoint(const IntPoint& globalPoint) const
1195 { 1248 {
1196 // Search up the parent chain and create a vector of all scrollable parent o bjects 1249 // Search up the parent chain and create a vector of all scrollable parent o bjects
1197 // and ending with this object itself. 1250 // and ending with this object itself.
1198 Vector<const AXObject*> objects; 1251 Vector<const AXObject*> objects;
1199 AXObject* parentObject; 1252 AXObject* parentObject;
1200 for (parentObject = this->parentObject(); parentObject; parentObject = paren tObject->parentObject()) { 1253 for (parentObject = this->parentObject(); parentObject; parentObject = paren tObject->parentObject()) {
1201 if (parentObject->getScrollableAreaIfScrollable()) 1254 if (parentObject->getScrollableAreaIfScrollable() && !parentObject->isAX ScrollView())
1202 objects.prepend(parentObject); 1255 objects.prepend(parentObject);
1203 } 1256 }
1204 objects.append(this); 1257 objects.append(this);
1205 1258
1206 // Start with the outermost scrollable (the main window) and try to scroll t he 1259 // Start with the outermost scrollable (the main window) and try to scroll t he
1207 // next innermost object to the given point. 1260 // next innermost object to the given point.
1208 int offsetX = 0, offsetY = 0; 1261 int offsetX = 0, offsetY = 0;
1209 IntPoint point = globalPoint; 1262 IntPoint point = globalPoint;
1210 size_t levels = objects.size() - 1; 1263 size_t levels = objects.size() - 1;
1211 for (size_t i = 0; i < levels; i++) { 1264 for (size_t i = 0; i < levels; i++) {
1212 const AXObject* outer = objects[i]; 1265 const AXObject* outer = objects[i];
1213 const AXObject* inner = objects[i + 1]; 1266 const AXObject* inner = objects[i + 1];
1214
1215 ScrollableArea* scrollableArea = outer->getScrollableAreaIfScrollable(); 1267 ScrollableArea* scrollableArea = outer->getScrollableAreaIfScrollable();
1216 1268
1217 IntRect innerRect = inner->isAXScrollView() ? pixelSnappedIntRect(inner- >parentObject()->elementRect()) : pixelSnappedIntRect(inner->elementRect()); 1269 IntRect innerRect = inner->isWebArea() ? pixelSnappedIntRect(inner->pare ntObject()->elementRect()) : pixelSnappedIntRect(inner->elementRect());
1218 IntRect objectRect = innerRect; 1270 IntRect objectRect = innerRect;
1219 IntPoint scrollPosition = scrollableArea->scrollPosition(); 1271 IntPoint scrollPosition = scrollableArea->scrollPosition();
1220 1272
1221 // Convert the object rect into local coordinates. 1273 // Convert the object rect into local coordinates.
1222 objectRect.move(offsetX, offsetY); 1274 objectRect.move(offsetX, offsetY);
1223 if (!outer->isAXScrollView()) 1275 if (!outer->isWebArea())
1224 objectRect.move(scrollPosition.x(), scrollPosition.y()); 1276 objectRect.move(scrollPosition.x(), scrollPosition.y());
1225 1277
1226 int desiredX = computeBestScrollOffset( 1278 int desiredX = computeBestScrollOffset(
1227 0, 1279 0,
1228 objectRect.x(), objectRect.maxX(), 1280 objectRect.x(), objectRect.maxX(),
1229 objectRect.x(), objectRect.maxX(), 1281 objectRect.x(), objectRect.maxX(),
1230 point.x(), point.x()); 1282 point.x(), point.x());
1231 int desiredY = computeBestScrollOffset( 1283 int desiredY = computeBestScrollOffset(
1232 0, 1284 0,
1233 objectRect.y(), objectRect.maxY(), 1285 objectRect.y(), objectRect.maxY(),
1234 objectRect.y(), objectRect.maxY(), 1286 objectRect.y(), objectRect.maxY(),
1235 point.y(), point.y()); 1287 point.y(), point.y());
1236 outer->scrollTo(IntPoint(desiredX, desiredY)); 1288 outer->setScrollOffset(IntPoint(desiredX, desiredY));
1237 1289
1238 if (outer->isAXScrollView() && !inner->isAXScrollView()) { 1290 if (outer->isWebArea() && !inner->isWebArea()) {
1239 // If outer object we just scrolled is a scroll view (main window or iframe) but the 1291 // If outer object we just scrolled is a web area (frame) but the in ner object
1240 // inner object is not, keep track of the coordinate transformation to apply to 1292 // is not, keep track of the coordinate transformation to apply to
1241 // future nested calculations. 1293 // future nested calculations.
1242 scrollPosition = scrollableArea->scrollPosition(); 1294 scrollPosition = scrollableArea->scrollPosition();
1243 offsetX -= (scrollPosition.x() + point.x()); 1295 offsetX -= (scrollPosition.x() + point.x());
1244 offsetY -= (scrollPosition.y() + point.y()); 1296 offsetY -= (scrollPosition.y() + point.y());
1245 point.move(scrollPosition.x() - innerRect.x(), scrollPosition.y() - innerRect.y()); 1297 point.move(scrollPosition.x() - innerRect.x(), scrollPosition.y() - innerRect.y());
1246 } else if (inner->isAXScrollView()) { 1298 } else if (inner->isWebArea()) {
1247 // Otherwise, if the inner object is a scroll view, reset the coordi nate transformation. 1299 // Otherwise, if the inner object is a web area, reset the coordinat e transformation.
1248 offsetX = 0; 1300 offsetX = 0;
1249 offsetY = 0; 1301 offsetY = 0;
1250 } 1302 }
1251 } 1303 }
1252 } 1304 }
1253 1305
1254 void AXObject::notifyIfIgnoredValueChanged() 1306 void AXObject::notifyIfIgnoredValueChanged()
1255 { 1307 {
1256 bool isIgnored = accessibilityIsIgnored(); 1308 bool isIgnored = accessibilityIsIgnored();
1257 if (lastKnownIsIgnoredValue() != isIgnored) { 1309 if (lastKnownIsIgnoredValue() != isIgnored) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 } 1439 }
1388 1440
1389 const AtomicString& AXObject::internalRoleName(AccessibilityRole role) 1441 const AtomicString& AXObject::internalRoleName(AccessibilityRole role)
1390 { 1442 {
1391 static const Vector<AtomicString>* internalRoleNameVector = createInternalRo leNameVector(); 1443 static const Vector<AtomicString>* internalRoleNameVector = createInternalRo leNameVector();
1392 1444
1393 return internalRoleNameVector->at(role); 1445 return internalRoleNameVector->at(role);
1394 } 1446 }
1395 1447
1396 } // namespace blink 1448 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/accessibility/AXObject.h ('k') | Source/modules/accessibility/AXScrollView.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698