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

Side by Side Diff: Source/core/paint/InlineTextBoxPainter.cpp

Issue 1325563002: Avoid style clobbering in setCompositionFromExistingText. (2nd land) (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix end to refer to endPosition Created 5 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/paint/InlineTextBoxPainter.h" 6 #include "core/paint/InlineTextBoxPainter.h"
7 7
8 #include "core/editing/CompositionUnderline.h" 8 #include "core/editing/CompositionUnderline.h"
9 #include "core/editing/CompositionUnderlineRangeFilter.h" 9 #include "core/editing/CompositionUnderlineRangeFilter.h"
10 #include "core/editing/Editor.h" 10 #include "core/editing/Editor.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 bool isPrinting = paintInfo.isPrinting(); 72 bool isPrinting = paintInfo.isPrinting();
73 73
74 // Determine whether or not we're selected. 74 // Determine whether or not we're selected.
75 bool haveSelection = !isPrinting && paintInfo.phase != PaintPhaseTextClip && m_inlineTextBox.selectionState() != SelectionNone; 75 bool haveSelection = !isPrinting && paintInfo.phase != PaintPhaseTextClip && m_inlineTextBox.selectionState() != SelectionNone;
76 if (!haveSelection && paintInfo.phase == PaintPhaseSelection) { 76 if (!haveSelection && paintInfo.phase == PaintPhaseSelection) {
77 // When only painting the selection, don't bother to paint if there is n one. 77 // When only painting the selection, don't bother to paint if there is n one.
78 return; 78 return;
79 } 79 }
80 80
81 // Determine whether or not we have composition underlines to draw. 81 // Determine whether or not we have composition underlines to draw.
82 bool containsComposition = m_inlineTextBox.layoutObject().node() && m_inline TextBox.layoutObject().frame()->inputMethodController().compositionNode() == m_i nlineTextBox.layoutObject().node(); 82 bool containsComposition = m_inlineTextBox.layoutObject().node() && m_inline TextBox.layoutObject().frame()->inputMethodController().isCompositionNode(m_inli neTextBox.layoutObject().node());
yosin_UTC9 2015/08/31 01:35:40 Note: |isCompositionNode(Node*)| should be fast, s
83 bool useCustomUnderlines = containsComposition && m_inlineTextBox.layoutObje ct().frame()->inputMethodController().compositionUsesCustomUnderlines(); 83 bool useCustomUnderlines = containsComposition && m_inlineTextBox.layoutObje ct().frame()->inputMethodController().customCompositionUnderlines(m_inlineTextBo x.layoutObject().node());
84 84
85 // The text clip phase already has a DrawingRecorder. Text clips are initiat ed only in BoxPainter::paintLayerExtended, which is already 85 // The text clip phase already has a DrawingRecorder. Text clips are initiat ed only in BoxPainter::paintLayerExtended, which is already
86 // within a DrawingRecorder. 86 // within a DrawingRecorder.
87 Optional<DrawingRecorder> drawingRecorder; 87 Optional<DrawingRecorder> drawingRecorder;
88 if (RuntimeEnabledFeatures::slimmingPaintEnabled() && paintInfo.phase != Pai ntPhaseTextClip) { 88 if (RuntimeEnabledFeatures::slimmingPaintEnabled() && paintInfo.phase != Pai ntPhaseTextClip) {
89 if (DrawingRecorder::useCachedDrawingIfPossible(*paintInfo.context, m_in lineTextBox, DisplayItem::paintPhaseToDrawingType(paintInfo.phase))) 89 if (DrawingRecorder::useCachedDrawingIfPossible(*paintInfo.context, m_in lineTextBox, DisplayItem::paintPhaseToDrawingType(paintInfo.phase)))
90 return; 90 return;
91 LayoutRect paintRect(logicalVisualOverflow); 91 LayoutRect paintRect(logicalVisualOverflow);
92 m_inlineTextBox.logicalRectToPhysicalRect(paintRect); 92 m_inlineTextBox.logicalRectToPhysicalRect(paintRect);
93 if (paintInfo.phase != PaintPhaseSelection && (haveSelection || contains Composition || paintsMarkerHighlights(m_inlineTextBox.layoutObject()))) 93 if (paintInfo.phase != PaintPhaseSelection && (haveSelection || contains Composition || paintsMarkerHighlights(m_inlineTextBox.layoutObject())))
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 paintDecoration(paintInfo, boxOrigin, textDecorations); 240 paintDecoration(paintInfo, boxOrigin, textDecorations);
241 if (combinedText) 241 if (combinedText)
242 context->concatCTM(TextPainter::rotation(boxRect, TextPainter::Count erclockwise)); 242 context->concatCTM(TextPainter::rotation(boxRect, TextPainter::Count erclockwise));
243 } 243 }
244 244
245 if (paintInfo.phase == PaintPhaseForeground) { 245 if (paintInfo.phase == PaintPhaseForeground) {
246 paintDocumentMarkers(context, boxOrigin, styleToUse, font, false); 246 paintDocumentMarkers(context, boxOrigin, styleToUse, font, false);
247 247
248 // Paint custom underlines for compositions. 248 // Paint custom underlines for compositions.
249 if (useCustomUnderlines) { 249 if (useCustomUnderlines) {
250 const Vector<CompositionUnderline>& underlines = m_inlineTextBox.lay outObject().frame()->inputMethodController().customCompositionUnderlines(); 250 if (const Vector<CompositionUnderline>* underlines = m_inlineTextBox .layoutObject().frame()->inputMethodController().customCompositionUnderlines(m_i nlineTextBox.layoutObject().node())) {
251 CompositionUnderlineRangeFilter filter(underlines, m_inlineTextBox.s tart(), m_inlineTextBox.end()); 251 CompositionUnderlineRangeFilter filter(*underlines, m_inlineText Box.start(), m_inlineTextBox.end());
252 for (CompositionUnderlineRangeFilter::ConstIterator it = filter.begi n(); it != filter.end(); ++it) { 252 for (CompositionUnderlineRangeFilter::ConstIterator it = filter. begin(); it != filter.end(); ++it) {
253 if (it->color == Color::transparent) 253 if (it->color == Color::transparent)
254 continue; 254 continue;
255 paintCompositionUnderline(context, boxOrigin, *it); 255 paintCompositionUnderline(context, boxOrigin, *it);
256 }
256 } 257 }
257 } 258 }
258 } 259 }
259 260
260 if (shouldRotate) 261 if (shouldRotate)
261 context->concatCTM(TextPainter::rotation(boxRect, TextPainter::Countercl ockwise)); 262 context->concatCTM(TextPainter::rotation(boxRect, TextPainter::Countercl ockwise));
262 } 263 }
263 264
264 unsigned InlineTextBoxPainter::underlinePaintStart(const CompositionUnderline& u nderline) 265 unsigned InlineTextBoxPainter::underlinePaintStart(const CompositionUnderline& u nderline)
265 { 266 {
266 return std::max(static_cast<unsigned>(m_inlineTextBox.start()), underline.st artOffset); 267 return std::max(static_cast<unsigned>(m_inlineTextBox.start()), underline.st artOffset);
267 } 268 }
268 269
269 unsigned InlineTextBoxPainter::underlinePaintEnd(const CompositionUnderline& und erline) 270 unsigned InlineTextBoxPainter::underlinePaintEnd(const CompositionUnderline& und erline)
270 { 271 {
271 unsigned paintEnd = std::min(m_inlineTextBox.end() + 1, underline.endOffset) ; // end() points at the last char, not past it. 272 unsigned paintEnd = std::min(m_inlineTextBox.end() + 1, underline.endOffset) ; // end() points at the last char, not past it.
272 if (m_inlineTextBox.truncation() != cNoTruncation) 273 if (m_inlineTextBox.truncation() != cNoTruncation)
273 paintEnd = std::min(paintEnd, static_cast<unsigned>(m_inlineTextBox.star t() + m_inlineTextBox.truncation())); 274 paintEnd = std::min(paintEnd, static_cast<unsigned>(m_inlineTextBox.star t() + m_inlineTextBox.truncation()));
274 return paintEnd; 275 return paintEnd;
275 } 276 }
276 277
277 void InlineTextBoxPainter::paintCompositionBackgrounds(GraphicsContext* pt, cons t LayoutPoint& boxOrigin, const ComputedStyle& style, const Font& font, bool use CustomUnderlines) 278 void InlineTextBoxPainter::paintCompositionBackgrounds(GraphicsContext* pt, cons t LayoutPoint& boxOrigin, const ComputedStyle& style, const Font& font, bool use CustomUnderlines)
278 { 279 {
279 if (useCustomUnderlines) { 280 if (useCustomUnderlines) {
280 // Paint custom background highlights for compositions. 281 // Paint custom background highlights for compositions.
281 const Vector<CompositionUnderline>& underlines = m_inlineTextBox.layoutO bject().frame()->inputMethodController().customCompositionUnderlines(); 282 if (const Vector<CompositionUnderline>* underlines = m_inlineTextBox.lay outObject().frame()->inputMethodController().customCompositionUnderlines(m_inlin eTextBox.layoutObject().node())) {
282 CompositionUnderlineRangeFilter filter(underlines, m_inlineTextBox.start (), m_inlineTextBox.end()); 283 CompositionUnderlineRangeFilter filter(*underlines, m_inlineTextBox. start(), m_inlineTextBox.end());
283 for (CompositionUnderlineRangeFilter::ConstIterator it = filter.begin(); it != filter.end(); ++it) { 284 for (CompositionUnderlineRangeFilter::ConstIterator it = filter.begi n(); it != filter.end(); ++it) {
284 if (it->backgroundColor == Color::transparent) 285 if (it->backgroundColor == Color::transparent)
285 continue; 286 continue;
286 paintSingleCompositionBackgroundRun(pt, boxOrigin, style, font, it-> backgroundColor, underlinePaintStart(*it), underlinePaintEnd(*it)); 287 paintSingleCompositionBackgroundRun(pt, boxOrigin, style, font, it->backgroundColor, underlinePaintStart(*it), underlinePaintEnd(*it));
288 }
287 } 289 }
288
289 } else { 290 } else {
290 paintSingleCompositionBackgroundRun(pt, boxOrigin, style, font, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor(), 291 paintSingleCompositionBackgroundRun(pt, boxOrigin, style, font, LayoutTh eme::theme().platformDefaultCompositionBackgroundColor(),
291 m_inlineTextBox.layoutObject().frame()->inputMethodController().comp ositionStart(), 292 m_inlineTextBox.layoutObject().frame()->inputMethodController().comp ositionStart(),
292 m_inlineTextBox.layoutObject().frame()->inputMethodController().comp ositionEnd()); 293 m_inlineTextBox.layoutObject().frame()->inputMethodController().comp ositionEnd());
293 } 294 }
294 } 295 }
295 296
296 void InlineTextBoxPainter::paintSingleCompositionBackgroundRun(GraphicsContext* context, const LayoutPoint& boxOrigin, const ComputedStyle& style, const Font& f ont, Color backgroundColor, int startPos, int endPos) 297 void InlineTextBoxPainter::paintSingleCompositionBackgroundRun(GraphicsContext* context, const LayoutPoint& boxOrigin, const ComputedStyle& style, const Font& f ont, Color backgroundColor, int startPos, int endPos)
297 { 298 {
298 int sPos = std::max(startPos - static_cast<int>(m_inlineTextBox.start()), 0) ; 299 int sPos = std::max(startPos - static_cast<int>(m_inlineTextBox.start()), 0) ;
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.fontMetri cs().ascent()); 830 LayoutPoint textOrigin(boxOrigin.x(), boxOrigin.y() + font.fontMetri cs().ascent());
830 TextPainter textPainter(pt, font, run, textOrigin, boxRect, m_inline TextBox.isHorizontal()); 831 TextPainter textPainter(pt, font, run, textOrigin, boxRect, m_inline TextBox.isHorizontal());
831 832
832 textPainter.paint(sPos, ePos, length, textStyle, 0); 833 textPainter.paint(sPos, ePos, length, textStyle, 0);
833 } 834 }
834 } 835 }
835 } 836 }
836 837
837 838
838 } // namespace blink 839 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698