MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / CalculateClickPoint

Method CalculateClickPoint

cpp/iedriver/Element.cpp:1496–1556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1494}
1495
1496LocationInfo Element::CalculateClickPoint(const LocationInfo location, const bool document_contains_frames) {
1497 LOG(TRACE) << "Entering Element::CalculateClickPoint";
1498
1499 long corrected_width = location.width;
1500 long corrected_height = location.height;
1501 long corrected_x = location.x;
1502 long corrected_y = location.y;
1503
1504 LocationInfo clickable_viewport = {};
1505 bool result = this->GetClickableViewPortLocation(document_contains_frames,
1506 &clickable_viewport);
1507
1508 if (result) {
1509 // TODO: Handle the case where the center of the target element
1510 // is already in the view port. The code would look something like
1511 // the following:
1512 // If the center of the target element is already in the view port,
1513 // we don't need to adjust to find the "in view center point."
1514 // Technically, this is a deliberate violation of the spec.
1515 //long element_center_x = location.x + static_cast<long>(floor(location.width / 2.0));
1516 //long element_center_y = location.y + static_cast<long>(floor(location.height / 2.0));
1517 //if (element_center_x < 0 ||
1518 // element_center_x >= clickable_viewport.width ||
1519 // element_center_y < 0 ||
1520 // element_center_y >= clickable_viewport.height) {
1521 RECT element_rect;
1522 element_rect.left = location.x;
1523 element_rect.top = location.y;
1524 element_rect.right = location.x + location.width;
1525 element_rect.bottom = location.y + location.height;
1526
1527 RECT viewport_rect;
1528 viewport_rect.left = clickable_viewport.x;
1529 viewport_rect.top = clickable_viewport.y;
1530 viewport_rect.right = clickable_viewport.x + clickable_viewport.width;
1531 viewport_rect.bottom = clickable_viewport.y + clickable_viewport.height;
1532
1533 RECT intersect_rect;
1534 BOOL is_intersecting = ::IntersectRect(&intersect_rect,
1535 &element_rect,
1536 &viewport_rect);
1537 if (is_intersecting) {
1538 corrected_width = intersect_rect.right - intersect_rect.left;
1539 corrected_height = intersect_rect.bottom - intersect_rect.top;
1540 // If the x or y coordinate is greater than or equal to zero, the
1541 // initial location will already be correct, and not need to be
1542 // adjusted.
1543 if (location.x < 0) {
1544 corrected_x = 0;
1545 }
1546 if (location.y < 0) {
1547 corrected_y = 0;
1548 }
1549 }
1550 }
1551
1552 LocationInfo click_location = {};
1553 click_location.x = corrected_x + static_cast<long>(floor(corrected_width / 2.0));

Callers 3

IsObscuredMethod · 0.95

Calls 2

LOGClass · 0.50

Tested by

no test coverage detected