OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef TextMatchMarker_h |
| 6 #define TextMatchMarker_h |
| 7 |
| 8 #include <utility> |
| 9 #include "core/editing/markers/DocumentMarker.h" |
| 10 #include "platform/geometry/LayoutRect.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 class CORE_EXPORT TextMatchMarker final : public DocumentMarker { |
| 15 public: |
| 16 TextMatchMarker(unsigned start_offset, |
| 17 unsigned end_offset, |
| 18 DocumentMarker::MatchStatus); |
| 19 |
| 20 bool IsRendered() const { return state_ == State::kValidNotNull; } |
| 21 |
| 22 void SetRenderedRect(const LayoutRect& rect) { |
| 23 if (state_ == State::kValidNotNull && rect == renderedRect_) |
| 24 return; |
| 25 state_ = State::kValidNotNull; |
| 26 renderedRect_ = rect; |
| 27 } |
| 28 |
| 29 const LayoutRect& RenderedRect() const { |
| 30 DCHECK_EQ(state_, State::kValidNotNull); |
| 31 return renderedRect_; |
| 32 } |
| 33 |
| 34 void UpdateRenderedRectIfNeeded(const Node&); |
| 35 void UpdateRenderedRect(const Node&); |
| 36 |
| 37 void NullifyRenderedRect() { |
| 38 state_ = State::kValidNull; |
| 39 // Now |renderedRect_| can not be accessed until |setRenderedRect| is |
| 40 // called. |
| 41 } |
| 42 |
| 43 void Invalidate() { state_ = State::kInvalid; } |
| 44 bool IsValid() const { return state_ != State::kInvalid; } |
| 45 |
| 46 protected: |
| 47 TextMatchMarker(const TextMatchMarker&) = default; |
| 48 |
| 49 private: |
| 50 enum class State { kInvalid, kValidNull, kValidNotNull }; |
| 51 |
| 52 LayoutRect renderedRect_; |
| 53 State state_; |
| 54 }; |
| 55 |
| 56 DEFINE_TYPE_CASTS(TextMatchMarker, |
| 57 DocumentMarker, |
| 58 marker, |
| 59 marker->GetType() == DocumentMarker::kTextMatch, |
| 60 marker.GetType() == DocumentMarker::kTextMatch); |
| 61 |
| 62 } // namespace blink |
| 63 |
| 64 #endif // TextMatchMarker_h |
OLD | NEW |