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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 String SmartClip::ExtractTextFromNode(Node* node) { | 239 String SmartClip::ExtractTextFromNode(Node* node) { |
240 // Science has proven that no text nodes are ever positioned at y == -99999. | 240 // Science has proven that no text nodes are ever positioned at y == -99999. |
241 int prev_y_pos = -99999; | 241 int prev_y_pos = -99999; |
242 | 242 |
243 StringBuilder result; | 243 StringBuilder result; |
244 for (Node& current_node : NodeTraversal::InclusiveDescendantsOf(*node)) { | 244 for (Node& current_node : NodeTraversal::InclusiveDescendantsOf(*node)) { |
245 const ComputedStyle* style = current_node.EnsureComputedStyle(); | 245 const ComputedStyle* style = current_node.EnsureComputedStyle(); |
246 if (style && style->UserSelect() == SELECT_NONE) | 246 if (style && style->UserSelect() == EUserSelect::kNone) |
247 continue; | 247 continue; |
248 | 248 |
249 if (Node* node_from_frame = NodeInsideFrame(¤t_node)) | 249 if (Node* node_from_frame = NodeInsideFrame(¤t_node)) |
250 result.Append(ExtractTextFromNode(node_from_frame)); | 250 result.Append(ExtractTextFromNode(node_from_frame)); |
251 | 251 |
252 IntRect node_rect = current_node.PixelSnappedBoundingBox(); | 252 IntRect node_rect = current_node.PixelSnappedBoundingBox(); |
253 if (current_node.GetLayoutObject() && !node_rect.IsEmpty()) { | 253 if (current_node.GetLayoutObject() && !node_rect.IsEmpty()) { |
254 if (current_node.IsTextNode()) { | 254 if (current_node.IsTextNode()) { |
255 String node_value = current_node.nodeValue(); | 255 String node_value = current_node.nodeValue(); |
256 | 256 |
257 // It's unclear why we blacklist solitary "\n" node values. | 257 // It's unclear why we blacklist solitary "\n" node values. |
258 // Maybe we're trying to ignore <br> tags somehow? | 258 // Maybe we're trying to ignore <br> tags somehow? |
259 if (node_value == "\n") | 259 if (node_value == "\n") |
260 node_value = ""; | 260 node_value = ""; |
261 | 261 |
262 if (node_rect.Y() != prev_y_pos) { | 262 if (node_rect.Y() != prev_y_pos) { |
263 prev_y_pos = node_rect.Y(); | 263 prev_y_pos = node_rect.Y(); |
264 result.Append('\n'); | 264 result.Append('\n'); |
265 } | 265 } |
266 | 266 |
267 result.Append(node_value); | 267 result.Append(node_value); |
268 } | 268 } |
269 } | 269 } |
270 } | 270 } |
271 | 271 |
272 return result.ToString(); | 272 return result.ToString(); |
273 } | 273 } |
274 | 274 |
275 } // namespace blink | 275 } // namespace blink |
OLD | NEW |