OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
(...skipping 25 matching lines...) Expand all Loading... |
36 // markers. We store whether or not the match is active, a LayoutRect used for | 36 // markers. We store whether or not the match is active, a LayoutRect used for |
37 // rendering the marker, and whether or not the LayoutRect is currently | 37 // rendering the marker, and whether or not the LayoutRect is currently |
38 // up-to-date. | 38 // up-to-date. |
39 class CORE_EXPORT TextMatchMarker final : public DocumentMarker { | 39 class CORE_EXPORT TextMatchMarker final : public DocumentMarker { |
40 private: | 40 private: |
41 enum class State { kInvalid, kValidNull, kValidNotNull }; | 41 enum class State { kInvalid, kValidNull, kValidNotNull }; |
42 | 42 |
43 public: | 43 public: |
44 enum class MatchStatus { kInactive, kActive }; | 44 enum class MatchStatus { kInactive, kActive }; |
45 | 45 |
46 TextMatchMarker(unsigned start_offset, | 46 TextMatchMarker(unsigned start_offset, unsigned end_offset, MatchStatus); |
47 unsigned end_offset, | |
48 MatchStatus status) | |
49 : DocumentMarker(start_offset, end_offset), match_status_(status) { | |
50 layout_state_ = State::kInvalid; | |
51 } | |
52 | 47 |
53 // DocumentMarker implementations | 48 // DocumentMarker implementations |
54 MarkerType GetType() const final; | 49 MarkerType GetType() const final; |
55 | 50 |
56 // TextMatchMarker-specific | 51 // TextMatchMarker-specific |
57 bool IsActiveMatch() const { return match_status_ == MatchStatus::kActive; } | 52 bool IsActiveMatch() const; |
58 void SetIsActiveMatch(bool active) { | 53 void SetIsActiveMatch(bool active); |
59 match_status_ = active ? MatchStatus::kActive : MatchStatus::kInactive; | |
60 } | |
61 | 54 |
62 bool IsRendered() const { return layout_state_ == State::kValidNotNull; } | 55 bool IsRendered() const; |
63 bool Contains(const LayoutPoint& point) const { | 56 bool Contains(const LayoutPoint&) const; |
64 DCHECK_EQ(layout_state_, State::kValidNotNull); | 57 void SetRenderedRect(const LayoutRect&); |
65 return rendered_rect_.Contains(point); | 58 const LayoutRect& RenderedRect() const; |
66 } | 59 void NullifyRenderedRect(); |
67 void SetRenderedRect(const LayoutRect& rect) { | 60 void Invalidate(); |
68 if (layout_state_ == State::kValidNotNull && rect == rendered_rect_) | 61 bool IsValid() const; |
69 return; | |
70 layout_state_ = State::kValidNotNull; | |
71 rendered_rect_ = rect; | |
72 } | |
73 | |
74 const LayoutRect& RenderedRect() const { | |
75 DCHECK_EQ(layout_state_, State::kValidNotNull); | |
76 return rendered_rect_; | |
77 } | |
78 | |
79 void NullifyRenderedRect() { | |
80 layout_state_ = State::kValidNull; | |
81 // Now |m_renderedRect| can not be accessed until |setRenderedRect| is | |
82 // called. | |
83 } | |
84 | |
85 void Invalidate() { layout_state_ = State::kInvalid; } | |
86 bool IsValid() const { return layout_state_ != State::kInvalid; } | |
87 | 62 |
88 private: | 63 private: |
89 MatchStatus match_status_; | 64 MatchStatus match_status_; |
90 LayoutRect rendered_rect_; | 65 LayoutRect rendered_rect_; |
91 State layout_state_; | 66 State layout_state_ = State::kInvalid; |
92 | 67 |
93 DISALLOW_COPY_AND_ASSIGN(TextMatchMarker); | 68 DISALLOW_COPY_AND_ASSIGN(TextMatchMarker); |
94 }; | 69 }; |
95 | 70 |
96 DEFINE_TYPE_CASTS(TextMatchMarker, | 71 DEFINE_TYPE_CASTS(TextMatchMarker, |
97 DocumentMarker, | 72 DocumentMarker, |
98 marker, | 73 marker, |
99 marker->GetType() == DocumentMarker::kTextMatch, | 74 marker->GetType() == DocumentMarker::kTextMatch, |
100 marker.GetType() == DocumentMarker::kTextMatch); | 75 marker.GetType() == DocumentMarker::kTextMatch); |
101 | 76 |
102 } // namespace blink | 77 } // namespace blink |
103 | 78 |
104 #endif | 79 #endif |
OLD | NEW |