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

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

Issue 2913773002: [WIP][b:eae_mywip_paint] Paint Selection NG.
Patch Set: tmp Created 3 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 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
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(
yoichio 2017/06/27 07:54:53 Much comment is appreciate
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()};
yoichio 2017/06/27 07:54:53 Rerturn painting full; define lewngth;
87
88 const std::pair<int, int> startend_in_ngblockflow =
89 text_fragment->GetLayoutObject()
90 ->GetFrameView()
91 ->GetFrame()
92 .Selection()
93 .LayoutSelectionStartEnd();
yoichio 2017/06/27 07:54:53 Describe much more.
94 int selection_start = std::max<int>(
95 0, startend_in_ngblockflow.first - text_fragment->StartOffset());
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 default:
108 NOTREACHED();
109 }
110
111 NOTREACHED();
112 return {0, 0};
113 }
114
78 } // anonymous namespace 115 } // anonymous namespace
79 116
80 void NGTextFragmentPainter::Paint(const Document& document, 117 void NGTextFragmentPainter::Paint(const Document& document,
81 const PaintInfo& paint_info, 118 const PaintInfo& paint_info,
82 const LayoutPoint& paint_offset) { 119 const LayoutPoint& paint_offset) {
83 // TODO(eae): Move 120 // TODO(eae): Move
84 static unsigned short kCNoTruncation = USHRT_MAX; 121 static unsigned short kCNoTruncation = USHRT_MAX;
85 static unsigned short kCFullTruncation = USHRT_MAX - 1; 122 static unsigned short kCFullTruncation = USHRT_MAX - 1;
86 123
87 const ComputedStyle& style_to_use = text_fragment_->Style(); 124 const ComputedStyle& style_to_use = text_fragment_->Style();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 // else 189 // else
153 // PaintSelection<InlineTextBoxPainter::PaintOptions::kNormal>( 190 // PaintSelection<InlineTextBoxPainter::PaintOptions::kNormal>(
154 // context, box_rect, style_to_use, font, 191 // context, box_rect, style_to_use, font,
155 // selection_style.fill_color); 192 // selection_style.fill_color);
156 //} 193 //}
157 } 194 }
158 195
159 // 2. Now paint the foreground, including text and decorations. 196 // 2. Now paint the foreground, including text and decorations.
160 int selection_start = 0; 197 int selection_start = 0;
161 int selection_end = 0; 198 int selection_end = 0;
162 // if (paint_selected_text_only || paint_selected_text_separately) 199 if (paint_selected_text_only || paint_selected_text_separately) {
163 // text_fragment_.SelectionStartEnd(selection_start, selection_end); 200 std::tie(selection_start, selection_end) =
201 SelectionStartEnd(text_fragment_);
202 }
164 203
165 // bool respect_hyphen = 204 // bool respect_hyphen =
166 // selection_end == static_cast<int>(text_fragment_.Len()) && 205 // selection_end == static_cast<int>(text_fragment_.Len()) &&
167 // text_fragment_.HasHyphen(); 206 // text_fragment_.HasHyphen();
168 // if (respect_hyphen) 207 // if (respect_hyphen)
169 // selection_end = text_run.length(); 208 // selection_end = text_run.length();
170 209
171 unsigned length = text_fragment_->Text().length(); 210 unsigned length = text_fragment_->Text().length();
172 211
173 bool ltr = true; 212 bool ltr = true;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // PaintDocumentMarkers(paint_info, box_origin, style_to_use, font, 310 // PaintDocumentMarkers(paint_info, box_origin, style_to_use, font,
272 // DocumentMarkerPaintPhase::kForeground); 311 // DocumentMarkerPaintPhase::kForeground);
273 312
274 if (should_rotate) { 313 if (should_rotate) {
275 context.ConcatCTM(TextPainterBase::Rotation( 314 context.ConcatCTM(TextPainterBase::Rotation(
276 box_rect, TextPainterBase::kCounterclockwise)); 315 box_rect, TextPainterBase::kCounterclockwise));
277 } 316 }
278 } 317 }
279 318
280 } // namespace blink 319 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698