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

Side by Side Diff: third_party/WebKit/Source/web/WebSurroundingText.cpp

Issue 2430273006: Remove the redundant layout update from WebSurroundingText::textContent (Closed)
Patch Set: Add note about do not store SurroundingText with null Range Created 4 years, 2 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 | « third_party/WebKit/Source/core/editing/SurroundingText.cpp ('k') | no next file » | 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) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 return; 51 return;
52 52
53 // VisiblePosition and SurroundingText must be created with clean layout. 53 // VisiblePosition and SurroundingText must be created with clean layout.
54 node->document().updateStyleAndLayoutIgnorePendingStylesheets(); 54 node->document().updateStyleAndLayoutIgnorePendingStylesheets();
55 DocumentLifecycle::DisallowTransitionScope disallowTransition( 55 DocumentLifecycle::DisallowTransitionScope disallowTransition(
56 node->document().lifecycle()); 56 node->document().lifecycle());
57 57
58 if (!node->layoutObject()) 58 if (!node->layoutObject())
59 return; 59 return;
60 60
61 // TODO(xiaochengh): The followinng SurroundingText can hold a null Range,
62 // in which case we should prevent it from being stored in |m_privated|.
tkent 2016/10/20 05:33:58 m_privated -> m_private
Xiaocheng 2016/10/20 05:37:49 Done.
61 m_private.reset(new SurroundingText( 63 m_private.reset(new SurroundingText(
62 createVisiblePosition(node->layoutObject()->positionForPoint( 64 createVisiblePosition(node->layoutObject()->positionForPoint(
63 static_cast<IntPoint>(nodePoint))) 65 static_cast<IntPoint>(nodePoint)))
64 .deepEquivalent() 66 .deepEquivalent()
65 .parentAnchoredEquivalent(), 67 .parentAnchoredEquivalent(),
66 maxLength)); 68 maxLength));
67 } 69 }
68 70
69 void WebSurroundingText::initializeFromCurrentSelection(WebLocalFrame* frame, 71 void WebSurroundingText::initializeFromCurrentSelection(WebLocalFrame* frame,
70 size_t maxLength) { 72 size_t maxLength) {
71 LocalFrame* webFrame = toWebLocalFrameImpl(frame)->frame(); 73 LocalFrame* webFrame = toWebLocalFrameImpl(frame)->frame();
72 74
73 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 75 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
74 // needs to be audited. See http://crbug.com/590369 for more details. 76 // needs to be audited. See http://crbug.com/590369 for more details.
75 webFrame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 77 webFrame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
76 78
77 if (Range* range = createRange( 79 if (Range* range = createRange(
78 webFrame->selection().selection().toNormalizedEphemeralRange())) 80 webFrame->selection().selection().toNormalizedEphemeralRange())) {
81 // TODO(xiaochengh): The followinng SurroundingText can hold a null Range,
82 // in which case we should prevent it from being stored in |m_privated|.
tkent 2016/10/20 05:33:58 m_privated -> m_private
Xiaocheng 2016/10/20 05:37:49 Done.
79 m_private.reset(new SurroundingText(*range, maxLength)); 83 m_private.reset(new SurroundingText(*range, maxLength));
84 }
80 } 85 }
81 86
82 WebString WebSurroundingText::textContent() const { 87 WebString WebSurroundingText::textContent() const {
83 DCHECK(m_private->document());
84
85 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
86 // needs to be audited. See http://crbug.com/590369 for more details.
87 m_private->document()->updateStyleAndLayoutIgnorePendingStylesheets();
88
89 return m_private->content(); 88 return m_private->content();
90 } 89 }
91 90
92 size_t WebSurroundingText::hitOffsetInTextContent() const { 91 size_t WebSurroundingText::hitOffsetInTextContent() const {
93 DCHECK_EQ(m_private->startOffsetInContent(), m_private->endOffsetInContent()); 92 DCHECK_EQ(m_private->startOffsetInContent(), m_private->endOffsetInContent());
94 return m_private->startOffsetInContent(); 93 return m_private->startOffsetInContent();
95 } 94 }
96 95
97 size_t WebSurroundingText::startOffsetInTextContent() const { 96 size_t WebSurroundingText::startOffsetInTextContent() const {
98 return m_private->startOffsetInContent(); 97 return m_private->startOffsetInContent();
99 } 98 }
100 99
101 size_t WebSurroundingText::endOffsetInTextContent() const { 100 size_t WebSurroundingText::endOffsetInTextContent() const {
102 return m_private->endOffsetInContent(); 101 return m_private->endOffsetInContent();
103 } 102 }
104 103
105 bool WebSurroundingText::isNull() const { 104 bool WebSurroundingText::isNull() const {
106 return !m_private.get(); 105 return !m_private.get();
107 } 106 }
108 107
109 } // namespace blink 108 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/SurroundingText.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698