Commit 2d5634fd authored by Lan Wei's avatar Lan Wei Committed by Commit Bot

Get the element central location correctly if there is drop down menu

When we calculate the element's central location, we need to consider
about the overflow case that the element's view area is less than its
actually area. For the drop down menu bar, the drop down menu list's
parent is the menu bar, which does not have any overlap with the menu
item, so we should consider about the parent's boundary when there is
no overlap between the element's area and the parent's area.

Bug: chromedriver:3205
Change-Id: I39c8292dc730cf23a562ed206ddaccb09a5b36c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1908057
Commit-Queue: Lan Wei <lanwei@chromium.org>
Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714587}
parent 379d7592
...@@ -20,8 +20,8 @@ function getInViewPoint(element) { ...@@ -20,8 +20,8 @@ function getInViewPoint(element) {
var top = Math.max(0, rect.top); var top = Math.max(0, rect.top);
var bottom = Math.min(window.innerHeight, rect.bottom); var bottom = Math.min(window.innerHeight, rect.bottom);
// Find the view boundry of the element by checking itself and all of its // Find the view boundary of the element by checking itself and all of its
// ancestor's boundry. // ancestor's boundary.
while (element.parentElement != null && while (element.parentElement != null &&
element.parentElement != document.body && element.parentElement != document.body &&
element.parentElement.getClientRects().length > 0) { element.parentElement.getClientRects().length > 0) {
...@@ -30,21 +30,26 @@ function getInViewPoint(element) { ...@@ -30,21 +30,26 @@ function getInViewPoint(element) {
var overflowX = parentStyle.getPropertyValue("overflow-x"); var overflowX = parentStyle.getPropertyValue("overflow-x");
var overflowY = parentStyle.getPropertyValue("overflow-y"); var overflowY = parentStyle.getPropertyValue("overflow-y");
var parentRect = getParentRect(element); var parentRect = getParentRect(element);
if (overflow == "auto" || overflow == "scroll" || overflow == "hidden") { // Only consider about overflow cases when the parent area overlaps with
left = Math.max(left, parentRect.left); // the element's area.
right = Math.min(right, parentRect.right); if (parentRect.right > left && parentRect.bottom > top &&
top = Math.max(top, parentRect.top); right > parentRect.left && bottom > parentRect.top) {
bottom = Math.min(bottom, parentRect.bottom); if (overflow == "auto" || overflow == "scroll" || overflow == "hidden") {
} else {
if (overflowX == "auto" || overflowX == "scroll" ||
overflowX == "hidden") {
left = Math.max(left, parentRect.left); left = Math.max(left, parentRect.left);
right = Math.min(right, parentRect.right); right = Math.min(right, parentRect.right);
}
if (overflowY == "auto" || overflowY == "scroll" ||
overflowY == "hidden") {
top = Math.max(top, parentRect.top); top = Math.max(top, parentRect.top);
bottom = Math.min(bottom, parentRect.bottom); bottom = Math.min(bottom, parentRect.bottom);
} else {
if (overflowX == "auto" || overflowX == "scroll" ||
overflowX == "hidden") {
left = Math.max(left, parentRect.left);
right = Math.min(right, parentRect.right);
}
if (overflowY == "auto" || overflowY == "scroll" ||
overflowY == "hidden") {
top = Math.max(top, parentRect.top);
bottom = Math.min(bottom, parentRect.bottom);
}
} }
} }
element = element.parentElement; element = element.parentElement;
...@@ -52,7 +57,6 @@ function getInViewPoint(element) { ...@@ -52,7 +57,6 @@ function getInViewPoint(element) {
var x = 0.5 * (left + right); var x = 0.5 * (left + right);
var y = 0.5 * (top + bottom); var y = 0.5 * (top + bottom);
return [x, y, left, top]; return [x, y, left, top];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment