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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 return parentNewNode; | 140 return parentNewNode; |
141 return newNode; | 141 return newNode; |
142 } | 142 } |
143 | 143 |
144 // This loop appears to find the nearest ancestor of minNode (in DOM order) | 144 // This loop appears to find the nearest ancestor of minNode (in DOM order) |
145 // that contains the newNodeRect. It's very unclear to me why that's an | 145 // that contains the newNodeRect. It's very unclear to me why that's an |
146 // interesting node to find. Presumably this loop will often just return | 146 // interesting node to find. Presumably this loop will often just return |
147 // the documentElement. | 147 // the documentElement. |
148 Node* node = minNode; | 148 Node* node = minNode; |
149 while (node) { | 149 while (node) { |
150 if (node->renderer()) { | 150 if (node->layoutObject()) { |
151 IntRect nodeRect = node->pixelSnappedBoundingBox(); | 151 IntRect nodeRect = node->pixelSnappedBoundingBox(); |
152 if (nodeRect.contains(newNodeRect)) { | 152 if (nodeRect.contains(newNodeRect)) { |
153 return node; | 153 return node; |
154 } | 154 } |
155 } | 155 } |
156 node = node->parentNode(); | 156 node = node->parentNode(); |
157 } | 157 } |
158 | 158 |
159 return nullptr; | 159 return nullptr; |
160 } | 160 } |
161 | 161 |
162 Node* SmartClip::findBestOverlappingNode(Node* rootNode, const IntRect& cropRect
) | 162 Node* SmartClip::findBestOverlappingNode(Node* rootNode, const IntRect& cropRect
) |
163 { | 163 { |
164 if (!rootNode) | 164 if (!rootNode) |
165 return nullptr; | 165 return nullptr; |
166 | 166 |
167 IntRect resizedCropRect = rootNode->document().view()->windowToContents(crop
Rect); | 167 IntRect resizedCropRect = rootNode->document().view()->windowToContents(crop
Rect); |
168 | 168 |
169 Node* node = rootNode; | 169 Node* node = rootNode; |
170 Node* minNode = nullptr; | 170 Node* minNode = nullptr; |
171 | 171 |
172 while (node) { | 172 while (node) { |
173 IntRect nodeRect = node->pixelSnappedBoundingBox(); | 173 IntRect nodeRect = node->pixelSnappedBoundingBox(); |
174 | 174 |
175 if (node->isElementNode() && equalIgnoringCase(toElement(node)->fastGetA
ttribute(HTMLNames::aria_hiddenAttr), "true")) { | 175 if (node->isElementNode() && equalIgnoringCase(toElement(node)->fastGetA
ttribute(HTMLNames::aria_hiddenAttr), "true")) { |
176 node = NodeTraversal::nextSkippingChildren(*node, rootNode); | 176 node = NodeTraversal::nextSkippingChildren(*node, rootNode); |
177 continue; | 177 continue; |
178 } | 178 } |
179 | 179 |
180 LayoutObject* renderer = node->renderer(); | 180 LayoutObject* renderer = node->layoutObject(); |
181 if (renderer && !nodeRect.isEmpty()) { | 181 if (renderer && !nodeRect.isEmpty()) { |
182 if (renderer->isText() | 182 if (renderer->isText() |
183 || renderer->isLayoutImage() | 183 || renderer->isLayoutImage() |
184 || node->isFrameOwnerElement() | 184 || node->isFrameOwnerElement() |
185 || (renderer->style()->hasBackgroundImage() && !shouldSkipBackgr
oundImage(node))) { | 185 || (renderer->style()->hasBackgroundImage() && !shouldSkipBackgr
oundImage(node))) { |
186 if (resizedCropRect.intersects(nodeRect)) { | 186 if (resizedCropRect.intersects(nodeRect)) { |
187 minNode = minNodeContainsNodes(minNode, node); | 187 minNode = minNodeContainsNodes(minNode, node); |
188 } else { | 188 } else { |
189 node = NodeTraversal::nextSkippingChildren(*node, rootNode); | 189 node = NodeTraversal::nextSkippingChildren(*node, rootNode); |
190 continue; | 190 continue; |
(...skipping 13 matching lines...) Expand all Loading... |
204 { | 204 { |
205 ASSERT(node); | 205 ASSERT(node); |
206 // Apparently we're only interested in background images on spans and divs. | 206 // Apparently we're only interested in background images on spans and divs. |
207 if (!isHTMLSpanElement(*node) && !isHTMLDivElement(*node)) | 207 if (!isHTMLSpanElement(*node) && !isHTMLDivElement(*node)) |
208 return true; | 208 return true; |
209 | 209 |
210 // This check actually makes a bit of sense. If you're going to sprite an | 210 // This check actually makes a bit of sense. If you're going to sprite an |
211 // image out of a CSS background, you're probably going to specify a height | 211 // image out of a CSS background, you're probably going to specify a height |
212 // or a width. On the other hand, if we've got a legit background image, | 212 // or a width. On the other hand, if we've got a legit background image, |
213 // it's very likely the height or the width will be set to auto. | 213 // it's very likely the height or the width will be set to auto. |
214 LayoutObject* renderer = node->renderer(); | 214 LayoutObject* renderer = node->layoutObject(); |
215 if (renderer && (renderer->style()->logicalHeight().isAuto() || renderer->st
yle()->logicalWidth().isAuto())) | 215 if (renderer && (renderer->style()->logicalHeight().isAuto() || renderer->st
yle()->logicalWidth().isAuto())) |
216 return true; | 216 return true; |
217 | 217 |
218 return false; | 218 return false; |
219 } | 219 } |
220 | 220 |
221 void SmartClip::collectOverlappingChildNodes(Node* parentNode, const IntRect& cr
opRect, WillBeHeapVector<RawPtrWillBeMember<Node>>& hitNodes) | 221 void SmartClip::collectOverlappingChildNodes(Node* parentNode, const IntRect& cr
opRect, WillBeHeapVector<RawPtrWillBeMember<Node>>& hitNodes) |
222 { | 222 { |
223 if (!parentNode) | 223 if (!parentNode) |
224 return; | 224 return; |
(...skipping 20 matching lines...) Expand all Loading... |
245 StringBuilder result; | 245 StringBuilder result; |
246 for (Node& currentNode : NodeTraversal::inclusiveDescendantsOf(*node)) { | 246 for (Node& currentNode : NodeTraversal::inclusiveDescendantsOf(*node)) { |
247 LayoutStyle* style = currentNode.computedStyle(); | 247 LayoutStyle* style = currentNode.computedStyle(); |
248 if (style && style->userSelect() == SELECT_NONE) | 248 if (style && style->userSelect() == SELECT_NONE) |
249 continue; | 249 continue; |
250 | 250 |
251 if (Node* nodeFromFrame = nodeInsideFrame(¤tNode)) | 251 if (Node* nodeFromFrame = nodeInsideFrame(¤tNode)) |
252 result.append(extractTextFromNode(nodeFromFrame)); | 252 result.append(extractTextFromNode(nodeFromFrame)); |
253 | 253 |
254 IntRect nodeRect = currentNode.pixelSnappedBoundingBox(); | 254 IntRect nodeRect = currentNode.pixelSnappedBoundingBox(); |
255 if (currentNode.renderer() && !nodeRect.isEmpty()) { | 255 if (currentNode.layoutObject() && !nodeRect.isEmpty()) { |
256 if (currentNode.isTextNode()) { | 256 if (currentNode.isTextNode()) { |
257 String nodeValue = currentNode.nodeValue(); | 257 String nodeValue = currentNode.nodeValue(); |
258 | 258 |
259 // It's unclear why we blacklist solitary "\n" node values. | 259 // It's unclear why we blacklist solitary "\n" node values. |
260 // Maybe we're trying to ignore <br> tags somehow? | 260 // Maybe we're trying to ignore <br> tags somehow? |
261 if (nodeValue == "\n") | 261 if (nodeValue == "\n") |
262 nodeValue = ""; | 262 nodeValue = ""; |
263 | 263 |
264 if (nodeRect.y() != prevYPos) { | 264 if (nodeRect.y() != prevYPos) { |
265 prevYPos = nodeRect.y(); | 265 prevYPos = nodeRect.y(); |
266 result.append('\n'); | 266 result.append('\n'); |
267 } | 267 } |
268 | 268 |
269 result.append(nodeValue); | 269 result.append(nodeValue); |
270 } | 270 } |
271 } | 271 } |
272 } | 272 } |
273 | 273 |
274 return result.toString(); | 274 return result.toString(); |
275 } | 275 } |
276 | 276 |
277 } // namespace blink | 277 } // namespace blink |
OLD | NEW |