Index: third_party/WebKit/Source/core/editing/markers/TextMatchMarker.cpp |
diff --git a/third_party/WebKit/Source/core/editing/markers/TextMatchMarker.cpp b/third_party/WebKit/Source/core/editing/markers/TextMatchMarker.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..efa13dba9e321d7a6c708a1694f77288b37f1db4 |
--- /dev/null |
+++ b/third_party/WebKit/Source/core/editing/markers/TextMatchMarker.cpp |
@@ -0,0 +1,42 @@ |
+// 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/TextMatchMarker.h" |
+ |
+#include "core/dom/Range.h" |
+ |
+namespace blink { |
+ |
+TextMatchMarker::TextMatchMarker(unsigned start_offset, |
+ unsigned end_offset, |
+ DocumentMarker::MatchStatus match_status) |
+ : DocumentMarker(start_offset, end_offset, match_status), |
+ state_(State::kInvalid) {} |
+ |
+void TextMatchMarker::UpdateRenderedRectIfNeeded(const Node& node) { |
+ if (!IsValid()) |
+ UpdateRenderedRect(node); |
+} |
+ |
+void TextMatchMarker::UpdateRenderedRect(const Node& node) { |
+ Range* range = Range::Create(node.GetDocument()); |
+ // The offsets of the marker may be out-dated, so check for exceptions. |
+ DummyExceptionStateForTesting exceptionState; |
+ range->setStart(&const_cast<Node&>(node), StartOffset(), exceptionState); |
+ if (!exceptionState.HadException()) { |
+ range->setEnd(&const_cast<Node&>(node), EndOffset(), |
+ IGNORE_EXCEPTION_FOR_TESTING); |
+ } |
+ |
+ if (!exceptionState.HadException()) { |
+ // TODO(yosin): Once we have a |EphemeralRange| version of |
+ // |boundingBox()|, we should use it instead of |Range| version. |
+ SetRenderedRect(LayoutRect(range->BoundingBox())); |
+ } else { |
+ NullifyRenderedRect(); |
+ } |
+ range->Dispose(); |
+} |
+ |
+} // namespace blink |