OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "core/EventNames.h" | 31 #include "core/EventNames.h" |
32 #include "core/HTMLNames.h" | 32 #include "core/HTMLNames.h" |
33 #include "core/XLinkNames.h" | 33 #include "core/XLinkNames.h" |
34 #include "core/clipboard/DataObject.h" | 34 #include "core/clipboard/DataObject.h" |
35 #include "core/clipboard/DataTransfer.h" | 35 #include "core/clipboard/DataTransfer.h" |
36 #include "core/clipboard/Pasteboard.h" | 36 #include "core/clipboard/Pasteboard.h" |
37 #include "core/css/CSSComputedStyleDeclaration.h" | 37 #include "core/css/CSSComputedStyleDeclaration.h" |
38 #include "core/css/StylePropertySet.h" | 38 #include "core/css/StylePropertySet.h" |
39 #include "core/dom/AXObjectCache.h" | 39 #include "core/dom/AXObjectCache.h" |
40 #include "core/dom/DocumentFragment.h" | 40 #include "core/dom/DocumentFragment.h" |
| 41 #include "core/dom/ElementTraversal.h" |
41 #include "core/dom/NodeTraversal.h" | 42 #include "core/dom/NodeTraversal.h" |
42 #include "core/dom/ParserContentPolicy.h" | 43 #include "core/dom/ParserContentPolicy.h" |
43 #include "core/dom/Text.h" | 44 #include "core/dom/Text.h" |
44 #include "core/editing/EditingUtilities.h" | 45 #include "core/editing/EditingUtilities.h" |
45 #include "core/editing/InputMethodController.h" | 46 #include "core/editing/InputMethodController.h" |
46 #include "core/editing/RenderedPosition.h" | 47 #include "core/editing/RenderedPosition.h" |
47 #include "core/editing/VisibleUnits.h" | 48 #include "core/editing/VisibleUnits.h" |
48 #include "core/editing/commands/ApplyStyleCommand.h" | 49 #include "core/editing/commands/ApplyStyleCommand.h" |
49 #include "core/editing/commands/DeleteSelectionCommand.h" | 50 #include "core/editing/commands/DeleteSelectionCommand.h" |
50 #include "core/editing/commands/IndentOutdentCommand.h" | 51 #include "core/editing/commands/IndentOutdentCommand.h" |
(...skipping 10 matching lines...) Expand all Loading... |
61 #include "core/events/ClipboardEvent.h" | 62 #include "core/events/ClipboardEvent.h" |
62 #include "core/events/KeyboardEvent.h" | 63 #include "core/events/KeyboardEvent.h" |
63 #include "core/events/ScopedEventQueue.h" | 64 #include "core/events/ScopedEventQueue.h" |
64 #include "core/events/TextEvent.h" | 65 #include "core/events/TextEvent.h" |
65 #include "core/fetch/ImageResource.h" | 66 #include "core/fetch/ImageResource.h" |
66 #include "core/fetch/ResourceFetcher.h" | 67 #include "core/fetch/ResourceFetcher.h" |
67 #include "core/frame/FrameView.h" | 68 #include "core/frame/FrameView.h" |
68 #include "core/frame/LocalFrame.h" | 69 #include "core/frame/LocalFrame.h" |
69 #include "core/frame/Settings.h" | 70 #include "core/frame/Settings.h" |
70 #include "core/frame/UseCounter.h" | 71 #include "core/frame/UseCounter.h" |
| 72 #include "core/html/HTMLBodyElement.h" |
71 #include "core/html/HTMLCanvasElement.h" | 73 #include "core/html/HTMLCanvasElement.h" |
| 74 #include "core/html/HTMLHtmlElement.h" |
72 #include "core/html/HTMLImageElement.h" | 75 #include "core/html/HTMLImageElement.h" |
73 #include "core/html/HTMLInputElement.h" | 76 #include "core/html/HTMLInputElement.h" |
74 #include "core/html/HTMLTextAreaElement.h" | 77 #include "core/html/HTMLTextAreaElement.h" |
75 #include "core/html/parser/HTMLParserIdioms.h" | 78 #include "core/html/parser/HTMLParserIdioms.h" |
76 #include "core/input/EventHandler.h" | 79 #include "core/input/EventHandler.h" |
| 80 #include "core/inspector/ConsoleMessage.h" |
77 #include "core/layout/HitTestResult.h" | 81 #include "core/layout/HitTestResult.h" |
78 #include "core/layout/LayoutImage.h" | 82 #include "core/layout/LayoutImage.h" |
79 #include "core/loader/EmptyClients.h" | 83 #include "core/loader/EmptyClients.h" |
80 #include "core/page/EditorClient.h" | 84 #include "core/page/EditorClient.h" |
81 #include "core/page/FocusController.h" | 85 #include "core/page/FocusController.h" |
82 #include "core/page/Page.h" | 86 #include "core/page/Page.h" |
83 #include "core/svg/SVGImageElement.h" | 87 #include "core/svg/SVGImageElement.h" |
84 #include "platform/KillRing.h" | 88 #include "platform/KillRing.h" |
85 #include "platform/weborigin/KURL.h" | 89 #include "platform/weborigin/KURL.h" |
86 #include "wtf/text/CharacterNames.h" | 90 #include "wtf/text/CharacterNames.h" |
(...skipping 1209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 { | 1300 { |
1297 return frame().spellChecker(); | 1301 return frame().spellChecker(); |
1298 } | 1302 } |
1299 | 1303 |
1300 void Editor::toggleOverwriteModeEnabled() | 1304 void Editor::toggleOverwriteModeEnabled() |
1301 { | 1305 { |
1302 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 1306 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
1303 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); | 1307 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); |
1304 } | 1308 } |
1305 | 1309 |
| 1310 void Editor::tidyUpHTMLStructure(Document& document) |
| 1311 { |
| 1312 // hasEditableStyle() needs up-to-date ComputedStyle. |
| 1313 document.updateLayoutTreeIfNeeded(); |
| 1314 bool needsValidStructure = document.hasEditableStyle() || (document.document
Element() && document.documentElement()->hasEditableStyle()); |
| 1315 if (!needsValidStructure) |
| 1316 return; |
| 1317 RefPtrWillBeRawPtr<Element> existingHead = nullptr; |
| 1318 RefPtrWillBeRawPtr<Element> existingBody = nullptr; |
| 1319 Element* currentRoot = document.documentElement(); |
| 1320 if (currentRoot) { |
| 1321 if (isHTMLHtmlElement(currentRoot)) |
| 1322 return; |
| 1323 if (isHTMLHeadElement(currentRoot)) |
| 1324 existingHead = currentRoot; |
| 1325 else if (isHTMLBodyElement(currentRoot)) |
| 1326 existingBody = currentRoot; |
| 1327 else if (isHTMLFrameSetElement(currentRoot)) |
| 1328 existingBody = currentRoot; |
| 1329 } |
| 1330 // We ensure only "the root is <html>." |
| 1331 // documentElement as rootEditableElement is problematic. So we move |
| 1332 // non-<html> root elements under <body>, and the <body> works as |
| 1333 // rootEditableElement. |
| 1334 document.addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMe
ssageLevel, "document.execCommand() doesn't work with an invalid HTML structure.
It is corrected automatically.")); |
| 1335 |
| 1336 RefPtrWillBeRawPtr<Element> root = HTMLHtmlElement::create(document); |
| 1337 if (existingHead) |
| 1338 root->appendChild(existingHead.release()); |
| 1339 RefPtrWillBeRawPtr<Element> body = nullptr; |
| 1340 if (existingBody) |
| 1341 body = existingBody.release(); |
| 1342 else |
| 1343 body = HTMLBodyElement::create(document); |
| 1344 if (document.documentElement()) |
| 1345 body->appendChild(document.documentElement()); |
| 1346 root->appendChild(body.release()); |
| 1347 ASSERT(!document.documentElement()); |
| 1348 document.appendChild(root.release()); |
| 1349 |
| 1350 // TODO(tkent): Should we check and move Text node children of <html>? |
| 1351 } |
| 1352 |
1306 DEFINE_TRACE(Editor) | 1353 DEFINE_TRACE(Editor) |
1307 { | 1354 { |
1308 visitor->trace(m_frame); | 1355 visitor->trace(m_frame); |
1309 visitor->trace(m_lastEditCommand); | 1356 visitor->trace(m_lastEditCommand); |
1310 visitor->trace(m_mark); | 1357 visitor->trace(m_mark); |
1311 } | 1358 } |
1312 | 1359 |
1313 } // namespace blink | 1360 } // namespace blink |
OLD | NEW |