Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/NGTextFragmentPainter.h" | 5 #include "core/paint/NGTextFragmentPainter.h" |
| 6 | 6 |
| 7 #include "core/editing/FrameSelection.h" | |
| 7 #include "core/frame/LocalFrame.h" | 8 #include "core/frame/LocalFrame.h" |
| 8 #include "core/layout/ng/inline/ng_physical_text_fragment.h" | 9 #include "core/layout/ng/inline/ng_physical_text_fragment.h" |
| 9 #include "core/paint/NGTextPainter.h" | 10 #include "core/paint/NGTextPainter.h" |
| 10 #include "core/paint/PaintInfo.h" | 11 #include "core/paint/PaintInfo.h" |
| 11 #include "core/paint/TextPainterBase.h" | 12 #include "core/paint/TextPainterBase.h" |
| 12 #include "core/style/AppliedTextDecoration.h" | 13 #include "core/style/AppliedTextDecoration.h" |
| 13 #include "platform/graphics/GraphicsContextStateSaver.h" | 14 #include "platform/graphics/GraphicsContextStateSaver.h" |
| 14 #include "platform/graphics/paint/DrawingRecorder.h" | 15 #include "platform/graphics/paint/DrawingRecorder.h" |
| 15 #include "platform/wtf/Optional.h" | 16 #include "platform/wtf/Optional.h" |
| 16 | 17 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 // decoration, | 69 // decoration, |
| 69 // overline_offset); | 70 // overline_offset); |
| 70 // } | 71 // } |
| 71 // // We could instead build a vector of the TextDecoration instances needing | 72 // // We could instead build a vector of the TextDecoration instances needing |
| 72 // // line-through but this is a rare case so better to avoid vector | 73 // // line-through but this is a rare case so better to avoid vector |
| 73 // overhead. has_line_through_decoration |= ((lines & | 74 // overhead. has_line_through_decoration |= ((lines & |
| 74 // kTextDecorationLineThrough) != 0); | 75 // kTextDecorationLineThrough) != 0); |
| 75 //} | 76 //} |
| 76 } | 77 } |
| 77 | 78 |
| 79 static std::pair<int, int> SelectionStartEnd( | |
|
kojii
2017/06/16 11:25:57
Can add explanation what this function does and wh
yoichio
2017/06/21 08:16:43
This returns 0-origin offset range in NGPhysicalTe
| |
| 80 const NGPhysicalTextFragment* text_fragment) { | |
| 81 const SelectionState& selection_state = | |
| 82 text_fragment->GetLayoutObject()->GetSelectionState(); | |
| 83 if (selection_state == SelectionState::kNone) | |
| 84 return {0, 0}; | |
| 85 if (selection_state == SelectionState::kInside) | |
| 86 return {0, text_fragment->Text().length()}; | |
|
kojii
2017/06/16 11:25:57
why it computes min/max to text_fragment->Start/En
yoichio
2017/06/21 08:16:43
Ah, it should be {text_fragment->StartOffst(),
te
| |
| 87 | |
| 88 const std::pair<int, int> startend_in_ngblockflow = | |
|
kojii
2017/06/16 11:25:57
I can't understand how this works...so you get two
yoichio
2017/06/21 08:16:43
They are index in NGInlineNodeData.text_content_,
kojii
2017/06/21 10:10:09
But you get data from Frame, without passing text_
| |
| 89 text_fragment->GetLayoutObject() | |
| 90 ->GetFrameView() | |
| 91 ->GetFrame() | |
| 92 .Selection() | |
| 93 .LayoutSelectionStartEnd(); | |
| 94 int selection_start = std::max<int>( | |
| 95 0, startend_in_ngblockflow.first - text_fragment->StartOffset()); | |
|
kojii
2017/06/16 11:25:57
This might not work, because StartOffset() is unsi
| |
| 96 int selection_end = std::min<int>( | |
| 97 text_fragment->Text().length(), | |
| 98 startend_in_ngblockflow.second - text_fragment->StartOffset()); | |
| 99 | |
| 100 switch (selection_state) { | |
| 101 case SelectionState::kStart: | |
| 102 return {selection_start, text_fragment->Text().length()}; | |
| 103 case SelectionState::kEnd: | |
| 104 return {0, selection_end}; | |
| 105 case SelectionState::kStartAndEnd: | |
| 106 return {selection_start, selection_end}; | |
| 107 } | |
| 108 | |
| 109 NOTREACHED(); | |
| 110 return {0, 0}; | |
| 111 } | |
| 112 | |
| 78 } // anonymous namespace | 113 } // anonymous namespace |
| 79 | 114 |
| 80 void NGTextFragmentPainter::Paint(const Document& document, | 115 void NGTextFragmentPainter::Paint(const Document& document, |
| 81 const PaintInfo& paint_info, | 116 const PaintInfo& paint_info, |
| 82 const LayoutPoint& paint_offset) { | 117 const LayoutPoint& paint_offset) { |
| 83 // TODO(eae): Move | 118 // TODO(eae): Move |
| 84 static unsigned short kCNoTruncation = USHRT_MAX; | 119 static unsigned short kCNoTruncation = USHRT_MAX; |
| 85 static unsigned short kCFullTruncation = USHRT_MAX - 1; | 120 static unsigned short kCFullTruncation = USHRT_MAX - 1; |
| 86 | 121 |
| 87 const ComputedStyle& style_to_use = text_fragment_->Style(); | 122 const ComputedStyle& style_to_use = text_fragment_->Style(); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 115 } | 150 } |
| 116 | 151 |
| 117 // Determine text colors. | 152 // Determine text colors. |
| 118 TextPainterBase::Style text_style = | 153 TextPainterBase::Style text_style = |
| 119 TextPainterBase::TextPaintingStyle(document, style_to_use, paint_info); | 154 TextPainterBase::TextPaintingStyle(document, style_to_use, paint_info); |
| 120 // TextPainterBase::Style selection_style = | 155 // TextPainterBase::Style selection_style = |
| 121 // TextPainter::SelectionPaintingStyle( | 156 // TextPainter::SelectionPaintingStyle( |
| 122 // text_fragment_.GetLineLayoutItem(), have_selection, paint_info, | 157 // text_fragment_.GetLineLayoutItem(), have_selection, paint_info, |
| 123 // text_style); | 158 // text_style); |
| 124 TextPainterBase::Style selection_style = text_style; | 159 TextPainterBase::Style selection_style = text_style; |
| 160 selection_style.fill_color = Color(1.0f, 0.0f, 0.0f, 1.0f); | |
|
kojii
2017/06/16 11:25:57
this is temporary, correct? Can you add TODO comme
yoichio
2017/06/21 08:16:43
Yes, just for testing. Remove from reviewing.
| |
| 125 bool paint_selected_text_only = (paint_info.phase == kPaintPhaseSelection); | 161 bool paint_selected_text_only = (paint_info.phase == kPaintPhaseSelection); |
| 126 bool paint_selected_text_separately = | 162 bool paint_selected_text_separately = |
| 127 !paint_selected_text_only && text_style != selection_style; | 163 !paint_selected_text_only && text_style != selection_style; |
| 128 | 164 |
| 129 // Set our font. | 165 // Set our font. |
| 130 const Font& font = style_to_use.GetFont(); | 166 const Font& font = style_to_use.GetFont(); |
| 131 const SimpleFontData* font_data = font.PrimaryFont(); | 167 const SimpleFontData* font_data = font.PrimaryFont(); |
| 132 DCHECK(font_data); | 168 DCHECK(font_data); |
| 133 | 169 |
| 134 int ascent = font_data ? font_data->GetFontMetrics().Ascent() : 0; | 170 int ascent = font_data ? font_data->GetFontMetrics().Ascent() : 0; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 151 // else | 187 // else |
| 152 // PaintSelection<InlineTextBoxPainter::PaintOptions::kNormal>( | 188 // PaintSelection<InlineTextBoxPainter::PaintOptions::kNormal>( |
| 153 // context, box_rect, style_to_use, font, | 189 // context, box_rect, style_to_use, font, |
| 154 // selection_style.fill_color); | 190 // selection_style.fill_color); |
| 155 //} | 191 //} |
| 156 } | 192 } |
| 157 | 193 |
| 158 // 2. Now paint the foreground, including text and decorations. | 194 // 2. Now paint the foreground, including text and decorations. |
| 159 int selection_start = 0; | 195 int selection_start = 0; |
| 160 int selection_end = 0; | 196 int selection_end = 0; |
| 161 // if (paint_selected_text_only || paint_selected_text_separately) | 197 if (paint_selected_text_only || paint_selected_text_separately) { |
| 162 // text_fragment_.SelectionStartEnd(selection_start, selection_end); | 198 std::tie(selection_start, selection_end) = |
| 199 SelectionStartEnd(text_fragment_); | |
| 200 } | |
| 163 | 201 |
| 164 // bool respect_hyphen = | 202 // bool respect_hyphen = |
| 165 // selection_end == static_cast<int>(text_fragment_.Len()) && | 203 // selection_end == static_cast<int>(text_fragment_.Len()) && |
| 166 // text_fragment_.HasHyphen(); | 204 // text_fragment_.HasHyphen(); |
| 167 // if (respect_hyphen) | 205 // if (respect_hyphen) |
| 168 // selection_end = text_run.length(); | 206 // selection_end = text_run.length(); |
| 169 | 207 |
| 170 unsigned length = text_fragment_->Text().length(); | 208 unsigned length = text_fragment_->Text().length(); |
| 171 | 209 |
| 172 bool ltr = true; | 210 bool ltr = true; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 270 // PaintDocumentMarkers(paint_info, box_origin, style_to_use, font, | 308 // PaintDocumentMarkers(paint_info, box_origin, style_to_use, font, |
| 271 // DocumentMarkerPaintPhase::kForeground); | 309 // DocumentMarkerPaintPhase::kForeground); |
| 272 | 310 |
| 273 if (should_rotate) { | 311 if (should_rotate) { |
| 274 context.ConcatCTM(TextPainterBase::Rotation( | 312 context.ConcatCTM(TextPainterBase::Rotation( |
| 275 box_rect, TextPainterBase::kCounterclockwise)); | 313 box_rect, TextPainterBase::kCounterclockwise)); |
| 276 } | 314 } |
| 277 } | 315 } |
| 278 | 316 |
| 279 } // namespace blink | 317 } // namespace blink |
| OLD | NEW |