Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * (C) 2001 Dirk Mueller (mueller@kde.org) | 4 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. | 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. |
| 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
| 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) | 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) |
| 8 * | 8 * |
| 9 * This library is free software; you can redistribute it and/or | 9 * This library is free software; you can redistribute it and/or |
| 10 * modify it under the terms of the GNU Library General Public | 10 * modify it under the terms of the GNU Library General Public |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 375 LayoutObject* layoutObject = m_data.m_rareData->layoutObject(); | 375 LayoutObject* layoutObject = m_data.m_rareData->layoutObject(); |
| 376 if (isElementNode()) | 376 if (isElementNode()) |
| 377 delete static_cast<ElementRareData*>(m_data.m_rareData); | 377 delete static_cast<ElementRareData*>(m_data.m_rareData); |
| 378 else | 378 else |
| 379 delete static_cast<NodeRareData*>(m_data.m_rareData); | 379 delete static_cast<NodeRareData*>(m_data.m_rareData); |
| 380 m_data.m_layoutObject = layoutObject; | 380 m_data.m_layoutObject = layoutObject; |
| 381 clearFlag(HasRareDataFlag); | 381 clearFlag(HasRareDataFlag); |
| 382 } | 382 } |
| 383 #endif | 383 #endif |
| 384 | 384 |
| 385 static bool isNodeInNodes(const Node& node, const HeapVector<NodeOrString>& node s) | |
|
philipj_slow
2015/06/26 14:13:25
Maybe move this block of statics to just before No
Paritosh Kumar
2015/06/30 10:49:09
Done.
| |
| 386 { | |
| 387 for (NodeOrString nodeOrString : nodes) { | |
|
philipj_slow
2015/06/26 14:13:26
I guess this should be "for (const NodeOrString& n
Paritosh Kumar
2015/06/30 10:49:09
Ohh, sorry. Thanks.
| |
| 388 if (nodeOrString.isNode() && nodeOrString.getAsNode() == &node) | |
| 389 return true; | |
| 390 } | |
| 391 return false; | |
| 392 } | |
| 393 | |
| 394 static Node* viablePreviousSibling(const Node& node, const HeapVector<NodeOrStri ng>& nodes) | |
| 395 { | |
| 396 for (Node* sibling = node.previousSibling(); sibling; sibling = sibling->pre viousSibling()) { | |
| 397 if (!isNodeInNodes(*sibling, nodes)) | |
| 398 return sibling; | |
| 399 } | |
| 400 return nullptr; | |
| 401 } | |
| 402 | |
| 403 static Node* viableNextSibling(const Node& node, const HeapVector<NodeOrString>& nodes) | |
| 404 { | |
| 405 for (Node* sibling = node.nextSibling(); sibling; sibling = sibling->nextSib ling()) { | |
| 406 if (!isNodeInNodes(*sibling, nodes)) | |
| 407 return sibling; | |
| 408 } | |
| 409 return nullptr; | |
| 410 } | |
| 411 | |
| 412 static PassRefPtrWillBeRawPtr<Node> nodeOrStringToNode(const NodeOrString& nodeO rString, Document& document) | |
| 413 { | |
| 414 if (nodeOrString.isNode()) | |
| 415 return nodeOrString.getAsNode(); | |
| 416 return Text::create(document, nodeOrString.getAsString()); | |
| 417 } | |
| 418 | |
| 419 static PassRefPtrWillBeRawPtr<Node> convertNodesIntoNode(const HeapVector<NodeOr String>& nodes, Document& document) | |
| 420 { | |
| 421 if (nodes.size() == 1) | |
| 422 return nodeOrStringToNode(nodes[0], document); | |
| 423 | |
| 424 RefPtrWillBeRawPtr<Node> node = DocumentFragment::create(document); | |
|
philipj_slow
2015/06/26 14:13:26
For clarity I would name this fragment instead of
Paritosh Kumar
2015/06/30 10:49:08
Done.
| |
| 425 for (const NodeOrString& nodeOrString : nodes) | |
| 426 node->appendChild(nodeOrStringToNode(nodeOrString, document), ASSERT_NO_ EXCEPTION); | |
| 427 return node.release(); | |
| 428 } | |
| 429 | |
| 385 Node* Node::toNode() | 430 Node* Node::toNode() |
| 386 { | 431 { |
| 387 return this; | 432 return this; |
| 388 } | 433 } |
| 389 | 434 |
| 390 short Node::tabIndex() const | 435 short Node::tabIndex() const |
| 391 { | 436 { |
| 392 return 0; | 437 return 0; |
| 393 } | 438 } |
| 394 | 439 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 | 539 |
| 495 PassRefPtrWillBeRawPtr<Node> Node::appendChild(PassRefPtrWillBeRawPtr<Node> newC hild, ExceptionState& exceptionState) | 540 PassRefPtrWillBeRawPtr<Node> Node::appendChild(PassRefPtrWillBeRawPtr<Node> newC hild, ExceptionState& exceptionState) |
| 496 { | 541 { |
| 497 if (isContainerNode()) | 542 if (isContainerNode()) |
| 498 return toContainerNode(this)->appendChild(newChild, exceptionState); | 543 return toContainerNode(this)->appendChild(newChild, exceptionState); |
| 499 | 544 |
| 500 exceptionState.throwDOMException(HierarchyRequestError, "This node type does not support this method."); | 545 exceptionState.throwDOMException(HierarchyRequestError, "This node type does not support this method."); |
| 501 return nullptr; | 546 return nullptr; |
| 502 } | 547 } |
| 503 | 548 |
| 549 void Node::prepend(const HeapVector<NodeOrString>& nodes, ExceptionState& except ionState) | |
| 550 { | |
| 551 this->insertBefore(convertNodesIntoNode(nodes, document()), this->firstChild (), exceptionState); | |
|
philipj_slow
2015/06/26 14:13:26
Is "this->" needed?
Paritosh Kumar
2015/06/30 10:49:09
No.
philipj_slow
2015/07/02 09:20:01
How about the "this->" at the beginning of the lin
| |
| 552 } | |
| 553 | |
| 554 void Node::append(const HeapVector<NodeOrString>& nodes, ExceptionState& excepti onState) | |
| 555 { | |
| 556 this->appendChild(convertNodesIntoNode(nodes, document()), exceptionState); | |
| 557 } | |
| 558 | |
| 559 void Node::before(const HeapVector<NodeOrString>& nodes, ExceptionState& excepti onState) | |
| 560 { | |
| 561 Node* parent = parentNode(); | |
| 562 if (!parent) | |
| 563 return; | |
| 564 Node* viablePreviousSiblingNode = viablePreviousSibling(*this, nodes); | |
|
philipj_slow
2015/06/26 14:13:26
Can this bit be written like the spec, with an |vi
Paritosh Kumar
2015/06/30 10:49:09
Changed with conditional. Yes, this should be viab
philipj_slow
2015/07/02 09:20:01
I see that you changed the before.html test, but c
| |
| 565 if (!viablePreviousSiblingNode) | |
| 566 parent->insertBefore(convertNodesIntoNode(nodes, document()), parent->fi rstChild(), exceptionState); | |
| 567 else | |
| 568 parent->insertBefore(convertNodesIntoNode(nodes, document()), viablePrev iousSiblingNode, exceptionState); | |
| 569 } | |
| 570 | |
| 571 void Node::after(const HeapVector<NodeOrString>& nodes, ExceptionState& exceptio nState) | |
| 572 { | |
| 573 Node* parent = parentNode(); | |
| 574 if (!parent) | |
| 575 return; | |
| 576 Node* viableNextSiblingNode = viableNextSibling(*this, nodes); | |
| 577 parent->insertBefore(convertNodesIntoNode(nodes, document()), viableNextSibl ingNode, exceptionState); | |
| 578 } | |
| 579 | |
| 580 void Node::replaceWith(const HeapVector<NodeOrString>& nodes, ExceptionState& ex ceptionState) | |
| 581 { | |
| 582 Node* parent = parentNode(); | |
| 583 if (!parent) | |
| 584 return; | |
| 585 Node* viableNextSiblingNode = viableNextSibling(*this, nodes); | |
| 586 if (parent == parentNode()) | |
|
philipj_slow
2015/06/26 14:13:26
The spec says "If context object’s parent is paren
Paritosh Kumar
2015/06/30 10:49:09
Hmmm, This looks very strange but @Annevk has take
philipj_slow
2015/07/02 09:20:01
Discussed with Anne on IRC:
http://krijnhoetmer.nl
| |
| 587 parent->replaceChild(convertNodesIntoNode(nodes, document()), this, exce ptionState); | |
| 588 else | |
| 589 parent->insertBefore(convertNodesIntoNode(nodes, document()), viableNext SiblingNode, exceptionState); | |
| 590 } | |
| 591 | |
| 504 void Node::remove(ExceptionState& exceptionState) | 592 void Node::remove(ExceptionState& exceptionState) |
| 505 { | 593 { |
| 506 if (ContainerNode* parent = parentNode()) | 594 if (ContainerNode* parent = parentNode()) |
| 507 parent->removeChild(this, exceptionState); | 595 parent->removeChild(this, exceptionState); |
| 508 } | 596 } |
| 509 | 597 |
| 510 void Node::normalize() | 598 void Node::normalize() |
| 511 { | 599 { |
| 512 updateDistribution(); | 600 updateDistribution(); |
| 513 | 601 |
| (...skipping 1988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2502 | 2590 |
| 2503 void showNodePath(const blink::Node* node) | 2591 void showNodePath(const blink::Node* node) |
| 2504 { | 2592 { |
| 2505 if (node) | 2593 if (node) |
| 2506 node->showNodePathForThis(); | 2594 node->showNodePathForThis(); |
| 2507 else | 2595 else |
| 2508 fprintf(stderr, "Cannot showNodePath for (nil)\n"); | 2596 fprintf(stderr, "Cannot showNodePath for (nil)\n"); |
| 2509 } | 2597 } |
| 2510 | 2598 |
| 2511 #endif | 2599 #endif |
| OLD | NEW |