Apply pdfium_noshorten_config to xfa/fwl

Fall back to checked_cast<> for some ranges where -1 may be
required as a sentinel. Convert other indices to size_t where
possible.

-- tidy stringview construction while at it.

Change-Id: I659c7208498d8ed6e891fabbbd5daf4ec1173aa8
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/90710
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/xfa/fwl/BUILD.gn b/xfa/fwl/BUILD.gn
index 0b02bf2..6036e6a 100644
--- a/xfa/fwl/BUILD.gn
+++ b/xfa/fwl/BUILD.gn
@@ -108,6 +108,11 @@
     "theme/cfwl_widgettp.cpp",
     "theme/cfwl_widgettp.h",
   ]
+  configs += [
+    "../../:pdfium_strict_config",
+    "../../:pdfium_noshorten_config",
+    "../:xfa_warnings",
+  ]
   deps = [
     "../../core/fxcrt",
     "../../core/fxge",
@@ -117,10 +122,6 @@
     "../fgas/font",
     "../fgas/graphics",
   ]
-  configs += [
-    "../../:pdfium_strict_config",
-    "../:xfa_warnings",
-  ]
   visibility = [ "../../*" ]
 }
 
diff --git a/xfa/fwl/cfwl_datetimepicker.cpp b/xfa/fwl/cfwl_datetimepicker.cpp
index aeb949e..ba00401 100644
--- a/xfa/fwl/cfwl_datetimepicker.cpp
+++ b/xfa/fwl/cfwl_datetimepicker.cpp
@@ -158,7 +158,7 @@
   return m_pEdit ? m_pEdit->GetText() : WideString();
 }
 
-int32_t CFWL_DateTimePicker::GetEditTextLength() const {
+size_t CFWL_DateTimePicker::GetEditTextLength() const {
   return m_pEdit ? m_pEdit->GetTextLength() : 0;
 }
 
diff --git a/xfa/fwl/cfwl_datetimepicker.h b/xfa/fwl/cfwl_datetimepicker.h
index 060a780..7b7a53f 100644
--- a/xfa/fwl/cfwl_datetimepicker.h
+++ b/xfa/fwl/cfwl_datetimepicker.h
@@ -49,7 +49,7 @@
   void SetCurSel(int32_t iYear, int32_t iMonth, int32_t iDay);
 
   void SetEditText(const WideString& wsText);
-  int32_t GetEditTextLength() const;
+  size_t GetEditTextLength() const;
   WideString GetEditText() const;
   void ClearText();
 
diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp
index f9c2146..ce2f507 100644
--- a/xfa/fwl/cfwl_edit.cpp
+++ b/xfa/fwl/cfwl_edit.cpp
@@ -16,6 +16,7 @@
 #include "core/fxge/text_char_pos.h"
 #include "third_party/base/check.h"
 #include "third_party/base/cxx17_backports.h"
+#include "third_party/base/numerics/safe_conversions.h"
 #include "v8/include/cppgc/visitor.h"
 #include "xfa/fde/cfde_textout.h"
 #include "xfa/fgas/font/cfgas_gefont.h"
@@ -157,7 +158,7 @@
                         CFDE_TextEditEngine::RecordOperation::kSkipNotify);
 }
 
-int32_t CFWL_Edit::GetTextLength() const {
+size_t CFWL_Edit::GetTextLength() const {
   return m_pEditEngine->GetLength();
 }
 
@@ -327,8 +328,9 @@
     size_t sel_start;
     size_t count;
     std::tie(sel_start, count) = m_pEditEngine->GetSelection();
-    std::vector<CFX_RectF> rects =
-        m_pEditEngine->GetCharacterRectsInRange(sel_start, count);
+    std::vector<CFX_RectF> rects = m_pEditEngine->GetCharacterRectsInRange(
+        pdfium::base::checked_cast<int32_t>(sel_start),
+        pdfium::base::checked_cast<int32_t>(count));
 
     CFGAS_GEPath path;
     for (auto& rect : rects) {
@@ -758,8 +760,8 @@
 void CFWL_Edit::UpdateCursorRect() {
   int32_t bidi_level;
   if (m_pEditEngine->CanGenerateCharacterInfo()) {
-    std::tie(bidi_level, m_CaretRect) =
-        m_pEditEngine->GetCharacterInfo(m_CursorPosition);
+    std::tie(bidi_level, m_CaretRect) = m_pEditEngine->GetCharacterInfo(
+        pdfium::base::checked_cast<int32_t>(m_CursorPosition));
   } else {
     bidi_level = 0;
     m_CaretRect = CFX_RectF();
diff --git a/xfa/fwl/cfwl_edit.h b/xfa/fwl/cfwl_edit.h
index a9ce04b..66ff7de 100644
--- a/xfa/fwl/cfwl_edit.h
+++ b/xfa/fwl/cfwl_edit.h
@@ -67,7 +67,7 @@
   virtual void SetText(const WideString& wsText);
   virtual void SetTextSkipNotify(const WideString& wsText);
 
-  int32_t GetTextLength() const;
+  size_t GetTextLength() const;
   WideString GetText() const;
   void ClearText();
 
diff --git a/xfa/fwl/cfwl_listbox.cpp b/xfa/fwl/cfwl_listbox.cpp
index 14e6fd4..6e1953d 100644
--- a/xfa/fwl/cfwl_listbox.cpp
+++ b/xfa/fwl/cfwl_listbox.cpp
@@ -12,6 +12,7 @@
 
 #include "core/fxcrt/stl_util.h"
 #include "third_party/base/cxx17_backports.h"
+#include "third_party/base/numerics/safe_conversions.h"
 #include "v8/include/cppgc/visitor.h"
 #include "xfa/fde/cfde_textout.h"
 #include "xfa/fgas/graphics/cfgas_gegraphics.h"
@@ -832,7 +833,9 @@
                          [pItem](const std::unique_ptr<Item>& candidate) {
                            return candidate.get() == pItem;
                          });
-  return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1;
+  return it != m_ItemArray.end()
+             ? pdfium::base::checked_cast<int32_t>(it - m_ItemArray.begin())
+             : -1;
 }
 
 CFWL_ListBox::Item* CFWL_ListBox::AddString(const WideString& wsAdd) {
diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp
index 55434e5..b49fda6 100644
--- a/xfa/fwl/theme/cfwl_widgettp.cpp
+++ b/xfa/fwl/theme/cfwl_widgettp.cpp
@@ -32,8 +32,7 @@
 
 void CFWL_WidgetTP::DrawText(const CFWL_ThemeText& pParams) {
   EnsureTTOInitialized();
-  int32_t iLen = pParams.m_wsText.GetLength();
-  if (iLen <= 0)
+  if (pParams.m_wsText.IsEmpty())
     return;
 
   CFGAS_GEGraphics* pGraphics = pParams.GetGraphics();
@@ -44,7 +43,7 @@
   matrix.Concat(*pGraphics->GetMatrix());
   m_pTextOut->SetMatrix(matrix);
   m_pTextOut->DrawLogicText(pGraphics->GetRenderDevice(),
-                            WideStringView(pParams.m_wsText.c_str(), iLen),
+                            pParams.m_wsText.AsStringView(),
                             pParams.m_PartRect);
 }