Commit 39616000 authored by JunHo Seo's avatar JunHo Seo Committed by Commit Bot

Snav: Use argument name 'direction' instead 'type'

'type' doesn't give much information. Use more informative name.

Bug: 770147

Change-Id: Iad53dfc11347c149f1d076cc5c326437df2f28c4
Reviewed-on: https://chromium-review.googlesource.com/989387
Commit-Queue: JunHo Seo <junho0924.seo@lge.com>
Reviewed-by: default avatarHugo Holgersson <hugoh@vewd.com>
Reviewed-by: default avatarStefan Zager <szager@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549437}
parent d9ccc270
...@@ -1247,7 +1247,7 @@ void FocusController::SetActive(bool active) { ...@@ -1247,7 +1247,7 @@ void FocusController::SetActive(bool active) {
} }
} }
static void UpdateFocusCandidateIfNeeded(WebFocusType type, static void UpdateFocusCandidateIfNeeded(WebFocusType direction,
const FocusCandidate& current, const FocusCandidate& current,
FocusCandidate& candidate, FocusCandidate& candidate,
FocusCandidate& closest) { FocusCandidate& closest) {
...@@ -1262,10 +1262,10 @@ static void UpdateFocusCandidateIfNeeded(WebFocusType type, ...@@ -1262,10 +1262,10 @@ static void UpdateFocusCandidateIfNeeded(WebFocusType type,
// Ignore off screen child nodes of containers that do not scroll // Ignore off screen child nodes of containers that do not scroll
// (overflow:hidden) // (overflow:hidden)
if (candidate.is_offscreen && !CanBeScrolledIntoView(type, candidate)) if (candidate.is_offscreen && !CanBeScrolledIntoView(direction, candidate))
return; return;
DistanceDataForNode(type, current, candidate); DistanceDataForNode(direction, current, candidate);
if (candidate.distance == MaxDistance()) if (candidate.distance == MaxDistance())
return; return;
...@@ -1314,7 +1314,7 @@ static void UpdateFocusCandidateIfNeeded(WebFocusType type, ...@@ -1314,7 +1314,7 @@ static void UpdateFocusCandidateIfNeeded(WebFocusType type,
void FocusController::FindFocusCandidateInContainer( void FocusController::FindFocusCandidateInContainer(
Node& container, Node& container,
const LayoutRect& starting_rect, const LayoutRect& starting_rect,
WebFocusType type, WebFocusType direction,
FocusCandidate& closest, FocusCandidate& closest,
const SkipList& already_checked) { const SkipList& already_checked) {
if (already_checked.Contains(&container)) if (already_checked.Contains(&container))
...@@ -1333,31 +1333,32 @@ void FocusController::FindFocusCandidateInContainer( ...@@ -1333,31 +1333,32 @@ void FocusController::FindFocusCandidateInContainer(
for (; element; for (; element;
element = element =
(IsNavigableContainer(element, type)) (IsNavigableContainer(element, direction))
? ElementTraversal::NextSkippingChildren(*element, &container) ? ElementTraversal::NextSkippingChildren(*element, &container)
: ElementTraversal::Next(*element, &container)) { : ElementTraversal::Next(*element, &container)) {
if (element == focused_element) if (element == focused_element)
continue; continue;
if (!element->IsKeyboardFocusable() && !IsNavigableContainer(element, type)) if (!element->IsKeyboardFocusable() &&
!IsNavigableContainer(element, direction))
continue; continue;
if (already_checked.Contains(element)) if (already_checked.Contains(element))
continue; continue;
FocusCandidate candidate = FocusCandidate(element, type); FocusCandidate candidate = FocusCandidate(element, direction);
if (candidate.IsNull()) if (candidate.IsNull())
continue; continue;
candidate.enclosing_scrollable_box = &container; candidate.enclosing_scrollable_box = &container;
UpdateFocusCandidateIfNeeded(type, current, candidate, closest); UpdateFocusCandidateIfNeeded(direction, current, candidate, closest);
} }
} }
bool FocusController::AdvanceFocusDirectionallyInContainer( bool FocusController::AdvanceFocusDirectionallyInContainer(
Node* start_container, Node* start_container,
const LayoutRect& starting_rect, const LayoutRect& starting_rect,
WebFocusType type, WebFocusType direction,
Node* pruned_sub_tree_root) { Node* pruned_sub_tree_root) {
if (!start_container) if (!start_container)
return false; return false;
...@@ -1373,26 +1374,26 @@ bool FocusController::AdvanceFocusDirectionallyInContainer( ...@@ -1373,26 +1374,26 @@ bool FocusController::AdvanceFocusDirectionallyInContainer(
Node* container = stack.back(); Node* container = stack.back();
FocusCandidate candidate; FocusCandidate candidate;
FindFocusCandidateInContainer(*container, starting_rect, type, candidate, FindFocusCandidateInContainer(*container, starting_rect, direction,
already_checked); candidate, already_checked);
if (candidate.IsNull()) { if (candidate.IsNull()) {
// Nothing to focus in this container, scroll if possible. // Nothing to focus in this container, scroll if possible.
// NOTE: If no scrolling is performed (i.e. ScrollInDirection returns // NOTE: If no scrolling is performed (i.e. ScrollInDirection returns
// false), the spatial navigation algorithm will skip this container. // false), the spatial navigation algorithm will skip this container.
if (ScrollInDirection(container, type)) if (ScrollInDirection(container, direction))
return true; return true;
stack.pop_back(); stack.pop_back();
continue; continue;
} }
if (!IsNavigableContainer(candidate.visible_node, type)) { if (!IsNavigableContainer(candidate.visible_node, direction)) {
// We found a new focus node, navigate to it. // We found a new focus node, navigate to it.
Element* element = ToElement(candidate.focusable_node); Element* element = ToElement(candidate.focusable_node);
DCHECK(element); DCHECK(element);
element->focus( element->focus(
FocusParams(SelectionBehaviorOnFocus::kReset, type, nullptr)); FocusParams(SelectionBehaviorOnFocus::kReset, direction, nullptr));
return true; return true;
} }
...@@ -1418,10 +1419,10 @@ bool FocusController::AdvanceFocusDirectionallyInContainer( ...@@ -1418,10 +1419,10 @@ bool FocusController::AdvanceFocusDirectionallyInContainer(
stack.push_back(candidate.visible_node); stack.push_back(candidate.visible_node);
} }
return ScrollInDirection(start_container, type); return ScrollInDirection(start_container, direction);
} }
bool FocusController::AdvanceFocusDirectionally(WebFocusType type) { bool FocusController::AdvanceFocusDirectionally(WebFocusType direction) {
// FIXME: Directional focus changes don't yet work with RemoteFrames. // FIXME: Directional focus changes don't yet work with RemoteFrames.
if (!FocusedOrMainFrame()->IsLocalFrame()) if (!FocusedOrMainFrame()->IsLocalFrame())
return false; return false;
...@@ -1439,13 +1440,14 @@ bool FocusController::AdvanceFocusDirectionally(WebFocusType type) { ...@@ -1439,13 +1440,14 @@ bool FocusController::AdvanceFocusDirectionally(WebFocusType type) {
if (focused_element) if (focused_element)
container = ScrollableAreaOrDocumentOf(focused_element); container = ScrollableAreaOrDocumentOf(focused_element);
const LayoutRect starting_rect = FindSearchStartPoint(current_frame, type); const LayoutRect starting_rect =
FindSearchStartPoint(current_frame, direction);
Node* pruned_sub_tree_root = nullptr; Node* pruned_sub_tree_root = nullptr;
bool consumed = false; bool consumed = false;
while (!consumed && container) { while (!consumed && container) {
consumed = AdvanceFocusDirectionallyInContainer(container, starting_rect, consumed = AdvanceFocusDirectionallyInContainer(
type, pruned_sub_tree_root); container, starting_rect, direction, pruned_sub_tree_root);
if (consumed) if (consumed)
break; break;
......
...@@ -49,7 +49,7 @@ using namespace HTMLNames; ...@@ -49,7 +49,7 @@ using namespace HTMLNames;
static void DeflateIfOverlapped(LayoutRect&, LayoutRect&); static void DeflateIfOverlapped(LayoutRect&, LayoutRect&);
static bool IsScrollableNode(const Node*); static bool IsScrollableNode(const Node*);
FocusCandidate::FocusCandidate(Node* node, WebFocusType type) FocusCandidate::FocusCandidate(Node* node, WebFocusType direction)
: visible_node(nullptr), : visible_node(nullptr),
focusable_node(nullptr), focusable_node(nullptr),
enclosing_scrollable_box(nullptr), enclosing_scrollable_box(nullptr),
...@@ -65,7 +65,8 @@ FocusCandidate::FocusCandidate(Node* node, WebFocusType type) ...@@ -65,7 +65,8 @@ FocusCandidate::FocusCandidate(Node* node, WebFocusType type)
return; return;
visible_node = image; visible_node = image;
rect_in_root_frame = VirtualRectForAreaElementAndDirection(*area, type); rect_in_root_frame =
VirtualRectForAreaElementAndDirection(*area, direction);
} else { } else {
if (!node->GetLayoutObject()) if (!node->GetLayoutObject())
return; return;
...@@ -76,7 +77,7 @@ FocusCandidate::FocusCandidate(Node* node, WebFocusType type) ...@@ -76,7 +77,7 @@ FocusCandidate::FocusCandidate(Node* node, WebFocusType type)
focusable_node = node; focusable_node = node;
is_offscreen = HasOffscreenRect(visible_node); is_offscreen = HasOffscreenRect(visible_node);
is_offscreen_after_scrolling = HasOffscreenRect(visible_node, type); is_offscreen_after_scrolling = HasOffscreenRect(visible_node, direction);
} }
bool IsSpatialNavigationEnabled(const LocalFrame* frame) { bool IsSpatialNavigationEnabled(const LocalFrame* frame) {
...@@ -89,10 +90,10 @@ bool SpatialNavigationIgnoresEventHandlers(const LocalFrame* frame) { ...@@ -89,10 +90,10 @@ bool SpatialNavigationIgnoresEventHandlers(const LocalFrame* frame) {
frame->GetSettings()->GetDeviceSupportsTouch()); frame->GetSettings()->GetDeviceSupportsTouch());
} }
static bool RectsIntersectOnOrthogonalAxis(WebFocusType type, static bool RectsIntersectOnOrthogonalAxis(WebFocusType direction,
const LayoutRect& a, const LayoutRect& a,
const LayoutRect& b) { const LayoutRect& b) {
switch (type) { switch (direction) {
case kWebFocusTypeLeft: case kWebFocusTypeLeft:
case kWebFocusTypeRight: case kWebFocusTypeRight:
return a.MaxY() > b.Y() && a.Y() < b.MaxY(); return a.MaxY() > b.Y() && a.Y() < b.MaxY();
...@@ -121,10 +122,10 @@ static inline bool RightOf(const LayoutRect& a, const LayoutRect& b) { ...@@ -121,10 +122,10 @@ static inline bool RightOf(const LayoutRect& a, const LayoutRect& b) {
a.Y() < b.MaxY() && a.MaxY() > b.Y()); a.Y() < b.MaxY() && a.MaxY() > b.Y());
} }
static bool IsRectInDirection(WebFocusType type, static bool IsRectInDirection(WebFocusType direction,
const LayoutRect& cur_rect, const LayoutRect& cur_rect,
const LayoutRect& target_rect) { const LayoutRect& target_rect) {
switch (type) { switch (direction) {
case kWebFocusTypeLeft: case kWebFocusTypeLeft:
return RightOf(cur_rect, target_rect); return RightOf(cur_rect, target_rect);
case kWebFocusTypeRight: case kWebFocusTypeRight:
...@@ -142,7 +143,7 @@ static bool IsRectInDirection(WebFocusType type, ...@@ -142,7 +143,7 @@ static bool IsRectInDirection(WebFocusType type,
// Checks if |node| is offscreen the visible area (viewport) of its container // Checks if |node| is offscreen the visible area (viewport) of its container
// document. In case it is, one can scroll in direction or take any different // document. In case it is, one can scroll in direction or take any different
// desired action later on. // desired action later on.
bool HasOffscreenRect(const Node* node, WebFocusType type) { bool HasOffscreenRect(const Node* node, WebFocusType direction) {
// Get the LocalFrameView in which |node| is (which means the current viewport // Get the LocalFrameView in which |node| is (which means the current viewport
// if |node| is not in an inner document), so we can check if its content rect // if |node| is not in an inner document), so we can check if its content rect
// is visible before we actually move the focus to it. // is visible before we actually move the focus to it.
...@@ -160,7 +161,7 @@ bool HasOffscreenRect(const Node* node, WebFocusType type) { ...@@ -160,7 +161,7 @@ bool HasOffscreenRect(const Node* node, WebFocusType type) {
// direction and we do not adjust for scrolling. // direction and we do not adjust for scrolling.
int pixels_per_line_step = int pixels_per_line_step =
ScrollableArea::PixelsPerLineStep(frame_view->GetChromeClient()); ScrollableArea::PixelsPerLineStep(frame_view->GetChromeClient());
switch (type) { switch (direction) {
case kWebFocusTypeLeft: case kWebFocusTypeLeft:
container_viewport_rect.SetX(container_viewport_rect.X() - container_viewport_rect.SetX(container_viewport_rect.X() -
pixels_per_line_step); pixels_per_line_step);
...@@ -196,15 +197,15 @@ bool HasOffscreenRect(const Node* node, WebFocusType type) { ...@@ -196,15 +197,15 @@ bool HasOffscreenRect(const Node* node, WebFocusType type) {
return !container_viewport_rect.Intersects(rect); return !container_viewport_rect.Intersects(rect);
} }
bool ScrollInDirection(LocalFrame* frame, WebFocusType type) { bool ScrollInDirection(LocalFrame* frame, WebFocusType direction) {
DCHECK(frame); DCHECK(frame);
if (frame && CanScrollInDirection(frame->GetDocument(), type)) { if (frame && CanScrollInDirection(frame->GetDocument(), direction)) {
int dx = 0; int dx = 0;
int dy = 0; int dy = 0;
int pixels_per_line_step = int pixels_per_line_step =
ScrollableArea::PixelsPerLineStep(frame->View()->GetChromeClient()); ScrollableArea::PixelsPerLineStep(frame->View()->GetChromeClient());
switch (type) { switch (direction) {
case kWebFocusTypeLeft: case kWebFocusTypeLeft:
dx = -pixels_per_line_step; dx = -pixels_per_line_step;
break; break;
...@@ -229,22 +230,22 @@ bool ScrollInDirection(LocalFrame* frame, WebFocusType type) { ...@@ -229,22 +230,22 @@ bool ScrollInDirection(LocalFrame* frame, WebFocusType type) {
return false; return false;
} }
bool ScrollInDirection(Node* container, WebFocusType type) { bool ScrollInDirection(Node* container, WebFocusType direction) {
DCHECK(container); DCHECK(container);
if (container->IsDocumentNode()) if (container->IsDocumentNode())
return ScrollInDirection(ToDocument(container)->GetFrame(), type); return ScrollInDirection(ToDocument(container)->GetFrame(), direction);
if (!container->GetLayoutBox()) if (!container->GetLayoutBox())
return false; return false;
if (CanScrollInDirection(container, type)) { if (CanScrollInDirection(container, direction)) {
int dx = 0; int dx = 0;
int dy = 0; int dy = 0;
// TODO(leviw): Why are these values truncated (toInt) instead of rounding? // TODO(leviw): Why are these values truncated (toInt) instead of rounding?
LocalFrameView* frame_view = container->GetDocument().View(); LocalFrameView* frame_view = container->GetDocument().View();
int pixels_per_line_step = ScrollableArea::PixelsPerLineStep( int pixels_per_line_step = ScrollableArea::PixelsPerLineStep(
frame_view ? frame_view->GetChromeClient() : nullptr); frame_view ? frame_view->GetChromeClient() : nullptr);
switch (type) { switch (direction) {
case kWebFocusTypeLeft: case kWebFocusTypeLeft:
dx = -pixels_per_line_step; dx = -pixels_per_line_step;
break; break;
...@@ -329,25 +330,25 @@ bool IsScrollableAreaOrDocument(const Node* node) { ...@@ -329,25 +330,25 @@ bool IsScrollableAreaOrDocument(const Node* node) {
IsScrollableNode(node); IsScrollableNode(node);
} }
bool IsNavigableContainer(const Node* node, WebFocusType type) { bool IsNavigableContainer(const Node* node, WebFocusType direction) {
if (!node) if (!node)
return false; return false;
return node->IsDocumentNode() || return node->IsDocumentNode() ||
(node->IsFrameOwnerElement() && (node->IsFrameOwnerElement() &&
ToHTMLFrameOwnerElement(node)->ContentFrame()) || ToHTMLFrameOwnerElement(node)->ContentFrame()) ||
CanScrollInDirection(node, type); CanScrollInDirection(node, direction);
} }
bool CanScrollInDirection(const Node* container, WebFocusType type) { bool CanScrollInDirection(const Node* container, WebFocusType direction) {
DCHECK(container); DCHECK(container);
if (container->IsDocumentNode()) if (container->IsDocumentNode())
return CanScrollInDirection(ToDocument(container)->GetFrame(), type); return CanScrollInDirection(ToDocument(container)->GetFrame(), direction);
if (!IsScrollableNode(container)) if (!IsScrollableNode(container))
return false; return false;
switch (type) { switch (direction) {
case kWebFocusTypeLeft: case kWebFocusTypeLeft:
return (container->GetLayoutObject()->Style()->OverflowX() != return (container->GetLayoutObject()->Style()->OverflowX() !=
EOverflow::kHidden && EOverflow::kHidden &&
...@@ -374,7 +375,7 @@ bool CanScrollInDirection(const Node* container, WebFocusType type) { ...@@ -374,7 +375,7 @@ bool CanScrollInDirection(const Node* container, WebFocusType type) {
} }
} }
bool CanScrollInDirection(const LocalFrame* frame, WebFocusType type) { bool CanScrollInDirection(const LocalFrame* frame, WebFocusType direction) {
if (!frame->View()) if (!frame->View())
return false; return false;
LayoutView* layoutView = frame->ContentLayoutObject(); LayoutView* layoutView = frame->ContentLayoutObject();
...@@ -383,10 +384,10 @@ bool CanScrollInDirection(const LocalFrame* frame, WebFocusType type) { ...@@ -383,10 +384,10 @@ bool CanScrollInDirection(const LocalFrame* frame, WebFocusType type) {
ScrollbarMode vertical_mode; ScrollbarMode vertical_mode;
ScrollbarMode horizontal_mode; ScrollbarMode horizontal_mode;
layoutView->CalculateScrollbarModes(horizontal_mode, vertical_mode); layoutView->CalculateScrollbarModes(horizontal_mode, vertical_mode);
if ((type == kWebFocusTypeLeft || type == kWebFocusTypeRight) && if ((direction == kWebFocusTypeLeft || direction == kWebFocusTypeRight) &&
kScrollbarAlwaysOff == horizontal_mode) kScrollbarAlwaysOff == horizontal_mode)
return false; return false;
if ((type == kWebFocusTypeUp || type == kWebFocusTypeDown) && if ((direction == kWebFocusTypeUp || direction == kWebFocusTypeDown) &&
kScrollbarAlwaysOff == vertical_mode) kScrollbarAlwaysOff == vertical_mode)
return false; return false;
ScrollableArea* scrollable_area = ScrollableArea* scrollable_area =
...@@ -395,7 +396,7 @@ bool CanScrollInDirection(const LocalFrame* frame, WebFocusType type) { ...@@ -395,7 +396,7 @@ bool CanScrollInDirection(const LocalFrame* frame, WebFocusType type) {
LayoutSize offset(scrollable_area->ScrollOffsetInt()); LayoutSize offset(scrollable_area->ScrollOffsetInt());
LayoutRect rect(scrollable_area->VisibleContentRect(kIncludeScrollbars)); LayoutRect rect(scrollable_area->VisibleContentRect(kIncludeScrollbars));
switch (type) { switch (direction) {
case kWebFocusTypeLeft: case kWebFocusTypeLeft:
return offset.Width() > 0; return offset.Width() > 0;
case kWebFocusTypeUp: case kWebFocusTypeUp:
...@@ -443,12 +444,12 @@ LayoutRect NodeRectInRootFrame(const Node* node, bool ignore_border) { ...@@ -443,12 +444,12 @@ LayoutRect NodeRectInRootFrame(const Node* node, bool ignore_border) {
// into the candidate rect. The line between those 2 points is the closest // into the candidate rect. The line between those 2 points is the closest
// distance between the 2 rects. Takes care of overlapping rects, defining // distance between the 2 rects. Takes care of overlapping rects, defining
// points so that the distance between them is zero where necessary // points so that the distance between them is zero where necessary
void EntryAndExitPointsForDirection(WebFocusType type, void EntryAndExitPointsForDirection(WebFocusType direction,
const LayoutRect& starting_rect, const LayoutRect& starting_rect,
const LayoutRect& potential_rect, const LayoutRect& potential_rect,
LayoutPoint& exit_point, LayoutPoint& exit_point,
LayoutPoint& entry_point) { LayoutPoint& entry_point) {
switch (type) { switch (direction) {
case kWebFocusTypeLeft: case kWebFocusTypeLeft:
exit_point.SetX(starting_rect.X()); exit_point.SetX(starting_rect.X());
if (potential_rect.MaxX() < starting_rect.X()) if (potential_rect.MaxX() < starting_rect.X())
...@@ -481,7 +482,7 @@ void EntryAndExitPointsForDirection(WebFocusType type, ...@@ -481,7 +482,7 @@ void EntryAndExitPointsForDirection(WebFocusType type,
NOTREACHED(); NOTREACHED();
} }
switch (type) { switch (direction) {
case kWebFocusTypeLeft: case kWebFocusTypeLeft:
case kWebFocusTypeRight: case kWebFocusTypeRight:
if (Below(starting_rect, potential_rect)) { if (Below(starting_rect, potential_rect)) {
...@@ -553,17 +554,17 @@ bool AreElementsOnSameLine(const FocusCandidate& first_candidate, ...@@ -553,17 +554,17 @@ bool AreElementsOnSameLine(const FocusCandidate& first_candidate,
return true; return true;
} }
void DistanceDataForNode(WebFocusType type, void DistanceDataForNode(WebFocusType direction,
const FocusCandidate& current, const FocusCandidate& current,
FocusCandidate& candidate) { FocusCandidate& candidate) {
if (!IsRectInDirection(type, current.rect_in_root_frame, if (!IsRectInDirection(direction, current.rect_in_root_frame,
candidate.rect_in_root_frame)) candidate.rect_in_root_frame))
return; return;
if (AreElementsOnSameLine(current, candidate)) { if (AreElementsOnSameLine(current, candidate)) {
if ((type == kWebFocusTypeUp && if ((direction == kWebFocusTypeUp &&
current.rect_in_root_frame.Y() > candidate.rect_in_root_frame.Y()) || current.rect_in_root_frame.Y() > candidate.rect_in_root_frame.Y()) ||
(type == kWebFocusTypeDown && (direction == kWebFocusTypeDown &&
candidate.rect_in_root_frame.Y() > current.rect_in_root_frame.Y())) { candidate.rect_in_root_frame.Y() > current.rect_in_root_frame.Y())) {
candidate.distance = 0; candidate.distance = 0;
return; return;
...@@ -576,7 +577,7 @@ void DistanceDataForNode(WebFocusType type, ...@@ -576,7 +577,7 @@ void DistanceDataForNode(WebFocusType type,
LayoutPoint exit_point; LayoutPoint exit_point;
LayoutPoint entry_point; LayoutPoint entry_point;
EntryAndExitPointsForDirection(type, current_rect, node_rect, exit_point, EntryAndExitPointsForDirection(direction, current_rect, node_rect, exit_point,
entry_point); entry_point);
LayoutUnit x_axis = (exit_point.X() - entry_point.X()).Abs(); LayoutUnit x_axis = (exit_point.X() - entry_point.X()).Abs();
...@@ -596,11 +597,11 @@ void DistanceDataForNode(WebFocusType type, ...@@ -596,11 +597,11 @@ void DistanceDataForNode(WebFocusType type,
const int kOrthogonalWeightForUpDown = 2; const int kOrthogonalWeightForUpDown = 2;
int orthogonal_bias = 0; int orthogonal_bias = 0;
switch (type) { switch (direction) {
case kWebFocusTypeLeft: case kWebFocusTypeLeft:
case kWebFocusTypeRight: case kWebFocusTypeRight:
navigation_axis_distance = x_axis; navigation_axis_distance = x_axis;
if (!RectsIntersectOnOrthogonalAxis(type, current_rect, node_rect)) if (!RectsIntersectOnOrthogonalAxis(direction, current_rect, node_rect))
orthogonal_bias = (current_rect.Height() / 2).ToInt(); orthogonal_bias = (current_rect.Height() / 2).ToInt();
weighted_orthogonal_axis_distance = weighted_orthogonal_axis_distance =
(y_axis + orthogonal_bias) * kOrthogonalWeightForLeftRight; (y_axis + orthogonal_bias) * kOrthogonalWeightForLeftRight;
...@@ -608,7 +609,7 @@ void DistanceDataForNode(WebFocusType type, ...@@ -608,7 +609,7 @@ void DistanceDataForNode(WebFocusType type,
case kWebFocusTypeUp: case kWebFocusTypeUp:
case kWebFocusTypeDown: case kWebFocusTypeDown:
navigation_axis_distance = y_axis; navigation_axis_distance = y_axis;
if (!RectsIntersectOnOrthogonalAxis(type, current_rect, node_rect)) if (!RectsIntersectOnOrthogonalAxis(direction, current_rect, node_rect))
orthogonal_bias = (current_rect.Width() / 2).ToInt(); orthogonal_bias = (current_rect.Width() / 2).ToInt();
weighted_orthogonal_axis_distance = weighted_orthogonal_axis_distance =
(x_axis + orthogonal_bias) * kOrthogonalWeightForUpDown; (x_axis + orthogonal_bias) * kOrthogonalWeightForUpDown;
...@@ -630,7 +631,8 @@ void DistanceDataForNode(WebFocusType type, ...@@ -630,7 +631,8 @@ void DistanceDataForNode(WebFocusType type,
weighted_orthogonal_axis_distance - sqrt(overlap); weighted_orthogonal_axis_distance - sqrt(overlap);
} }
bool CanBeScrolledIntoView(WebFocusType type, const FocusCandidate& candidate) { bool CanBeScrolledIntoView(WebFocusType direction,
const FocusCandidate& candidate) {
DCHECK(candidate.visible_node); DCHECK(candidate.visible_node);
DCHECK(candidate.is_offscreen); DCHECK(candidate.is_offscreen);
LayoutRect candidate_rect = candidate.rect_in_root_frame; LayoutRect candidate_rect = candidate.rect_in_root_frame;
...@@ -645,16 +647,17 @@ bool CanBeScrolledIntoView(WebFocusType type, const FocusCandidate& candidate) { ...@@ -645,16 +647,17 @@ bool CanBeScrolledIntoView(WebFocusType type, const FocusCandidate& candidate) {
LayoutRect parent_rect = NodeRectInRootFrame(&parent_node); LayoutRect parent_rect = NodeRectInRootFrame(&parent_node);
if (!candidate_rect.Intersects(parent_rect)) { if (!candidate_rect.Intersects(parent_rect)) {
if (((type == kWebFocusTypeLeft || type == kWebFocusTypeRight) && if (((direction == kWebFocusTypeLeft ||
direction == kWebFocusTypeRight) &&
parent_node.GetLayoutObject()->Style()->OverflowX() == parent_node.GetLayoutObject()->Style()->OverflowX() ==
EOverflow::kHidden) || EOverflow::kHidden) ||
((type == kWebFocusTypeUp || type == kWebFocusTypeDown) && ((direction == kWebFocusTypeUp || direction == kWebFocusTypeDown) &&
parent_node.GetLayoutObject()->Style()->OverflowY() == parent_node.GetLayoutObject()->Style()->OverflowY() ==
EOverflow::kHidden)) EOverflow::kHidden))
return false; return false;
} }
if (parent_node == candidate.enclosing_scrollable_box) if (parent_node == candidate.enclosing_scrollable_box)
return CanScrollInDirection(&parent_node, type); return CanScrollInDirection(&parent_node, direction);
} }
return true; return true;
} }
...@@ -663,11 +666,11 @@ bool CanBeScrolledIntoView(WebFocusType type, const FocusCandidate& candidate) { ...@@ -663,11 +666,11 @@ bool CanBeScrolledIntoView(WebFocusType type, const FocusCandidate& candidate) {
// Compose a virtual starting rect if there is no focused node or if it is off // Compose a virtual starting rect if there is no focused node or if it is off
// screen. The virtual rect is the edge of the container or frame. We select // screen. The virtual rect is the edge of the container or frame. We select
// which edge depending on the direction of the navigation. // which edge depending on the direction of the navigation.
LayoutRect VirtualRectForDirection(WebFocusType type, LayoutRect VirtualRectForDirection(WebFocusType direction,
const LayoutRect& starting_rect, const LayoutRect& starting_rect,
LayoutUnit width) { LayoutUnit width) {
LayoutRect virtual_starting_rect = starting_rect; LayoutRect virtual_starting_rect = starting_rect;
switch (type) { switch (direction) {
case kWebFocusTypeLeft: case kWebFocusTypeLeft:
virtual_starting_rect.SetX(virtual_starting_rect.MaxX() - width); virtual_starting_rect.SetX(virtual_starting_rect.MaxX() - width);
virtual_starting_rect.SetWidth(width); virtual_starting_rect.SetWidth(width);
...@@ -690,13 +693,13 @@ LayoutRect VirtualRectForDirection(WebFocusType type, ...@@ -690,13 +693,13 @@ LayoutRect VirtualRectForDirection(WebFocusType type,
} }
LayoutRect VirtualRectForAreaElementAndDirection(const HTMLAreaElement& area, LayoutRect VirtualRectForAreaElementAndDirection(const HTMLAreaElement& area,
WebFocusType type) { WebFocusType direction) {
DCHECK(area.ImageElement()); DCHECK(area.ImageElement());
// Area elements tend to overlap more than other focusable elements. We // Area elements tend to overlap more than other focusable elements. We
// flatten the rect of the area elements to minimize the effect of overlapping // flatten the rect of the area elements to minimize the effect of overlapping
// areas. // areas.
LayoutRect rect = VirtualRectForDirection( LayoutRect rect = VirtualRectForDirection(
type, direction,
area.GetDocument().GetFrame()->View()->AbsoluteToRootFrame( area.GetDocument().GetFrame()->View()->AbsoluteToRootFrame(
area.ComputeAbsoluteRect(area.ImageElement()->GetLayoutObject())), area.ComputeAbsoluteRect(area.ImageElement()->GetLayoutObject())),
LayoutUnit(1)); LayoutUnit(1));
......
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