| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 if (Node* bestNodeInFrame = | 81 if (Node* bestNodeInFrame = |
| 82 findBestOverlappingNode(nodeFromFrame, cropRectInViewport)) | 82 findBestOverlappingNode(nodeFromFrame, cropRectInViewport)) |
| 83 bestNode = bestNodeInFrame; | 83 bestNode = bestNodeInFrame; |
| 84 } | 84 } |
| 85 | 85 |
| 86 HeapVector<Member<Node>> hitNodes; | 86 HeapVector<Member<Node>> hitNodes; |
| 87 collectOverlappingChildNodes(bestNode, cropRectInViewport, hitNodes); | 87 collectOverlappingChildNodes(bestNode, cropRectInViewport, hitNodes); |
| 88 | 88 |
| 89 if (hitNodes.isEmpty() || hitNodes.size() == bestNode->countChildren()) { | 89 if (hitNodes.isEmpty() || hitNodes.size() == bestNode->countChildren()) { |
| 90 hitNodes.clear(); | 90 hitNodes.clear(); |
| 91 hitNodes.append(bestNode); | 91 hitNodes.push_back(bestNode); |
| 92 } | 92 } |
| 93 | 93 |
| 94 // Unite won't work with the empty rect, so we initialize to the first rect. | 94 // Unite won't work with the empty rect, so we initialize to the first rect. |
| 95 IntRect unitedRects = hitNodes[0]->pixelSnappedBoundingBox(); | 95 IntRect unitedRects = hitNodes[0]->pixelSnappedBoundingBox(); |
| 96 StringBuilder collectedText; | 96 StringBuilder collectedText; |
| 97 for (size_t i = 0; i < hitNodes.size(); ++i) { | 97 for (size_t i = 0; i < hitNodes.size(); ++i) { |
| 98 collectedText.append(extractTextFromNode(hitNodes[i])); | 98 collectedText.append(extractTextFromNode(hitNodes[i])); |
| 99 unitedRects.unite(hitNodes[i]->pixelSnappedBoundingBox()); | 99 unitedRects.unite(hitNodes[i]->pixelSnappedBoundingBox()); |
| 100 } | 100 } |
| 101 | 101 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 const IntRect& cropRectInViewport, | 222 const IntRect& cropRectInViewport, |
| 223 HeapVector<Member<Node>>& hitNodes) { | 223 HeapVector<Member<Node>>& hitNodes) { |
| 224 if (!parentNode) | 224 if (!parentNode) |
| 225 return; | 225 return; |
| 226 IntRect resizedCropRect = convertToContentCoordinatesWithoutCollapsingToZero( | 226 IntRect resizedCropRect = convertToContentCoordinatesWithoutCollapsingToZero( |
| 227 cropRectInViewport, parentNode->document().view()); | 227 cropRectInViewport, parentNode->document().view()); |
| 228 for (Node* child = parentNode->firstChild(); child; | 228 for (Node* child = parentNode->firstChild(); child; |
| 229 child = child->nextSibling()) { | 229 child = child->nextSibling()) { |
| 230 IntRect childRect = child->pixelSnappedBoundingBox(); | 230 IntRect childRect = child->pixelSnappedBoundingBox(); |
| 231 if (resizedCropRect.intersects(childRect)) | 231 if (resizedCropRect.intersects(childRect)) |
| 232 hitNodes.append(child); | 232 hitNodes.push_back(child); |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 | 235 |
| 236 String SmartClip::extractTextFromNode(Node* node) { | 236 String SmartClip::extractTextFromNode(Node* node) { |
| 237 // Science has proven that no text nodes are ever positioned at y == -99999. | 237 // Science has proven that no text nodes are ever positioned at y == -99999. |
| 238 int prevYPos = -99999; | 238 int prevYPos = -99999; |
| 239 | 239 |
| 240 StringBuilder result; | 240 StringBuilder result; |
| 241 for (Node& currentNode : NodeTraversal::inclusiveDescendantsOf(*node)) { | 241 for (Node& currentNode : NodeTraversal::inclusiveDescendantsOf(*node)) { |
| 242 const ComputedStyle* style = currentNode.ensureComputedStyle(); | 242 const ComputedStyle* style = currentNode.ensureComputedStyle(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 263 | 263 |
| 264 result.append(nodeValue); | 264 result.append(nodeValue); |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 } | 267 } |
| 268 | 268 |
| 269 return result.toString(); | 269 return result.toString(); |
| 270 } | 270 } |
| 271 | 271 |
| 272 } // namespace blink | 272 } // namespace blink |
| OLD | NEW |