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

Side by Side Diff: third_party/WebKit/Source/core/editing/Editor.cpp

Issue 2147123003: Editing: Add a TODO comment to tidyUpHTMLStructure(). (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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/frame/UseCounter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 { 1371 {
1372 return frame().spellChecker(); 1372 return frame().spellChecker();
1373 } 1373 }
1374 1374
1375 void Editor::toggleOverwriteModeEnabled() 1375 void Editor::toggleOverwriteModeEnabled()
1376 { 1376 {
1377 m_overwriteModeEnabled = !m_overwriteModeEnabled; 1377 m_overwriteModeEnabled = !m_overwriteModeEnabled;
1378 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); 1378 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled);
1379 } 1379 }
1380 1380
1381 // TODO(tkent): This is a workaround of some crash bugs in the editing code,
1382 // which assumes a document has a valid HTML structure. We should make the
1383 // editing code more robust, and should remove this hack. crbug.com/580941.
1381 void Editor::tidyUpHTMLStructure(Document& document) 1384 void Editor::tidyUpHTMLStructure(Document& document)
1382 { 1385 {
1383 // hasEditableStyle() needs up-to-date ComputedStyle. 1386 // hasEditableStyle() needs up-to-date ComputedStyle.
1384 document.updateStyleAndLayoutTree(); 1387 document.updateStyleAndLayoutTree();
1385 bool needsValidStructure = document.hasEditableStyle() || (document.document Element() && document.documentElement()->hasEditableStyle()); 1388 bool needsValidStructure = document.hasEditableStyle() || (document.document Element() && document.documentElement()->hasEditableStyle());
1386 if (!needsValidStructure) 1389 if (!needsValidStructure)
1387 return; 1390 return;
1388 Element* existingHead = nullptr; 1391 Element* existingHead = nullptr;
1389 Element* existingBody = nullptr; 1392 Element* existingBody = nullptr;
1390 Element* currentRoot = document.documentElement(); 1393 Element* currentRoot = document.documentElement();
1391 if (currentRoot) { 1394 if (currentRoot) {
1392 if (isHTMLHtmlElement(currentRoot)) 1395 if (isHTMLHtmlElement(currentRoot))
1393 return; 1396 return;
1394 if (isHTMLHeadElement(currentRoot)) 1397 if (isHTMLHeadElement(currentRoot))
1395 existingHead = currentRoot; 1398 existingHead = currentRoot;
1396 else if (isHTMLBodyElement(currentRoot)) 1399 else if (isHTMLBodyElement(currentRoot))
1397 existingBody = currentRoot; 1400 existingBody = currentRoot;
1398 else if (isHTMLFrameSetElement(currentRoot)) 1401 else if (isHTMLFrameSetElement(currentRoot))
1399 existingBody = currentRoot; 1402 existingBody = currentRoot;
1400 } 1403 }
1401 // We ensure only "the root is <html>." 1404 // We ensure only "the root is <html>."
1402 // documentElement as rootEditableElement is problematic. So we move 1405 // documentElement as rootEditableElement is problematic. So we move
1403 // non-<html> root elements under <body>, and the <body> works as 1406 // non-<html> root elements under <body>, and the <body> works as
1404 // rootEditableElement. 1407 // rootEditableElement.
1405 document.addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMe ssageLevel, "document.execCommand() doesn't work with an invalid HTML structure. It is corrected automatically.")); 1408 document.addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMe ssageLevel, "document.execCommand() doesn't work with an invalid HTML structure. It is corrected automatically."));
1409 UseCounter::count(document, UseCounter::ExecCommandAltersHTMLStructure);
1406 1410
1407 Element* root = HTMLHtmlElement::create(document); 1411 Element* root = HTMLHtmlElement::create(document);
1408 if (existingHead) 1412 if (existingHead)
1409 root->appendChild(existingHead); 1413 root->appendChild(existingHead);
1410 Element* body = nullptr; 1414 Element* body = nullptr;
1411 if (existingBody) 1415 if (existingBody)
1412 body = existingBody; 1416 body = existingBody;
1413 else 1417 else
1414 body = HTMLBodyElement::create(document); 1418 body = HTMLBodyElement::create(document);
1415 if (document.documentElement() && body != document.documentElement()) 1419 if (document.documentElement() && body != document.documentElement())
1416 body->appendChild(document.documentElement()); 1420 body->appendChild(document.documentElement());
1417 root->appendChild(body); 1421 root->appendChild(body);
1418 DCHECK(!document.documentElement()); 1422 DCHECK(!document.documentElement());
1419 document.appendChild(root); 1423 document.appendChild(root);
1420 1424
1421 // TODO(tkent): Should we check and move Text node children of <html>? 1425 // TODO(tkent): Should we check and move Text node children of <html>?
1422 } 1426 }
1423 1427
1424 DEFINE_TRACE(Editor) 1428 DEFINE_TRACE(Editor)
1425 { 1429 {
1426 visitor->trace(m_frame); 1430 visitor->trace(m_frame);
1427 visitor->trace(m_lastEditCommand); 1431 visitor->trace(m_lastEditCommand);
1428 visitor->trace(m_undoStack); 1432 visitor->trace(m_undoStack);
1429 visitor->trace(m_mark); 1433 visitor->trace(m_mark);
1430 } 1434 }
1431 1435
1432 } // namespace blink 1436 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/frame/UseCounter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698