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

Side by Side Diff: third_party/WebKit/Source/core/editing/markers/TextMatchMarker.h

Issue 2904093002: [DMC #18] Eliminate DocumentMarkerTextMatch (subclass of DocumentMarkerDetails) (Closed)
Patch Set: Add const, rebase 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 22 matching lines...) Expand all
33 namespace blink { 33 namespace blink {
34 34
35 class TextMatchMarker final : public DocumentMarker { 35 class TextMatchMarker final : public DocumentMarker {
36 private: 36 private:
37 enum class State { kInvalid, kValidNull, kValidNotNull }; 37 enum class State { kInvalid, kValidNull, kValidNotNull };
38 38
39 public: 39 public:
40 TextMatchMarker(unsigned start_offset, 40 TextMatchMarker(unsigned start_offset,
41 unsigned end_offset, 41 unsigned end_offset,
42 MatchStatus status) 42 MatchStatus status)
43 : DocumentMarker(start_offset, end_offset, status), 43 : DocumentMarker(DocumentMarker::kTextMatch, start_offset, end_offset),
44 state_(State::kInvalid) {} 44 match_status_(status) {
45 layout_state_ = State::kInvalid;
46 }
45 47
46 bool IsRendered() const { return state_ == State::kValidNotNull; } 48 bool IsActiveMatch() const { return match_status_ == MatchStatus::kActive; }
49 void SetIsActiveMatch(bool active) {
50 match_status_ = active ? MatchStatus::kActive : MatchStatus::kInactive;
51 }
52
53 bool IsRendered() const { return layout_state_ == State::kValidNotNull; }
47 bool Contains(const LayoutPoint& point) const { 54 bool Contains(const LayoutPoint& point) const {
48 DCHECK_EQ(state_, State::kValidNotNull); 55 DCHECK_EQ(layout_state_, State::kValidNotNull);
49 return rendered_rect_.Contains(point); 56 return rendered_rect_.Contains(point);
50 } 57 }
51 void SetRenderedRect(const LayoutRect& rect) { 58 void SetRenderedRect(const LayoutRect& rect) {
52 if (state_ == State::kValidNotNull && rect == rendered_rect_) 59 if (layout_state_ == State::kValidNotNull && rect == rendered_rect_)
53 return; 60 return;
54 state_ = State::kValidNotNull; 61 layout_state_ = State::kValidNotNull;
55 rendered_rect_ = rect; 62 rendered_rect_ = rect;
56 } 63 }
57 64
58 const LayoutRect& RenderedRect() const { 65 const LayoutRect& RenderedRect() const {
59 DCHECK_EQ(state_, State::kValidNotNull); 66 DCHECK_EQ(layout_state_, State::kValidNotNull);
60 return rendered_rect_; 67 return rendered_rect_;
61 } 68 }
62 69
63 void NullifyRenderedRect() { 70 void NullifyRenderedRect() {
64 state_ = State::kValidNull; 71 layout_state_ = State::kValidNull;
65 // Now |m_renderedRect| can not be accessed until |setRenderedRect| is 72 // Now |m_renderedRect| can not be accessed until |setRenderedRect| is
66 // called. 73 // called.
67 } 74 }
68 75
69 void Invalidate() { state_ = State::kInvalid; } 76 void Invalidate() { layout_state_ = State::kInvalid; }
70 bool IsValid() const { return state_ != State::kInvalid; } 77 bool IsValid() const { return layout_state_ != State::kInvalid; }
71 78
72 private: 79 private:
80 MatchStatus match_status_;
73 LayoutRect rendered_rect_; 81 LayoutRect rendered_rect_;
74 State state_; 82 State layout_state_;
Xiaocheng 2017/05/31 18:09:02 I think |State| should also be renamed to reduce c
75 }; 83 };
76 84
77 DEFINE_TYPE_CASTS(TextMatchMarker, 85 DEFINE_TYPE_CASTS(TextMatchMarker,
78 DocumentMarker, 86 DocumentMarker,
79 marker, 87 marker,
80 marker->GetType() == DocumentMarker::kTextMatch, 88 marker->GetType() == DocumentMarker::kTextMatch,
81 marker.GetType() == DocumentMarker::kTextMatch); 89 marker.GetType() == DocumentMarker::kTextMatch);
82 90
83 } // namespace blink 91 } // namespace blink
84 92
85 #endif 93 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/markers/DocumentMarker.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698