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

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

Issue 2007103003: Expand WTF::StringView's API to be more like StringPiece. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a lot of tests, fix a bunch of bugs. Created 4 years, 6 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 "core/paint/InlineTextBoxPainter.h" 5 #include "core/paint/InlineTextBoxPainter.h"
6 6
7 #include "core/editing/CompositionUnderline.h" 7 #include "core/editing/CompositionUnderline.h"
8 #include "core/editing/Editor.h" 8 #include "core/editing/Editor.h"
9 #include "core/editing/markers/DocumentMarkerController.h" 9 #include "core/editing/markers/DocumentMarkerController.h"
10 #include "core/editing/markers/RenderedDocumentMarker.h" 10 #include "core/editing/markers/RenderedDocumentMarker.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 if (haveSelection && !paintsCompositionMarkers(textBoxLayoutObject)) { 142 if (haveSelection && !paintsCompositionMarkers(textBoxLayoutObject)) {
143 if (combinedText) 143 if (combinedText)
144 paintSelection<InlineTextBoxPainter::PaintOptions::CombinedText> (context, boxRect, styleToUse, font, selectionStyle.fillColor, combinedText); 144 paintSelection<InlineTextBoxPainter::PaintOptions::CombinedText> (context, boxRect, styleToUse, font, selectionStyle.fillColor, combinedText);
145 else 145 else
146 paintSelection<InlineTextBoxPainter::PaintOptions::Normal>(conte xt, boxRect, styleToUse, font, selectionStyle.fillColor); 146 paintSelection<InlineTextBoxPainter::PaintOptions::Normal>(conte xt, boxRect, styleToUse, font, selectionStyle.fillColor);
147 } 147 }
148 } 148 }
149 149
150 // 2. Now paint the foreground, including text and decorations like underlin e/overline (in quirks mode only). 150 // 2. Now paint the foreground, including text and decorations like underlin e/overline (in quirks mode only).
151 int length = m_inlineTextBox.len(); 151 int length = m_inlineTextBox.len();
152 StringView string = m_inlineTextBox.getLineLayoutItem().text().createView(); 152 StringView string = StringView(m_inlineTextBox.getLineLayoutItem().text(), m _inlineTextBox.start(), length);
153 ASSERT(m_inlineTextBox.start() + length <= string.length());
154 if (static_cast<unsigned>(length) != string.length() || m_inlineTextBox.star t())
155 string.narrow(m_inlineTextBox.start(), length);
156 int maximumLength = m_inlineTextBox.getLineLayoutItem().textLength() - m_inl ineTextBox.start(); 153 int maximumLength = m_inlineTextBox.getLineLayoutItem().textLength() - m_inl ineTextBox.start();
157 154
158 StringBuilder charactersWithHyphen; 155 StringBuilder charactersWithHyphen;
159 TextRun textRun = m_inlineTextBox.constructTextRun(styleToUse, font, string, maximumLength, m_inlineTextBox.hasHyphen() ? &charactersWithHyphen : 0); 156 TextRun textRun = m_inlineTextBox.constructTextRun(styleToUse, font, string, maximumLength, m_inlineTextBox.hasHyphen() ? &charactersWithHyphen : 0);
160 if (m_inlineTextBox.hasHyphen()) 157 if (m_inlineTextBox.hasHyphen())
161 length = textRun.length(); 158 length = textRun.length();
162 159
163 int selectionStart = 0; 160 int selectionStart = 0;
164 int selectionEnd = 0; 161 int selectionEnd = 0;
165 if (paintSelectedTextOnly || paintSelectedTextSeparately) 162 if (paintSelectedTextOnly || paintSelectedTextSeparately)
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 return; 431 return;
435 432
436 // If the text color ends up being the same as the selection background, inv ert the selection 433 // If the text color ends up being the same as the selection background, inv ert the selection
437 // background. 434 // background.
438 if (textColor == c) 435 if (textColor == c)
439 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue()); 436 c = Color(0xff - c.red(), 0xff - c.green(), 0xff - c.blue());
440 437
441 // If the text is truncated, let the thing being painted in the truncation 438 // If the text is truncated, let the thing being painted in the truncation
442 // draw its own highlight. 439 // draw its own highlight.
443 int length = m_inlineTextBox.truncation() != cNoTruncation ? m_inlineTextBox .truncation() : m_inlineTextBox.len(); 440 int length = m_inlineTextBox.truncation() != cNoTruncation ? m_inlineTextBox .truncation() : m_inlineTextBox.len();
444 StringView string = m_inlineTextBox.getLineLayoutItem().text().createView(); 441 StringView string(m_inlineTextBox.getLineLayoutItem().text(), m_inlineTextBo x.start(), static_cast<unsigned>(length));
445
446 if (string.length() != static_cast<unsigned>(length) || m_inlineTextBox.star t())
447 string.narrow(m_inlineTextBox.start(), length);
448 442
449 StringBuilder charactersWithHyphen; 443 StringBuilder charactersWithHyphen;
450 bool respectHyphen = ePos == length && m_inlineTextBox.hasHyphen(); 444 bool respectHyphen = ePos == length && m_inlineTextBox.hasHyphen();
451 TextRun textRun = m_inlineTextBox.constructTextRun(style, font, string, m_in lineTextBox.getLineLayoutItem().textLength() - m_inlineTextBox.start(), respectH yphen ? &charactersWithHyphen : 0); 445 TextRun textRun = m_inlineTextBox.constructTextRun(style, font, string, m_in lineTextBox.getLineLayoutItem().textLength() - m_inlineTextBox.start(), respectH yphen ? &charactersWithHyphen : 0);
452 if (respectHyphen) 446 if (respectHyphen)
453 ePos = textRun.length(); 447 ePos = textRun.length();
454 448
455 GraphicsContextStateSaver stateSaver(context); 449 GraphicsContextStateSaver stateSaver(context);
456 450
457 if (options == InlineTextBoxPainter::PaintOptions::CombinedText) { 451 if (options == InlineTextBoxPainter::PaintOptions::CombinedText) {
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 847
854 Color color = LayoutTheme::theme().platformTextSearchHighlightColor(marker-> activeMatch()); 848 Color color = LayoutTheme::theme().platformTextSearchHighlightColor(marker-> activeMatch());
855 GraphicsContext& context = paintInfo.context; 849 GraphicsContext& context = paintInfo.context;
856 GraphicsContextStateSaver stateSaver(context); 850 GraphicsContextStateSaver stateSaver(context);
857 context.clip(FloatRect(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toF loat(), m_inlineTextBox.logicalWidth().toFloat(), selHeight)); 851 context.clip(FloatRect(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toF loat(), m_inlineTextBox.logicalWidth().toFloat(), selHeight));
858 context.drawHighlightForText(font, run, FloatPoint(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toFloat()), selHeight, color, sPos, ePos); 852 context.drawHighlightForText(font, run, FloatPoint(boxOrigin.x().toFloat(), (boxOrigin.y() - deltaY).toFloat()), selHeight, color, sPos, ePos);
859 } 853 }
860 854
861 855
862 } // namespace blink 856 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698