OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) | 2 * Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies) |
3 * Copyright (C) 2009 Antonio Gomes <tonikitoo@webkit.org> | 3 * Copyright (C) 2009 Antonio Gomes <tonikitoo@webkit.org> |
4 * | 4 * |
5 * All rights reserved. | 5 * All rights reserved. |
6 * | 6 * |
7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
9 * are met: | 9 * are met: |
10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 int dy = 0; | 242 int dy = 0; |
243 // TODO(leviw): Why are these values truncated (toInt) instead of rounding? | 243 // TODO(leviw): Why are these values truncated (toInt) instead of rounding? |
244 FrameView* frame_view = container->GetDocument().View(); | 244 FrameView* frame_view = container->GetDocument().View(); |
245 int pixels_per_line_step = ScrollableArea::PixelsPerLineStep( | 245 int pixels_per_line_step = ScrollableArea::PixelsPerLineStep( |
246 frame_view ? frame_view->GetChromeClient() : nullptr); | 246 frame_view ? frame_view->GetChromeClient() : nullptr); |
247 switch (type) { | 247 switch (type) { |
248 case kWebFocusTypeLeft: | 248 case kWebFocusTypeLeft: |
249 dx = -pixels_per_line_step; | 249 dx = -pixels_per_line_step; |
250 break; | 250 break; |
251 case kWebFocusTypeRight: | 251 case kWebFocusTypeRight: |
252 ASSERT(container->GetLayoutBox()->ScrollWidth() > | 252 DCHECK(container->GetLayoutBox()->ScrollWidth() > |
253 (container->GetLayoutBox()->ScrollLeft() + | 253 (container->GetLayoutBox()->ScrollLeft() + |
254 container->GetLayoutBox()->ClientWidth())); | 254 container->GetLayoutBox()->ClientWidth())); |
255 dx = pixels_per_line_step; | 255 dx = pixels_per_line_step; |
256 break; | 256 break; |
257 case kWebFocusTypeUp: | 257 case kWebFocusTypeUp: |
258 dy = -pixels_per_line_step; | 258 dy = -pixels_per_line_step; |
259 break; | 259 break; |
260 case kWebFocusTypeDown: | 260 case kWebFocusTypeDown: |
261 ASSERT(container->GetLayoutBox()->ScrollHeight() - | 261 DCHECK(container->GetLayoutBox()->ScrollHeight() - |
262 (container->GetLayoutBox()->ScrollTop() + | 262 (container->GetLayoutBox()->ScrollTop() + |
263 container->GetLayoutBox()->ClientHeight())); | 263 container->GetLayoutBox()->ClientHeight())); |
264 dy = pixels_per_line_step; | 264 dy = pixels_per_line_step; |
265 break; | 265 break; |
266 default: | 266 default: |
267 NOTREACHED(); | 267 NOTREACHED(); |
268 return false; | 268 return false; |
269 } | 269 } |
270 | 270 |
271 container->GetLayoutBox()->ScrollByRecursively(ScrollOffset(dx, dy)); | 271 container->GetLayoutBox()->ScrollByRecursively(ScrollOffset(dx, dy)); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 LayoutObject* layout_object = element->GetLayoutObject(); | 401 LayoutObject* layout_object = element->GetLayoutObject(); |
402 element = layout_object ? layout_object->OffsetParent() : nullptr; | 402 element = layout_object ? layout_object->OffsetParent() : nullptr; |
403 } while (element); | 403 } while (element); |
404 rect.Move((-ToLocalFrame(frame)->View()->ScrollOffsetInt())); | 404 rect.Move((-ToLocalFrame(frame)->View()->ScrollOffsetInt())); |
405 } | 405 } |
406 } | 406 } |
407 return rect; | 407 return rect; |
408 } | 408 } |
409 | 409 |
410 LayoutRect NodeRectInAbsoluteCoordinates(Node* node, bool ignore_border) { | 410 LayoutRect NodeRectInAbsoluteCoordinates(Node* node, bool ignore_border) { |
411 ASSERT(node && node->GetLayoutObject() && | 411 DCHECK(node && node->GetLayoutObject() && |
412 !node->GetDocument().View()->NeedsLayout()); | 412 !node->GetDocument().View()->NeedsLayout()); |
413 | 413 |
414 if (node->IsDocumentNode()) | 414 if (node->IsDocumentNode()) |
415 return FrameRectInAbsoluteCoordinates(ToDocument(node)->GetFrame()); | 415 return FrameRectInAbsoluteCoordinates(ToDocument(node)->GetFrame()); |
416 LayoutRect rect = RectToAbsoluteCoordinates(node->GetDocument().GetFrame(), | 416 LayoutRect rect = RectToAbsoluteCoordinates(node->GetDocument().GetFrame(), |
417 node->BoundingBox()); | 417 node->BoundingBox()); |
418 | 418 |
419 // For authors that use border instead of outline in their CSS, we compensate | 419 // For authors that use border instead of outline in their CSS, we compensate |
420 // by ignoring the border when calculating the rect of the focused element. | 420 // by ignoring the border when calculating the rect of the focused element. |
421 if (ignore_border) { | 421 if (ignore_border) { |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 double overlap = | 617 double overlap = |
618 (intersection_rect.Width() * intersection_rect.Height()).ToDouble(); | 618 (intersection_rect.Width() * intersection_rect.Height()).ToDouble(); |
619 | 619 |
620 // Distance calculation is based on http://www.w3.org/TR/WICD/#focus-handling | 620 // Distance calculation is based on http://www.w3.org/TR/WICD/#focus-handling |
621 candidate.distance = sqrt(euclidian_distance_pow2) + | 621 candidate.distance = sqrt(euclidian_distance_pow2) + |
622 navigation_axis_distance + | 622 navigation_axis_distance + |
623 weighted_orthogonal_axis_distance - sqrt(overlap); | 623 weighted_orthogonal_axis_distance - sqrt(overlap); |
624 } | 624 } |
625 | 625 |
626 bool CanBeScrolledIntoView(WebFocusType type, const FocusCandidate& candidate) { | 626 bool CanBeScrolledIntoView(WebFocusType type, const FocusCandidate& candidate) { |
627 ASSERT(candidate.visible_node && candidate.is_offscreen); | 627 DCHECK(candidate.visible_node && candidate.is_offscreen); |
628 LayoutRect candidate_rect = candidate.rect; | 628 LayoutRect candidate_rect = candidate.rect; |
629 for (Node& parent_node : | 629 for (Node& parent_node : |
630 NodeTraversal::AncestorsOf(*candidate.visible_node)) { | 630 NodeTraversal::AncestorsOf(*candidate.visible_node)) { |
631 LayoutRect parent_rect = NodeRectInAbsoluteCoordinates(&parent_node); | 631 LayoutRect parent_rect = NodeRectInAbsoluteCoordinates(&parent_node); |
632 if (!candidate_rect.Intersects(parent_rect)) { | 632 if (!candidate_rect.Intersects(parent_rect)) { |
633 if (((type == kWebFocusTypeLeft || type == kWebFocusTypeRight) && | 633 if (((type == kWebFocusTypeLeft || type == kWebFocusTypeRight) && |
634 parent_node.GetLayoutObject()->Style()->OverflowX() == | 634 parent_node.GetLayoutObject()->Style()->OverflowX() == |
635 EOverflow::kHidden) || | 635 EOverflow::kHidden) || |
636 ((type == kWebFocusTypeUp || type == kWebFocusTypeDown) && | 636 ((type == kWebFocusTypeUp || type == kWebFocusTypeDown) && |
637 parent_node.GetLayoutObject()->Style()->OverflowY() == | 637 parent_node.GetLayoutObject()->Style()->OverflowY() == |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 return rect; | 689 return rect; |
690 } | 690 } |
691 | 691 |
692 HTMLFrameOwnerElement* FrameOwnerElement(FocusCandidate& candidate) { | 692 HTMLFrameOwnerElement* FrameOwnerElement(FocusCandidate& candidate) { |
693 return candidate.IsFrameOwnerElement() | 693 return candidate.IsFrameOwnerElement() |
694 ? ToHTMLFrameOwnerElement(candidate.visible_node) | 694 ? ToHTMLFrameOwnerElement(candidate.visible_node) |
695 : nullptr; | 695 : nullptr; |
696 }; | 696 }; |
697 | 697 |
698 } // namespace blink | 698 } // namespace blink |
OLD | NEW |