| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 const PositionWithAffinity& b) { | 265 const PositionWithAffinity& b) { |
| 266 return comparePositions(a.position(), b.position()); | 266 return comparePositions(a.position(), b.position()); |
| 267 } | 267 } |
| 268 | 268 |
| 269 int comparePositions(const VisiblePosition& a, const VisiblePosition& b) { | 269 int comparePositions(const VisiblePosition& a, const VisiblePosition& b) { |
| 270 return comparePositions(a.deepEquivalent(), b.deepEquivalent()); | 270 return comparePositions(a.deepEquivalent(), b.deepEquivalent()); |
| 271 } | 271 } |
| 272 | 272 |
| 273 enum EditableLevel { Editable, RichlyEditable }; | 273 enum EditableLevel { Editable, RichlyEditable }; |
| 274 static bool hasEditableLevel(const Node& node, EditableLevel editableLevel) { | 274 static bool hasEditableLevel(const Node& node, EditableLevel editableLevel) { |
| 275 // TODO(yoichio): We should have this check. | 275 DCHECK(node.document().isActive()); |
| 276 // DCHECK(!needsLayoutTreeUpdate(node)); | 276 // TODO(editing-dev): We should have this check: |
| 277 // DCHECK_GE(node.document().lifecycle().state(), |
| 278 // DocumentLifecycle::StyleClean); |
| 277 if (node.isPseudoElement()) | 279 if (node.isPseudoElement()) |
| 278 return false; | 280 return false; |
| 279 | 281 |
| 280 // Ideally we'd call DCHECK(!needsStyleRecalc()) here, but | 282 // Ideally we'd call DCHECK(!needsStyleRecalc()) here, but |
| 281 // ContainerNode::setFocus() calls setNeedsStyleRecalc(), so the assertion | 283 // ContainerNode::setFocus() calls setNeedsStyleRecalc(), so the assertion |
| 282 // would fire in the middle of Document::setFocusedNode(). | 284 // would fire in the middle of Document::setFocusedNode(). |
| 283 | 285 |
| 284 for (const Node& ancestor : NodeTraversal::inclusiveAncestorsOf(node)) { | 286 for (const Node& ancestor : NodeTraversal::inclusiveAncestorsOf(node)) { |
| 285 if ((ancestor.isHTMLElement() || ancestor.isDocumentNode()) && | 287 if ((ancestor.isHTMLElement() || ancestor.isDocumentNode()) && |
| 286 ancestor.layoutObject()) { | 288 ancestor.layoutObject()) { |
| 287 switch (ancestor.layoutObject()->style()->userModify()) { | 289 switch (ancestor.layoutObject()->style()->userModify()) { |
| 288 case READ_ONLY: | 290 case READ_ONLY: |
| 289 return false; | 291 return false; |
| 290 case READ_WRITE: | 292 case READ_WRITE: |
| 291 return true; | 293 return true; |
| 292 case READ_WRITE_PLAINTEXT_ONLY: | 294 case READ_WRITE_PLAINTEXT_ONLY: |
| 293 return editableLevel != RichlyEditable; | 295 return editableLevel != RichlyEditable; |
| 294 } | 296 } |
| 295 NOTREACHED(); | 297 NOTREACHED(); |
| 296 return false; | 298 return false; |
| 297 } | 299 } |
| 298 } | 300 } |
| 299 | 301 |
| 300 return false; | 302 return false; |
| 301 } | 303 } |
| 302 | 304 |
| 303 bool hasEditableStyle(const Node& node) { | 305 bool hasEditableStyle(const Node& node) { |
| 306 // TODO(editing-dev): We shouldn't check editable style in inactive documents. |
| 307 // We should hoist this check in the call stack, replace it by a DCHECK of |
| 308 // active document and ultimately cleanup the code paths with inactive |
| 309 // documents. See crbug.com/667681 |
| 310 if (!node.document().isActive()) |
| 311 return false; |
| 312 |
| 304 return hasEditableLevel(node, Editable); | 313 return hasEditableLevel(node, Editable); |
| 305 } | 314 } |
| 306 | 315 |
| 307 bool hasRichlyEditableStyle(const Node& node) { | 316 bool hasRichlyEditableStyle(const Node& node) { |
| 317 // TODO(editing-dev): We shouldn't check editable style in inactive documents. |
| 318 // We should hoist this check in the call stack, replace it by a DCHECK of |
| 319 // active document and ultimately cleanup the code paths with inactive |
| 320 // documents. See crbug.com/667681 |
| 321 if (!node.document().isActive()) |
| 322 return false; |
| 323 |
| 308 return hasEditableLevel(node, RichlyEditable); | 324 return hasEditableLevel(node, RichlyEditable); |
| 309 } | 325 } |
| 310 | 326 |
| 311 bool isRootEditableElement(const Node& node) { | 327 bool isRootEditableElement(const Node& node) { |
| 312 return hasEditableStyle(node) && node.isElementNode() && | 328 return hasEditableStyle(node) && node.isElementNode() && |
| 313 (!node.parentNode() || !hasEditableStyle(*node.parentNode()) || | 329 (!node.parentNode() || !hasEditableStyle(*node.parentNode()) || |
| 314 !node.parentNode()->isElementNode() || | 330 !node.parentNode()->isElementNode() || |
| 315 &node == node.document().body()); | 331 &node == node.document().body()); |
| 316 } | 332 } |
| 317 | 333 |
| (...skipping 1808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2126 return InputType::DeleteWordBackward; | 2142 return InputType::DeleteWordBackward; |
| 2127 if (granularity == LineBoundary) | 2143 if (granularity == LineBoundary) |
| 2128 return InputType::DeleteLineBackward; | 2144 return InputType::DeleteLineBackward; |
| 2129 return InputType::DeleteContentBackward; | 2145 return InputType::DeleteContentBackward; |
| 2130 default: | 2146 default: |
| 2131 return InputType::None; | 2147 return InputType::None; |
| 2132 } | 2148 } |
| 2133 } | 2149 } |
| 2134 | 2150 |
| 2135 } // namespace blink | 2151 } // namespace blink |
| OLD | NEW |