本文整理汇总了C++中LayoutUnit::abs方法的典型用法代码示例。如果您正苦于以下问题:C++ LayoutUnit::abs方法的具体用法?C++ LayoutUnit::abs怎么用?C++ LayoutUnit::abs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LayoutUnit
的用法示例。
在下文中一共展示了LayoutUnit::abs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: distanceDataForNode
void distanceDataForNode(FocusType type, const FocusCandidate& current, FocusCandidate& candidate)
{
if (areElementsOnSameLine(current, candidate)) {
if ((type == FocusTypeUp && current.rect.y() > candidate.rect.y()) || (type == FocusTypeDown && candidate.rect.y() > current.rect.y())) {
candidate.distance = 0;
candidate.alignment = Full;
return;
}
}
LayoutRect nodeRect = candidate.rect;
LayoutRect currentRect = current.rect;
deflateIfOverlapped(currentRect, nodeRect);
if (!isRectInDirection(type, currentRect, nodeRect))
return;
LayoutPoint exitPoint;
LayoutPoint entryPoint;
entryAndExitPointsForDirection(type, currentRect, nodeRect, exitPoint, entryPoint);
LayoutUnit xAxis = exitPoint.x() - entryPoint.x();
LayoutUnit yAxis = exitPoint.y() - entryPoint.y();
LayoutUnit navigationAxisDistance;
LayoutUnit orthogonalAxisDistance;
switch (type) {
case FocusTypeLeft:
case FocusTypeRight:
navigationAxisDistance = xAxis.abs();
orthogonalAxisDistance = yAxis.abs();
break;
case FocusTypeUp:
case FocusTypeDown:
navigationAxisDistance = yAxis.abs();
orthogonalAxisDistance = xAxis.abs();
break;
default:
ASSERT_NOT_REACHED();
return;
}
double euclidianDistancePow2 = (xAxis * xAxis + yAxis * yAxis).toDouble();
LayoutRect intersectionRect = intersection(currentRect, nodeRect);
double overlap = (intersectionRect.width() * intersectionRect.height()).toDouble();
// Distance calculation is based on http://www.w3.org/TR/WICD/#focus-handling
candidate.distance = sqrt(euclidianDistancePow2) + navigationAxisDistance+ orthogonalAxisDistance * 2 - sqrt(overlap);
LayoutSize viewSize = candidate.visibleNode->document().page()->deprecatedLocalMainFrame()->view()->visibleContentRect().size();
candidate.alignment = alignmentForRects(type, currentRect, nodeRect, viewSize);
}