Commit 2546cdae authored by rlanday's avatar rlanday Committed by Commit Bot

Add CompositionMarker (subclass of DocumentMarker)

This CL moves the Composition marker-specific functionality of DocumentMarker
into a new CompositionMarker subclass (similar to TextMatchMarker). I will do
the same for Spelling and Grammar markers in future CLs.

BUG=707867
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_layout_tests_slimming_paint_v2

Review-Url: https://codereview.chromium.org/2908643002
Cr-Commit-Position: refs/heads/master@{#476220}
parent ed672497
...@@ -192,6 +192,8 @@ blink_core_sources("editing") { ...@@ -192,6 +192,8 @@ blink_core_sources("editing") {
"iterators/TextIteratorTextState.h", "iterators/TextIteratorTextState.h",
"iterators/TextSearcherICU.cpp", "iterators/TextSearcherICU.cpp",
"iterators/TextSearcherICU.h", "iterators/TextSearcherICU.h",
"markers/CompositionMarker.cpp",
"markers/CompositionMarker.h",
"markers/CompositionMarkerListImpl.cpp", "markers/CompositionMarkerListImpl.cpp",
"markers/CompositionMarkerListImpl.h", "markers/CompositionMarkerListImpl.h",
"markers/DocumentMarker.cpp", "markers/DocumentMarker.cpp",
...@@ -312,6 +314,7 @@ source_set("unit_tests") { ...@@ -312,6 +314,7 @@ source_set("unit_tests") {
"iterators/TextIteratorTest.cpp", "iterators/TextIteratorTest.cpp",
"iterators/TextSearcherICUTest.cpp", "iterators/TextSearcherICUTest.cpp",
"markers/CompositionMarkerListImplTest.cpp", "markers/CompositionMarkerListImplTest.cpp",
"markers/CompositionMarkerTest.cpp",
"markers/DocumentMarkerControllerTest.cpp", "markers/DocumentMarkerControllerTest.cpp",
"markers/DocumentMarkerListEditorTest.cpp", "markers/DocumentMarkerListEditorTest.cpp",
"markers/DocumentMarkerTest.cpp", "markers/DocumentMarkerTest.cpp",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/editing/markers/CompositionMarker.h"
namespace blink {
CompositionMarker::CompositionMarker(unsigned start_offset,
unsigned end_offset,
Color underline_color,
bool thick,
Color background_color)
: DocumentMarker(DocumentMarker::kComposition, start_offset, end_offset),
underline_color_(underline_color),
background_color_(background_color),
thick_(thick) {}
Color CompositionMarker::UnderlineColor() const {
return underline_color_;
}
bool CompositionMarker::Thick() const {
return thick_;
}
Color CompositionMarker::BackgroundColor() const {
return background_color_;
}
} // namespace blink
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CompositionMarker_h
#define CompositionMarker_h
#include "core/editing/markers/DocumentMarker.h"
namespace blink {
// A subclass of DocumentMarker used to store information specific to
// composition markers. We store what color to display the underline (possibly
// transparent), whether the underline should be thick or not, and what
// background color should be used under the marked text (also possibly
// transparent).
class CORE_EXPORT CompositionMarker final : public DocumentMarker {
public:
CompositionMarker(unsigned start_offset,
unsigned end_offset,
Color underline_color,
bool thick,
Color background_color);
Color UnderlineColor() const;
bool Thick() const;
Color BackgroundColor() const;
private:
const Color underline_color_;
const Color background_color_;
const bool thick_;
DISALLOW_COPY_AND_ASSIGN(CompositionMarker);
};
DEFINE_TYPE_CASTS(CompositionMarker,
DocumentMarker,
marker,
marker->GetType() == DocumentMarker::kComposition,
marker.GetType() == DocumentMarker::kComposition);
} // namespace blink
#endif
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "core/editing/markers/CompositionMarkerListImpl.h" #include "core/editing/markers/CompositionMarkerListImpl.h"
#include "core/editing/EditingTestBase.h" #include "core/editing/EditingTestBase.h"
#include "core/editing/markers/CompositionMarker.h"
namespace blink { namespace blink {
...@@ -14,8 +15,8 @@ class CompositionMarkerListImplTest : public EditingTestBase { ...@@ -14,8 +15,8 @@ class CompositionMarkerListImplTest : public EditingTestBase {
: marker_list_(new CompositionMarkerListImpl()) {} : marker_list_(new CompositionMarkerListImpl()) {}
DocumentMarker* CreateMarker(unsigned start_offset, unsigned end_offset) { DocumentMarker* CreateMarker(unsigned start_offset, unsigned end_offset) {
return new DocumentMarker(start_offset, end_offset, Color::kBlack, false, return new CompositionMarker(start_offset, end_offset, Color::kBlack, false,
Color::kBlack); Color::kBlack);
} }
Persistent<CompositionMarkerListImpl> marker_list_; Persistent<CompositionMarkerListImpl> marker_list_;
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/editing/markers/CompositionMarker.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
class CompositionMarkerTest : public ::testing::Test {};
TEST_F(CompositionMarkerTest, MarkerType) {
DocumentMarker* marker = new CompositionMarker(0, 1, Color::kTransparent,
false, Color::kTransparent);
EXPECT_EQ(DocumentMarker::kComposition, marker->GetType());
}
TEST_F(CompositionMarkerTest, ConstructorAndGetters) {
CompositionMarker* marker =
new CompositionMarker(0, 1, Color::kDarkGray, false, Color::kGray);
EXPECT_EQ(Color::kDarkGray, marker->UnderlineColor());
EXPECT_FALSE(marker->Thick());
EXPECT_EQ(Color::kGray, marker->BackgroundColor());
CompositionMarker* thick_marker =
new CompositionMarker(0, 1, Color::kDarkGray, true, Color::kGray);
EXPECT_EQ(true, thick_marker->Thick());
}
} // namespace blink
...@@ -63,45 +63,6 @@ inline DocumentMarkerDescription* ToDocumentMarkerDescription( ...@@ -63,45 +63,6 @@ inline DocumentMarkerDescription* ToDocumentMarkerDescription(
return 0; return 0;
} }
class TextCompositionMarkerDetails final : public DocumentMarkerDetails {
public:
static TextCompositionMarkerDetails* Create(Color underline_color,
bool thick,
Color background_color);
bool IsComposition() const override { return true; }
Color UnderlineColor() const { return underline_color_; }
bool Thick() const { return thick_; }
Color BackgroundColor() const { return background_color_; }
private:
TextCompositionMarkerDetails(Color underline_color,
bool thick,
Color background_color)
: underline_color_(underline_color),
background_color_(background_color),
thick_(thick) {}
Color underline_color_;
Color background_color_;
bool thick_;
};
TextCompositionMarkerDetails* TextCompositionMarkerDetails::Create(
Color underline_color,
bool thick,
Color background_color) {
return new TextCompositionMarkerDetails(underline_color, thick,
background_color);
}
inline TextCompositionMarkerDetails* ToTextCompositionMarkerDetails(
DocumentMarkerDetails* details) {
if (details && details->IsComposition())
return static_cast<TextCompositionMarkerDetails*>(details);
return nullptr;
}
DocumentMarker::DocumentMarker(MarkerType type, DocumentMarker::DocumentMarker(MarkerType type,
unsigned start_offset, unsigned start_offset,
unsigned end_offset) unsigned end_offset)
...@@ -120,18 +81,6 @@ DocumentMarker::DocumentMarker(MarkerType type, ...@@ -120,18 +81,6 @@ DocumentMarker::DocumentMarker(MarkerType type,
? nullptr ? nullptr
: DocumentMarkerDescription::Create(description)) {} : DocumentMarkerDescription::Create(description)) {}
DocumentMarker::DocumentMarker(unsigned start_offset,
unsigned end_offset,
Color underline_color,
bool thick,
Color background_color)
: type_(DocumentMarker::kComposition),
start_offset_(start_offset),
end_offset_(end_offset),
details_(TextCompositionMarkerDetails::Create(underline_color,
thick,
background_color)) {}
Optional<DocumentMarker::MarkerOffsets> Optional<DocumentMarker::MarkerOffsets>
DocumentMarker::ComputeOffsetsAfterShift(unsigned offset, DocumentMarker::ComputeOffsetsAfterShift(unsigned offset,
unsigned old_length, unsigned old_length,
...@@ -190,27 +139,6 @@ const String& DocumentMarker::Description() const { ...@@ -190,27 +139,6 @@ const String& DocumentMarker::Description() const {
return g_empty_string; return g_empty_string;
} }
Color DocumentMarker::UnderlineColor() const {
if (TextCompositionMarkerDetails* details =
ToTextCompositionMarkerDetails(details_.Get()))
return details->UnderlineColor();
return Color::kTransparent;
}
bool DocumentMarker::Thick() const {
if (TextCompositionMarkerDetails* details =
ToTextCompositionMarkerDetails(details_.Get()))
return details->Thick();
return false;
}
Color DocumentMarker::BackgroundColor() const {
if (TextCompositionMarkerDetails* details =
ToTextCompositionMarkerDetails(details_.Get()))
return details->BackgroundColor();
return Color::kTransparent;
}
DEFINE_TRACE(DocumentMarker) { DEFINE_TRACE(DocumentMarker) {
visitor->Trace(details_); visitor->Trace(details_);
} }
......
...@@ -132,20 +132,12 @@ class CORE_EXPORT DocumentMarker : public GarbageCollected<DocumentMarker> { ...@@ -132,20 +132,12 @@ class CORE_EXPORT DocumentMarker : public GarbageCollected<DocumentMarker> {
unsigned start_offset, unsigned start_offset,
unsigned end_offset, unsigned end_offset,
const String& description); const String& description);
DocumentMarker(unsigned start_offset,
unsigned end_offset,
Color underline_color,
bool thick,
Color background_color);
MarkerType GetType() const { return type_; } MarkerType GetType() const { return type_; }
unsigned StartOffset() const { return start_offset_; } unsigned StartOffset() const { return start_offset_; }
unsigned EndOffset() const { return end_offset_; } unsigned EndOffset() const { return end_offset_; }
const String& Description() const; const String& Description() const;
Color UnderlineColor() const;
bool Thick() const;
Color BackgroundColor() const;
DocumentMarkerDetails* Details() const; DocumentMarkerDetails* Details() const;
void ClearDetails() { details_.Clear(); } void ClearDetails() { details_.Clear(); }
...@@ -191,7 +183,6 @@ class DocumentMarkerDetails ...@@ -191,7 +183,6 @@ class DocumentMarkerDetails
DocumentMarkerDetails() {} DocumentMarkerDetails() {}
virtual ~DocumentMarkerDetails(); virtual ~DocumentMarkerDetails();
virtual bool IsDescription() const { return false; } virtual bool IsDescription() const { return false; }
virtual bool IsComposition() const { return false; }
DEFINE_INLINE_VIRTUAL_TRACE() {} DEFINE_INLINE_VIRTUAL_TRACE() {}
}; };
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "core/dom/Text.h" #include "core/dom/Text.h"
#include "core/editing/VisibleUnits.h" #include "core/editing/VisibleUnits.h"
#include "core/editing/iterators/TextIterator.h" #include "core/editing/iterators/TextIterator.h"
#include "core/editing/markers/CompositionMarker.h"
#include "core/editing/markers/CompositionMarkerListImpl.h" #include "core/editing/markers/CompositionMarkerListImpl.h"
#include "core/editing/markers/DocumentMarkerListEditor.h" #include "core/editing/markers/DocumentMarkerListEditor.h"
#include "core/editing/markers/GrammarMarkerListImpl.h" #include "core/editing/markers/GrammarMarkerListImpl.h"
...@@ -162,8 +163,8 @@ void DocumentMarkerController::AddCompositionMarker(const EphemeralRange& range, ...@@ -162,8 +163,8 @@ void DocumentMarkerController::AddCompositionMarker(const EphemeralRange& range,
DCHECK(!document_->NeedsLayoutTreeUpdate()); DCHECK(!document_->NeedsLayoutTreeUpdate());
AddMarkerInternal(range, [underline_color, thick, background_color]( AddMarkerInternal(range, [underline_color, thick, background_color](
int start_offset, int end_offset) { int start_offset, int end_offset) {
return new DocumentMarker(start_offset, end_offset, underline_color, thick, return new CompositionMarker(start_offset, end_offset, underline_color,
background_color); thick, background_color);
}); });
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "core/editing/CompositionUnderline.h" #include "core/editing/CompositionUnderline.h"
#include "core/editing/Editor.h" #include "core/editing/Editor.h"
#include "core/editing/markers/CompositionMarker.h"
#include "core/editing/markers/DocumentMarkerController.h" #include "core/editing/markers/DocumentMarkerController.h"
#include "core/editing/markers/TextMatchMarker.h" #include "core/editing/markers/TextMatchMarker.h"
#include "core/frame/LocalFrame.h" #include "core/frame/LocalFrame.h"
...@@ -676,9 +677,12 @@ void InlineTextBoxPainter::PaintDocumentMarkers( ...@@ -676,9 +677,12 @@ void InlineTextBoxPainter::PaintDocumentMarkers(
} }
break; break;
case DocumentMarker::kComposition: { case DocumentMarker::kComposition: {
CompositionUnderline underline(marker.StartOffset(), marker.EndOffset(), const CompositionMarker& composition_marker =
marker.UnderlineColor(), marker.Thick(), ToCompositionMarker(marker);
marker.BackgroundColor()); CompositionUnderline underline(
composition_marker.StartOffset(), composition_marker.EndOffset(),
composition_marker.UnderlineColor(), composition_marker.Thick(),
composition_marker.BackgroundColor());
if (marker_paint_phase == DocumentMarkerPaintPhase::kBackground) if (marker_paint_phase == DocumentMarkerPaintPhase::kBackground)
PaintSingleCompositionBackgroundRun( PaintSingleCompositionBackgroundRun(
paint_info.context, box_origin, style, font, paint_info.context, box_origin, style, font,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment