Commit ce6ace7f authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Make TextIterator::CurrentContainer() to return const Node&

This patch changes |TextIterator::CurrentContainer()| to return |const Node&|
instead of |const Node*| since it always non-null for improving code health.

Change-Id: Idb0a827d78afe7a8b27e398db7023527a2f2380a
Reviewed-on: https://chromium-review.googlesource.com/1050053
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Reviewed-by: default avatarYoichi Osato <yoichio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557144}
parent 99e7ef1f
...@@ -64,7 +64,7 @@ const Document& CharacterIteratorAlgorithm<Strategy>::OwnerDocument() const { ...@@ -64,7 +64,7 @@ const Document& CharacterIteratorAlgorithm<Strategy>::OwnerDocument() const {
template <typename Strategy> template <typename Strategy>
const Node* CharacterIteratorAlgorithm<Strategy>::CurrentContainer() const { const Node* CharacterIteratorAlgorithm<Strategy>::CurrentContainer() const {
return text_iterator_.CurrentContainer(); return &text_iterator_.CurrentContainer();
} }
template <typename Strategy> template <typename Strategy>
...@@ -104,9 +104,9 @@ PositionTemplate<Strategy> CharacterIteratorAlgorithm<Strategy>::StartPosition() ...@@ -104,9 +104,9 @@ PositionTemplate<Strategy> CharacterIteratorAlgorithm<Strategy>::StartPosition()
const { const {
if (!text_iterator_.AtEnd()) { if (!text_iterator_.AtEnd()) {
if (text_iterator_.length() > 1) { if (text_iterator_.length() > 1) {
const Node* n = text_iterator_.CurrentContainer(); const Node& node = text_iterator_.CurrentContainer();
int offset = text_iterator_.StartOffsetInCurrentContainer() + run_offset_; int offset = text_iterator_.StartOffsetInCurrentContainer() + run_offset_;
return PositionTemplate<Strategy>::EditingPositionOf(n, offset); return PositionTemplate<Strategy>::EditingPositionOf(&node, offset);
} }
DCHECK(!run_offset_); DCHECK(!run_offset_);
} }
...@@ -118,9 +118,9 @@ PositionTemplate<Strategy> CharacterIteratorAlgorithm<Strategy>::EndPosition() ...@@ -118,9 +118,9 @@ PositionTemplate<Strategy> CharacterIteratorAlgorithm<Strategy>::EndPosition()
const { const {
if (!text_iterator_.AtEnd()) { if (!text_iterator_.AtEnd()) {
if (text_iterator_.length() > 1) { if (text_iterator_.length() > 1) {
const Node* n = text_iterator_.CurrentContainer(); const Node& node = text_iterator_.CurrentContainer();
int offset = text_iterator_.StartOffsetInCurrentContainer() + run_offset_; int offset = text_iterator_.StartOffsetInCurrentContainer() + run_offset_;
return PositionTemplate<Strategy>::EditingPositionOf(n, offset + 1); return PositionTemplate<Strategy>::EditingPositionOf(&node, offset + 1);
} }
DCHECK(!run_offset_); DCHECK(!run_offset_);
} }
......
...@@ -844,10 +844,10 @@ const Document& TextIteratorAlgorithm<Strategy>::OwnerDocument() const { ...@@ -844,10 +844,10 @@ const Document& TextIteratorAlgorithm<Strategy>::OwnerDocument() const {
template <typename Strategy> template <typename Strategy>
const Node* TextIteratorAlgorithm<Strategy>::GetNode() const { const Node* TextIteratorAlgorithm<Strategy>::GetNode() const {
const Node* node = CurrentContainer(); const Node& node = CurrentContainer();
if (node->IsCharacterDataNode()) if (node.IsCharacterDataNode())
return node; return &node;
return Strategy::ChildAt(*node, StartOffsetInCurrentContainer()); return Strategy::ChildAt(node, StartOffsetInCurrentContainer());
} }
template <typename Strategy> template <typename Strategy>
...@@ -867,11 +867,11 @@ int TextIteratorAlgorithm<Strategy>::EndOffsetInCurrentContainer() const { ...@@ -867,11 +867,11 @@ int TextIteratorAlgorithm<Strategy>::EndOffsetInCurrentContainer() const {
} }
template <typename Strategy> template <typename Strategy>
const Node* TextIteratorAlgorithm<Strategy>::CurrentContainer() const { const Node& TextIteratorAlgorithm<Strategy>::CurrentContainer() const {
if (!text_state_.PositionNode()) if (!text_state_.PositionNode())
return end_container_; return *end_container_;
EnsurePositionContainer(); EnsurePositionContainer();
return text_state_.PositionContainerNode(); return *text_state_.PositionContainerNode();
} }
template <typename Strategy> template <typename Strategy>
...@@ -947,14 +947,14 @@ template <typename Strategy> ...@@ -947,14 +947,14 @@ template <typename Strategy>
PositionTemplate<Strategy> PositionTemplate<Strategy>
TextIteratorAlgorithm<Strategy>::StartPositionInCurrentContainer() const { TextIteratorAlgorithm<Strategy>::StartPositionInCurrentContainer() const {
return PositionTemplate<Strategy>::EditingPositionOf( return PositionTemplate<Strategy>::EditingPositionOf(
CurrentContainer(), StartOffsetInCurrentContainer()); &CurrentContainer(), StartOffsetInCurrentContainer());
} }
template <typename Strategy> template <typename Strategy>
PositionTemplate<Strategy> PositionTemplate<Strategy>
TextIteratorAlgorithm<Strategy>::EndPositionInCurrentContainer() const { TextIteratorAlgorithm<Strategy>::EndPositionInCurrentContainer() const {
return PositionTemplate<Strategy>::EditingPositionOf( return PositionTemplate<Strategy>::EditingPositionOf(
CurrentContainer(), EndOffsetInCurrentContainer()); &CurrentContainer(), EndOffsetInCurrentContainer());
} }
template <typename Strategy> template <typename Strategy>
......
...@@ -75,7 +75,7 @@ class CORE_TEMPLATE_CLASS_EXPORT TextIteratorAlgorithm { ...@@ -75,7 +75,7 @@ class CORE_TEMPLATE_CLASS_EXPORT TextIteratorAlgorithm {
const Node* GetNode() const; const Node* GetNode() const;
const Document& OwnerDocument() const; const Document& OwnerDocument() const;
const Node* CurrentContainer() const; const Node& CurrentContainer() const;
int StartOffsetInCurrentContainer() const; int StartOffsetInCurrentContainer() const;
int EndOffsetInCurrentContainer() const; int EndOffsetInCurrentContainer() const;
PositionTemplate<Strategy> StartPositionInCurrentContainer() const; PositionTemplate<Strategy> StartPositionInCurrentContainer() const;
......
...@@ -232,7 +232,7 @@ void DocumentMarkerController::RemoveMarkers( ...@@ -232,7 +232,7 @@ void DocumentMarkerController::RemoveMarkers(
int start_offset = marked_text.StartOffsetInCurrentContainer(); int start_offset = marked_text.StartOffsetInCurrentContainer();
int end_offset = marked_text.EndOffsetInCurrentContainer(); int end_offset = marked_text.EndOffsetInCurrentContainer();
RemoveMarkersInternal(marked_text.CurrentContainer(), start_offset, RemoveMarkersInternal(&marked_text.CurrentContainer(), start_offset,
end_offset - start_offset, marker_types); end_offset - start_offset, marker_types);
} }
} }
...@@ -267,13 +267,13 @@ void DocumentMarkerController::AddMarkerInternal( ...@@ -267,13 +267,13 @@ void DocumentMarkerController::AddMarkerInternal(
// Ignore text emitted by TextIterator for non-text nodes (e.g. implicit // Ignore text emitted by TextIterator for non-text nodes (e.g. implicit
// newlines) // newlines)
const Node* const node = marked_text.CurrentContainer(); const Node& node = marked_text.CurrentContainer();
if (!node->IsTextNode()) if (!node.IsTextNode())
continue; continue;
DocumentMarker* const new_marker = create_marker_from_offsets( DocumentMarker* const new_marker = create_marker_from_offsets(
start_offset_in_current_container, end_offset_in_current_container); start_offset_in_current_container, end_offset_in_current_container);
AddMarkerToNode(node, new_marker); AddMarkerToNode(&node, new_marker);
} }
} }
......
...@@ -87,8 +87,8 @@ NSAttributedString* AttributedSubstringFromRange(const EphemeralRange& range, ...@@ -87,8 +87,8 @@ NSAttributedString* AttributedSubstringFromRange(const EphemeralRange& range,
if (!num_characters) if (!num_characters)
continue; continue;
const Node* container = it.CurrentContainer(); const Node& container = it.CurrentContainer();
LayoutObject* layout_object = container->GetLayoutObject(); LayoutObject* layout_object = container.GetLayoutObject();
DCHECK(layout_object); DCHECK(layout_object);
if (!layout_object) if (!layout_object)
continue; continue;
......
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