OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2010 Google Inc. All rights reserved. | 3 * Copyright (C) 2010 Google Inc. All rights reserved. |
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 : CompositeEditCommand(document), m_tagName(tagName) {} | 54 : CompositeEditCommand(document), m_tagName(tagName) {} |
55 | 55 |
56 void ApplyBlockElementCommand::doApply(EditingState* editingState) { | 56 void ApplyBlockElementCommand::doApply(EditingState* editingState) { |
57 if (!endingSelection().rootEditableElement()) | 57 if (!endingSelection().rootEditableElement()) |
58 return; | 58 return; |
59 | 59 |
60 // ApplyBlockElementCommands are only created directly by editor commands' | 60 // ApplyBlockElementCommands are only created directly by editor commands' |
61 // execution, which updates layout before entering doApply(). | 61 // execution, which updates layout before entering doApply(). |
62 DCHECK(!document().needsLayoutTreeUpdate()); | 62 DCHECK(!document().needsLayoutTreeUpdate()); |
63 | 63 |
| 64 // We don't want to modify outside of <body>. |
| 65 shrinkEndingSelectionToFitBody(); |
| 66 |
64 VisiblePosition visibleEnd = endingSelection().visibleEnd(); | 67 VisiblePosition visibleEnd = endingSelection().visibleEnd(); |
65 VisiblePosition visibleStart = endingSelection().visibleStart(); | 68 VisiblePosition visibleStart = endingSelection().visibleStart(); |
66 if (visibleStart.isNull() || visibleStart.isOrphan() || visibleEnd.isNull() || | 69 if (visibleStart.isNull() || visibleStart.isOrphan() || visibleEnd.isNull() || |
67 visibleEnd.isOrphan()) | 70 visibleEnd.isOrphan()) |
68 return; | 71 return; |
69 | 72 |
70 // When a selection ends at the start of a paragraph, we rarely paint | 73 // When a selection ends at the start of a paragraph, we rarely paint |
71 // the selection gap before that paragraph, because there often is no gap. | 74 // the selection gap before that paragraph, because there often is no gap. |
72 // In a case like this, it's not obvious to the user that the selection | 75 // In a case like this, it's not obvious to the user that the selection |
73 // ends "inside" that paragraph, so it would be confusing if Indent/Outdent | 76 // ends "inside" that paragraph, so it would be confusing if Indent/Outdent |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 405 } |
403 | 406 |
404 HTMLElement* ApplyBlockElementCommand::createBlockElement() const { | 407 HTMLElement* ApplyBlockElementCommand::createBlockElement() const { |
405 HTMLElement* element = createHTMLElement(document(), m_tagName); | 408 HTMLElement* element = createHTMLElement(document(), m_tagName); |
406 if (m_inlineStyle.length()) | 409 if (m_inlineStyle.length()) |
407 element->setAttribute(styleAttr, m_inlineStyle); | 410 element->setAttribute(styleAttr, m_inlineStyle); |
408 return element; | 411 return element; |
409 } | 412 } |
410 | 413 |
411 } // namespace blink | 414 } // namespace blink |
OLD | NEW |