Index: third_party/WebKit/Source/core/paint/NGTextFragmentPainter.cpp |
diff --git a/third_party/WebKit/Source/core/paint/NGTextFragmentPainter.cpp b/third_party/WebKit/Source/core/paint/NGTextFragmentPainter.cpp |
index 06d32ffda48718afee6d6822ff57773550427f40..1d3242fa795f8bc2d817bb29f19885318cee7141 100644 |
--- a/third_party/WebKit/Source/core/paint/NGTextFragmentPainter.cpp |
+++ b/third_party/WebKit/Source/core/paint/NGTextFragmentPainter.cpp |
@@ -4,6 +4,7 @@ |
#include "core/paint/NGTextFragmentPainter.h" |
+#include "core/editing/FrameSelection.h" |
#include "core/frame/LocalFrame.h" |
#include "core/layout/ng/inline/ng_physical_text_fragment.h" |
#include "core/paint/NGTextPainter.h" |
@@ -75,6 +76,40 @@ static void PaintDecorationsExceptLineThrough( |
//} |
} |
+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
|
+ const NGPhysicalTextFragment* text_fragment) { |
+ const SelectionState& selection_state = |
+ text_fragment->GetLayoutObject()->GetSelectionState(); |
+ if (selection_state == SelectionState::kNone) |
+ return {0, 0}; |
+ if (selection_state == SelectionState::kInside) |
+ 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
|
+ |
+ 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_
|
+ text_fragment->GetLayoutObject() |
+ ->GetFrameView() |
+ ->GetFrame() |
+ .Selection() |
+ .LayoutSelectionStartEnd(); |
+ int selection_start = std::max<int>( |
+ 0, startend_in_ngblockflow.first - text_fragment->StartOffset()); |
kojii
2017/06/16 11:25:57
This might not work, because StartOffset() is unsi
|
+ int selection_end = std::min<int>( |
+ text_fragment->Text().length(), |
+ startend_in_ngblockflow.second - text_fragment->StartOffset()); |
+ |
+ switch (selection_state) { |
+ case SelectionState::kStart: |
+ return {selection_start, text_fragment->Text().length()}; |
+ case SelectionState::kEnd: |
+ return {0, selection_end}; |
+ case SelectionState::kStartAndEnd: |
+ return {selection_start, selection_end}; |
+ } |
+ |
+ NOTREACHED(); |
+ return {0, 0}; |
+} |
+ |
} // anonymous namespace |
void NGTextFragmentPainter::Paint(const Document& document, |
@@ -122,6 +157,7 @@ void NGTextFragmentPainter::Paint(const Document& document, |
// text_fragment_.GetLineLayoutItem(), have_selection, paint_info, |
// text_style); |
TextPainterBase::Style selection_style = text_style; |
+ 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.
|
bool paint_selected_text_only = (paint_info.phase == kPaintPhaseSelection); |
bool paint_selected_text_separately = |
!paint_selected_text_only && text_style != selection_style; |
@@ -158,8 +194,10 @@ void NGTextFragmentPainter::Paint(const Document& document, |
// 2. Now paint the foreground, including text and decorations. |
int selection_start = 0; |
int selection_end = 0; |
- // if (paint_selected_text_only || paint_selected_text_separately) |
- // text_fragment_.SelectionStartEnd(selection_start, selection_end); |
+ if (paint_selected_text_only || paint_selected_text_separately) { |
+ std::tie(selection_start, selection_end) = |
+ SelectionStartEnd(text_fragment_); |
+ } |
// bool respect_hyphen = |
// selection_end == static_cast<int>(text_fragment_.Len()) && |