Commit 87f4947e authored by Takashi Toyoshima's avatar Takashi Toyoshima Committed by Commit Bot

Use WTF::Optional instead of base::Optional

WTF::Optional is just an alias of base::Optional for some valid
use cases, but it does not compile for use cases that are not
compatible with Oilpan.

To take the advantage of this safe type check, we should use
WTF::Optional in Blink core instead of direct use of base::Optional.

Also base::Optional in Blink core causes presubmit check errors.

Change-Id: Ie5b97645cccccbef3464c0d07e3a95d3135cd9d9
Reviewed-on: https://chromium-review.googlesource.com/743821Reviewed-by: default avatarYoshifumi Inoue <yosin@chromium.org>
Commit-Queue: Takashi Toyoshima <toyoshim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512764}
parent ad3436a1
......@@ -1156,10 +1156,10 @@ void FrameSelection::ClearDocumentCachedRange() {
selection_editor_->ClearDocumentCachedRange();
}
base::Optional<int> FrameSelection::LayoutSelectionStart() const {
WTF::Optional<int> FrameSelection::LayoutSelectionStart() const {
return layout_selection_->SelectionStart();
}
base::Optional<int> FrameSelection::LayoutSelectionEnd() const {
WTF::Optional<int> FrameSelection::LayoutSelectionEnd() const {
return layout_selection_->SelectionEnd();
}
......
......@@ -37,6 +37,7 @@
#include "platform/geometry/LayoutRect.h"
#include "platform/heap/Handle.h"
#include "platform/wtf/Noncopyable.h"
#include "platform/wtf/Optional.h"
namespace blink {
......@@ -217,8 +218,8 @@ class CORE_EXPORT FrameSelection final
FrameCaret& FrameCaretForTesting() const { return *frame_caret_; }
base::Optional<int> LayoutSelectionStart() const;
base::Optional<int> LayoutSelectionEnd() const;
WTF::Optional<int> LayoutSelectionStart() const;
WTF::Optional<int> LayoutSelectionEnd() const;
void ClearLayoutSelection();
void Trace(blink::Visitor*);
......
......@@ -37,9 +37,9 @@
namespace blink {
SelectionPaintRange::SelectionPaintRange(LayoutObject* start_layout_object,
base::Optional<int> start_offset,
WTF::Optional<int> start_offset,
LayoutObject* end_layout_object,
base::Optional<int> end_offset)
WTF::Optional<int> end_offset)
: start_layout_object_(start_layout_object),
start_offset_(start_offset),
end_layout_object_(end_layout_object),
......@@ -57,7 +57,7 @@ LayoutObject* SelectionPaintRange::StartLayoutObject() const {
return start_layout_object_;
}
base::Optional<int> SelectionPaintRange::StartOffset() const {
WTF::Optional<int> SelectionPaintRange::StartOffset() const {
DCHECK(!IsNull());
return start_offset_;
}
......@@ -67,7 +67,7 @@ LayoutObject* SelectionPaintRange::EndLayoutObject() const {
return end_layout_object_;
}
base::Optional<int> SelectionPaintRange::EndOffset() const {
WTF::Optional<int> SelectionPaintRange::EndOffset() const {
DCHECK(!IsNull());
return end_offset_;
}
......@@ -265,17 +265,17 @@ static void SetShouldInvalidateSelection(
}
}
base::Optional<int> LayoutSelection::SelectionStart() const {
WTF::Optional<int> LayoutSelection::SelectionStart() const {
DCHECK(!HasPendingSelection());
if (paint_range_.IsNull())
return base::nullopt;
return WTF::nullopt;
return paint_range_.StartOffset();
}
base::Optional<int> LayoutSelection::SelectionEnd() const {
WTF::Optional<int> LayoutSelection::SelectionEnd() const {
DCHECK(!HasPendingSelection());
if (paint_range_.IsNull())
return base::nullopt;
return WTF::nullopt;
return paint_range_.EndOffset();
}
......@@ -301,24 +301,23 @@ void LayoutSelection::ClearSelection() {
paint_range_ = SelectionPaintRange();
}
static base::Optional<int> ComputeStartOffset(
static WTF::Optional<int> ComputeStartOffset(
const LayoutObject& layout_object,
const PositionInFlatTree& position) {
Node* const layout_node = layout_object.GetNode();
if (!layout_node || !layout_node->IsTextNode())
return base::nullopt;
return WTF::nullopt;
if (layout_node == position.AnchorNode())
return position.OffsetInContainerNode();
return 0;
}
static base::Optional<int> ComputeEndOffset(
const LayoutObject& layout_object,
const PositionInFlatTree& position) {
static WTF::Optional<int> ComputeEndOffset(const LayoutObject& layout_object,
const PositionInFlatTree& position) {
Node* const layout_node = layout_object.GetNode();
if (!layout_node || !layout_node->IsTextNode())
return base::nullopt;
return WTF::nullopt;
if (layout_node == position.AnchorNode())
return position.OffsetInContainerNode();
......@@ -355,14 +354,14 @@ static void MarkSelectedInside(SelectedLayoutObjects* invalidation_set,
static NewPaintRangeAndSelectedLayoutObjects MarkStartAndEndInOneNode(
SelectedLayoutObjects invalidation_set,
LayoutObject* layout_object,
base::Optional<int> start_offset,
base::Optional<int> end_offset) {
WTF::Optional<int> start_offset,
WTF::Optional<int> end_offset) {
if (!layout_object->GetNode()->IsTextNode()) {
DCHECK(!start_offset.has_value());
DCHECK(!end_offset.has_value());
MarkSelected(&invalidation_set, layout_object,
SelectionState::kStartAndEnd);
return {{layout_object, base::nullopt, layout_object, base::nullopt},
return {{layout_object, WTF::nullopt, layout_object, WTF::nullopt},
std::move(invalidation_set)};
}
......@@ -416,10 +415,10 @@ static NewPaintRangeAndSelectedLayoutObjects MarkStartAndEndInOneNode(
struct LayoutObjectAndOffset {
STACK_ALLOCATED();
LayoutObject* layout_object;
base::Optional<int> offset;
WTF::Optional<int> offset;
explicit LayoutObjectAndOffset(LayoutObject* passed_layout_object)
: layout_object(passed_layout_object), offset(base::nullopt) {
: layout_object(passed_layout_object), offset(WTF::nullopt) {
DCHECK(passed_layout_object);
DCHECK(!passed_layout_object->GetNode()->IsTextNode());
}
......@@ -432,7 +431,7 @@ struct LayoutObjectAndOffset {
LayoutObjectAndOffset MarkStart(SelectedLayoutObjects* invalidation_set,
LayoutObject* start_layout_object,
base::Optional<int> start_offset) {
WTF::Optional<int> start_offset) {
if (!start_layout_object->GetNode()->IsTextNode()) {
DCHECK(!start_offset.has_value());
MarkSelected(invalidation_set, start_layout_object, SelectionState::kStart);
......@@ -464,7 +463,7 @@ LayoutObjectAndOffset MarkStart(SelectedLayoutObjects* invalidation_set,
LayoutObjectAndOffset MarkEnd(SelectedLayoutObjects* invalidation_set,
LayoutObject* end_layout_object,
base::Optional<int> end_offset) {
WTF::Optional<int> end_offset) {
if (!end_layout_object->GetNode()->IsTextNode()) {
DCHECK(!end_offset.has_value());
MarkSelected(invalidation_set, end_layout_object, SelectionState::kEnd);
......@@ -501,9 +500,9 @@ LayoutObjectAndOffset MarkEnd(SelectedLayoutObjects* invalidation_set,
static NewPaintRangeAndSelectedLayoutObjects MarkStartAndEndInTwoNodes(
SelectedLayoutObjects invalidation_set,
LayoutObject* start_layout_object,
base::Optional<int> start_offset,
WTF::Optional<int> start_offset,
LayoutObject* end_layout_object,
base::Optional<int> end_offset) {
WTF::Optional<int> end_offset) {
const LayoutObjectAndOffset& start =
MarkStart(&invalidation_set, start_layout_object, start_offset);
const LayoutObjectAndOffset& end =
......@@ -555,9 +554,9 @@ CalcSelectionRangeAndSetSelectionState(const FrameSelection& frame_selection) {
}
// Compute offset. It has value iff start/end is text.
const base::Optional<int> start_offset = ComputeStartOffset(
const WTF::Optional<int> start_offset = ComputeStartOffset(
*start_layout_object, selection.StartPosition().ToOffsetInAnchor());
const base::Optional<int> end_offset = ComputeEndOffset(
const WTF::Optional<int> end_offset = ComputeEndOffset(
*end_layout_object, selection.EndPosition().ToOffsetInAnchor());
if (start_layout_object == end_layout_object) {
......
......@@ -25,6 +25,7 @@
#include "core/CoreExport.h"
#include "core/editing/Forward.h"
#include "platform/heap/Handle.h"
#include "platform/wtf/Optional.h"
namespace blink {
......@@ -67,24 +68,24 @@ class SelectionPaintRange {
SelectionPaintRange() = default;
SelectionPaintRange(LayoutObject* start_layout_object,
base::Optional<int> start_offset,
WTF::Optional<int> start_offset,
LayoutObject* end_layout_object,
base::Optional<int> end_offset);
WTF::Optional<int> end_offset);
bool operator==(const SelectionPaintRange& other) const;
LayoutObject* StartLayoutObject() const;
base::Optional<int> StartOffset() const;
WTF::Optional<int> StartOffset() const;
LayoutObject* EndLayoutObject() const;
base::Optional<int> EndOffset() const;
WTF::Optional<int> EndOffset() const;
bool IsNull() const { return !start_layout_object_; }
private:
LayoutObject* start_layout_object_ = nullptr;
base::Optional<int> start_offset_ = base::nullopt;
WTF::Optional<int> start_offset_ = WTF::nullopt;
LayoutObject* end_layout_object_ = nullptr;
base::Optional<int> end_offset_ = base::nullopt;
WTF::Optional<int> end_offset_ = WTF::nullopt;
};
class LayoutSelection final : public GarbageCollected<LayoutSelection> {
......@@ -101,8 +102,8 @@ class LayoutSelection final : public GarbageCollected<LayoutSelection> {
void InvalidatePaintForSelection();
void ClearSelection();
base::Optional<int> SelectionStart() const;
base::Optional<int> SelectionEnd() const;
WTF::Optional<int> SelectionStart() const;
WTF::Optional<int> SelectionEnd() const;
void OnDocumentShutdown();
void Trace(blink::Visitor*);
......
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