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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutText.cpp

Issue 2299213003: Fix the inconsistent problem while the content of textNodes is changed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add layout test cases and fix format issues Created 4 years, 1 month 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 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org) 3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
5 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) 5 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net)
6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) 6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 16 matching lines...) Expand all
27 #include "core/dom/AXObjectCache.h" 27 #include "core/dom/AXObjectCache.h"
28 #include "core/dom/Text.h" 28 #include "core/dom/Text.h"
29 #include "core/editing/VisiblePosition.h" 29 #include "core/editing/VisiblePosition.h"
30 #include "core/editing/iterators/TextIterator.h" 30 #include "core/editing/iterators/TextIterator.h"
31 #include "core/frame/FrameView.h" 31 #include "core/frame/FrameView.h"
32 #include "core/frame/Settings.h" 32 #include "core/frame/Settings.h"
33 #include "core/layout/LayoutBlock.h" 33 #include "core/layout/LayoutBlock.h"
34 #include "core/layout/LayoutTableCell.h" 34 #include "core/layout/LayoutTableCell.h"
35 #include "core/layout/LayoutTextCombine.h" 35 #include "core/layout/LayoutTextCombine.h"
36 #include "core/layout/LayoutView.h" 36 #include "core/layout/LayoutView.h"
37 #include "core/layout/TextAutosizer.h"
37 #include "core/layout/api/LineLayoutBox.h" 38 #include "core/layout/api/LineLayoutBox.h"
38 #include "core/layout/line/AbstractInlineTextBox.h" 39 #include "core/layout/line/AbstractInlineTextBox.h"
39 #include "core/layout/line/EllipsisBox.h" 40 #include "core/layout/line/EllipsisBox.h"
40 #include "core/layout/line/GlyphOverflow.h" 41 #include "core/layout/line/GlyphOverflow.h"
41 #include "core/layout/line/InlineTextBox.h" 42 #include "core/layout/line/InlineTextBox.h"
42 #include "platform/fonts/CharacterRange.h" 43 #include "platform/fonts/CharacterRange.h"
43 #include "platform/geometry/FloatQuad.h" 44 #include "platform/geometry/FloatQuad.h"
44 #include "platform/text/BidiResolver.h" 45 #include "platform/text/BidiResolver.h"
45 #include "platform/text/Character.h" 46 #include "platform/text/Character.h"
46 #include "platform/text/Hyphenation.h" 47 #include "platform/text/Hyphenation.h"
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 const ComputedStyle& newStyle = styleRef(); 203 const ComputedStyle& newStyle = styleRef();
203 ETextTransform oldTransform = oldStyle ? oldStyle->textTransform() : TTNONE; 204 ETextTransform oldTransform = oldStyle ? oldStyle->textTransform() : TTNONE;
204 ETextSecurity oldSecurity = oldStyle ? oldStyle->textSecurity() : TSNONE; 205 ETextSecurity oldSecurity = oldStyle ? oldStyle->textSecurity() : TSNONE;
205 if (oldTransform != newStyle.textTransform() || 206 if (oldTransform != newStyle.textTransform() ||
206 oldSecurity != newStyle.textSecurity()) 207 oldSecurity != newStyle.textSecurity())
207 transformText(); 208 transformText();
208 209
209 // This is an optimization that kicks off font load before layout. 210 // This is an optimization that kicks off font load before layout.
210 if (!text().containsOnlyWhitespace()) 211 if (!text().containsOnlyWhitespace())
211 newStyle.font().willUseFontData(text()); 212 newStyle.font().willUseFontData(text());
213
214 TextAutosizer* textAutosizer = document().textAutosizer();
215 unsigned newAddedTextLength = text().stripWhiteSpace().length();
216 if (!oldStyle && textAutosizer && newAddedTextLength > 0 &&
skobes 2016/11/09 03:11:39 Why do we check !oldStyle here?
cathiechentx 2016/11/09 12:58:46 We only keep a count of new created/added text. "!
217 newStyle.textAutosizingFingerPrint() != 0) {
218 textAutosizer->textAutosizingNewTextAdded(
219 newStyle.textAutosizingFingerPrint(), newAddedTextLength);
skobes 2016/11/09 03:11:39 Can we just pass the LayoutText* and have TextAuto
cathiechentx 2016/11/09 12:58:46 yes, passing the LayoutText* is more elegant, and
220 }
212 } 221 }
213 222
214 void LayoutText::removeAndDestroyTextBoxes() { 223 void LayoutText::removeAndDestroyTextBoxes() {
215 if (!documentBeingDestroyed()) { 224 if (!documentBeingDestroyed()) {
216 if (firstTextBox()) { 225 if (firstTextBox()) {
217 if (isBR()) { 226 if (isBR()) {
218 RootInlineBox* next = firstTextBox()->root().nextRootBox(); 227 RootInlineBox* next = firstTextBox()->root().nextRootBox();
219 if (next) 228 if (next)
220 next->markDirty(); 229 next->markDirty();
221 } 230 }
(...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 secureTextTimer->invalidate(); 1656 secureTextTimer->invalidate();
1648 } 1657 }
1649 } 1658 }
1650 1659
1651 void LayoutText::setText(PassRefPtr<StringImpl> text, bool force) { 1660 void LayoutText::setText(PassRefPtr<StringImpl> text, bool force) {
1652 ASSERT(text); 1661 ASSERT(text);
1653 1662
1654 if (!force && equal(m_text.impl(), text.get())) 1663 if (!force && equal(m_text.impl(), text.get()))
1655 return; 1664 return;
1656 1665
1666 int newAddedTextLength =
1667 text->stripWhiteSpace()->length() - m_text.stripWhiteSpace().length();
1657 setTextInternal(std::move(text)); 1668 setTextInternal(std::move(text));
1658 // If preferredLogicalWidthsDirty() of an orphan child is true, 1669 // If preferredLogicalWidthsDirty() of an orphan child is true,
1659 // LayoutObjectChildList::insertChildNode() fails to set true to owner. 1670 // LayoutObjectChildList::insertChildNode() fails to set true to owner.
1660 // To avoid that, we call setNeedsLayoutAndPrefWidthsRecalc() only if this 1671 // To avoid that, we call setNeedsLayoutAndPrefWidthsRecalc() only if this
1661 // LayoutText has parent. 1672 // LayoutText has parent.
1662 if (parent()) 1673 if (parent())
1663 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation( 1674 setNeedsLayoutAndPrefWidthsRecalcAndFullPaintInvalidation(
1664 LayoutInvalidationReason::TextChanged); 1675 LayoutInvalidationReason::TextChanged);
1665 m_knownToHaveNoOverflowAndNoFallbackFonts = false; 1676 m_knownToHaveNoOverflowAndNoFallbackFonts = false;
1666 1677
1678 TextAutosizer* textAutosizer = document().textAutosizer();
1679 if (textAutosizer && style() && newAddedTextLength > 0 &&
1680 style()->textAutosizingFingerPrint() != 0) {
1681 textAutosizer->textAutosizingNewTextAdded(
1682 style()->textAutosizingFingerPrint(), (unsigned)newAddedTextLength);
1683 }
1684
1667 if (AXObjectCache* cache = document().existingAXObjectCache()) 1685 if (AXObjectCache* cache = document().existingAXObjectCache())
1668 cache->textChanged(this); 1686 cache->textChanged(this);
1669 } 1687 }
1670 1688
1671 void LayoutText::dirtyOrDeleteLineBoxesIfNeeded(bool fullLayout) { 1689 void LayoutText::dirtyOrDeleteLineBoxesIfNeeded(bool fullLayout) {
1672 if (fullLayout) 1690 if (fullLayout)
1673 deleteTextBoxes(); 1691 deleteTextBoxes();
1674 else if (!m_linesDirty) 1692 else if (!m_linesDirty)
1675 dirtyLineBoxes(); 1693 dirtyLineBoxes();
1676 m_linesDirty = false; 1694 m_linesDirty = false;
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 LayoutRect rect = LayoutRect( 1991 LayoutRect rect = LayoutRect(
1974 IntRect(firstRunX(), firstRunY(), linesBox.width(), linesBox.height())); 1992 IntRect(firstRunX(), firstRunY(), linesBox.width(), linesBox.height()));
1975 LayoutBlock* block = containingBlock(); 1993 LayoutBlock* block = containingBlock();
1976 if (block && hasTextBoxes()) 1994 if (block && hasTextBoxes())
1977 block->adjustChildDebugRect(rect); 1995 block->adjustChildDebugRect(rect);
1978 1996
1979 return rect; 1997 return rect;
1980 } 1998 }
1981 1999
1982 } // namespace blink 2000 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698