0

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:
Victor Hugo Vianna Silva
2025-03-11 10:26:21 -07:00
committed by Chromium LUCI CQ
parent 4651e859ff
commit 7387b18bdc
4 changed files with 33 additions and 32 deletions

@@ -14,6 +14,7 @@
#include <string> #include <string>
#include <string_view> #include <string_view>
#include <utility> #include <utility>
#include <variant>
#include <vector> #include <vector>
#include "base/check.h" #include "base/check.h"
@@ -1152,11 +1153,11 @@ void PdfInkModule::ApplyUndoRedoCommandsHelper(
std::set<InkModeledShapeId> shape_ids; std::set<InkModeledShapeId> shape_ids;
for (PdfInkUndoRedoModel::IdType id : ids) { for (PdfInkUndoRedoModel::IdType id : ids) {
bool inserted; bool inserted;
if (absl::holds_alternative<InkStrokeId>(id)) { if (std::holds_alternative<InkStrokeId>(id)) {
inserted = stroke_ids.insert(absl::get<InkStrokeId>(id)).second; inserted = stroke_ids.insert(std::get<InkStrokeId>(id)).second;
} else { } else {
CHECK(absl::holds_alternative<InkModeledShapeId>(id)); CHECK(std::holds_alternative<InkModeledShapeId>(id));
inserted = shape_ids.insert(absl::get<InkModeledShapeId>(id)).second; inserted = shape_ids.insert(std::get<InkModeledShapeId>(id)).second;
} }
CHECK(inserted); CHECK(inserted);
} }

@@ -9,6 +9,7 @@
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <set> #include <set>
#include <variant>
#include <vector> #include <vector>
#include "base/containers/flat_set.h" #include "base/containers/flat_set.h"
@@ -22,7 +23,6 @@
#include "pdf/pdf_ink_ids.h" #include "pdf/pdf_ink_ids.h"
#include "pdf/pdf_ink_undo_redo_model.h" #include "pdf/pdf_ink_undo_redo_model.h"
#include "pdf/ui/thumbnail.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/geometry/partitioned_mesh.h"
#include "third_party/ink/src/ink/strokes/in_progress_stroke.h" #include "third_party/ink/src/ink/strokes/in_progress_stroke.h"
#include "third_party/ink/src/ink/strokes/input/stroke_input.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); void HandleSetAnnotationModeMessage(const base::Value::Dict& message);
bool is_drawing_stroke() const { 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 { 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 { const DrawingStrokeState& drawing_stroke_state() const {
return absl::get<DrawingStrokeState>(current_tool_state_); return std::get<DrawingStrokeState>(current_tool_state_);
} }
DrawingStrokeState& drawing_stroke_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 { const EraserState& erasing_stroke_state() const {
return absl::get<EraserState>(current_tool_state_); return std::get<EraserState>(current_tool_state_);
} }
EraserState& erasing_stroke_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. // Returns the current brush. Must be in a drawing stroke state.
@@ -438,7 +438,7 @@ class PdfInkModule {
std::optional<PendingDrawingBrushState> pending_drawing_brush_state_; std::optional<PendingDrawingBrushState> pending_drawing_brush_state_;
// The state of the current tool that is in use. // 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. // The state of the strokes that have been completed.
DocumentStrokesMap strokes_; DocumentStrokesMap strokes_;

@@ -8,13 +8,13 @@
#include <optional> #include <optional>
#include <set> #include <set>
#include <variant>
#include <vector> #include <vector>
#include "base/check.h" #include "base/check.h"
#include "base/check_op.h" #include "base/check_op.h"
#include "base/notreached.h" #include "base/notreached.h"
#include "base/types/strong_alias.h" #include "base/types/strong_alias.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
namespace chrome_pdf { namespace chrome_pdf {
@@ -22,12 +22,12 @@ namespace {
PdfInkUndoRedoModel::DrawCommands& GetModifiableDrawCommands( PdfInkUndoRedoModel::DrawCommands& GetModifiableDrawCommands(
PdfInkUndoRedoModel::Commands& commands) { PdfInkUndoRedoModel::Commands& commands) {
return absl::get<PdfInkUndoRedoModel::DrawCommands>(commands); return std::get<PdfInkUndoRedoModel::DrawCommands>(commands);
} }
PdfInkUndoRedoModel::EraseCommands& GetModifiableEraseCommands( PdfInkUndoRedoModel::EraseCommands& GetModifiableEraseCommands(
PdfInkUndoRedoModel::Commands& commands) { PdfInkUndoRedoModel::Commands& commands) {
return absl::get<PdfInkUndoRedoModel::EraseCommands>(commands); return std::get<PdfInkUndoRedoModel::EraseCommands>(commands);
} }
} // namespace } // namespace
@@ -70,11 +70,11 @@ bool PdfInkUndoRedoModel::FinishDraw() {
auto& commands = commands_stack_.back(); auto& commands = commands_stack_.back();
if (GetDrawCommands(commands)->empty()) { if (GetDrawCommands(commands)->empty()) {
commands = absl::monostate(); // Reuse top of stack if empty. commands = std::monostate(); // Reuse top of stack if empty.
} else { } else {
// Otherwise push new item onto the stack. // Otherwise push new item onto the stack.
++stack_position_; ++stack_position_;
commands_stack_.push_back(absl::monostate()); commands_stack_.push_back(std::monostate());
} }
return true; return true;
} }
@@ -130,11 +130,11 @@ bool PdfInkUndoRedoModel::FinishErase() {
auto& commands = commands_stack_.back(); auto& commands = commands_stack_.back();
if (GetEraseCommands(commands)->empty()) { if (GetEraseCommands(commands)->empty()) {
commands = absl::monostate(); // Reuse top of stack if empty. commands = std::monostate(); // Reuse top of stack if empty.
} else { } else {
// Otherwise push new item onto the stack. // Otherwise push new item onto the stack.
++stack_position_; ++stack_position_;
commands_stack_.push_back(absl::monostate()); commands_stack_.push_back(std::monostate());
} }
return true; return true;
} }
@@ -144,7 +144,7 @@ PdfInkUndoRedoModel::Commands PdfInkUndoRedoModel::Undo() {
CHECK_LT(stack_position_, commands_stack_.size()); CHECK_LT(stack_position_, commands_stack_.size());
if (stack_position_ == 0) { 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. // Result is reverse of the recorded commands.
@@ -177,7 +177,7 @@ PdfInkUndoRedoModel::Commands PdfInkUndoRedoModel::Redo() {
CHECK_LT(stack_position_, commands_stack_.size()); CHECK_LT(stack_position_, commands_stack_.size());
if (stack_position_ == commands_stack_.size() - 1) { 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. // Result is the recorded commands as-is.
@@ -200,26 +200,26 @@ PdfInkUndoRedoModel::Commands PdfInkUndoRedoModel::Redo() {
// static // static
PdfInkUndoRedoModel::CommandsType PdfInkUndoRedoModel::GetCommandsType( PdfInkUndoRedoModel::CommandsType PdfInkUndoRedoModel::GetCommandsType(
const Commands& commands) { const Commands& commands) {
if (absl::holds_alternative<absl::monostate>(commands)) { if (std::holds_alternative<std::monostate>(commands)) {
return CommandsType::kNone; return CommandsType::kNone;
} }
if (absl::holds_alternative<DrawCommands>(commands)) { if (std::holds_alternative<DrawCommands>(commands)) {
return CommandsType::kDraw; return CommandsType::kDraw;
} }
CHECK(absl::holds_alternative<EraseCommands>(commands)); CHECK(std::holds_alternative<EraseCommands>(commands));
return CommandsType::kErase; return CommandsType::kErase;
} }
// static // static
const PdfInkUndoRedoModel::DrawCommands& PdfInkUndoRedoModel::GetDrawCommands( const PdfInkUndoRedoModel::DrawCommands& PdfInkUndoRedoModel::GetDrawCommands(
const Commands& commands) { const Commands& commands) {
return absl::get<DrawCommands>(commands); return std::get<DrawCommands>(commands);
} }
// static // static
const PdfInkUndoRedoModel::EraseCommands& PdfInkUndoRedoModel::GetEraseCommands( const PdfInkUndoRedoModel::EraseCommands& PdfInkUndoRedoModel::GetEraseCommands(
const Commands& commands) { const Commands& commands) {
return absl::get<EraseCommands>(commands); return std::get<EraseCommands>(commands);
} }
template <typename T> template <typename T>
@@ -244,7 +244,7 @@ PdfInkUndoRedoModel::StartImpl() {
if (GetCommandsType(commands_stack_[i]) == CommandsType::kDraw) { if (GetCommandsType(commands_stack_[i]) == CommandsType::kDraw) {
for (IdType id : GetDrawCommands(commands_stack_[i]).value()) { for (IdType id : GetDrawCommands(commands_stack_[i]).value()) {
bool inserted = bool inserted =
discarded_commands.insert(absl::get<InkStrokeId>(id)).second; discarded_commands.insert(std::get<InkStrokeId>(id)).second;
CHECK(inserted); CHECK(inserted);
} }
} }

@@ -9,12 +9,12 @@
#include <optional> #include <optional>
#include <set> #include <set>
#include <variant>
#include <vector> #include <vector>
#include "base/types/strong_alias.h" #include "base/types/strong_alias.h"
#include "pdf/buildflags.h" #include "pdf/buildflags.h"
#include "pdf/pdf_ink_ids.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"); static_assert(BUILDFLAG(ENABLE_PDF_INK2), "ENABLE_PDF_INK2 not set to true");
@@ -36,13 +36,13 @@ class PdfInkUndoRedoModel {
// later. // later.
// - `InkModeledShapeId` is for modeled shapes that are pre-existing and can // - `InkModeledShapeId` is for modeled shapes that are pre-existing and can
// be erased. // be erased.
using IdType = absl::variant<InkStrokeId, InkModeledShapeId>; using IdType = std::variant<InkStrokeId, InkModeledShapeId>;
using DrawCommands = using DrawCommands =
base::StrongAlias<class DrawCommandsTag, std::set<IdType>>; base::StrongAlias<class DrawCommandsTag, std::set<IdType>>;
using EraseCommands = using EraseCommands =
base::StrongAlias<class EraseCommandsTag, std::set<IdType>>; 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 // Set of IDs used for drawing to discard. This does not use `IdType`, because
// model shapes are pre-existing and cannot be discarded. // model shapes are pre-existing and cannot be discarded.
@@ -122,7 +122,7 @@ class PdfInkUndoRedoModel {
// Invariants: // Invariants:
// (1) Never empty. // (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` // (3) IDs used in `DrawCommands` elements are unique among all `DrawCommands`
// elements. // elements.
// (4) IDs added to a `DrawCommands` must not exist in any `EraseCommands`. // (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 // `DrawCommands` can hold `InkModeledShapeId` is to undo an
// `InkModeledShapeId` erasure, where the caller needs to know they need // `InkModeledShapeId` erasure, where the caller needs to know they need
// to draw the shape. // to draw the shape.
std::vector<Commands> commands_stack_ = {absl::monostate()}; std::vector<Commands> commands_stack_ = {std::monostate()};
// Invariants: // Invariants:
// (8) Always less than the size of `commands_stack_`. // (8) Always less than the size of `commands_stack_`.