Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(882)

Side by Side Diff: third_party/WebKit/Source/core/dom/Node.cpp

Issue 2177783003: [Editing][DOM][CodeHealth] Move Node::*editable* functions to core/editing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 if (node == this) 527 if (node == this)
528 break; 528 break;
529 529
530 if (node->getNodeType() == TEXT_NODE) 530 if (node->getNodeType() == TEXT_NODE)
531 node = toText(node)->mergeNextSiblingNodesIfPossible(); 531 node = toText(node)->mergeNextSiblingNodesIfPossible();
532 else 532 else
533 node = NodeTraversal::nextPostOrder(*node); 533 node = NodeTraversal::nextPostOrder(*node);
534 } 534 }
535 } 535 }
536 536
537 // TODO(yoichio): Move to core/editing
538 enum EditableLevel { Editable, RichlyEditable };
539 static bool hasEditableStyle(const Node&, EditableLevel);
540 static bool isEditableToAccessibility(const Node&, EditableLevel);
541
542 // TODO(yoichio): Move to core/editing
543 bool isContentEditable(const Node& node)
544 {
545 node.document().updateStyleAndLayoutTree();
546 return blink::hasEditableStyle(node, Editable);
547 }
548
549 // TODO(yoichio): Move to core/editing
550 bool isContentRichlyEditable(const Node& node)
551 {
552 node.document().updateStyleAndLayoutTree();
553 return blink::hasEditableStyle(node, RichlyEditable);
554 }
555
556 // TODO(yoichio): Move to core/editing
557 static bool hasEditableStyle(const Node& node, EditableLevel editableLevel)
558 {
559 if (node.isPseudoElement())
560 return false;
561
562 // Ideally we'd call DCHECK(!needsStyleRecalc()) here, but
563 // ContainerNode::setFocus() calls setNeedsStyleRecalc(), so the assertion
564 // would fire in the middle of Document::setFocusedNode().
565
566 for (const Node& ancestor : NodeTraversal::inclusiveAncestorsOf(node)) {
567 if ((ancestor.isHTMLElement() || ancestor.isDocumentNode()) && ancestor. layoutObject()) {
568 switch (ancestor.layoutObject()->style()->userModify()) {
569 case READ_ONLY:
570 return false;
571 case READ_WRITE:
572 return true;
573 case READ_WRITE_PLAINTEXT_ONLY:
574 return editableLevel != RichlyEditable;
575 }
576 ASSERT_NOT_REACHED();
577 return false;
578 }
579 }
580
581 return false;
582 }
583
584 // TODO(yoichio): Move to core/editing
585 static bool isEditableToAccessibility(const Node& node, EditableLevel editableLe vel)
586 {
587 if (blink::hasEditableStyle(node, editableLevel))
588 return true;
589
590 // FIXME: Respect editableLevel for ARIA editable elements.
591 if (editableLevel == RichlyEditable)
592 return false;
593
594 // FIXME(dmazzoni): support ScopedAXObjectCache (crbug/489851).
595 if (AXObjectCache* cache = node.document().existingAXObjectCache())
596 return cache->rootAXEditableElement(&node);
597
598 return false;
599 }
600
601 // TODO(yoichio): Move to core/editing
602 bool hasEditableStyle(const Node& node, EditableType editableType)
603 {
604 switch (editableType) {
605 case ContentIsEditable:
606 return blink::hasEditableStyle(node, Editable);
607 case HasEditableAXRole:
608 return isEditableToAccessibility(node, Editable);
609 }
610 NOTREACHED();
611 return false;
612 }
613
614 // TODO(yoichio): Move to core/editing
615 bool layoutObjectIsRichlyEditable(const Node& node, EditableType editableType)
616 {
617 switch (editableType) {
618 case ContentIsEditable:
619 return blink::hasEditableStyle(node, RichlyEditable);
620 case HasEditableAXRole:
621 return isEditableToAccessibility(node, RichlyEditable);
622 }
623 NOTREACHED();
624 return false;
625 }
626
627 LayoutBox* Node::layoutBox() const 537 LayoutBox* Node::layoutBox() const
628 { 538 {
629 LayoutObject* layoutObject = this->layoutObject(); 539 LayoutObject* layoutObject = this->layoutObject();
630 return layoutObject && layoutObject->isBox() ? toLayoutBox(layoutObject) : n ullptr; 540 return layoutObject && layoutObject->isBox() ? toLayoutBox(layoutObject) : n ullptr;
631 } 541 }
632 542
633 LayoutBoxModelObject* Node::layoutBoxModelObject() const 543 LayoutBoxModelObject* Node::layoutBoxModelObject() const
634 { 544 {
635 LayoutObject* layoutObject = this->layoutObject(); 545 LayoutObject* layoutObject = this->layoutObject();
636 return layoutObject && layoutObject->isBoxModelObject() ? toLayoutBoxModelOb ject(layoutObject) : nullptr; 546 return layoutObject && layoutObject->isBoxModelObject() ? toLayoutBoxModelOb ject(layoutObject) : nullptr;
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 return toElement(parent); 1044 return toElement(parent);
1135 } 1045 }
1136 1046
1137 ContainerNode* Node::parentOrShadowHostOrTemplateHostNode() const 1047 ContainerNode* Node::parentOrShadowHostOrTemplateHostNode() const
1138 { 1048 {
1139 if (isDocumentFragment() && toDocumentFragment(this)->isTemplateContent()) 1049 if (isDocumentFragment() && toDocumentFragment(this)->isTemplateContent())
1140 return static_cast<const TemplateContentDocumentFragment*>(this)->host() ; 1050 return static_cast<const TemplateContentDocumentFragment*>(this)->host() ;
1141 return parentOrShadowHostNode(); 1051 return parentOrShadowHostNode();
1142 } 1052 }
1143 1053
1144 // TODO(yoichio): Move to core/editing
1145 bool isRootEditableElement(const Node& node)
1146 {
1147 return hasEditableStyle(node) && node.isElementNode() && (!node.parentNode() || !hasEditableStyle(*node.parentNode())
1148 || !node.parentNode()->isElementNode() || &node == node.document().body( ));
1149 }
1150
1151 // TODO(yoichio): Move to core/editing
1152 Element* rootEditableElement(const Node& node, EditableType editableType)
1153 {
1154 if (editableType == HasEditableAXRole) {
1155 if (AXObjectCache* cache = node.document().existingAXObjectCache())
1156 return const_cast<Element*>(cache->rootAXEditableElement(&node));
1157 }
1158
1159 return rootEditableElement(node);
1160 }
1161
1162 // TODO(yoichio): Move to core/editing
1163 Element* rootEditableElement(const Node& node)
1164 {
1165 const Node* result = nullptr;
1166 for (const Node* n = &node; n && hasEditableStyle(*n); n = n->parentNode()) {
1167 if (n->isElementNode())
1168 result = n;
1169 if (node.document().body() == n)
1170 break;
1171 }
1172 return toElement(const_cast<Node*>(result));
1173 }
1174
1175 // FIXME: End of obviously misplaced HTML editing functions. Try to move these out of Node.
1176
1177 Document* Node::ownerDocument() const 1054 Document* Node::ownerDocument() const
1178 { 1055 {
1179 Document* doc = &document(); 1056 Document* doc = &document();
1180 return doc == this ? nullptr : doc; 1057 return doc == this ? nullptr : doc;
1181 } 1058 }
1182 1059
1183 const KURL& Node::baseURI() const 1060 const KURL& Node::baseURI() const
1184 { 1061 {
1185 return document().baseURL(); 1062 return document().baseURL();
1186 } 1063 }
(...skipping 1351 matching lines...) Expand 10 before | Expand all | Expand 10 after
2538 2415
2539 void showNodePath(const blink::Node* node) 2416 void showNodePath(const blink::Node* node)
2540 { 2417 {
2541 if (node) 2418 if (node)
2542 node->showNodePathForThis(); 2419 node->showNodePathForThis();
2543 else 2420 else
2544 fprintf(stderr, "Cannot showNodePath for (nil)\n"); 2421 fprintf(stderr, "Cannot showNodePath for (nil)\n");
2545 } 2422 }
2546 2423
2547 #endif 2424 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698