Move xfa/fde code into namespace pdfium

Remove "pdfium::" usage within. Add some temporarily `using` statements
in xfa/fde headers to make the build work.

Bug: 42271761
Change-Id: I86cb481137a06fb4e5f5147c98e45414ae0c0efe
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/123352
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@google.com>
diff --git a/xfa/fde/cfde_data.h b/xfa/fde/cfde_data.h
index bfc0ef3..ccbb18b 100644
--- a/xfa/fde/cfde_data.h
+++ b/xfa/fde/cfde_data.h
@@ -9,6 +9,8 @@
 
 #include "core/fxcrt/fx_coordinates.h"
 
+namespace pdfium {
+
 enum class FDE_TextAlignment : uint8_t {
   kTopLeft = 0,
   kCenterLeft,
@@ -31,4 +33,10 @@
   bool last_line_height_ = false;
 };
 
+}  // namespace pdfium
+
+// TODO(crbug.com/42271761): Remove.
+using pdfium::FDE_TextAlignment;
+using pdfium::FDE_TextStyle;
+
 #endif  // XFA_FDE_CFDE_DATA_H_
diff --git a/xfa/fde/cfde_texteditengine.cpp b/xfa/fde/cfde_texteditengine.cpp
index 50098cb..400464a 100644
--- a/xfa/fde/cfde_texteditengine.cpp
+++ b/xfa/fde/cfde_texteditengine.cpp
@@ -20,6 +20,8 @@
 #include "xfa/fde/cfde_wordbreak_data.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
 
+namespace pdfium {
+
 namespace {
 
 class InsertOperation final : public CFDE_TextEditEngine::Operation {
@@ -286,12 +288,12 @@
   if (validation_enabled_ || limit_horizontal_area_ || limit_vertical_area_) {
     WideString str;
     if (gap_position_ > 0) {
-      str += WideStringView(pdfium::make_span(content_).first(gap_position_));
+      str += WideStringView(make_span(content_).first(gap_position_));
     }
     str += text;
 
     if (text_length_ - gap_position_ > 0) {
-      str += WideStringView(pdfium::make_span(content_).subspan(
+      str += WideStringView(make_span(content_).subspan(
           gap_position_ + gap_size_, text_length_ - gap_position_));
     }
 
@@ -329,7 +331,7 @@
 
   // Copy the new text into the gap.
   fxcrt::Copy(text.span().first(length),
-              pdfium::make_span(content_).subspan(gap_position_));
+              make_span(content_).subspan(gap_position_));
 
   gap_position_ += length;
   gap_size_ -= length;
@@ -756,18 +758,18 @@
   if (selection_.start_idx < gap_position_) {
     // Fully on left of gap.
     if (selection_.start_idx + selection_.count < gap_position_) {
-      text += WideStringView(pdfium::make_span(content_).subspan(
-          selection_.start_idx, selection_.count));
+      text += WideStringView(
+          make_span(content_).subspan(selection_.start_idx, selection_.count));
       return text;
     }
 
     // Pre-gap text
-    text += WideStringView(pdfium::make_span(content_).subspan(
+    text += WideStringView(make_span(content_).subspan(
         selection_.start_idx, gap_position_ - selection_.start_idx));
 
     if (selection_.count - (gap_position_ - selection_.start_idx) > 0) {
       // Post-gap text
-      text += WideStringView(pdfium::make_span(content_).subspan(
+      text += WideStringView(make_span(content_).subspan(
           gap_position_ + gap_size_,
           selection_.count - (gap_position_ - selection_.start_idx)));
     }
@@ -776,7 +778,7 @@
   }
 
   // Fully right of gap
-  text += WideStringView(pdfium::make_span(content_).subspan(
+  text += WideStringView(make_span(content_).subspan(
       gap_size_ + selection_.start_idx, selection_.count));
   return text;
 }
@@ -821,7 +823,7 @@
   AdjustGap(start_idx + length, 0);
 
   WideString ret(
-      WideStringView(pdfium::make_span(content_).subspan(start_idx, length)));
+      WideStringView(make_span(content_).subspan(start_idx, length)));
 
   if (add_operation == RecordOperation::kInsertRecord) {
     AddOperationRecord(std::make_unique<DeleteOperation>(this, start_idx, ret));
@@ -877,10 +879,10 @@
 WideString CFDE_TextEditEngine::GetText() const {
   WideString str;
   if (gap_position_ > 0) {
-    str += WideStringView(pdfium::make_span(content_).first(gap_position_));
+    str += WideStringView(make_span(content_).first(gap_position_));
   }
   if (text_length_ - gap_position_ > 0) {
-    str += WideStringView(pdfium::make_span(content_).subspan(
+    str += WideStringView(make_span(content_).subspan(
         gap_position_ + gap_size_, text_length_ - gap_position_));
   }
   return str;
@@ -1075,7 +1077,7 @@
       txtEdtPiece.rtPiece.top = current_line_start;
       txtEdtPiece.rtPiece.width = piece->GetWidth() / 20000.0f;
       txtEdtPiece.rtPiece.height = line_spacing_;
-      txtEdtPiece.nStart = pdfium::checked_cast<int32_t>(current_piece_start);
+      txtEdtPiece.nStart = checked_cast<int32_t>(current_piece_start);
       txtEdtPiece.nCount = piece->GetCharCount();
       txtEdtPiece.nBidiLevel = piece->GetBidiLevel();
       txtEdtPiece.dwCharStyles = piece->GetCharStyles();
@@ -1207,7 +1209,7 @@
 
 void CFDE_TextEditEngine::Iterator::SetAt(size_t nIndex) {
   nIndex = std::min(nIndex, engine_->GetLength());
-  current_position_ = pdfium::checked_cast<int32_t>(nIndex);
+  current_position_ = checked_cast<int32_t>(nIndex);
 }
 
 bool CFDE_TextEditEngine::Iterator::IsEOF(bool bPrev) const {
@@ -1272,3 +1274,5 @@
   }
   return current_position_ > -1 ? current_position_ : 0;
 }
+
+}  // namespace pdfium
diff --git a/xfa/fde/cfde_texteditengine.h b/xfa/fde/cfde_texteditengine.h
index c020e8f..b82f3dd 100644
--- a/xfa/fde/cfde_texteditengine.h
+++ b/xfa/fde/cfde_texteditengine.h
@@ -21,6 +21,8 @@
 class CFGAS_GEFont;
 class TextCharPos;
 
+namespace pdfium {
+
 struct FDE_TEXTEDITPIECE {
   FDE_TEXTEDITPIECE();
   FDE_TEXTEDITPIECE(const FDE_TEXTEDITPIECE& that);
@@ -251,4 +253,10 @@
   Selection selection_{0, 0};
 };
 
+}  // namespace pdfium
+
+// TODO(crbug.com/42271761): Remove.
+using pdfium::CFDE_TextEditEngine;
+using pdfium::FDE_TEXTEDITPIECE;
+
 #endif  // XFA_FDE_CFDE_TEXTEDITENGINE_H_
diff --git a/xfa/fde/cfde_texteditengine_unittest.cpp b/xfa/fde/cfde_texteditengine_unittest.cpp
index 67b516e..d684670 100644
--- a/xfa/fde/cfde_texteditengine_unittest.cpp
+++ b/xfa/fde/cfde_texteditengine_unittest.cpp
@@ -11,6 +11,8 @@
 #include "testing/xfa_test_environment.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
 
+namespace pdfium {
+
 class CFDE_TextEditEngineTest : public testing::Test {
  public:
   class Delegate final : public CFDE_TextEditEngine::Delegate {
@@ -842,3 +844,5 @@
   engine()->SetSelection(engine()->GetIndexRight(5U), 5);
   EXPECT_EQ(L"World", engine()->GetSelectedText());
 }
+
+}  // namespace pdfium
diff --git a/xfa/fde/cfde_textout.cpp b/xfa/fde/cfde_textout.cpp
index 755da41..1a9bba0 100644
--- a/xfa/fde/cfde_textout.cpp
+++ b/xfa/fde/cfde_textout.cpp
@@ -28,6 +28,8 @@
 #include "xfa/fgas/font/cfgas_gefont.h"
 #include "xfa/fgas/layout/cfgas_txtbreak.h"
 
+namespace pdfium {
+
 namespace {
 
 bool TextAlignmentVerticallyCentered(const FDE_TextAlignment align) {
@@ -46,7 +48,7 @@
 bool CFDE_TextOut::DrawString(CFX_RenderDevice* device,
                               FX_ARGB color,
                               const RetainPtr<CFGAS_GEFont>& pFont,
-                              pdfium::span<TextCharPos> pCharPos,
+                              span<TextCharPos> pCharPos,
                               float fFontSize,
                               const CFX_Matrix& matrix) {
   DCHECK(pFont);
@@ -93,8 +95,8 @@
 #else
         font = pFxFont;
 #endif
-        device->DrawNormalText(UNSAFE_TODO(pdfium::make_span(pCurCP, count)),
-                               font, -fFontSize, matrix, color, kOptions);
+        device->DrawNormalText(UNSAFE_TODO(make_span(pCurCP, count)), font,
+                               -fFontSize, matrix, color, kOptions);
       }
       pCurFont = pSTFont;
       pCurCP = &pos;
@@ -113,8 +115,8 @@
 #else
     font = pFxFont;
 #endif
-    return device->DrawNormalText(UNSAFE_TODO(pdfium::make_span(pCurCP, count)),
-                                  font, -fFontSize, matrix, color, kOptions);
+    return device->DrawNormalText(UNSAFE_TODO(make_span(pCurCP, count)), font,
+                                  -fFontSize, matrix, color, kOptions);
   }
   return true;
 }
@@ -303,8 +305,8 @@
         continue;
       }
       CFDE_TextOut::DrawString(device, m_TxtColor, m_pFont,
-                               pdfium::make_span(m_CharPos).first(szCount),
-                               m_fFontSize, m_Matrix);
+                               make_span(m_CharPos).first(szCount), m_fFontSize,
+                               m_Matrix);
     }
   }
   device->RestoreState(false);
@@ -455,7 +457,7 @@
 }
 
 void CFDE_TextOut::ReloadLinePiece(Line* line, const CFX_RectF& rect) {
-  pdfium::span<const wchar_t> text_span = m_wsText.span();
+  span<const wchar_t> text_span = m_wsText.span();
   size_t start_char = 0;
   size_t piece_count = line->GetSize();
   int32_t piece_widths = 0;
@@ -510,8 +512,8 @@
 
   CFGAS_TxtBreak::Run tr;
   tr.wsStr = m_wsText.Substr(pPiece->start_char);
-  tr.pWidths = pdfium::make_span(m_CharWidths).subspan(pPiece->start_char);
-  tr.iLength = pdfium::checked_cast<int32_t>(pPiece->char_count);
+  tr.pWidths = make_span(m_CharWidths).subspan(pPiece->start_char);
+  tr.iLength = checked_cast<int32_t>(pPiece->char_count);
   tr.pFont = m_pFont;
   tr.fFontSize = m_fFontSize;
   tr.dwStyles = m_dwTxtBkStyles;
@@ -554,3 +556,5 @@
 void CFDE_TextOut::Line::RemoveLast(size_t count) {
   pieces_.erase(pieces_.end() - std::min(count, pieces_.size()), pieces_.end());
 }
+
+}  // namespace pdfium
diff --git a/xfa/fde/cfde_textout.h b/xfa/fde/cfde_textout.h
index 2f08c59..7675f0f 100644
--- a/xfa/fde/cfde_textout.h
+++ b/xfa/fde/cfde_textout.h
@@ -24,12 +24,14 @@
 class CFX_RenderDevice;
 class TextCharPos;
 
+namespace pdfium {
+
 class CFDE_TextOut {
  public:
   static bool DrawString(CFX_RenderDevice* device,
                          FX_ARGB color,
                          const RetainPtr<CFGAS_GEFont>& pFont,
-                         pdfium::span<TextCharPos> pCharPos,
+                         span<TextCharPos> pCharPos,
                          float fFontSize,
                          const CFX_Matrix& matrix);
 
@@ -121,4 +123,9 @@
   std::vector<TextCharPos> m_CharPos;
 };
 
+}  // namespace pdfium
+
+// TODO(crbug.com/42271761): Remove.
+using pdfium::CFDE_TextOut;
+
 #endif  // XFA_FDE_CFDE_TEXTOUT_H_
diff --git a/xfa/fde/cfde_textout_unittest.cpp b/xfa/fde/cfde_textout_unittest.cpp
index 79536cf..f598f08 100644
--- a/xfa/fde/cfde_textout_unittest.cpp
+++ b/xfa/fde/cfde_textout_unittest.cpp
@@ -21,6 +21,8 @@
 #include "xfa/fgas/font/cfgas_gefont.h"
 #include "xfa/fgas/font/cfgas_gemodule.h"
 
+namespace pdfium {
+
 class CFDETextOutTest : public testing::Test {
  public:
   CFDETextOutTest() = default;
@@ -31,7 +33,7 @@
     CFX_GlyphCache::InitializeGlobals();
 #endif
     CFX_Size bitmap_size = GetBitmapSize();
-    bitmap_ = pdfium::MakeRetain<CFX_DIBitmap>();
+    bitmap_ = MakeRetain<CFX_DIBitmap>();
     ASSERT_TRUE(bitmap_->Create(bitmap_size.width, bitmap_size.height,
                                 FXDIB_Format::kArgb));
 
@@ -184,3 +186,5 @@
   EXPECT_EQ(GetLargeTextBlobChecksum(), GetBitmapChecksum());
 }
 #endif  // !BUILDFLAG(IS_WIN)
+
+}  // namespace pdfium
diff --git a/xfa/fde/cfde_wordbreak_data.cpp b/xfa/fde/cfde_wordbreak_data.cpp
index 557363a..20b2d82 100644
--- a/xfa/fde/cfde_wordbreak_data.cpp
+++ b/xfa/fde/cfde_wordbreak_data.cpp
@@ -13,6 +13,8 @@
 #include "core/fxcrt/fx_system.h"
 #include "core/fxcrt/span.h"
 
+namespace pdfium {
+
 namespace {
 
 enum WordBreakMask : uint16_t {
@@ -82,7 +84,7 @@
                             kWordBreakMaskExtendNumLet)),
 };
 
-const pdfium::span<const uint16_t> kWordBreakTable{kWordBreakTableData};
+const span<const uint16_t> kWordBreakTable{kWordBreakTableData};
 
 // Table of |WordBreakProperty| for each of the possible uint16_t values,
 // packed as nibbles, with the low nibble first.
@@ -2838,3 +2840,5 @@
   return static_cast<WordBreakProperty>((wcCodePoint & 1) ? (dwProperty & 0x0F)
                                                           : (dwProperty >> 4));
 }
+
+}  // namespace pdfium
diff --git a/xfa/fde/cfde_wordbreak_data.h b/xfa/fde/cfde_wordbreak_data.h
index 537254b..592d089 100644
--- a/xfa/fde/cfde_wordbreak_data.h
+++ b/xfa/fde/cfde_wordbreak_data.h
@@ -9,6 +9,8 @@
 
 #include <stdint.h>
 
+namespace pdfium {
+
 enum class WordBreakProperty : uint8_t {
   // Internal tables depend on constants computed from these values, so do
   // not re-order.
@@ -31,4 +33,6 @@
                                      WordBreakProperty to);
 WordBreakProperty FX_GetWordBreakProperty(wchar_t wcCodePoint);
 
+}  // namespace pdfium
+
 #endif  // XFA_FDE_CFDE_WORDBREAK_DATA_H_
diff --git a/xfa/fwl/theme/cfwl_widgettp.h b/xfa/fwl/theme/cfwl_widgettp.h
index 405e1ec..3d582e6 100644
--- a/xfa/fwl/theme/cfwl_widgettp.h
+++ b/xfa/fwl/theme/cfwl_widgettp.h
@@ -17,7 +17,10 @@
 #include "v8/include/cppgc/garbage-collected.h"
 #include "xfa/fwl/theme/cfwl_utils.h"
 
+namespace pdfium {
 class CFDE_TextOut;
+}  // namespace pdfium
+
 class CFGAS_GEGraphics;
 class CFWL_ThemeBackground;
 class CFWL_ThemeText;
@@ -74,7 +77,7 @@
                     FWLTHEME_STATE eState,
                     const CFX_Matrix& matrix);
 
-  std::unique_ptr<CFDE_TextOut> m_pTextOut;
+  std::unique_ptr<pdfium::CFDE_TextOut> m_pTextOut;
   std::unique_ptr<CColorData> m_pColorData;
 };
 
diff --git a/xfa/fxfa/cxfa_fwltheme.h b/xfa/fxfa/cxfa_fwltheme.h
index b42b5c5..e23da7e 100644
--- a/xfa/fxfa/cxfa_fwltheme.h
+++ b/xfa/fxfa/cxfa_fwltheme.h
@@ -17,7 +17,10 @@
 #include "v8/include/cppgc/prefinalizer.h"
 #include "xfa/fwl/ifwl_themeprovider.h"
 
+namespace pdfium {
 class CFDE_TextOut;
+}  // namespace pdfium
+
 class CXFA_FFApp;
 class CXFA_FFDoc;
 
@@ -52,7 +55,7 @@
  private:
   CXFA_FWLTheme(cppgc::Heap* pHeap, CXFA_FFApp* pApp);
 
-  std::unique_ptr<CFDE_TextOut> m_pTextOut;
+  std::unique_ptr<pdfium::CFDE_TextOut> m_pTextOut;
   RetainPtr<CFGAS_GEFont> m_pFWLFont;
   RetainPtr<CFGAS_GEFont> m_pCalendarFont;
   cppgc::Member<CXFA_FFApp> const m_pApp;