Migrate absl variant.h and utility.h in pdf
Since https://crrev.com/c/6330348, some utils in third_party/abseil-cpp/absl/types/variant.h and and third_party/abseil-cpp/absl/utility/utility.h are only aliases for their std counterparts. This CL migrates code to use std:: directly. Bug: 40242126 Change-Id: I77d062299c1476b27c416a4b1ed6af5b217218c0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6340829 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Cr-Commit-Position: refs/heads/main@{#1430979}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
4651e859ff
commit
7387b18bdc
@ -14,6 +14,7 @@
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "base/check.h"
|
||||
@ -1152,11 +1153,11 @@ void PdfInkModule::ApplyUndoRedoCommandsHelper(
|
||||
std::set<InkModeledShapeId> shape_ids;
|
||||
for (PdfInkUndoRedoModel::IdType id : ids) {
|
||||
bool inserted;
|
||||
if (absl::holds_alternative<InkStrokeId>(id)) {
|
||||
inserted = stroke_ids.insert(absl::get<InkStrokeId>(id)).second;
|
||||
if (std::holds_alternative<InkStrokeId>(id)) {
|
||||
inserted = stroke_ids.insert(std::get<InkStrokeId>(id)).second;
|
||||
} else {
|
||||
CHECK(absl::holds_alternative<InkModeledShapeId>(id));
|
||||
inserted = shape_ids.insert(absl::get<InkModeledShapeId>(id)).second;
|
||||
CHECK(std::holds_alternative<InkModeledShapeId>(id));
|
||||
inserted = shape_ids.insert(std::get<InkModeledShapeId>(id)).second;
|
||||
}
|
||||
CHECK(inserted);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "base/containers/flat_set.h"
|
||||
@ -22,7 +23,6 @@
|
||||
#include "pdf/pdf_ink_ids.h"
|
||||
#include "pdf/pdf_ink_undo_redo_model.h"
|
||||
#include "pdf/ui/thumbnail.h"
|
||||
#include "third_party/abseil-cpp/absl/types/variant.h"
|
||||
#include "third_party/ink/src/ink/geometry/partitioned_mesh.h"
|
||||
#include "third_party/ink/src/ink/strokes/in_progress_stroke.h"
|
||||
#include "third_party/ink/src/ink/strokes/input/stroke_input.h"
|
||||
@ -336,22 +336,22 @@ class PdfInkModule {
|
||||
void HandleSetAnnotationModeMessage(const base::Value::Dict& message);
|
||||
|
||||
bool is_drawing_stroke() const {
|
||||
return absl::holds_alternative<DrawingStrokeState>(current_tool_state_);
|
||||
return std::holds_alternative<DrawingStrokeState>(current_tool_state_);
|
||||
}
|
||||
bool is_erasing_stroke() const {
|
||||
return absl::holds_alternative<EraserState>(current_tool_state_);
|
||||
return std::holds_alternative<EraserState>(current_tool_state_);
|
||||
}
|
||||
const DrawingStrokeState& drawing_stroke_state() const {
|
||||
return absl::get<DrawingStrokeState>(current_tool_state_);
|
||||
return std::get<DrawingStrokeState>(current_tool_state_);
|
||||
}
|
||||
DrawingStrokeState& drawing_stroke_state() {
|
||||
return absl::get<DrawingStrokeState>(current_tool_state_);
|
||||
return std::get<DrawingStrokeState>(current_tool_state_);
|
||||
}
|
||||
const EraserState& erasing_stroke_state() const {
|
||||
return absl::get<EraserState>(current_tool_state_);
|
||||
return std::get<EraserState>(current_tool_state_);
|
||||
}
|
||||
EraserState& erasing_stroke_state() {
|
||||
return absl::get<EraserState>(current_tool_state_);
|
||||
return std::get<EraserState>(current_tool_state_);
|
||||
}
|
||||
|
||||
// Returns the current brush. Must be in a drawing stroke state.
|
||||
@ -438,7 +438,7 @@ class PdfInkModule {
|
||||
std::optional<PendingDrawingBrushState> pending_drawing_brush_state_;
|
||||
|
||||
// The state of the current tool that is in use.
|
||||
absl::variant<DrawingStrokeState, EraserState> current_tool_state_;
|
||||
std::variant<DrawingStrokeState, EraserState> current_tool_state_;
|
||||
|
||||
// The state of the strokes that have been completed.
|
||||
DocumentStrokesMap strokes_;
|
||||
|
@ -8,13 +8,13 @@
|
||||
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "base/check.h"
|
||||
#include "base/check_op.h"
|
||||
#include "base/notreached.h"
|
||||
#include "base/types/strong_alias.h"
|
||||
#include "third_party/abseil-cpp/absl/types/variant.h"
|
||||
|
||||
namespace chrome_pdf {
|
||||
|
||||
@ -22,12 +22,12 @@ namespace {
|
||||
|
||||
PdfInkUndoRedoModel::DrawCommands& GetModifiableDrawCommands(
|
||||
PdfInkUndoRedoModel::Commands& commands) {
|
||||
return absl::get<PdfInkUndoRedoModel::DrawCommands>(commands);
|
||||
return std::get<PdfInkUndoRedoModel::DrawCommands>(commands);
|
||||
}
|
||||
|
||||
PdfInkUndoRedoModel::EraseCommands& GetModifiableEraseCommands(
|
||||
PdfInkUndoRedoModel::Commands& commands) {
|
||||
return absl::get<PdfInkUndoRedoModel::EraseCommands>(commands);
|
||||
return std::get<PdfInkUndoRedoModel::EraseCommands>(commands);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@ -70,11 +70,11 @@ bool PdfInkUndoRedoModel::FinishDraw() {
|
||||
|
||||
auto& commands = commands_stack_.back();
|
||||
if (GetDrawCommands(commands)->empty()) {
|
||||
commands = absl::monostate(); // Reuse top of stack if empty.
|
||||
commands = std::monostate(); // Reuse top of stack if empty.
|
||||
} else {
|
||||
// Otherwise push new item onto the stack.
|
||||
++stack_position_;
|
||||
commands_stack_.push_back(absl::monostate());
|
||||
commands_stack_.push_back(std::monostate());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -130,11 +130,11 @@ bool PdfInkUndoRedoModel::FinishErase() {
|
||||
|
||||
auto& commands = commands_stack_.back();
|
||||
if (GetEraseCommands(commands)->empty()) {
|
||||
commands = absl::monostate(); // Reuse top of stack if empty.
|
||||
commands = std::monostate(); // Reuse top of stack if empty.
|
||||
} else {
|
||||
// Otherwise push new item onto the stack.
|
||||
++stack_position_;
|
||||
commands_stack_.push_back(absl::monostate());
|
||||
commands_stack_.push_back(std::monostate());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -144,7 +144,7 @@ PdfInkUndoRedoModel::Commands PdfInkUndoRedoModel::Undo() {
|
||||
CHECK_LT(stack_position_, commands_stack_.size());
|
||||
|
||||
if (stack_position_ == 0) {
|
||||
return absl::monostate(); // Already at bottom of stack.
|
||||
return std::monostate(); // Already at bottom of stack.
|
||||
}
|
||||
|
||||
// Result is reverse of the recorded commands.
|
||||
@ -177,7 +177,7 @@ PdfInkUndoRedoModel::Commands PdfInkUndoRedoModel::Redo() {
|
||||
CHECK_LT(stack_position_, commands_stack_.size());
|
||||
|
||||
if (stack_position_ == commands_stack_.size() - 1) {
|
||||
return absl::monostate(); // Already at top of stack.
|
||||
return std::monostate(); // Already at top of stack.
|
||||
}
|
||||
|
||||
// Result is the recorded commands as-is.
|
||||
@ -200,26 +200,26 @@ PdfInkUndoRedoModel::Commands PdfInkUndoRedoModel::Redo() {
|
||||
// static
|
||||
PdfInkUndoRedoModel::CommandsType PdfInkUndoRedoModel::GetCommandsType(
|
||||
const Commands& commands) {
|
||||
if (absl::holds_alternative<absl::monostate>(commands)) {
|
||||
if (std::holds_alternative<std::monostate>(commands)) {
|
||||
return CommandsType::kNone;
|
||||
}
|
||||
if (absl::holds_alternative<DrawCommands>(commands)) {
|
||||
if (std::holds_alternative<DrawCommands>(commands)) {
|
||||
return CommandsType::kDraw;
|
||||
}
|
||||
CHECK(absl::holds_alternative<EraseCommands>(commands));
|
||||
CHECK(std::holds_alternative<EraseCommands>(commands));
|
||||
return CommandsType::kErase;
|
||||
}
|
||||
|
||||
// static
|
||||
const PdfInkUndoRedoModel::DrawCommands& PdfInkUndoRedoModel::GetDrawCommands(
|
||||
const Commands& commands) {
|
||||
return absl::get<DrawCommands>(commands);
|
||||
return std::get<DrawCommands>(commands);
|
||||
}
|
||||
|
||||
// static
|
||||
const PdfInkUndoRedoModel::EraseCommands& PdfInkUndoRedoModel::GetEraseCommands(
|
||||
const Commands& commands) {
|
||||
return absl::get<EraseCommands>(commands);
|
||||
return std::get<EraseCommands>(commands);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@ -244,7 +244,7 @@ PdfInkUndoRedoModel::StartImpl() {
|
||||
if (GetCommandsType(commands_stack_[i]) == CommandsType::kDraw) {
|
||||
for (IdType id : GetDrawCommands(commands_stack_[i]).value()) {
|
||||
bool inserted =
|
||||
discarded_commands.insert(absl::get<InkStrokeId>(id)).second;
|
||||
discarded_commands.insert(std::get<InkStrokeId>(id)).second;
|
||||
CHECK(inserted);
|
||||
}
|
||||
}
|
||||
|
@ -9,12 +9,12 @@
|
||||
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "base/types/strong_alias.h"
|
||||
#include "pdf/buildflags.h"
|
||||
#include "pdf/pdf_ink_ids.h"
|
||||
#include "third_party/abseil-cpp/absl/types/variant.h"
|
||||
|
||||
static_assert(BUILDFLAG(ENABLE_PDF_INK2), "ENABLE_PDF_INK2 not set to true");
|
||||
|
||||
@ -36,13 +36,13 @@ class PdfInkUndoRedoModel {
|
||||
// later.
|
||||
// - `InkModeledShapeId` is for modeled shapes that are pre-existing and can
|
||||
// be erased.
|
||||
using IdType = absl::variant<InkStrokeId, InkModeledShapeId>;
|
||||
using IdType = std::variant<InkStrokeId, InkModeledShapeId>;
|
||||
using DrawCommands =
|
||||
base::StrongAlias<class DrawCommandsTag, std::set<IdType>>;
|
||||
using EraseCommands =
|
||||
base::StrongAlias<class EraseCommandsTag, std::set<IdType>>;
|
||||
|
||||
using Commands = absl::variant<absl::monostate, DrawCommands, EraseCommands>;
|
||||
using Commands = std::variant<std::monostate, DrawCommands, EraseCommands>;
|
||||
|
||||
// Set of IDs used for drawing to discard. This does not use `IdType`, because
|
||||
// model shapes are pre-existing and cannot be discarded.
|
||||
@ -122,7 +122,7 @@ class PdfInkUndoRedoModel {
|
||||
|
||||
// Invariants:
|
||||
// (1) Never empty.
|
||||
// (2) The last element and only the last element can be `absl::monostate`.
|
||||
// (2) The last element and only the last element can be `std::monostate`.
|
||||
// (3) IDs used in `DrawCommands` elements are unique among all `DrawCommands`
|
||||
// elements.
|
||||
// (4) IDs added to a `DrawCommands` must not exist in any `EraseCommands`.
|
||||
@ -134,7 +134,7 @@ class PdfInkUndoRedoModel {
|
||||
// `DrawCommands` can hold `InkModeledShapeId` is to undo an
|
||||
// `InkModeledShapeId` erasure, where the caller needs to know they need
|
||||
// to draw the shape.
|
||||
std::vector<Commands> commands_stack_ = {absl::monostate()};
|
||||
std::vector<Commands> commands_stack_ = {std::monostate()};
|
||||
|
||||
// Invariants:
|
||||
// (8) Always less than the size of `commands_stack_`.
|
||||
|
Reference in New Issue
Block a user