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

Unified 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 side-by-side diff with in-line comments
Download patch
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 36dd5b96bcd6f705d26cb44b98aa0d624c697f39..aca4e5b8ccb530d19382285a765a897dd4073154 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,42 @@ static void PaintDecorationsExceptLineThrough(
//}
}
+static std::pair<int, int> SelectionStartEnd(
yoichio 2017/06/27 07:54:53 Much comment is appreciate
+ 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()};
yoichio 2017/06/27 07:54:53 Rerturn painting full; define lewngth;
+
+ const std::pair<int, int> startend_in_ngblockflow =
+ text_fragment->GetLayoutObject()
+ ->GetFrameView()
+ ->GetFrame()
+ .Selection()
+ .LayoutSelectionStartEnd();
yoichio 2017/06/27 07:54:53 Describe much more.
+ int selection_start = std::max<int>(
+ 0, startend_in_ngblockflow.first - text_fragment->StartOffset());
+ 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};
+ default:
+ NOTREACHED();
+ }
+
+ NOTREACHED();
+ return {0, 0};
+}
+
} // anonymous namespace
void NGTextFragmentPainter::Paint(const Document& document,
@@ -159,8 +196,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()) &&

Powered by Google App Engine
This is Rietveld 408576698