aboutsummaryrefslogtreecommitdiff
path: root/xfa/fwl
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fwl')
-rw-r--r--xfa/fwl/BUILD.gn30
-rw-r--r--xfa/fwl/DEPS4
-rw-r--r--xfa/fwl/cfwl_app.cpp24
-rw-r--r--xfa/fwl/cfwl_app.h58
-rw-r--r--xfa/fwl/cfwl_barcode.cpp100
-rw-r--r--xfa/fwl/cfwl_barcode.h52
-rw-r--r--xfa/fwl/cfwl_caret.cpp51
-rw-r--r--xfa/fwl/cfwl_caret.h22
-rw-r--r--xfa/fwl/cfwl_checkbox.cpp261
-rw-r--r--xfa/fwl/cfwl_checkbox.h38
-rw-r--r--xfa/fwl/cfwl_combobox.cpp371
-rw-r--r--xfa/fwl/cfwl_combobox.h65
-rw-r--r--xfa/fwl/cfwl_comboedit.cpp44
-rw-r--r--xfa/fwl/cfwl_comboedit.h19
-rw-r--r--xfa/fwl/cfwl_combolist.cpp106
-rw-r--r--xfa/fwl/cfwl_combolist.h15
-rw-r--r--xfa/fwl/cfwl_datetimeedit.cpp28
-rw-r--r--xfa/fwl/cfwl_datetimeedit.h16
-rw-r--r--xfa/fwl/cfwl_datetimepicker.cpp315
-rw-r--r--xfa/fwl/cfwl_datetimepicker.h51
-rw-r--r--xfa/fwl/cfwl_edit.cpp766
-rw-r--r--xfa/fwl/cfwl_edit.h65
-rw-r--r--xfa/fwl/cfwl_edit_embeddertest.cpp185
-rw-r--r--xfa/fwl/cfwl_event.cpp2
-rw-r--r--xfa/fwl/cfwl_event.h17
-rw-r--r--xfa/fwl/cfwl_eventmouse.cpp13
-rw-r--r--xfa/fwl/cfwl_eventmouse.h12
-rw-r--r--xfa/fwl/cfwl_eventscroll.cpp12
-rw-r--r--xfa/fwl/cfwl_eventscroll.h12
-rw-r--r--xfa/fwl/cfwl_eventselectchanged.cpp23
-rw-r--r--xfa/fwl/cfwl_eventselectchanged.h24
-rw-r--r--xfa/fwl/cfwl_eventtarget.cpp31
-rw-r--r--xfa/fwl/cfwl_eventtarget.h34
-rw-r--r--xfa/fwl/cfwl_eventtextwillchange.cpp15
-rw-r--r--xfa/fwl/cfwl_eventtextwillchange.h38
-rw-r--r--xfa/fwl/cfwl_eventvalidate.cpp10
-rw-r--r--xfa/fwl/cfwl_eventvalidate.h14
-rw-r--r--xfa/fwl/cfwl_listbox.cpp608
-rw-r--r--xfa/fwl/cfwl_listbox.h128
-rw-r--r--xfa/fwl/cfwl_listitem.cpp11
-rw-r--r--xfa/fwl/cfwl_listitem.h32
-rw-r--r--xfa/fwl/cfwl_message.cpp8
-rw-r--r--xfa/fwl/cfwl_message.h26
-rw-r--r--xfa/fwl/cfwl_messagekey.cpp16
-rw-r--r--xfa/fwl/cfwl_messagekey.h22
-rw-r--r--xfa/fwl/cfwl_messagekillfocus.cpp14
-rw-r--r--xfa/fwl/cfwl_messagekillfocus.h9
-rw-r--r--xfa/fwl/cfwl_messagemouse.cpp17
-rw-r--r--xfa/fwl/cfwl_messagemouse.h41
-rw-r--r--xfa/fwl/cfwl_messagemousewheel.cpp20
-rw-r--r--xfa/fwl/cfwl_messagemousewheel.h22
-rw-r--r--xfa/fwl/cfwl_messagesetfocus.cpp12
-rw-r--r--xfa/fwl/cfwl_messagesetfocus.h6
-rw-r--r--xfa/fwl/cfwl_monthcalendar.cpp640
-rw-r--r--xfa/fwl/cfwl_monthcalendar.h123
-rw-r--r--xfa/fwl/cfwl_notedriver.cpp160
-rw-r--r--xfa/fwl/cfwl_notedriver.h63
-rw-r--r--xfa/fwl/cfwl_picturebox.cpp26
-rw-r--r--xfa/fwl/cfwl_picturebox.h19
-rw-r--r--xfa/fwl/cfwl_pushbutton.cpp172
-rw-r--r--xfa/fwl/cfwl_pushbutton.h33
-rw-r--r--xfa/fwl/cfwl_scrollbar.cpp351
-rw-r--r--xfa/fwl/cfwl_scrollbar.h84
-rw-r--r--xfa/fwl/cfwl_themebackground.cpp14
-rw-r--r--xfa/fwl/cfwl_themebackground.h26
-rw-r--r--xfa/fwl/cfwl_themepart.cpp23
-rw-r--r--xfa/fwl/cfwl_themepart.h157
-rw-r--r--xfa/fwl/cfwl_themetext.cpp14
-rw-r--r--xfa/fwl/cfwl_themetext.h23
-rw-r--r--xfa/fwl/cfwl_widget.cpp207
-rw-r--r--xfa/fwl/cfwl_widget.h125
-rw-r--r--xfa/fwl/cfwl_widgetmgr.cpp293
-rw-r--r--xfa/fwl/cfwl_widgetmgr.h82
-rw-r--r--xfa/fwl/cfwl_widgetproperties.cpp11
-rw-r--r--xfa/fwl/cfwl_widgetproperties.h31
-rw-r--r--xfa/fwl/fwl_widgetdef.h32
-rw-r--r--xfa/fwl/fwl_widgethit.h2
-rw-r--r--xfa/fwl/ifwl_themeprovider.cpp89
-rw-r--r--xfa/fwl/ifwl_themeprovider.h37
-rw-r--r--xfa/fwl/ifwl_widgetdelegate.h10
-rw-r--r--xfa/fwl/theme/cfwl_barcodetp.cpp16
-rw-r--r--xfa/fwl/theme/cfwl_barcodetp.h8
-rw-r--r--xfa/fwl/theme/cfwl_carettp.cpp28
-rw-r--r--xfa/fwl/theme/cfwl_carettp.h12
-rw-r--r--xfa/fwl/theme/cfwl_checkboxtp.cpp260
-rw-r--r--xfa/fwl/theme/cfwl_checkboxtp.h29
-rw-r--r--xfa/fwl/theme/cfwl_comboboxtp.cpp76
-rw-r--r--xfa/fwl/theme/cfwl_comboboxtp.h11
-rw-r--r--xfa/fwl/theme/cfwl_datetimepickertp.cpp48
-rw-r--r--xfa/fwl/theme/cfwl_datetimepickertp.h10
-rw-r--r--xfa/fwl/theme/cfwl_edittp.cpp83
-rw-r--r--xfa/fwl/theme/cfwl_edittp.h10
-rw-r--r--xfa/fwl/theme/cfwl_listboxtp.cpp56
-rw-r--r--xfa/fwl/theme/cfwl_listboxtp.h14
-rw-r--r--xfa/fwl/theme/cfwl_monthcalendartp.cpp236
-rw-r--r--xfa/fwl/theme/cfwl_monthcalendartp.h10
-rw-r--r--xfa/fwl/theme/cfwl_pictureboxtp.cpp12
-rw-r--r--xfa/fwl/theme/cfwl_pictureboxtp.h10
-rw-r--r--xfa/fwl/theme/cfwl_pushbuttontp.cpp83
-rw-r--r--xfa/fwl/theme/cfwl_pushbuttontp.h19
-rw-r--r--xfa/fwl/theme/cfwl_scrollbartp.cpp238
-rw-r--r--xfa/fwl/theme/cfwl_scrollbartp.h23
-rw-r--r--xfa/fwl/theme/cfwl_utils.h31
-rw-r--r--xfa/fwl/theme/cfwl_widgettp.cpp188
-rw-r--r--xfa/fwl/theme/cfwl_widgettp.h77
105 files changed, 3734 insertions, 4636 deletions
diff --git a/xfa/fwl/BUILD.gn b/xfa/fwl/BUILD.gn
index 765704dd1..b6b09b8e4 100644
--- a/xfa/fwl/BUILD.gn
+++ b/xfa/fwl/BUILD.gn
@@ -1,4 +1,4 @@
-# Copyright 2018 The PDFium Authors. All rights reserved.
+# Copyright 2018 The PDFium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
@@ -37,16 +37,12 @@ source_set("fwl") {
"cfwl_eventscroll.h",
"cfwl_eventselectchanged.cpp",
"cfwl_eventselectchanged.h",
- "cfwl_eventtarget.cpp",
- "cfwl_eventtarget.h",
"cfwl_eventtextwillchange.cpp",
"cfwl_eventtextwillchange.h",
"cfwl_eventvalidate.cpp",
"cfwl_eventvalidate.h",
"cfwl_listbox.cpp",
"cfwl_listbox.h",
- "cfwl_listitem.cpp",
- "cfwl_listitem.h",
"cfwl_message.cpp",
"cfwl_message.h",
"cfwl_messagekey.cpp",
@@ -69,18 +65,19 @@ source_set("fwl") {
"cfwl_pushbutton.h",
"cfwl_scrollbar.cpp",
"cfwl_scrollbar.h",
+ "cfwl_themebackground.cpp",
"cfwl_themebackground.h",
"cfwl_themepart.cpp",
"cfwl_themepart.h",
+ "cfwl_themetext.cpp",
"cfwl_themetext.h",
"cfwl_widget.cpp",
"cfwl_widget.h",
"cfwl_widgetmgr.cpp",
"cfwl_widgetmgr.h",
- "cfwl_widgetproperties.cpp",
- "cfwl_widgetproperties.h",
"fwl_widgetdef.h",
"fwl_widgethit.h",
+ "ifwl_themeprovider.cpp",
"ifwl_themeprovider.h",
"ifwl_widgetdelegate.h",
"theme/cfwl_barcodetp.cpp",
@@ -109,22 +106,29 @@ source_set("fwl") {
"theme/cfwl_widgettp.cpp",
"theme/cfwl_widgettp.h",
]
+ configs += [
+ "../../:pdfium_strict_config",
+ "../../:pdfium_noshorten_config",
+ "../:xfa_warnings",
+ ]
deps = [
"../../core/fxcrt",
"../../core/fxge",
"../../fxbarcode",
+ "../../fxjs:gc",
"../fde",
- "../fgas",
- "../fxgraphics",
- ]
- configs += [
- "../../:pdfium_core_config",
- "../:xfa_warnings",
+ "../fgas/font",
+ "../fgas/graphics",
]
visibility = [ "../../*" ]
}
pdfium_embeddertest_source_set("embeddertests") {
sources = [ "cfwl_edit_embeddertest.cpp" ]
+ deps = [
+ ":fwl",
+ "../../core/fxge",
+ "../../fxjs:gc",
+ ]
pdfium_root_dir = "../../"
}
diff --git a/xfa/fwl/DEPS b/xfa/fwl/DEPS
new file mode 100644
index 000000000..8bea3a37f
--- /dev/null
+++ b/xfa/fwl/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+ # fwl is standalone vis-a-vis fxfa. https://crbug.com/pdfium/507
+ '-xfa/fxfa',
+]
diff --git a/xfa/fwl/cfwl_app.cpp b/xfa/fwl/cfwl_app.cpp
index c3a06e36d..250fcec33 100644
--- a/xfa/fwl/cfwl_app.cpp
+++ b/xfa/fwl/cfwl_app.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,17 +6,25 @@
#include "xfa/fwl/cfwl_app.h"
-#include "third_party/base/ptr_util.h"
+#include "v8/include/cppgc/allocation.h"
#include "xfa/fwl/cfwl_notedriver.h"
#include "xfa/fwl/cfwl_widget.h"
#include "xfa/fwl/cfwl_widgetmgr.h"
CFWL_App::CFWL_App(AdapterIface* pAdapter)
- : m_pAdapterNative(pAdapter),
- m_pWidgetMgr(
- pdfium::MakeUnique<CFWL_WidgetMgr>(pAdapter->GetWidgetMgrAdapter())),
- m_pNoteDriver(pdfium::MakeUnique<CFWL_NoteDriver>()) {
- ASSERT(m_pAdapterNative);
-}
+ : m_pAdapter(pAdapter),
+ m_pWidgetMgr(cppgc::MakeGarbageCollected<CFWL_WidgetMgr>(
+ pAdapter->GetHeap()->GetAllocationHandle(),
+ pAdapter->GetWidgetMgrAdapter(),
+ this)),
+ m_pNoteDriver(cppgc::MakeGarbageCollected<CFWL_NoteDriver>(
+ pAdapter->GetHeap()->GetAllocationHandle(),
+ this)) {}
CFWL_App::~CFWL_App() = default;
+
+void CFWL_App::Trace(cppgc::Visitor* visitor) const {
+ visitor->Trace(m_pAdapter);
+ visitor->Trace(m_pWidgetMgr);
+ visitor->Trace(m_pNoteDriver);
+}
diff --git a/xfa/fwl/cfwl_app.h b/xfa/fwl/cfwl_app.h
index a911ab2a1..b6a76fa96 100644
--- a/xfa/fwl/cfwl_app.h
+++ b/xfa/fwl/cfwl_app.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,45 +7,51 @@
#ifndef XFA_FWL_CFWL_APP_H_
#define XFA_FWL_CFWL_APP_H_
-#include <memory>
-
-#include "core/fxcrt/fx_string.h"
-#include "core/fxcrt/timerhandler_iface.h"
+#include "core/fxcrt/cfx_timer.h"
+#include "fxjs/gc/heap.h"
+#include "v8/include/cppgc/garbage-collected.h"
+#include "v8/include/cppgc/member.h"
+#include "v8/include/cppgc/visitor.h"
#include "xfa/fwl/cfwl_widgetmgr.h"
class CFWL_NoteDriver;
-class CFWL_WidgetMgr;
-
-enum FWL_KeyFlag {
- FWL_KEYFLAG_Ctrl = 1 << 0,
- FWL_KEYFLAG_Alt = 1 << 1,
- FWL_KEYFLAG_Shift = 1 << 2,
- FWL_KEYFLAG_Command = 1 << 3,
- FWL_KEYFLAG_LButton = 1 << 4,
- FWL_KEYFLAG_RButton = 1 << 5,
- FWL_KEYFLAG_MButton = 1 << 6
-};
+class IFWL_ThemeProvider;
-class CFWL_App {
+class CFWL_App final : public cppgc::GarbageCollected<CFWL_App> {
public:
- class AdapterIface {
+ class AdapterIface : public cppgc::GarbageCollectedMixin {
public:
virtual ~AdapterIface() = default;
virtual CFWL_WidgetMgr::AdapterIface* GetWidgetMgrAdapter() = 0;
- virtual TimerHandlerIface* GetTimerHandler() = 0;
+ virtual CFX_Timer::HandlerIface* GetTimerHandler() = 0;
+ virtual IFWL_ThemeProvider* GetThemeProvider() = 0;
+ virtual cppgc::Heap* GetHeap() = 0;
};
- explicit CFWL_App(AdapterIface* pAdapter);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_App();
- AdapterIface* GetAdapterNative() const { return m_pAdapterNative.Get(); }
- CFWL_WidgetMgr* GetWidgetMgr() const { return m_pWidgetMgr.get(); }
- CFWL_NoteDriver* GetNoteDriver() const { return m_pNoteDriver.get(); }
+ void Trace(cppgc::Visitor* visitor) const;
+
+ CFWL_WidgetMgr::AdapterIface* GetWidgetMgrAdapter() const {
+ return m_pAdapter->GetWidgetMgrAdapter();
+ }
+ CFX_Timer::HandlerIface* GetTimerHandler() const {
+ return m_pAdapter->GetTimerHandler();
+ }
+ IFWL_ThemeProvider* GetThemeProvider() const {
+ return m_pAdapter->GetThemeProvider();
+ }
+ cppgc::Heap* GetHeap() const { return m_pAdapter->GetHeap(); }
+ CFWL_WidgetMgr* GetWidgetMgr() const { return m_pWidgetMgr; }
+ CFWL_NoteDriver* GetNoteDriver() const { return m_pNoteDriver; }
private:
- UnownedPtr<AdapterIface> const m_pAdapterNative;
- std::unique_ptr<CFWL_WidgetMgr> m_pWidgetMgr;
- std::unique_ptr<CFWL_NoteDriver> m_pNoteDriver;
+ explicit CFWL_App(AdapterIface* pAdapter);
+
+ cppgc::Member<AdapterIface> const m_pAdapter;
+ cppgc::Member<CFWL_WidgetMgr> m_pWidgetMgr;
+ cppgc::Member<CFWL_NoteDriver> m_pNoteDriver;
};
#endif // XFA_FWL_CFWL_APP_H_
diff --git a/xfa/fwl/cfwl_barcode.cpp b/xfa/fwl/cfwl_barcode.cpp
index 008424d82..1802c7fce 100644
--- a/xfa/fwl/cfwl_barcode.cpp
+++ b/xfa/fwl/cfwl_barcode.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,18 +6,15 @@
#include "xfa/fwl/cfwl_barcode.h"
-#include <utility>
-
#include "fxbarcode/cfx_barcode.h"
-#include "third_party/base/ptr_util.h"
#include "xfa/fgas/font/cfgas_gefont.h"
#include "xfa/fwl/cfwl_notedriver.h"
#include "xfa/fwl/cfwl_themepart.h"
#include "xfa/fwl/ifwl_themeprovider.h"
#include "xfa/fwl/theme/cfwl_utils.h"
-CFWL_Barcode::CFWL_Barcode(const CFWL_App* app)
- : CFWL_Edit(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr) {}
+CFWL_Barcode::CFWL_Barcode(CFWL_App* app)
+ : CFWL_Edit(app, Properties(), nullptr) {}
CFWL_Barcode::~CFWL_Barcode() = default;
@@ -33,13 +30,12 @@ void CFWL_Barcode::Update() {
GenerateBarcodeImageCache();
}
-void CFWL_Barcode::DrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_Barcode::DrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
if (!pGraphics)
return;
- if (!m_pProperties->m_pThemeProvider)
- return;
- if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) {
+
+ if ((m_Properties.m_dwStates & FWL_STATE_WGT_Focused) == 0) {
GenerateBarcodeImageCache();
if (!m_pBarcodeEngine || m_eStatus != Status::kEncodeSuccess)
return;
@@ -49,7 +45,8 @@ void CFWL_Barcode::DrawWidget(CXFA_Graphics* pGraphics,
mt.f = GetRTClient().top;
mt.Concat(matrix);
- m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), &matrix);
+ // TODO(tsepez): Curious as to why |mt| is unused?
+ m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), matrix);
return;
}
CFWL_Edit::DrawWidget(pGraphics, matrix);
@@ -81,8 +78,8 @@ bool CFWL_Barcode::IsProtectedType() const {
return true;
BC_TYPE tEngineType = m_pBarcodeEngine->GetType();
- return tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 ||
- tEngineType == BC_DATAMATRIX;
+ return tEngineType == BC_TYPE::kQRCode || tEngineType == BC_TYPE::kPDF417 ||
+ tEngineType == BC_TYPE::kDataMatrix;
}
void CFWL_Barcode::OnProcessEvent(CFWL_Event* pEvent) {
@@ -94,58 +91,47 @@ void CFWL_Barcode::OnProcessEvent(CFWL_Event* pEvent) {
}
void CFWL_Barcode::SetCharEncoding(BC_CHAR_ENCODING encoding) {
- m_dwAttributeMask |= FWL_BCDATTRIBUTE_CHARENCODING;
m_eCharEncoding = encoding;
}
void CFWL_Barcode::SetModuleHeight(int32_t height) {
- m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEHEIGHT;
m_nModuleHeight = height;
}
void CFWL_Barcode::SetModuleWidth(int32_t width) {
- m_dwAttributeMask |= FWL_BCDATTRIBUTE_MODULEWIDTH;
m_nModuleWidth = width;
}
void CFWL_Barcode::SetDataLength(int32_t dataLength) {
- m_dwAttributeMask |= FWL_BCDATTRIBUTE_DATALENGTH;
m_nDataLength = dataLength;
SetLimit(dataLength);
}
void CFWL_Barcode::SetCalChecksum(bool calChecksum) {
- m_dwAttributeMask |= FWL_BCDATTRIBUTE_CALCHECKSUM;
m_bCalChecksum = calChecksum;
}
void CFWL_Barcode::SetPrintChecksum(bool printChecksum) {
- m_dwAttributeMask |= FWL_BCDATTRIBUTE_PRINTCHECKSUM;
m_bPrintChecksum = printChecksum;
}
void CFWL_Barcode::SetTextLocation(BC_TEXT_LOC location) {
- m_dwAttributeMask |= FWL_BCDATTRIBUTE_TEXTLOCATION;
m_eTextLocation = location;
}
void CFWL_Barcode::SetWideNarrowRatio(int8_t ratio) {
- m_dwAttributeMask |= FWL_BCDATTRIBUTE_WIDENARROWRATIO;
m_nWideNarrowRatio = ratio;
}
void CFWL_Barcode::SetStartChar(char startChar) {
- m_dwAttributeMask |= FWL_BCDATTRIBUTE_STARTCHAR;
m_cStartChar = startChar;
}
void CFWL_Barcode::SetEndChar(char endChar) {
- m_dwAttributeMask |= FWL_BCDATTRIBUTE_ENDCHAR;
m_cEndChar = endChar;
}
void CFWL_Barcode::SetErrorCorrectionLevel(int32_t ecLevel) {
- m_dwAttributeMask |= FWL_BCDATTRIBUTE_ECLEVEL;
m_nECLevel = ecLevel;
}
@@ -158,44 +144,38 @@ void CFWL_Barcode::GenerateBarcodeImageCache() {
if (!m_pBarcodeEngine)
return;
- IFWL_ThemeProvider* pTheme = GetAvailableTheme();
- if (pTheme) {
- CFWL_ThemePart part;
- part.m_pWidget = this;
- if (RetainPtr<CFGAS_GEFont> pFont = pTheme->GetFont(part)) {
- if (CFX_Font* pCXFont = pFont->GetDevFont())
- m_pBarcodeEngine->SetFont(pCXFont);
- }
- m_pBarcodeEngine->SetFontSize(pTheme->GetFontSize(part));
- m_pBarcodeEngine->SetFontColor(pTheme->GetTextColor(part));
- } else {
- m_pBarcodeEngine->SetFontSize(FWLTHEME_CAPACITY_FontSize);
+ IFWL_ThemeProvider* pTheme = GetThemeProvider();
+ CFWL_ThemePart part(CFWL_ThemePart::Part::kNone, this);
+ if (RetainPtr<CFGAS_GEFont> pFont = pTheme->GetFont(part)) {
+ if (CFX_Font* pCXFont = pFont->GetDevFont())
+ m_pBarcodeEngine->SetFont(pCXFont);
}
-
+ m_pBarcodeEngine->SetFontSize(pTheme->GetFontSize(part));
+ m_pBarcodeEngine->SetFontColor(pTheme->GetTextColor(part));
m_pBarcodeEngine->SetHeight(int32_t(GetRTClient().height));
m_pBarcodeEngine->SetWidth(int32_t(GetRTClient().width));
- if (m_dwAttributeMask & FWL_BCDATTRIBUTE_CHARENCODING)
- m_pBarcodeEngine->SetCharEncoding(m_eCharEncoding);
- if (m_dwAttributeMask & FWL_BCDATTRIBUTE_MODULEHEIGHT)
- m_pBarcodeEngine->SetModuleHeight(m_nModuleHeight);
- if (m_dwAttributeMask & FWL_BCDATTRIBUTE_MODULEWIDTH)
- m_pBarcodeEngine->SetModuleWidth(m_nModuleWidth);
- if (m_dwAttributeMask & FWL_BCDATTRIBUTE_DATALENGTH)
- m_pBarcodeEngine->SetDataLength(m_nDataLength);
- if (m_dwAttributeMask & FWL_BCDATTRIBUTE_CALCHECKSUM)
- m_pBarcodeEngine->SetCalChecksum(m_bCalChecksum);
- if (m_dwAttributeMask & FWL_BCDATTRIBUTE_PRINTCHECKSUM)
- m_pBarcodeEngine->SetPrintChecksum(m_bPrintChecksum);
- if (m_dwAttributeMask & FWL_BCDATTRIBUTE_TEXTLOCATION)
- m_pBarcodeEngine->SetTextLocation(m_eTextLocation);
- if (m_dwAttributeMask & FWL_BCDATTRIBUTE_WIDENARROWRATIO)
- m_pBarcodeEngine->SetWideNarrowRatio(m_nWideNarrowRatio);
- if (m_dwAttributeMask & FWL_BCDATTRIBUTE_STARTCHAR)
- m_pBarcodeEngine->SetStartChar(m_cStartChar);
- if (m_dwAttributeMask & FWL_BCDATTRIBUTE_ENDCHAR)
- m_pBarcodeEngine->SetEndChar(m_cEndChar);
- if (m_dwAttributeMask & FWL_BCDATTRIBUTE_ECLEVEL)
- m_pBarcodeEngine->SetErrorCorrectionLevel(m_nECLevel);
+ if (m_eCharEncoding.has_value())
+ m_pBarcodeEngine->SetCharEncoding(m_eCharEncoding.value());
+ if (m_nModuleHeight.has_value())
+ m_pBarcodeEngine->SetModuleHeight(m_nModuleHeight.value());
+ if (m_nModuleWidth.has_value())
+ m_pBarcodeEngine->SetModuleWidth(m_nModuleWidth.value());
+ if (m_nDataLength.has_value())
+ m_pBarcodeEngine->SetDataLength(m_nDataLength.value());
+ if (m_bCalChecksum.has_value())
+ m_pBarcodeEngine->SetCalChecksum(m_bCalChecksum.value());
+ if (m_bPrintChecksum.has_value())
+ m_pBarcodeEngine->SetPrintChecksum(m_bPrintChecksum.value());
+ if (m_eTextLocation.has_value())
+ m_pBarcodeEngine->SetTextLocation(m_eTextLocation.value());
+ if (m_nWideNarrowRatio.has_value())
+ m_pBarcodeEngine->SetWideNarrowRatio(m_nWideNarrowRatio.value());
+ if (m_cStartChar.has_value())
+ m_pBarcodeEngine->SetStartChar(m_cStartChar.value());
+ if (m_cEndChar.has_value())
+ m_pBarcodeEngine->SetEndChar(m_cEndChar.value());
+ if (m_nECLevel.has_value())
+ m_pBarcodeEngine->SetErrorCorrectionLevel(m_nECLevel.value());
m_eStatus = m_pBarcodeEngine->Encode(GetText().AsStringView())
? Status::kEncodeSuccess
@@ -203,7 +183,7 @@ void CFWL_Barcode::GenerateBarcodeImageCache() {
}
void CFWL_Barcode::CreateBarcodeEngine() {
- if (m_pBarcodeEngine || m_type == BC_UNKNOWN)
+ if (m_pBarcodeEngine || m_type == BC_TYPE::kUnknown)
return;
m_pBarcodeEngine = CFX_Barcode::Create(m_type);
diff --git a/xfa/fwl/cfwl_barcode.h b/xfa/fwl/cfwl_barcode.h
index d2cd716d4..45da19c25 100644
--- a/xfa/fwl/cfwl_barcode.h
+++ b/xfa/fwl/cfwl_barcode.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,37 +7,26 @@
#ifndef XFA_FWL_CFWL_BARCODE_H_
#define XFA_FWL_CFWL_BARCODE_H_
+#include <stdint.h>
+
#include <memory>
#include "fxbarcode/BC_Library.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
#include "xfa/fwl/cfwl_edit.h"
class CFX_Barcode;
-enum FWL_BCDAttribute {
- FWL_BCDATTRIBUTE_NONE = 0,
- FWL_BCDATTRIBUTE_CHARENCODING = 1 << 0,
- FWL_BCDATTRIBUTE_MODULEHEIGHT = 1 << 1,
- FWL_BCDATTRIBUTE_MODULEWIDTH = 1 << 2,
- FWL_BCDATTRIBUTE_DATALENGTH = 1 << 3,
- FWL_BCDATTRIBUTE_CALCHECKSUM = 1 << 4,
- FWL_BCDATTRIBUTE_PRINTCHECKSUM = 1 << 5,
- FWL_BCDATTRIBUTE_TEXTLOCATION = 1 << 6,
- FWL_BCDATTRIBUTE_WIDENARROWRATIO = 1 << 7,
- FWL_BCDATTRIBUTE_STARTCHAR = 1 << 8,
- FWL_BCDATTRIBUTE_ENDCHAR = 1 << 9,
- FWL_BCDATTRIBUTE_ECLEVEL = 1 << 10,
-};
-
class CFWL_Barcode final : public CFWL_Edit {
public:
- explicit CFWL_Barcode(const CFWL_App* pApp);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_Barcode() override;
// CFWL_Widget
FWL_Type GetClassID() const override;
void Update() override;
- void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
+ void DrawWidget(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& matrix) override;
void OnProcessEvent(CFWL_Event* pEvent) override;
// CFWL_Edit
@@ -66,23 +55,24 @@ class CFWL_Barcode final : public CFWL_Edit {
kEncodeSuccess,
};
+ explicit CFWL_Barcode(CFWL_App* pApp);
+
void GenerateBarcodeImageCache();
void CreateBarcodeEngine();
- BC_TYPE m_type = BC_UNKNOWN;
- BC_CHAR_ENCODING m_eCharEncoding = CHAR_ENCODING_UTF8;
- BC_TEXT_LOC m_eTextLocation = BC_TEXT_LOC_NONE;
+ BC_TYPE m_type = BC_TYPE::kUnknown;
Status m_eStatus = Status::kNormal;
- bool m_bCalChecksum = false;
- bool m_bPrintChecksum = false;
- char m_cStartChar = 0;
- char m_cEndChar = 0;
- int8_t m_nWideNarrowRatio = 1;
- int32_t m_nModuleHeight = -1;
- int32_t m_nModuleWidth = -1;
- int32_t m_nDataLength = 0;
- int32_t m_nECLevel = 0;
- uint32_t m_dwAttributeMask = 0;
+ absl::optional<BC_TEXT_LOC> m_eTextLocation;
+ absl::optional<BC_CHAR_ENCODING> m_eCharEncoding;
+ absl::optional<bool> m_bCalChecksum;
+ absl::optional<bool> m_bPrintChecksum;
+ absl::optional<char> m_cStartChar;
+ absl::optional<char> m_cEndChar;
+ absl::optional<int8_t> m_nWideNarrowRatio;
+ absl::optional<int32_t> m_nModuleHeight;
+ absl::optional<int32_t> m_nModuleWidth;
+ absl::optional<int32_t> m_nDataLength;
+ absl::optional<int32_t> m_nECLevel;
std::unique_ptr<CFX_Barcode> m_pBarcodeEngine;
};
diff --git a/xfa/fwl/cfwl_caret.cpp b/xfa/fwl/cfwl_caret.cpp
index ef5bdcc54..a573cae56 100644
--- a/xfa/fwl/cfwl_caret.cpp
+++ b/xfa/fwl/cfwl_caret.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,11 +8,9 @@
#include <utility>
-#include "third_party/base/ptr_util.h"
#include "xfa/fwl/cfwl_app.h"
#include "xfa/fwl/cfwl_notedriver.h"
#include "xfa/fwl/cfwl_themebackground.h"
-#include "xfa/fwl/cfwl_widgetproperties.h"
#include "xfa/fwl/ifwl_themeprovider.h"
namespace {
@@ -23,10 +21,10 @@ constexpr int kStateHighlight = (1 << 0);
} // namespace
-CFWL_Caret::CFWL_Caret(const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
+CFWL_Caret::CFWL_Caret(CFWL_App* app,
+ const Properties& properties,
CFWL_Widget* pOuter)
- : CFWL_Widget(app, std::move(properties), pOuter) {
+ : CFWL_Widget(app, properties, pOuter) {
SetStates(kStateHighlight);
}
@@ -38,51 +36,42 @@ FWL_Type CFWL_Caret::GetClassID() const {
void CFWL_Caret::Update() {}
-void CFWL_Caret::DrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_Caret::DrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
if (!pGraphics)
return;
- if (!m_pProperties->m_pThemeProvider)
- m_pProperties->m_pThemeProvider = GetAvailableTheme();
- if (!m_pProperties->m_pThemeProvider)
- return;
- DrawCaretBK(pGraphics, m_pProperties->m_pThemeProvider.Get(), &matrix);
+ DrawCaretBK(pGraphics, matrix);
}
void CFWL_Caret::ShowCaret() {
- m_pTimer = pdfium::MakeUnique<CFX_Timer>(
- GetOwnerApp()->GetAdapterNative()->GetTimerHandler(), this,
- kBlinkPeriodMs);
- RemoveStates(FWL_WGTSTATE_Invisible);
+ m_pTimer = std::make_unique<CFX_Timer>(GetFWLApp()->GetTimerHandler(), this,
+ kBlinkPeriodMs);
+ RemoveStates(FWL_STATE_WGT_Invisible);
SetStates(kStateHighlight);
}
void CFWL_Caret::HideCaret() {
m_pTimer.reset();
- SetStates(FWL_WGTSTATE_Invisible);
+ SetStates(FWL_STATE_WGT_Invisible);
}
-void CFWL_Caret::DrawCaretBK(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- if (!(m_pProperties->m_dwStates & kStateHighlight))
+void CFWL_Caret::DrawCaretBK(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ if (!(m_Properties.m_dwStates & kStateHighlight))
return;
- CFWL_ThemeBackground param;
- param.m_pWidget = this;
- param.m_pGraphics = pGraphics;
- param.m_rtPart = CFX_RectF(0, 0, GetWidgetRect().Size());
- param.m_iPart = CFWL_Part::Background;
- param.m_dwStates = CFWL_PartState_HightLight;
- if (pMatrix)
- param.m_matrix.Concat(*pMatrix);
- pTheme->DrawBackground(param);
+ CFWL_ThemeBackground param(CFWL_ThemePart::Part::kBackground, this,
+ pGraphics);
+ param.m_PartRect = CFX_RectF(0, 0, GetWidgetRect().Size());
+ param.m_dwStates = CFWL_PartState::kHightLight;
+ param.m_matrix = mtMatrix;
+ GetThemeProvider()->DrawBackground(param);
}
void CFWL_Caret::OnProcessMessage(CFWL_Message* pMessage) {}
-void CFWL_Caret::OnDrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_Caret::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
DrawWidget(pGraphics, matrix);
}
diff --git a/xfa/fwl/cfwl_caret.h b/xfa/fwl/cfwl_caret.h
index 7f5dfdff2..4c1b39536 100644
--- a/xfa/fwl/cfwl_caret.h
+++ b/xfa/fwl/cfwl_caret.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,24 +10,20 @@
#include <memory>
#include "core/fxcrt/cfx_timer.h"
+#include "xfa/fgas/graphics/cfgas_gecolor.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fxgraphics/cxfa_gecolor.h"
-
-class CFWL_WidgetProperties;
-class CFWL_Widget;
class CFWL_Caret final : public CFWL_Widget, public CFX_Timer::CallbackIface {
public:
- CFWL_Caret(const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_Caret() override;
// CFWL_Widget:
FWL_Type GetClassID() const override;
- void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
+ void DrawWidget(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& matrix) override;
void OnProcessMessage(CFWL_Message* pMessage) override;
- void OnDrawWidget(CXFA_Graphics* pGraphics,
+ void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) override;
void Update() override;
@@ -38,9 +34,9 @@ class CFWL_Caret final : public CFWL_Widget, public CFX_Timer::CallbackIface {
void HideCaret();
private:
- void DrawCaretBK(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
+ CFWL_Caret(CFWL_App* app, const Properties& properties, CFWL_Widget* pOuter);
+
+ void DrawCaretBK(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
std::unique_ptr<CFX_Timer> m_pTimer;
};
diff --git a/xfa/fwl/cfwl_checkbox.cpp b/xfa/fwl/cfwl_checkbox.cpp
index 1342554cd..ee78201e0 100644
--- a/xfa/fwl/cfwl_checkbox.cpp
+++ b/xfa/fwl/cfwl_checkbox.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,11 +7,8 @@
#include "xfa/fwl/cfwl_checkbox.h"
#include <algorithm>
-#include <memory>
#include <utility>
-#include <vector>
-#include "third_party/base/ptr_util.h"
#include "xfa/fde/cfde_textout.h"
#include "xfa/fwl/cfwl_app.h"
#include "xfa/fwl/cfwl_event.h"
@@ -30,12 +27,12 @@ const int kCaptionMargin = 5;
} // namespace
-CFWL_CheckBox::CFWL_CheckBox(const CFWL_App* app)
- : CFWL_Widget(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr) {
+CFWL_CheckBox::CFWL_CheckBox(CFWL_App* app)
+ : CFWL_Widget(app, Properties(), nullptr) {
m_TTOStyles.single_line_ = true;
}
-CFWL_CheckBox::~CFWL_CheckBox() {}
+CFWL_CheckBox::~CFWL_CheckBox() = default;
FWL_Type CFWL_CheckBox::GetClassID() const {
return FWL_Type::CheckBox;
@@ -48,50 +45,43 @@ void CFWL_CheckBox::SetBoxSize(float fHeight) {
void CFWL_CheckBox::Update() {
if (IsLocked())
return;
- if (!m_pProperties->m_pThemeProvider)
- m_pProperties->m_pThemeProvider = GetAvailableTheme();
UpdateTextOutStyles();
Layout();
}
-void CFWL_CheckBox::DrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_CheckBox::DrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
if (!pGraphics)
return;
- IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get();
- if (!pTheme)
- return;
-
if (HasBorder())
- DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
-
- int32_t dwStates = GetPartStates();
+ DrawBorder(pGraphics, CFWL_ThemePart::Part::kBorder, matrix);
- CFWL_ThemeBackground param;
- param.m_pWidget = this;
- param.m_iPart = CFWL_Part::Background;
+ Mask<CFWL_PartState> dwStates = GetPartStates();
+ IFWL_ThemeProvider* pTheme = GetThemeProvider();
+ CFWL_ThemeBackground param(CFWL_ThemePart::Part::kBackground, this,
+ pGraphics);
param.m_dwStates = dwStates;
- param.m_pGraphics = pGraphics;
- param.m_matrix.Concat(matrix);
- param.m_rtPart = m_rtClient;
- if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)
-
- param.m_pRtData = &m_rtFocus;
+ param.m_matrix = matrix;
+ param.m_PartRect = m_ClientRect;
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Focused)
+ param.m_pRtData = &m_FocusRect;
pTheme->DrawBackground(param);
- param.m_iPart = CFWL_Part::CheckBox;
- param.m_rtPart = m_rtBox;
- pTheme->DrawBackground(param);
+ CFWL_ThemeBackground checkParam(CFWL_ThemePart::Part::kCheckBox, this,
+ pGraphics);
+ checkParam.m_dwStates = dwStates;
+ checkParam.m_matrix = matrix;
+ checkParam.m_PartRect = m_BoxRect;
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Focused)
+ checkParam.m_pRtData = &m_FocusRect;
+ pTheme->DrawBackground(checkParam);
- CFWL_ThemeText textParam;
- textParam.m_pWidget = this;
- textParam.m_iPart = CFWL_Part::Caption;
+ CFWL_ThemeText textParam(CFWL_ThemePart::Part::kCaption, this, pGraphics);
textParam.m_dwStates = dwStates;
- textParam.m_pGraphics = pGraphics;
- textParam.m_matrix.Concat(matrix);
- textParam.m_rtPart = m_rtCaption;
+ textParam.m_matrix = matrix;
+ textParam.m_PartRect = m_CaptionRect;
textParam.m_wsText = L"Check box";
textParam.m_dwTTOStyles = m_TTOStyles;
textParam.m_iTTOAlign = m_iTTOAlign;
@@ -99,63 +89,60 @@ void CFWL_CheckBox::DrawWidget(CXFA_Graphics* pGraphics,
}
void CFWL_CheckBox::SetCheckState(int32_t iCheck) {
- m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask;
+ m_Properties.m_dwStates &= ~FWL_STATE_CKB_CheckMask;
switch (iCheck) {
case 1:
- m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked;
+ m_Properties.m_dwStates |= FWL_STATE_CKB_Checked;
break;
case 2:
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State)
- m_pProperties->m_dwStates |= FWL_STATE_CKB_Neutral;
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_CKB_3State)
+ m_Properties.m_dwStates |= FWL_STATE_CKB_Neutral;
break;
default:
break;
}
- RepaintRect(m_rtClient);
+ RepaintRect(m_ClientRect);
}
void CFWL_CheckBox::Layout() {
- m_pProperties->m_rtWidget.width =
- FXSYS_roundf(m_pProperties->m_rtWidget.width);
- m_pProperties->m_rtWidget.height =
- FXSYS_roundf(m_pProperties->m_rtWidget.height);
- m_rtClient = GetClientRect();
-
- float fTextLeft = m_rtClient.left + m_fBoxHeight;
- m_rtBox = CFX_RectF(m_rtClient.TopLeft(), m_fBoxHeight, m_fBoxHeight);
- m_rtCaption = CFX_RectF(fTextLeft, m_rtClient.top,
- m_rtClient.right() - fTextLeft, m_rtClient.height);
- m_rtCaption.Inflate(-kCaptionMargin, -kCaptionMargin);
-
- CFX_RectF rtFocus = m_rtCaption;
- CalcTextRect(L"Check box", m_pProperties->m_pThemeProvider.Get(), m_TTOStyles,
- m_iTTOAlign, &rtFocus);
-
- m_rtFocus = CFX_RectF(m_rtCaption.TopLeft(),
- std::max(m_rtCaption.width, rtFocus.width),
- std::min(m_rtCaption.height, rtFocus.height));
- m_rtFocus.Inflate(1, 1);
+ m_WidgetRect.width = FXSYS_roundf(m_WidgetRect.width);
+ m_WidgetRect.height = FXSYS_roundf(m_WidgetRect.height);
+ m_ClientRect = GetClientRect();
+
+ float fTextLeft = m_ClientRect.left + m_fBoxHeight;
+ m_BoxRect = CFX_RectF(m_ClientRect.TopLeft(), m_fBoxHeight, m_fBoxHeight);
+ m_CaptionRect =
+ CFX_RectF(fTextLeft, m_ClientRect.top, m_ClientRect.right() - fTextLeft,
+ m_ClientRect.height);
+ m_CaptionRect.Inflate(-kCaptionMargin, -kCaptionMargin);
+
+ CFX_RectF rtFocus = m_CaptionRect;
+ CalcTextRect(L"Check box", m_TTOStyles, m_iTTOAlign, &rtFocus);
+ m_FocusRect = CFX_RectF(m_CaptionRect.TopLeft(),
+ std::max(m_CaptionRect.width, rtFocus.width),
+ std::min(m_CaptionRect.height, rtFocus.height));
+ m_FocusRect.Inflate(1, 1);
}
-uint32_t CFWL_CheckBox::GetPartStates() const {
- int32_t dwStates = CFWL_PartState_Normal;
- if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) ==
+Mask<CFWL_PartState> CFWL_CheckBox::GetPartStates() const {
+ Mask<CFWL_PartState> dwStates = CFWL_PartState::kNormal;
+ if ((m_Properties.m_dwStates & FWL_STATE_CKB_CheckMask) ==
FWL_STATE_CKB_Neutral) {
- dwStates = CFWL_PartState_Neutral;
- } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) ==
+ dwStates = CFWL_PartState::kNeutral;
+ } else if ((m_Properties.m_dwStates & FWL_STATE_CKB_CheckMask) ==
FWL_STATE_CKB_Checked) {
- dwStates = CFWL_PartState_Checked;
+ dwStates = CFWL_PartState::kChecked;
}
- if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
- dwStates |= CFWL_PartState_Disabled;
- else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered)
- dwStates |= CFWL_PartState_Hovered;
- else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed)
- dwStates |= CFWL_PartState_Pressed;
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)
+ dwStates |= CFWL_PartState::kDisabled;
+ else if (m_Properties.m_dwStates & FWL_STATE_CKB_Hovered)
+ dwStates |= CFWL_PartState::kHovered;
+ else if (m_Properties.m_dwStates & FWL_STATE_CKB_Pressed)
+ dwStates |= CFWL_PartState::kPressed;
else
- dwStates |= CFWL_PartState_Normal;
- if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)
- dwStates |= CFWL_PartState_Focused;
+ dwStates |= CFWL_PartState::kNormal;
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Focused)
+ dwStates |= CFWL_PartState::kFocused;
return dwStates;
}
@@ -166,31 +153,31 @@ void CFWL_CheckBox::UpdateTextOutStyles() {
}
void CFWL_CheckBox::NextStates() {
- uint32_t dwFirststate = m_pProperties->m_dwStates;
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_RadioButton) {
- if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) ==
+ uint32_t dwFirststate = m_Properties.m_dwStates;
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_CKB_RadioButton) {
+ if ((m_Properties.m_dwStates & FWL_STATE_CKB_CheckMask) ==
FWL_STATE_CKB_Unchecked) {
- m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked;
+ m_Properties.m_dwStates |= FWL_STATE_CKB_Checked;
}
} else {
- if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) ==
+ if ((m_Properties.m_dwStates & FWL_STATE_CKB_CheckMask) ==
FWL_STATE_CKB_Neutral) {
- m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask;
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State)
- m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked;
- } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) ==
+ m_Properties.m_dwStates &= ~FWL_STATE_CKB_CheckMask;
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_CKB_3State)
+ m_Properties.m_dwStates |= FWL_STATE_CKB_Checked;
+ } else if ((m_Properties.m_dwStates & FWL_STATE_CKB_CheckMask) ==
FWL_STATE_CKB_Checked) {
- m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask;
+ m_Properties.m_dwStates &= ~FWL_STATE_CKB_CheckMask;
} else {
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State)
- m_pProperties->m_dwStates |= FWL_STATE_CKB_Neutral;
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_CKB_3State)
+ m_Properties.m_dwStates |= FWL_STATE_CKB_Neutral;
else
- m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked;
+ m_Properties.m_dwStates |= FWL_STATE_CKB_Checked;
}
}
- RepaintRect(m_rtClient);
- if (dwFirststate == m_pProperties->m_dwStates)
+ RepaintRect(m_ClientRect);
+ if (dwFirststate == m_Properties.m_dwStates)
return;
CFWL_Event wmCheckBoxState(CFWL_Event::Type::CheckStateChanged, this);
@@ -198,29 +185,26 @@ void CFWL_CheckBox::NextStates() {
}
void CFWL_CheckBox::OnProcessMessage(CFWL_Message* pMessage) {
- if (!pMessage)
- return;
-
switch (pMessage->GetType()) {
- case CFWL_Message::Type::SetFocus:
- OnFocusChanged(true);
+ case CFWL_Message::Type::kSetFocus:
+ OnFocusGained();
break;
- case CFWL_Message::Type::KillFocus:
- OnFocusChanged(false);
+ case CFWL_Message::Type::kKillFocus:
+ OnFocusLost();
break;
- case CFWL_Message::Type::Mouse: {
+ case CFWL_Message::Type::kMouse: {
CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
switch (pMsg->m_dwCmd) {
- case FWL_MouseCommand::LeftButtonDown:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonDown:
OnLButtonDown();
break;
- case FWL_MouseCommand::LeftButtonUp:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonUp:
OnLButtonUp(pMsg);
break;
- case FWL_MouseCommand::Move:
+ case CFWL_MessageMouse::MouseCommand::kMove:
OnMouseMove(pMsg);
break;
- case FWL_MouseCommand::Leave:
+ case CFWL_MessageMouse::MouseCommand::kLeave:
OnMouseLeave();
break;
default:
@@ -228,9 +212,9 @@ void CFWL_CheckBox::OnProcessMessage(CFWL_Message* pMessage) {
}
break;
}
- case CFWL_Message::Type::Key: {
+ case CFWL_Message::Type::kKey: {
CFWL_MessageKey* pKey = static_cast<CFWL_MessageKey*>(pMessage);
- if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown)
+ if (pKey->m_dwCmd == CFWL_MessageKey::KeyCommand::kKeyDown)
OnKeyDown(pKey);
break;
}
@@ -242,28 +226,29 @@ void CFWL_CheckBox::OnProcessMessage(CFWL_Message* pMessage) {
CFWL_Widget::OnProcessMessage(pMessage);
}
-void CFWL_CheckBox::OnDrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_CheckBox::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
DrawWidget(pGraphics, matrix);
}
-void CFWL_CheckBox::OnFocusChanged(bool bSet) {
- if (bSet)
- m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
- else
- m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
+void CFWL_CheckBox::OnFocusGained() {
+ m_Properties.m_dwStates |= FWL_STATE_WGT_Focused;
+ RepaintRect(m_ClientRect);
+}
- RepaintRect(m_rtClient);
+void CFWL_CheckBox::OnFocusLost() {
+ m_Properties.m_dwStates &= ~FWL_STATE_WGT_Focused;
+ RepaintRect(m_ClientRect);
}
void CFWL_CheckBox::OnLButtonDown() {
- if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)
return;
m_bBtnDown = true;
- m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered;
- m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed;
- RepaintRect(m_rtClient);
+ m_Properties.m_dwStates &= ~FWL_STATE_CKB_Hovered;
+ m_Properties.m_dwStates |= FWL_STATE_CKB_Pressed;
+ RepaintRect(m_ClientRect);
}
void CFWL_CheckBox::OnLButtonUp(CFWL_MessageMouse* pMsg) {
@@ -271,65 +256,65 @@ void CFWL_CheckBox::OnLButtonUp(CFWL_MessageMouse* pMsg) {
return;
m_bBtnDown = false;
- if (!m_rtClient.Contains(pMsg->m_pos))
+ if (!m_ClientRect.Contains(pMsg->m_pos))
return;
- m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered;
- m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed;
+ m_Properties.m_dwStates |= FWL_STATE_CKB_Hovered;
+ m_Properties.m_dwStates &= ~FWL_STATE_CKB_Pressed;
NextStates();
}
void CFWL_CheckBox::OnMouseMove(CFWL_MessageMouse* pMsg) {
- if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)
return;
bool bRepaint = false;
if (m_bBtnDown) {
- if (m_rtClient.Contains(pMsg->m_pos)) {
- if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) == 0) {
+ if (m_ClientRect.Contains(pMsg->m_pos)) {
+ if ((m_Properties.m_dwStates & FWL_STATE_CKB_Pressed) == 0) {
bRepaint = true;
- m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed;
+ m_Properties.m_dwStates |= FWL_STATE_CKB_Pressed;
}
- if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered)) {
+ if ((m_Properties.m_dwStates & FWL_STATE_CKB_Hovered)) {
bRepaint = true;
- m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered;
+ m_Properties.m_dwStates &= ~FWL_STATE_CKB_Hovered;
}
} else {
- if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) {
+ if (m_Properties.m_dwStates & FWL_STATE_CKB_Pressed) {
bRepaint = true;
- m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed;
+ m_Properties.m_dwStates &= ~FWL_STATE_CKB_Pressed;
}
- if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) {
+ if ((m_Properties.m_dwStates & FWL_STATE_CKB_Hovered) == 0) {
bRepaint = true;
- m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered;
+ m_Properties.m_dwStates |= FWL_STATE_CKB_Hovered;
}
}
} else {
- if (m_rtClient.Contains(pMsg->m_pos)) {
- if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) {
+ if (m_ClientRect.Contains(pMsg->m_pos)) {
+ if ((m_Properties.m_dwStates & FWL_STATE_CKB_Hovered) == 0) {
bRepaint = true;
- m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered;
+ m_Properties.m_dwStates |= FWL_STATE_CKB_Hovered;
}
}
}
if (bRepaint)
- RepaintRect(m_rtBox);
+ RepaintRect(m_BoxRect);
}
void CFWL_CheckBox::OnMouseLeave() {
if (m_bBtnDown)
- m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered;
+ m_Properties.m_dwStates |= FWL_STATE_CKB_Hovered;
else
- m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered;
+ m_Properties.m_dwStates &= ~FWL_STATE_CKB_Hovered;
- RepaintRect(m_rtBox);
+ RepaintRect(m_BoxRect);
}
void CFWL_CheckBox::OnKeyDown(CFWL_MessageKey* pMsg) {
- if (pMsg->m_dwKeyCode == XFA_FWL_VKEY_Tab)
+ if (pMsg->m_dwKeyCodeOrChar == XFA_FWL_VKEY_Tab)
return;
- if (pMsg->m_dwKeyCode == XFA_FWL_VKEY_Return ||
- pMsg->m_dwKeyCode == XFA_FWL_VKEY_Space) {
+ if (pMsg->m_dwKeyCodeOrChar == XFA_FWL_VKEY_Return ||
+ pMsg->m_dwKeyCodeOrChar == XFA_FWL_VKEY_Space) {
NextStates();
}
}
diff --git a/xfa/fwl/cfwl_checkbox.h b/xfa/fwl/cfwl_checkbox.h
index 0fa023638..9ab1cb811 100644
--- a/xfa/fwl/cfwl_checkbox.h
+++ b/xfa/fwl/cfwl_checkbox.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,7 +9,6 @@
#include "xfa/fwl/cfwl_event.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fwl/cfwl_widgetproperties.h"
#define FWL_STYLEEXT_CKB_3State (1L << 6)
#define FWL_STYLEEXT_CKB_RadioButton (1L << 7)
@@ -20,50 +19,53 @@
#define FWL_STYLEEXT_CKB_SignShapeSquare (4L << 10)
#define FWL_STYLEEXT_CKB_SignShapeStar (5L << 10)
#define FWL_STYLEEXT_CKB_SignShapeMask (7L << 10)
-#define FWL_STATE_CKB_Hovered (1 << FWL_WGTSTATE_MAX)
-#define FWL_STATE_CKB_Pressed (1 << (FWL_WGTSTATE_MAX + 1))
+#define FWL_STATE_CKB_Hovered (1 << FWL_STATE_WGT_MAX)
+#define FWL_STATE_CKB_Pressed (1 << (FWL_STATE_WGT_MAX + 1))
#define FWL_STATE_CKB_Unchecked 0
-#define FWL_STATE_CKB_Checked (1 << (FWL_WGTSTATE_MAX + 2))
-#define FWL_STATE_CKB_Neutral (2 << (FWL_WGTSTATE_MAX + 2))
-#define FWL_STATE_CKB_CheckMask (3L << (FWL_WGTSTATE_MAX + 2))
+#define FWL_STATE_CKB_Checked (1 << (FWL_STATE_WGT_MAX + 2))
+#define FWL_STATE_CKB_Neutral (2 << (FWL_STATE_WGT_MAX + 2))
+#define FWL_STATE_CKB_CheckMask (3L << (FWL_STATE_WGT_MAX + 2))
+class CFWL_MessageKey;
class CFWL_MessageMouse;
-class CFWL_WidgetProperties;
-class CFWL_Widget;
class CFWL_CheckBox final : public CFWL_Widget {
public:
- explicit CFWL_CheckBox(const CFWL_App* pApp);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_CheckBox() override;
// CFWL_Widget
FWL_Type GetClassID() const override;
void Update() override;
- void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
+ void DrawWidget(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& matrix) override;
void OnProcessMessage(CFWL_Message* pMessage) override;
- void OnDrawWidget(CXFA_Graphics* pGraphics,
+ void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) override;
void SetBoxSize(float fHeight);
private:
+ explicit CFWL_CheckBox(CFWL_App* pApp);
+
void SetCheckState(int32_t iCheck);
void Layout();
- uint32_t GetPartStates() const;
+ Mask<CFWL_PartState> GetPartStates() const;
void UpdateTextOutStyles();
void NextStates();
- void OnFocusChanged(bool bSet);
+ void OnFocusGained();
+ void OnFocusLost();
void OnLButtonDown();
void OnLButtonUp(CFWL_MessageMouse* pMsg);
void OnMouseMove(CFWL_MessageMouse* pMsg);
void OnMouseLeave();
void OnKeyDown(CFWL_MessageKey* pMsg);
- CFX_RectF m_rtClient;
- CFX_RectF m_rtBox;
- CFX_RectF m_rtCaption;
- CFX_RectF m_rtFocus;
+ CFX_RectF m_ClientRect;
+ CFX_RectF m_BoxRect;
+ CFX_RectF m_CaptionRect;
+ CFX_RectF m_FocusRect;
FDE_TextStyle m_TTOStyles;
FDE_TextAlignment m_iTTOAlign = FDE_TextAlignment::kCenter;
bool m_bBtnDown = false;
diff --git a/xfa/fwl/cfwl_combobox.cpp b/xfa/fwl/cfwl_combobox.cpp
index 9c5edf4f3..7653b83b3 100644
--- a/xfa/fwl/cfwl_combobox.cpp
+++ b/xfa/fwl/cfwl_combobox.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,11 +6,7 @@
#include "xfa/fwl/cfwl_combobox.h"
-#include <algorithm>
-#include <memory>
-#include <utility>
-
-#include "third_party/base/ptr_util.h"
+#include "v8/include/cppgc/visitor.h"
#include "xfa/fde/cfde_texteditengine.h"
#include "xfa/fde/cfde_textout.h"
#include "xfa/fwl/cfwl_app.h"
@@ -29,14 +25,28 @@
#include "xfa/fwl/fwl_widgetdef.h"
#include "xfa/fwl/ifwl_themeprovider.h"
-CFWL_ComboBox::CFWL_ComboBox(const CFWL_App* app)
- : CFWL_Widget(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr) {
- InitComboList();
- InitComboEdit();
-}
+CFWL_ComboBox::CFWL_ComboBox(CFWL_App* app)
+ : CFWL_Widget(app, Properties(), nullptr),
+ m_pEdit(cppgc::MakeGarbageCollected<CFWL_ComboEdit>(
+ app->GetHeap()->GetAllocationHandle(),
+ app,
+ Properties(),
+ this)),
+ m_pListBox(cppgc::MakeGarbageCollected<CFWL_ComboList>(
+ app->GetHeap()->GetAllocationHandle(),
+ app,
+ Properties{FWL_STYLE_WGT_Border | FWL_STYLE_WGT_VScroll, 0,
+ FWL_STATE_WGT_Invisible},
+ this)) {}
CFWL_ComboBox::~CFWL_ComboBox() = default;
+void CFWL_ComboBox::Trace(cppgc::Visitor* visitor) const {
+ CFWL_Widget::Trace(visitor);
+ visitor->Trace(m_pEdit);
+ visitor->Trace(m_pListBox);
+}
+
FWL_Type CFWL_ComboBox::GetClassID() const {
return FWL_Type::ComboBox;
}
@@ -53,39 +63,35 @@ void CFWL_ComboBox::RemoveAll() {
m_pListBox->DeleteAll();
}
-void CFWL_ComboBox::ModifyStylesEx(uint32_t dwStylesExAdded,
- uint32_t dwStylesExRemoved) {
- if (!m_pEdit)
- InitComboEdit();
-
- bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown);
- bool bDelDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown);
-
- dwStylesExRemoved &= ~FWL_STYLEEXT_CMB_DropDown;
- m_pProperties->m_dwStyleExes |= FWL_STYLEEXT_CMB_DropDown;
-
+void CFWL_ComboBox::ModifyStyleExts(uint32_t dwStyleExtsAdded,
+ uint32_t dwStyleExtsRemoved) {
+ bool bAddDropDown = !!(dwStyleExtsAdded & FWL_STYLEEXT_CMB_DropDown);
+ bool bDelDropDown = !!(dwStyleExtsRemoved & FWL_STYLEEXT_CMB_DropDown);
+ dwStyleExtsRemoved &= ~FWL_STYLEEXT_CMB_DropDown;
+ m_Properties.m_dwStyleExts |= FWL_STYLEEXT_CMB_DropDown;
if (bAddDropDown)
- m_pEdit->ModifyStylesEx(0, FWL_STYLEEXT_EDT_ReadOnly);
+ m_pEdit->ModifyStyleExts(0, FWL_STYLEEXT_EDT_ReadOnly);
else if (bDelDropDown)
- m_pEdit->ModifyStylesEx(FWL_STYLEEXT_EDT_ReadOnly, 0);
- CFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved);
+ m_pEdit->ModifyStyleExts(FWL_STYLEEXT_EDT_ReadOnly, 0);
+
+ CFWL_Widget::ModifyStyleExts(dwStyleExtsAdded, dwStyleExtsRemoved);
}
void CFWL_ComboBox::Update() {
- if (m_iLock)
+ if (IsLocked())
return;
+
if (m_pEdit)
ResetEditAlignment();
- ResetTheme();
Layout();
}
FWL_WidgetHit CFWL_ComboBox::HitTest(const CFX_PointF& point) {
- CFX_RectF rect(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width,
- m_pProperties->m_rtWidget.height);
+ CFX_RectF rect(0, 0, m_WidgetRect.width - m_BtnRect.width,
+ m_WidgetRect.height);
if (rect.Contains(point))
return FWL_WidgetHit::Edit;
- if (m_rtBtn.Contains(point))
+ if (m_BtnRect.Contains(point))
return FWL_WidgetHit::Client;
if (IsDropListVisible()) {
rect = m_pListBox->GetWidgetRect();
@@ -95,22 +101,17 @@ FWL_WidgetHit CFWL_ComboBox::HitTest(const CFX_PointF& point) {
return FWL_WidgetHit::Unknown;
}
-void CFWL_ComboBox::DrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_ComboBox::DrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
- IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get();
- pGraphics->SaveGraphState();
- pGraphics->ConcatMatrix(&matrix);
- if (!m_rtBtn.IsEmpty(0.1f)) {
- CFWL_ThemeBackground param;
- param.m_pWidget = this;
- param.m_iPart = CFWL_Part::DropDownButton;
+ if (!m_BtnRect.IsEmpty(0.1f)) {
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ pGraphics->ConcatMatrix(matrix);
+ CFWL_ThemeBackground param(CFWL_ThemePart::Part::kDropDownButton, this,
+ pGraphics);
param.m_dwStates = m_iBtnState;
- param.m_pGraphics = pGraphics;
- param.m_rtPart = m_rtBtn;
- pTheme->DrawBackground(param);
+ param.m_PartRect = m_BtnRect;
+ GetThemeProvider()->DrawBackground(param);
}
- pGraphics->RestoreGraphState();
-
if (m_pEdit) {
CFX_RectF rtEdit = m_pEdit->GetWidgetRect();
CFX_Matrix mt(1, 0, 0, 1, rtEdit.left, rtEdit.top);
@@ -125,20 +126,8 @@ void CFWL_ComboBox::DrawWidget(CXFA_Graphics* pGraphics,
}
}
-void CFWL_ComboBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
- if (!pThemeProvider)
- return;
-
- m_pProperties->m_pThemeProvider = pThemeProvider;
- if (m_pListBox)
- m_pListBox->SetThemeProvider(pThemeProvider);
- if (m_pEdit)
- m_pEdit->SetThemeProvider(pThemeProvider);
-}
-
WideString CFWL_ComboBox::GetTextByIndex(int32_t iIndex) const {
- CFWL_ListItem* pItem = static_cast<CFWL_ListItem*>(
- m_pListBox->GetItem(m_pListBox.get(), iIndex));
+ CFWL_ListBox::Item* pItem = m_pListBox->GetItem(m_pListBox, iIndex);
return pItem ? pItem->GetText() : WideString();
}
@@ -149,7 +138,7 @@ void CFWL_ComboBox::SetCurSel(int32_t iSel) {
if (bClearSel) {
m_pEdit->SetText(WideString());
} else {
- CFWL_ListItem* hItem = m_pListBox->GetItem(this, iSel);
+ CFWL_ListBox::Item* hItem = m_pListBox->GetItem(this, iSel);
m_pEdit->SetText(hItem ? hItem->GetText() : WideString());
}
m_pEdit->Update();
@@ -187,16 +176,12 @@ WideString CFWL_ComboBox::GetEditText() const {
if (!m_pListBox)
return WideString();
- CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel);
+ CFWL_ListBox::Item* hItem = m_pListBox->GetItem(this, m_iCurSel);
return hItem ? hItem->GetText() : WideString();
}
-void CFWL_ComboBox::OpenDropDownList(bool bActivate) {
- ShowDropList(bActivate);
-}
-
CFX_RectF CFWL_ComboBox::GetBBox() const {
- CFX_RectF rect = m_pProperties->m_rtWidget;
+ CFX_RectF rect = m_WidgetRect;
if (!m_pListBox || !IsDropListVisible())
return rect;
@@ -206,52 +191,56 @@ CFX_RectF CFWL_ComboBox::GetBBox() const {
return rect;
}
-void CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded,
- uint32_t dwStylesExRemoved) {
+void CFWL_ComboBox::EditModifyStyleExts(uint32_t dwStyleExtsAdded,
+ uint32_t dwStyleExtsRemoved) {
if (m_pEdit)
- m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved);
+ m_pEdit->ModifyStyleExts(dwStyleExtsAdded, dwStyleExtsRemoved);
}
-void CFWL_ComboBox::ShowDropList(bool bActivate) {
- if (IsDropListVisible() == bActivate)
+void CFWL_ComboBox::ShowDropDownList() {
+ if (IsDropListVisible())
return;
- if (bActivate) {
- CFWL_Event preEvent(CFWL_Event::Type::PreDropDown, this);
- DispatchEvent(&preEvent);
- if (!preEvent.GetSrcTarget())
- return;
+ CFWL_Event preEvent(CFWL_Event::Type::PreDropDown, this);
+ DispatchEvent(&preEvent);
+ if (!preEvent.GetSrcTarget())
+ return;
- CFWL_ComboList* pComboList = m_pListBox.get();
- int32_t iItems = pComboList->CountItems(nullptr);
- if (iItems < 1)
- return;
+ CFWL_ComboList* pComboList = m_pListBox;
+ int32_t iItems = pComboList->CountItems(nullptr);
+ if (iItems < 1)
+ return;
- ResetListItemAlignment();
- pComboList->ChangeSelected(m_iCurSel);
+ ResetListItemAlignment();
+ pComboList->ChangeSelected(m_iCurSel);
- float fItemHeight = pComboList->CalcItemHeight();
- float fBorder = GetCXBorderSize();
- float fPopupMin = 0.0f;
- if (iItems > 3)
- fPopupMin = fItemHeight * 3 + fBorder * 2;
+ float fItemHeight = pComboList->CalcItemHeight();
+ float fBorder = GetCXBorderSize();
+ float fPopupMin = 0.0f;
+ if (iItems > 3)
+ fPopupMin = fItemHeight * 3 + fBorder * 2;
- float fPopupMax = fItemHeight * iItems + fBorder * 2;
- CFX_RectF rtList(m_rtClient.left, 0, m_pProperties->m_rtWidget.width, 0);
- GetPopupPos(fPopupMin, fPopupMax, m_pProperties->m_rtWidget, &rtList);
+ float fPopupMax = fItemHeight * iItems + fBorder * 2;
+ CFX_RectF rtList(m_ClientRect.left, 0, m_WidgetRect.width, 0);
+ GetPopupPos(fPopupMin, fPopupMax, m_WidgetRect, &rtList);
+ m_pListBox->SetWidgetRect(rtList);
+ m_pListBox->Update();
+ m_pListBox->RemoveStates(FWL_STATE_WGT_Invisible);
- m_pListBox->SetWidgetRect(rtList);
- m_pListBox->Update();
- }
+ CFWL_Event postEvent(CFWL_Event::Type::PostDropDown, this);
+ DispatchEvent(&postEvent);
+ RepaintInflatedListBoxRect();
+}
- if (bActivate) {
- m_pListBox->RemoveStates(FWL_WGTSTATE_Invisible);
- CFWL_Event postEvent(CFWL_Event::Type::PostDropDown, this);
- DispatchEvent(&postEvent);
- } else {
- m_pListBox->SetStates(FWL_WGTSTATE_Invisible);
- }
+void CFWL_ComboBox::HideDropDownList() {
+ if (!IsDropListVisible())
+ return;
+
+ m_pListBox->SetStates(FWL_STATE_WGT_Invisible);
+ RepaintInflatedListBoxRect();
+}
+void CFWL_ComboBox::RepaintInflatedListBoxRect() {
CFX_RectF rect = m_pListBox->GetWidgetRect();
rect.Inflate(2, 2);
RepaintRect(rect);
@@ -271,65 +260,51 @@ void CFWL_ComboBox::MatchEditText() {
}
void CFWL_ComboBox::SyncEditText(int32_t iListItem) {
- CFWL_ListItem* hItem = m_pListBox->GetItem(this, iListItem);
+ CFWL_ListBox::Item* hItem = m_pListBox->GetItem(this, iListItem);
m_pEdit->SetText(hItem ? hItem->GetText() : WideString());
m_pEdit->Update();
m_pEdit->SetSelected();
}
void CFWL_ComboBox::Layout() {
- m_rtClient = GetClientRect();
- m_rtContent = m_rtClient;
- IFWL_ThemeProvider* theme = GetAvailableTheme();
- if (!theme)
- return;
+ m_ClientRect = GetClientRect();
+ m_ContentRect = m_ClientRect;
+ IFWL_ThemeProvider* theme = GetThemeProvider();
float borderWidth = 1;
float fBtn = theme->GetScrollBarWidth();
- if (!(GetStylesEx() & FWL_STYLEEXT_CMB_ReadOnly)) {
- m_rtBtn =
- CFX_RectF(m_rtClient.right() - fBtn, m_rtClient.top + borderWidth,
- fBtn - borderWidth, m_rtClient.height - 2 * borderWidth);
+ if (!(GetStyleExts() & FWL_STYLEEXT_CMB_ReadOnly)) {
+ m_BtnRect =
+ CFX_RectF(m_ClientRect.right() - fBtn, m_ClientRect.top + borderWidth,
+ fBtn - borderWidth, m_ClientRect.height - 2 * borderWidth);
}
- CFWL_ThemePart part;
- part.m_pWidget = this;
+ CFWL_ThemePart part(CFWL_ThemePart::Part::kNone, this);
CFX_RectF pUIMargin = theme->GetUIMargin(part);
- m_rtContent.Deflate(pUIMargin.left, pUIMargin.top, pUIMargin.width,
- pUIMargin.height);
+ m_ContentRect.Deflate(pUIMargin.left, pUIMargin.top, pUIMargin.width,
+ pUIMargin.height);
if (!IsDropDownStyle() || !m_pEdit)
return;
- CFX_RectF rtEdit(m_rtContent.left, m_rtContent.top, m_rtContent.width - fBtn,
- m_rtContent.height);
+ CFX_RectF rtEdit(m_ContentRect.left, m_ContentRect.top,
+ m_ContentRect.width - fBtn, m_ContentRect.height);
m_pEdit->SetWidgetRect(rtEdit);
if (m_iCurSel >= 0) {
- CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel);
- ScopedUpdateLock update_lock(m_pEdit.get());
+ CFWL_ListBox::Item* hItem = m_pListBox->GetItem(this, m_iCurSel);
+ ScopedUpdateLock update_lock(m_pEdit);
m_pEdit->SetText(hItem ? hItem->GetText() : WideString());
}
m_pEdit->Update();
}
-void CFWL_ComboBox::ResetTheme() {
- if (!m_pProperties->m_pThemeProvider)
- m_pProperties->m_pThemeProvider = GetAvailableTheme();
-
- IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get();
- if (m_pListBox && !m_pListBox->GetThemeProvider())
- m_pListBox->SetThemeProvider(pTheme);
- if (m_pEdit && !m_pEdit->GetThemeProvider())
- m_pEdit->SetThemeProvider(pTheme);
-}
-
void CFWL_ComboBox::ResetEditAlignment() {
if (!m_pEdit)
return;
uint32_t dwAdd = 0;
- switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditHAlignMask) {
+ switch (m_Properties.m_dwStyleExts & FWL_STYLEEXT_CMB_EditHAlignMask) {
case FWL_STYLEEXT_CMB_EditHCenter: {
dwAdd |= FWL_STYLEEXT_EDT_HCenter;
break;
@@ -339,7 +314,7 @@ void CFWL_ComboBox::ResetEditAlignment() {
break;
}
}
- switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditVAlignMask) {
+ switch (m_Properties.m_dwStyleExts & FWL_STYLEEXT_CMB_EditVAlignMask) {
case FWL_STYLEEXT_CMB_EditVCenter: {
dwAdd |= FWL_STYLEEXT_EDT_VCenter;
break;
@@ -353,12 +328,12 @@ void CFWL_ComboBox::ResetEditAlignment() {
break;
}
}
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditJustified)
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_CMB_EditJustified)
dwAdd |= FWL_STYLEEXT_EDT_Justified;
- m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask |
- FWL_STYLEEXT_EDT_HAlignModeMask |
- FWL_STYLEEXT_EDT_VAlignMask);
+ m_pEdit->ModifyStyleExts(dwAdd, FWL_STYLEEXT_EDT_HAlignMask |
+ FWL_STYLEEXT_EDT_HAlignModeMask |
+ FWL_STYLEEXT_EDT_VAlignMask);
}
void CFWL_ComboBox::ResetListItemAlignment() {
@@ -366,7 +341,7 @@ void CFWL_ComboBox::ResetListItemAlignment() {
return;
uint32_t dwAdd = 0;
- switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemAlignMask) {
+ switch (m_Properties.m_dwStyleExts & FWL_STYLEEXT_CMB_ListItemAlignMask) {
case FWL_STYLEEXT_CMB_ListItemCenterAlign: {
dwAdd |= FWL_STYLEEXT_LTB_CenterAlign;
break;
@@ -376,80 +351,49 @@ void CFWL_ComboBox::ResetListItemAlignment() {
break;
}
}
- m_pListBox->ModifyStylesEx(dwAdd, FWL_STYLEEXT_CMB_ListItemAlignMask);
+ m_pListBox->ModifyStyleExts(dwAdd, FWL_STYLEEXT_CMB_ListItemAlignMask);
}
void CFWL_ComboBox::ProcessSelChanged(bool bLButtonUp) {
m_iCurSel = m_pListBox->GetItemIndex(this, m_pListBox->GetSelItem(0));
if (!IsDropDownStyle()) {
- RepaintRect(m_rtClient);
+ RepaintRect(m_ClientRect);
return;
}
-
- CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel);
+ CFWL_ListBox::Item* hItem = m_pListBox->GetItem(this, m_iCurSel);
if (!hItem)
return;
+
if (m_pEdit) {
m_pEdit->SetText(hItem->GetText());
m_pEdit->Update();
m_pEdit->SetSelected();
}
-
- CFWL_EventSelectChanged ev(this);
- ev.bLButtonUp = bLButtonUp;
+ CFWL_EventSelectChanged ev(this, bLButtonUp);
DispatchEvent(&ev);
}
-void CFWL_ComboBox::InitComboList() {
- if (m_pListBox)
- return;
-
- auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>();
- prop->m_pParent = this;
- prop->m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll;
- prop->m_dwStates = FWL_WGTSTATE_Invisible;
- prop->m_pThemeProvider = m_pProperties->m_pThemeProvider;
- m_pListBox = pdfium::MakeUnique<CFWL_ComboList>(m_pOwnerApp.Get(),
- std::move(prop), this);
-}
-
-void CFWL_ComboBox::InitComboEdit() {
- if (m_pEdit)
- return;
-
- auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>();
- prop->m_pParent = this;
- prop->m_pThemeProvider = m_pProperties->m_pThemeProvider;
-
- m_pEdit = pdfium::MakeUnique<CFWL_ComboEdit>(m_pOwnerApp.Get(),
- std::move(prop), this);
- m_pEdit->SetOuter(this);
-}
-
void CFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) {
- if (!pMessage)
- return;
-
bool backDefault = true;
switch (pMessage->GetType()) {
- case CFWL_Message::Type::SetFocus: {
+ case CFWL_Message::Type::kSetFocus: {
backDefault = false;
- OnFocusChanged(pMessage, true);
+ OnFocusGained();
break;
}
- case CFWL_Message::Type::KillFocus: {
+ case CFWL_Message::Type::kKillFocus: {
backDefault = false;
- OnFocusChanged(pMessage, false);
+ OnFocusLost();
break;
}
- case CFWL_Message::Type::Mouse: {
+ case CFWL_Message::Type::kMouse: {
backDefault = false;
CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
switch (pMsg->m_dwCmd) {
- case FWL_MouseCommand::LeftButtonDown:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonDown:
OnLButtonDown(pMsg);
break;
- case FWL_MouseCommand::LeftButtonUp:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonUp:
OnLButtonUp(pMsg);
break;
default:
@@ -457,16 +401,15 @@ void CFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) {
}
break;
}
- case CFWL_Message::Type::Key: {
+ case CFWL_Message::Type::kKey: {
backDefault = false;
CFWL_MessageKey* pKey = static_cast<CFWL_MessageKey*>(pMessage);
- if (pKey->m_dwCmd == FWL_KeyCommand::KeyUp)
- break;
- if (IsDropListVisible() && pKey->m_dwCmd == FWL_KeyCommand::KeyDown) {
- bool bListKey = pKey->m_dwKeyCode == XFA_FWL_VKEY_Up ||
- pKey->m_dwKeyCode == XFA_FWL_VKEY_Down ||
- pKey->m_dwKeyCode == XFA_FWL_VKEY_Return ||
- pKey->m_dwKeyCode == XFA_FWL_VKEY_Escape;
+ if (IsDropListVisible() &&
+ pKey->m_dwCmd == CFWL_MessageKey::KeyCommand::kKeyDown) {
+ bool bListKey = pKey->m_dwKeyCodeOrChar == XFA_FWL_VKEY_Up ||
+ pKey->m_dwKeyCodeOrChar == XFA_FWL_VKEY_Down ||
+ pKey->m_dwKeyCodeOrChar == XFA_FWL_VKEY_Return ||
+ pKey->m_dwKeyCodeOrChar == XFA_FWL_VKEY_Escape;
if (bListKey) {
m_pListBox->GetDelegate()->OnProcessMessage(pMessage);
break;
@@ -487,9 +430,8 @@ void CFWL_ComboBox::OnProcessEvent(CFWL_Event* pEvent) {
CFWL_Event::Type type = pEvent->GetType();
if (type == CFWL_Event::Type::Scroll) {
CFWL_EventScroll* pScrollEvent = static_cast<CFWL_EventScroll*>(pEvent);
- CFWL_EventScroll pScrollEv(this);
- pScrollEv.m_iScrollCode = pScrollEvent->m_iScrollCode;
- pScrollEv.m_fPos = pScrollEvent->m_fPos;
+ CFWL_EventScroll pScrollEv(this, pScrollEvent->GetScrollCode(),
+ pScrollEvent->GetPos());
DispatchEvent(&pScrollEv);
} else if (type == CFWL_Event::Type::TextWillChange) {
CFWL_Event pTemp(CFWL_Event::Type::EditChanged, this);
@@ -497,56 +439,55 @@ void CFWL_ComboBox::OnProcessEvent(CFWL_Event* pEvent) {
}
}
-void CFWL_ComboBox::OnDrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_ComboBox::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
DrawWidget(pGraphics, matrix);
}
void CFWL_ComboBox::OnLButtonUp(CFWL_MessageMouse* pMsg) {
- if (m_rtBtn.Contains(pMsg->m_pos))
- m_iBtnState = CFWL_PartState_Hovered;
+ if (m_BtnRect.Contains(pMsg->m_pos))
+ m_iBtnState = CFWL_PartState::kHovered;
else
- m_iBtnState = CFWL_PartState_Normal;
+ m_iBtnState = CFWL_PartState::kNormal;
- RepaintRect(m_rtBtn);
+ RepaintRect(m_BtnRect);
}
void CFWL_ComboBox::OnLButtonDown(CFWL_MessageMouse* pMsg) {
- bool bDropDown = IsDropListVisible();
- CFX_RectF& rtBtn = bDropDown ? m_rtBtn : m_rtClient;
- if (!rtBtn.Contains(pMsg->m_pos))
- return;
-
if (IsDropListVisible()) {
- ShowDropList(false);
+ if (m_BtnRect.Contains(pMsg->m_pos))
+ HideDropDownList();
return;
}
+ if (!m_ClientRect.Contains(pMsg->m_pos))
+ return;
+
if (m_pEdit)
MatchEditText();
- ShowDropList(true);
+ ShowDropDownList();
}
-void CFWL_ComboBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) {
- if (bSet) {
- m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
- if ((m_pEdit->GetStates() & FWL_WGTSTATE_Focused) == 0) {
- CFWL_MessageSetFocus msg(nullptr, m_pEdit.get());
- m_pEdit->GetDelegate()->OnProcessMessage(&msg);
- }
- } else {
- m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
- ShowDropList(false);
- CFWL_MessageKillFocus msg(m_pEdit.get());
+void CFWL_ComboBox::OnFocusGained() {
+ m_Properties.m_dwStates |= FWL_STATE_WGT_Focused;
+ if ((m_pEdit->GetStates() & FWL_STATE_WGT_Focused) == 0) {
+ CFWL_MessageSetFocus msg(m_pEdit);
m_pEdit->GetDelegate()->OnProcessMessage(&msg);
}
}
+void CFWL_ComboBox::OnFocusLost() {
+ m_Properties.m_dwStates &= ~FWL_STATE_WGT_Focused;
+ HideDropDownList();
+ CFWL_MessageKillFocus msg(nullptr);
+ m_pEdit->GetDelegate()->OnProcessMessage(&msg);
+}
+
void CFWL_ComboBox::OnKey(CFWL_MessageKey* pMsg) {
- uint32_t dwKeyCode = pMsg->m_dwKeyCode;
+ uint32_t dwKeyCode = pMsg->m_dwKeyCodeOrChar;
const bool bUp = dwKeyCode == XFA_FWL_VKEY_Up;
const bool bDown = dwKeyCode == XFA_FWL_VKEY_Down;
if (bUp || bDown) {
- CFWL_ComboList* pComboList = m_pListBox.get();
+ CFWL_ComboList* pComboList = m_pListBox;
int32_t iCount = pComboList->CountItems(nullptr);
if (iCount < 1)
return;
@@ -557,7 +498,7 @@ void CFWL_ComboBox::OnKey(CFWL_MessageKey* pMsg) {
WideString wsText = m_pEdit->GetText();
iCurSel = pComboList->MatchItem(wsText.AsStringView());
if (iCurSel >= 0) {
- CFWL_ListItem* item = m_pListBox->GetSelItem(iCurSel);
+ CFWL_ListBox::Item* item = m_pListBox->GetSelItem(iCurSel);
bMatchEqual = wsText == (item ? item->GetText() : WideString());
}
}
@@ -583,6 +524,6 @@ void CFWL_ComboBox::GetPopupPos(float fMinHeight,
float fMaxHeight,
const CFX_RectF& rtAnchor,
CFX_RectF* pPopupRect) {
- m_pWidgetMgr->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor,
- pPopupRect);
+ GetWidgetMgr()->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor,
+ pPopupRect);
}
diff --git a/xfa/fwl/cfwl_combobox.h b/xfa/fwl/cfwl_combobox.h
index 39c952c5c..590b889b6 100644
--- a/xfa/fwl/cfwl_combobox.h
+++ b/xfa/fwl/cfwl_combobox.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,17 +7,11 @@
#ifndef XFA_FWL_CFWL_COMBOBOX_H_
#define XFA_FWL_CFWL_COMBOBOX_H_
-#include <memory>
-
+#include "xfa/fgas/graphics/cfgas_gegraphics.h"
#include "xfa/fwl/cfwl_comboedit.h"
#include "xfa/fwl/cfwl_combolist.h"
#include "xfa/fwl/cfwl_listbox.h"
-#include "xfa/fxgraphics/cxfa_graphics.h"
-
-class CFWL_WidgetProperties;
-class CFWL_ComboBox;
-class CFWL_ListBox;
-class CFWL_Widget;
+#include "xfa/fwl/cfwl_widget.h"
#define FWL_STYLEEXT_CMB_DropDown (1L << 0)
#define FWL_STYLEEXT_CMB_Sort (1L << 1)
@@ -37,22 +31,23 @@ class CFWL_Widget;
class CFWL_ComboBox final : public CFWL_Widget {
public:
- explicit CFWL_ComboBox(const CFWL_App* pApp);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_ComboBox() override;
// CFWL_Widget
+ void Trace(cppgc::Visitor* visitor) const override;
FWL_Type GetClassID() const override;
- void ModifyStylesEx(uint32_t dwStylesExAdded,
- uint32_t dwStylesExRemoved) override;
+ void ModifyStyleExts(uint32_t dwStyleExtsAdded,
+ uint32_t dwStyleExtsRemoved) override;
void SetStates(uint32_t dwStates) override;
void RemoveStates(uint32_t dwStates) override;
void Update() override;
FWL_WidgetHit HitTest(const CFX_PointF& point) override;
- void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
- void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override;
+ void DrawWidget(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& matrix) override;
void OnProcessMessage(CFWL_Message* pMessage) override;
void OnProcessEvent(CFWL_Event* pEvent) override;
- void OnDrawWidget(CXFA_Graphics* pGraphics,
+ void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) override;
WideString GetTextByIndex(int32_t iIndex) const;
@@ -66,43 +61,44 @@ class CFWL_ComboBox final : public CFWL_Widget {
void SetEditText(const WideString& wsText);
WideString GetEditText() const;
- void OpenDropDownList(bool bActivate);
-
bool EditCanUndo() const { return m_pEdit->CanUndo(); }
bool EditCanRedo() const { return m_pEdit->CanRedo(); }
bool EditUndo() { return m_pEdit->Undo(); }
bool EditRedo() { return m_pEdit->Redo(); }
bool EditCanCopy() const { return m_pEdit->HasSelection(); }
bool EditCanCut() const {
- if (m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly)
+ if (m_pEdit->GetStyleExts() & FWL_STYLEEXT_EDT_ReadOnly)
return false;
return EditCanCopy();
}
bool EditCanSelectAll() const { return m_pEdit->GetTextLength() > 0; }
- Optional<WideString> EditCopy() const { return m_pEdit->Copy(); }
- Optional<WideString> EditCut() { return m_pEdit->Cut(); }
+ absl::optional<WideString> EditCopy() const { return m_pEdit->Copy(); }
+ absl::optional<WideString> EditCut() { return m_pEdit->Cut(); }
bool EditPaste(const WideString& wsPaste) { return m_pEdit->Paste(wsPaste); }
void EditSelectAll() { m_pEdit->SelectAll(); }
void EditDelete() { m_pEdit->ClearText(); }
void EditDeSelect() { m_pEdit->ClearSelection(); }
CFX_RectF GetBBox() const;
- void EditModifyStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved);
- void ShowDropList(bool bActivate);
+ void EditModifyStyleExts(uint32_t dwStyleExtsAdded,
+ uint32_t dwStyleExtsRemoved);
+ void ShowDropDownList();
+ void HideDropDownList();
- CFWL_ComboEdit* GetComboEdit() const { return m_pEdit.get(); }
+ CFWL_ComboEdit* GetComboEdit() const { return m_pEdit; }
void ProcessSelChanged(bool bLButtonUp);
int32_t GetCurrentSelection() const { return m_iCurSel; }
private:
+ explicit CFWL_ComboBox(CFWL_App* pApp);
+
bool IsDropDownStyle() const {
- return !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown);
+ return !!(GetStyleExts() & FWL_STYLEEXT_CMB_DropDown);
}
void MatchEditText();
void SyncEditText(int32_t iListItem);
void Layout();
- void ResetTheme();
void ResetEditAlignment();
void ResetListItemAlignment();
void GetPopupPos(float fMinHeight,
@@ -110,21 +106,20 @@ class CFWL_ComboBox final : public CFWL_Widget {
const CFX_RectF& rtAnchor,
CFX_RectF* pPopupRect);
void OnLButtonUp(CFWL_MessageMouse* pMsg);
-
- void InitComboList();
- void InitComboEdit();
bool IsDropListVisible() const { return m_pListBox->IsVisible(); }
void OnLButtonDown(CFWL_MessageMouse* pMsg);
- void OnFocusChanged(CFWL_Message* pMsg, bool bSet);
+ void OnFocusGained();
+ void OnFocusLost();
void OnKey(CFWL_MessageKey* pMsg);
+ void RepaintInflatedListBoxRect();
- CFX_RectF m_rtClient;
- CFX_RectF m_rtContent;
- CFX_RectF m_rtBtn;
- std::unique_ptr<CFWL_ComboEdit> m_pEdit;
- std::unique_ptr<CFWL_ComboList> m_pListBox;
+ CFX_RectF m_ClientRect;
+ CFX_RectF m_ContentRect;
+ CFX_RectF m_BtnRect;
+ cppgc::Member<CFWL_ComboEdit> const m_pEdit;
+ cppgc::Member<CFWL_ComboList> const m_pListBox;
int32_t m_iCurSel = -1;
- int32_t m_iBtnState = CFWL_PartState_Normal;
+ Mask<CFWL_PartState> m_iBtnState = CFWL_PartState::kNormal;
};
#endif // XFA_FWL_CFWL_COMBOBOX_H_
diff --git a/xfa/fwl/cfwl_comboedit.cpp b/xfa/fwl/cfwl_comboedit.cpp
index 6ab081a21..0be03d3a8 100644
--- a/xfa/fwl/cfwl_comboedit.cpp
+++ b/xfa/fwl/cfwl_comboedit.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,19 +6,14 @@
#include "xfa/fwl/cfwl_comboedit.h"
-#include <memory>
-#include <utility>
-
#include "xfa/fde/cfde_texteditengine.h"
#include "xfa/fwl/cfwl_combobox.h"
#include "xfa/fwl/cfwl_messagemouse.h"
-CFWL_ComboEdit::CFWL_ComboEdit(
- const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter)
- : CFWL_Edit(app, std::move(properties), pOuter) {
-}
+CFWL_ComboEdit::CFWL_ComboEdit(CFWL_App* app,
+ const Properties& properties,
+ CFWL_Widget* pOuter)
+ : CFWL_Edit(app, properties, pOuter) {}
CFWL_ComboEdit::~CFWL_ComboEdit() = default;
@@ -28,40 +23,27 @@ void CFWL_ComboEdit::ClearSelected() {
}
void CFWL_ComboEdit::SetSelected() {
- FlagFocus(true);
+ m_Properties.m_dwStates |= FWL_STATE_WGT_Focused;
SelectAll();
}
-void CFWL_ComboEdit::FlagFocus(bool bSet) {
- if (bSet) {
- m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
- return;
- }
-
- m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
- HideCaret(nullptr);
-}
-
void CFWL_ComboEdit::OnProcessMessage(CFWL_Message* pMessage) {
- if (!pMessage)
- return;
-
bool backDefault = true;
switch (pMessage->GetType()) {
- case CFWL_Message::Type::SetFocus: {
- m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
+ case CFWL_Message::Type::kSetFocus: {
+ m_Properties.m_dwStates |= FWL_STATE_WGT_Focused;
backDefault = false;
break;
}
- case CFWL_Message::Type::KillFocus: {
- m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
+ case CFWL_Message::Type::kKillFocus: {
+ m_Properties.m_dwStates &= ~FWL_STATE_WGT_Focused;
backDefault = false;
break;
}
- case CFWL_Message::Type::Mouse: {
+ case CFWL_Message::Type::kMouse: {
CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
- if ((pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonDown) &&
- ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)) {
+ if ((pMsg->m_dwCmd == CFWL_MessageMouse::MouseCommand::kLeftButtonDown) &&
+ ((m_Properties.m_dwStates & FWL_STATE_WGT_Focused) == 0)) {
SetSelected();
}
break;
diff --git a/xfa/fwl/cfwl_comboedit.h b/xfa/fwl/cfwl_comboedit.h
index 68e6caa87..91e7f35b8 100644
--- a/xfa/fwl/cfwl_comboedit.h
+++ b/xfa/fwl/cfwl_comboedit.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,27 +7,24 @@
#ifndef XFA_FWL_CFWL_COMBOEDIT_H_
#define XFA_FWL_CFWL_COMBOEDIT_H_
-#include <memory>
-
#include "xfa/fwl/cfwl_edit.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fwl/cfwl_widgetproperties.h"
-
-class CFWL_ComboBox;
class CFWL_ComboEdit final : public CFWL_Edit {
public:
- CFWL_ComboEdit(const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_ComboEdit() override;
- // CFWL_Edit.
+ // CFWL_Edit:
void OnProcessMessage(CFWL_Message* pMessage) override;
void ClearSelected();
void SetSelected();
- void FlagFocus(bool bSet);
+
+ private:
+ CFWL_ComboEdit(CFWL_App* app,
+ const Properties& properties,
+ CFWL_Widget* pOuter);
};
#endif // XFA_FWL_CFWL_COMBOEDIT_H_
diff --git a/xfa/fwl/cfwl_combolist.cpp b/xfa/fwl/cfwl_combolist.cpp
index d25f31266..938bc10f7 100644
--- a/xfa/fwl/cfwl_combolist.cpp
+++ b/xfa/fwl/cfwl_combolist.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,9 +6,7 @@
#include "xfa/fwl/cfwl_combolist.h"
-#include <memory>
-#include <utility>
-
+#include "third_party/base/check.h"
#include "xfa/fwl/cfwl_combobox.h"
#include "xfa/fwl/cfwl_comboedit.h"
#include "xfa/fwl/cfwl_listbox.h"
@@ -17,21 +15,22 @@
#include "xfa/fwl/cfwl_messagemouse.h"
#include "xfa/fwl/fwl_widgetdef.h"
-CFWL_ComboList::CFWL_ComboList(
- const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter)
- : CFWL_ListBox(app, std::move(properties), pOuter) {
- ASSERT(pOuter);
+CFWL_ComboList::CFWL_ComboList(CFWL_App* app,
+ const Properties& properties,
+ CFWL_Widget* pOuter)
+ : CFWL_ListBox(app, properties, pOuter) {
+ DCHECK(pOuter);
}
+CFWL_ComboList::~CFWL_ComboList() = default;
+
int32_t CFWL_ComboList::MatchItem(WideStringView wsMatch) {
if (wsMatch.IsEmpty())
return -1;
int32_t iCount = CountItems(this);
for (int32_t i = 0; i < iCount; i++) {
- CFWL_ListItem* hItem = GetItem(this, i);
+ CFWL_ListBox::Item* hItem = GetItem(this, i);
WideString wsText = hItem ? hItem->GetText() : WideString();
auto pos = wsText.Find(wsMatch);
if (pos.has_value() && pos.value() == 0)
@@ -41,22 +40,22 @@ int32_t CFWL_ComboList::MatchItem(WideStringView wsMatch) {
}
void CFWL_ComboList::ChangeSelected(int32_t iSel) {
- CFWL_ListItem* hItem = GetItem(this, iSel);
- CFWL_ListItem* hOld = GetSelItem(0);
+ CFWL_ListBox::Item* hItem = GetItem(this, iSel);
+ CFWL_ListBox::Item* hOld = GetSelItem(0);
int32_t iOld = GetItemIndex(this, hOld);
if (iOld == iSel)
return;
CFX_RectF rtInvalidate;
if (iOld > -1) {
- if (CFWL_ListItem* hOldItem = GetItem(this, iOld))
+ if (CFWL_ListBox::Item* hOldItem = GetItem(this, iOld))
rtInvalidate = hOldItem->GetRect();
SetSelItem(hOld, false);
}
if (hItem) {
- if (CFWL_ListItem* hOldItem = GetItem(this, iSel))
+ if (CFWL_ListBox::Item* hOldItem = GetItem(this, iSel))
rtInvalidate.Union(hOldItem->GetRect());
- CFWL_ListItem* hSel = GetItem(this, iSel);
+ CFWL_ListBox::Item* hSel = GetItem(this, iSel);
SetSelItem(hSel, true);
}
if (!rtInvalidate.IsEmpty())
@@ -64,25 +63,19 @@ void CFWL_ComboList::ChangeSelected(int32_t iSel) {
}
CFX_PointF CFWL_ComboList::ClientToOuter(const CFX_PointF& point) {
- CFX_PointF ret = point + CFX_PointF(m_pProperties->m_rtWidget.left,
- m_pProperties->m_rtWidget.top);
- CFWL_Widget* pOwner = GetOwner();
- return pOwner ? pOwner->TransformTo(m_pOuter, ret) : ret;
+ return point + CFX_PointF(m_WidgetRect.left, m_WidgetRect.top);
}
void CFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) {
- if (!pMessage)
- return;
-
CFWL_Message::Type type = pMessage->GetType();
bool backDefault = true;
- if (type == CFWL_Message::Type::SetFocus ||
- type == CFWL_Message::Type::KillFocus) {
- OnDropListFocusChanged(pMessage, type == CFWL_Message::Type::SetFocus);
- } else if (type == CFWL_Message::Type::Mouse) {
+ if (type == CFWL_Message::Type::kSetFocus ||
+ type == CFWL_Message::Type::kKillFocus) {
+ OnDropListFocusChanged(pMessage, type == CFWL_Message::Type::kSetFocus);
+ } else if (type == CFWL_Message::Type::kMouse) {
CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
CFWL_ScrollBar* vertSB = GetVertScrollBar();
- if (IsShowScrollBar(true) && vertSB) {
+ if (IsShowVertScrollBar() && vertSB) {
CFX_RectF rect = vertSB->GetWidgetRect();
if (rect.Contains(pMsg->m_pos)) {
pMsg->m_pos -= rect.TopLeft();
@@ -91,25 +84,22 @@ void CFWL_ComboList::OnProcessMessage(CFWL_Message* pMessage) {
}
}
switch (pMsg->m_dwCmd) {
- case FWL_MouseCommand::Move: {
+ case CFWL_MessageMouse::MouseCommand::kMove:
backDefault = false;
OnDropListMouseMove(pMsg);
break;
- }
- case FWL_MouseCommand::LeftButtonDown: {
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonDown:
backDefault = false;
OnDropListLButtonDown(pMsg);
break;
- }
- case FWL_MouseCommand::LeftButtonUp: {
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonUp:
backDefault = false;
OnDropListLButtonUp(pMsg);
break;
- }
default:
break;
}
- } else if (type == CFWL_Message::Type::Key) {
+ } else if (type == CFWL_Message::Type::kKey) {
backDefault = !OnDropListKey(static_cast<CFWL_MessageKey*>(pMessage));
}
if (backDefault)
@@ -121,10 +111,10 @@ void CFWL_ComboList::OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet) {
return;
CFWL_MessageKillFocus* pKill = static_cast<CFWL_MessageKillFocus*>(pMsg);
- CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter);
- if (pKill->IsFocusedOnWidget(m_pOuter) ||
+ CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(GetOuter());
+ if (pKill->IsFocusedOnWidget(pOuter) ||
pKill->IsFocusedOnWidget(pOuter->GetComboEdit())) {
- pOuter->ShowDropList(false);
+ pOuter->HideDropDownList();
}
}
@@ -134,13 +124,13 @@ void CFWL_ComboList::OnDropListMouseMove(CFWL_MessageMouse* pMsg) {
m_bNotifyOwner = false;
CFWL_ScrollBar* vertSB = GetVertScrollBar();
- if (IsShowScrollBar(true) && vertSB) {
+ if (IsShowVertScrollBar() && vertSB) {
CFX_RectF rect = vertSB->GetWidgetRect();
if (rect.Contains(pMsg->m_pos))
return;
}
- CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_pos);
+ CFWL_ListBox::Item* hItem = GetItemAtPoint(pMsg->m_pos);
if (!hItem)
return;
@@ -148,7 +138,7 @@ void CFWL_ComboList::OnDropListMouseMove(CFWL_MessageMouse* pMsg) {
} else if (m_bNotifyOwner) {
pMsg->m_pos = ClientToOuter(pMsg->m_pos);
- CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter);
+ CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(GetOuter());
pOuter->GetDelegate()->OnProcessMessage(pMsg);
}
}
@@ -157,12 +147,12 @@ void CFWL_ComboList::OnDropListLButtonDown(CFWL_MessageMouse* pMsg) {
if (GetRTClient().Contains(pMsg->m_pos))
return;
- CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter);
- pOuter->ShowDropList(false);
+ CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(GetOuter());
+ pOuter->HideDropDownList();
}
void CFWL_ComboList::OnDropListLButtonUp(CFWL_MessageMouse* pMsg) {
- CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter);
+ CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(GetOuter());
if (m_bNotifyOwner) {
pMsg->m_pos = ClientToOuter(pMsg->m_pos);
pOuter->GetDelegate()->OnProcessMessage(pMsg);
@@ -170,27 +160,27 @@ void CFWL_ComboList::OnDropListLButtonUp(CFWL_MessageMouse* pMsg) {
}
CFWL_ScrollBar* vertSB = GetVertScrollBar();
- if (IsShowScrollBar(true) && vertSB) {
+ if (IsShowVertScrollBar() && vertSB) {
CFX_RectF rect = vertSB->GetWidgetRect();
if (rect.Contains(pMsg->m_pos))
return;
}
- pOuter->ShowDropList(false);
+ pOuter->HideDropDownList();
- CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_pos);
+ CFWL_ListBox::Item* hItem = GetItemAtPoint(pMsg->m_pos);
if (hItem)
pOuter->ProcessSelChanged(true);
}
bool CFWL_ComboList::OnDropListKey(CFWL_MessageKey* pKey) {
- CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter);
+ CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(GetOuter());
bool bPropagate = false;
- if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) {
- uint32_t dwKeyCode = pKey->m_dwKeyCode;
+ if (pKey->m_dwCmd == CFWL_MessageKey::KeyCommand::kKeyDown) {
+ uint32_t dwKeyCode = pKey->m_dwKeyCodeOrChar;
switch (dwKeyCode) {
case XFA_FWL_VKEY_Return:
case XFA_FWL_VKEY_Escape: {
- pOuter->ShowDropList(false);
+ pOuter->HideDropDownList();
return true;
}
case XFA_FWL_VKEY_Up:
@@ -204,11 +194,11 @@ bool CFWL_ComboList::OnDropListKey(CFWL_MessageKey* pKey) {
break;
}
}
- } else if (pKey->m_dwCmd == FWL_KeyCommand::Char) {
+ } else if (pKey->m_dwCmd == CFWL_MessageKey::KeyCommand::kChar) {
bPropagate = true;
}
if (bPropagate) {
- pKey->SetDstTarget(m_pOuter);
+ pKey->SetDstTarget(GetOuter());
pOuter->GetDelegate()->OnProcessMessage(pKey);
return true;
}
@@ -216,23 +206,21 @@ bool CFWL_ComboList::OnDropListKey(CFWL_MessageKey* pKey) {
}
void CFWL_ComboList::OnDropListKeyDown(CFWL_MessageKey* pKey) {
- uint32_t dwKeyCode = pKey->m_dwKeyCode;
+ auto dwKeyCode = static_cast<XFA_FWL_VKEYCODE>(pKey->m_dwKeyCodeOrChar);
switch (dwKeyCode) {
case XFA_FWL_VKEY_Up:
case XFA_FWL_VKEY_Down:
case XFA_FWL_VKEY_Home:
case XFA_FWL_VKEY_End: {
- CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(m_pOuter);
- CFWL_ListItem* hItem = GetItem(this, pOuter->GetCurrentSelection());
+ CFWL_ComboBox* pOuter = static_cast<CFWL_ComboBox*>(GetOuter());
+ CFWL_ListBox::Item* hItem = GetItem(this, pOuter->GetCurrentSelection());
hItem = GetListItem(hItem, dwKeyCode);
if (!hItem)
break;
SetSelection(hItem, hItem, true);
ScrollToVisible(hItem);
- CFX_RectF rtInvalidate(0, 0, m_pProperties->m_rtWidget.width,
- m_pProperties->m_rtWidget.height);
- RepaintRect(rtInvalidate);
+ RepaintRect(CFX_RectF(0, 0, m_WidgetRect.width, m_WidgetRect.height));
break;
}
default:
diff --git a/xfa/fwl/cfwl_combolist.h b/xfa/fwl/cfwl_combolist.h
index c275c7268..7ee273794 100644
--- a/xfa/fwl/cfwl_combolist.h
+++ b/xfa/fwl/cfwl_combolist.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,26 +7,25 @@
#ifndef XFA_FWL_CFWL_COMBOLIST_H_
#define XFA_FWL_CFWL_COMBOLIST_H_
-#include <memory>
-
#include "xfa/fwl/cfwl_listbox.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fwl/cfwl_widgetproperties.h"
class CFWL_ComboList final : public CFWL_ListBox {
public:
- CFWL_ComboList(const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
+ ~CFWL_ComboList() override;
// CFWL_ListBox.
void OnProcessMessage(CFWL_Message* pMessage) override;
int32_t MatchItem(WideStringView wsMatch);
void ChangeSelected(int32_t iSel);
- void SetNotifyOwner(bool notify) { m_bNotifyOwner = notify; }
private:
+ CFWL_ComboList(CFWL_App* app,
+ const Properties& properties,
+ CFWL_Widget* pOuter);
+
CFX_PointF ClientToOuter(const CFX_PointF& point);
void OnDropListFocusChanged(CFWL_Message* pMsg, bool bSet);
void OnDropListMouseMove(CFWL_MessageMouse* pMsg);
diff --git a/xfa/fwl/cfwl_datetimeedit.cpp b/xfa/fwl/cfwl_datetimeedit.cpp
index 313e89a36..2acf69088 100644
--- a/xfa/fwl/cfwl_datetimeedit.cpp
+++ b/xfa/fwl/cfwl_datetimeedit.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,38 +6,34 @@
#include "xfa/fwl/cfwl_datetimeedit.h"
-#include <memory>
-#include <utility>
-
#include "xfa/fwl/cfwl_datetimepicker.h"
#include "xfa/fwl/cfwl_messagemouse.h"
#include "xfa/fwl/cfwl_widgetmgr.h"
-CFWL_DateTimeEdit::CFWL_DateTimeEdit(
- const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter)
- : CFWL_Edit(app, std::move(properties), pOuter) {}
+CFWL_DateTimeEdit::CFWL_DateTimeEdit(CFWL_App* app,
+ const Properties& properties,
+ CFWL_Widget* pOuter)
+ : CFWL_Edit(app, properties, pOuter) {}
CFWL_DateTimeEdit::~CFWL_DateTimeEdit() = default;
void CFWL_DateTimeEdit::OnProcessMessage(CFWL_Message* pMessage) {
- if (pMessage->GetType() != CFWL_Message::Type::Mouse) {
+ if (pMessage->GetType() != CFWL_Message::Type::kMouse) {
CFWL_Edit::OnProcessMessage(pMessage);
return;
}
CFWL_MessageMouse* pMouse = static_cast<CFWL_MessageMouse*>(pMessage);
- if (pMouse->m_dwCmd == FWL_MouseCommand::LeftButtonDown ||
- pMouse->m_dwCmd == FWL_MouseCommand::RightButtonDown) {
- if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)
- m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
+ if (pMouse->m_dwCmd == CFWL_MessageMouse::MouseCommand::kLeftButtonDown ||
+ pMouse->m_dwCmd == CFWL_MessageMouse::MouseCommand::kRightButtonDown) {
+ if ((m_Properties.m_dwStates & FWL_STATE_WGT_Focused) == 0)
+ m_Properties.m_dwStates |= FWL_STATE_WGT_Focused;
CFWL_DateTimePicker* pDateTime =
- static_cast<CFWL_DateTimePicker*>(m_pOuter);
+ static_cast<CFWL_DateTimePicker*>(GetOuter());
if (pDateTime->IsMonthCalendarVisible()) {
CFX_RectF rtInvalidate = pDateTime->GetWidgetRect();
- pDateTime->ShowMonthCalendar(false);
+ pDateTime->HideMonthCalendar();
rtInvalidate.Offset(-rtInvalidate.left, -rtInvalidate.top);
pDateTime->RepaintRect(rtInvalidate);
}
diff --git a/xfa/fwl/cfwl_datetimeedit.h b/xfa/fwl/cfwl_datetimeedit.h
index e617ff486..a34d790b2 100644
--- a/xfa/fwl/cfwl_datetimeedit.h
+++ b/xfa/fwl/cfwl_datetimeedit.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,21 +7,21 @@
#ifndef XFA_FWL_CFWL_DATETIMEEDIT_H_
#define XFA_FWL_CFWL_DATETIMEEDIT_H_
-#include <memory>
-
#include "xfa/fwl/cfwl_edit.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fwl/cfwl_widgetproperties.h"
class CFWL_DateTimeEdit final : public CFWL_Edit {
public:
- CFWL_DateTimeEdit(const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_DateTimeEdit() override;
- // CFWL_Edit.
+ // CFWL_Edit:
void OnProcessMessage(CFWL_Message* pMessage) override;
+
+ private:
+ CFWL_DateTimeEdit(CFWL_App* app,
+ const Properties& properties,
+ CFWL_Widget* pOuter);
};
#endif // XFA_FWL_CFWL_DATETIMEEDIT_H_
diff --git a/xfa/fwl/cfwl_datetimepicker.cpp b/xfa/fwl/cfwl_datetimepicker.cpp
index 11ea81088..dd0cf212e 100644
--- a/xfa/fwl/cfwl_datetimepicker.cpp
+++ b/xfa/fwl/cfwl_datetimepicker.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,10 +6,7 @@
#include "xfa/fwl/cfwl_datetimepicker.h"
-#include <memory>
-#include <utility>
-
-#include "third_party/base/ptr_util.h"
+#include "xfa/fwl/cfwl_app.h"
#include "xfa/fwl/cfwl_event.h"
#include "xfa/fwl/cfwl_eventselectchanged.h"
#include "xfa/fwl/cfwl_messagemouse.h"
@@ -21,36 +18,44 @@
namespace {
-const int kDateTimePickerHeight = 20;
+constexpr int kDateTimePickerHeight = 20;
} // namespace
-CFWL_DateTimePicker::CFWL_DateTimePicker(const CFWL_App* app)
- : CFWL_Widget(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr) {
- m_pProperties->m_dwStyleExes = FWL_STYLEEXT_DTP_ShortDateFormat;
-
- auto monthProp = pdfium::MakeUnique<CFWL_WidgetProperties>();
- monthProp->m_dwStyles = FWL_WGTSTYLE_Popup | FWL_WGTSTYLE_Border;
- monthProp->m_dwStates = FWL_WGTSTATE_Invisible;
- monthProp->m_pParent = this;
- monthProp->m_pThemeProvider = m_pProperties->m_pThemeProvider;
- m_pMonthCal = pdfium::MakeUnique<CFWL_MonthCalendar>(
- m_pOwnerApp.Get(), std::move(monthProp), this);
+CFWL_DateTimePicker::CFWL_DateTimePicker(CFWL_App* app)
+ : CFWL_Widget(app,
+ Properties{0, FWL_STYLEEXT_DTP_ShortDateFormat, 0},
+ nullptr),
+ m_pEdit(cppgc::MakeGarbageCollected<CFWL_DateTimeEdit>(
+ app->GetHeap()->GetAllocationHandle(),
+ app,
+ Properties(),
+ this)),
+ m_pMonthCal(cppgc::MakeGarbageCollected<CFWL_MonthCalendar>(
+ app->GetHeap()->GetAllocationHandle(),
+ app,
+ Properties{FWL_STYLE_WGT_Popup | FWL_STYLE_WGT_Border, 0,
+ FWL_STATE_WGT_Invisible},
+ this)) {
m_pMonthCal->SetWidgetRect(
CFX_RectF(0, 0, m_pMonthCal->GetAutosizedWidgetRect().Size()));
- auto editProp = pdfium::MakeUnique<CFWL_WidgetProperties>();
- editProp->m_pParent = this;
- editProp->m_pThemeProvider = m_pProperties->m_pThemeProvider;
-
- m_pEdit = pdfium::MakeUnique<CFWL_DateTimeEdit>(m_pOwnerApp.Get(),
- std::move(editProp), this);
- RegisterEventTarget(m_pMonthCal.get());
- RegisterEventTarget(m_pEdit.get());
+ CFWL_NoteDriver* pNoteDriver = GetFWLApp()->GetNoteDriver();
+ pNoteDriver->RegisterEventTarget(this, m_pMonthCal);
+ pNoteDriver->RegisterEventTarget(this, m_pEdit);
}
-CFWL_DateTimePicker::~CFWL_DateTimePicker() {
+CFWL_DateTimePicker::~CFWL_DateTimePicker() = default;
+
+void CFWL_DateTimePicker::PreFinalize() {
UnregisterEventTarget();
+ CFWL_Widget::PreFinalize();
+}
+
+void CFWL_DateTimePicker::Trace(cppgc::Visitor* visitor) const {
+ CFWL_Widget::Trace(visitor);
+ visitor->Trace(m_pEdit);
+ visitor->Trace(m_pMonthCal);
}
FWL_Type CFWL_DateTimePicker::GetClassID() const {
@@ -58,24 +63,15 @@ FWL_Type CFWL_DateTimePicker::GetClassID() const {
}
void CFWL_DateTimePicker::Update() {
- if (m_iLock)
+ if (IsLocked())
return;
- if (!m_pProperties->m_pThemeProvider)
- m_pProperties->m_pThemeProvider = GetAvailableTheme();
- m_pEdit->SetThemeProvider(m_pProperties->m_pThemeProvider.Get());
- m_rtClient = GetClientRect();
- m_pEdit->SetWidgetRect(m_rtClient);
+ m_ClientRect = GetClientRect();
+ m_pEdit->SetWidgetRect(m_ClientRect);
ResetEditAlignment();
m_pEdit->Update();
- if (!m_pMonthCal->GetThemeProvider())
- m_pMonthCal->SetThemeProvider(m_pProperties->m_pThemeProvider.Get());
- IFWL_ThemeProvider* theme = GetAvailableTheme();
- if (!theme)
- return;
-
- m_fBtn = theme->GetScrollBarWidth();
+ m_fBtn = GetThemeProvider()->GetScrollBarWidth();
CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect();
CFX_RectF rtPopUp(rtMonthCal.left, rtMonthCal.top + kDateTimePickerHeight,
rtMonthCal.width, rtMonthCal.height);
@@ -84,8 +80,7 @@ void CFWL_DateTimePicker::Update() {
}
FWL_WidgetHit CFWL_DateTimePicker::HitTest(const CFX_PointF& point) {
- CFX_RectF rect(0, 0, m_pProperties->m_rtWidget.width,
- m_pProperties->m_rtWidget.height);
+ CFX_RectF rect(0, 0, m_WidgetRect.width, m_WidgetRect.height);
if (rect.Contains(point))
return FWL_WidgetHit::Edit;
if (NeedsToShowButton())
@@ -99,23 +94,19 @@ FWL_WidgetHit CFWL_DateTimePicker::HitTest(const CFX_PointF& point) {
return FWL_WidgetHit::Unknown;
}
-void CFWL_DateTimePicker::DrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_DateTimePicker::DrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
if (!pGraphics)
return;
- IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get();
- if (!pTheme)
- return;
-
if (HasBorder())
- DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
- if (!m_rtBtn.IsEmpty())
- DrawDropDownButton(pGraphics, pTheme, &matrix);
+ DrawBorder(pGraphics, CFWL_ThemePart::Part::kBorder, matrix);
+
+ if (!m_BtnRect.IsEmpty())
+ DrawDropDownButton(pGraphics, matrix);
if (m_pEdit) {
CFX_RectF rtEdit = m_pEdit->GetWidgetRect();
-
CFX_Matrix mt(1, 0, 0, 1, rtEdit.left, rtEdit.top);
mt.Concat(matrix);
m_pEdit->DrawWidget(pGraphics, mt);
@@ -129,11 +120,6 @@ void CFWL_DateTimePicker::DrawWidget(CXFA_Graphics* pGraphics,
m_pMonthCal->DrawWidget(pGraphics, mt);
}
-void CFWL_DateTimePicker::SetThemeProvider(IFWL_ThemeProvider* pTP) {
- m_pProperties->m_pThemeProvider = pTP;
- m_pMonthCal->SetThemeProvider(pTP);
-}
-
void CFWL_DateTimePicker::GetCurSel(int32_t& iYear,
int32_t& iMonth,
int32_t& iDay) {
@@ -163,7 +149,7 @@ void CFWL_DateTimePicker::SetEditText(const WideString& wsText) {
return;
m_pEdit->SetText(wsText);
- RepaintRect(m_rtClient);
+ RepaintRect(m_ClientRect);
CFWL_Event ev(CFWL_Event::Type::EditChanged);
DispatchEvent(&ev);
@@ -173,82 +159,80 @@ WideString CFWL_DateTimePicker::GetEditText() const {
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;
}
CFX_RectF CFWL_DateTimePicker::GetBBox() const {
- CFX_RectF rect = m_pProperties->m_rtWidget;
+ CFX_RectF rect = m_WidgetRect;
if (NeedsToShowButton())
rect.width += m_fBtn;
if (!IsMonthCalendarVisible())
return rect;
CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect();
- rtMonth.Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top);
+ rtMonth.Offset(m_WidgetRect.left, m_WidgetRect.top);
rect.Union(rtMonth);
return rect;
}
-void CFWL_DateTimePicker::ModifyEditStylesEx(uint32_t dwStylesExAdded,
- uint32_t dwStylesExRemoved) {
- m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved);
+void CFWL_DateTimePicker::ModifyEditStyleExts(uint32_t dwStyleExtsAdded,
+ uint32_t dwStyleExtsRemoved) {
+ m_pEdit->ModifyStyleExts(dwStyleExtsAdded, dwStyleExtsRemoved);
}
-void CFWL_DateTimePicker::DrawDropDownButton(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeBackground param;
- param.m_pWidget = this;
- param.m_iPart = CFWL_Part::DropDownButton;
+void CFWL_DateTimePicker::DrawDropDownButton(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeBackground param(CFWL_ThemePart::Part::kDropDownButton, this,
+ pGraphics);
param.m_dwStates = m_iBtnState;
- param.m_pGraphics = pGraphics;
- param.m_rtPart = m_rtBtn;
- if (pMatrix)
- param.m_matrix.Concat(*pMatrix);
- pTheme->DrawBackground(param);
+ param.m_PartRect = m_BtnRect;
+ param.m_matrix = mtMatrix;
+ GetThemeProvider()->DrawBackground(param);
}
WideString CFWL_DateTimePicker::FormatDateString(int32_t iYear,
int32_t iMonth,
int32_t iDay) {
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_ShortDateFormat)
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_DTP_ShortDateFormat)
return WideString::Format(L"%d-%d-%d", iYear, iMonth, iDay);
return WideString::Format(L"%d Year %d Month %d Day", iYear, iMonth, iDay);
}
-void CFWL_DateTimePicker::ShowMonthCalendar(bool bActivate) {
- if (IsMonthCalendarVisible() == bActivate)
+void CFWL_DateTimePicker::ShowMonthCalendar() {
+ if (IsMonthCalendarVisible())
return;
- if (bActivate) {
- CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect();
- float fPopupMin = rtMonthCal.height;
- float fPopupMax = rtMonthCal.height;
- CFX_RectF rtAnchor(m_pProperties->m_rtWidget);
- rtAnchor.width = rtMonthCal.width;
- rtMonthCal.left = m_rtClient.left;
- rtMonthCal.top = rtAnchor.Height();
- GetPopupPos(fPopupMin, fPopupMax, rtAnchor, &rtMonthCal);
- m_pMonthCal->SetWidgetRect(rtMonthCal);
- if (m_iYear > 0 && m_iMonth > 0 && m_iDay > 0)
- m_pMonthCal->SetSelect(m_iYear, m_iMonth, m_iDay);
- m_pMonthCal->Update();
- }
- if (bActivate)
- m_pMonthCal->RemoveStates(FWL_WGTSTATE_Invisible);
- else
- m_pMonthCal->SetStates(FWL_WGTSTATE_Invisible);
+ CFX_RectF rtMonthCal = m_pMonthCal->GetAutosizedWidgetRect();
+ float fPopupMin = rtMonthCal.height;
+ float fPopupMax = rtMonthCal.height;
+ CFX_RectF rtAnchor = m_WidgetRect;
+ rtAnchor.width = rtMonthCal.width;
+ rtMonthCal.left = m_ClientRect.left;
+ rtMonthCal.top = rtAnchor.Height();
+ GetPopupPos(fPopupMin, fPopupMax, rtAnchor, &rtMonthCal);
+ m_pMonthCal->SetWidgetRect(rtMonthCal);
+ if (m_iYear > 0 && m_iMonth > 0 && m_iDay > 0)
+ m_pMonthCal->SetSelect(m_iYear, m_iMonth, m_iDay);
+ m_pMonthCal->Update();
+ m_pMonthCal->RemoveStates(FWL_STATE_WGT_Invisible);
- if (bActivate) {
- CFWL_MessageSetFocus msg(m_pEdit.get(), m_pMonthCal.get());
- m_pEdit->GetDelegate()->OnProcessMessage(&msg);
- }
+ CFWL_MessageSetFocus msg(m_pMonthCal);
+ m_pEdit->GetDelegate()->OnProcessMessage(&msg);
+ RepaintInflatedMonthCalRect();
+}
- CFX_RectF rtInvalidate(0, 0, m_pProperties->m_rtWidget.width,
- m_pProperties->m_rtWidget.height);
+void CFWL_DateTimePicker::HideMonthCalendar() {
+ if (!IsMonthCalendarVisible())
+ return;
+ m_pMonthCal->SetStates(FWL_STATE_WGT_Invisible);
+ RepaintInflatedMonthCalRect();
+}
+
+void CFWL_DateTimePicker::RepaintInflatedMonthCalRect() {
+ CFX_RectF rtInvalidate(0, 0, m_WidgetRect.width, m_WidgetRect.height);
CFX_RectF rtCal = m_pMonthCal->GetWidgetRect();
rtInvalidate.Union(rtCal);
rtInvalidate.Inflate(2, 2);
@@ -264,7 +248,7 @@ void CFWL_DateTimePicker::ResetEditAlignment() {
return;
uint32_t dwAdd = 0;
- switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditHAlignMask) {
+ switch (m_Properties.m_dwStyleExts & FWL_STYLEEXT_DTP_EditHAlignMask) {
case FWL_STYLEEXT_DTP_EditHCenter: {
dwAdd |= FWL_STYLEEXT_EDT_HCenter;
break;
@@ -278,7 +262,7 @@ void CFWL_DateTimePicker::ResetEditAlignment() {
break;
}
}
- switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditVAlignMask) {
+ switch (m_Properties.m_dwStyleExts & FWL_STYLEEXT_DTP_EditVAlignMask) {
case FWL_STYLEEXT_DTP_EditVCenter: {
dwAdd |= FWL_STYLEEXT_EDT_VCenter;
break;
@@ -292,12 +276,12 @@ void CFWL_DateTimePicker::ResetEditAlignment() {
break;
}
}
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_DTP_EditJustified)
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_DTP_EditJustified)
dwAdd |= FWL_STYLEEXT_EDT_Justified;
- m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask |
- FWL_STYLEEXT_EDT_HAlignModeMask |
- FWL_STYLEEXT_EDT_VAlignMask);
+ m_pEdit->ModifyStyleExts(dwAdd, FWL_STYLEEXT_EDT_HAlignMask |
+ FWL_STYLEEXT_EDT_HAlignModeMask |
+ FWL_STYLEEXT_EDT_VAlignMask);
}
void CFWL_DateTimePicker::ProcessSelChanged(int32_t iYear,
@@ -306,49 +290,41 @@ void CFWL_DateTimePicker::ProcessSelChanged(int32_t iYear,
m_iYear = iYear;
m_iMonth = iMonth;
m_iDay = iDay;
-
- WideString wsText = FormatDateString(m_iYear, m_iMonth, m_iDay);
- m_pEdit->SetText(wsText);
+ m_pEdit->SetText(FormatDateString(m_iYear, m_iMonth, m_iDay));
m_pEdit->Update();
- RepaintRect(m_rtClient);
+ RepaintRect(m_ClientRect);
- CFWL_EventSelectChanged ev(this);
- ev.iYear = m_iYear;
- ev.iMonth = m_iMonth;
- ev.iDay = m_iDay;
+ CFWL_EventSelectChanged ev(this, m_iYear, m_iMonth, m_iDay);
DispatchEvent(&ev);
}
bool CFWL_DateTimePicker::NeedsToShowButton() const {
- return m_pProperties->m_dwStates & FWL_WGTSTATE_Focused ||
- m_pMonthCal->GetStates() & FWL_WGTSTATE_Focused ||
- m_pEdit->GetStates() & FWL_WGTSTATE_Focused;
+ return m_Properties.m_dwStates & FWL_STATE_WGT_Focused ||
+ m_pMonthCal->GetStates() & FWL_STATE_WGT_Focused ||
+ m_pEdit->GetStates() & FWL_STATE_WGT_Focused;
}
void CFWL_DateTimePicker::OnProcessMessage(CFWL_Message* pMessage) {
- if (!pMessage)
- return;
-
switch (pMessage->GetType()) {
- case CFWL_Message::Type::SetFocus:
- OnFocusChanged(pMessage, true);
+ case CFWL_Message::Type::kSetFocus:
+ OnFocusGained(pMessage);
break;
- case CFWL_Message::Type::KillFocus:
- OnFocusChanged(pMessage, false);
+ case CFWL_Message::Type::kKillFocus:
+ OnFocusLost(pMessage);
break;
- case CFWL_Message::Type::Mouse: {
+ case CFWL_Message::Type::kMouse: {
CFWL_MessageMouse* pMouse = static_cast<CFWL_MessageMouse*>(pMessage);
switch (pMouse->m_dwCmd) {
- case FWL_MouseCommand::LeftButtonDown:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonDown:
OnLButtonDown(pMouse);
break;
- case FWL_MouseCommand::LeftButtonUp:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonUp:
OnLButtonUp(pMouse);
break;
- case FWL_MouseCommand::Move:
+ case CFWL_MessageMouse::MouseCommand::kMove:
OnMouseMove(pMouse);
break;
- case FWL_MouseCommand::Leave:
+ case CFWL_MessageMouse::MouseCommand::kLeave:
OnMouseLeave(pMouse);
break;
default:
@@ -356,8 +332,8 @@ void CFWL_DateTimePicker::OnProcessMessage(CFWL_Message* pMessage) {
}
break;
}
- case CFWL_Message::Type::Key: {
- if (m_pEdit->GetStates() & FWL_WGTSTATE_Focused) {
+ case CFWL_Message::Type::kKey: {
+ if (m_pEdit->GetStates() & FWL_STATE_WGT_Focused) {
m_pEdit->GetDelegate()->OnProcessMessage(pMessage);
return;
}
@@ -371,35 +347,31 @@ void CFWL_DateTimePicker::OnProcessMessage(CFWL_Message* pMessage) {
CFWL_Widget::OnProcessMessage(pMessage);
}
-void CFWL_DateTimePicker::OnDrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_DateTimePicker::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
DrawWidget(pGraphics, matrix);
}
-void CFWL_DateTimePicker::OnFocusChanged(CFWL_Message* pMsg, bool bSet) {
- if (!pMsg)
- return;
+void CFWL_DateTimePicker::OnFocusGained(CFWL_Message* pMsg) {
+ m_Properties.m_dwStates |= FWL_STATE_WGT_Focused;
+ if (m_pEdit && !(m_pEdit->GetStyleExts() & FWL_STYLEEXT_EDT_ReadOnly)) {
+ m_BtnRect =
+ CFX_RectF(m_WidgetRect.width, 0, m_fBtn, m_WidgetRect.height - 1);
+ }
+ CFX_RectF rtInvalidate(m_BtnRect);
+ pMsg->SetDstTarget(m_pEdit);
+ m_pEdit->GetDelegate()->OnProcessMessage(pMsg);
+ rtInvalidate.Inflate(2, 2);
+ RepaintRect(rtInvalidate);
+}
- CFX_RectF rtInvalidate(m_rtBtn);
- if (bSet) {
- m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
- if (m_pEdit && !(m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly)) {
- m_rtBtn = CFX_RectF(m_pProperties->m_rtWidget.width, 0, m_fBtn,
- m_pProperties->m_rtWidget.height - 1);
- }
- rtInvalidate = m_rtBtn;
- pMsg->SetDstTarget(m_pEdit.get());
+void CFWL_DateTimePicker::OnFocusLost(CFWL_Message* pMsg) {
+ CFX_RectF rtInvalidate(m_BtnRect);
+ m_Properties.m_dwStates &= ~FWL_STATE_WGT_Focused;
+ m_BtnRect = CFX_RectF();
+ HideMonthCalendar();
+ if (m_pEdit->GetStates() & FWL_STATE_WGT_Focused)
m_pEdit->GetDelegate()->OnProcessMessage(pMsg);
- } else {
- m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
- m_rtBtn = CFX_RectF();
- if (IsMonthCalendarVisible())
- ShowMonthCalendar(false);
- if (m_pEdit->GetStates() & FWL_WGTSTATE_Focused) {
- pMsg->SetSrcTarget(m_pEdit.get());
- m_pEdit->GetDelegate()->OnProcessMessage(pMsg);
- }
- }
rtInvalidate.Inflate(2, 2);
RepaintRect(rtInvalidate);
}
@@ -407,17 +379,16 @@ void CFWL_DateTimePicker::OnFocusChanged(CFWL_Message* pMsg, bool bSet) {
void CFWL_DateTimePicker::OnLButtonDown(CFWL_MessageMouse* pMsg) {
if (!pMsg)
return;
- if (!m_rtBtn.Contains(pMsg->m_pos))
+ if (!m_BtnRect.Contains(pMsg->m_pos))
return;
if (IsMonthCalendarVisible()) {
- ShowMonthCalendar(false);
+ HideMonthCalendar();
return;
}
- ShowMonthCalendar(true);
-
+ ShowMonthCalendar();
m_bLBtnDown = true;
- RepaintRect(m_rtClient);
+ RepaintRect(m_ClientRect);
}
void CFWL_DateTimePicker::OnLButtonUp(CFWL_MessageMouse* pMsg) {
@@ -425,32 +396,32 @@ void CFWL_DateTimePicker::OnLButtonUp(CFWL_MessageMouse* pMsg) {
return;
m_bLBtnDown = false;
- if (m_rtBtn.Contains(pMsg->m_pos))
- m_iBtnState = CFWL_PartState_Hovered;
+ if (m_BtnRect.Contains(pMsg->m_pos))
+ m_iBtnState = CFWL_PartState::kHovered;
else
- m_iBtnState = CFWL_PartState_Normal;
- RepaintRect(m_rtBtn);
+ m_iBtnState = CFWL_PartState::kNormal;
+ RepaintRect(m_BtnRect);
}
void CFWL_DateTimePicker::OnMouseMove(CFWL_MessageMouse* pMsg) {
- if (!m_rtBtn.Contains(pMsg->m_pos))
- m_iBtnState = CFWL_PartState_Normal;
- RepaintRect(m_rtBtn);
+ if (!m_BtnRect.Contains(pMsg->m_pos))
+ m_iBtnState = CFWL_PartState::kNormal;
+ RepaintRect(m_BtnRect);
}
void CFWL_DateTimePicker::OnMouseLeave(CFWL_MessageMouse* pMsg) {
if (!pMsg)
return;
- m_iBtnState = CFWL_PartState_Normal;
- RepaintRect(m_rtBtn);
+ m_iBtnState = CFWL_PartState::kNormal;
+ RepaintRect(m_BtnRect);
}
void CFWL_DateTimePicker::GetPopupPos(float fMinHeight,
float fMaxHeight,
const CFX_RectF& rtAnchor,
CFX_RectF* pPopupRect) {
- m_pWidgetMgr->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor,
- pPopupRect);
+ GetWidgetMgr()->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor,
+ pPopupRect);
}
void CFWL_DateTimePicker::ClearText() {
@@ -465,11 +436,11 @@ void CFWL_DateTimePicker::ClearSelection() {
m_pEdit->ClearSelection();
}
-Optional<WideString> CFWL_DateTimePicker::Copy() {
+absl::optional<WideString> CFWL_DateTimePicker::Copy() {
return m_pEdit->Copy();
}
-Optional<WideString> CFWL_DateTimePicker::Cut() {
+absl::optional<WideString> CFWL_DateTimePicker::Cut() {
return m_pEdit->Cut();
}
diff --git a/xfa/fwl/cfwl_datetimepicker.h b/xfa/fwl/cfwl_datetimepicker.h
index 69520ebe0..75c73ac0e 100644
--- a/xfa/fwl/cfwl_datetimepicker.h
+++ b/xfa/fwl/cfwl_datetimepicker.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,14 +7,13 @@
#ifndef XFA_FWL_CFWL_DATETIMEPICKER_H_
#define XFA_FWL_CFWL_DATETIMEPICKER_H_
-#include <memory>
#include <utility>
+#include "v8/include/cppgc/member.h"
#include "xfa/fwl/cfwl_datetimeedit.h"
#include "xfa/fwl/cfwl_event.h"
#include "xfa/fwl/cfwl_monthcalendar.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fwl/cfwl_widgetproperties.h"
#define FWL_STYLEEXT_DTP_ShortDateFormat (1L << 1)
#define FWL_STYLEEXT_DTP_EditHAlignMask (3L << 4)
@@ -31,24 +30,26 @@ class CFWL_DateTimeEdit;
class CFWL_DateTimePicker final : public CFWL_Widget {
public:
- explicit CFWL_DateTimePicker(const CFWL_App* pApp);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_DateTimePicker() override;
- // CFWL_Widget
+ // CFWL_Widget:
+ void PreFinalize() override;
+ void Trace(cppgc::Visitor* visitor) const override;
FWL_Type GetClassID() const override;
void Update() override;
FWL_WidgetHit HitTest(const CFX_PointF& point) override;
- void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
- void SetThemeProvider(IFWL_ThemeProvider* pTP) override;
+ void DrawWidget(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& matrix) override;
void OnProcessMessage(CFWL_Message* pMessage) override;
- void OnDrawWidget(CXFA_Graphics* pGraphics,
+ void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) override;
void GetCurSel(int32_t& iYear, int32_t& iMonth, int32_t& iDay);
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();
@@ -59,8 +60,8 @@ class CFWL_DateTimePicker final : public CFWL_Widget {
std::pair<size_t, size_t> GetSelection() const {
return m_pEdit->GetSelection();
}
- Optional<WideString> Copy();
- Optional<WideString> Cut();
+ absl::optional<WideString> Copy();
+ absl::optional<WideString> Cut();
bool Paste(const WideString& wsPaste);
bool Undo();
bool Redo();
@@ -69,40 +70,44 @@ class CFWL_DateTimePicker final : public CFWL_Widget {
CFX_RectF GetBBox() const;
void SetEditLimit(int32_t nLimit) { m_pEdit->SetLimit(nLimit); }
- void ModifyEditStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved);
+ void ModifyEditStyleExts(uint32_t dwStyleExtsAdded,
+ uint32_t dwStyleExtsRemoved);
bool IsMonthCalendarVisible() const;
- void ShowMonthCalendar(bool bActivate);
+ void ShowMonthCalendar();
+ void HideMonthCalendar();
void ProcessSelChanged(int32_t iYear, int32_t iMonth, int32_t iDay);
private:
- void DrawDropDownButton(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
+ explicit CFWL_DateTimePicker(CFWL_App* pApp);
+
+ void DrawDropDownButton(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix);
WideString FormatDateString(int32_t iYear, int32_t iMonth, int32_t iDay);
void ResetEditAlignment();
void GetPopupPos(float fMinHeight,
float fMaxHeight,
const CFX_RectF& rtAnchor,
CFX_RectF* pPopupRect);
- void OnFocusChanged(CFWL_Message* pMsg, bool bSet);
+ void OnFocusGained(CFWL_Message* pMsg);
+ void OnFocusLost(CFWL_Message* pMsg);
void OnLButtonDown(CFWL_MessageMouse* pMsg);
void OnLButtonUp(CFWL_MessageMouse* pMsg);
void OnMouseMove(CFWL_MessageMouse* pMsg);
void OnMouseLeave(CFWL_MessageMouse* pMsg);
-
bool NeedsToShowButton() const;
+ void RepaintInflatedMonthCalRect();
bool m_bLBtnDown = false;
- int32_t m_iBtnState = 1;
+ Mask<CFWL_PartState> m_iBtnState = CFWL_PartState::kChecked;
int32_t m_iYear = -1;
int32_t m_iMonth = -1;
int32_t m_iDay = -1;
float m_fBtn = 0.0f;
- CFX_RectF m_rtBtn;
- CFX_RectF m_rtClient;
- std::unique_ptr<CFWL_DateTimeEdit> m_pEdit;
- std::unique_ptr<CFWL_MonthCalendar> m_pMonthCal;
+ CFX_RectF m_BtnRect;
+ CFX_RectF m_ClientRect;
+ cppgc::Member<CFWL_DateTimeEdit> const m_pEdit;
+ cppgc::Member<CFWL_MonthCalendar> const m_pMonthCal;
};
#endif // XFA_FWL_CFWL_DATETIMEPICKER_H_
diff --git a/xfa/fwl/cfwl_edit.cpp b/xfa/fwl/cfwl_edit.cpp
index 1f265b5a3..f95176db3 100644
--- a/xfa/fwl/cfwl_edit.cpp
+++ b/xfa/fwl/cfwl_edit.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -14,10 +14,14 @@
#include "build/build_config.h"
#include "core/fxge/cfx_renderdevice.h"
#include "core/fxge/text_char_pos.h"
-#include "third_party/base/ptr_util.h"
-#include "third_party/base/stl_util.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"
+#include "xfa/fgas/graphics/cfgas_gegraphics.h"
+#include "xfa/fgas/graphics/cfgas_gepath.h"
#include "xfa/fwl/cfwl_app.h"
#include "xfa/fwl/cfwl_caret.h"
#include "xfa/fwl/cfwl_event.h"
@@ -31,32 +35,40 @@
#include "xfa/fwl/fwl_widgetdef.h"
#include "xfa/fwl/ifwl_themeprovider.h"
#include "xfa/fwl/theme/cfwl_utils.h"
-#include "xfa/fxgraphics/cxfa_gepath.h"
namespace {
constexpr int kEditMargin = 3;
-#if defined(OS_MACOSX)
-constexpr int kEditingModifier = FWL_KEYFLAG_Command;
+#if BUILDFLAG(IS_APPLE)
+constexpr XFA_FWL_KeyFlag kEditingModifier = XFA_FWL_KeyFlag::kCommand;
#else
-constexpr int kEditingModifier = FWL_KEYFLAG_Ctrl;
+constexpr XFA_FWL_KeyFlag kEditingModifier = XFA_FWL_KeyFlag::kCtrl;
#endif
} // namespace
-CFWL_Edit::CFWL_Edit(const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
+CFWL_Edit::CFWL_Edit(CFWL_App* app,
+ const Properties& properties,
CFWL_Widget* pOuter)
- : CFWL_Widget(app, std::move(properties), pOuter),
- m_pEditEngine(pdfium::MakeUnique<CFDE_TextEditEngine>()) {
+ : CFWL_Widget(app, properties, pOuter),
+ m_pEditEngine(std::make_unique<CFDE_TextEditEngine>()) {
m_pEditEngine->SetDelegate(this);
}
-CFWL_Edit::~CFWL_Edit() {
+CFWL_Edit::~CFWL_Edit() = default;
+
+void CFWL_Edit::PreFinalize() {
m_pEditEngine->SetDelegate(nullptr);
- if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Focused)
HideCaret(nullptr);
+ CFWL_Widget::PreFinalize();
+}
+
+void CFWL_Edit::Trace(cppgc::Visitor* visitor) const {
+ CFWL_Widget::Trace(visitor);
+ visitor->Trace(m_pVertScrollBar);
+ visitor->Trace(m_pCaret);
}
FWL_Type CFWL_Edit::GetClassID() const {
@@ -64,39 +76,32 @@ FWL_Type CFWL_Edit::GetClassID() const {
}
CFX_RectF CFWL_Edit::GetWidgetRect() {
- CFX_RectF rect = m_pProperties->m_rtWidget;
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) {
- IFWL_ThemeProvider* theme = GetAvailableTheme();
- float scrollbarWidth = theme ? theme->GetScrollBarWidth() : 0.0f;
- if (IsShowScrollBar(true)) {
+ CFX_RectF rect = m_WidgetRect;
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_OuterScrollbar) {
+ float scrollbarWidth = GetThemeProvider()->GetScrollBarWidth();
+ if (IsShowVertScrollBar()) {
rect.width += scrollbarWidth;
rect.width += kEditMargin;
}
- if (IsShowScrollBar(false)) {
- rect.height += scrollbarWidth;
- rect.height += kEditMargin;
- }
}
return rect;
}
CFX_RectF CFWL_Edit::GetAutosizedWidgetRect() {
CFX_RectF rect;
-
if (m_pEditEngine->GetLength() > 0) {
CFX_SizeF size = CalcTextSize(
- m_pEditEngine->GetText(), m_pProperties->m_pThemeProvider.Get(),
- !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine));
+ m_pEditEngine->GetText(),
+ !!(m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_MultiLine));
rect = CFX_RectF(0, 0, size);
}
-
InflateWidgetRect(rect);
return rect;
}
void CFWL_Edit::SetStates(uint32_t dwStates) {
- if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) ||
- (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) {
+ if ((m_Properties.m_dwStates & FWL_STATE_WGT_Invisible) ||
+ (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)) {
HideCaret(nullptr);
}
CFWL_Widget::SetStates(dwStates);
@@ -105,11 +110,9 @@ void CFWL_Edit::SetStates(uint32_t dwStates) {
void CFWL_Edit::Update() {
if (IsLocked())
return;
- if (!m_pProperties->m_pThemeProvider)
- m_pProperties->m_pThemeProvider = GetAvailableTheme();
Layout();
- if (m_rtClient.IsEmpty())
+ if (m_ClientRect.IsEmpty())
return;
UpdateEditEngine();
@@ -119,47 +122,28 @@ void CFWL_Edit::Update() {
}
FWL_WidgetHit CFWL_Edit::HitTest(const CFX_PointF& point) {
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) {
- if (IsShowScrollBar(true)) {
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_OuterScrollbar) {
+ if (IsShowVertScrollBar()) {
if (m_pVertScrollBar->GetWidgetRect().Contains(point))
return FWL_WidgetHit::VScrollBar;
}
- if (IsShowScrollBar(false)) {
- if (m_pHorzScrollBar->GetWidgetRect().Contains(point))
- return FWL_WidgetHit::HScrollBar;
- }
}
- if (m_rtClient.Contains(point))
+ if (m_ClientRect.Contains(point))
return FWL_WidgetHit::Edit;
return FWL_WidgetHit::Unknown;
}
-void CFWL_Edit::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) {
+void CFWL_Edit::DrawWidget(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& matrix) {
if (!pGraphics)
return;
- if (m_rtClient.IsEmpty())
- return;
-
- IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get();
- if (!pTheme)
+ if (m_ClientRect.IsEmpty())
return;
- DrawContent(pGraphics, pTheme, &matrix);
+ DrawContent(pGraphics, matrix);
if (HasBorder())
- DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
-}
-
-void CFWL_Edit::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
- if (!pThemeProvider)
- return;
- if (m_pHorzScrollBar)
- m_pHorzScrollBar->SetThemeProvider(pThemeProvider);
- if (m_pVertScrollBar)
- m_pVertScrollBar->SetThemeProvider(pThemeProvider);
- if (m_pCaret)
- m_pCaret->SetThemeProvider(pThemeProvider);
- m_pProperties->m_pThemeProvider = pThemeProvider;
+ DrawBorder(pGraphics, CFWL_ThemePart::Part::kBorder, matrix);
}
void CFWL_Edit::SetText(const WideString& wsText) {
@@ -174,7 +158,7 @@ void CFWL_Edit::SetTextSkipNotify(const WideString& wsText) {
CFDE_TextEditEngine::RecordOperation::kSkipNotify);
}
-int32_t CFWL_Edit::GetTextLength() const {
+size_t CFWL_Edit::GetTextLength() const {
return m_pEditEngine->GetLength();
}
@@ -221,20 +205,20 @@ void CFWL_Edit::SetAliasChar(wchar_t wAlias) {
m_pEditEngine->SetAliasChar(wAlias);
}
-Optional<WideString> CFWL_Edit::Copy() {
+absl::optional<WideString> CFWL_Edit::Copy() {
if (!m_pEditEngine->HasSelection())
- return {};
+ return absl::nullopt;
- return {m_pEditEngine->GetSelectedText()};
+ return m_pEditEngine->GetSelectedText();
}
-Optional<WideString> CFWL_Edit::Cut() {
+absl::optional<WideString> CFWL_Edit::Cut() {
if (!m_pEditEngine->HasSelection())
- return {};
+ return absl::nullopt;
WideString cut_text = m_pEditEngine->DeleteSelectedText();
UpdateCaret();
- return {cut_text};
+ return cut_text;
}
bool CFWL_Edit::Paste(const WideString& wsPaste) {
@@ -262,26 +246,22 @@ bool CFWL_Edit::CanRedo() {
return m_pEditEngine->CanRedo();
}
-void CFWL_Edit::SetOuter(CFWL_Widget* pOuter) {
- m_pOuter = pOuter;
-}
-
void CFWL_Edit::NotifyTextFull() {
CFWL_Event evt(CFWL_Event::Type::TextFull, this);
DispatchEvent(&evt);
}
void CFWL_Edit::OnCaretChanged() {
- if (m_rtEngine.IsEmpty())
+ if (m_EngineRect.IsEmpty())
return;
- if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)
+ if ((m_Properties.m_dwStates & FWL_STATE_WGT_Focused) == 0)
return;
bool bRepaintContent = UpdateOffset();
UpdateCaret();
CFX_RectF rtInvalid;
bool bRepaintScroll = false;
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) {
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_MultiLine) {
CFWL_ScrollBar* pScroll = UpdateScroll();
if (pScroll) {
rtInvalid = pScroll->GetWidgetRect();
@@ -290,29 +270,25 @@ void CFWL_Edit::OnCaretChanged() {
}
if (bRepaintContent || bRepaintScroll) {
if (bRepaintContent)
- rtInvalid.Union(m_rtEngine);
+ rtInvalid.Union(m_EngineRect);
RepaintRect(rtInvalid);
}
}
void CFWL_Edit::OnTextWillChange(CFDE_TextEditEngine::TextChange* change) {
- CFWL_EventTextWillChange event(this);
- event.previous_text = change->previous_text;
- event.change_text = change->text;
- event.selection_start = change->selection_start;
- event.selection_end = change->selection_end;
- event.cancelled = false;
-
+ CFWL_EventTextWillChange event(this, change->text, change->previous_text,
+ change->selection_start,
+ change->selection_end);
DispatchEvent(&event);
- change->text = event.change_text;
- change->selection_start = event.selection_start;
- change->selection_end = event.selection_end;
- change->cancelled = event.cancelled;
+ change->text = event.GetChangeText();
+ change->selection_start = event.GetSelectionStart();
+ change->selection_end = event.GetSelectionEnd();
+ change->cancelled = event.GetCancelled();
}
void CFWL_Edit::OnTextChanged() {
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VAlignMask)
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_VAlignMask)
UpdateVAlignment();
LayoutScrollBar();
@@ -324,76 +300,57 @@ void CFWL_Edit::OnSelChanged() {
}
bool CFWL_Edit::OnValidate(const WideString& wsText) {
- CFWL_EventValidate event(this);
- event.wsInsert = wsText;
- event.bValidate = true;
+ CFWL_EventValidate event(this, wsText);
DispatchEvent(&event);
- return event.bValidate;
+ return event.GetValidate();
}
void CFWL_Edit::SetScrollOffset(float fScrollOffset) {
m_fScrollOffsetY = fScrollOffset;
}
-void CFWL_Edit::DrawTextBk(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeBackground param;
- param.m_pWidget = this;
- param.m_iPart = CFWL_Part::Background;
- param.m_bStaticBackground = false;
- param.m_dwStates = m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly
- ? CFWL_PartState_ReadOnly
- : CFWL_PartState_Normal;
- uint32_t dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled);
- if (dwStates)
- param.m_dwStates = CFWL_PartState_Disabled;
- param.m_pGraphics = pGraphics;
- param.m_matrix = *pMatrix;
- param.m_rtPart = m_rtClient;
- pTheme->DrawBackground(param);
-
- if (!IsShowScrollBar(true) || !IsShowScrollBar(false))
- return;
-
- CFX_RectF rtScroll = m_pHorzScrollBar->GetWidgetRect();
-
- CFX_RectF rtStatic(m_rtClient.right() - rtScroll.height,
- m_rtClient.bottom() - rtScroll.height, rtScroll.height,
- rtScroll.height);
- param.m_bStaticBackground = true;
- param.m_bMaximize = true;
- param.m_rtPart = rtStatic;
- pTheme->DrawBackground(param);
+void CFWL_Edit::DrawContent(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ DrawContentNonComb(pGraphics, mtMatrix);
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_CombText) {
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ CFGAS_GEPath path;
+ const int32_t iLimit = m_nLimit > 0 ? m_nLimit : 1;
+ const float fStep = m_EngineRect.width / iLimit;
+ float fLeft = m_EngineRect.left + 1;
+ for (int32_t i = 1; i < iLimit; i++) {
+ fLeft += fStep;
+ path.AddLine(CFX_PointF(fLeft, m_ClientRect.top),
+ CFX_PointF(fLeft, m_ClientRect.bottom()));
+ }
+ CFWL_ThemeBackground param(CFWL_ThemePart::Part::kCombTextLine, this,
+ pGraphics);
+ param.m_matrix = mtMatrix;
+ param.SetPath(&path);
+ GetThemeProvider()->DrawBackground(param);
+ }
}
-void CFWL_Edit::DrawContent(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- pGraphics->SaveGraphState();
-
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText)
- pGraphics->SaveGraphState();
-
- CFX_RectF rtClip = m_rtEngine;
- float fOffSetX = m_rtEngine.left - m_fScrollOffsetX;
- float fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset;
-
+void CFWL_Edit::DrawContentNonComb(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ CFX_RectF rtClip = m_EngineRect;
+ float fOffSetX = m_EngineRect.left - m_fScrollOffsetX;
+ float fOffSetY = m_EngineRect.top - m_fScrollOffsetY + m_fVAlignOffset;
CFX_Matrix mt(1, 0, 0, 1, fOffSetX, fOffSetY);
- if (pMatrix) {
- rtClip = pMatrix->TransformRect(rtClip);
- mt.Concat(*pMatrix);
- }
+ rtClip = mtMatrix.TransformRect(rtClip);
+ mt.Concat(mtMatrix);
- bool bShowSel = !!(m_pProperties->m_dwStates & FWL_WGTSTATE_Focused);
+ bool bShowSel = !!(m_Properties.m_dwStates & FWL_STATE_WGT_Focused);
if (bShowSel && m_pEditEngine->HasSelection()) {
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));
- CXFA_GEPath path;
+ CFGAS_GEPath path;
for (auto& rect : rects) {
rect.left += fOffSetX;
rect.top += fOffSetY;
@@ -401,46 +358,21 @@ void CFWL_Edit::DrawContent(CXFA_Graphics* pGraphics,
}
pGraphics->SetClipRect(rtClip);
- CFWL_ThemeBackground param;
- param.m_pGraphics = pGraphics;
- param.m_matrix = *pMatrix;
- param.m_pWidget = this;
- param.m_iPart = CFWL_Part::Background;
- param.m_pPath = &path;
- pTheme->DrawBackground(param);
+ CFWL_ThemeBackground param(CFWL_ThemePart::Part::kBackground, this,
+ pGraphics);
+ param.m_matrix = mtMatrix;
+ param.SetPath(&path);
+ GetThemeProvider()->DrawBackground(param);
}
CFX_RenderDevice* pRenderDev = pGraphics->GetRenderDevice();
RenderText(pRenderDev, rtClip, mt);
-
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) {
- pGraphics->RestoreGraphState();
-
- CXFA_GEPath path;
- int32_t iLimit = m_nLimit > 0 ? m_nLimit : 1;
- float fStep = m_rtEngine.width / iLimit;
- float fLeft = m_rtEngine.left + 1;
- for (int32_t i = 1; i < iLimit; i++) {
- fLeft += fStep;
- path.AddLine(CFX_PointF(fLeft, m_rtClient.top),
- CFX_PointF(fLeft, m_rtClient.bottom()));
- }
-
- CFWL_ThemeBackground param;
- param.m_pGraphics = pGraphics;
- param.m_matrix = *pMatrix;
- param.m_pWidget = this;
- param.m_iPart = CFWL_Part::CombTextLine;
- param.m_pPath = &path;
- pTheme->DrawBackground(param);
- }
- pGraphics->RestoreGraphState();
}
void CFWL_Edit::RenderText(CFX_RenderDevice* pRenderDev,
const CFX_RectF& clipRect,
const CFX_Matrix& mt) {
- ASSERT(pRenderDev);
+ DCHECK(pRenderDev);
RetainPtr<CFGAS_GEFont> font = m_pEditEngine->GetFont();
if (!font)
@@ -477,17 +409,17 @@ void CFWL_Edit::UpdateEditEngine() {
}
void CFWL_Edit::UpdateEditParams() {
- m_pEditEngine->SetAvailableWidth(m_rtEngine.width);
+ m_pEditEngine->SetAvailableWidth(m_EngineRect.width);
m_pEditEngine->SetCombText(
- !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText));
+ !!(m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_CombText));
m_pEditEngine->EnableValidation(
- !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Validate));
+ !!(m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_Validate));
m_pEditEngine->EnablePasswordMode(
- !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Password));
+ !!(m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_Password));
uint32_t alignment = 0;
- switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HAlignMask) {
+ switch (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_HAlignMask) {
case FWL_STYLEEXT_EDT_HNear: {
alignment |= CFX_TxtLineAlignment_Left;
break;
@@ -503,7 +435,7 @@ void CFWL_Edit::UpdateEditParams() {
default:
break;
}
- switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HAlignModeMask) {
+ switch (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_HAlignModeMask) {
case FWL_STYLEEXT_EDT_Justified: {
alignment |= CFX_TxtLineAlignment_Justified;
break;
@@ -514,13 +446,13 @@ void CFWL_Edit::UpdateEditParams() {
m_pEditEngine->SetAlignment(alignment);
bool auto_hscroll =
- !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoHScroll);
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) {
+ !!(m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_AutoHScroll);
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_MultiLine) {
m_pEditEngine->EnableMultiLine(true);
m_pEditEngine->EnableLineWrap(!auto_hscroll);
m_pEditEngine->LimitVerticalScroll(
- (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) == 0 &&
- (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoVScroll) == 0);
+ (m_Properties.m_dwStyles & FWL_STYLE_WGT_VScroll) == 0 &&
+ (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_AutoVScroll) == 0);
} else {
m_pEditEngine->EnableMultiLine(false);
m_pEditEngine->EnableLineWrap(false);
@@ -528,14 +460,8 @@ void CFWL_Edit::UpdateEditParams() {
}
m_pEditEngine->LimitHorizontalScroll(!auto_hscroll);
- IFWL_ThemeProvider* theme = GetAvailableTheme();
- CFWL_ThemePart part;
- part.m_pWidget = this;
-
- if (!theme) {
- m_fFontSize = FWLTHEME_CAPACITY_FontSize;
- return;
- }
+ IFWL_ThemeProvider* theme = GetThemeProvider();
+ CFWL_ThemePart part(CFWL_ThemePart::Part::kNone, this);
m_fFontSize = theme->GetFontSize(part);
RetainPtr<CFGAS_GEFont> pFont = theme->GetFont(part);
@@ -547,7 +473,7 @@ void CFWL_Edit::UpdateEditParams() {
m_pEditEngine->SetFontSize(m_fFontSize);
m_pEditEngine->SetLineSpace(theme->GetLineHeight(part));
m_pEditEngine->SetTabWidth(m_fFontSize);
- m_pEditEngine->SetVisibleLineCount(m_rtEngine.height /
+ m_pEditEngine->SetVisibleLineCount(m_EngineRect.height /
theme->GetLineHeight(part));
}
@@ -556,13 +482,13 @@ void CFWL_Edit::UpdateEditLayout() {
}
bool CFWL_Edit::UpdateOffset() {
- CFX_RectF rtCaret = m_rtCaret;
+ CFX_RectF rtCaret = m_CaretRect;
- float fOffSetX = m_rtEngine.left - m_fScrollOffsetX;
- float fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset;
+ float fOffSetX = m_EngineRect.left - m_fScrollOffsetX;
+ float fOffSetY = m_EngineRect.top - m_fScrollOffsetY + m_fVAlignOffset;
rtCaret.Offset(fOffSetX, fOffSetY);
- const CFX_RectF& edit_bounds = m_rtEngine;
+ const CFX_RectF& edit_bounds = m_EngineRect;
if (edit_bounds.Contains(rtCaret)) {
CFX_RectF contents_bounds = m_pEditEngine->GetContentsBoundingBox();
contents_bounds.Offset(fOffSetX, fOffSetY);
@@ -591,44 +517,34 @@ bool CFWL_Edit::UpdateOffset() {
m_fScrollOffsetX += offsetX;
m_fScrollOffsetY += offsetY;
- if (m_fFontSize > m_rtEngine.height)
+ if (m_fFontSize > m_EngineRect.height)
m_fScrollOffsetY = 0;
return true;
}
bool CFWL_Edit::UpdateOffset(CFWL_ScrollBar* pScrollBar, float fPosChanged) {
- if (pScrollBar == m_pHorzScrollBar.get())
- m_fScrollOffsetX += fPosChanged;
- else
- m_fScrollOffsetY += fPosChanged;
+ m_fScrollOffsetY += fPosChanged;
return true;
}
void CFWL_Edit::UpdateVAlignment() {
- float fSpaceAbove = 0.0f;
- float fSpaceBelow = 0.0f;
- IFWL_ThemeProvider* theme = GetAvailableTheme();
- if (theme) {
- CFWL_ThemePart part;
- part.m_pWidget = this;
-
- CFX_SizeF pSpace = theme->GetSpaceAboveBelow(part);
- fSpaceAbove = pSpace.width >= 0.1f ? pSpace.width : 0.0f;
- fSpaceBelow = pSpace.height >= 0.1f ? pSpace.height : 0.0f;
- }
-
+ IFWL_ThemeProvider* theme = GetThemeProvider();
+ CFWL_ThemePart part(CFWL_ThemePart::Part::kNone, this);
+ const CFX_SizeF pSpace = theme->GetSpaceAboveBelow(part);
+ const float fSpaceAbove = pSpace.width >= 0.1f ? pSpace.width : 0.0f;
+ const float fSpaceBelow = pSpace.height >= 0.1f ? pSpace.height : 0.0f;
float fOffsetY = 0.0f;
CFX_RectF contents_bounds = m_pEditEngine->GetContentsBoundingBox();
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VCenter) {
- fOffsetY = (m_rtEngine.height - contents_bounds.height) / 2.0f;
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_VCenter) {
+ fOffsetY = (m_EngineRect.height - contents_bounds.height) / 2.0f;
if (fOffsetY < (fSpaceAbove + fSpaceBelow) / 2.0f &&
fSpaceAbove < fSpaceBelow) {
return;
}
fOffsetY += (fSpaceAbove - fSpaceBelow) / 2.0f;
- } else if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VFar) {
- fOffsetY = (m_rtEngine.height - contents_bounds.height);
+ } else if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_VFar) {
+ fOffsetY = (m_EngineRect.height - contents_bounds.height);
fOffsetY -= fSpaceBelow;
} else {
fOffsetY += fSpaceAbove;
@@ -637,9 +553,9 @@ void CFWL_Edit::UpdateVAlignment() {
}
void CFWL_Edit::UpdateCaret() {
- CFX_RectF rtCaret = m_rtCaret;
- rtCaret.Offset(m_rtEngine.left - m_fScrollOffsetX,
- m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset);
+ CFX_RectF rtCaret = m_CaretRect;
+ rtCaret.Offset(m_EngineRect.left - m_fScrollOffsetX,
+ m_EngineRect.top - m_fScrollOffsetY + m_fVAlignOffset);
CFX_RectF rtClient = GetClientRect();
rtCaret.Intersect(rtClient);
@@ -649,251 +565,139 @@ void CFWL_Edit::UpdateCaret() {
rtCaret.width = right - rtCaret.left;
}
- if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && !rtCaret.IsEmpty())
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Focused && !rtCaret.IsEmpty())
ShowCaret(&rtCaret);
else
HideCaret(&rtCaret);
}
CFWL_ScrollBar* CFWL_Edit::UpdateScroll() {
- bool bShowHorz = m_pHorzScrollBar && m_pHorzScrollBar->IsVisible();
bool bShowVert = m_pVertScrollBar && m_pVertScrollBar->IsVisible();
- if (!bShowHorz && !bShowVert)
+ if (!bShowVert)
return nullptr;
CFX_RectF contents_bounds = m_pEditEngine->GetContentsBoundingBox();
- CFWL_ScrollBar* pRepaint = nullptr;
- if (bShowHorz) {
- CFX_RectF rtScroll = m_pHorzScrollBar->GetWidgetRect();
- if (rtScroll.width < contents_bounds.width) {
- {
- ScopedUpdateLock update_lock(m_pHorzScrollBar.get());
- float fRange = contents_bounds.width - rtScroll.width;
- m_pHorzScrollBar->SetRange(0.0f, fRange);
-
- float fPos = pdfium::clamp(m_fScrollOffsetX, 0.0f, fRange);
- m_pHorzScrollBar->SetPos(fPos);
- m_pHorzScrollBar->SetTrackPos(fPos);
- m_pHorzScrollBar->SetPageSize(rtScroll.width);
- m_pHorzScrollBar->SetStepSize(rtScroll.width / 10);
- m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Disabled);
- }
- m_pHorzScrollBar->Update();
- pRepaint = m_pHorzScrollBar.get();
- } else if ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) {
- {
- ScopedUpdateLock update_lock(m_pHorzScrollBar.get());
- m_pHorzScrollBar->SetRange(0, -1);
- m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Disabled);
- }
- m_pHorzScrollBar->Update();
- pRepaint = m_pHorzScrollBar.get();
- }
+ CFX_RectF rtScroll = m_pVertScrollBar->GetWidgetRect();
+ if (rtScroll.height < contents_bounds.height) {
+ float fStep = m_pEditEngine->GetLineSpace();
+ float fRange =
+ std::max(contents_bounds.height - m_EngineRect.height, fStep);
+ m_pVertScrollBar->SetRange(0.0f, fRange);
+ float fPos = pdfium::clamp(m_fScrollOffsetY, 0.0f, fRange);
+ m_pVertScrollBar->SetPos(fPos);
+ m_pVertScrollBar->SetTrackPos(fPos);
+ m_pVertScrollBar->SetPageSize(rtScroll.height);
+ m_pVertScrollBar->SetStepSize(fStep);
+ m_pVertScrollBar->RemoveStates(FWL_STATE_WGT_Disabled);
+ m_pVertScrollBar->Update();
+ return m_pVertScrollBar;
}
-
- if (bShowVert) {
- CFX_RectF rtScroll = m_pVertScrollBar->GetWidgetRect();
- if (rtScroll.height < contents_bounds.height) {
- {
- ScopedUpdateLock update_lock(m_pHorzScrollBar.get());
- float fStep = m_pEditEngine->GetLineSpace();
- float fRange =
- std::max(contents_bounds.height - m_rtEngine.height, fStep);
-
- m_pVertScrollBar->SetRange(0.0f, fRange);
- float fPos = pdfium::clamp(m_fScrollOffsetY, 0.0f, fRange);
- m_pVertScrollBar->SetPos(fPos);
- m_pVertScrollBar->SetTrackPos(fPos);
- m_pVertScrollBar->SetPageSize(rtScroll.height);
- m_pVertScrollBar->SetStepSize(fStep);
- m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Disabled);
- }
- m_pVertScrollBar->Update();
- pRepaint = m_pVertScrollBar.get();
- } else if ((m_pVertScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) {
- {
- ScopedUpdateLock update_lock(m_pHorzScrollBar.get());
- m_pVertScrollBar->SetRange(0, -1);
- m_pVertScrollBar->SetStates(FWL_WGTSTATE_Disabled);
- }
- m_pVertScrollBar->Update();
- pRepaint = m_pVertScrollBar.get();
- }
+ if ((m_pVertScrollBar->GetStates() & FWL_STATE_WGT_Disabled) == 0) {
+ m_pVertScrollBar->SetRange(0, -1);
+ m_pVertScrollBar->SetStates(FWL_STATE_WGT_Disabled);
+ m_pVertScrollBar->Update();
+ return m_pVertScrollBar;
}
- return pRepaint;
+ return nullptr;
}
-bool CFWL_Edit::IsShowScrollBar(bool bVert) {
- if (!bVert)
- return false;
- bool bShow =
- (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ShowScrollbarFocus)
- ? (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) ==
- FWL_WGTSTATE_Focused
- : true;
- return bShow && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) &&
- (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) &&
+bool CFWL_Edit::IsShowVertScrollBar() const {
+ const bool bShow =
+ !(m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_ShowScrollbarFocus) ||
+ (m_Properties.m_dwStates & FWL_STATE_WGT_Focused);
+ return bShow && (m_Properties.m_dwStyles & FWL_STYLE_WGT_VScroll) &&
+ (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_MultiLine) &&
IsContentHeightOverflow();
}
-bool CFWL_Edit::IsContentHeightOverflow() {
+bool CFWL_Edit::IsContentHeightOverflow() const {
return m_pEditEngine->GetContentsBoundingBox().height >
- m_rtEngine.height + 1.0f;
+ m_EngineRect.height + 1.0f;
}
void CFWL_Edit::Layout() {
- m_rtClient = GetClientRect();
- m_rtEngine = m_rtClient;
- IFWL_ThemeProvider* theme = GetAvailableTheme();
- if (!theme)
- return;
+ m_ClientRect = GetClientRect();
+ m_EngineRect = m_ClientRect;
+ IFWL_ThemeProvider* theme = GetThemeProvider();
float fWidth = theme->GetScrollBarWidth();
- CFWL_ThemePart part;
- if (!m_pOuter) {
- part.m_pWidget = this;
+ if (!GetOuter()) {
+ CFWL_ThemePart part(CFWL_ThemePart::Part::kNone, this);
CFX_RectF pUIMargin = theme->GetUIMargin(part);
- m_rtEngine.Deflate(pUIMargin.left, pUIMargin.top, pUIMargin.width,
- pUIMargin.height);
- } else if (m_pOuter->GetClassID() == FWL_Type::DateTimePicker) {
- part.m_pWidget = m_pOuter;
+ m_EngineRect.Deflate(pUIMargin.left, pUIMargin.top, pUIMargin.width,
+ pUIMargin.height);
+ } else if (GetOuter()->GetClassID() == FWL_Type::DateTimePicker) {
+ CFWL_ThemePart part(CFWL_ThemePart::Part::kNone, GetOuter());
CFX_RectF pUIMargin = theme->GetUIMargin(part);
- m_rtEngine.Deflate(pUIMargin.left, pUIMargin.top, pUIMargin.width,
- pUIMargin.height);
+ m_EngineRect.Deflate(pUIMargin.left, pUIMargin.top, pUIMargin.width,
+ pUIMargin.height);
}
- bool bShowVertScrollbar = IsShowScrollBar(true);
- bool bShowHorzScrollbar = IsShowScrollBar(false);
+ bool bShowVertScrollbar = IsShowVertScrollBar();
if (bShowVertScrollbar) {
InitVerticalScrollBar();
CFX_RectF rtVertScr;
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) {
- rtVertScr = CFX_RectF(m_rtClient.right() + kEditMargin, m_rtClient.top,
- fWidth, m_rtClient.height);
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_OuterScrollbar) {
+ rtVertScr = CFX_RectF(m_ClientRect.right() + kEditMargin,
+ m_ClientRect.top, fWidth, m_ClientRect.height);
} else {
- rtVertScr = CFX_RectF(m_rtClient.right() - fWidth, m_rtClient.top, fWidth,
- m_rtClient.height);
- if (bShowHorzScrollbar)
- rtVertScr.height -= fWidth;
- m_rtEngine.width -= fWidth;
+ rtVertScr = CFX_RectF(m_ClientRect.right() - fWidth, m_ClientRect.top,
+ fWidth, m_ClientRect.height);
+ m_EngineRect.width -= fWidth;
}
m_pVertScrollBar->SetWidgetRect(rtVertScr);
- m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible);
+ m_pVertScrollBar->RemoveStates(FWL_STATE_WGT_Invisible);
m_pVertScrollBar->Update();
} else if (m_pVertScrollBar) {
- m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible);
- }
-
- if (bShowHorzScrollbar) {
- InitHorizontalScrollBar();
-
- CFX_RectF rtHoriScr;
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) {
- rtHoriScr = CFX_RectF(m_rtClient.left, m_rtClient.bottom() + kEditMargin,
- m_rtClient.width, fWidth);
- } else {
- rtHoriScr = CFX_RectF(m_rtClient.left, m_rtClient.bottom() - fWidth,
- m_rtClient.width, fWidth);
- if (bShowVertScrollbar)
- rtHoriScr.width -= fWidth;
- m_rtEngine.height -= fWidth;
- }
- m_pHorzScrollBar->SetWidgetRect(rtHoriScr);
- m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Invisible);
- m_pHorzScrollBar->Update();
- } else if (m_pHorzScrollBar) {
- m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible);
+ m_pVertScrollBar->SetStates(FWL_STATE_WGT_Invisible);
}
}
void CFWL_Edit::LayoutScrollBar() {
- if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ShowScrollbarFocus) ==
- 0) {
+ if (!(m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_ShowScrollbarFocus))
return;
- }
-
- bool bShowVertScrollbar = IsShowScrollBar(true);
- bool bShowHorzScrollbar = IsShowScrollBar(false);
- IFWL_ThemeProvider* theme = GetAvailableTheme();
- float fWidth = theme ? theme->GetScrollBarWidth() : 0;
+ bool bShowVertScrollbar = IsShowVertScrollBar();
+ IFWL_ThemeProvider* theme = GetThemeProvider();
+ float fWidth = theme->GetScrollBarWidth();
if (bShowVertScrollbar) {
if (!m_pVertScrollBar) {
InitVerticalScrollBar();
CFX_RectF rtVertScr;
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) {
- rtVertScr = CFX_RectF(m_rtClient.right() + kEditMargin, m_rtClient.top,
- fWidth, m_rtClient.height);
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_OuterScrollbar) {
+ rtVertScr = CFX_RectF(m_ClientRect.right() + kEditMargin,
+ m_ClientRect.top, fWidth, m_ClientRect.height);
} else {
- rtVertScr = CFX_RectF(m_rtClient.right() - fWidth, m_rtClient.top,
- fWidth, m_rtClient.height);
- if (bShowHorzScrollbar)
- rtVertScr.height -= fWidth;
+ rtVertScr = CFX_RectF(m_ClientRect.right() - fWidth, m_ClientRect.top,
+ fWidth, m_ClientRect.height);
}
m_pVertScrollBar->SetWidgetRect(rtVertScr);
m_pVertScrollBar->Update();
}
- m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible);
+ m_pVertScrollBar->RemoveStates(FWL_STATE_WGT_Invisible);
} else if (m_pVertScrollBar) {
- m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible);
+ m_pVertScrollBar->SetStates(FWL_STATE_WGT_Invisible);
}
-
- if (bShowHorzScrollbar) {
- if (!m_pHorzScrollBar) {
- InitHorizontalScrollBar();
- CFX_RectF rtHoriScr;
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) {
- rtHoriScr =
- CFX_RectF(m_rtClient.left, m_rtClient.bottom() + kEditMargin,
- m_rtClient.width, fWidth);
- } else {
- rtHoriScr = CFX_RectF(m_rtClient.left, m_rtClient.bottom() - fWidth,
- m_rtClient.width, fWidth);
- if (bShowVertScrollbar)
- rtHoriScr.width -= (fWidth);
- }
- m_pHorzScrollBar->SetWidgetRect(rtHoriScr);
- m_pHorzScrollBar->Update();
- }
- m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Invisible);
- } else if (m_pHorzScrollBar) {
- m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible);
- }
- if (bShowVertScrollbar || bShowHorzScrollbar)
+ if (bShowVertScrollbar)
UpdateScroll();
}
CFX_PointF CFWL_Edit::DeviceToEngine(const CFX_PointF& pt) {
- return pt + CFX_PointF(m_fScrollOffsetX - m_rtEngine.left,
- m_fScrollOffsetY - m_rtEngine.top - m_fVAlignOffset);
+ return pt + CFX_PointF(m_fScrollOffsetX - m_EngineRect.left,
+ m_fScrollOffsetY - m_EngineRect.top - m_fVAlignOffset);
}
void CFWL_Edit::InitVerticalScrollBar() {
if (m_pVertScrollBar)
return;
- auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>();
- prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Vert;
- prop->m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible;
- prop->m_pParent = this;
- prop->m_pThemeProvider = m_pProperties->m_pThemeProvider;
- m_pVertScrollBar = pdfium::MakeUnique<CFWL_ScrollBar>(m_pOwnerApp.Get(),
- std::move(prop), this);
-}
-
-void CFWL_Edit::InitHorizontalScrollBar() {
- if (m_pHorzScrollBar)
- return;
-
- auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>();
- prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Horz;
- prop->m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible;
- prop->m_pParent = this;
- prop->m_pThemeProvider = m_pProperties->m_pThemeProvider;
- m_pHorzScrollBar = pdfium::MakeUnique<CFWL_ScrollBar>(m_pOwnerApp.Get(),
- std::move(prop), this);
+ m_pVertScrollBar = cppgc::MakeGarbageCollected<CFWL_ScrollBar>(
+ GetFWLApp()->GetHeap()->GetAllocationHandle(), GetFWLApp(),
+ Properties{0, FWL_STYLEEXT_SCB_Vert,
+ FWL_STATE_WGT_Disabled | FWL_STATE_WGT_Invisible},
+ this);
}
void CFWL_Edit::ShowCaret(CFX_RectF* pRect) {
@@ -901,15 +705,14 @@ void CFWL_Edit::ShowCaret(CFX_RectF* pRect) {
m_pCaret->ShowCaret();
if (!pRect->IsEmpty())
m_pCaret->SetWidgetRect(*pRect);
- RepaintRect(m_rtEngine);
+ RepaintRect(m_EngineRect);
return;
}
CFWL_Widget* pOuter = this;
- pRect->Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top);
+ pRect->Offset(m_WidgetRect.left, m_WidgetRect.top);
while (pOuter->GetOuter()) {
pOuter = pOuter->GetOuter();
-
CFX_RectF rtOuter = pOuter->GetWidgetRect();
pRect->Offset(rtOuter.left, rtOuter.top);
}
@@ -925,7 +728,7 @@ void CFWL_Edit::ShowCaret(CFX_RectF* pRect) {
void CFWL_Edit::HideCaret(CFX_RectF* pRect) {
if (m_pCaret) {
m_pCaret->HideCaret();
- RepaintRect(m_rtEngine);
+ RepaintRect(m_EngineRect);
return;
}
@@ -940,55 +743,35 @@ void CFWL_Edit::HideCaret(CFX_RectF* pRect) {
pXFAWidget->DisplayCaret(false, pRect);
}
-bool CFWL_Edit::ValidateNumberChar(wchar_t cNum) {
- if (!m_bSetRange)
- return true;
-
- WideString wsText = m_pEditEngine->GetText();
- if (wsText.IsEmpty())
- return cNum != L'0';
-
- if (HasSelection())
- return wsText.GetInteger() <= m_iMax;
- if (cNum == L'0' && m_CursorPosition == 0)
- return false;
-
- int32_t nLen = wsText.GetLength();
- WideString first = wsText.First(m_CursorPosition);
- WideString last = wsText.Last(nLen - m_CursorPosition);
- WideString wsNew = first + cNum + last;
- return wsNew.GetInteger() <= m_iMax;
-}
-
void CFWL_Edit::InitCaret() {
if (m_pCaret)
return;
- m_pCaret = pdfium::MakeUnique<CFWL_Caret>(
- m_pOwnerApp.Get(), pdfium::MakeUnique<CFWL_WidgetProperties>(), this);
- m_pCaret->SetParent(this);
- m_pCaret->SetStates(m_pProperties->m_dwStates);
+ m_pCaret = cppgc::MakeGarbageCollected<CFWL_Caret>(
+ GetFWLApp()->GetHeap()->GetAllocationHandle(), GetFWLApp(), Properties(),
+ this);
+ m_pCaret->SetStates(m_Properties.m_dwStates);
UpdateCursorRect();
}
void CFWL_Edit::UpdateCursorRect() {
int32_t bidi_level;
- if (m_pEditEngine->GetLength() > 0) {
- std::tie(bidi_level, m_rtCaret) =
- m_pEditEngine->GetCharacterInfo(m_CursorPosition);
+ if (m_pEditEngine->CanGenerateCharacterInfo()) {
+ std::tie(bidi_level, m_CaretRect) = m_pEditEngine->GetCharacterInfo(
+ pdfium::base::checked_cast<int32_t>(m_CursorPosition));
} else {
bidi_level = 0;
- m_rtCaret = CFX_RectF();
+ m_CaretRect = CFX_RectF();
}
// TODO(dsinclair): This should handle bidi level ...
- m_rtCaret.width = 1.0f;
+ m_CaretRect.width = 1.0f;
// TODO(hnakashima): Handle correctly edits with empty text instead of using
// these defaults.
- if (m_rtCaret.height == 0)
- m_rtCaret.height = 8.0f;
+ if (m_CaretRect.height == 0)
+ m_CaretRect.height = 8.0f;
}
void CFWL_Edit::SetCursorPosition(size_t position) {
@@ -1001,32 +784,29 @@ void CFWL_Edit::SetCursorPosition(size_t position) {
}
void CFWL_Edit::OnProcessMessage(CFWL_Message* pMessage) {
- if (!pMessage)
- return;
-
switch (pMessage->GetType()) {
- case CFWL_Message::Type::SetFocus:
- OnFocusChanged(pMessage, true);
+ case CFWL_Message::Type::kSetFocus:
+ OnFocusGained();
break;
- case CFWL_Message::Type::KillFocus:
- OnFocusChanged(pMessage, false);
+ case CFWL_Message::Type::kKillFocus:
+ OnFocusLost();
break;
- case CFWL_Message::Type::Mouse: {
+ case CFWL_Message::Type::kMouse: {
CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
switch (pMsg->m_dwCmd) {
- case FWL_MouseCommand::LeftButtonDown:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonDown:
OnLButtonDown(pMsg);
break;
- case FWL_MouseCommand::LeftButtonUp:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonUp:
OnLButtonUp(pMsg);
break;
- case FWL_MouseCommand::LeftButtonDblClk:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonDblClk:
OnButtonDoubleClick(pMsg);
break;
- case FWL_MouseCommand::Move:
+ case CFWL_MessageMouse::MouseCommand::kMove:
OnMouseMove(pMsg);
break;
- case FWL_MouseCommand::RightButtonDown:
+ case CFWL_MessageMouse::MouseCommand::kRightButtonDown:
DoRButtonDown(pMsg);
break;
default:
@@ -1034,11 +814,11 @@ void CFWL_Edit::OnProcessMessage(CFWL_Message* pMessage) {
}
break;
}
- case CFWL_Message::Type::Key: {
+ case CFWL_Message::Type::kKey: {
CFWL_MessageKey* pKey = static_cast<CFWL_MessageKey*>(pMessage);
- if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown)
+ if (pKey->m_dwCmd == CFWL_MessageKey::KeyCommand::kKeyDown)
OnKeyDown(pKey);
- else if (pKey->m_dwCmd == FWL_KeyCommand::Char)
+ else if (pKey->m_dwCmd == CFWL_MessageKey::KeyCommand::kChar)
OnChar(pKey);
break;
}
@@ -1055,15 +835,14 @@ void CFWL_Edit::OnProcessEvent(CFWL_Event* pEvent) {
return;
CFWL_Widget* pSrcTarget = pEvent->GetSrcTarget();
- if ((pSrcTarget == m_pVertScrollBar.get() && m_pVertScrollBar) ||
- (pSrcTarget == m_pHorzScrollBar.get() && m_pHorzScrollBar)) {
+ if ((pSrcTarget == m_pVertScrollBar && m_pVertScrollBar)) {
CFWL_EventScroll* pScrollEvent = static_cast<CFWL_EventScroll*>(pEvent);
OnScroll(static_cast<CFWL_ScrollBar*>(pSrcTarget),
- pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos);
+ pScrollEvent->GetScrollCode(), pScrollEvent->GetPos());
}
}
-void CFWL_Edit::OnDrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_Edit::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
DrawWidget(pGraphics, matrix);
}
@@ -1073,36 +852,34 @@ void CFWL_Edit::DoRButtonDown(CFWL_MessageMouse* pMsg) {
m_pEditEngine->GetIndexForPoint(DeviceToEngine(pMsg->m_pos)));
}
-void CFWL_Edit::OnFocusChanged(CFWL_Message* pMsg, bool bSet) {
- bool bRepaint = false;
- if (bSet) {
- m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
+void CFWL_Edit::OnFocusGained() {
+ m_Properties.m_dwStates |= FWL_STATE_WGT_Focused;
+ UpdateVAlignment();
+ UpdateOffset();
+ UpdateCaret();
+ LayoutScrollBar();
+}
- UpdateVAlignment();
- UpdateOffset();
- UpdateCaret();
- } else if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) {
- m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
+void CFWL_Edit::OnFocusLost() {
+ bool bRepaint = false;
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Focused) {
+ m_Properties.m_dwStates &= ~FWL_STATE_WGT_Focused;
HideCaret(nullptr);
-
if (HasSelection()) {
ClearSelection();
bRepaint = true;
}
UpdateOffset();
}
-
LayoutScrollBar();
if (!bRepaint)
return;
- CFX_RectF rtInvalidate(0, 0, m_pProperties->m_rtWidget.width,
- m_pProperties->m_rtWidget.height);
- RepaintRect(rtInvalidate);
+ RepaintRect(CFX_RectF(0, 0, m_WidgetRect.width, m_WidgetRect.height));
}
void CFWL_Edit::OnLButtonDown(CFWL_MessageMouse* pMsg) {
- if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)
return;
m_bLButtonDown = true;
@@ -1118,7 +895,7 @@ void CFWL_Edit::OnLButtonDown(CFWL_MessageMouse* pMsg) {
m_pEditEngine->GetIndexForPoint(DeviceToEngine(pMsg->m_pos));
if (index_at_click != m_CursorPosition &&
- !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift)) {
+ !!(pMsg->m_dwFlags & XFA_FWL_KeyFlag::kShift)) {
size_t start = std::min(m_CursorPosition, index_at_click);
size_t end = std::max(m_CursorPosition, index_at_click);
@@ -1129,7 +906,7 @@ void CFWL_Edit::OnLButtonDown(CFWL_MessageMouse* pMsg) {
}
if (bRepaint)
- RepaintRect(m_rtEngine);
+ RepaintRect(m_EngineRect);
}
void CFWL_Edit::OnLButtonUp(CFWL_MessageMouse* pMsg) {
@@ -1146,11 +923,11 @@ void CFWL_Edit::OnButtonDoubleClick(CFWL_MessageMouse* pMsg) {
m_pEditEngine->SetSelection(start_idx, count);
m_CursorPosition = start_idx + count;
- RepaintRect(m_rtEngine);
+ RepaintRect(m_EngineRect);
}
void CFWL_Edit::OnMouseMove(CFWL_MessageMouse* pMsg) {
- bool shift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift);
+ bool shift = !!(pMsg->m_dwFlags & XFA_FWL_KeyFlag::kShift);
if (!m_bLButtonDown || !shift)
return;
@@ -1177,8 +954,8 @@ void CFWL_Edit::OnMouseMove(CFWL_MessageMouse* pMsg) {
}
void CFWL_Edit::OnKeyDown(CFWL_MessageKey* pMsg) {
- bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift);
- bool bCtrl = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl);
+ bool bShift = !!(pMsg->m_dwFlags & XFA_FWL_KeyFlag::kShift);
+ bool bCtrl = !!(pMsg->m_dwFlags & XFA_FWL_KeyFlag::kCtrl);
size_t sel_start = m_CursorPosition;
if (m_pEditEngine->HasSelection()) {
@@ -1188,7 +965,7 @@ void CFWL_Edit::OnKeyDown(CFWL_MessageKey* pMsg) {
sel_start = start_idx;
}
- switch (pMsg->m_dwKeyCode) {
+ switch (pMsg->m_dwKeyCodeOrChar) {
case XFA_FWL_VKEY_Left:
SetCursorPosition(m_pEditEngine->GetIndexLeft(m_CursorPosition));
break;
@@ -1211,8 +988,8 @@ void CFWL_Edit::OnKeyDown(CFWL_MessageKey* pMsg) {
: m_pEditEngine->GetIndexAtEndOfLine(m_CursorPosition));
break;
case XFA_FWL_VKEY_Delete: {
- if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) ||
- (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) {
+ if ((m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_ReadOnly) ||
+ (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)) {
break;
}
@@ -1231,17 +1008,17 @@ void CFWL_Edit::OnKeyDown(CFWL_MessageKey* pMsg) {
if (bShift && sel_start != m_CursorPosition) {
m_pEditEngine->SetSelection(std::min(sel_start, m_CursorPosition),
std::max(sel_start, m_CursorPosition));
- RepaintRect(m_rtEngine);
+ RepaintRect(m_EngineRect);
}
}
void CFWL_Edit::OnChar(CFWL_MessageKey* pMsg) {
- if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) ||
- (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) {
+ if ((m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_ReadOnly) ||
+ (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)) {
return;
}
- wchar_t c = static_cast<wchar_t>(pMsg->m_dwKeyCode);
+ wchar_t c = static_cast<wchar_t>(pMsg->m_dwKeyCodeOrChar);
switch (c) {
case L'\b':
if (m_CursorPosition > 0) {
@@ -1259,7 +1036,7 @@ void CFWL_Edit::OnChar(CFWL_MessageKey* pMsg) {
SetCursorPosition(m_CursorPosition + 1);
break;
case L'\r':
- if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_WantReturn) {
+ if (m_Properties.m_dwStyleExts & FWL_STYLEEXT_EDT_WantReturn) {
m_pEditEngine->Insert(m_CursorPosition, L"\n");
SetCursorPosition(m_CursorPosition + 1);
}
@@ -1278,44 +1055,45 @@ void CFWL_Edit::OnChar(CFWL_MessageKey* pMsg) {
bool CFWL_Edit::OnScroll(CFWL_ScrollBar* pScrollBar,
CFWL_EventScroll::Code dwCode,
float fPos) {
- CFX_SizeF fs;
- pScrollBar->GetRange(&fs.width, &fs.height);
+ float fMin;
+ float fMax;
+ pScrollBar->GetRange(&fMin, &fMax);
float iCurPos = pScrollBar->GetPos();
float fStep = pScrollBar->GetStepSize();
switch (dwCode) {
case CFWL_EventScroll::Code::Min: {
- fPos = fs.width;
+ fPos = fMin;
break;
}
case CFWL_EventScroll::Code::Max: {
- fPos = fs.height;
+ fPos = fMax;
break;
}
case CFWL_EventScroll::Code::StepBackward: {
fPos -= fStep;
- if (fPos < fs.width + fStep / 2) {
- fPos = fs.width;
+ if (fPos < fMin + fStep / 2) {
+ fPos = fMin;
}
break;
}
case CFWL_EventScroll::Code::StepForward: {
fPos += fStep;
- if (fPos > fs.height - fStep / 2) {
- fPos = fs.height;
+ if (fPos > fMax - fStep / 2) {
+ fPos = fMax;
}
break;
}
case CFWL_EventScroll::Code::PageBackward: {
fPos -= pScrollBar->GetPageSize();
- if (fPos < fs.width) {
- fPos = fs.width;
+ if (fPos < fMin) {
+ fPos = fMin;
}
break;
}
case CFWL_EventScroll::Code::PageForward: {
fPos += pScrollBar->GetPageSize();
- if (fPos > fs.height) {
- fPos = fs.height;
+ if (fPos > fMax) {
+ fPos = fMax;
}
break;
}
diff --git a/xfa/fwl/cfwl_edit.h b/xfa/fwl/cfwl_edit.h
index 0242e5ca9..2a859356d 100644
--- a/xfa/fwl/cfwl_edit.h
+++ b/xfa/fwl/cfwl_edit.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,10 +11,10 @@
#include <utility>
#include "xfa/fde/cfde_texteditengine.h"
+#include "xfa/fgas/graphics/cfgas_gepath.h"
#include "xfa/fwl/cfwl_event.h"
#include "xfa/fwl/cfwl_scrollbar.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fxgraphics/cxfa_gepath.h"
#define FWL_STYLEEXT_EDT_ReadOnly (1L << 0)
#define FWL_STYLEEXT_EDT_MultiLine (1L << 1)
@@ -38,36 +38,36 @@
#define FWL_STYLEEXT_EDT_ShowScrollbarFocus (1L << 25)
#define FWL_STYLEEXT_EDT_OuterScrollbar (1L << 26)
-class CFWL_Edit;
+class CFWL_MessageKey;
class CFWL_MessageMouse;
-class CFWL_WidgetProperties;
class CFWL_Caret;
+class CFX_RenderDevice;
class CFWL_Edit : public CFWL_Widget, public CFDE_TextEditEngine::Delegate {
public:
- CFWL_Edit(const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_Edit() override;
// CFWL_Widget:
+ void PreFinalize() override;
+ void Trace(cppgc::Visitor* visitor) const override;
FWL_Type GetClassID() const override;
CFX_RectF GetAutosizedWidgetRect() override;
CFX_RectF GetWidgetRect() override;
void Update() override;
FWL_WidgetHit HitTest(const CFX_PointF& point) override;
void SetStates(uint32_t dwStates) override;
- void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
- void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override;
+ void DrawWidget(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& matrix) override;
void OnProcessMessage(CFWL_Message* pMessage) override;
void OnProcessEvent(CFWL_Event* pEvent) override;
- void OnDrawWidget(CXFA_Graphics* pGraphics,
+ void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) override;
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();
@@ -80,16 +80,14 @@ class CFWL_Edit : public CFWL_Widget, public CFDE_TextEditEngine::Delegate {
int32_t GetLimit() const;
void SetLimit(int32_t nLimit);
void SetAliasChar(wchar_t wAlias);
- Optional<WideString> Copy();
- Optional<WideString> Cut();
+ absl::optional<WideString> Copy();
+ absl::optional<WideString> Cut();
bool Paste(const WideString& wsPaste);
bool Undo();
bool Redo();
bool CanUndo();
bool CanRedo();
- void SetOuter(CFWL_Widget* pOuter);
-
// CFDE_TextEditEngine::Delegate
void NotifyTextFull() override;
void OnCaretChanged() override;
@@ -100,21 +98,20 @@ class CFWL_Edit : public CFWL_Widget, public CFDE_TextEditEngine::Delegate {
void SetScrollOffset(float fScrollOffset) override;
protected:
+ CFWL_Edit(CFWL_App* app, const Properties& properties, CFWL_Widget* pOuter);
+
void ShowCaret(CFX_RectF* pRect);
void HideCaret(CFX_RectF* pRect);
- const CFX_RectF& GetRTClient() const { return m_rtClient; }
+ const CFX_RectF& GetRTClient() const { return m_ClientRect; }
CFDE_TextEditEngine* GetTxtEdtEngine() { return m_pEditEngine.get(); }
private:
void RenderText(CFX_RenderDevice* pRenderDev,
const CFX_RectF& clipRect,
const CFX_Matrix& mt);
- void DrawTextBk(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawContent(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
+ void DrawContent(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawContentNonComb(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix);
void UpdateEditEngine();
void UpdateEditParams();
@@ -128,17 +125,16 @@ class CFWL_Edit : public CFWL_Widget, public CFDE_TextEditEngine::Delegate {
void LayoutScrollBar();
CFX_PointF DeviceToEngine(const CFX_PointF& pt);
void InitVerticalScrollBar();
- void InitHorizontalScrollBar();
void InitEngine();
void InitCaret();
- bool ValidateNumberChar(wchar_t cNum);
- bool IsShowScrollBar(bool bVert);
- bool IsContentHeightOverflow();
+ bool IsShowVertScrollBar() const;
+ bool IsContentHeightOverflow() const;
void SetCursorPosition(size_t position);
void UpdateCursorRect();
void DoRButtonDown(CFWL_MessageMouse* pMsg);
- void OnFocusChanged(CFWL_Message* pMsg, bool bSet);
+ void OnFocusGained();
+ void OnFocusLost();
void OnLButtonDown(CFWL_MessageMouse* pMsg);
void OnLButtonUp(CFWL_MessageMouse* pMsg);
void OnButtonDoubleClick(CFWL_MessageMouse* pMsg);
@@ -149,23 +145,20 @@ class CFWL_Edit : public CFWL_Widget, public CFDE_TextEditEngine::Delegate {
CFWL_EventScroll::Code dwCode,
float fPos);
- CFX_RectF m_rtClient;
- CFX_RectF m_rtEngine;
- CFX_RectF m_rtStatic;
- CFX_RectF m_rtCaret;
+ CFX_RectF m_ClientRect;
+ CFX_RectF m_EngineRect;
+ CFX_RectF m_StaticRect;
+ CFX_RectF m_CaretRect;
bool m_bLButtonDown = false;
- bool m_bSetRange = false;
int32_t m_nLimit = -1;
- int32_t m_iMax = 0xFFFFFFF;
float m_fVAlignOffset = 0.0f;
float m_fScrollOffsetX = 0.0f;
float m_fScrollOffsetY = 0.0f;
float m_fFontSize = 0.0f;
size_t m_CursorPosition = 0;
std::unique_ptr<CFDE_TextEditEngine> const m_pEditEngine;
- std::unique_ptr<CFWL_ScrollBar> m_pVertScrollBar;
- std::unique_ptr<CFWL_ScrollBar> m_pHorzScrollBar;
- std::unique_ptr<CFWL_Caret> m_pCaret;
+ cppgc::Member<CFWL_ScrollBar> m_pVertScrollBar;
+ cppgc::Member<CFWL_Caret> m_pCaret;
WideString m_wsCache;
WideString m_wsFont;
};
diff --git a/xfa/fwl/cfwl_edit_embeddertest.cpp b/xfa/fwl/cfwl_edit_embeddertest.cpp
index 92532932c..6904b8d8e 100644
--- a/xfa/fwl/cfwl_edit_embeddertest.cpp
+++ b/xfa/fwl/cfwl_edit_embeddertest.cpp
@@ -1,29 +1,53 @@
-// Copyright 2017 PDFium Authors. All rights reserved.
+// Copyright 2017 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "xfa/fwl/cfwl_edit.h"
+
+#include <memory>
+
#include "core/fxcrt/widestring.h"
+#include "core/fxge/cfx_defaultrenderdevice.h"
+#include "public/fpdf_ext.h"
#include "public/fpdf_formfill.h"
#include "public/fpdf_fwlevent.h"
#include "testing/embedder_test.h"
+#include "testing/embedder_test_environment.h"
#include "testing/embedder_test_timer_handling_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/xfa_js_embedder_test.h"
+namespace {
+
+const char kEmailRecommendedFilledChecksum[] =
+ "211e4e46eb347aa2bc7c425556d600b0";
+
+} // namespace
+
class CFWLEditEmbedderTest : public XFAJSEmbedderTest {
protected:
void SetUp() override {
EmbedderTest::SetUp();
SetDelegate(&delegate_);
+
+ // Arbitrary, picked nice even number, 2020-09-13 12:26:40.
+ FSDK_SetTimeFunction([]() -> time_t { return 1600000000; });
+ FSDK_SetLocaltimeFunction([](const time_t* t) { return gmtime(t); });
}
void TearDown() override {
- UnloadPage(page());
+ FSDK_SetTimeFunction(nullptr);
+ FSDK_SetLocaltimeFunction(nullptr);
+ // TODO(crbug.com/pdfium/11): A page might not have been loaded if a test
+ // is skipped at runtime. This check for a non-null page should be able to
+ // removed once none of the tests are being skipped for Skia.
+ if (page())
+ UnloadPage(page());
EmbedderTest::TearDown();
}
void CreateAndInitializeFormPDF(const char* filename) {
- EXPECT_TRUE(OpenDocument(filename));
+ ASSERT_TRUE(OpenDocument(filename));
page_ = LoadPage(0);
ASSERT_TRUE(page_);
}
@@ -32,7 +56,7 @@ class CFWLEditEmbedderTest : public XFAJSEmbedderTest {
EmbedderTestTimerHandlingDelegate delegate() const { return delegate_; }
private:
- FPDF_PAGE page_;
+ FPDF_PAGE page_ = nullptr;
EmbedderTestTimerHandlingDelegate delegate_;
};
@@ -59,13 +83,11 @@ TEST_F(CFWLEditEmbedderTest, LeftClickMouseSelection) {
EXPECT_STREQ(L"defgh", WideString::FromUTF16LE(buf, len).c_str());
}
-// TODO(crbug.com/pdfium/11): Fix this test and enable.
-#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
-#define MAYBE_DragMouseSelection DISABLED_DragMouseSelection
-#else
-#define MAYBE_DragMouseSelection DragMouseSelection
-#endif
-TEST_F(CFWLEditEmbedderTest, MAYBE_DragMouseSelection) {
+TEST_F(CFWLEditEmbedderTest, DragMouseSelection) {
+ // TODO(crbug.com/pdfium/11): Fix this test and enable for Skia variants.
+ if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer())
+ return;
+
CreateAndInitializeFormPDF("xfa/email_recommended.pdf");
FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
for (size_t i = 0; i < 10; ++i)
@@ -91,13 +113,11 @@ TEST_F(CFWLEditEmbedderTest, MAYBE_DragMouseSelection) {
}
}
-// TODO(crbug.com/pdfium/11): Fix this test and enable.
-#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
-#define MAYBE_SimpleFill DISABLED_SimpleFill
-#else
-#define MAYBE_SimpleFill SimpleFill
-#endif
-TEST_F(CFWLEditEmbedderTest, MAYBE_SimpleFill) {
+TEST_F(CFWLEditEmbedderTest, SimpleFill) {
+ // TODO(crbug.com/pdfium/11): Fix this test and enable for Skia variants.
+ if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer())
+ return;
+
CreateAndInitializeFormPDF("xfa/email_recommended.pdf");
const char kBlankMD5[] = "8dda78a3afaf9f7b5210eb81cacc4600";
{
@@ -110,22 +130,18 @@ TEST_F(CFWLEditEmbedderTest, MAYBE_SimpleFill) {
for (size_t i = 0; i < 10; ++i)
FORM_OnChar(form_handle(), page(), 'a' + i, 0);
- const char kFilledMD5[] = "211e4e46eb347aa2bc7c425556d600b0";
{
ScopedFPDFBitmap page_bitmap =
RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
- CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
+ CompareBitmap(page_bitmap.get(), 612, 792, kEmailRecommendedFilledChecksum);
}
}
-// TODO(crbug.com/pdfium/11): Fix this test and enable.
-#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
-#define MAYBE_FillWithNewLineWithoutMultiline \
- DISABLED_FillWithNewLineWithoutMultiline
-#else
-#define MAYBE_FillWithNewLineWithoutMultiline FillWithNewLineWithoutMultiline
-#endif
-TEST_F(CFWLEditEmbedderTest, MAYBE_FillWithNewLineWithoutMultiline) {
+TEST_F(CFWLEditEmbedderTest, FillWithNewLineWithoutMultiline) {
+ // TODO(crbug.com/pdfium/11): Fix this test and enable for Skia variants.
+ if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer())
+ return;
+
CreateAndInitializeFormPDF("xfa/email_recommended.pdf");
FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
for (size_t i = 0; i < 5; ++i)
@@ -134,11 +150,10 @@ TEST_F(CFWLEditEmbedderTest, MAYBE_FillWithNewLineWithoutMultiline) {
for (size_t i = 5; i < 10; ++i)
FORM_OnChar(form_handle(), page(), 'a' + i, 0);
- const char kFilledMD5[] = "211e4e46eb347aa2bc7c425556d600b0";
{
ScopedFPDFBitmap page_bitmap =
RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
- CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
+ CompareBitmap(page_bitmap.get(), 612, 792, kEmailRecommendedFilledChecksum);
}
}
@@ -157,11 +172,11 @@ TEST_F(CFWLEditEmbedderTest, DISABLED_FillWithNewLineWithMultiline) {
// abcde
// fghij|
{
-#if _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
const char kFilledMultilineMD5[] = "fc1f4d5fdb2c5755005fc525b0a60ec9";
#else
const char kFilledMultilineMD5[] = "a5654e027d8b1667c20f3b86d1918003";
-#endif // _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
+#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
ScopedFPDFBitmap page_bitmap =
RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
CompareBitmap(page_bitmap.get(), 612, 792, kFilledMultilineMD5);
@@ -182,61 +197,117 @@ TEST_F(CFWLEditEmbedderTest, DISABLED_FillWithNewLineWithMultiline) {
// Should look like:
// abcde|ghij
{
-#if _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
+#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
const char kMultilineBackspaceMD5[] = "8bb62a8100ff1e1cc113d4033e0d824e";
#else
const char kMultilineBackspaceMD5[] = "a2f1dcab92bb1fb7c2f9ccc70100c989";
-#endif // _FX_PLATFORM_ == _FX_PLATFORM_LINUX_
+#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
ScopedFPDFBitmap page_bitmap =
RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
CompareBitmap(page_bitmap.get(), 612, 792, kMultilineBackspaceMD5);
}
}
-// TODO(crbug.com/pdfium/11): Fix this test and enable.
-#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
-#define MAYBE_DateTimePickerTest DISABLED_DateTimePickerTest
-#else
-#define MAYBE_DateTimePickerTest DateTimePickerTest
-#endif
-TEST_F(CFWLEditEmbedderTest, MAYBE_DateTimePickerTest) {
+TEST_F(CFWLEditEmbedderTest, DateTimePickerTest) {
+ // TODO(crbug.com/pdfium/11): Fix this test and enable for Skia variants.
+ if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer())
+ return;
+
CreateAndInitializeFormPDF("xfa/xfa_date_time_edit.pdf");
+
+ // Give focus to date time widget, creating down-arrow button.
FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
+ FORM_OnLButtonUp(form_handle(), page(), 0, 115, 58);
+ const char kSelectedMD5[] = "1036b8837a9dba75c6bd8f9347ae2eb2";
+ {
+ ScopedFPDFBitmap page_bitmap =
+ RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
+ CompareBitmap(page_bitmap.get(), 612, 792, kSelectedMD5);
+ }
- const char kFilledMD5[] = "1036b8837a9dba75c6bd8f9347ae2eb2";
+ // Click down-arrow button, bringing up calendar widget.
+ FORM_OnLButtonDown(form_handle(), page(), 0, 446, 54);
+ FORM_OnLButtonUp(form_handle(), page(), 0, 446, 54);
{
ScopedFPDFBitmap page_bitmap =
RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
- CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
+
+ // TODO(tsepez): hermetic fonts.
+ // const char kCalendarOpenMD5[] = "02de64e7e83c82c1ef0ae484d671a51d";
+ // CompareBitmap(page_bitmap.get(), 612, 792, kCalendarOpenMD5);
+ }
+
+ // Click on date on calendar, putting result into field as text.
+ FORM_OnLButtonDown(form_handle(), page(), 0, 100, 162);
+ FORM_OnLButtonUp(form_handle(), page(), 0, 100, 162);
+ {
+ ScopedFPDFBitmap page_bitmap =
+ RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
+
+ // TODO(tsepez): hermetic fonts.
+ // const char kFilledMD5[] = "1bce66c11f1c87b8d639ce0076ac36d3";
+ // CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
}
}
TEST_F(CFWLEditEmbedderTest, ImageEditTest) {
CreateAndInitializeFormPDF("xfa/xfa_image_edit.pdf");
FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
+ const char* filled_checksum = []() {
+ if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer())
+ return "23658ed124114f05518372d41c80e41b";
+ return "101cf6223fa2403fba4c413a8310ab02";
+ }();
+ ScopedFPDFBitmap page_bitmap = RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
+ CompareBitmap(page_bitmap.get(), 612, 792, filled_checksum);
+}
- const char kFilledMD5[] = "1940568c9ba33bac5d0b1ee9558c76b3";
+TEST_F(CFWLEditEmbedderTest, ComboBoxTest) {
+ CreateAndInitializeFormPDF("xfa/xfa_combobox.pdf");
+
+ // Give focus to widget.
+ FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
+ FORM_OnLButtonUp(form_handle(), page(), 0, 115, 58);
{
+ const char* filled_checksum = []() {
+ if (CFX_DefaultRenderDevice::SkiaIsDefaultRenderer())
+ return "8c555487e09ee4acf3ace77db5929bdc";
+ return "dad642ae8a5afce2591ffbcabbfc58dd";
+ }();
ScopedFPDFBitmap page_bitmap =
RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
- CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
+ CompareBitmap(page_bitmap.get(), 612, 792, filled_checksum);
}
-}
-// TODO(crbug.com/pdfium/11): Fix this test and enable.
-#if defined(_SKIA_SUPPORT_) || defined(_SKIA_SUPPORT_PATHS_)
-#define MAYBE_ComboBoxTest DISABLED_ComboBoxTest
-#else
-#define MAYBE_ComboBoxTest ComboBoxTest
-#endif
-TEST_F(CFWLEditEmbedderTest, MAYBE_ComboBoxTest) {
- CreateAndInitializeFormPDF("xfa/xfa_combobox.pdf");
- FORM_OnLButtonDown(form_handle(), page(), 0, 115, 58);
+ // Click on down-arrow button, dropdown list appears.
+ FORM_OnLButtonDown(form_handle(), page(), 0, 438, 53);
+ FORM_OnLButtonUp(form_handle(), page(), 0, 438, 53);
+ {
+ ScopedFPDFBitmap page_bitmap =
+ RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
+ // TODO(tsepez): hermetic fonts.
+ // const char kFilledMD5[] = "dad642ae8a5afce2591ffbcabbfc58dd";
+ // CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
+ }
+
+ // Enter drop-down list, selection highlighted.
+ FORM_OnMouseMove(form_handle(), page(), 0, 253, 107);
+ {
+ ScopedFPDFBitmap page_bitmap =
+ RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
+ // TODO(tsepez): hermetic fonts.
+ // const char kFilledMD5[] = "dad642ae8a5afce2591ffbcabbfc58dd";
+ // CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
+ }
- const char kFilledMD5[] = "dad642ae8a5afce2591ffbcabbfc58dd";
+ // Click on selection, putting result into field.
+ FORM_OnLButtonDown(form_handle(), page(), 0, 253, 107);
+ FORM_OnLButtonUp(form_handle(), page(), 0, 253, 107);
{
ScopedFPDFBitmap page_bitmap =
RenderLoadedPageWithFlags(page(), FPDF_ANNOT);
- CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
+ // TODO(tsepez): hermetic fonts.
+ // const char kFilledMD5[] = "dad642ae8a5afce2591ffbcabbfc58dd";
+ // CompareBitmap(page_bitmap.get(), 612, 792, kFilledMD5);
}
}
diff --git a/xfa/fwl/cfwl_event.cpp b/xfa/fwl/cfwl_event.cpp
index 5922bc198..24321bb14 100644
--- a/xfa/fwl/cfwl_event.cpp
+++ b/xfa/fwl/cfwl_event.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/xfa/fwl/cfwl_event.h b/xfa/fwl/cfwl_event.h
index 832c01f01..385abec12 100644
--- a/xfa/fwl/cfwl_event.h
+++ b/xfa/fwl/cfwl_event.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,10 +7,13 @@
#ifndef XFA_FWL_CFWL_EVENT_H_
#define XFA_FWL_CFWL_EVENT_H_
-#include "core/fxcrt/observed_ptr.h"
-#include "xfa/fwl/cfwl_widget.h"
+#include "v8/include/cppgc/macros.h"
+
+class CFWL_Widget;
class CFWL_Event {
+ CPPGC_STACK_ALLOCATED(); // Allow Raw/Unowned pointers.
+
public:
enum class Type {
CheckStateChanged,
@@ -33,13 +36,13 @@ class CFWL_Event {
virtual ~CFWL_Event();
Type GetType() const { return m_type; }
- CFWL_Widget* GetSrcTarget() const { return m_pSrcTarget.Get(); }
- CFWL_Widget* GetDstTarget() const { return m_pDstTarget.Get(); }
+ CFWL_Widget* GetSrcTarget() const { return m_pSrcTarget; }
+ CFWL_Widget* GetDstTarget() const { return m_pDstTarget; }
private:
const Type m_type;
- ObservedPtr<CFWL_Widget> const m_pSrcTarget;
- ObservedPtr<CFWL_Widget> const m_pDstTarget;
+ CFWL_Widget* const m_pSrcTarget = nullptr;
+ CFWL_Widget* const m_pDstTarget = nullptr;
};
#endif // XFA_FWL_CFWL_EVENT_H_
diff --git a/xfa/fwl/cfwl_eventmouse.cpp b/xfa/fwl/cfwl_eventmouse.cpp
index 3f8c7734c..2182e40f8 100644
--- a/xfa/fwl/cfwl_eventmouse.cpp
+++ b/xfa/fwl/cfwl_eventmouse.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,11 +6,10 @@
#include "xfa/fwl/cfwl_eventmouse.h"
-CFWL_EventMouse::CFWL_EventMouse(CFWL_Widget* pSrcTarget)
- : CFWL_EventMouse(pSrcTarget, nullptr) {}
-
CFWL_EventMouse::CFWL_EventMouse(CFWL_Widget* pSrcTarget,
- CFWL_Widget* pDstTarget)
- : CFWL_Event(CFWL_Event::Type::Mouse, pSrcTarget, pDstTarget) {}
+ CFWL_Widget* pDstTarget,
+ CFWL_MessageMouse::MouseCommand cmd)
+ : CFWL_Event(CFWL_Event::Type::Mouse, pSrcTarget, pDstTarget),
+ m_dwCmd(cmd) {}
-CFWL_EventMouse::~CFWL_EventMouse() {}
+CFWL_EventMouse::~CFWL_EventMouse() = default;
diff --git a/xfa/fwl/cfwl_eventmouse.h b/xfa/fwl/cfwl_eventmouse.h
index e7982fbe4..5764e936f 100644
--- a/xfa/fwl/cfwl_eventmouse.h
+++ b/xfa/fwl/cfwl_eventmouse.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -12,11 +12,15 @@
class CFWL_EventMouse final : public CFWL_Event {
public:
- explicit CFWL_EventMouse(CFWL_Widget* pSrcTarget);
- CFWL_EventMouse(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget);
+ CFWL_EventMouse(CFWL_Widget* pSrcTarget,
+ CFWL_Widget* pDstTarget,
+ CFWL_MessageMouse::MouseCommand cmd);
~CFWL_EventMouse() override;
- FWL_MouseCommand m_dwCmd = FWL_MouseCommand::LeftButtonDown;
+ CFWL_MessageMouse::MouseCommand GetCommand() const { return m_dwCmd; }
+
+ private:
+ const CFWL_MessageMouse::MouseCommand m_dwCmd;
};
#endif // XFA_FWL_CFWL_EVENTMOUSE_H_
diff --git a/xfa/fwl/cfwl_eventscroll.cpp b/xfa/fwl/cfwl_eventscroll.cpp
index 0e9e26c1c..11df10926 100644
--- a/xfa/fwl/cfwl_eventscroll.cpp
+++ b/xfa/fwl/cfwl_eventscroll.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,7 +6,11 @@
#include "xfa/fwl/cfwl_eventscroll.h"
-CFWL_EventScroll::CFWL_EventScroll(CFWL_Widget* pSrcTarget)
- : CFWL_Event(CFWL_Event::Type::Scroll, pSrcTarget) {}
+CFWL_EventScroll::CFWL_EventScroll(CFWL_Widget* pSrcTarget,
+ Code code,
+ float pos)
+ : CFWL_Event(CFWL_Event::Type::Scroll, pSrcTarget),
+ m_iScrollCode(code),
+ m_fPos(pos) {}
-CFWL_EventScroll::~CFWL_EventScroll() {}
+CFWL_EventScroll::~CFWL_EventScroll() = default;
diff --git a/xfa/fwl/cfwl_eventscroll.h b/xfa/fwl/cfwl_eventscroll.h
index 78960c8d5..ce97b0ba0 100644
--- a/xfa/fwl/cfwl_eventscroll.h
+++ b/xfa/fwl/cfwl_eventscroll.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -24,11 +24,15 @@ class CFWL_EventScroll final : public CFWL_Event {
EndScroll,
};
- explicit CFWL_EventScroll(CFWL_Widget* pSrcTarget);
+ CFWL_EventScroll(CFWL_Widget* pSrcTarget, Code code, float pos);
~CFWL_EventScroll() override;
- Code m_iScrollCode = Code::None;
- float m_fPos = 0.0f;
+ Code GetScrollCode() const { return m_iScrollCode; }
+ float GetPos() const { return m_fPos; }
+
+ private:
+ const Code m_iScrollCode;
+ const float m_fPos;
};
#endif // XFA_FWL_CFWL_EVENTSCROLL_H_
diff --git a/xfa/fwl/cfwl_eventselectchanged.cpp b/xfa/fwl/cfwl_eventselectchanged.cpp
index bc6859590..e385a9c1c 100644
--- a/xfa/fwl/cfwl_eventselectchanged.cpp
+++ b/xfa/fwl/cfwl_eventselectchanged.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,7 +6,22 @@
#include "xfa/fwl/cfwl_eventselectchanged.h"
-CFWL_EventSelectChanged::CFWL_EventSelectChanged(CFWL_Widget* pSrcTarget)
- : CFWL_Event(CFWL_Event::Type::SelectChanged, pSrcTarget) {}
+CFWL_EventSelectChanged::CFWL_EventSelectChanged(CFWL_Widget* pSrcTarget,
+ bool bLButtonUp)
+ : CFWL_Event(CFWL_Event::Type::SelectChanged, pSrcTarget),
+ m_bLButtonUp(bLButtonUp),
+ m_iYear(-1),
+ m_iMonth(-1),
+ m_iDay(-1) {}
-CFWL_EventSelectChanged::~CFWL_EventSelectChanged() {}
+CFWL_EventSelectChanged::CFWL_EventSelectChanged(CFWL_Widget* pSrcTarget,
+ int32_t iYear,
+ int32_t iMonth,
+ int32_t iDay)
+ : CFWL_Event(CFWL_Event::Type::SelectChanged, pSrcTarget),
+ m_bLButtonUp(false),
+ m_iYear(iYear),
+ m_iMonth(iMonth),
+ m_iDay(iDay) {}
+
+CFWL_EventSelectChanged::~CFWL_EventSelectChanged() = default;
diff --git a/xfa/fwl/cfwl_eventselectchanged.h b/xfa/fwl/cfwl_eventselectchanged.h
index d4b68b35b..8f79fe39c 100644
--- a/xfa/fwl/cfwl_eventselectchanged.h
+++ b/xfa/fwl/cfwl_eventselectchanged.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,20 +7,32 @@
#ifndef XFA_FWL_CFWL_EVENTSELECTCHANGED_H_
#define XFA_FWL_CFWL_EVENTSELECTCHANGED_H_
+#include <stdint.h>
+
#include "xfa/fwl/cfwl_event.h"
class CFWL_EventSelectChanged final : public CFWL_Event {
public:
- explicit CFWL_EventSelectChanged(CFWL_Widget* pSrcTarget);
+ CFWL_EventSelectChanged(CFWL_Widget* pSrcTarget, bool bLButtonUp);
+ CFWL_EventSelectChanged(CFWL_Widget* pSrcTarget,
+ int32_t iYear,
+ int32_t iMonth,
+ int32_t iDay);
~CFWL_EventSelectChanged() override;
+ bool GetLButtonUp() const { return m_bLButtonUp; }
+ int32_t GetYear() const { return m_iYear; }
+ int32_t GetMonth() const { return m_iMonth; }
+ int32_t GetDay() const { return m_iDay; }
+
+ protected:
// Used by ComboBox.
- bool bLButtonUp = false;
+ const bool m_bLButtonUp;
// Used by DateTimePIcker
- int32_t iYear = -1;
- int32_t iMonth = -1;
- int32_t iDay = -1;
+ const int32_t m_iYear;
+ const int32_t m_iMonth;
+ const int32_t m_iDay;
};
#endif // XFA_FWL_CFWL_EVENTSELECTCHANGED_H_
diff --git a/xfa/fwl/cfwl_eventtarget.cpp b/xfa/fwl/cfwl_eventtarget.cpp
deleted file mode 100644
index 4b3d87cc9..000000000
--- a/xfa/fwl/cfwl_eventtarget.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fwl/cfwl_eventtarget.h"
-
-#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fwl/ifwl_widgetdelegate.h"
-
-CFWL_EventTarget::CFWL_EventTarget(CFWL_Widget* pListener)
- : m_pListener(pListener) {}
-
-CFWL_EventTarget::~CFWL_EventTarget() {}
-
-void CFWL_EventTarget::SetEventSource(CFWL_Widget* pSource) {
- if (pSource)
- m_widgets.insert(pSource);
-}
-
-bool CFWL_EventTarget::ProcessEvent(CFWL_Event* pEvent) {
- IFWL_WidgetDelegate* pDelegate = m_pListener->GetDelegate();
- if (!pDelegate)
- return false;
- if (!m_widgets.empty() && m_widgets.count(pEvent->GetSrcTarget()) == 0)
- return false;
-
- pDelegate->OnProcessEvent(pEvent);
- return true;
-}
diff --git a/xfa/fwl/cfwl_eventtarget.h b/xfa/fwl/cfwl_eventtarget.h
deleted file mode 100644
index f61431973..000000000
--- a/xfa/fwl/cfwl_eventtarget.h
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FWL_CFWL_EVENTTARGET_H_
-#define XFA_FWL_CFWL_EVENTTARGET_H_
-
-#include <set>
-
-#include "xfa/fwl/cfwl_event.h"
-
-class CFWL_Event;
-class CFWL_Widget;
-
-class CFWL_EventTarget {
- public:
- explicit CFWL_EventTarget(CFWL_Widget* pListener);
- ~CFWL_EventTarget();
-
- void SetEventSource(CFWL_Widget* pSource);
- bool ProcessEvent(CFWL_Event* pEvent);
-
- bool IsValid() const { return m_bValid; }
- void FlagInvalid() { m_bValid = false; }
-
- private:
- bool m_bValid = true;
- CFWL_Widget* const m_pListener;
- std::set<CFWL_Widget*> m_widgets;
-};
-
-#endif // XFA_FWL_CFWL_EVENTTARGET_H_
diff --git a/xfa/fwl/cfwl_eventtextwillchange.cpp b/xfa/fwl/cfwl_eventtextwillchange.cpp
index 22b1100f5..6052cb7d4 100644
--- a/xfa/fwl/cfwl_eventtextwillchange.cpp
+++ b/xfa/fwl/cfwl_eventtextwillchange.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,7 +6,16 @@
#include "xfa/fwl/cfwl_eventtextwillchange.h"
-CFWL_EventTextWillChange::CFWL_EventTextWillChange(CFWL_Widget* pSrcTarget)
- : CFWL_Event(CFWL_Event::Type::TextWillChange, pSrcTarget) {}
+CFWL_EventTextWillChange::CFWL_EventTextWillChange(
+ CFWL_Widget* pSrcTarget,
+ const WideString& change_text,
+ const WideString& previous_text,
+ size_t selection_start,
+ size_t selection_end)
+ : CFWL_Event(CFWL_Event::Type::TextWillChange, pSrcTarget),
+ change_text_(change_text),
+ previous_text_(previous_text),
+ selection_start_(selection_start),
+ selection_end_(selection_end) {}
CFWL_EventTextWillChange::~CFWL_EventTextWillChange() = default;
diff --git a/xfa/fwl/cfwl_eventtextwillchange.h b/xfa/fwl/cfwl_eventtextwillchange.h
index a1bfe8cde..65c0d893e 100644
--- a/xfa/fwl/cfwl_eventtextwillchange.h
+++ b/xfa/fwl/cfwl_eventtextwillchange.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,18 +7,42 @@
#ifndef XFA_FWL_CFWL_EVENTTEXTWILLCHANGE_H_
#define XFA_FWL_CFWL_EVENTTEXTWILLCHANGE_H_
+#include "core/fxcrt/widestring.h"
#include "xfa/fwl/cfwl_event.h"
class CFWL_EventTextWillChange final : public CFWL_Event {
public:
- explicit CFWL_EventTextWillChange(CFWL_Widget* pSrcTarget);
+ CFWL_EventTextWillChange(CFWL_Widget* pSrcTarget,
+ const WideString& change_text,
+ const WideString& previous_text,
+ size_t selection_start,
+ size_t selection_end);
~CFWL_EventTextWillChange() override;
- WideString change_text;
- WideString previous_text;
- bool cancelled = false;
- size_t selection_start = 0;
- size_t selection_end = 0;
+ WideString GetChangeText() const { return change_text_; }
+ WideString GetPreviousText() const { return previous_text_; }
+ size_t GetSelectionStart() const { return selection_start_; }
+ size_t GetSelectionEnd() const { return selection_end_; }
+ bool GetCancelled() const { return cancelled_; }
+
+ void SetChangeText(const WideString& change_text) {
+ change_text_ = change_text;
+ }
+ void SetPreviousText(const WideString& previous_text) {
+ previous_text_ = previous_text;
+ }
+ void SetSelectionStart(size_t selection_start) {
+ selection_start_ = selection_start;
+ }
+ void SetSelectionEnd(size_t selection_end) { selection_end_ = selection_end; }
+ void SetCancelled(bool cancelled) { cancelled_ = cancelled; }
+
+ protected:
+ WideString change_text_;
+ WideString previous_text_;
+ size_t selection_start_;
+ size_t selection_end_;
+ bool cancelled_ = false;
};
#endif // XFA_FWL_CFWL_EVENTTEXTWILLCHANGE_H_
diff --git a/xfa/fwl/cfwl_eventvalidate.cpp b/xfa/fwl/cfwl_eventvalidate.cpp
index c54d49152..37a3ee7ba 100644
--- a/xfa/fwl/cfwl_eventvalidate.cpp
+++ b/xfa/fwl/cfwl_eventvalidate.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,7 +6,9 @@
#include "xfa/fwl/cfwl_eventvalidate.h"
-CFWL_EventValidate::CFWL_EventValidate(CFWL_Widget* pSrcTarget)
- : CFWL_Event(CFWL_Event::Type::Validate, pSrcTarget) {}
+CFWL_EventValidate::CFWL_EventValidate(CFWL_Widget* pSrcTarget,
+ const WideString& wsInsert)
+ : CFWL_Event(CFWL_Event::Type::Validate, pSrcTarget),
+ m_wsInsert(wsInsert) {}
-CFWL_EventValidate::~CFWL_EventValidate() {}
+CFWL_EventValidate::~CFWL_EventValidate() = default;
diff --git a/xfa/fwl/cfwl_eventvalidate.h b/xfa/fwl/cfwl_eventvalidate.h
index 26e3c7f8f..de2b7221c 100644
--- a/xfa/fwl/cfwl_eventvalidate.h
+++ b/xfa/fwl/cfwl_eventvalidate.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,15 +7,21 @@
#ifndef XFA_FWL_CFWL_EVENTVALIDATE_H_
#define XFA_FWL_CFWL_EVENTVALIDATE_H_
+#include "core/fxcrt/widestring.h"
#include "xfa/fwl/cfwl_event.h"
class CFWL_EventValidate final : public CFWL_Event {
public:
- explicit CFWL_EventValidate(CFWL_Widget* pSrcTarget);
+ CFWL_EventValidate(CFWL_Widget* pSrcTarget, const WideString& wsInsert);
~CFWL_EventValidate() override;
- bool bValidate = false;
- WideString wsInsert;
+ WideString GetInsert() const { return m_wsInsert; }
+ bool GetValidate() const { return m_bValidate; }
+ void SetValidate(bool bValidate) { m_bValidate = bValidate; }
+
+ protected:
+ const WideString m_wsInsert;
+ bool m_bValidate = true;
};
#endif // XFA_FWL_CFWL_EVENTVALIDATE_H_
diff --git a/xfa/fwl/cfwl_listbox.cpp b/xfa/fwl/cfwl_listbox.cpp
index b2b0f2efe..dbd29e16b 100644
--- a/xfa/fwl/cfwl_listbox.cpp
+++ b/xfa/fwl/cfwl_listbox.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,9 +10,12 @@
#include <memory>
#include <utility>
-#include "third_party/base/ptr_util.h"
-#include "third_party/base/stl_util.h"
+#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"
#include "xfa/fwl/cfwl_app.h"
#include "xfa/fwl/cfwl_messagekey.h"
#include "xfa/fwl/cfwl_messagemouse.h"
@@ -29,12 +32,18 @@ const int kItemTextMargin = 2;
} // namespace
-CFWL_ListBox::CFWL_ListBox(const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
+CFWL_ListBox::CFWL_ListBox(CFWL_App* app,
+ const Properties& properties,
CFWL_Widget* pOuter)
- : CFWL_Widget(app, std::move(properties), pOuter) {}
+ : CFWL_Widget(app, properties, pOuter) {}
-CFWL_ListBox::~CFWL_ListBox() {}
+CFWL_ListBox::~CFWL_ListBox() = default;
+
+void CFWL_ListBox::Trace(cppgc::Visitor* visitor) const {
+ CFWL_Widget::Trace(visitor);
+ visitor->Trace(m_pHorzScrollBar);
+ visitor->Trace(m_pVertScrollBar);
+}
FWL_Type CFWL_ListBox::GetClassID() const {
return FWL_Type::ListBox;
@@ -43,91 +52,74 @@ FWL_Type CFWL_ListBox::GetClassID() const {
void CFWL_ListBox::Update() {
if (IsLocked())
return;
- if (!m_pProperties->m_pThemeProvider)
- m_pProperties->m_pThemeProvider = GetAvailableTheme();
- switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_AlignMask) {
- case FWL_STYLEEXT_LTB_LeftAlign: {
+ switch (m_Properties.m_dwStyleExts & FWL_STYLEEXT_LTB_AlignMask) {
+ case FWL_STYLEEXT_LTB_LeftAlign:
m_iTTOAligns = FDE_TextAlignment::kCenterLeft;
break;
- }
- case FWL_STYLEEXT_LTB_RightAlign: {
+ case FWL_STYLEEXT_LTB_RightAlign:
m_iTTOAligns = FDE_TextAlignment::kCenterRight;
break;
- }
case FWL_STYLEEXT_LTB_CenterAlign:
- default: {
+ default:
m_iTTOAligns = FDE_TextAlignment::kCenter;
break;
- }
}
m_TTOStyles.single_line_ = true;
m_fScorllBarWidth = GetScrollWidth();
- CalcSize(false);
+ CalcSize();
}
FWL_WidgetHit CFWL_ListBox::HitTest(const CFX_PointF& point) {
- if (IsShowScrollBar(false)) {
+ if (IsShowHorzScrollBar()) {
CFX_RectF rect = m_pHorzScrollBar->GetWidgetRect();
if (rect.Contains(point))
return FWL_WidgetHit::HScrollBar;
}
- if (IsShowScrollBar(true)) {
+ if (IsShowVertScrollBar()) {
CFX_RectF rect = m_pVertScrollBar->GetWidgetRect();
if (rect.Contains(point))
return FWL_WidgetHit::VScrollBar;
}
- if (m_rtClient.Contains(point))
+ if (m_ClientRect.Contains(point))
return FWL_WidgetHit::Client;
return FWL_WidgetHit::Unknown;
}
-void CFWL_ListBox::DrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_ListBox::DrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
if (!pGraphics)
return;
- IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get();
- if (!pTheme)
- return;
-
- pGraphics->SaveGraphState();
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
if (HasBorder())
- DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
+ DrawBorder(pGraphics, CFWL_ThemePart::Part::kBorder, matrix);
- CFX_RectF rtClip(m_rtConent);
- if (IsShowScrollBar(false))
+ CFX_RectF rtClip(m_ContentRect);
+ if (IsShowHorzScrollBar())
rtClip.height -= m_fScorllBarWidth;
- if (IsShowScrollBar(true))
+ if (IsShowVertScrollBar())
rtClip.width -= m_fScorllBarWidth;
pGraphics->SetClipRect(matrix.TransformRect(rtClip));
- if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_NoBackground) == 0)
- DrawBkground(pGraphics, pTheme, &matrix);
-
- DrawItems(pGraphics, pTheme, &matrix);
- pGraphics->RestoreGraphState();
-}
+ if ((m_Properties.m_dwStyles & FWL_STYLE_WGT_NoBackground) == 0)
+ DrawBkground(pGraphics, matrix);
-void CFWL_ListBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
- if (pThemeProvider)
- m_pProperties->m_pThemeProvider = pThemeProvider;
+ DrawItems(pGraphics, matrix);
}
int32_t CFWL_ListBox::CountSelItems() {
int32_t iRet = 0;
int32_t iCount = CountItems(this);
for (int32_t i = 0; i < iCount; i++) {
- CFWL_ListItem* pItem = GetItem(this, i);
- if (!pItem)
- continue;
- if (pItem->GetStates() & FWL_ITEMSTATE_LTB_Selected)
+ Item* pItem = GetItem(this, i);
+ if (pItem && pItem->IsSelected())
iRet++;
}
return iRet;
}
-CFWL_ListItem* CFWL_ListBox::GetSelItem(int32_t nIndexSel) {
+CFWL_ListBox::Item* CFWL_ListBox::GetSelItem(int32_t nIndexSel) {
int32_t idx = GetSelIndex(nIndexSel);
if (idx < 0)
return nullptr;
@@ -138,10 +130,10 @@ int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) {
int32_t index = 0;
int32_t iCount = CountItems(this);
for (int32_t i = 0; i < iCount; i++) {
- CFWL_ListItem* pItem = GetItem(this, i);
+ Item* pItem = GetItem(this, i);
if (!pItem)
return -1;
- if (pItem->GetStates() & FWL_ITEMSTATE_LTB_Selected) {
+ if (pItem->IsSelected()) {
if (index == nIndex)
return i;
index++;
@@ -150,7 +142,7 @@ int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) {
return -1;
}
-void CFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) {
+void CFWL_ListBox::SetSelItem(Item* pItem, bool bSelect) {
if (!pItem) {
if (bSelect) {
SelectAll();
@@ -161,14 +153,14 @@ void CFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) {
return;
}
if (IsMultiSelection())
- SetSelectionDirect(pItem, bSelect);
+ pItem->SetSelected(bSelect);
else
SetSelection(pItem, pItem, bSelect);
}
-CFWL_ListItem* CFWL_ListBox::GetListItem(CFWL_ListItem* pItem,
- uint32_t dwKeyCode) {
- CFWL_ListItem* hRet = nullptr;
+CFWL_ListBox::Item* CFWL_ListBox::GetListItem(Item* pItem,
+ XFA_FWL_VKEYCODE dwKeyCode) {
+ Item* hRet = nullptr;
switch (dwKeyCode) {
case XFA_FWL_VKEY_Up:
case XFA_FWL_VKEY_Down:
@@ -196,57 +188,41 @@ CFWL_ListItem* CFWL_ListBox::GetListItem(CFWL_ListItem* pItem,
return hRet;
}
-void CFWL_ListBox::SetSelection(CFWL_ListItem* hStart,
- CFWL_ListItem* hEnd,
- bool bSelected) {
+void CFWL_ListBox::SetSelection(Item* hStart, Item* hEnd, bool bSelected) {
int32_t iStart = GetItemIndex(this, hStart);
int32_t iEnd = GetItemIndex(this, hEnd);
- if (iStart > iEnd) {
- int32_t iTemp = iStart;
- iStart = iEnd;
- iEnd = iTemp;
- }
+ if (iStart > iEnd)
+ std::swap(iStart, iEnd);
if (bSelected) {
int32_t iCount = CountItems(this);
for (int32_t i = 0; i < iCount; i++) {
- CFWL_ListItem* pItem = GetItem(this, i);
- SetSelectionDirect(pItem, false);
+ Item* pItem = GetItem(this, i);
+ if (pItem)
+ pItem->SetSelected(false);
}
}
- for (; iStart <= iEnd; iStart++) {
- CFWL_ListItem* pItem = GetItem(this, iStart);
- SetSelectionDirect(pItem, bSelected);
+ while (iStart <= iEnd) {
+ Item* pItem = GetItem(this, iStart);
+ if (pItem)
+ pItem->SetSelected(bSelected);
+ ++iStart;
}
}
-void CFWL_ListBox::SetSelectionDirect(CFWL_ListItem* pItem, bool bSelect) {
- if (!pItem)
- return;
-
- uint32_t dwOldStyle = pItem->GetStates();
- bSelect ? dwOldStyle |= FWL_ITEMSTATE_LTB_Selected
- : dwOldStyle &= ~FWL_ITEMSTATE_LTB_Selected;
- pItem->SetStates(dwOldStyle);
-}
-
bool CFWL_ListBox::IsMultiSelection() const {
- return m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection;
-}
-
-bool CFWL_ListBox::IsItemSelected(CFWL_ListItem* pItem) {
- return pItem && (pItem->GetStates() & FWL_ITEMSTATE_LTB_Selected) != 0;
+ return m_Properties.m_dwStyleExts & FWL_STYLEEXT_LTB_MultiSelection;
}
void CFWL_ListBox::ClearSelection() {
bool bMulti = IsMultiSelection();
int32_t iCount = CountItems(this);
for (int32_t i = 0; i < iCount; i++) {
- CFWL_ListItem* pItem = GetItem(this, i);
+ Item* pItem = GetItem(this, i);
if (!pItem)
continue;
- if (!(pItem->GetStates() & FWL_ITEMSTATE_LTB_Selected))
+ if (!pItem->IsSelected())
continue;
- SetSelectionDirect(pItem, false);
+ pItem->SetSelected(false);
if (!bMulti)
return;
}
@@ -260,42 +236,36 @@ void CFWL_ListBox::SelectAll() {
if (iCount <= 0)
return;
- CFWL_ListItem* pItemStart = GetItem(this, 0);
- CFWL_ListItem* pItemEnd = GetItem(this, iCount - 1);
+ Item* pItemStart = GetItem(this, 0);
+ Item* pItemEnd = GetItem(this, iCount - 1);
SetSelection(pItemStart, pItemEnd, false);
}
-CFWL_ListItem* CFWL_ListBox::GetFocusedItem() {
+CFWL_ListBox::Item* CFWL_ListBox::GetFocusedItem() {
int32_t iCount = CountItems(this);
for (int32_t i = 0; i < iCount; i++) {
- CFWL_ListItem* pItem = GetItem(this, i);
+ Item* pItem = GetItem(this, i);
if (!pItem)
- return nullptr;
- if (pItem->GetStates() & FWL_ITEMSTATE_LTB_Focused)
+ break;
+ if (pItem->IsFocused())
return pItem;
}
return nullptr;
}
-void CFWL_ListBox::SetFocusItem(CFWL_ListItem* pItem) {
- CFWL_ListItem* hFocus = GetFocusedItem();
+void CFWL_ListBox::SetFocusItem(Item* pItem) {
+ Item* hFocus = GetFocusedItem();
if (pItem == hFocus)
return;
- if (hFocus) {
- uint32_t dwStyle = hFocus->GetStates();
- dwStyle &= ~FWL_ITEMSTATE_LTB_Focused;
- hFocus->SetStates(dwStyle);
- }
- if (pItem) {
- uint32_t dwStyle = pItem->GetStates();
- dwStyle |= FWL_ITEMSTATE_LTB_Focused;
- pItem->SetStates(dwStyle);
- }
+ if (hFocus)
+ hFocus->SetFocused(false);
+ if (pItem)
+ pItem->SetFocused(true);
}
-CFWL_ListItem* CFWL_ListBox::GetItemAtPoint(const CFX_PointF& point) {
- CFX_PointF pos = point - m_rtConent.TopLeft();
+CFWL_ListBox::Item* CFWL_ListBox::GetItemAtPoint(const CFX_PointF& point) {
+ CFX_PointF pos = point - m_ContentRect.TopLeft();
float fPosX = 0.0f;
if (m_pHorzScrollBar)
fPosX = m_pHorzScrollBar->GetPos();
@@ -306,7 +276,7 @@ CFWL_ListItem* CFWL_ListBox::GetItemAtPoint(const CFX_PointF& point) {
int32_t nCount = CountItems(this);
for (int32_t i = 0; i < nCount; i++) {
- CFWL_ListItem* pItem = GetItem(this, i);
+ Item* pItem = GetItem(this, i);
if (!pItem)
continue;
@@ -318,19 +288,19 @@ CFWL_ListItem* CFWL_ListBox::GetItemAtPoint(const CFX_PointF& point) {
return nullptr;
}
-bool CFWL_ListBox::ScrollToVisible(CFWL_ListItem* pItem) {
+bool CFWL_ListBox::ScrollToVisible(Item* pItem) {
if (!m_pVertScrollBar)
return false;
CFX_RectF rtItem = pItem ? pItem->GetRect() : CFX_RectF();
bool bScroll = false;
float fPosY = m_pVertScrollBar->GetPos();
- rtItem.Offset(0, -fPosY + m_rtConent.top);
- if (rtItem.top < m_rtConent.top) {
- fPosY += rtItem.top - m_rtConent.top;
+ rtItem.Offset(0, -fPosY + m_ContentRect.top);
+ if (rtItem.top < m_ContentRect.top) {
+ fPosY += rtItem.top - m_ContentRect.top;
bScroll = true;
- } else if (rtItem.bottom() > m_rtConent.bottom()) {
- fPosY += rtItem.bottom() - m_rtConent.bottom();
+ } else if (rtItem.bottom() > m_ContentRect.bottom()) {
+ fPosY += rtItem.bottom() - m_ContentRect.bottom();
bScroll = true;
}
if (!bScroll)
@@ -338,36 +308,28 @@ bool CFWL_ListBox::ScrollToVisible(CFWL_ListItem* pItem) {
m_pVertScrollBar->SetPos(fPosY);
m_pVertScrollBar->SetTrackPos(fPosY);
- RepaintRect(m_rtClient);
+ RepaintRect(m_ClientRect);
return true;
}
-void CFWL_ListBox::DrawBkground(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
+void CFWL_ListBox::DrawBkground(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
if (!pGraphics)
return;
- if (!pTheme)
- return;
- CFWL_ThemeBackground param;
- param.m_pWidget = this;
- param.m_iPart = CFWL_Part::Background;
- param.m_dwStates = 0;
- param.m_pGraphics = pGraphics;
- param.m_matrix.Concat(*pMatrix);
- param.m_rtPart = m_rtClient;
- if (IsShowScrollBar(false) && IsShowScrollBar(true))
- param.m_pRtData = &m_rtStatic;
+ CFWL_ThemeBackground param(CFWL_ThemePart::Part::kBackground, this,
+ pGraphics);
+ param.m_matrix = mtMatrix;
+ param.m_PartRect = m_ClientRect;
+ if (IsShowHorzScrollBar() && IsShowVertScrollBar())
+ param.m_pRtData = &m_StaticRect;
if (!IsEnabled())
- param.m_dwStates = CFWL_PartState_Disabled;
-
- pTheme->DrawBackground(param);
+ param.m_dwStates = CFWL_PartState::kDisabled;
+ GetThemeProvider()->DrawBackground(param);
}
-void CFWL_ListBox::DrawItems(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
+void CFWL_ListBox::DrawItems(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
float fPosX = 0.0f;
if (m_pHorzScrollBar)
fPosX = m_pHorzScrollBar->GetPos();
@@ -376,7 +338,7 @@ void CFWL_ListBox::DrawItems(CXFA_Graphics* pGraphics,
if (m_pVertScrollBar)
fPosY = m_pVertScrollBar->GetPos();
- CFX_RectF rtView(m_rtConent);
+ CFX_RectF rtView(m_ContentRect);
if (m_pHorzScrollBar)
rtView.height -= m_fScorllBarWidth;
if (m_pVertScrollBar)
@@ -384,56 +346,53 @@ void CFWL_ListBox::DrawItems(CXFA_Graphics* pGraphics,
int32_t iCount = CountItems(this);
for (int32_t i = 0; i < iCount; i++) {
- CFWL_ListItem* pItem = GetItem(this, i);
+ CFWL_ListBox::Item* pItem = GetItem(this, i);
if (!pItem)
continue;
CFX_RectF rtItem = pItem->GetRect();
- rtItem.Offset(m_rtConent.left - fPosX, m_rtConent.top - fPosY);
- if (rtItem.bottom() < m_rtConent.top)
+ rtItem.Offset(m_ContentRect.left - fPosX, m_ContentRect.top - fPosY);
+ if (rtItem.bottom() < m_ContentRect.top)
continue;
- if (rtItem.top >= m_rtConent.bottom())
+ if (rtItem.top >= m_ContentRect.bottom())
break;
- DrawItem(pGraphics, pTheme, pItem, i, rtItem, pMatrix);
+ DrawItem(pGraphics, pItem, i, rtItem, mtMatrix);
}
}
-void CFWL_ListBox::DrawItem(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- CFWL_ListItem* pItem,
+void CFWL_ListBox::DrawItem(CFGAS_GEGraphics* pGraphics,
+ Item* pItem,
int32_t Index,
const CFX_RectF& rtItem,
- const CFX_Matrix* pMatrix) {
- uint32_t dwItemStyles = pItem ? pItem->GetStates() : 0;
- uint32_t dwPartStates = CFWL_PartState_Normal;
- if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
- dwPartStates = CFWL_PartState_Disabled;
- else if (dwItemStyles & FWL_ITEMSTATE_LTB_Selected)
- dwPartStates = CFWL_PartState_Selected;
-
- if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused &&
- dwItemStyles & FWL_ITEMSTATE_LTB_Focused) {
- dwPartStates |= CFWL_PartState_Focused;
- }
-
- CFWL_ThemeBackground bg_param;
- bg_param.m_pWidget = this;
- bg_param.m_iPart = CFWL_Part::ListItem;
+ const CFX_Matrix& mtMatrix) {
+ Mask<CFWL_PartState> dwPartStates = CFWL_PartState::kNormal;
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)
+ dwPartStates = CFWL_PartState::kDisabled;
+ else if (pItem && pItem->IsSelected())
+ dwPartStates = CFWL_PartState::kSelected;
+
+ if ((m_Properties.m_dwStates & FWL_STATE_WGT_Focused) && pItem &&
+ pItem->IsFocused()) {
+ dwPartStates |= CFWL_PartState::kFocused;
+ }
+
+ CFX_RectF rtFocus(rtItem); // Must outlive |bg_param|.
+ CFWL_ThemeBackground bg_param(CFWL_ThemePart::Part::kListItem, this,
+ pGraphics);
bg_param.m_dwStates = dwPartStates;
- bg_param.m_pGraphics = pGraphics;
- bg_param.m_matrix.Concat(*pMatrix);
- bg_param.m_rtPart = rtItem;
+ bg_param.m_matrix = mtMatrix;
+ bg_param.m_PartRect = rtItem;
bg_param.m_bMaximize = true;
- CFX_RectF rtFocus(rtItem);
bg_param.m_pRtData = &rtFocus;
if (m_pVertScrollBar && !m_pHorzScrollBar &&
- (dwPartStates & CFWL_PartState_Focused)) {
- bg_param.m_rtPart.left += 1;
- bg_param.m_rtPart.width -= (m_fScorllBarWidth + 1);
+ (dwPartStates & CFWL_PartState::kFocused)) {
+ bg_param.m_PartRect.left += 1;
+ bg_param.m_PartRect.width -= (m_fScorllBarWidth + 1);
rtFocus.Deflate(0.5, 0.5, 1 + m_fScorllBarWidth, 1);
}
- pTheme->DrawBackground(bg_param);
+ IFWL_ThemeProvider* pTheme = GetThemeProvider();
+ pTheme->DrawBackground(bg_param);
if (!pItem)
return;
@@ -444,13 +403,10 @@ void CFWL_ListBox::DrawItem(CXFA_Graphics* pGraphics,
CFX_RectF rtText(rtItem);
rtText.Deflate(kItemTextMargin, kItemTextMargin);
- CFWL_ThemeText textParam;
- textParam.m_pWidget = this;
- textParam.m_iPart = CFWL_Part::ListItem;
+ CFWL_ThemeText textParam(CFWL_ThemePart::Part::kListItem, this, pGraphics);
textParam.m_dwStates = dwPartStates;
- textParam.m_pGraphics = pGraphics;
- textParam.m_matrix.Concat(*pMatrix);
- textParam.m_rtPart = rtText;
+ textParam.m_matrix = mtMatrix;
+ textParam.m_PartRect = rtText;
textParam.m_wsText = std::move(wsText);
textParam.m_dwTTOStyles = m_TTOStyles;
textParam.m_iTTOAlign = m_iTTOAligns;
@@ -458,125 +414,112 @@ void CFWL_ListBox::DrawItem(CXFA_Graphics* pGraphics,
pTheme->DrawText(textParam);
}
-CFX_SizeF CFWL_ListBox::CalcSize(bool bAutoSize) {
- if (!m_pProperties->m_pThemeProvider)
- return CFX_SizeF();
-
- m_rtClient = GetClientRect();
- m_rtConent = m_rtClient;
+CFX_SizeF CFWL_ListBox::CalcSize() {
+ m_ClientRect = GetClientRect();
+ m_ContentRect = m_ClientRect;
CFX_RectF rtUIMargin;
- if (!m_pOuter) {
- CFWL_ThemePart part;
- part.m_pWidget = this;
- IFWL_ThemeProvider* theme = GetAvailableTheme();
- CFX_RectF pUIMargin = theme ? theme->GetUIMargin(part) : CFX_RectF();
- m_rtConent.Deflate(pUIMargin.left, pUIMargin.top, pUIMargin.width,
- pUIMargin.height);
+ if (!GetOuter()) {
+ CFWL_ThemePart part(CFWL_ThemePart::Part::kNone, this);
+ CFX_RectF pUIMargin = GetThemeProvider()->GetUIMargin(part);
+ m_ContentRect.Deflate(pUIMargin.left, pUIMargin.top, pUIMargin.width,
+ pUIMargin.height);
}
float fWidth = GetMaxTextWidth();
fWidth += 2 * kItemTextMargin;
- if (!bAutoSize) {
- float fActualWidth = m_rtClient.width - rtUIMargin.left - rtUIMargin.width;
- fWidth = std::max(fWidth, fActualWidth);
- }
+
+ float fActualWidth = m_ClientRect.width - rtUIMargin.left - rtUIMargin.width;
+ fWidth = std::max(fWidth, fActualWidth);
m_fItemHeight = CalcItemHeight();
int32_t iCount = CountItems(this);
CFX_SizeF fs;
for (int32_t i = 0; i < iCount; i++) {
- CFWL_ListItem* htem = GetItem(this, i);
- UpdateItemSize(htem, fs, fWidth, m_fItemHeight, bAutoSize);
+ Item* htem = GetItem(this, i);
+ UpdateItemSize(htem, fs, fWidth, m_fItemHeight);
}
- if (bAutoSize)
- return fs;
- float iHeight = m_rtClient.height;
+ float iHeight = m_ClientRect.height;
bool bShowVertScr = false;
bool bShowHorzScr = false;
- if (!bShowVertScr && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll))
+ if (!bShowVertScr && (m_Properties.m_dwStyles & FWL_STYLE_WGT_VScroll))
bShowVertScr = (fs.height > iHeight);
- CFX_SizeF szRange;
+ float fMax = 0.0f;
if (bShowVertScr) {
if (!m_pVertScrollBar)
InitVerticalScrollBar();
- CFX_RectF rtScrollBar(m_rtClient.right() - m_fScorllBarWidth,
- m_rtClient.top, m_fScorllBarWidth,
- m_rtClient.height - 1);
+ CFX_RectF rtScrollBar(m_ClientRect.right() - m_fScorllBarWidth,
+ m_ClientRect.top, m_fScorllBarWidth,
+ m_ClientRect.height - 1);
if (bShowHorzScr)
rtScrollBar.height -= m_fScorllBarWidth;
m_pVertScrollBar->SetWidgetRect(rtScrollBar);
- szRange.width = 0;
- szRange.height = std::max(fs.height - m_rtConent.height, m_fItemHeight);
+ fMax = std::max(fs.height - m_ContentRect.height, m_fItemHeight);
- m_pVertScrollBar->SetRange(szRange.width, szRange.height);
+ m_pVertScrollBar->SetRange(0.0f, fMax);
m_pVertScrollBar->SetPageSize(rtScrollBar.height * 9 / 10);
m_pVertScrollBar->SetStepSize(m_fItemHeight);
- float fPos =
- pdfium::clamp(m_pVertScrollBar->GetPos(), 0.0f, szRange.height);
+ float fPos = pdfium::clamp(m_pVertScrollBar->GetPos(), 0.0f, fMax);
m_pVertScrollBar->SetPos(fPos);
m_pVertScrollBar->SetTrackPos(fPos);
- if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) ==
+ if ((m_Properties.m_dwStyleExts & FWL_STYLEEXT_LTB_ShowScrollBarFocus) ==
0 ||
- (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) {
- m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible);
+ (m_Properties.m_dwStates & FWL_STATE_WGT_Focused)) {
+ m_pVertScrollBar->RemoveStates(FWL_STATE_WGT_Invisible);
}
m_pVertScrollBar->Update();
} else if (m_pVertScrollBar) {
m_pVertScrollBar->SetPos(0);
m_pVertScrollBar->SetTrackPos(0);
- m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible);
+ m_pVertScrollBar->SetStates(FWL_STATE_WGT_Invisible);
}
if (bShowHorzScr) {
if (!m_pHorzScrollBar)
InitHorizontalScrollBar();
- CFX_RectF rtScrollBar(m_rtClient.left,
- m_rtClient.bottom() - m_fScorllBarWidth,
- m_rtClient.width, m_fScorllBarWidth);
+ CFX_RectF rtScrollBar(m_ClientRect.left,
+ m_ClientRect.bottom() - m_fScorllBarWidth,
+ m_ClientRect.width, m_fScorllBarWidth);
if (bShowVertScr)
rtScrollBar.width -= m_fScorllBarWidth;
m_pHorzScrollBar->SetWidgetRect(rtScrollBar);
- szRange.width = 0;
- szRange.height = fs.width - rtScrollBar.width;
- m_pHorzScrollBar->SetRange(szRange.width, szRange.height);
+ fMax = fs.width - rtScrollBar.width;
+ m_pHorzScrollBar->SetRange(0.0f, fMax);
m_pHorzScrollBar->SetPageSize(fWidth * 9 / 10);
m_pHorzScrollBar->SetStepSize(fWidth / 10);
- float fPos =
- pdfium::clamp(m_pHorzScrollBar->GetPos(), 0.0f, szRange.height);
+ float fPos = pdfium::clamp(m_pHorzScrollBar->GetPos(), 0.0f, fMax);
m_pHorzScrollBar->SetPos(fPos);
m_pHorzScrollBar->SetTrackPos(fPos);
- if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_ShowScrollBarFocus) ==
+ if ((m_Properties.m_dwStyleExts & FWL_STYLEEXT_LTB_ShowScrollBarFocus) ==
0 ||
- (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)) {
- m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Invisible);
+ (m_Properties.m_dwStates & FWL_STATE_WGT_Focused)) {
+ m_pHorzScrollBar->RemoveStates(FWL_STATE_WGT_Invisible);
}
m_pHorzScrollBar->Update();
} else if (m_pHorzScrollBar) {
m_pHorzScrollBar->SetPos(0);
m_pHorzScrollBar->SetTrackPos(0);
- m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible);
+ m_pHorzScrollBar->SetStates(FWL_STATE_WGT_Invisible);
}
if (bShowVertScr && bShowHorzScr) {
- m_rtStatic = CFX_RectF(m_rtClient.right() - m_fScorllBarWidth,
- m_rtClient.bottom() - m_fScorllBarWidth,
- m_fScorllBarWidth, m_fScorllBarWidth);
+ m_StaticRect = CFX_RectF(m_ClientRect.right() - m_fScorllBarWidth,
+ m_ClientRect.bottom() - m_fScorllBarWidth,
+ m_fScorllBarWidth, m_fScorllBarWidth);
}
return fs;
}
-void CFWL_ListBox::UpdateItemSize(CFWL_ListItem* pItem,
+void CFWL_ListBox::UpdateItemSize(Item* pItem,
CFX_SizeF& size,
float fWidth,
- float fItemHeight,
- bool bAutoSize) const {
- if (!bAutoSize && pItem) {
+ float fItemHeight) const {
+ if (pItem) {
CFX_RectF rtItem(0, size.height, fWidth, fItemHeight);
pItem->SetRect(rtItem);
}
@@ -588,86 +531,76 @@ float CFWL_ListBox::GetMaxTextWidth() {
float fRet = 0.0f;
int32_t iCount = CountItems(this);
for (int32_t i = 0; i < iCount; i++) {
- CFWL_ListItem* pItem = GetItem(this, i);
+ Item* pItem = GetItem(this, i);
if (!pItem)
continue;
- CFX_SizeF sz = CalcTextSize(pItem->GetText(),
- m_pProperties->m_pThemeProvider.Get(), false);
+ CFX_SizeF sz = CalcTextSize(pItem->GetText(), false);
fRet = std::max(fRet, sz.width);
}
return fRet;
}
float CFWL_ListBox::GetScrollWidth() {
- IFWL_ThemeProvider* theme = GetAvailableTheme();
- return theme ? theme->GetScrollBarWidth() : 0.0f;
+ return GetThemeProvider()->GetScrollBarWidth();
}
float CFWL_ListBox::CalcItemHeight() {
- IFWL_ThemeProvider* theme = GetAvailableTheme();
- CFWL_ThemePart part;
- part.m_pWidget = this;
- return (theme ? theme->GetFontSize(part) : 20.0f) + 2 * kItemTextMargin;
+ CFWL_ThemePart part(CFWL_ThemePart::Part::kNone, this);
+ return GetThemeProvider()->GetFontSize(part) + 2 * kItemTextMargin;
}
void CFWL_ListBox::InitVerticalScrollBar() {
if (m_pVertScrollBar)
return;
- auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>();
- prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Vert;
- prop->m_dwStates = FWL_WGTSTATE_Invisible;
- prop->m_pParent = this;
- prop->m_pThemeProvider = m_pScrollBarTP;
- m_pVertScrollBar = pdfium::MakeUnique<CFWL_ScrollBar>(m_pOwnerApp.Get(),
- std::move(prop), this);
+ m_pVertScrollBar = cppgc::MakeGarbageCollected<CFWL_ScrollBar>(
+ GetFWLApp()->GetHeap()->GetAllocationHandle(), GetFWLApp(),
+ Properties{0, FWL_STYLEEXT_SCB_Vert, FWL_STATE_WGT_Invisible}, this);
}
void CFWL_ListBox::InitHorizontalScrollBar() {
if (m_pHorzScrollBar)
return;
- auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>();
- prop->m_dwStyleExes = FWL_STYLEEXT_SCB_Horz;
- prop->m_dwStates = FWL_WGTSTATE_Invisible;
- prop->m_pParent = this;
- prop->m_pThemeProvider = m_pScrollBarTP;
- m_pHorzScrollBar = pdfium::MakeUnique<CFWL_ScrollBar>(m_pOwnerApp.Get(),
- std::move(prop), this);
+ m_pHorzScrollBar = cppgc::MakeGarbageCollected<CFWL_ScrollBar>(
+ GetFWLApp()->GetHeap()->GetAllocationHandle(), GetFWLApp(),
+ Properties{0, FWL_STYLEEXT_SCB_Horz, FWL_STATE_WGT_Invisible}, this);
}
-bool CFWL_ListBox::IsShowScrollBar(bool bVert) {
- CFWL_ScrollBar* pScrollbar =
- bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get();
- if (!pScrollbar || !pScrollbar->IsVisible())
- return false;
+bool CFWL_ListBox::IsShowVertScrollBar() const {
+ return m_pVertScrollBar && m_pVertScrollBar->IsVisible() &&
+ ScrollBarPropertiesPresent();
+}
+
+bool CFWL_ListBox::IsShowHorzScrollBar() const {
+ return m_pHorzScrollBar && m_pHorzScrollBar->IsVisible() &&
+ ScrollBarPropertiesPresent();
+}
- return !(m_pProperties->m_dwStyleExes &
- FWL_STYLEEXT_LTB_ShowScrollBarFocus) ||
- (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused);
+bool CFWL_ListBox::ScrollBarPropertiesPresent() const {
+ return !(m_Properties.m_dwStyleExts & FWL_STYLEEXT_LTB_ShowScrollBarFocus) ||
+ (m_Properties.m_dwStates & FWL_STATE_WGT_Focused);
}
void CFWL_ListBox::OnProcessMessage(CFWL_Message* pMessage) {
- if (!pMessage)
- return;
if (!IsEnabled())
return;
switch (pMessage->GetType()) {
- case CFWL_Message::Type::SetFocus:
- OnFocusChanged(pMessage, true);
+ case CFWL_Message::Type::kSetFocus:
+ OnFocusGained();
break;
- case CFWL_Message::Type::KillFocus:
- OnFocusChanged(pMessage, false);
+ case CFWL_Message::Type::kKillFocus:
+ OnFocusLost();
break;
- case CFWL_Message::Type::Mouse: {
+ case CFWL_Message::Type::kMouse: {
CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
switch (pMsg->m_dwCmd) {
- case FWL_MouseCommand::LeftButtonDown:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonDown:
OnLButtonDown(pMsg);
break;
- case FWL_MouseCommand::LeftButtonUp:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonUp:
OnLButtonUp(pMsg);
break;
default:
@@ -675,12 +608,12 @@ void CFWL_ListBox::OnProcessMessage(CFWL_Message* pMessage) {
}
break;
}
- case CFWL_Message::Type::MouseWheel:
+ case CFWL_Message::Type::kMouseWheel:
OnMouseWheel(static_cast<CFWL_MessageMouseWheel*>(pMessage));
break;
- case CFWL_Message::Type::Key: {
+ case CFWL_Message::Type::kKey: {
CFWL_MessageKey* pMsg = static_cast<CFWL_MessageKey*>(pMessage);
- if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown)
+ if (pMsg->m_dwCmd == CFWL_MessageKey::KeyCommand::kKeyDown)
OnKeyDown(pMsg);
break;
}
@@ -699,59 +632,57 @@ void CFWL_ListBox::OnProcessEvent(CFWL_Event* pEvent) {
return;
CFWL_Widget* pSrcTarget = pEvent->GetSrcTarget();
- if ((pSrcTarget == m_pVertScrollBar.get() && m_pVertScrollBar) ||
- (pSrcTarget == m_pHorzScrollBar.get() && m_pHorzScrollBar)) {
+ if ((pSrcTarget == m_pVertScrollBar && m_pVertScrollBar) ||
+ (pSrcTarget == m_pHorzScrollBar && m_pHorzScrollBar)) {
CFWL_EventScroll* pScrollEvent = static_cast<CFWL_EventScroll*>(pEvent);
OnScroll(static_cast<CFWL_ScrollBar*>(pSrcTarget),
- pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos);
+ pScrollEvent->GetScrollCode(), pScrollEvent->GetPos());
}
}
-void CFWL_ListBox::OnDrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_ListBox::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
DrawWidget(pGraphics, matrix);
}
-void CFWL_ListBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) {
- if (GetStylesEx() & FWL_STYLEEXT_LTB_ShowScrollBarFocus) {
- if (m_pVertScrollBar) {
- if (bSet)
- m_pVertScrollBar->RemoveStates(FWL_WGTSTATE_Invisible);
- else
- m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible);
- }
- if (m_pHorzScrollBar) {
- if (bSet)
- m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Invisible);
- else
- m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible);
- }
+void CFWL_ListBox::OnFocusGained() {
+ if (GetStyleExts() & FWL_STYLEEXT_LTB_ShowScrollBarFocus) {
+ if (m_pVertScrollBar)
+ m_pVertScrollBar->RemoveStates(FWL_STATE_WGT_Invisible);
+ if (m_pHorzScrollBar)
+ m_pHorzScrollBar->RemoveStates(FWL_STATE_WGT_Invisible);
}
- if (bSet)
- m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused);
- else
- m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused);
+ m_Properties.m_dwStates |= FWL_STATE_WGT_Focused;
+ RepaintRect(m_ClientRect);
+}
- RepaintRect(m_rtClient);
+void CFWL_ListBox::OnFocusLost() {
+ if (GetStyleExts() & FWL_STYLEEXT_LTB_ShowScrollBarFocus) {
+ if (m_pVertScrollBar)
+ m_pVertScrollBar->SetStates(FWL_STATE_WGT_Invisible);
+ if (m_pHorzScrollBar)
+ m_pHorzScrollBar->SetStates(FWL_STATE_WGT_Invisible);
+ }
+ m_Properties.m_dwStates &= ~FWL_STATE_WGT_Focused;
+ RepaintRect(m_ClientRect);
}
void CFWL_ListBox::OnLButtonDown(CFWL_MessageMouse* pMsg) {
m_bLButtonDown = true;
- CFWL_ListItem* pItem = GetItemAtPoint(pMsg->m_pos);
+ Item* pItem = GetItemAtPoint(pMsg->m_pos);
if (!pItem)
return;
if (IsMultiSelection()) {
- if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) {
- bool bSelected = IsItemSelected(pItem);
- SetSelectionDirect(pItem, !bSelected);
+ if (pMsg->m_dwFlags & XFA_FWL_KeyFlag::kCtrl) {
+ pItem->SetSelected(!pItem->IsSelected());
m_hAnchor = pItem;
- } else if (pMsg->m_dwFlags & FWL_KEYFLAG_Shift) {
+ } else if (pMsg->m_dwFlags & XFA_FWL_KeyFlag::kShift) {
if (m_hAnchor)
SetSelection(m_hAnchor, pItem, true);
else
- SetSelectionDirect(pItem, true);
+ pItem->SetSelected(true);
} else {
SetSelection(pItem, pItem, true);
m_hAnchor = pItem;
@@ -763,7 +694,7 @@ void CFWL_ListBox::OnLButtonDown(CFWL_MessageMouse* pMsg) {
SetFocusItem(pItem);
ScrollToVisible(pItem);
SetGrab(true);
- RepaintRect(m_rtClient);
+ RepaintRect(m_ClientRect);
}
void CFWL_ListBox::OnLButtonUp(CFWL_MessageMouse* pMsg) {
@@ -775,22 +706,21 @@ void CFWL_ListBox::OnLButtonUp(CFWL_MessageMouse* pMsg) {
}
void CFWL_ListBox::OnMouseWheel(CFWL_MessageMouseWheel* pMsg) {
- if (IsShowScrollBar(true))
+ if (IsShowVertScrollBar())
m_pVertScrollBar->GetDelegate()->OnProcessMessage(pMsg);
}
void CFWL_ListBox::OnKeyDown(CFWL_MessageKey* pMsg) {
- uint32_t dwKeyCode = pMsg->m_dwKeyCode;
+ auto dwKeyCode = static_cast<XFA_FWL_VKEYCODE>(pMsg->m_dwKeyCodeOrChar);
switch (dwKeyCode) {
case XFA_FWL_VKEY_Tab:
case XFA_FWL_VKEY_Up:
case XFA_FWL_VKEY_Down:
case XFA_FWL_VKEY_Home:
case XFA_FWL_VKEY_End: {
- CFWL_ListItem* pItem = GetFocusedItem();
- pItem = GetListItem(pItem, dwKeyCode);
- bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift);
- bool bCtrl = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl);
+ Item* pItem = GetListItem(GetFocusedItem(), dwKeyCode);
+ bool bShift = !!(pMsg->m_dwFlags & XFA_FWL_KeyFlag::kShift);
+ bool bCtrl = !!(pMsg->m_dwFlags & XFA_FWL_KeyFlag::kCtrl);
OnVK(pItem, bShift, bCtrl);
break;
}
@@ -799,7 +729,7 @@ void CFWL_ListBox::OnKeyDown(CFWL_MessageKey* pMsg) {
}
}
-void CFWL_ListBox::OnVK(CFWL_ListItem* pItem, bool bShift, bool bCtrl) {
+void CFWL_ListBox::OnVK(Item* pItem, bool bShift, bool bCtrl) {
if (!pItem)
return;
@@ -810,7 +740,7 @@ void CFWL_ListBox::OnVK(CFWL_ListItem* pItem, bool bShift, bool bCtrl) {
if (m_hAnchor)
SetSelection(m_hAnchor, pItem, true);
else
- SetSelectionDirect(pItem, true);
+ pItem->SetSelected(true);
} else {
SetSelection(pItem, pItem, true);
m_hAnchor = pItem;
@@ -821,49 +751,48 @@ void CFWL_ListBox::OnVK(CFWL_ListItem* pItem, bool bShift, bool bCtrl) {
SetFocusItem(pItem);
ScrollToVisible(pItem);
-
- RepaintRect(CFX_RectF(0, 0, m_pProperties->m_rtWidget.width,
- m_pProperties->m_rtWidget.height));
+ RepaintRect(CFX_RectF(0, 0, m_WidgetRect.width, m_WidgetRect.height));
}
bool CFWL_ListBox::OnScroll(CFWL_ScrollBar* pScrollBar,
CFWL_EventScroll::Code dwCode,
float fPos) {
- CFX_SizeF fs;
- pScrollBar->GetRange(&fs.width, &fs.height);
+ float fMin;
+ float fMax;
+ pScrollBar->GetRange(&fMin, &fMax);
float iCurPos = pScrollBar->GetPos();
float fStep = pScrollBar->GetStepSize();
switch (dwCode) {
case CFWL_EventScroll::Code::Min: {
- fPos = fs.width;
+ fPos = fMin;
break;
}
case CFWL_EventScroll::Code::Max: {
- fPos = fs.height;
+ fPos = fMax;
break;
}
case CFWL_EventScroll::Code::StepBackward: {
fPos -= fStep;
- if (fPos < fs.width + fStep / 2)
- fPos = fs.width;
+ if (fPos < fMin + fStep / 2)
+ fPos = fMin;
break;
}
case CFWL_EventScroll::Code::StepForward: {
fPos += fStep;
- if (fPos > fs.height - fStep / 2)
- fPos = fs.height;
+ if (fPos > fMax - fStep / 2)
+ fPos = fMax;
break;
}
case CFWL_EventScroll::Code::PageBackward: {
fPos -= pScrollBar->GetPageSize();
- if (fPos < fs.width)
- fPos = fs.width;
+ if (fPos < fMin)
+ fPos = fMin;
break;
}
case CFWL_EventScroll::Code::PageForward: {
fPos += pScrollBar->GetPageSize();
- if (fPos > fs.height)
- fPos = fs.height;
+ if (fPos > fMax)
+ fPos = fMax;
break;
}
case CFWL_EventScroll::Code::Pos:
@@ -876,33 +805,34 @@ bool CFWL_ListBox::OnScroll(CFWL_ScrollBar* pScrollBar,
if (iCurPos != fPos) {
pScrollBar->SetPos(fPos);
pScrollBar->SetTrackPos(fPos);
- RepaintRect(m_rtClient);
+ RepaintRect(m_ClientRect);
}
return true;
}
int32_t CFWL_ListBox::CountItems(const CFWL_Widget* pWidget) const {
- return pdfium::CollectionSize<int32_t>(m_ItemArray);
+ return fxcrt::CollectionSize<int32_t>(m_ItemArray);
}
-CFWL_ListItem* CFWL_ListBox::GetItem(const CFWL_Widget* pWidget,
- int32_t nIndex) const {
+CFWL_ListBox::Item* CFWL_ListBox::GetItem(const CFWL_Widget* pWidget,
+ int32_t nIndex) const {
if (nIndex < 0 || nIndex >= CountItems(pWidget))
return nullptr;
return m_ItemArray[nIndex].get();
}
-int32_t CFWL_ListBox::GetItemIndex(CFWL_Widget* pWidget, CFWL_ListItem* pItem) {
- auto it =
- std::find_if(m_ItemArray.begin(), m_ItemArray.end(),
- [pItem](const std::unique_ptr<CFWL_ListItem>& candidate) {
- return candidate.get() == pItem;
- });
- return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1;
+int32_t CFWL_ListBox::GetItemIndex(CFWL_Widget* pWidget, Item* pItem) {
+ auto it = std::find_if(m_ItemArray.begin(), m_ItemArray.end(),
+ [pItem](const std::unique_ptr<Item>& candidate) {
+ return candidate.get() == pItem;
+ });
+ return it != m_ItemArray.end()
+ ? pdfium::base::checked_cast<int32_t>(it - m_ItemArray.begin())
+ : -1;
}
-CFWL_ListItem* CFWL_ListBox::AddString(const WideString& wsAdd) {
- m_ItemArray.emplace_back(pdfium::MakeUnique<CFWL_ListItem>(wsAdd));
+CFWL_ListBox::Item* CFWL_ListBox::AddString(const WideString& wsAdd) {
+ m_ItemArray.push_back(std::make_unique<Item>(wsAdd));
return m_ItemArray.back().get();
}
@@ -912,7 +842,7 @@ void CFWL_ListBox::RemoveAt(int32_t iIndex) {
m_ItemArray.erase(m_ItemArray.begin() + iIndex);
}
-void CFWL_ListBox::DeleteString(CFWL_ListItem* pItem) {
+void CFWL_ListBox::DeleteString(Item* pItem) {
int32_t nIndex = GetItemIndex(this, pItem);
if (nIndex < 0 || static_cast<size_t>(nIndex) >= m_ItemArray.size())
return;
@@ -921,13 +851,17 @@ void CFWL_ListBox::DeleteString(CFWL_ListItem* pItem) {
if (iSel >= CountItems(this))
iSel = nIndex - 1;
if (iSel >= 0) {
- if (CFWL_ListItem* item = GetItem(this, iSel))
- item->SetStates(item->GetStates() | FWL_ITEMSTATE_LTB_Selected);
+ Item* item = GetItem(this, iSel);
+ if (item)
+ item->SetSelected(true);
}
-
m_ItemArray.erase(m_ItemArray.begin() + nIndex);
}
void CFWL_ListBox::DeleteAll() {
m_ItemArray.clear();
}
+
+CFWL_ListBox::Item::Item(const WideString& text) : m_wsText(text) {}
+
+CFWL_ListBox::Item::~Item() = default;
diff --git a/xfa/fwl/cfwl_listbox.h b/xfa/fwl/cfwl_listbox.h
index 178e49a8d..9f27b6530 100644
--- a/xfa/fwl/cfwl_listbox.h
+++ b/xfa/fwl/cfwl_listbox.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -13,9 +13,8 @@
#include "xfa/fwl/cfwl_edit.h"
#include "xfa/fwl/cfwl_event.h"
#include "xfa/fwl/cfwl_listbox.h"
-#include "xfa/fwl/cfwl_listitem.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fwl/cfwl_widgetproperties.h"
+#include "xfa/fwl/fwl_widgetdef.h"
#define FWL_STYLEEXT_LTB_MultiSelection (1L << 0)
#define FWL_STYLEEXT_LTB_LeftAlign (0L << 4)
@@ -23,113 +22,122 @@
#define FWL_STYLEEXT_LTB_RightAlign (2L << 4)
#define FWL_STYLEEXT_LTB_AlignMask (3L << 4)
#define FWL_STYLEEXT_LTB_ShowScrollBarFocus (1L << 10)
-#define FWL_ITEMSTATE_LTB_Selected (1L << 0)
-#define FWL_ITEMSTATE_LTB_Focused (1L << 1)
-class CFWL_MessageKillFocus;
class CFWL_MessageMouse;
class CFWL_MessageMouseWheel;
-class CFX_DIBitmap;
class CFWL_ListBox : public CFWL_Widget {
public:
- explicit CFWL_ListBox(const CFWL_App* pApp,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter);
+ class Item {
+ public:
+ explicit Item(const WideString& text);
+ ~Item();
+
+ bool IsSelected() const { return m_bIsSelected; }
+ void SetSelected(bool enable) { m_bIsSelected = enable; }
+ bool IsFocused() const { return m_bIsFocused; }
+ void SetFocused(bool enable) { m_bIsFocused = enable; }
+ CFX_RectF GetRect() const { return m_ItemRect; }
+ void SetRect(const CFX_RectF& rect) { m_ItemRect = rect; }
+ WideString GetText() const { return m_wsText; }
+
+ private:
+ bool m_bIsSelected = false;
+ bool m_bIsFocused = false;
+ CFX_RectF m_ItemRect;
+ const WideString m_wsText;
+ };
+
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_ListBox() override;
- // CFWL_Widget
+ // CFWL_Widget:
+ void Trace(cppgc::Visitor* visitor) const override;
FWL_Type GetClassID() const override;
void Update() override;
FWL_WidgetHit HitTest(const CFX_PointF& point) override;
- void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
- void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override;
+ void DrawWidget(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& matrix) override;
void OnProcessMessage(CFWL_Message* pMessage) override;
void OnProcessEvent(CFWL_Event* pEvent) override;
- void OnDrawWidget(CXFA_Graphics* pGraphics,
+ void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) override;
int32_t CountItems(const CFWL_Widget* pWidget) const;
- CFWL_ListItem* GetItem(const CFWL_Widget* pWidget, int32_t nIndex) const;
- int32_t GetItemIndex(CFWL_Widget* pWidget, CFWL_ListItem* pItem);
-
- CFWL_ListItem* AddString(const WideString& wsAdd);
+ Item* GetItem(const CFWL_Widget* pWidget, int32_t nIndex) const;
+ int32_t GetItemIndex(CFWL_Widget* pWidget, Item* pItem);
+ Item* AddString(const WideString& wsAdd);
void RemoveAt(int32_t iIndex);
- void DeleteString(CFWL_ListItem* pItem);
+ void DeleteString(Item* pItem);
void DeleteAll();
-
int32_t CountSelItems();
- CFWL_ListItem* GetSelItem(int32_t nIndexSel);
+ Item* GetSelItem(int32_t nIndexSel);
int32_t GetSelIndex(int32_t nIndex);
- void SetSelItem(CFWL_ListItem* hItem, bool bSelect);
-
- float GetItemHeight() const { return m_fItemHeight; }
+ void SetSelItem(Item* hItem, bool bSelect);
float CalcItemHeight();
protected:
- CFWL_ListItem* GetListItem(CFWL_ListItem* hItem, uint32_t dwKeyCode);
- void SetSelection(CFWL_ListItem* hStart, CFWL_ListItem* hEnd, bool bSelected);
- CFWL_ListItem* GetItemAtPoint(const CFX_PointF& point);
- bool ScrollToVisible(CFWL_ListItem* hItem);
+ CFWL_ListBox(CFWL_App* pApp,
+ const Properties& properties,
+ CFWL_Widget* pOuter);
+
+ Item* GetListItem(Item* hItem, XFA_FWL_VKEYCODE dwKeyCode);
+ void SetSelection(Item* hStart, Item* hEnd, bool bSelected);
+ Item* GetItemAtPoint(const CFX_PointF& point);
+ bool ScrollToVisible(Item* hItem);
void InitVerticalScrollBar();
void InitHorizontalScrollBar();
- bool IsShowScrollBar(bool bVert);
- CFWL_ScrollBar* GetVertScrollBar() const { return m_pVertScrollBar.get(); }
- const CFX_RectF& GetRTClient() const { return m_rtClient; }
+ bool IsShowVertScrollBar() const;
+ bool IsShowHorzScrollBar() const;
+ bool ScrollBarPropertiesPresent() const;
+ CFWL_ScrollBar* GetVertScrollBar() const { return m_pVertScrollBar; }
+ const CFX_RectF& GetRTClient() const { return m_ClientRect; }
private:
- void SetSelectionDirect(CFWL_ListItem* hItem, bool bSelect);
bool IsMultiSelection() const;
- bool IsItemSelected(CFWL_ListItem* hItem);
void ClearSelection();
void SelectAll();
- CFWL_ListItem* GetFocusedItem();
- void SetFocusItem(CFWL_ListItem* hItem);
- void DrawBkground(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawItems(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawItem(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- CFWL_ListItem* hItem,
+ Item* GetFocusedItem();
+ void SetFocusItem(Item* hItem);
+ void DrawBkground(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawItems(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawItem(CFGAS_GEGraphics* pGraphics,
+ Item* hItem,
int32_t Index,
const CFX_RectF& rtItem,
- const CFX_Matrix* pMatrix);
- void DrawStatic(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme);
- CFX_SizeF CalcSize(bool bAutoSize);
- void UpdateItemSize(CFWL_ListItem* hItem,
+ const CFX_Matrix& pMatrix);
+ void DrawStatic(CFGAS_GEGraphics* pGraphics);
+ CFX_SizeF CalcSize();
+ void UpdateItemSize(Item* hItem,
CFX_SizeF& size,
float fWidth,
- float fHeight,
- bool bAutoSize) const;
+ float fHeight) const;
float GetMaxTextWidth();
float GetScrollWidth();
- void OnFocusChanged(CFWL_Message* pMsg, bool bSet);
+ void OnFocusGained();
+ void OnFocusLost();
void OnLButtonDown(CFWL_MessageMouse* pMsg);
void OnLButtonUp(CFWL_MessageMouse* pMsg);
void OnMouseWheel(CFWL_MessageMouseWheel* pMsg);
void OnKeyDown(CFWL_MessageKey* pMsg);
- void OnVK(CFWL_ListItem* hItem, bool bShift, bool bCtrl);
+ void OnVK(Item* hItem, bool bShift, bool bCtrl);
bool OnScroll(CFWL_ScrollBar* pScrollBar,
CFWL_EventScroll::Code dwCode,
float fPos);
- CFX_RectF m_rtClient;
- CFX_RectF m_rtStatic;
- CFX_RectF m_rtConent;
- std::unique_ptr<CFWL_ScrollBar> m_pHorzScrollBar;
- std::unique_ptr<CFWL_ScrollBar> m_pVertScrollBar;
+ CFX_RectF m_ClientRect;
+ CFX_RectF m_StaticRect;
+ CFX_RectF m_ContentRect;
+ cppgc::Member<CFWL_ScrollBar> m_pHorzScrollBar;
+ cppgc::Member<CFWL_ScrollBar> m_pVertScrollBar;
FDE_TextStyle m_TTOStyles;
FDE_TextAlignment m_iTTOAligns = FDE_TextAlignment::kTopLeft;
bool m_bLButtonDown = false;
float m_fItemHeight = 0.0f;
float m_fScorllBarWidth = 0.0f;
- CFWL_ListItem* m_hAnchor = nullptr;
- IFWL_ThemeProvider* m_pScrollBarTP = nullptr;
- std::vector<std::unique_ptr<CFWL_ListItem>> m_ItemArray;
+ Item* m_hAnchor = nullptr;
+ std::vector<std::unique_ptr<Item>> m_ItemArray;
};
#endif // XFA_FWL_CFWL_LISTBOX_H_
diff --git a/xfa/fwl/cfwl_listitem.cpp b/xfa/fwl/cfwl_listitem.cpp
deleted file mode 100644
index edf1be355..000000000
--- a/xfa/fwl/cfwl_listitem.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fwl/cfwl_listitem.h"
-
-CFWL_ListItem::CFWL_ListItem(const WideString& text) : m_wsText(text) {}
-
-CFWL_ListItem::~CFWL_ListItem() {}
diff --git a/xfa/fwl/cfwl_listitem.h b/xfa/fwl/cfwl_listitem.h
deleted file mode 100644
index a6afb224c..000000000
--- a/xfa/fwl/cfwl_listitem.h
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FWL_CFWL_LISTITEM_H_
-#define XFA_FWL_CFWL_LISTITEM_H_
-
-#include "core/fxcrt/fx_coordinates.h"
-#include "core/fxcrt/fx_string.h"
-
-class CFWL_ListItem {
- public:
- explicit CFWL_ListItem(const WideString& text);
- ~CFWL_ListItem();
-
- CFX_RectF GetRect() const { return m_rtItem; }
- void SetRect(const CFX_RectF& rect) { m_rtItem = rect; }
-
- uint32_t GetStates() const { return m_dwStates; }
- void SetStates(uint32_t dwStates) { m_dwStates = dwStates; }
-
- WideString GetText() const { return m_wsText; }
-
- private:
- uint32_t m_dwStates = 0;
- CFX_RectF m_rtItem;
- WideString m_wsText;
-};
-
-#endif // XFA_FWL_CFWL_LISTITEM_H_
diff --git a/xfa/fwl/cfwl_message.cpp b/xfa/fwl/cfwl_message.cpp
index f330a0841..d388f7e79 100644
--- a/xfa/fwl/cfwl_message.cpp
+++ b/xfa/fwl/cfwl_message.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,9 +6,7 @@
#include "xfa/fwl/cfwl_message.h"
-CFWL_Message::CFWL_Message(Type type,
- CFWL_Widget* pSrcTarget,
- CFWL_Widget* pDstTarget)
- : m_type(type), m_pSrcTarget(pSrcTarget), m_pDstTarget(pDstTarget) {}
+CFWL_Message::CFWL_Message(Type type, CFWL_Widget* pDstTarget)
+ : m_type(type), m_pDstTarget(pDstTarget) {}
CFWL_Message::~CFWL_Message() = default;
diff --git a/xfa/fwl/cfwl_message.h b/xfa/fwl/cfwl_message.h
index 69f7bf533..3a8d53d4c 100644
--- a/xfa/fwl/cfwl_message.h
+++ b/xfa/fwl/cfwl_message.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,34 +7,32 @@
#ifndef XFA_FWL_CFWL_MESSAGE_H_
#define XFA_FWL_CFWL_MESSAGE_H_
-#include <memory>
+#include "core/fxcrt/mask.h"
+#include "core/fxcrt/unowned_ptr.h"
+#include "v8/include/cppgc/macros.h"
-#include "core/fxcrt/fx_string.h"
-#include "core/fxcrt/fx_system.h"
-#include "core/fxcrt/observed_ptr.h"
-#include "xfa/fwl/cfwl_widget.h"
+class CFWL_Widget;
class CFWL_Message {
+ CPPGC_STACK_ALLOCATED(); // Allow Raw/Unowned pointers.
+
public:
- enum class Type { Key, KillFocus, Mouse, MouseWheel, SetFocus };
+ enum class Type { kKey, kKillFocus, kMouse, kMouseWheel, kSetFocus };
virtual ~CFWL_Message();
Type GetType() const { return m_type; }
- CFWL_Widget* GetSrcTarget() const { return m_pSrcTarget.Get(); }
- CFWL_Widget* GetDstTarget() const { return m_pDstTarget.Get(); }
- void SetSrcTarget(CFWL_Widget* pWidget) { m_pSrcTarget.Reset(pWidget); }
- void SetDstTarget(CFWL_Widget* pWidget) { m_pDstTarget.Reset(pWidget); }
+ CFWL_Widget* GetDstTarget() const { return m_pDstTarget; }
+ void SetDstTarget(CFWL_Widget* pWidget) { m_pDstTarget = pWidget; }
protected:
- CFWL_Message(Type type, CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget);
+ CFWL_Message(Type type, CFWL_Widget* pDstTarget);
CFWL_Message(const CFWL_Message& that) = delete;
CFWL_Message& operator=(const CFWL_Message& that) = delete;
private:
const Type m_type;
- ObservedPtr<CFWL_Widget> m_pSrcTarget;
- ObservedPtr<CFWL_Widget> m_pDstTarget;
+ UnownedPtr<CFWL_Widget> m_pDstTarget;
};
#endif // XFA_FWL_CFWL_MESSAGE_H_
diff --git a/xfa/fwl/cfwl_messagekey.cpp b/xfa/fwl/cfwl_messagekey.cpp
index 9abb0c1a3..2e9269dc0 100644
--- a/xfa/fwl/cfwl_messagekey.cpp
+++ b/xfa/fwl/cfwl_messagekey.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,17 +6,13 @@
#include "xfa/fwl/cfwl_messagekey.h"
-#include <memory>
-
-#include "third_party/base/ptr_util.h"
-
CFWL_MessageKey::CFWL_MessageKey(CFWL_Widget* pDstTarget,
- FWL_KeyCommand cmd,
- uint32_t flags,
- uint32_t keycode)
- : CFWL_Message(CFWL_Message::Type::Key, nullptr, pDstTarget),
+ KeyCommand cmd,
+ Mask<XFA_FWL_KeyFlag> flags,
+ uint32_t dwKeyCodeOrChar)
+ : CFWL_Message(CFWL_Message::Type::kKey, pDstTarget),
m_dwCmd(cmd),
m_dwFlags(flags),
- m_dwKeyCode(keycode) {}
+ m_dwKeyCodeOrChar(dwKeyCodeOrChar) {}
CFWL_MessageKey::~CFWL_MessageKey() = default;
diff --git a/xfa/fwl/cfwl_messagekey.h b/xfa/fwl/cfwl_messagekey.h
index b1226479b..96f461066 100644
--- a/xfa/fwl/cfwl_messagekey.h
+++ b/xfa/fwl/cfwl_messagekey.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,23 +7,23 @@
#ifndef XFA_FWL_CFWL_MESSAGEKEY_H_
#define XFA_FWL_CFWL_MESSAGEKEY_H_
-#include <memory>
-
+#include "core/fxcrt/mask.h"
#include "xfa/fwl/cfwl_message.h"
-
-enum class FWL_KeyCommand { KeyDown, KeyUp, Char };
+#include "xfa/fwl/fwl_widgetdef.h"
class CFWL_MessageKey final : public CFWL_Message {
public:
+ enum class KeyCommand : uint8_t { kKeyDown, kChar };
+
CFWL_MessageKey(CFWL_Widget* pDstTarget,
- FWL_KeyCommand cmd,
- uint32_t flags,
- uint32_t keycode);
+ KeyCommand subtype,
+ Mask<XFA_FWL_KeyFlag> flags,
+ uint32_t dwKeyCodeOrChar);
~CFWL_MessageKey() override;
- const FWL_KeyCommand m_dwCmd;
- const uint32_t m_dwFlags;
- const uint32_t m_dwKeyCode;
+ const KeyCommand m_dwCmd;
+ const Mask<XFA_FWL_KeyFlag> m_dwFlags;
+ const uint32_t m_dwKeyCodeOrChar;
};
#endif // XFA_FWL_CFWL_MESSAGEKEY_H_
diff --git a/xfa/fwl/cfwl_messagekillfocus.cpp b/xfa/fwl/cfwl_messagekillfocus.cpp
index 15fe562b2..a6c064976 100644
--- a/xfa/fwl/cfwl_messagekillfocus.cpp
+++ b/xfa/fwl/cfwl_messagekillfocus.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,15 +6,7 @@
#include "xfa/fwl/cfwl_messagekillfocus.h"
-#include <memory>
-
-#include "third_party/base/ptr_util.h"
-
-CFWL_MessageKillFocus::CFWL_MessageKillFocus(CFWL_Widget* pSrcTarget)
- : CFWL_MessageKillFocus(pSrcTarget, nullptr) {}
-
-CFWL_MessageKillFocus::CFWL_MessageKillFocus(CFWL_Widget* pSrcTarget,
- CFWL_Widget* pDstTarget)
- : CFWL_Message(CFWL_Message::Type::KillFocus, pSrcTarget, pDstTarget) {}
+CFWL_MessageKillFocus::CFWL_MessageKillFocus(CFWL_Widget* pDstTarget)
+ : CFWL_Message(CFWL_Message::Type::kKillFocus, pDstTarget) {}
CFWL_MessageKillFocus::~CFWL_MessageKillFocus() = default;
diff --git a/xfa/fwl/cfwl_messagekillfocus.h b/xfa/fwl/cfwl_messagekillfocus.h
index 18e64f98d..996fc10ad 100644
--- a/xfa/fwl/cfwl_messagekillfocus.h
+++ b/xfa/fwl/cfwl_messagekillfocus.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,15 +7,12 @@
#ifndef XFA_FWL_CFWL_MESSAGEKILLFOCUS_H_
#define XFA_FWL_CFWL_MESSAGEKILLFOCUS_H_
-#include <memory>
-
#include "core/fxcrt/unowned_ptr.h"
#include "xfa/fwl/cfwl_message.h"
class CFWL_MessageKillFocus final : public CFWL_Message {
public:
- explicit CFWL_MessageKillFocus(CFWL_Widget* pSrcTarget);
- CFWL_MessageKillFocus(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget);
+ explicit CFWL_MessageKillFocus(CFWL_Widget* pDstTarget);
~CFWL_MessageKillFocus() override;
bool IsFocusedOnWidget(const CFWL_Widget* pWidget) const {
@@ -23,7 +20,7 @@ class CFWL_MessageKillFocus final : public CFWL_Message {
}
private:
- UnownedPtr<CFWL_Widget> m_pSetFocus;
+ UnownedPtr<CFWL_Widget> m_pSetFocus; // Ok, stack-only.
};
#endif // XFA_FWL_CFWL_MESSAGEKILLFOCUS_H_
diff --git a/xfa/fwl/cfwl_messagemouse.cpp b/xfa/fwl/cfwl_messagemouse.cpp
index 395c9e6cc..50aa80152 100644
--- a/xfa/fwl/cfwl_messagemouse.cpp
+++ b/xfa/fwl/cfwl_messagemouse.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,20 +6,11 @@
#include "xfa/fwl/cfwl_messagemouse.h"
-#include <memory>
-
-#include "third_party/base/ptr_util.h"
-
-CFWL_MessageMouse::CFWL_MessageMouse(CFWL_Widget* pDstTarget,
- FWL_MouseCommand cmd)
- : CFWL_Message(CFWL_Message::Type::Mouse, nullptr, pDstTarget),
- m_dwCmd(cmd) {}
-
CFWL_MessageMouse::CFWL_MessageMouse(CFWL_Widget* pDstTarget,
- FWL_MouseCommand cmd,
- uint32_t flags,
+ MouseCommand cmd,
+ Mask<XFA_FWL_KeyFlag> flags,
CFX_PointF pos)
- : CFWL_Message(CFWL_Message::Type::Mouse, nullptr, pDstTarget),
+ : CFWL_Message(CFWL_Message::Type::kMouse, pDstTarget),
m_dwCmd(cmd),
m_dwFlags(flags),
m_pos(pos) {}
diff --git a/xfa/fwl/cfwl_messagemouse.h b/xfa/fwl/cfwl_messagemouse.h
index 10c298ac2..fda76688e 100644
--- a/xfa/fwl/cfwl_messagemouse.h
+++ b/xfa/fwl/cfwl_messagemouse.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,35 +7,34 @@
#ifndef XFA_FWL_CFWL_MESSAGEMOUSE_H_
#define XFA_FWL_CFWL_MESSAGEMOUSE_H_
-#include <memory>
-
#include "core/fxcrt/fx_coordinates.h"
+#include "core/fxcrt/mask.h"
#include "xfa/fwl/cfwl_message.h"
-
-enum class FWL_MouseCommand {
- LeftButtonDown,
- LeftButtonUp,
- LeftButtonDblClk,
- RightButtonDown,
- RightButtonUp,
- RightButtonDblClk,
- Move,
- Enter,
- Leave,
- Hover
-};
+#include "xfa/fwl/fwl_widgetdef.h"
class CFWL_MessageMouse final : public CFWL_Message {
public:
- CFWL_MessageMouse(CFWL_Widget* pDstTarget, FWL_MouseCommand cmd);
+ enum class MouseCommand : uint8_t {
+ kLeftButtonDown,
+ kLeftButtonUp,
+ kLeftButtonDblClk,
+ kRightButtonDown,
+ kRightButtonUp,
+ kRightButtonDblClk,
+ kMove,
+ kEnter,
+ kLeave,
+ kHover
+ };
+
CFWL_MessageMouse(CFWL_Widget* pDstTarget,
- FWL_MouseCommand cmd,
- uint32_t flags,
+ MouseCommand cmd,
+ Mask<XFA_FWL_KeyFlag> flags,
CFX_PointF pos);
~CFWL_MessageMouse() override;
- const FWL_MouseCommand m_dwCmd;
- uint32_t m_dwFlags = 0;
+ const MouseCommand m_dwCmd;
+ Mask<XFA_FWL_KeyFlag> m_dwFlags;
CFX_PointF m_pos;
};
diff --git a/xfa/fwl/cfwl_messagemousewheel.cpp b/xfa/fwl/cfwl_messagemousewheel.cpp
index 333117908..8eb51cbdd 100644
--- a/xfa/fwl/cfwl_messagemousewheel.cpp
+++ b/xfa/fwl/cfwl_messagemousewheel.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,17 +6,11 @@
#include "xfa/fwl/cfwl_messagemousewheel.h"
-#include <memory>
-
-#include "third_party/base/ptr_util.h"
-
-CFWL_MessageMouseWheel::CFWL_MessageMouseWheel(CFWL_Widget* pDstTarget,
- uint32_t flags,
- CFX_PointF pos,
- CFX_PointF delta)
- : CFWL_Message(CFWL_Message::Type::MouseWheel, nullptr, pDstTarget),
- m_dwFlags(flags),
- m_pos(pos),
- m_delta(delta) {}
+CFWL_MessageMouseWheel::CFWL_MessageMouseWheel(CFWL_Widget* destination,
+ const CFX_PointF& pos,
+ const CFX_Vector& delta)
+ : CFWL_Message(CFWL_Message::Type::kMouseWheel, destination),
+ pos_(pos),
+ delta_(delta) {}
CFWL_MessageMouseWheel::~CFWL_MessageMouseWheel() = default;
diff --git a/xfa/fwl/cfwl_messagemousewheel.h b/xfa/fwl/cfwl_messagemousewheel.h
index 9908951d3..e0ea1c612 100644
--- a/xfa/fwl/cfwl_messagemousewheel.h
+++ b/xfa/fwl/cfwl_messagemousewheel.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,22 +7,24 @@
#ifndef XFA_FWL_CFWL_MESSAGEMOUSEWHEEL_H_
#define XFA_FWL_CFWL_MESSAGEMOUSEWHEEL_H_
-#include <memory>
-
#include "core/fxcrt/fx_coordinates.h"
#include "xfa/fwl/cfwl_message.h"
class CFWL_MessageMouseWheel final : public CFWL_Message {
public:
- CFWL_MessageMouseWheel(CFWL_Widget* pDstTarget,
- uint32_t flags,
- CFX_PointF pos,
- CFX_PointF delta);
+ CFWL_MessageMouseWheel(CFWL_Widget* destination,
+ const CFX_PointF& pos,
+ const CFX_Vector& delta);
~CFWL_MessageMouseWheel() override;
- const uint32_t m_dwFlags;
- CFX_PointF m_pos;
- CFX_PointF m_delta;
+ void set_pos(const CFX_PointF& pos) { pos_ = pos; }
+ const CFX_PointF& pos() const { return pos_; }
+
+ const CFX_Vector& delta() const { return delta_; }
+
+ private:
+ CFX_PointF pos_;
+ const CFX_Vector delta_;
};
#endif // XFA_FWL_CFWL_MESSAGEMOUSEWHEEL_H_
diff --git a/xfa/fwl/cfwl_messagesetfocus.cpp b/xfa/fwl/cfwl_messagesetfocus.cpp
index ec0c27ab0..01b74b250 100644
--- a/xfa/fwl/cfwl_messagesetfocus.cpp
+++ b/xfa/fwl/cfwl_messagesetfocus.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,13 +6,7 @@
#include "xfa/fwl/cfwl_messagesetfocus.h"
-#include <memory>
-
-#include "third_party/base/ptr_util.h"
-
-CFWL_MessageSetFocus::CFWL_MessageSetFocus(CFWL_Widget* pSrcTarget,
- CFWL_Widget* pDstTarget)
- : CFWL_Message(CFWL_Message::Type::SetFocus, pSrcTarget, pDstTarget) {}
+CFWL_MessageSetFocus::CFWL_MessageSetFocus(CFWL_Widget* pDstTarget)
+ : CFWL_Message(CFWL_Message::Type::kSetFocus, pDstTarget) {}
CFWL_MessageSetFocus::~CFWL_MessageSetFocus() = default;
-
diff --git a/xfa/fwl/cfwl_messagesetfocus.h b/xfa/fwl/cfwl_messagesetfocus.h
index 67e003560..2a4f76d42 100644
--- a/xfa/fwl/cfwl_messagesetfocus.h
+++ b/xfa/fwl/cfwl_messagesetfocus.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,13 +7,11 @@
#ifndef XFA_FWL_CFWL_MESSAGESETFOCUS_H_
#define XFA_FWL_CFWL_MESSAGESETFOCUS_H_
-#include <memory>
-
#include "xfa/fwl/cfwl_message.h"
class CFWL_MessageSetFocus final : public CFWL_Message {
public:
- CFWL_MessageSetFocus(CFWL_Widget* pSrcTarget, CFWL_Widget* pDstTarget);
+ explicit CFWL_MessageSetFocus(CFWL_Widget* pDstTarget);
~CFWL_MessageSetFocus() override;
};
diff --git a/xfa/fwl/cfwl_monthcalendar.cpp b/xfa/fwl/cfwl_monthcalendar.cpp
index 76d915628..145198bd9 100644
--- a/xfa/fwl/cfwl_monthcalendar.cpp
+++ b/xfa/fwl/cfwl_monthcalendar.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,8 +10,11 @@
#include <memory>
#include <utility>
-#include "third_party/base/ptr_util.h"
-#include "third_party/base/stl_util.h"
+#include "core/fxcrt/cfx_datetime.h"
+#include "core/fxcrt/stl_util.h"
+#include "third_party/base/check.h"
+#include "third_party/base/containers/contains.h"
+#include "third_party/base/notreached.h"
#include "xfa/fde/cfde_textout.h"
#include "xfa/fwl/cfwl_datetimepicker.h"
#include "xfa/fwl/cfwl_messagemouse.h"
@@ -20,16 +23,16 @@
#include "xfa/fwl/cfwl_themetext.h"
#include "xfa/fwl/ifwl_themeprovider.h"
-#define MONTHCAL_HSEP_HEIGHT 1
-#define MONTHCAL_HMARGIN 3
-#define MONTHCAL_VMARGIN 2
-#define MONTHCAL_ROWS 9
-#define MONTHCAL_COLUMNS 7
-#define MONTHCAL_HEADER_BTN_VMARGIN 7
-#define MONTHCAL_HEADER_BTN_HMARGIN 5
-
namespace {
+constexpr float kMonthCalHSepHeight = 1.0f;
+constexpr float kMonthCalHMargin = 3.0f;
+constexpr float kMonthCalVMargin = 2.0f;
+constexpr float kMonthCalRows = 9.0f;
+constexpr float kMonthCalColumns = 7.0f;
+constexpr float kMonthCalHeaderBtnVMargin = 7.0f;
+constexpr float kMonthCalHeaderBtnHMargin = 5.0f;
+
WideString GetAbbreviatedDayOfWeek(int day) {
switch (day) {
case 0:
@@ -86,11 +89,10 @@ WideString GetMonth(int month) {
} // namespace
-CFWL_MonthCalendar::CFWL_MonthCalendar(
- const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter)
- : CFWL_Widget(app, std::move(properties), pOuter) {}
+CFWL_MonthCalendar::CFWL_MonthCalendar(CFWL_App* app,
+ const Properties& properties,
+ CFWL_Widget* pOuter)
+ : CFWL_Widget(app, properties, pOuter) {}
CFWL_MonthCalendar::~CFWL_MonthCalendar() = default;
@@ -108,44 +110,36 @@ CFX_RectF CFWL_MonthCalendar::GetAutosizedWidgetRect() {
void CFWL_MonthCalendar::Update() {
if (IsLocked())
return;
- if (!m_pProperties->m_pThemeProvider)
- m_pProperties->m_pThemeProvider = GetAvailableTheme();
- GetCapValue();
if (!m_bInitialized) {
InitDate();
m_bInitialized = true;
}
-
ClearDateItem();
ResetDateItem();
Layout();
}
-void CFWL_MonthCalendar::DrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_MonthCalendar::DrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
if (!pGraphics)
return;
- if (!m_pProperties->m_pThemeProvider)
- m_pProperties->m_pThemeProvider = GetAvailableTheme();
-
- IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get();
if (HasBorder())
- DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
-
- DrawBackground(pGraphics, pTheme, &matrix);
- DrawHeadBK(pGraphics, pTheme, &matrix);
- DrawLButton(pGraphics, pTheme, &matrix);
- DrawRButton(pGraphics, pTheme, &matrix);
- DrawSeparator(pGraphics, pTheme, &matrix);
- DrawDatesInBK(pGraphics, pTheme, &matrix);
- DrawDatesInCircle(pGraphics, pTheme, &matrix);
- DrawCaption(pGraphics, pTheme, &matrix);
- DrawWeek(pGraphics, pTheme, &matrix);
- DrawDatesIn(pGraphics, pTheme, &matrix);
- DrawDatesOut(pGraphics, pTheme, &matrix);
- DrawToday(pGraphics, pTheme, &matrix);
+ DrawBorder(pGraphics, CFWL_ThemePart::Part::kBorder, matrix);
+
+ DrawBackground(pGraphics, matrix);
+ DrawHeadBK(pGraphics, matrix);
+ DrawLButton(pGraphics, matrix);
+ DrawRButton(pGraphics, matrix);
+ DrawSeparator(pGraphics, matrix);
+ DrawDatesInBK(pGraphics, matrix);
+ DrawDatesInCircle(pGraphics, matrix);
+ DrawCaption(pGraphics, matrix);
+ DrawWeek(pGraphics, matrix);
+ DrawDatesIn(pGraphics, matrix);
+ DrawDatesOut(pGraphics, matrix);
+ DrawToday(pGraphics, matrix);
}
void CFWL_MonthCalendar::SetSelect(int32_t iYear,
@@ -155,342 +149,269 @@ void CFWL_MonthCalendar::SetSelect(int32_t iYear,
AddSelDay(iDay);
}
-void CFWL_MonthCalendar::DrawBackground(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeBackground params;
- params.m_pWidget = this;
- params.m_iPart = CFWL_Part::Background;
- params.m_pGraphics = pGraphics;
- params.m_dwStates = CFWL_PartState_Normal;
- params.m_rtPart = m_rtClient;
- if (pMatrix)
- params.m_matrix.Concat(*pMatrix);
- pTheme->DrawBackground(params);
-}
-
-void CFWL_MonthCalendar::DrawHeadBK(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeBackground params;
- params.m_pWidget = this;
- params.m_iPart = CFWL_Part::Header;
- params.m_pGraphics = pGraphics;
- params.m_dwStates = CFWL_PartState_Normal;
- params.m_rtPart = m_rtHead;
- if (pMatrix)
- params.m_matrix.Concat(*pMatrix);
- pTheme->DrawBackground(params);
-}
-
-void CFWL_MonthCalendar::DrawLButton(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeBackground params;
- params.m_pWidget = this;
- params.m_iPart = CFWL_Part::LBtn;
- params.m_pGraphics = pGraphics;
+void CFWL_MonthCalendar::DrawBackground(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeBackground params(CFWL_ThemePart::Part::kBackground, this,
+ pGraphics);
+ params.m_PartRect = m_ClientRect;
+ params.m_matrix = mtMatrix;
+ GetThemeProvider()->DrawBackground(params);
+}
+
+void CFWL_MonthCalendar::DrawHeadBK(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeBackground params(CFWL_ThemePart::Part::kHeader, this, pGraphics);
+ params.m_PartRect = m_HeadRect;
+ params.m_matrix = mtMatrix;
+ GetThemeProvider()->DrawBackground(params);
+}
+
+void CFWL_MonthCalendar::DrawLButton(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeBackground params(CFWL_ThemePart::Part::kLBtn, this, pGraphics);
params.m_dwStates = m_iLBtnPartStates;
- params.m_rtPart = m_rtLBtn;
- if (pMatrix)
- params.m_matrix.Concat(*pMatrix);
- pTheme->DrawBackground(params);
-}
-
-void CFWL_MonthCalendar::DrawRButton(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeBackground params;
- params.m_pWidget = this;
- params.m_iPart = CFWL_Part::RBtn;
- params.m_pGraphics = pGraphics;
+ params.m_PartRect = m_LBtnRect;
+ params.m_matrix = mtMatrix;
+ GetThemeProvider()->DrawBackground(params);
+}
+
+void CFWL_MonthCalendar::DrawRButton(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeBackground params(CFWL_ThemePart::Part::kRBtn, this, pGraphics);
params.m_dwStates = m_iRBtnPartStates;
- params.m_rtPart = m_rtRBtn;
- if (pMatrix)
- params.m_matrix.Concat(*pMatrix);
- pTheme->DrawBackground(params);
-}
-
-void CFWL_MonthCalendar::DrawCaption(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeText textParam;
- textParam.m_pWidget = this;
- textParam.m_iPart = CFWL_Part::Caption;
- textParam.m_dwStates = CFWL_PartState_Normal;
- textParam.m_pGraphics = pGraphics;
+ params.m_PartRect = m_RBtnRect;
+ params.m_matrix = mtMatrix;
+ GetThemeProvider()->DrawBackground(params);
+}
+
+void CFWL_MonthCalendar::DrawCaption(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeText textParam(CFWL_ThemePart::Part::kCaption, this, pGraphics);
textParam.m_wsText = GetHeadText(m_iCurYear, m_iCurMonth);
- m_szHead = CalcTextSize(textParam.m_wsText,
- m_pProperties->m_pThemeProvider.Get(), false);
+ m_HeadSize = CalcTextSize(textParam.m_wsText, false);
CalcHeadSize();
- textParam.m_rtPart = m_rtHeadText;
+ textParam.m_PartRect = m_HeadTextRect;
textParam.m_dwTTOStyles.single_line_ = true;
textParam.m_iTTOAlign = FDE_TextAlignment::kCenter;
- if (pMatrix)
- textParam.m_matrix.Concat(*pMatrix);
- pTheme->DrawText(textParam);
-}
-
-void CFWL_MonthCalendar::DrawSeparator(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeBackground params;
- params.m_pWidget = this;
- params.m_iPart = CFWL_Part::HSeparator;
- params.m_pGraphics = pGraphics;
- params.m_dwStates = CFWL_PartState_Normal;
- params.m_rtPart = m_rtHSep;
- if (pMatrix)
- params.m_matrix.Concat(*pMatrix);
- pTheme->DrawBackground(params);
-}
-
-void CFWL_MonthCalendar::DrawDatesInBK(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeBackground params;
- params.m_pWidget = this;
- params.m_iPart = CFWL_Part::DateInBK;
- params.m_pGraphics = pGraphics;
- if (pMatrix)
- params.m_matrix.Concat(*pMatrix);
-
- int32_t iCount = pdfium::CollectionSize<int32_t>(m_arrDates);
+ textParam.m_matrix = mtMatrix;
+ GetThemeProvider()->DrawText(textParam);
+}
+
+void CFWL_MonthCalendar::DrawSeparator(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeBackground params(CFWL_ThemePart::Part::kHSeparator, this,
+ pGraphics);
+ params.m_PartRect = m_HSepRect;
+ params.m_matrix = mtMatrix;
+ GetThemeProvider()->DrawBackground(params);
+}
+
+void CFWL_MonthCalendar::DrawDatesInBK(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeBackground params(CFWL_ThemePart::Part::kDateInBK, this, pGraphics);
+ params.m_matrix = mtMatrix;
+
+ IFWL_ThemeProvider* pTheme = GetThemeProvider();
+ int32_t iCount = fxcrt::CollectionSize<int32_t>(m_DateArray);
for (int32_t j = 0; j < iCount; j++) {
- DATEINFO* pDataInfo = m_arrDates[j].get();
- if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Selected) {
- params.m_dwStates |= CFWL_PartState_Selected;
- if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) {
- params.m_dwStates |= CFWL_PartState_Flagged;
+ DATEINFO* pDataInfo = m_DateArray[j].get();
+ if (pDataInfo->bSelected) {
+ params.m_dwStates |= CFWL_PartState::kSelected;
+ if (pDataInfo->bFlagged) {
+ params.m_dwStates |= CFWL_PartState::kFlagged;
}
} else if (j == m_iHovered - 1) {
- params.m_dwStates |= CFWL_PartState_Hovered;
- } else if (pDataInfo->dwStates & FWL_ITEMSTATE_MCD_Flag) {
- params.m_dwStates = CFWL_PartState_Flagged;
+ params.m_dwStates |= CFWL_PartState::kHovered;
+ } else if (pDataInfo->bFlagged) {
+ params.m_dwStates = CFWL_PartState::kFlagged;
pTheme->DrawBackground(params);
}
- params.m_rtPart = pDataInfo->rect;
+ params.m_PartRect = pDataInfo->rect;
pTheme->DrawBackground(params);
- params.m_dwStates = 0;
+ params.m_dwStates = CFWL_PartState::kNormal;
}
}
-void CFWL_MonthCalendar::DrawWeek(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeText params;
- params.m_pWidget = this;
- params.m_iPart = CFWL_Part::Week;
- params.m_pGraphics = pGraphics;
- params.m_dwStates = CFWL_PartState_Normal;
+void CFWL_MonthCalendar::DrawWeek(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeText params(CFWL_ThemePart::Part::kWeek, this, pGraphics);
params.m_iTTOAlign = FDE_TextAlignment::kCenter;
params.m_dwTTOStyles.single_line_ = true;
+ params.m_matrix = mtMatrix;
+ IFWL_ThemeProvider* pTheme = GetThemeProvider();
CFX_RectF rtDayOfWeek;
- if (pMatrix)
- params.m_matrix.Concat(*pMatrix);
-
for (int32_t i = 0; i < 7; ++i) {
- rtDayOfWeek =
- CFX_RectF(m_rtWeek.left + i * (m_szCell.width + MONTHCAL_HMARGIN * 2),
- m_rtWeek.top, m_szCell);
+ rtDayOfWeek = CFX_RectF(
+ m_WeekRect.left + i * (m_CellSize.width + kMonthCalHMargin * 2),
+ m_WeekRect.top, m_CellSize);
- params.m_rtPart = rtDayOfWeek;
+ params.m_PartRect = rtDayOfWeek;
params.m_wsText = GetAbbreviatedDayOfWeek(i);
pTheme->DrawText(params);
}
}
-void CFWL_MonthCalendar::DrawToday(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeText params;
- params.m_pWidget = this;
- params.m_iPart = CFWL_Part::Today;
- params.m_pGraphics = pGraphics;
- params.m_dwStates = CFWL_PartState_Normal;
+void CFWL_MonthCalendar::DrawToday(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeText params(CFWL_ThemePart::Part::kToday, this, pGraphics);
params.m_iTTOAlign = FDE_TextAlignment::kCenterLeft;
params.m_wsText = GetTodayText(m_iYear, m_iMonth, m_iDay);
-
- m_szToday = CalcTextSize(params.m_wsText,
- m_pProperties->m_pThemeProvider.Get(), false);
+ m_TodaySize = CalcTextSize(params.m_wsText, false);
CalcTodaySize();
- params.m_rtPart = m_rtToday;
+ params.m_PartRect = m_TodayRect;
params.m_dwTTOStyles.single_line_ = true;
-
- if (pMatrix)
- params.m_matrix.Concat(*pMatrix);
- pTheme->DrawText(params);
+ params.m_matrix = mtMatrix;
+ GetThemeProvider()->DrawText(params);
}
-void CFWL_MonthCalendar::DrawDatesIn(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeText params;
- params.m_pWidget = this;
- params.m_iPart = CFWL_Part::DatesIn;
- params.m_pGraphics = pGraphics;
- params.m_dwStates = CFWL_PartState_Normal;
+void CFWL_MonthCalendar::DrawDatesIn(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeText params(CFWL_ThemePart::Part::kDatesIn, this, pGraphics);
params.m_iTTOAlign = FDE_TextAlignment::kCenter;
- if (pMatrix)
- params.m_matrix.Concat(*pMatrix);
+ params.m_matrix = mtMatrix;
- int32_t iCount = pdfium::CollectionSize<int32_t>(m_arrDates);
+ IFWL_ThemeProvider* pTheme = GetThemeProvider();
+ int32_t iCount = fxcrt::CollectionSize<int32_t>(m_DateArray);
for (int32_t j = 0; j < iCount; j++) {
- DATEINFO* pDataInfo = m_arrDates[j].get();
+ DATEINFO* pDataInfo = m_DateArray[j].get();
params.m_wsText = pDataInfo->wsDay;
- params.m_rtPart = pDataInfo->rect;
- params.m_dwStates = pDataInfo->dwStates;
+ params.m_PartRect = pDataInfo->rect;
+ params.m_dwStates = pDataInfo->AsPartStateMask();
if (j + 1 == m_iHovered)
- params.m_dwStates |= CFWL_PartState_Hovered;
+ params.m_dwStates |= CFWL_PartState::kHovered;
params.m_dwTTOStyles.single_line_ = true;
pTheme->DrawText(params);
}
}
-void CFWL_MonthCalendar::DrawDatesOut(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeText params;
- params.m_pWidget = this;
- params.m_iPart = CFWL_Part::DatesOut;
- params.m_pGraphics = pGraphics;
- params.m_dwStates = CFWL_PartState_Normal;
+void CFWL_MonthCalendar::DrawDatesOut(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeText params(CFWL_ThemePart::Part::kDatesOut, this, pGraphics);
params.m_iTTOAlign = FDE_TextAlignment::kCenter;
- if (pMatrix)
- params.m_matrix.Concat(*pMatrix);
- pTheme->DrawText(params);
+ params.m_matrix = mtMatrix;
+ GetThemeProvider()->DrawText(params);
}
-void CFWL_MonthCalendar::DrawDatesInCircle(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
+void CFWL_MonthCalendar::DrawDatesInCircle(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
if (m_iMonth != m_iCurMonth || m_iYear != m_iCurYear)
return;
- if (m_iDay < 1 || m_iDay > pdfium::CollectionSize<int32_t>(m_arrDates))
+ if (m_iDay < 1 || m_iDay > fxcrt::CollectionSize<int32_t>(m_DateArray))
return;
- DATEINFO* pDate = m_arrDates[m_iDay - 1].get();
+ DATEINFO* pDate = m_DateArray[m_iDay - 1].get();
if (!pDate)
return;
- CFWL_ThemeBackground params;
- params.m_pWidget = this;
- params.m_iPart = CFWL_Part::DateInCircle;
- params.m_pGraphics = pGraphics;
- params.m_rtPart = pDate->rect;
- params.m_dwStates = CFWL_PartState_Normal;
- if (pMatrix)
- params.m_matrix.Concat(*pMatrix);
- pTheme->DrawBackground(params);
+ CFWL_ThemeBackground params(CFWL_ThemePart::Part::kDateInCircle, this,
+ pGraphics);
+ params.m_PartRect = pDate->rect;
+ params.m_matrix = mtMatrix;
+ GetThemeProvider()->DrawBackground(params);
}
CFX_SizeF CFWL_MonthCalendar::CalcSize() {
- IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get();
- if (!pTheme)
- return CFX_SizeF();
-
float fMaxWeekW = 0.0f;
float fMaxWeekH = 0.0f;
for (int i = 0; i < 7; ++i) {
- CFX_SizeF sz = CalcTextSize(GetAbbreviatedDayOfWeek(i), pTheme, false);
+ CFX_SizeF sz = CalcTextSize(GetAbbreviatedDayOfWeek(i), false);
fMaxWeekW = (fMaxWeekW >= sz.width) ? fMaxWeekW : sz.width;
fMaxWeekH = (fMaxWeekH >= sz.height) ? fMaxWeekH : sz.height;
}
-
float fDayMaxW = 0.0f;
float fDayMaxH = 0.0f;
for (int day = 10; day <= 31; day++) {
- CFX_SizeF sz = CalcTextSize(WideString::Format(L"%d", day), pTheme, false);
+ CFX_SizeF sz = CalcTextSize(WideString::FormatInteger(day), false);
fDayMaxW = (fDayMaxW >= sz.width) ? fDayMaxW : sz.width;
fDayMaxH = (fDayMaxH >= sz.height) ? fDayMaxH : sz.height;
}
- m_szCell.width =
+ m_CellSize.width =
static_cast<int>(0.5 + (fMaxWeekW >= fDayMaxW ? fMaxWeekW : fDayMaxW));
- m_szCell.height = fMaxWeekH >= fDayMaxH ? fMaxWeekH : fDayMaxH;
+ m_CellSize.height = fMaxWeekH >= fDayMaxH ? fMaxWeekH : fDayMaxH;
CFX_SizeF fs;
- fs.width = m_szCell.width * MONTHCAL_COLUMNS +
- MONTHCAL_HMARGIN * MONTHCAL_COLUMNS * 2 +
- MONTHCAL_HEADER_BTN_HMARGIN * 2;
+ fs.width = m_CellSize.width * kMonthCalColumns +
+ kMonthCalHMargin * kMonthCalColumns * 2 +
+ kMonthCalHeaderBtnHMargin * 2;
float fMonthMaxW = 0.0f;
float fMonthMaxH = 0.0f;
for (int i = 0; i < 12; ++i) {
- CFX_SizeF sz = CalcTextSize(GetMonth(i), pTheme, false);
+ CFX_SizeF sz = CalcTextSize(GetMonth(i), false);
fMonthMaxW = (fMonthMaxW >= sz.width) ? fMonthMaxW : sz.width;
fMonthMaxH = (fMonthMaxH >= sz.height) ? fMonthMaxH : sz.height;
}
- CFX_SizeF szYear =
- CalcTextSize(GetHeadText(m_iYear, m_iMonth), pTheme, false);
+ CFX_SizeF szYear = CalcTextSize(GetHeadText(m_iYear, m_iMonth), false);
fMonthMaxH = std::max(fMonthMaxH, szYear.height);
- m_szHead = CFX_SizeF(fMonthMaxW + szYear.width, fMonthMaxH);
+ m_HeadSize = CFX_SizeF(fMonthMaxW + szYear.width, fMonthMaxH);
fMonthMaxW =
- m_szHead.width + MONTHCAL_HEADER_BTN_HMARGIN * 2 + m_szCell.width * 2;
+ m_HeadSize.width + kMonthCalHeaderBtnHMargin * 2 + m_CellSize.width * 2;
fs.width = std::max(fs.width, fMonthMaxW);
m_wsToday = GetTodayText(m_iYear, m_iMonth, m_iDay);
- m_szToday = CalcTextSize(m_wsToday, pTheme, false);
- m_szToday.height = (m_szToday.height >= m_szCell.height) ? m_szToday.height
- : m_szCell.height;
- fs.height = m_szCell.width + m_szCell.height * (MONTHCAL_ROWS - 2) +
- m_szToday.height + MONTHCAL_VMARGIN * MONTHCAL_ROWS * 2 +
- MONTHCAL_HEADER_BTN_VMARGIN * 4;
+ m_TodaySize = CalcTextSize(m_wsToday, false);
+ m_TodaySize.height = (m_TodaySize.height >= m_CellSize.height)
+ ? m_TodaySize.height
+ : m_CellSize.height;
+ fs.height = m_CellSize.width + m_CellSize.height * (kMonthCalRows - 2) +
+ m_TodaySize.height + kMonthCalVMargin * kMonthCalRows * 2 +
+ kMonthCalHeaderBtnVMargin * 4;
return fs;
}
void CFWL_MonthCalendar::CalcHeadSize() {
- float fHeadHMargin = (m_rtClient.width - m_szHead.width) / 2;
- float fHeadVMargin = (m_szCell.width - m_szHead.height) / 2;
- m_rtHeadText = CFX_RectF(m_rtClient.left + fHeadHMargin,
- m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN +
- MONTHCAL_VMARGIN + fHeadVMargin,
- m_szHead);
+ float fHeadHMargin = (m_ClientRect.width - m_HeadSize.width) / 2;
+ float fHeadVMargin = (m_CellSize.width - m_HeadSize.height) / 2;
+ m_HeadTextRect = CFX_RectF(m_ClientRect.left + fHeadHMargin,
+ m_ClientRect.top + kMonthCalHeaderBtnVMargin +
+ kMonthCalVMargin + fHeadVMargin,
+ m_HeadSize);
}
void CFWL_MonthCalendar::CalcTodaySize() {
- m_rtTodayFlag = CFX_RectF(
- m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN,
- m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN,
- m_szCell.width, m_szToday.height);
- m_rtToday = CFX_RectF(
- m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + m_szCell.width +
- MONTHCAL_HMARGIN * 2,
- m_rtDates.bottom() + MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN,
- m_szToday);
+ m_TodayFlagRect = CFX_RectF(
+ m_ClientRect.left + kMonthCalHeaderBtnHMargin + kMonthCalHMargin,
+ m_DatesRect.bottom() + kMonthCalHeaderBtnVMargin + kMonthCalVMargin,
+ m_CellSize.width, m_TodaySize.height);
+ m_TodayRect = CFX_RectF(
+ m_ClientRect.left + kMonthCalHeaderBtnHMargin + m_CellSize.width +
+ kMonthCalHMargin * 2,
+ m_DatesRect.bottom() + kMonthCalHeaderBtnVMargin + kMonthCalVMargin,
+ m_TodaySize);
}
void CFWL_MonthCalendar::Layout() {
- m_rtClient = GetClientRect();
-
- m_rtHead = CFX_RectF(
- m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN, m_rtClient.top,
- m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2,
- m_szCell.width + (MONTHCAL_HEADER_BTN_VMARGIN + MONTHCAL_VMARGIN) * 2);
- m_rtWeek = CFX_RectF(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN,
- m_rtHead.bottom(),
- m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2,
- m_szCell.height + MONTHCAL_VMARGIN * 2);
- m_rtLBtn = CFX_RectF(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN,
- m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN,
- m_szCell.width, m_szCell.width);
- m_rtRBtn = CFX_RectF(m_rtClient.left + m_rtClient.width -
- MONTHCAL_HEADER_BTN_HMARGIN - m_szCell.width,
- m_rtClient.top + MONTHCAL_HEADER_BTN_VMARGIN,
- m_szCell.width, m_szCell.width);
- m_rtHSep = CFX_RectF(
- m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN,
- m_rtWeek.bottom() - MONTHCAL_VMARGIN,
- m_rtClient.width - (MONTHCAL_HEADER_BTN_HMARGIN + MONTHCAL_HMARGIN) * 2,
- MONTHCAL_HSEP_HEIGHT);
- m_rtDates = CFX_RectF(m_rtClient.left + MONTHCAL_HEADER_BTN_HMARGIN,
- m_rtWeek.bottom(),
- m_rtClient.width - MONTHCAL_HEADER_BTN_HMARGIN * 2,
- m_szCell.height * (MONTHCAL_ROWS - 3) +
- MONTHCAL_VMARGIN * (MONTHCAL_ROWS - 3) * 2);
+ m_ClientRect = GetClientRect();
+
+ m_HeadRect = CFX_RectF(
+ m_ClientRect.left + kMonthCalHeaderBtnHMargin, m_ClientRect.top,
+ m_ClientRect.width - kMonthCalHeaderBtnHMargin * 2,
+ m_CellSize.width + (kMonthCalHeaderBtnVMargin + kMonthCalVMargin) * 2);
+ m_WeekRect = CFX_RectF(m_ClientRect.left + kMonthCalHeaderBtnHMargin,
+ m_HeadRect.bottom(),
+ m_ClientRect.width - kMonthCalHeaderBtnHMargin * 2,
+ m_CellSize.height + kMonthCalVMargin * 2);
+ m_LBtnRect = CFX_RectF(m_ClientRect.left + kMonthCalHeaderBtnHMargin,
+ m_ClientRect.top + kMonthCalHeaderBtnVMargin,
+ m_CellSize.width, m_CellSize.width);
+ m_RBtnRect = CFX_RectF(m_ClientRect.left + m_ClientRect.width -
+ kMonthCalHeaderBtnHMargin - m_CellSize.width,
+ m_ClientRect.top + kMonthCalHeaderBtnVMargin,
+ m_CellSize.width, m_CellSize.width);
+ m_HSepRect = CFX_RectF(
+ m_ClientRect.left + kMonthCalHeaderBtnHMargin + kMonthCalHMargin,
+ m_WeekRect.bottom() - kMonthCalVMargin,
+ m_ClientRect.width - (kMonthCalHeaderBtnHMargin + kMonthCalHMargin) * 2,
+ kMonthCalHSepHeight);
+ m_DatesRect = CFX_RectF(m_ClientRect.left + kMonthCalHeaderBtnHMargin,
+ m_WeekRect.bottom(),
+ m_ClientRect.width - kMonthCalHeaderBtnHMargin * 2,
+ m_CellSize.height * (kMonthCalRows - 3) +
+ kMonthCalVMargin * (kMonthCalRows - 3) * 2);
CalDateItem();
}
@@ -498,29 +419,24 @@ void CFWL_MonthCalendar::Layout() {
void CFWL_MonthCalendar::CalDateItem() {
bool bNewWeek = false;
int32_t iWeekOfMonth = 0;
- float fLeft = m_rtDates.left;
- float fTop = m_rtDates.top;
- for (const auto& pDateInfo : m_arrDates) {
+ float fLeft = m_DatesRect.left;
+ float fTop = m_DatesRect.top;
+ for (const auto& pDateInfo : m_DateArray) {
if (bNewWeek) {
iWeekOfMonth++;
bNewWeek = false;
}
pDateInfo->rect = CFX_RectF(
fLeft +
- pDateInfo->iDayOfWeek * (m_szCell.width + (MONTHCAL_HMARGIN * 2)),
- fTop + iWeekOfMonth * (m_szCell.height + (MONTHCAL_VMARGIN * 2)),
- m_szCell.width + (MONTHCAL_HMARGIN * 2),
- m_szCell.height + (MONTHCAL_VMARGIN * 2));
+ pDateInfo->iDayOfWeek * (m_CellSize.width + (kMonthCalHMargin * 2)),
+ fTop + iWeekOfMonth * (m_CellSize.height + (kMonthCalVMargin * 2)),
+ m_CellSize.width + (kMonthCalHMargin * 2),
+ m_CellSize.height + (kMonthCalVMargin * 2));
if (pDateInfo->iDayOfWeek >= 6)
bNewWeek = true;
}
}
-void CFWL_MonthCalendar::GetCapValue() {
- if (!m_pProperties->m_pThemeProvider)
- m_pProperties->m_pThemeProvider = GetAvailableTheme();
-}
-
void CFWL_MonthCalendar::InitDate() {
CFX_DateTime now = CFX_DateTime::Now();
@@ -537,27 +453,23 @@ void CFWL_MonthCalendar::InitDate() {
}
void CFWL_MonthCalendar::ClearDateItem() {
- m_arrDates.clear();
+ m_DateArray.clear();
}
void CFWL_MonthCalendar::ResetDateItem() {
int32_t iDays = FX_DaysInMonth(m_iCurYear, m_iCurMonth);
int32_t iDayOfWeek =
CFX_DateTime(m_iCurYear, m_iCurMonth, 1, 0, 0, 0, 0).GetDayOfWeek();
- for (int32_t i = 0; i < iDays; i++) {
+ for (int32_t i = 0; i < iDays; ++i, ++iDayOfWeek) {
if (iDayOfWeek >= 7)
iDayOfWeek = 0;
- uint32_t dwStates = 0;
- if (m_iYear == m_iCurYear && m_iMonth == m_iCurMonth && m_iDay == (i + 1))
- dwStates |= FWL_ITEMSTATE_MCD_Flag;
- if (pdfium::ContainsValue(m_arrSelDays, i + 1))
- dwStates |= FWL_ITEMSTATE_MCD_Selected;
-
- CFX_RectF rtDate;
- m_arrDates.push_back(pdfium::MakeUnique<DATEINFO>(
- i + 1, iDayOfWeek, dwStates, rtDate, WideString::Format(L"%d", i + 1)));
- iDayOfWeek++;
+ const bool bFlagged =
+ m_iYear == m_iCurYear && m_iMonth == m_iCurMonth && m_iDay == i + 1;
+ const bool bSelected = pdfium::Contains(m_SelDayArray, i + 1);
+ m_DateArray.push_back(
+ std::make_unique<DATEINFO>(i + 1, iDayOfWeek, bFlagged, bSelected,
+ WideString::FormatInteger(i + 1)));
}
}
@@ -608,24 +520,24 @@ void CFWL_MonthCalendar::ChangeToMonth(int32_t iYear, int32_t iMonth) {
}
void CFWL_MonthCalendar::RemoveSelDay() {
- int32_t iDatesCount = pdfium::CollectionSize<int32_t>(m_arrDates);
- for (int32_t iSelDay : m_arrSelDays) {
+ int32_t iDatesCount = fxcrt::CollectionSize<int32_t>(m_DateArray);
+ for (int32_t iSelDay : m_SelDayArray) {
if (iSelDay <= iDatesCount)
- m_arrDates[iSelDay - 1]->dwStates &= ~FWL_ITEMSTATE_MCD_Selected;
+ m_DateArray[iSelDay - 1]->bSelected = false;
}
- m_arrSelDays.clear();
+ m_SelDayArray.clear();
}
void CFWL_MonthCalendar::AddSelDay(int32_t iDay) {
- ASSERT(iDay > 0);
- if (!pdfium::ContainsValue(m_arrSelDays, iDay))
+ DCHECK(iDay > 0);
+ if (!pdfium::Contains(m_SelDayArray, iDay))
return;
RemoveSelDay();
- if (iDay <= pdfium::CollectionSize<int32_t>(m_arrDates))
- m_arrDates[iDay - 1]->dwStates |= FWL_ITEMSTATE_MCD_Selected;
+ if (iDay <= fxcrt::CollectionSize<int32_t>(m_DateArray))
+ m_DateArray[iDay - 1]->bSelected = true;
- m_arrSelDays.push_back(iDay);
+ m_SelDayArray.push_back(iDay);
}
void CFWL_MonthCalendar::JumpToToday() {
@@ -637,13 +549,13 @@ void CFWL_MonthCalendar::JumpToToday() {
return;
}
- if (!pdfium::ContainsValue(m_arrSelDays, m_iDay))
+ if (!pdfium::Contains(m_SelDayArray, m_iDay))
AddSelDay(m_iDay);
}
WideString CFWL_MonthCalendar::GetHeadText(int32_t iYear, int32_t iMonth) {
- ASSERT(iMonth > 0);
- ASSERT(iMonth < 13);
+ DCHECK(iMonth > 0);
+ DCHECK(iMonth < 13);
static const wchar_t* const pMonth[] = {L"January", L"February", L"March",
L"April", L"May", L"June",
@@ -660,7 +572,7 @@ WideString CFWL_MonthCalendar::GetTodayText(int32_t iYear,
int32_t CFWL_MonthCalendar::GetDayAtPoint(const CFX_PointF& point) const {
int i = 1; // one-based day values.
- for (const auto& pDateInfo : m_arrDates) {
+ for (const auto& pDateInfo : m_DateArray) {
if (pDateInfo->rect.Contains(point))
return i;
++i;
@@ -669,37 +581,34 @@ int32_t CFWL_MonthCalendar::GetDayAtPoint(const CFX_PointF& point) const {
}
CFX_RectF CFWL_MonthCalendar::GetDayRect(int32_t iDay) {
- if (iDay <= 0 || iDay > pdfium::CollectionSize<int32_t>(m_arrDates))
+ if (iDay <= 0 || iDay > fxcrt::CollectionSize<int32_t>(m_DateArray))
return CFX_RectF();
- DATEINFO* pDateInfo = m_arrDates[iDay - 1].get();
+ DATEINFO* pDateInfo = m_DateArray[iDay - 1].get();
return pDateInfo ? pDateInfo->rect : CFX_RectF();
}
void CFWL_MonthCalendar::OnProcessMessage(CFWL_Message* pMessage) {
- if (!pMessage)
- return;
-
switch (pMessage->GetType()) {
- case CFWL_Message::Type::SetFocus:
- case CFWL_Message::Type::KillFocus:
+ case CFWL_Message::Type::kSetFocus:
+ case CFWL_Message::Type::kKillFocus:
GetOuter()->GetDelegate()->OnProcessMessage(pMessage);
break;
- case CFWL_Message::Type::Key:
+ case CFWL_Message::Type::kKey:
break;
- case CFWL_Message::Type::Mouse: {
+ case CFWL_Message::Type::kMouse: {
CFWL_MessageMouse* pMouse = static_cast<CFWL_MessageMouse*>(pMessage);
switch (pMouse->m_dwCmd) {
- case FWL_MouseCommand::LeftButtonDown:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonDown:
OnLButtonDown(pMouse);
break;
- case FWL_MouseCommand::LeftButtonUp:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonUp:
OnLButtonUp(pMouse);
break;
- case FWL_MouseCommand::Move:
+ case CFWL_MessageMouse::MouseCommand::kMove:
OnMouseMove(pMouse);
break;
- case FWL_MouseCommand::Leave:
+ case CFWL_MessageMouse::MouseCommand::kLeave:
OnMouseLeave(pMouse);
break;
default:
@@ -715,64 +624,64 @@ void CFWL_MonthCalendar::OnProcessMessage(CFWL_Message* pMessage) {
CFWL_Widget::OnProcessMessage(pMessage);
}
-void CFWL_MonthCalendar::OnDrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_MonthCalendar::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
DrawWidget(pGraphics, matrix);
}
void CFWL_MonthCalendar::OnLButtonDown(CFWL_MessageMouse* pMsg) {
- if (m_rtLBtn.Contains(pMsg->m_pos)) {
- m_iLBtnPartStates = CFWL_PartState_Pressed;
+ if (m_LBtnRect.Contains(pMsg->m_pos)) {
+ m_iLBtnPartStates = CFWL_PartState::kPressed;
PrevMonth();
- RepaintRect(m_rtClient);
- } else if (m_rtRBtn.Contains(pMsg->m_pos)) {
- m_iRBtnPartStates |= CFWL_PartState_Pressed;
+ RepaintRect(m_ClientRect);
+ } else if (m_RBtnRect.Contains(pMsg->m_pos)) {
+ m_iRBtnPartStates |= CFWL_PartState::kPressed;
NextMonth();
- RepaintRect(m_rtClient);
- } else if (m_rtToday.Contains(pMsg->m_pos)) {
+ RepaintRect(m_ClientRect);
+ } else if (m_TodayRect.Contains(pMsg->m_pos)) {
JumpToToday();
- RepaintRect(m_rtClient);
+ RepaintRect(m_ClientRect);
}
}
void CFWL_MonthCalendar::OnLButtonUp(CFWL_MessageMouse* pMsg) {
- if (m_rtLBtn.Contains(pMsg->m_pos)) {
- m_iLBtnPartStates = 0;
- RepaintRect(m_rtLBtn);
+ if (m_LBtnRect.Contains(pMsg->m_pos)) {
+ m_iLBtnPartStates = CFWL_PartState::kNormal;
+ RepaintRect(m_LBtnRect);
return;
}
- if (m_rtRBtn.Contains(pMsg->m_pos)) {
- m_iRBtnPartStates = 0;
- RepaintRect(m_rtRBtn);
+ if (m_RBtnRect.Contains(pMsg->m_pos)) {
+ m_iRBtnPartStates = CFWL_PartState::kNormal;
+ RepaintRect(m_RBtnRect);
return;
}
- if (m_rtToday.Contains(pMsg->m_pos))
+ if (m_TodayRect.Contains(pMsg->m_pos))
return;
int32_t iOldSel = 0;
- if (!m_arrSelDays.empty())
- iOldSel = m_arrSelDays[0];
+ if (!m_SelDayArray.empty())
+ iOldSel = m_SelDayArray[0];
int32_t iCurSel = GetDayAtPoint(pMsg->m_pos);
if (iCurSel > 0) {
- DATEINFO* lpDatesInfo = m_arrDates[iCurSel - 1].get();
- CFX_RectF rtInvalidate(lpDatesInfo->rect);
- if (iOldSel > 0 && iOldSel <= pdfium::CollectionSize<int32_t>(m_arrDates)) {
- lpDatesInfo = m_arrDates[iOldSel - 1].get();
- rtInvalidate.Union(lpDatesInfo->rect);
+ DATEINFO* pDateInfo = m_DateArray[iCurSel - 1].get();
+ CFX_RectF rtInvalidate(pDateInfo->rect);
+ if (iOldSel > 0 && iOldSel <= fxcrt::CollectionSize<int32_t>(m_DateArray)) {
+ pDateInfo = m_DateArray[iOldSel - 1].get();
+ rtInvalidate.Union(pDateInfo->rect);
}
AddSelDay(iCurSel);
CFWL_DateTimePicker* pDateTime =
- static_cast<CFWL_DateTimePicker*>(m_pOuter);
+ static_cast<CFWL_DateTimePicker*>(GetOuter());
pDateTime->ProcessSelChanged(m_iCurYear, m_iCurMonth, iCurSel);
- pDateTime->ShowMonthCalendar(false);
+ pDateTime->HideMonthCalendar();
}
}
void CFWL_MonthCalendar::OnMouseMove(CFWL_MessageMouse* pMsg) {
bool bRepaint = false;
CFX_RectF rtInvalidate;
- if (m_rtDates.Contains(pMsg->m_pos)) {
+ if (m_DatesRect.Contains(pMsg->m_pos)) {
int32_t iHover = GetDayAtPoint(pMsg->m_pos);
bRepaint = m_iHovered != iHover;
if (bRepaint) {
@@ -810,13 +719,22 @@ void CFWL_MonthCalendar::OnMouseLeave(CFWL_MessageMouse* pMsg) {
CFWL_MonthCalendar::DATEINFO::DATEINFO(int32_t day,
int32_t dayofweek,
- uint32_t dwSt,
- CFX_RectF rc,
+ bool bFlag,
+ bool bSelect,
const WideString& wsday)
: iDay(day),
iDayOfWeek(dayofweek),
- dwStates(dwSt),
- rect(rc),
+ bFlagged(bFlag),
+ bSelected(bSelect),
wsDay(wsday) {}
-CFWL_MonthCalendar::DATEINFO::~DATEINFO() {}
+CFWL_MonthCalendar::DATEINFO::~DATEINFO() = default;
+
+Mask<CFWL_PartState> CFWL_MonthCalendar::DATEINFO::AsPartStateMask() const {
+ Mask<CFWL_PartState> dwStates = CFWL_PartState::kNormal;
+ if (bFlagged)
+ dwStates |= CFWL_PartState::kFlagged;
+ if (bSelected)
+ dwStates |= CFWL_PartState::kSelected;
+ return dwStates;
+}
diff --git a/xfa/fwl/cfwl_monthcalendar.h b/xfa/fwl/cfwl_monthcalendar.h
index a00ea0ff1..c7c718339 100644
--- a/xfa/fwl/cfwl_monthcalendar.h
+++ b/xfa/fwl/cfwl_monthcalendar.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,30 +10,25 @@
#include <memory>
#include <vector>
-#include "core/fxcrt/cfx_datetime.h"
+#include "core/fxcrt/widestring.h"
#include "xfa/fwl/cfwl_event.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fwl/cfwl_widgetproperties.h"
-
-#define FWL_ITEMSTATE_MCD_Flag (1L << 0)
-#define FWL_ITEMSTATE_MCD_Selected (1L << 1)
class CFWL_MessageMouse;
class CFWL_MonthCalendar final : public CFWL_Widget {
public:
- CFWL_MonthCalendar(const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_MonthCalendar() override;
- // FWL_WidgetImp
+ // CFWL_Widget:
FWL_Type GetClassID() const override;
CFX_RectF GetAutosizedWidgetRect() override;
void Update() override;
- void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
+ void DrawWidget(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& matrix) override;
void OnProcessMessage(CFWL_Message* pMessage) override;
- void OnDrawWidget(CXFA_Graphics* pGraphics,
+ void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) override;
void SetSelect(int32_t iYear, int32_t iMonth, int32_t iDay);
@@ -73,63 +68,47 @@ class CFWL_MonthCalendar final : public CFWL_Widget {
int32_t iMonth;
int32_t iDay;
};
+
struct DATEINFO {
DATEINFO(int32_t day,
int32_t dayofweek,
- uint32_t dwSt,
- CFX_RectF rc,
+ bool bFlag,
+ bool bSelect,
const WideString& wsday);
~DATEINFO();
- int32_t iDay;
- int32_t iDayOfWeek;
- uint32_t dwStates;
+ Mask<CFWL_PartState> AsPartStateMask() const;
+
+ const int32_t iDay;
+ const int32_t iDayOfWeek;
+ bool bFlagged;
+ bool bSelected;
CFX_RectF rect;
- WideString wsDay;
+ const WideString wsDay;
};
- void DrawBackground(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawHeadBK(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawLButton(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawRButton(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawCaption(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawSeparator(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawDatesInBK(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawWeek(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawToday(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawDatesIn(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawDatesOut(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- void DrawDatesInCircle(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
+ CFWL_MonthCalendar(CFWL_App* app,
+ const Properties& properties,
+ CFWL_Widget* pOuter);
+
+ void DrawBackground(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawHeadBK(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawLButton(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawRButton(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawCaption(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawSeparator(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawDatesInBK(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawWeek(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawToday(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawDatesIn(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawDatesOut(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawDatesInCircle(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix);
CFX_SizeF CalcSize();
void Layout();
void CalcHeadSize();
void CalcTodaySize();
void CalDateItem();
- void GetCapValue();
void InitDate();
void ClearDateItem();
void ResetDateItem();
@@ -149,33 +128,33 @@ class CFWL_MonthCalendar final : public CFWL_Widget {
void OnMouseLeave(CFWL_MessageMouse* pMsg);
bool m_bInitialized = false;
- CFX_RectF m_rtHead;
- CFX_RectF m_rtWeek;
- CFX_RectF m_rtLBtn;
- CFX_RectF m_rtRBtn;
- CFX_RectF m_rtDates;
- CFX_RectF m_rtHSep;
- CFX_RectF m_rtHeadText;
- CFX_RectF m_rtToday;
- CFX_RectF m_rtTodayFlag;
+ CFX_RectF m_HeadRect;
+ CFX_RectF m_WeekRect;
+ CFX_RectF m_LBtnRect;
+ CFX_RectF m_RBtnRect;
+ CFX_RectF m_DatesRect;
+ CFX_RectF m_HSepRect;
+ CFX_RectF m_HeadTextRect;
+ CFX_RectF m_TodayRect;
+ CFX_RectF m_TodayFlagRect;
WideString m_wsHead;
WideString m_wsToday;
- std::vector<std::unique_ptr<DATEINFO>> m_arrDates;
+ std::vector<std::unique_ptr<DATEINFO>> m_DateArray;
int32_t m_iCurYear = 2011;
int32_t m_iCurMonth = 1;
int32_t m_iYear = 2011;
int32_t m_iMonth = 1;
int32_t m_iDay = 1;
int32_t m_iHovered = -1;
- int32_t m_iLBtnPartStates = CFWL_PartState_Normal;
- int32_t m_iRBtnPartStates = CFWL_PartState_Normal;
+ Mask<CFWL_PartState> m_iLBtnPartStates = CFWL_PartState::kNormal;
+ Mask<CFWL_PartState> m_iRBtnPartStates = CFWL_PartState::kNormal;
DATE m_dtMin;
DATE m_dtMax;
- CFX_SizeF m_szHead;
- CFX_SizeF m_szCell;
- CFX_SizeF m_szToday;
- std::vector<int32_t> m_arrSelDays;
- CFX_RectF m_rtClient;
+ CFX_SizeF m_HeadSize;
+ CFX_SizeF m_CellSize;
+ CFX_SizeF m_TodaySize;
+ std::vector<int32_t> m_SelDayArray;
+ CFX_RectF m_ClientRect;
};
#endif // XFA_FWL_CFWL_MONTHCALENDAR_H_
diff --git a/xfa/fwl/cfwl_notedriver.cpp b/xfa/fwl/cfwl_notedriver.cpp
index 821dd5c25..e6bcfe8ba 100644
--- a/xfa/fwl/cfwl_notedriver.cpp
+++ b/xfa/fwl/cfwl_notedriver.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,10 +11,9 @@
#include "build/build_config.h"
#include "core/fxcrt/fx_extension.h"
-#include "third_party/base/ptr_util.h"
-#include "third_party/base/stl_util.h"
+#include "fxjs/gc/container_trace.h"
#include "xfa/fwl/cfwl_app.h"
-#include "xfa/fwl/cfwl_eventtarget.h"
+#include "xfa/fwl/cfwl_event.h"
#include "xfa/fwl/cfwl_messagekey.h"
#include "xfa/fwl/cfwl_messagekillfocus.h"
#include "xfa/fwl/cfwl_messagemouse.h"
@@ -23,10 +22,24 @@
#include "xfa/fwl/cfwl_widgetmgr.h"
#include "xfa/fwl/fwl_widgetdef.h"
-CFWL_NoteDriver::CFWL_NoteDriver() = default;
+namespace {
+
+uint64_t g_next_listener_key = 1;
+
+} // namespace
+
+CFWL_NoteDriver::CFWL_NoteDriver(CFWL_App* pApp) : m_pApp(pApp) {}
CFWL_NoteDriver::~CFWL_NoteDriver() = default;
+void CFWL_NoteDriver::Trace(cppgc::Visitor* visitor) const {
+ visitor->Trace(m_pApp);
+ ContainerTrace(visitor, m_eventTargets);
+ visitor->Trace(m_pHover);
+ visitor->Trace(m_pFocus);
+ visitor->Trace(m_pGrab);
+}
+
void CFWL_NoteDriver::SendEvent(CFWL_Event* pNote) {
for (const auto& pair : m_eventTargets) {
if (pair.second->IsValid())
@@ -36,48 +49,26 @@ void CFWL_NoteDriver::SendEvent(CFWL_Event* pNote) {
void CFWL_NoteDriver::RegisterEventTarget(CFWL_Widget* pListener,
CFWL_Widget* pEventSource) {
- uint32_t key = pListener->GetEventKey();
+ uint64_t key = pListener->GetEventKey();
if (key == 0) {
- do {
- key = rand();
- } while (key == 0 || pdfium::ContainsKey(m_eventTargets, key));
+ key = g_next_listener_key++;
pListener->SetEventKey(key);
}
- if (!m_eventTargets[key])
- m_eventTargets[key] = pdfium::MakeUnique<CFWL_EventTarget>(pListener);
-
+ if (!m_eventTargets[key]) {
+ m_eventTargets[key] = cppgc::MakeGarbageCollected<Target>(
+ m_pApp->GetHeap()->GetAllocationHandle(), pListener);
+ }
m_eventTargets[key]->SetEventSource(pEventSource);
}
void CFWL_NoteDriver::UnregisterEventTarget(CFWL_Widget* pListener) {
- uint32_t key = pListener->GetEventKey();
+ uint64_t key = pListener->GetEventKey();
if (key == 0)
return;
auto it = m_eventTargets.find(key);
if (it != m_eventTargets.end())
- it->second->FlagInvalid();
-}
-
-bool CFWL_NoteDriver::SetFocus(CFWL_Widget* pFocus) {
- if (m_pFocus == pFocus)
- return true;
-
- CFWL_Widget* pPrev = m_pFocus.Get();
- m_pFocus = pFocus;
- if (pPrev) {
- if (IFWL_WidgetDelegate* pDelegate = pPrev->GetDelegate()) {
- CFWL_MessageKillFocus ms(pPrev, pPrev);
- pDelegate->OnProcessMessage(&ms);
- }
- }
- if (pFocus) {
- if (IFWL_WidgetDelegate* pDelegate = pFocus->GetDelegate()) {
- CFWL_MessageSetFocus ms(nullptr, pFocus);
- pDelegate->OnProcessMessage(&ms);
- }
- }
- return true;
+ it->second->Invalidate();
}
void CFWL_NoteDriver::NotifyTargetHide(CFWL_Widget* pNoteTarget) {
@@ -100,42 +91,42 @@ void CFWL_NoteDriver::NotifyTargetDestroy(CFWL_Widget* pNoteTarget) {
UnregisterEventTarget(pNoteTarget);
}
-void CFWL_NoteDriver::ProcessMessage(std::unique_ptr<CFWL_Message> pMessage) {
+void CFWL_NoteDriver::ProcessMessage(CFWL_Message* pMessage) {
CFWL_Widget* pMessageForm = pMessage->GetDstTarget();
if (!pMessageForm)
return;
- if (!DispatchMessage(pMessage.get(), pMessageForm))
+ if (!DispatchMessage(pMessage, pMessageForm))
return;
- if (pMessage->GetType() == CFWL_Message::Type::Mouse)
- MouseSecondary(pMessage.get());
+ if (pMessage->GetType() == CFWL_Message::Type::kMouse)
+ MouseSecondary(pMessage);
}
bool CFWL_NoteDriver::DispatchMessage(CFWL_Message* pMessage,
CFWL_Widget* pMessageForm) {
switch (pMessage->GetType()) {
- case CFWL_Message::Type::SetFocus: {
+ case CFWL_Message::Type::kSetFocus: {
if (!DoSetFocus(pMessage, pMessageForm))
return false;
break;
}
- case CFWL_Message::Type::KillFocus: {
+ case CFWL_Message::Type::kKillFocus: {
if (!DoKillFocus(pMessage, pMessageForm))
return false;
break;
}
- case CFWL_Message::Type::Key: {
+ case CFWL_Message::Type::kKey: {
if (!DoKey(pMessage, pMessageForm))
return false;
break;
}
- case CFWL_Message::Type::Mouse: {
+ case CFWL_Message::Type::kMouse: {
if (!DoMouse(pMessage, pMessageForm))
return false;
break;
}
- case CFWL_Message::Type::MouseWheel: {
+ case CFWL_Message::Type::kMouseWheel: {
if (!DoWheel(pMessage, pMessageForm))
return false;
break;
@@ -165,25 +156,9 @@ bool CFWL_NoteDriver::DoKillFocus(CFWL_Message* pMessage,
bool CFWL_NoteDriver::DoKey(CFWL_Message* pMessage, CFWL_Widget* pMessageForm) {
CFWL_MessageKey* pMsg = static_cast<CFWL_MessageKey*>(pMessage);
-#if !defined(OS_MACOSX)
- if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown &&
- pMsg->m_dwKeyCode == XFA_FWL_VKEY_Tab) {
- CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr();
- CFWL_Widget* pForm = GetMessageForm(pMsg->GetDstTarget());
- CFWL_Widget* pFocus = m_pFocus.Get();
- if (m_pFocus && pWidgetMgr->GetSystemFormWidget(m_pFocus.Get()) != pForm)
- pFocus = nullptr;
-
- CFWL_Widget* pNextTabStop = nullptr;
- if (pForm) {
- pNextTabStop = CFWL_WidgetMgr::NextTab(pForm, pFocus);
- if (!pNextTabStop)
- pNextTabStop = CFWL_WidgetMgr::NextTab(pForm, nullptr);
- }
- if (pNextTabStop == pFocus)
- return true;
- if (pNextTabStop)
- SetFocus(pNextTabStop);
+#if !BUILDFLAG(IS_APPLE)
+ if (pMsg->m_dwCmd == CFWL_MessageKey::KeyCommand::kKeyDown &&
+ pMsg->m_dwKeyCodeOrChar == XFA_FWL_VKEY_Tab) {
return true;
}
#endif
@@ -193,9 +168,9 @@ bool CFWL_NoteDriver::DoKey(CFWL_Message* pMessage, CFWL_Widget* pMessageForm) {
return true;
}
- if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown &&
- pMsg->m_dwKeyCode == XFA_FWL_VKEY_Return) {
- CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr();
+ if (pMsg->m_dwCmd == CFWL_MessageKey::KeyCommand::kKeyDown &&
+ pMsg->m_dwKeyCodeOrChar == XFA_FWL_VKEY_Return) {
+ CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetFWLApp()->GetWidgetMgr();
CFWL_Widget* pDefButton = pWidgetMgr->GetDefaultButton(pMessageForm);
if (pDefButton) {
pMsg->SetDstTarget(pDefButton);
@@ -208,9 +183,9 @@ bool CFWL_NoteDriver::DoKey(CFWL_Message* pMessage, CFWL_Widget* pMessageForm) {
bool CFWL_NoteDriver::DoMouse(CFWL_Message* pMessage,
CFWL_Widget* pMessageForm) {
CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
- if (pMsg->m_dwCmd == FWL_MouseCommand::Leave ||
- pMsg->m_dwCmd == FWL_MouseCommand::Hover ||
- pMsg->m_dwCmd == FWL_MouseCommand::Enter) {
+ if (pMsg->m_dwCmd == CFWL_MessageMouse::MouseCommand::kLeave ||
+ pMsg->m_dwCmd == CFWL_MessageMouse::MouseCommand::kHover ||
+ pMsg->m_dwCmd == CFWL_MessageMouse::MouseCommand::kEnter) {
return !!pMsg->GetDstTarget();
}
if (pMsg->GetDstTarget() != pMessageForm)
@@ -222,20 +197,20 @@ bool CFWL_NoteDriver::DoMouse(CFWL_Message* pMessage,
bool CFWL_NoteDriver::DoWheel(CFWL_Message* pMessage,
CFWL_Widget* pMessageForm) {
- CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr();
+ CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetFWLApp()->GetWidgetMgr();
CFWL_MessageMouseWheel* pMsg = static_cast<CFWL_MessageMouseWheel*>(pMessage);
- CFWL_Widget* pDst = pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->m_pos);
+ CFWL_Widget* pDst = pWidgetMgr->GetWidgetAtPoint(pMessageForm, pMsg->pos());
if (!pDst)
return false;
- pMsg->m_pos = pMessageForm->TransformTo(pDst, pMsg->m_pos);
+ pMsg->set_pos(pMessageForm->TransformTo(pDst, pMsg->pos()));
pMsg->SetDstTarget(pDst);
return true;
}
bool CFWL_NoteDriver::DoMouseEx(CFWL_Message* pMessage,
CFWL_Widget* pMessageForm) {
- CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetOwnerApp()->GetWidgetMgr();
+ CFWL_WidgetMgr* pWidgetMgr = pMessageForm->GetFWLApp()->GetWidgetMgr();
CFWL_Widget* pTarget = nullptr;
if (m_pGrab)
pTarget = m_pGrab.Get();
@@ -260,7 +235,8 @@ void CFWL_NoteDriver::MouseSecondary(CFWL_Message* pMessage) {
CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
if (m_pHover) {
CFWL_MessageMouse msLeave(
- m_pHover.Get(), FWL_MouseCommand::Leave, 0,
+ m_pHover.Get(), CFWL_MessageMouse::MouseCommand::kLeave,
+ Mask<XFA_FWL_KeyFlag>(),
pTarget->TransformTo(m_pHover.Get(), pMsg->m_pos));
DispatchMessage(&msLeave, nullptr);
}
@@ -270,23 +246,33 @@ void CFWL_NoteDriver::MouseSecondary(CFWL_Message* pMessage) {
}
m_pHover = pTarget;
- CFWL_MessageMouse msHover(pTarget, FWL_MouseCommand::Hover, 0, pMsg->m_pos);
+ CFWL_MessageMouse msHover(pTarget, CFWL_MessageMouse::MouseCommand::kHover,
+ Mask<XFA_FWL_KeyFlag>(), pMsg->m_pos);
DispatchMessage(&msHover, nullptr);
}
-CFWL_Widget* CFWL_NoteDriver::GetMessageForm(CFWL_Widget* pDstTarget) {
- if (!pDstTarget)
- return nullptr;
+CFWL_NoteDriver::Target::Target(CFWL_Widget* pListener)
+ : m_pListener(pListener) {}
+
+CFWL_NoteDriver::Target::~Target() = default;
- CFWL_WidgetMgr* pWidgetMgr = pDstTarget->GetOwnerApp()->GetWidgetMgr();
- return pWidgetMgr->GetSystemFormWidget(pDstTarget);
+void CFWL_NoteDriver::Target::Trace(cppgc::Visitor* visitor) const {
+ visitor->Trace(m_pListener);
+ for (auto& widget : m_widgets)
+ visitor->Trace(widget);
}
-void CFWL_NoteDriver::ClearEventTargets() {
- auto it = m_eventTargets.begin();
- while (it != m_eventTargets.end()) {
- auto old = it++;
- if (!old->second->IsValid())
- m_eventTargets.erase(old);
- }
+void CFWL_NoteDriver::Target::SetEventSource(CFWL_Widget* pSource) {
+ if (pSource)
+ m_widgets.insert(pSource);
+}
+
+bool CFWL_NoteDriver::Target::ProcessEvent(CFWL_Event* pEvent) {
+ IFWL_WidgetDelegate* pDelegate = m_pListener->GetDelegate();
+ if (!pDelegate)
+ return false;
+ if (!m_widgets.empty() && m_widgets.count(pEvent->GetSrcTarget()) == 0)
+ return false;
+ pDelegate->OnProcessEvent(pEvent);
+ return true;
}
diff --git a/xfa/fwl/cfwl_notedriver.h b/xfa/fwl/cfwl_notedriver.h
index 1de761bb9..00fd9618d 100644
--- a/xfa/fwl/cfwl_notedriver.h
+++ b/xfa/fwl/cfwl_notedriver.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,39 +9,52 @@
#include <map>
#include <memory>
-#include <vector>
+#include <set>
-#include "core/fxcrt/unowned_ptr.h"
-#include "xfa/fwl/cfwl_event.h"
+#include "fxjs/gc/heap.h"
+#include "v8/include/cppgc/garbage-collected.h"
+#include "v8/include/cppgc/member.h"
+#include "v8/include/cppgc/visitor.h"
+#include "xfa/fgas/graphics/cfgas_gegraphics.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fxgraphics/cxfa_graphics.h"
-class CFWL_EventTarget;
-class CFWL_TargetImp;
-class CFWL_Widget;
+class CFWL_Event;
-class CFWL_NoteDriver {
+class CFWL_NoteDriver final : public cppgc::GarbageCollected<CFWL_NoteDriver> {
public:
- CFWL_NoteDriver();
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_NoteDriver();
- void SendEvent(CFWL_Event* pNote);
+ void Trace(cppgc::Visitor* visitor) const;
+ void SendEvent(CFWL_Event* pNote);
+ void ProcessMessage(CFWL_Message* pMessage);
void RegisterEventTarget(CFWL_Widget* pListener, CFWL_Widget* pEventSource);
void UnregisterEventTarget(CFWL_Widget* pListener);
- void ClearEventTargets();
-
- CFWL_Widget* GetFocus() const { return m_pFocus.Get(); }
- bool SetFocus(CFWL_Widget* pFocus);
- void SetGrab(CFWL_Widget* pGrab, bool bSet) {
- m_pGrab = bSet ? pGrab : nullptr;
- }
-
void NotifyTargetHide(CFWL_Widget* pNoteTarget);
void NotifyTargetDestroy(CFWL_Widget* pNoteTarget);
- void ProcessMessage(std::unique_ptr<CFWL_Message> pMessage);
+ void SetGrab(CFWL_Widget* pGrab) { m_pGrab = pGrab; }
private:
+ class Target : public cppgc::GarbageCollected<Target> {
+ public:
+ explicit Target(CFWL_Widget* pListener);
+ ~Target();
+
+ void Trace(cppgc::Visitor* visitor) const;
+ void SetEventSource(CFWL_Widget* pSource);
+ bool ProcessEvent(CFWL_Event* pEvent);
+ bool IsValid() const { return m_bValid; }
+ void Invalidate() { m_bValid = false; }
+
+ private:
+ bool m_bValid = true;
+ cppgc::Member<CFWL_Widget> const m_pListener;
+ std::set<cppgc::Member<CFWL_Widget>> m_widgets;
+ };
+
+ explicit CFWL_NoteDriver(CFWL_App* pApp);
+
bool DispatchMessage(CFWL_Message* pMessage, CFWL_Widget* pMessageForm);
bool DoSetFocus(CFWL_Message* pMsg, CFWL_Widget* pMessageForm);
bool DoKillFocus(CFWL_Message* pMsg, CFWL_Widget* pMessageForm);
@@ -50,12 +63,12 @@ class CFWL_NoteDriver {
bool DoWheel(CFWL_Message* pMsg, CFWL_Widget* pMessageForm);
bool DoMouseEx(CFWL_Message* pMsg, CFWL_Widget* pMessageForm);
void MouseSecondary(CFWL_Message* pMsg);
- CFWL_Widget* GetMessageForm(CFWL_Widget* pDstTarget);
- std::map<uint32_t, std::unique_ptr<CFWL_EventTarget>> m_eventTargets;
- UnownedPtr<CFWL_Widget> m_pHover;
- UnownedPtr<CFWL_Widget> m_pFocus;
- UnownedPtr<CFWL_Widget> m_pGrab;
+ cppgc::Member<CFWL_App> m_pApp;
+ std::map<uint64_t, cppgc::Member<Target>> m_eventTargets;
+ cppgc::Member<CFWL_Widget> m_pHover;
+ cppgc::Member<CFWL_Widget> m_pFocus;
+ cppgc::Member<CFWL_Widget> m_pGrab;
};
#endif // XFA_FWL_CFWL_NOTEDRIVER_H_
diff --git a/xfa/fwl/cfwl_picturebox.cpp b/xfa/fwl/cfwl_picturebox.cpp
index 6e9076545..6e864db92 100644
--- a/xfa/fwl/cfwl_picturebox.cpp
+++ b/xfa/fwl/cfwl_picturebox.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,15 +6,10 @@
#include "xfa/fwl/cfwl_picturebox.h"
-#include <memory>
+CFWL_PictureBox::CFWL_PictureBox(CFWL_App* app)
+ : CFWL_Widget(app, CFWL_Widget::Properties(), nullptr) {}
-#include "third_party/base/ptr_util.h"
-
-CFWL_PictureBox::CFWL_PictureBox(const CFWL_App* app)
- : CFWL_Widget(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr) {
-}
-
-CFWL_PictureBox::~CFWL_PictureBox() {}
+CFWL_PictureBox::~CFWL_PictureBox() = default;
FWL_Type CFWL_PictureBox::GetClassID() const {
return FWL_Type::PictureBox;
@@ -23,25 +18,20 @@ FWL_Type CFWL_PictureBox::GetClassID() const {
void CFWL_PictureBox::Update() {
if (IsLocked())
return;
- if (!m_pProperties->m_pThemeProvider)
- m_pProperties->m_pThemeProvider = GetAvailableTheme();
- m_rtClient = GetClientRect();
+ m_ClientRect = GetClientRect();
}
-void CFWL_PictureBox::DrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_PictureBox::DrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
if (!pGraphics)
return;
- if (!m_pProperties->m_pThemeProvider)
- return;
- IFWL_ThemeProvider* pTheme = GetAvailableTheme();
if (HasBorder())
- DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
+ DrawBorder(pGraphics, CFWL_ThemePart::Part::kBorder, matrix);
}
-void CFWL_PictureBox::OnDrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_PictureBox::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
DrawWidget(pGraphics, matrix);
}
diff --git a/xfa/fwl/cfwl_picturebox.h b/xfa/fwl/cfwl_picturebox.h
index 11689d255..944bcb2a6 100644
--- a/xfa/fwl/cfwl_picturebox.h
+++ b/xfa/fwl/cfwl_picturebox.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,26 +8,25 @@
#define XFA_FWL_CFWL_PICTUREBOX_H_
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fwl/cfwl_widgetproperties.h"
-
-class CFX_DIBitmap;
-class CFWL_Widget;
class CFWL_PictureBox final : public CFWL_Widget {
public:
- explicit CFWL_PictureBox(const CFWL_App* pApp);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_PictureBox() override;
// CFWL_Widget
FWL_Type GetClassID() const override;
void Update() override;
- void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
- void OnDrawWidget(CXFA_Graphics* pGraphics,
+ void DrawWidget(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& matrix) override;
+ void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) override;
private:
- CFX_RectF m_rtClient;
- CFX_RectF m_rtImage;
+ explicit CFWL_PictureBox(CFWL_App* pApp);
+
+ CFX_RectF m_ClientRect;
+ CFX_RectF m_ImageRect;
CFX_Matrix m_matrix;
};
diff --git a/xfa/fwl/cfwl_pushbutton.cpp b/xfa/fwl/cfwl_pushbutton.cpp
index 7806399c9..715b420ae 100644
--- a/xfa/fwl/cfwl_pushbutton.cpp
+++ b/xfa/fwl/cfwl_pushbutton.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,10 +6,6 @@
#include "xfa/fwl/cfwl_pushbutton.h"
-#include <memory>
-#include <utility>
-
-#include "third_party/base/ptr_util.h"
#include "xfa/fde/cfde_textout.h"
#include "xfa/fwl/cfwl_event.h"
#include "xfa/fwl/cfwl_eventmouse.h"
@@ -21,18 +17,18 @@
#include "xfa/fwl/fwl_widgetdef.h"
#include "xfa/fwl/ifwl_themeprovider.h"
-CFWL_PushButton::CFWL_PushButton(const CFWL_App* app)
- : CFWL_Widget(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr) {}
+CFWL_PushButton::CFWL_PushButton(CFWL_App* app)
+ : CFWL_Widget(app, Properties(), nullptr) {}
-CFWL_PushButton::~CFWL_PushButton() {}
+CFWL_PushButton::~CFWL_PushButton() = default;
FWL_Type CFWL_PushButton::GetClassID() const {
return FWL_Type::PushButton;
}
void CFWL_PushButton::SetStates(uint32_t dwStates) {
- if (dwStates & FWL_WGTSTATE_Disabled) {
- m_pProperties->m_dwStates = FWL_WGTSTATE_Disabled;
+ if (dwStates & FWL_STATE_WGT_Disabled) {
+ m_Properties.m_dwStates = FWL_STATE_WGT_Disabled;
return;
}
CFWL_Widget::SetStates(dwStates);
@@ -41,82 +37,71 @@ void CFWL_PushButton::SetStates(uint32_t dwStates) {
void CFWL_PushButton::Update() {
if (IsLocked())
return;
- if (!m_pProperties->m_pThemeProvider)
- m_pProperties->m_pThemeProvider = GetAvailableTheme();
- m_rtClient = GetClientRect();
- m_rtCaption = m_rtClient;
+ m_ClientRect = GetClientRect();
+ m_CaptionRect = m_ClientRect;
}
-void CFWL_PushButton::DrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_PushButton::DrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
if (!pGraphics)
return;
- IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get();
- if (!pTheme)
- return;
-
if (HasBorder())
- DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
- DrawBkground(pGraphics, pTheme, &matrix);
+ DrawBorder(pGraphics, CFWL_ThemePart::Part::kBorder, matrix);
+
+ DrawBkground(pGraphics, matrix);
}
-void CFWL_PushButton::DrawBkground(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeBackground param;
- param.m_pWidget = this;
- param.m_iPart = CFWL_Part::Background;
+void CFWL_PushButton::DrawBkground(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& matrix) {
+ CFWL_ThemeBackground param(CFWL_ThemePart::Part::kBackground, this,
+ pGraphics);
param.m_dwStates = GetPartStates();
- param.m_pGraphics = pGraphics;
- if (pMatrix)
- param.m_matrix.Concat(*pMatrix);
- param.m_rtPart = m_rtClient;
- if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)
- param.m_pRtData = &m_rtCaption;
- pTheme->DrawBackground(param);
+ param.m_matrix = matrix;
+ param.m_PartRect = m_ClientRect;
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Focused)
+ param.m_pRtData = &m_CaptionRect;
+ GetThemeProvider()->DrawBackground(param);
}
-uint32_t CFWL_PushButton::GetPartStates() {
- uint32_t dwStates = CFWL_PartState_Normal;
- if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused)
- dwStates |= CFWL_PartState_Focused;
- if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
- dwStates = CFWL_PartState_Disabled;
- else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed)
- dwStates |= CFWL_PartState_Pressed;
- else if (m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered)
- dwStates |= CFWL_PartState_Hovered;
+Mask<CFWL_PartState> CFWL_PushButton::GetPartStates() {
+ Mask<CFWL_PartState> dwStates = CFWL_PartState::kNormal;
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Focused)
+ dwStates |= CFWL_PartState::kFocused;
+ if (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)
+ dwStates = CFWL_PartState::kDisabled;
+ else if (m_Properties.m_dwStates & FWL_STATE_PSB_Pressed)
+ dwStates |= CFWL_PartState::kPressed;
+ else if (m_Properties.m_dwStates & FWL_STATE_PSB_Hovered)
+ dwStates |= CFWL_PartState::kHovered;
return dwStates;
}
void CFWL_PushButton::OnProcessMessage(CFWL_Message* pMessage) {
- if (!pMessage)
- return;
if (!IsEnabled())
return;
switch (pMessage->GetType()) {
- case CFWL_Message::Type::SetFocus:
- OnFocusChanged(pMessage, true);
+ case CFWL_Message::Type::kSetFocus:
+ OnFocusGained();
break;
- case CFWL_Message::Type::KillFocus:
- OnFocusChanged(pMessage, false);
+ case CFWL_Message::Type::kKillFocus:
+ OnFocusLost();
break;
- case CFWL_Message::Type::Mouse: {
+ case CFWL_Message::Type::kMouse: {
CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
switch (pMsg->m_dwCmd) {
- case FWL_MouseCommand::LeftButtonDown:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonDown:
OnLButtonDown(pMsg);
break;
- case FWL_MouseCommand::LeftButtonUp:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonUp:
OnLButtonUp(pMsg);
break;
- case FWL_MouseCommand::Move:
+ case CFWL_MessageMouse::MouseCommand::kMove:
OnMouseMove(pMsg);
break;
- case FWL_MouseCommand::Leave:
+ case CFWL_MessageMouse::MouseCommand::kLeave:
OnMouseLeave(pMsg);
break;
default:
@@ -124,9 +109,9 @@ void CFWL_PushButton::OnProcessMessage(CFWL_Message* pMessage) {
}
break;
}
- case CFWL_Message::Type::Key: {
+ case CFWL_Message::Type::kKey: {
CFWL_MessageKey* pKey = static_cast<CFWL_MessageKey*>(pMessage);
- if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown)
+ if (pKey->m_dwCmd == CFWL_MessageKey::KeyCommand::kKeyDown)
OnKeyDown(pKey);
break;
}
@@ -138,90 +123,91 @@ void CFWL_PushButton::OnProcessMessage(CFWL_Message* pMessage) {
CFWL_Widget::OnProcessMessage(pMessage);
}
-void CFWL_PushButton::OnDrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_PushButton::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
DrawWidget(pGraphics, matrix);
}
-void CFWL_PushButton::OnFocusChanged(CFWL_Message* pMsg, bool bSet) {
- if (bSet)
- m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
- else
- m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
+void CFWL_PushButton::OnFocusGained() {
+ m_Properties.m_dwStates |= FWL_STATE_WGT_Focused;
+ RepaintRect(m_ClientRect);
+}
- RepaintRect(m_rtClient);
+void CFWL_PushButton::OnFocusLost() {
+ m_Properties.m_dwStates &= ~FWL_STATE_WGT_Focused;
+ RepaintRect(m_ClientRect);
}
void CFWL_PushButton::OnLButtonDown(CFWL_MessageMouse* pMsg) {
m_bBtnDown = true;
- m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered;
- m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed;
- RepaintRect(m_rtClient);
+ m_Properties.m_dwStates |= FWL_STATE_PSB_Hovered;
+ m_Properties.m_dwStates |= FWL_STATE_PSB_Pressed;
+ RepaintRect(m_ClientRect);
}
void CFWL_PushButton::OnLButtonUp(CFWL_MessageMouse* pMsg) {
m_bBtnDown = false;
- if (m_rtClient.Contains(pMsg->m_pos)) {
- m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed;
- m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered;
+ if (m_ClientRect.Contains(pMsg->m_pos)) {
+ m_Properties.m_dwStates &= ~FWL_STATE_PSB_Pressed;
+ m_Properties.m_dwStates |= FWL_STATE_PSB_Hovered;
} else {
- m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered;
- m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed;
+ m_Properties.m_dwStates &= ~FWL_STATE_PSB_Hovered;
+ m_Properties.m_dwStates &= ~FWL_STATE_PSB_Pressed;
}
- if (m_rtClient.Contains(pMsg->m_pos)) {
+ if (m_ClientRect.Contains(pMsg->m_pos)) {
CFWL_Event wmClick(CFWL_Event::Type::Click, this);
DispatchEvent(&wmClick);
}
- RepaintRect(m_rtClient);
+ RepaintRect(m_ClientRect);
}
void CFWL_PushButton::OnMouseMove(CFWL_MessageMouse* pMsg) {
bool bRepaint = false;
if (m_bBtnDown) {
- if (m_rtClient.Contains(pMsg->m_pos)) {
- if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) == 0) {
- m_pProperties->m_dwStates |= FWL_STATE_PSB_Pressed;
+ if (m_ClientRect.Contains(pMsg->m_pos)) {
+ if ((m_Properties.m_dwStates & FWL_STATE_PSB_Pressed) == 0) {
+ m_Properties.m_dwStates |= FWL_STATE_PSB_Pressed;
bRepaint = true;
}
- if (m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) {
- m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered;
+ if (m_Properties.m_dwStates & FWL_STATE_PSB_Hovered) {
+ m_Properties.m_dwStates &= ~FWL_STATE_PSB_Hovered;
bRepaint = true;
}
} else {
- if (m_pProperties->m_dwStates & FWL_STATE_PSB_Pressed) {
- m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed;
+ if (m_Properties.m_dwStates & FWL_STATE_PSB_Pressed) {
+ m_Properties.m_dwStates &= ~FWL_STATE_PSB_Pressed;
bRepaint = true;
}
- if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) == 0) {
- m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered;
+ if ((m_Properties.m_dwStates & FWL_STATE_PSB_Hovered) == 0) {
+ m_Properties.m_dwStates |= FWL_STATE_PSB_Hovered;
bRepaint = true;
}
}
} else {
- if (!m_rtClient.Contains(pMsg->m_pos))
+ if (!m_ClientRect.Contains(pMsg->m_pos))
return;
- if ((m_pProperties->m_dwStates & FWL_STATE_PSB_Hovered) == 0) {
- m_pProperties->m_dwStates |= FWL_STATE_PSB_Hovered;
+ if ((m_Properties.m_dwStates & FWL_STATE_PSB_Hovered) == 0) {
+ m_Properties.m_dwStates |= FWL_STATE_PSB_Hovered;
bRepaint = true;
}
}
if (bRepaint)
- RepaintRect(m_rtClient);
+ RepaintRect(m_ClientRect);
}
void CFWL_PushButton::OnMouseLeave(CFWL_MessageMouse* pMsg) {
m_bBtnDown = false;
- m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Hovered;
- m_pProperties->m_dwStates &= ~FWL_STATE_PSB_Pressed;
- RepaintRect(m_rtClient);
+ m_Properties.m_dwStates &= ~FWL_STATE_PSB_Hovered;
+ m_Properties.m_dwStates &= ~FWL_STATE_PSB_Pressed;
+ RepaintRect(m_ClientRect);
}
void CFWL_PushButton::OnKeyDown(CFWL_MessageKey* pMsg) {
- if (pMsg->m_dwKeyCode != XFA_FWL_VKEY_Return)
+ if (pMsg->m_dwKeyCodeOrChar != XFA_FWL_VKEY_Return)
return;
- CFWL_EventMouse wmMouse(this);
- wmMouse.m_dwCmd = FWL_MouseCommand::LeftButtonUp;
+ CFWL_EventMouse wmMouse(this, nullptr,
+ CFWL_MessageMouse::MouseCommand::kLeftButtonUp);
DispatchEvent(&wmMouse);
if (!wmMouse.GetSrcTarget())
return;
diff --git a/xfa/fwl/cfwl_pushbutton.h b/xfa/fwl/cfwl_pushbutton.h
index 925dbb653..412e5bcf0 100644
--- a/xfa/fwl/cfwl_pushbutton.h
+++ b/xfa/fwl/cfwl_pushbutton.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,36 +8,37 @@
#define XFA_FWL_CFWL_PUSHBUTTON_H_
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fwl/cfwl_widgetproperties.h"
-#define FWL_STATE_PSB_Hovered (1 << FWL_WGTSTATE_MAX)
-#define FWL_STATE_PSB_Pressed (1 << (FWL_WGTSTATE_MAX + 1))
+#define FWL_STATE_PSB_Hovered (1 << FWL_STATE_WGT_MAX)
+#define FWL_STATE_PSB_Pressed (1 << (FWL_STATE_WGT_MAX + 1))
+#define FWL_STATE_PSB_Default (1 << (FWL_STATE_WGT_MAX + 2))
+class CFWL_MessageKey;
class CFWL_MessageMouse;
-class CFX_DIBitmap;
-class CFWL_Widget;
class CFWL_PushButton final : public CFWL_Widget {
public:
- explicit CFWL_PushButton(const CFWL_App*);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_PushButton() override;
// CFWL_Widget
FWL_Type GetClassID() const override;
void SetStates(uint32_t dwStates) override;
void Update() override;
- void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
+ void DrawWidget(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& matrix) override;
void OnProcessMessage(CFWL_Message* pMessage) override;
- void OnDrawWidget(CXFA_Graphics* pGraphics,
+ void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) override;
private:
- void DrawBkground(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
- uint32_t GetPartStates();
+ explicit CFWL_PushButton(CFWL_App* pApp);
+
+ void DrawBkground(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ Mask<CFWL_PartState> GetPartStates();
void UpdateTextOutStyles();
- void OnFocusChanged(CFWL_Message* pMsg, bool bSet);
+ void OnFocusGained();
+ void OnFocusLost();
void OnLButtonDown(CFWL_MessageMouse* pMsg);
void OnLButtonUp(CFWL_MessageMouse* pMsg);
void OnMouseMove(CFWL_MessageMouse* pMsg);
@@ -45,8 +46,8 @@ class CFWL_PushButton final : public CFWL_Widget {
void OnKeyDown(CFWL_MessageKey* pMsg);
bool m_bBtnDown = false;
- CFX_RectF m_rtClient;
- CFX_RectF m_rtCaption;
+ CFX_RectF m_ClientRect;
+ CFX_RectF m_CaptionRect;
};
#endif // XFA_FWL_CFWL_PUSHBUTTON_H_
diff --git a/xfa/fwl/cfwl_scrollbar.cpp b/xfa/fwl/cfwl_scrollbar.cpp
index acc144f36..36dd9e567 100644
--- a/xfa/fwl/cfwl_scrollbar.cpp
+++ b/xfa/fwl/cfwl_scrollbar.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,8 +10,7 @@
#include <memory>
#include <utility>
-#include "third_party/base/ptr_util.h"
-#include "third_party/base/stl_util.h"
+#include "third_party/base/cxx17_backports.h"
#include "xfa/fwl/cfwl_app.h"
#include "xfa/fwl/cfwl_messagemouse.h"
#include "xfa/fwl/cfwl_messagemousewheel.h"
@@ -20,19 +19,17 @@
#include "xfa/fwl/cfwl_themepart.h"
#include "xfa/fwl/ifwl_themeprovider.h"
-#define FWL_SCROLLBAR_Elapse 500
-
namespace {
-const float kMinThumbSize = 5.0f;
+constexpr int kScrollbarElapsedMsecs = 500;
+constexpr float kMinThumbSize = 5.0f;
} // namespace
-CFWL_ScrollBar::CFWL_ScrollBar(
- const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter)
- : CFWL_Widget(app, std::move(properties), pOuter) {}
+CFWL_ScrollBar::CFWL_ScrollBar(CFWL_App* app,
+ const Properties& properties,
+ CFWL_Widget* pOuter)
+ : CFWL_Widget(app, properties, pOuter) {}
CFWL_ScrollBar::~CFWL_ScrollBar() = default;
@@ -43,34 +40,30 @@ FWL_Type CFWL_ScrollBar::GetClassID() const {
void CFWL_ScrollBar::Update() {
if (IsLocked())
return;
- if (!m_pProperties->m_pThemeProvider)
- m_pProperties->m_pThemeProvider = GetAvailableTheme();
Layout();
}
-void CFWL_ScrollBar::DrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_ScrollBar::DrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
if (!pGraphics)
return;
- if (!m_pProperties->m_pThemeProvider)
- return;
- IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get();
if (HasBorder())
- DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix);
- DrawTrack(pGraphics, pTheme, true, &matrix);
- DrawTrack(pGraphics, pTheme, false, &matrix);
- DrawArrowBtn(pGraphics, pTheme, true, &matrix);
- DrawArrowBtn(pGraphics, pTheme, false, &matrix);
- DrawThumb(pGraphics, pTheme, &matrix);
+ DrawBorder(pGraphics, CFWL_ThemePart::Part::kBorder, matrix);
+
+ DrawLowerTrack(pGraphics, matrix);
+ DrawUpperTrack(pGraphics, matrix);
+ DrawMinArrowBtn(pGraphics, matrix);
+ DrawMaxArrowBtn(pGraphics, matrix);
+ DrawThumb(pGraphics, matrix);
}
void CFWL_ScrollBar::SetTrackPos(float fTrackPos) {
m_fTrackPos = fTrackPos;
- m_rtThumb = CalcThumbButtonRect(m_rtThumb);
- m_rtMinTrack = CalcMinTrackRect(m_rtMinTrack);
- m_rtMaxTrack = CalcMaxTrackRect(m_rtMaxTrack);
+ m_ThumbRect = CalcThumbButtonRect(m_ThumbRect);
+ m_MinTrackRect = CalcMinTrackRect(m_MinTrackRect);
+ m_MaxTrackRect = CalcMaxTrackRect(m_MaxTrackRect);
}
bool CFWL_ScrollBar::DoScroll(CFWL_EventScroll::Code dwCode, float fPos) {
@@ -79,68 +72,79 @@ bool CFWL_ScrollBar::DoScroll(CFWL_EventScroll::Code dwCode, float fPos) {
return OnScroll(dwCode, fPos);
}
-void CFWL_ScrollBar::DrawTrack(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- bool bLower,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeBackground param;
- param.m_pWidget = this;
- param.m_iPart = bLower ? CFWL_Part::LowerTrack : CFWL_Part::UpperTrack;
- param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
- ? CFWL_PartState_Disabled
- : (bLower ? m_iMinTrackState : m_iMaxTrackState);
- param.m_pGraphics = pGraphics;
- param.m_matrix.Concat(*pMatrix);
- param.m_rtPart = bLower ? m_rtMinTrack : m_rtMaxTrack;
- pTheme->DrawBackground(param);
-}
-
-void CFWL_ScrollBar::DrawArrowBtn(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- bool bMinBtn,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeBackground param;
- param.m_pWidget = this;
- param.m_iPart = bMinBtn ? CFWL_Part::ForeArrow : CFWL_Part::BackArrow;
- param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
- ? CFWL_PartState_Disabled
- : (bMinBtn ? m_iMinButtonState : m_iMaxButtonState);
- param.m_pGraphics = pGraphics;
- param.m_matrix.Concat(*pMatrix);
- param.m_rtPart = bMinBtn ? m_rtMinBtn : m_rtMaxBtn;
- if (param.m_rtPart.height > 0 && param.m_rtPart.width > 0)
- pTheme->DrawBackground(param);
-}
-
-void CFWL_ScrollBar::DrawThumb(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeBackground param;
- param.m_pWidget = this;
- param.m_iPart = CFWL_Part::Thumb;
- param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)
- ? CFWL_PartState_Disabled
+void CFWL_ScrollBar::DrawUpperTrack(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeBackground param(CFWL_ThemePart::Part::kUpperTrack, this,
+ pGraphics);
+ param.m_dwStates = (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)
+ ? CFWL_PartState::kDisabled
+ : m_iMaxTrackState;
+ param.m_matrix = mtMatrix;
+ param.m_PartRect = m_MaxTrackRect;
+ GetThemeProvider()->DrawBackground(param);
+}
+
+void CFWL_ScrollBar::DrawLowerTrack(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeBackground param(CFWL_ThemePart::Part::kLowerTrack, this,
+ pGraphics);
+ param.m_dwStates = (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)
+ ? CFWL_PartState::kDisabled
+ : m_iMinTrackState;
+ param.m_matrix = mtMatrix;
+ param.m_PartRect = m_MinTrackRect;
+ GetThemeProvider()->DrawBackground(param);
+}
+
+void CFWL_ScrollBar::DrawMaxArrowBtn(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeBackground param(CFWL_ThemePart::Part::kBackArrow, this, pGraphics);
+ param.m_dwStates = (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)
+ ? CFWL_PartState::kDisabled
+ : m_iMaxButtonState;
+ param.m_matrix = mtMatrix;
+ param.m_PartRect = m_MaxBtnRect;
+ if (param.m_PartRect.height > 0 && param.m_PartRect.width > 0)
+ GetThemeProvider()->DrawBackground(param);
+}
+
+void CFWL_ScrollBar::DrawMinArrowBtn(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeBackground param(CFWL_ThemePart::Part::kForeArrow, this, pGraphics);
+ param.m_dwStates = (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)
+ ? CFWL_PartState::kDisabled
+ : m_iMinButtonState;
+ param.m_matrix = mtMatrix;
+ param.m_PartRect = m_MinBtnRect;
+ if (param.m_PartRect.height > 0 && param.m_PartRect.width > 0)
+ GetThemeProvider()->DrawBackground(param);
+}
+
+void CFWL_ScrollBar::DrawThumb(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeBackground param(CFWL_ThemePart::Part::kThumb, this, pGraphics);
+ param.m_dwStates = (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled)
+ ? CFWL_PartState::kDisabled
: m_iThumbButtonState;
- param.m_pGraphics = pGraphics;
- param.m_matrix.Concat(*pMatrix);
- param.m_rtPart = m_rtThumb;
- pTheme->DrawBackground(param);
+ param.m_matrix = mtMatrix;
+ param.m_PartRect = m_ThumbRect;
+ GetThemeProvider()->DrawBackground(param);
}
void CFWL_ScrollBar::Layout() {
- m_rtClient = GetClientRect();
+ m_ClientRect = GetClientRect();
CalcButtonLen();
- m_rtMinBtn = CalcMinButtonRect();
- m_rtMaxBtn = CalcMaxButtonRect();
- m_rtThumb = CalcThumbButtonRect(m_rtThumb);
- m_rtMinTrack = CalcMinTrackRect(m_rtMinTrack);
- m_rtMaxTrack = CalcMaxTrackRect(m_rtMaxTrack);
+ m_MinBtnRect = CalcMinButtonRect();
+ m_MaxBtnRect = CalcMaxButtonRect();
+ m_ThumbRect = CalcThumbButtonRect(m_ThumbRect);
+ m_MinTrackRect = CalcMinTrackRect(m_MinTrackRect);
+ m_MaxTrackRect = CalcMaxTrackRect(m_MaxTrackRect);
}
void CFWL_ScrollBar::CalcButtonLen() {
- m_fButtonLen = IsVertical() ? m_rtClient.width : m_rtClient.height;
- float fLength = IsVertical() ? m_rtClient.height : m_rtClient.width;
+ m_fButtonLen = IsVertical() ? m_ClientRect.width : m_ClientRect.height;
+ float fLength = IsVertical() ? m_ClientRect.height : m_ClientRect.width;
if (fLength < m_fButtonLen * 2) {
m_fButtonLen = fLength / 2;
m_bMinSize = true;
@@ -151,17 +155,17 @@ void CFWL_ScrollBar::CalcButtonLen() {
CFX_RectF CFWL_ScrollBar::CalcMinButtonRect() {
if (IsVertical())
- return CFX_RectF(m_rtClient.TopLeft(), m_rtClient.width, m_fButtonLen);
- return CFX_RectF(m_rtClient.TopLeft(), m_fButtonLen, m_rtClient.height);
+ return CFX_RectF(m_ClientRect.TopLeft(), m_ClientRect.width, m_fButtonLen);
+ return CFX_RectF(m_ClientRect.TopLeft(), m_fButtonLen, m_ClientRect.height);
}
CFX_RectF CFWL_ScrollBar::CalcMaxButtonRect() {
if (IsVertical()) {
- return CFX_RectF(m_rtClient.left, m_rtClient.bottom() - m_fButtonLen,
- m_rtClient.width, m_fButtonLen);
+ return CFX_RectF(m_ClientRect.left, m_ClientRect.bottom() - m_fButtonLen,
+ m_ClientRect.width, m_fButtonLen);
}
- return CFX_RectF(m_rtClient.right() - m_fButtonLen, m_rtClient.top,
- m_fButtonLen, m_rtClient.height);
+ return CFX_RectF(m_ClientRect.right() - m_fButtonLen, m_ClientRect.top,
+ m_fButtonLen, m_ClientRect.height);
}
CFX_RectF CFWL_ScrollBar::CalcThumbButtonRect(const CFX_RectF& rtThumb) {
@@ -178,13 +182,14 @@ CFX_RectF CFWL_ScrollBar::CalcThumbButtonRect(const CFX_RectF& rtThumb) {
float fRange = m_fRangeMax - m_fRangeMin;
if (fRange < 0) {
if (IsVertical()) {
- return CFX_RectF(m_rtClient.left, m_rtMaxBtn.bottom(), m_rtClient.width,
- 0);
+ return CFX_RectF(m_ClientRect.left, m_MaxBtnRect.bottom(),
+ m_ClientRect.width, 0);
}
- return CFX_RectF(m_rtMaxBtn.right(), m_rtClient.top, 0, m_rtClient.height);
+ return CFX_RectF(m_MaxBtnRect.right(), m_ClientRect.top, 0,
+ m_ClientRect.height);
}
- CFX_RectF rtClient = m_rtClient;
+ CFX_RectF rtClient = m_ClientRect;
float fLength = IsVertical() ? rtClient.height : rtClient.width;
float fSize = m_fButtonLen;
fLength -= fSize * 2.0f;
@@ -222,14 +227,14 @@ CFX_RectF CFWL_ScrollBar::CalcMinTrackRect(const CFX_RectF& rtMinRect) {
return rect;
}
- rect.left = m_rtClient.left;
- rect.top = m_rtClient.top;
+ rect.left = m_ClientRect.left;
+ rect.top = m_ClientRect.top;
if (IsVertical()) {
- rect.width = m_rtClient.width;
- rect.height = (m_rtThumb.top + m_rtThumb.bottom()) / 2;
+ rect.width = m_ClientRect.width;
+ rect.height = (m_ThumbRect.top + m_ThumbRect.bottom()) / 2;
} else {
- rect.width = (m_rtThumb.left + m_rtThumb.right()) / 2;
- rect.height = m_rtClient.height;
+ rect.width = (m_ThumbRect.left + m_ThumbRect.right()) / 2;
+ rect.height = m_ClientRect.height;
}
return rect;
}
@@ -239,14 +244,14 @@ CFX_RectF CFWL_ScrollBar::CalcMaxTrackRect(const CFX_RectF& rtMaxRect) {
return CFX_RectF(rtMaxRect.TopLeft(), 0, 0);
if (IsVertical()) {
- float iy = (m_rtThumb.top + m_rtThumb.bottom()) / 2;
- return CFX_RectF(m_rtClient.left, iy, m_rtClient.width,
- m_rtClient.bottom() - iy);
+ float iy = (m_ThumbRect.top + m_ThumbRect.bottom()) / 2;
+ return CFX_RectF(m_ClientRect.left, iy, m_ClientRect.width,
+ m_ClientRect.bottom() - iy);
}
- float ix = (m_rtThumb.left + m_rtThumb.right()) / 2;
- return CFX_RectF(ix, m_rtClient.top, m_rtClient.height - ix,
- m_rtClient.height);
+ float ix = (m_ThumbRect.left + m_ThumbRect.right()) / 2;
+ return CFX_RectF(ix, m_ClientRect.top, m_ClientRect.height - ix,
+ m_ClientRect.height);
}
float CFWL_ScrollBar::GetTrackPointPos(const CFX_PointF& point) {
@@ -256,10 +261,10 @@ float CFWL_ScrollBar::GetTrackPointPos(const CFX_PointF& point) {
if (IsVertical()) {
fPos = fRange * diff.y /
- (m_rtMaxBtn.top - m_rtMinBtn.bottom() - m_rtThumb.height);
+ (m_MaxBtnRect.top - m_MinBtnRect.bottom() - m_ThumbRect.height);
} else {
fPos = fRange * diff.x /
- (m_rtMaxBtn.left - m_rtMinBtn.right() - m_rtThumb.width);
+ (m_MaxBtnRect.left - m_MinBtnRect.right() - m_ThumbRect.width);
}
fPos += m_fLastTrackPos;
@@ -267,21 +272,21 @@ float CFWL_ScrollBar::GetTrackPointPos(const CFX_PointF& point) {
}
bool CFWL_ScrollBar::SendEvent() {
- if (m_iMinButtonState == CFWL_PartState_Pressed) {
+ if (m_iMinButtonState == CFWL_PartState::kPressed) {
DoScroll(CFWL_EventScroll::Code::StepBackward, m_fTrackPos);
return false;
}
- if (m_iMaxButtonState == CFWL_PartState_Pressed) {
+ if (m_iMaxButtonState == CFWL_PartState::kPressed) {
DoScroll(CFWL_EventScroll::Code::StepForward, m_fTrackPos);
return false;
}
- if (m_iMinTrackState == CFWL_PartState_Pressed) {
+ if (m_iMinTrackState == CFWL_PartState::kPressed) {
DoScroll(CFWL_EventScroll::Code::PageBackward, m_fTrackPos);
- return m_rtThumb.Contains(m_cpTrackPoint);
+ return m_ThumbRect.Contains(m_cpTrackPoint);
}
- if (m_iMaxTrackState == CFWL_PartState_Pressed) {
+ if (m_iMaxTrackState == CFWL_PartState::kPressed) {
DoScroll(CFWL_EventScroll::Code::PageForward, m_fTrackPos);
- return m_rtThumb.Contains(m_cpTrackPoint);
+ return m_ThumbRect.Contains(m_cpTrackPoint);
}
if (m_iMouseWheel) {
CFWL_EventScroll::Code dwCode = m_iMouseWheel < 0
@@ -293,44 +298,38 @@ bool CFWL_ScrollBar::SendEvent() {
}
bool CFWL_ScrollBar::OnScroll(CFWL_EventScroll::Code dwCode, float fPos) {
- CFWL_EventScroll ev(this);
- ev.m_iScrollCode = dwCode;
- ev.m_fPos = fPos;
+ CFWL_EventScroll ev(this, dwCode, fPos);
DispatchEvent(&ev);
return true;
}
void CFWL_ScrollBar::OnProcessMessage(CFWL_Message* pMessage) {
- if (!pMessage)
- return;
-
CFWL_Message::Type type = pMessage->GetType();
- if (type == CFWL_Message::Type::Mouse) {
+ if (type == CFWL_Message::Type::kMouse) {
CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
switch (pMsg->m_dwCmd) {
- case FWL_MouseCommand::LeftButtonDown:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonDown:
OnLButtonDown(pMsg->m_pos);
break;
- case FWL_MouseCommand::LeftButtonUp:
+ case CFWL_MessageMouse::MouseCommand::kLeftButtonUp:
OnLButtonUp(pMsg->m_pos);
break;
- case FWL_MouseCommand::Move:
+ case CFWL_MessageMouse::MouseCommand::kMove:
OnMouseMove(pMsg->m_pos);
break;
- case FWL_MouseCommand::Leave:
+ case CFWL_MessageMouse::MouseCommand::kLeave:
OnMouseLeave();
break;
default:
break;
}
- } else if (type == CFWL_Message::Type::MouseWheel) {
- CFWL_MessageMouseWheel* pMsg =
- static_cast<CFWL_MessageMouseWheel*>(pMessage);
- OnMouseWheel(pMsg->m_delta);
+ } else if (type == CFWL_Message::Type::kMouseWheel) {
+ auto* pMsg = static_cast<CFWL_MessageMouseWheel*>(pMessage);
+ OnMouseWheel(pMsg->delta());
}
}
-void CFWL_ScrollBar::OnDrawWidget(CXFA_Graphics* pGraphics,
+void CFWL_ScrollBar::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
DrawWidget(pGraphics, matrix);
}
@@ -344,97 +343,97 @@ void CFWL_ScrollBar::OnLButtonDown(const CFX_PointF& point) {
m_cpTrackPoint = point;
m_fLastTrackPos = m_fTrackPos;
- if (m_rtMinBtn.Contains(point))
- DoMouseDown(0, m_rtMinBtn, m_iMinButtonState, point);
- else if (m_rtThumb.Contains(point))
- DoMouseDown(1, m_rtThumb, m_iThumbButtonState, point);
- else if (m_rtMaxBtn.Contains(point))
- DoMouseDown(2, m_rtMaxBtn, m_iMaxButtonState, point);
- else if (m_rtMinTrack.Contains(point))
- DoMouseDown(3, m_rtMinTrack, m_iMinTrackState, point);
+ if (m_MinBtnRect.Contains(point))
+ DoMouseDown(0, m_MinBtnRect, &m_iMinButtonState, point);
+ else if (m_ThumbRect.Contains(point))
+ DoMouseDown(1, m_ThumbRect, &m_iThumbButtonState, point);
+ else if (m_MaxBtnRect.Contains(point))
+ DoMouseDown(2, m_MaxBtnRect, &m_iMaxButtonState, point);
+ else if (m_MinTrackRect.Contains(point))
+ DoMouseDown(3, m_MinTrackRect, &m_iMinTrackState, point);
else
- DoMouseDown(4, m_rtMaxTrack, m_iMaxTrackState, point);
+ DoMouseDown(4, m_MaxTrackRect, &m_iMaxTrackState, point);
if (!SendEvent()) {
- m_pTimer = pdfium::MakeUnique<CFX_Timer>(
- GetOwnerApp()->GetAdapterNative()->GetTimerHandler(), this,
- FWL_SCROLLBAR_Elapse);
+ m_pTimer = std::make_unique<CFX_Timer>(GetFWLApp()->GetTimerHandler(), this,
+ kScrollbarElapsedMsecs);
}
}
void CFWL_ScrollBar::OnLButtonUp(const CFX_PointF& point) {
m_pTimer.reset();
m_bMouseDown = false;
- DoMouseUp(0, m_rtMinBtn, m_iMinButtonState, point);
- DoMouseUp(1, m_rtThumb, m_iThumbButtonState, point);
- DoMouseUp(2, m_rtMaxBtn, m_iMaxButtonState, point);
- DoMouseUp(3, m_rtMinTrack, m_iMinTrackState, point);
- DoMouseUp(4, m_rtMaxTrack, m_iMaxTrackState, point);
+ DoMouseUp(0, m_MinBtnRect, &m_iMinButtonState, point);
+ DoMouseUp(1, m_ThumbRect, &m_iThumbButtonState, point);
+ DoMouseUp(2, m_MaxBtnRect, &m_iMaxButtonState, point);
+ DoMouseUp(3, m_MinTrackRect, &m_iMinTrackState, point);
+ DoMouseUp(4, m_MaxTrackRect, &m_iMaxTrackState, point);
SetGrab(false);
}
void CFWL_ScrollBar::OnMouseMove(const CFX_PointF& point) {
- DoMouseMove(0, m_rtMinBtn, m_iMinButtonState, point);
- DoMouseMove(1, m_rtThumb, m_iThumbButtonState, point);
- DoMouseMove(2, m_rtMaxBtn, m_iMaxButtonState, point);
- DoMouseMove(3, m_rtMinTrack, m_iMinTrackState, point);
- DoMouseMove(4, m_rtMaxTrack, m_iMaxTrackState, point);
+ DoMouseMove(0, m_MinBtnRect, &m_iMinButtonState, point);
+ DoMouseMove(1, m_ThumbRect, &m_iThumbButtonState, point);
+ DoMouseMove(2, m_MaxBtnRect, &m_iMaxButtonState, point);
+ DoMouseMove(3, m_MinTrackRect, &m_iMinTrackState, point);
+ DoMouseMove(4, m_MaxTrackRect, &m_iMaxTrackState, point);
}
void CFWL_ScrollBar::OnMouseLeave() {
- DoMouseLeave(0, m_rtMinBtn, m_iMinButtonState);
- DoMouseLeave(1, m_rtThumb, m_iThumbButtonState);
- DoMouseLeave(2, m_rtMaxBtn, m_iMaxButtonState);
- DoMouseLeave(3, m_rtMinTrack, m_iMinTrackState);
- DoMouseLeave(4, m_rtMaxTrack, m_iMaxTrackState);
+ DoMouseLeave(0, m_MinBtnRect, &m_iMinButtonState);
+ DoMouseLeave(1, m_ThumbRect, &m_iThumbButtonState);
+ DoMouseLeave(2, m_MaxBtnRect, &m_iMaxButtonState);
+ DoMouseLeave(3, m_MinTrackRect, &m_iMinTrackState);
+ DoMouseLeave(4, m_MaxTrackRect, &m_iMaxTrackState);
}
-void CFWL_ScrollBar::OnMouseWheel(const CFX_PointF& delta) {
- m_iMouseWheel = static_cast<int32_t>(delta.x);
+void CFWL_ScrollBar::OnMouseWheel(const CFX_Vector& delta) {
+ m_iMouseWheel = delta.y;
SendEvent();
m_iMouseWheel = 0;
}
void CFWL_ScrollBar::DoMouseDown(int32_t iItem,
const CFX_RectF& rtItem,
- int32_t& iState,
+ CFWL_PartState* pState,
const CFX_PointF& point) {
if (!rtItem.Contains(point))
return;
- if (iState == CFWL_PartState_Pressed)
+ if (*pState == CFWL_PartState::kPressed)
return;
- iState = CFWL_PartState_Pressed;
+ *pState = CFWL_PartState::kPressed;
RepaintRect(rtItem);
}
void CFWL_ScrollBar::DoMouseUp(int32_t iItem,
const CFX_RectF& rtItem,
- int32_t& iState,
+ CFWL_PartState* pState,
const CFX_PointF& point) {
- int32_t iNewState =
- rtItem.Contains(point) ? CFWL_PartState_Hovered : CFWL_PartState_Normal;
- if (iState == iNewState)
+ CFWL_PartState iNewState = rtItem.Contains(point) ? CFWL_PartState::kHovered
+ : CFWL_PartState::kNormal;
+ if (*pState == iNewState)
return;
- iState = iNewState;
+ *pState = iNewState;
RepaintRect(rtItem);
OnScroll(CFWL_EventScroll::Code::EndScroll, m_fTrackPos);
}
void CFWL_ScrollBar::DoMouseMove(int32_t iItem,
const CFX_RectF& rtItem,
- int32_t& iState,
+ CFWL_PartState* pState,
const CFX_PointF& point) {
if (!m_bMouseDown) {
- int32_t iNewState =
- rtItem.Contains(point) ? CFWL_PartState_Hovered : CFWL_PartState_Normal;
- if (iState == iNewState)
+ CFWL_PartState iNewState = rtItem.Contains(point) ? CFWL_PartState::kHovered
+ : CFWL_PartState::kNormal;
+ if (*pState == iNewState)
return;
- iState = iNewState;
+ *pState = iNewState;
RepaintRect(rtItem);
- } else if ((2 == iItem) && (m_iThumbButtonState == CFWL_PartState_Pressed)) {
+ } else if ((2 == iItem) &&
+ (m_iThumbButtonState == CFWL_PartState::kPressed)) {
m_fTrackPos = GetTrackPointPos(point);
OnScroll(CFWL_EventScroll::Code::TrackPos, m_fTrackPos);
}
@@ -442,28 +441,28 @@ void CFWL_ScrollBar::DoMouseMove(int32_t iItem,
void CFWL_ScrollBar::DoMouseLeave(int32_t iItem,
const CFX_RectF& rtItem,
- int32_t& iState) {
- if (iState == CFWL_PartState_Normal)
+ CFWL_PartState* pState) {
+ if (*pState == CFWL_PartState::kNormal)
return;
- iState = CFWL_PartState_Normal;
+ *pState = CFWL_PartState::kNormal;
RepaintRect(rtItem);
}
void CFWL_ScrollBar::DoMouseHover(int32_t iItem,
const CFX_RectF& rtItem,
- int32_t& iState) {
- if (iState == CFWL_PartState_Hovered)
+ CFWL_PartState* pState) {
+ if (*pState == CFWL_PartState::kHovered)
return;
- iState = CFWL_PartState_Hovered;
+ *pState = CFWL_PartState::kHovered;
RepaintRect(rtItem);
}
void CFWL_ScrollBar::OnTimerFired() {
m_pTimer.reset();
if (!SendEvent()) {
- m_pTimer = pdfium::MakeUnique<CFX_Timer>(
- GetOwnerApp()->GetAdapterNative()->GetTimerHandler(), this, 0);
+ m_pTimer =
+ std::make_unique<CFX_Timer>(GetFWLApp()->GetTimerHandler(), this, 0);
}
}
diff --git a/xfa/fwl/cfwl_scrollbar.h b/xfa/fwl/cfwl_scrollbar.h
index c98479d84..598d19de6 100644
--- a/xfa/fwl/cfwl_scrollbar.h
+++ b/xfa/fwl/cfwl_scrollbar.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,16 +7,15 @@
#ifndef XFA_FWL_CFWL_SCROLLBAR_H_
#define XFA_FWL_CFWL_SCROLLBAR_H_
+#include <stdint.h>
+
#include <memory>
#include "core/fxcrt/cfx_timer.h"
-#include "core/fxcrt/fx_system.h"
-#include "core/fxcrt/unowned_ptr.h"
+#include "third_party/base/check.h"
#include "xfa/fwl/cfwl_eventscroll.h"
+#include "xfa/fwl/cfwl_themepart.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fwl/cfwl_widgetproperties.h"
-
-class CFWL_Widget;
#define FWL_STYLEEXT_SCB_Horz (0L << 0)
#define FWL_STYLEEXT_SCB_Vert (1L << 0)
@@ -24,25 +23,22 @@ class CFWL_Widget;
class CFWL_ScrollBar final : public CFWL_Widget,
public CFX_Timer::CallbackIface {
public:
- CFWL_ScrollBar(const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_ScrollBar() override;
// CFWL_Widget:
FWL_Type GetClassID() const override;
void Update() override;
- void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
+ void DrawWidget(CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& matrix) override;
void OnProcessMessage(CFWL_Message* pMessage) override;
- void OnDrawWidget(CXFA_Graphics* pGraphics,
+ void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) override;
// CFX_Timer::CallbackIface:
void OnTimerFired() override;
void GetRange(float* fMin, float* fMax) const {
- ASSERT(fMin);
- ASSERT(fMax);
*fMin = m_fRangeMin;
*fMax = m_fRangeMax;
}
@@ -59,20 +55,16 @@ class CFWL_ScrollBar final : public CFWL_Widget,
void SetTrackPos(float fTrackPos);
private:
- bool IsVertical() const {
- return !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_SCB_Vert);
- }
- void DrawTrack(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- bool bLower,
- const CFX_Matrix* pMatrix);
- void DrawArrowBtn(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- bool bMinBtn,
- const CFX_Matrix* pMatrix);
- void DrawThumb(CXFA_Graphics* pGraphics,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
+ CFWL_ScrollBar(CFWL_App* app,
+ const Properties& properties,
+ CFWL_Widget* pOuter);
+
+ bool IsVertical() const { return !!(GetStyleExts() & FWL_STYLEEXT_SCB_Vert); }
+ void DrawUpperTrack(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawLowerTrack(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawMaxArrowBtn(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawMinArrowBtn(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
+ void DrawThumb(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
void Layout();
void CalcButtonLen();
CFX_RectF CalcMinButtonRect();
@@ -88,22 +80,26 @@ class CFWL_ScrollBar final : public CFWL_Widget,
void OnLButtonUp(const CFX_PointF& point);
void OnMouseMove(const CFX_PointF& point);
void OnMouseLeave();
- void OnMouseWheel(const CFX_PointF& delta);
+ void OnMouseWheel(const CFX_Vector& delta);
bool DoScroll(CFWL_EventScroll::Code dwCode, float fPos);
void DoMouseDown(int32_t iItem,
const CFX_RectF& rtItem,
- int32_t& iState,
+ CFWL_PartState* pState,
const CFX_PointF& point);
void DoMouseUp(int32_t iItem,
const CFX_RectF& rtItem,
- int32_t& iState,
+ CFWL_PartState* pState,
const CFX_PointF& point);
void DoMouseMove(int32_t iItem,
const CFX_RectF& rtItem,
- int32_t& iState,
+ CFWL_PartState* pState,
const CFX_PointF& point);
- void DoMouseLeave(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState);
- void DoMouseHover(int32_t iItem, const CFX_RectF& rtItem, int32_t& iState);
+ void DoMouseLeave(int32_t iItem,
+ const CFX_RectF& rtItem,
+ CFWL_PartState* pState);
+ void DoMouseHover(int32_t iItem,
+ const CFX_RectF& rtItem,
+ CFWL_PartState* pState);
float m_fRangeMin = 0.0f;
float m_fRangeMax = -1.0f;
@@ -111,23 +107,23 @@ class CFWL_ScrollBar final : public CFWL_Widget,
float m_fStepSize = 0.0f;
float m_fPos = 0.0f;
float m_fTrackPos = 0.0f;
- int32_t m_iMinButtonState = CFWL_PartState_Normal;
- int32_t m_iMaxButtonState = CFWL_PartState_Normal;
- int32_t m_iThumbButtonState = CFWL_PartState_Normal;
- int32_t m_iMinTrackState = CFWL_PartState_Normal;
- int32_t m_iMaxTrackState = CFWL_PartState_Normal;
+ CFWL_PartState m_iMinButtonState = CFWL_PartState::kNormal;
+ CFWL_PartState m_iMaxButtonState = CFWL_PartState::kNormal;
+ CFWL_PartState m_iThumbButtonState = CFWL_PartState::kNormal;
+ CFWL_PartState m_iMinTrackState = CFWL_PartState::kNormal;
+ CFWL_PartState m_iMaxTrackState = CFWL_PartState::kNormal;
float m_fLastTrackPos = 0.0f;
CFX_PointF m_cpTrackPoint;
int32_t m_iMouseWheel = 0;
float m_fButtonLen = 0.0f;
bool m_bMouseDown = false;
bool m_bMinSize = false;
- CFX_RectF m_rtClient;
- CFX_RectF m_rtThumb;
- CFX_RectF m_rtMinBtn;
- CFX_RectF m_rtMaxBtn;
- CFX_RectF m_rtMinTrack;
- CFX_RectF m_rtMaxTrack;
+ CFX_RectF m_ClientRect;
+ CFX_RectF m_ThumbRect;
+ CFX_RectF m_MinBtnRect;
+ CFX_RectF m_MaxBtnRect;
+ CFX_RectF m_MinTrackRect;
+ CFX_RectF m_MaxTrackRect;
std::unique_ptr<CFX_Timer> m_pTimer;
};
diff --git a/xfa/fwl/cfwl_themebackground.cpp b/xfa/fwl/cfwl_themebackground.cpp
new file mode 100644
index 000000000..87500ac9e
--- /dev/null
+++ b/xfa/fwl/cfwl_themebackground.cpp
@@ -0,0 +1,14 @@
+// Copyright 2021 The PDFium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/fwl/cfwl_themebackground.h"
+
+CFWL_ThemeBackground::CFWL_ThemeBackground(Part iPart,
+ CFWL_Widget* pWidget,
+ CFGAS_GEGraphics* pGraphics)
+ : CFWL_ThemePart(iPart, pWidget), m_pGraphics(pGraphics) {}
+
+CFWL_ThemeBackground::~CFWL_ThemeBackground() = default;
diff --git a/xfa/fwl/cfwl_themebackground.h b/xfa/fwl/cfwl_themebackground.h
index 46df73c8b..704ef4313 100644
--- a/xfa/fwl/cfwl_themebackground.h
+++ b/xfa/fwl/cfwl_themebackground.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,23 +7,29 @@
#ifndef XFA_FWL_CFWL_THEMEBACKGROUND_H_
#define XFA_FWL_CFWL_THEMEBACKGROUND_H_
+#include "core/fxcrt/fx_memory.h"
#include "core/fxcrt/unowned_ptr.h"
#include "xfa/fwl/cfwl_themepart.h"
-class CXFA_Graphics;
-class CXFA_GEPath;
+class CFGAS_GEGraphics;
+class CFGAS_GEPath;
class CFWL_ThemeBackground final : public CFWL_ThemePart {
public:
- CFWL_ThemeBackground();
- ~CFWL_ThemeBackground();
+ FX_STACK_ALLOCATED();
- UnownedPtr<CXFA_Graphics> m_pGraphics;
- UnownedPtr<CXFA_GEPath> m_pPath;
-};
+ CFWL_ThemeBackground(Part iPart,
+ CFWL_Widget* pWidget,
+ CFGAS_GEGraphics* pGraphics);
+ ~CFWL_ThemeBackground();
-inline CFWL_ThemeBackground::CFWL_ThemeBackground() = default;
+ CFGAS_GEGraphics* GetGraphics() const { return m_pGraphics; }
+ const CFGAS_GEPath* GetPath() const { return m_pPath; }
+ void SetPath(const CFGAS_GEPath* pPath) { m_pPath = pPath; }
-inline CFWL_ThemeBackground::~CFWL_ThemeBackground() = default;
+ private:
+ UnownedPtr<const CFGAS_GEPath> m_pPath;
+ UnownedPtr<CFGAS_GEGraphics> const m_pGraphics;
+};
#endif // XFA_FWL_CFWL_THEMEBACKGROUND_H_
diff --git a/xfa/fwl/cfwl_themepart.cpp b/xfa/fwl/cfwl_themepart.cpp
index 831e4945b..7294a1aa9 100644
--- a/xfa/fwl/cfwl_themepart.cpp
+++ b/xfa/fwl/cfwl_themepart.cpp
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,10 +6,17 @@
#include "xfa/fwl/cfwl_themepart.h"
-CFWL_ThemePart::CFWL_ThemePart()
- : m_pWidget(nullptr),
- m_iPart(CFWL_Part::None),
- m_dwStates(CFWL_PartState_Normal),
- m_bMaximize(false),
- m_bStaticBackground(false),
- m_pRtData(nullptr) {}
+CFWL_ThemePart::CFWL_ThemePart(Part iPart, CFWL_Widget* pWidget)
+ : m_iPart(iPart), m_pWidget(pWidget) {}
+
+CFWL_ThemePart::~CFWL_ThemePart() = default;
+
+FWLTHEME_STATE CFWL_ThemePart::GetThemeState() const {
+ if (m_dwStates & CFWL_PartState::kDisabled)
+ return FWLTHEME_STATE::kDisable;
+ if (m_dwStates & CFWL_PartState::kPressed)
+ return FWLTHEME_STATE::kPressed;
+ if (m_dwStates & CFWL_PartState::kHovered)
+ return FWLTHEME_STATE::kHover;
+ return FWLTHEME_STATE::kNormal;
+}
diff --git a/xfa/fwl/cfwl_themepart.h b/xfa/fwl/cfwl_themepart.h
index 46be2050d..25f8a7f57 100644
--- a/xfa/fwl/cfwl_themepart.h
+++ b/xfa/fwl/cfwl_themepart.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,87 +7,100 @@
#ifndef XFA_FWL_CFWL_THEMEPART_H_
#define XFA_FWL_CFWL_THEMEPART_H_
+#include <stdint.h>
+
#include "core/fxcrt/fx_coordinates.h"
-#include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/fx_memory.h"
+#include "core/fxcrt/mask.h"
+#include "core/fxcrt/unowned_ptr.h"
+#include "xfa/fwl/theme/cfwl_utils.h"
-enum class CFWL_Part {
- None = 0,
+class CFWL_Widget;
- BackArrow,
- Background,
- Border,
- Caption,
- Check,
- CheckBox,
- CloseBox,
- CombTextLine,
- DateInBK,
- DateInCircle,
- DatesIn,
- DatesOut,
- DownButton,
- DropDownButton,
- ForeArrow,
- HSeparator,
- HeadText,
- Header,
- Icon,
- Image,
- LBtn,
- ListItem,
- LowerTrack,
- MinimizeBox,
- MaximizeBox,
- NarrowCaption,
- RBtn,
- Thumb,
- ThumbBackArrow,
- ThumbForeArrow,
- ThumbLowerTrack,
- ThumbThumb,
- ThumbUpperTrack,
- Today,
- TodayCircle,
- UpButton,
- UpperTrack,
- VSeparator,
- Week,
- WeekNum,
- WeekNumSep
+enum class CFWL_PartState : uint16_t {
+ kNormal = 0,
+ kChecked = 1 << 1,
+ kDefault = 1 << 2,
+ kDisabled = 1 << 3,
+ kFlagged = 1 << 4,
+ kFocused = 1 << 5,
+ kHightLight = 1 << 6,
+ kHovered = 1 << 7,
+ kNeutral = 1 << 9,
+ kPressed = 1 << 10,
+ kReadOnly = 1 << 11,
+ kLSelected = 1 << 12,
+ kRSelected = 1 << 13,
+ kSelected = 1 << 14
};
-enum CFWL_PartState {
- CFWL_PartState_Normal = 0,
+class CFWL_ThemePart {
+ public:
+ enum class Part : uint8_t {
+ kNone = 0,
- CFWL_PartState_Checked = 1 << 1,
- CFWL_PartState_Default = 1 << 2,
- CFWL_PartState_Disabled = 1 << 3,
- CFWL_PartState_Flagged = 1 << 4,
- CFWL_PartState_Focused = 1 << 5,
- CFWL_PartState_HightLight = 1 << 6,
- CFWL_PartState_Hovered = 1 << 7,
- CFWL_PartState_Neutral = 1 << 9,
- CFWL_PartState_Pressed = 1 << 10,
- CFWL_PartState_ReadOnly = 1 << 11,
- CFWL_PartState_LSelected = 1 << 12,
- CFWL_PartState_RSelected = 1 << 13,
- CFWL_PartState_Selected = 1 << 14
-};
+ kBackArrow,
+ kBackground,
+ kBorder,
+ kCaption,
+ kCheck,
+ kCheckBox,
+ kCloseBox,
+ kCombTextLine,
+ kDateInBK,
+ kDateInCircle,
+ kDatesIn,
+ kDatesOut,
+ kDownButton,
+ kDropDownButton,
+ kForeArrow,
+ kHSeparator,
+ kHeadText,
+ kHeader,
+ kIcon,
+ kImage,
+ kLBtn,
+ kListItem,
+ kLowerTrack,
+ kMinimizeBox,
+ kMaximizeBox,
+ kNarrowCaption,
+ kRBtn,
+ kThumb,
+ kThumbBackArrow,
+ kThumbForeArrow,
+ kThumbLowerTrack,
+ kThumbThumb,
+ kThumbUpperTrack,
+ kToday,
+ kTodayCircle,
+ kUpButton,
+ kUpperTrack,
+ kVSeparator,
+ kWeek,
+ kWeekNum,
+ kWeekNumSep
+ };
-class CFWL_Widget;
+ FX_STACK_ALLOCATED();
-class CFWL_ThemePart {
- public:
- CFWL_ThemePart();
+ CFWL_ThemePart(Part iPart, CFWL_Widget* pWidget);
+ ~CFWL_ThemePart();
+
+ Part GetPart() const { return m_iPart; }
+ CFWL_Widget* GetWidget() const { return m_pWidget; }
+ FWLTHEME_STATE GetThemeState() const;
CFX_Matrix m_matrix;
- CFX_RectF m_rtPart;
- CFWL_Widget* m_pWidget;
- CFWL_Part m_iPart;
- uint32_t m_dwStates;
- bool m_bMaximize;
- bool m_bStaticBackground;
- CFX_RectF* m_pRtData;
+ CFX_RectF m_PartRect;
+ UnownedPtr<const CFX_RectF> m_pRtData;
+ Mask<CFWL_PartState> m_dwStates = CFWL_PartState::kNormal;
+ bool m_bMaximize = false;
+ bool m_bStaticBackground = false;
+
+ private:
+ const Part m_iPart;
+ UnownedPtr<CFWL_Widget> const m_pWidget;
};
#endif // XFA_FWL_CFWL_THEMEPART_H_
diff --git a/xfa/fwl/cfwl_themetext.cpp b/xfa/fwl/cfwl_themetext.cpp
new file mode 100644
index 000000000..c228c9348
--- /dev/null
+++ b/xfa/fwl/cfwl_themetext.cpp
@@ -0,0 +1,14 @@
+// Copyright 2021 The PDFium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/fwl/cfwl_themetext.h"
+
+CFWL_ThemeText::CFWL_ThemeText(Part iPart,
+ CFWL_Widget* pWidget,
+ CFGAS_GEGraphics* pGraphics)
+ : CFWL_ThemePart(iPart, pWidget), m_pGraphics(pGraphics) {}
+
+CFWL_ThemeText::~CFWL_ThemeText() = default;
diff --git a/xfa/fwl/cfwl_themetext.h b/xfa/fwl/cfwl_themetext.h
index f0cfaa7de..71f8d8d0a 100644
--- a/xfa/fwl/cfwl_themetext.h
+++ b/xfa/fwl/cfwl_themetext.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,18 +7,29 @@
#ifndef XFA_FWL_CFWL_THEMETEXT_H_
#define XFA_FWL_CFWL_THEMETEXT_H_
-#include "core/fxcrt/fx_string.h"
-#include "core/fxcrt/fx_system.h"
+#include "core/fxcrt/fx_memory.h"
+#include "core/fxcrt/unowned_ptr.h"
+#include "core/fxcrt/widestring.h"
+#include "xfa/fde/cfde_data.h"
#include "xfa/fwl/cfwl_themepart.h"
+class CFGAS_GEGraphics;
+
class CFWL_ThemeText final : public CFWL_ThemePart {
public:
- CFWL_ThemeText() = default;
+ FX_STACK_ALLOCATED();
+
+ CFWL_ThemeText(Part iPart, CFWL_Widget* pWidget, CFGAS_GEGraphics* pGraphics);
+ ~CFWL_ThemeText();
+
+ CFGAS_GEGraphics* GetGraphics() const { return m_pGraphics; }
FDE_TextAlignment m_iTTOAlign = FDE_TextAlignment::kTopLeft;
- CXFA_Graphics* m_pGraphics = nullptr;
- WideString m_wsText;
FDE_TextStyle m_dwTTOStyles;
+ WideString m_wsText;
+
+ private:
+ UnownedPtr<CFGAS_GEGraphics> const m_pGraphics;
};
#endif // XFA_FWL_CFWL_THEMETEXT_H_
diff --git a/xfa/fwl/cfwl_widget.cpp b/xfa/fwl/cfwl_widget.cpp
index 39b706b88..61d12f215 100644
--- a/xfa/fwl/cfwl_widget.cpp
+++ b/xfa/fwl/cfwl_widget.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,7 +10,8 @@
#include <utility>
#include <vector>
-#include "third_party/base/stl_util.h"
+#include "third_party/base/check.h"
+#include "v8/include/cppgc/visitor.h"
#include "xfa/fde/cfde_textout.h"
#include "xfa/fwl/cfwl_app.h"
#include "xfa/fwl/cfwl_combobox.h"
@@ -28,28 +29,40 @@
#include "xfa/fwl/cfwl_widgetmgr.h"
#include "xfa/fwl/ifwl_themeprovider.h"
-#define FWL_WGT_CalcHeight 2048
-#define FWL_WGT_CalcWidth 2048
-#define FWL_WGT_CalcMultiLineDefWidth 120.0f
+namespace {
-CFWL_Widget::CFWL_Widget(const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
+constexpr float kCalcHeight = 2048.0f;
+constexpr float kCalcWidth = 2048.0f;
+constexpr float kCalcMultiLineDefWidth = 120.0f;
+
+} // namespace
+
+CFWL_Widget::CFWL_Widget(CFWL_App* app,
+ const Properties& properties,
CFWL_Widget* pOuter)
- : m_pOwnerApp(app),
+ : m_Properties(properties),
+ m_pFWLApp(app),
m_pWidgetMgr(app->GetWidgetMgr()),
- m_pProperties(std::move(properties)),
m_pOuter(pOuter) {
- ASSERT(m_pWidgetMgr);
- ASSERT(m_pProperties);
- m_pWidgetMgr->InsertWidget(m_pProperties->m_pParent, this);
+ m_pWidgetMgr->InsertWidget(m_pOuter, this);
}
-CFWL_Widget::~CFWL_Widget() {
+CFWL_Widget::~CFWL_Widget() = default;
+
+void CFWL_Widget::PreFinalize() {
CHECK(!IsLocked()); // Prefer hard stop to UaF.
NotifyDriver();
m_pWidgetMgr->RemoveWidget(this);
}
+void CFWL_Widget::Trace(cppgc::Visitor* visitor) const {
+ visitor->Trace(m_pAdapterIface);
+ visitor->Trace(m_pFWLApp);
+ visitor->Trace(m_pWidgetMgr);
+ visitor->Trace(m_pDelegate);
+ visitor->Trace(m_pOuter);
+}
+
bool CFWL_Widget::IsForm() const {
return false;
}
@@ -59,7 +72,7 @@ CFX_RectF CFWL_Widget::GetAutosizedWidgetRect() {
}
CFX_RectF CFWL_Widget::GetWidgetRect() {
- return m_pProperties->m_rtWidget;
+ return m_WidgetRect;
}
void CFWL_Widget::InflateWidgetRect(CFX_RectF& rect) {
@@ -71,35 +84,23 @@ void CFWL_Widget::InflateWidgetRect(CFX_RectF& rect) {
}
void CFWL_Widget::SetWidgetRect(const CFX_RectF& rect) {
- m_pProperties->m_rtWidget = rect;
+ m_WidgetRect = rect;
}
CFX_RectF CFWL_Widget::GetClientRect() {
return GetEdgeRect();
}
-void CFWL_Widget::SetParent(CFWL_Widget* pParent) {
- m_pProperties->m_pParent = pParent;
- m_pWidgetMgr->SetParent(pParent, this);
-}
-
void CFWL_Widget::ModifyStyles(uint32_t dwStylesAdded,
uint32_t dwStylesRemoved) {
- m_pProperties->m_dwStyles =
- (m_pProperties->m_dwStyles & ~dwStylesRemoved) | dwStylesAdded;
+ m_Properties.m_dwStyles &= ~dwStylesRemoved;
+ m_Properties.m_dwStyles |= dwStylesAdded;
}
-uint32_t CFWL_Widget::GetStylesEx() const {
- return m_pProperties->m_dwStyleExes;
-}
-uint32_t CFWL_Widget::GetStates() const {
- return m_pProperties->m_dwStates;
-}
-
-void CFWL_Widget::ModifyStylesEx(uint32_t dwStylesExAdded,
- uint32_t dwStylesExRemoved) {
- m_pProperties->m_dwStyleExes =
- (m_pProperties->m_dwStyleExes & ~dwStylesExRemoved) | dwStylesExAdded;
+void CFWL_Widget::ModifyStyleExts(uint32_t dwStyleExtsAdded,
+ uint32_t dwStyleExtsRemoved) {
+ m_Properties.m_dwStyleExts &= ~dwStyleExtsRemoved;
+ m_Properties.m_dwStyleExts |= dwStyleExtsAdded;
}
static void NotifyHideChildWidget(CFWL_WidgetMgr* widgetMgr,
@@ -114,25 +115,24 @@ static void NotifyHideChildWidget(CFWL_WidgetMgr* widgetMgr,
}
void CFWL_Widget::SetStates(uint32_t dwStates) {
- m_pProperties->m_dwStates |= dwStates;
+ m_Properties.m_dwStates |= dwStates;
if (IsVisible())
return;
- CFWL_NoteDriver* noteDriver = GetOwnerApp()->GetNoteDriver();
+ CFWL_NoteDriver* noteDriver = GetFWLApp()->GetNoteDriver();
noteDriver->NotifyTargetHide(this);
- CFWL_WidgetMgr* widgetMgr = GetOwnerApp()->GetWidgetMgr();
+ CFWL_WidgetMgr* widgetMgr = GetFWLApp()->GetWidgetMgr();
CFWL_Widget* child = widgetMgr->GetFirstChildWidget(this);
while (child) {
noteDriver->NotifyTargetHide(child);
NotifyHideChildWidget(widgetMgr, child, noteDriver);
child = widgetMgr->GetNextSiblingWidget(child);
}
- return;
}
void CFWL_Widget::RemoveStates(uint32_t dwStates) {
- m_pProperties->m_dwStates &= ~dwStates;
+ m_Properties.m_dwStates &= ~dwStates;
}
FWL_WidgetHit CFWL_Widget::HitTest(const CFX_PointF& point) {
@@ -172,33 +172,33 @@ CFX_Matrix CFWL_Widget::GetMatrix() const {
return matrix;
}
-void CFWL_Widget::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
- m_pProperties->m_pThemeProvider = pThemeProvider;
+IFWL_ThemeProvider* CFWL_Widget::GetThemeProvider() const {
+ return GetFWLApp()->GetThemeProvider();
}
bool CFWL_Widget::IsEnabled() const {
- return (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == 0;
+ return (m_Properties.m_dwStates & FWL_STATE_WGT_Disabled) == 0;
}
bool CFWL_Widget::HasBorder() const {
- return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border);
+ return !!(m_Properties.m_dwStyles & FWL_STYLE_WGT_Border);
}
bool CFWL_Widget::IsVisible() const {
- return !(m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible);
+ return !(m_Properties.m_dwStates & FWL_STATE_WGT_Invisible);
}
bool CFWL_Widget::IsOverLapper() const {
- return (m_pProperties->m_dwStyles & FWL_WGTSTYLE_WindowTypeMask) ==
- FWL_WGTSTYLE_OverLapper;
+ return (m_Properties.m_dwStyles & FWL_STYLE_WGT_WindowTypeMask) ==
+ FWL_STYLE_WGT_OverLapper;
}
bool CFWL_Widget::IsPopup() const {
- return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Popup);
+ return !!(m_Properties.m_dwStyles & FWL_STYLE_WGT_Popup);
}
bool CFWL_Widget::IsChild() const {
- return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Child);
+ return !!(m_Properties.m_dwStyles & FWL_STYLE_WGT_Child);
}
CFWL_Widget* CFWL_Widget::GetOutmost() const {
@@ -209,53 +209,26 @@ CFWL_Widget* CFWL_Widget::GetOutmost() const {
}
CFX_RectF CFWL_Widget::GetEdgeRect() const {
- CFX_RectF rtEdge(0, 0, m_pProperties->m_rtWidget.width,
- m_pProperties->m_rtWidget.height);
+ CFX_RectF rtEdge(0, 0, m_WidgetRect.width, m_WidgetRect.height);
if (HasBorder())
rtEdge.Deflate(GetCXBorderSize(), GetCYBorderSize());
return rtEdge;
}
float CFWL_Widget::GetCXBorderSize() const {
- IFWL_ThemeProvider* theme = GetAvailableTheme();
- return theme ? theme->GetCXBorderSize() : 0.0f;
+ return GetThemeProvider()->GetCXBorderSize();
}
float CFWL_Widget::GetCYBorderSize() const {
- IFWL_ThemeProvider* theme = GetAvailableTheme();
- return theme ? theme->GetCYBorderSize() : 0.0f;
+ return GetThemeProvider()->GetCYBorderSize();
}
CFX_RectF CFWL_Widget::GetRelativeRect() const {
- return CFX_RectF(0, 0, m_pProperties->m_rtWidget.width,
- m_pProperties->m_rtWidget.height);
-}
-
-IFWL_ThemeProvider* CFWL_Widget::GetAvailableTheme() const {
- if (m_pProperties->m_pThemeProvider)
- return m_pProperties->m_pThemeProvider.Get();
-
- const CFWL_Widget* pUp = this;
- do {
- pUp = pUp->IsPopup() ? m_pWidgetMgr->GetOwnerWidget(pUp)
- : m_pWidgetMgr->GetParentWidget(pUp);
- if (pUp) {
- IFWL_ThemeProvider* pRet = pUp->GetThemeProvider();
- if (pRet)
- return pRet;
- }
- } while (pUp);
- return nullptr;
+ return CFX_RectF(0, 0, m_WidgetRect.width, m_WidgetRect.height);
}
-CFX_SizeF CFWL_Widget::CalcTextSize(const WideString& wsText,
- IFWL_ThemeProvider* pTheme,
- bool bMultiLine) {
- if (!pTheme)
- return CFX_SizeF();
-
- CFWL_ThemeText calPart;
- calPart.m_pWidget = this;
+CFX_SizeF CFWL_Widget::CalcTextSize(const WideString& wsText, bool bMultiLine) {
+ CFWL_ThemeText calPart(CFWL_ThemePart::Part::kNone, this, nullptr);
calPart.m_wsText = wsText;
if (bMultiLine)
calPart.m_dwTTOStyles.line_wrap_ = true;
@@ -263,37 +236,30 @@ CFX_SizeF CFWL_Widget::CalcTextSize(const WideString& wsText,
calPart.m_dwTTOStyles.single_line_ = true;
calPart.m_iTTOAlign = FDE_TextAlignment::kTopLeft;
- float fWidth = bMultiLine ? FWL_WGT_CalcMultiLineDefWidth : FWL_WGT_CalcWidth;
- CFX_RectF rect(0, 0, fWidth, FWL_WGT_CalcHeight);
- pTheme->CalcTextRect(calPart, &rect);
+ float fWidth = bMultiLine ? kCalcMultiLineDefWidth : kCalcWidth;
+ CFX_RectF rect(0, 0, fWidth, kCalcHeight);
+ GetThemeProvider()->CalcTextRect(calPart, &rect);
return CFX_SizeF(rect.width, rect.height);
}
void CFWL_Widget::CalcTextRect(const WideString& wsText,
- IFWL_ThemeProvider* pTheme,
const FDE_TextStyle& dwTTOStyles,
FDE_TextAlignment iTTOAlign,
CFX_RectF* pRect) {
- CFWL_ThemeText calPart;
- calPart.m_pWidget = this;
+ CFWL_ThemeText calPart(CFWL_ThemePart::Part::kNone, this, nullptr);
calPart.m_wsText = wsText;
calPart.m_dwTTOStyles = dwTTOStyles;
calPart.m_iTTOAlign = iTTOAlign;
- pTheme->CalcTextRect(calPart, pRect);
+ GetThemeProvider()->CalcTextRect(calPart, pRect);
}
void CFWL_Widget::SetGrab(bool bSet) {
- CFWL_NoteDriver* pDriver = GetOwnerApp()->GetNoteDriver();
- pDriver->SetGrab(this, bSet);
-}
-
-void CFWL_Widget::RegisterEventTarget(CFWL_Widget* pEventSource) {
- CFWL_NoteDriver* pNoteDriver = GetOwnerApp()->GetNoteDriver();
- pNoteDriver->RegisterEventTarget(this, pEventSource);
+ CFWL_NoteDriver* pDriver = GetFWLApp()->GetNoteDriver();
+ pDriver->SetGrab(bSet ? this : nullptr);
}
void CFWL_Widget::UnregisterEventTarget() {
- CFWL_NoteDriver* pNoteDriver = GetOwnerApp()->GetNoteDriver();
+ CFWL_NoteDriver* pNoteDriver = GetFWLApp()->GetNoteDriver();
pNoteDriver->UnregisterEventTarget(this);
}
@@ -302,7 +268,7 @@ void CFWL_Widget::DispatchEvent(CFWL_Event* pEvent) {
m_pOuter->GetDelegate()->OnProcessEvent(pEvent);
return;
}
- CFWL_NoteDriver* pNoteDriver = GetOwnerApp()->GetNoteDriver();
+ CFWL_NoteDriver* pNoteDriver = GetFWLApp()->GetNoteDriver();
pNoteDriver->SendEvent(pEvent);
}
@@ -310,35 +276,26 @@ void CFWL_Widget::RepaintRect(const CFX_RectF& pRect) {
m_pWidgetMgr->RepaintWidget(this, pRect);
}
-void CFWL_Widget::DrawBackground(CXFA_Graphics* pGraphics,
- CFWL_Part iPartBk,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix) {
- CFWL_ThemeBackground param;
- param.m_pWidget = this;
- param.m_iPart = iPartBk;
- param.m_pGraphics = pGraphics;
- if (pMatrix)
- param.m_matrix = *pMatrix;
- param.m_rtPart = GetRelativeRect();
- pTheme->DrawBackground(param);
+void CFWL_Widget::DrawBackground(CFGAS_GEGraphics* pGraphics,
+ CFWL_ThemePart::Part iPartBk,
+ const CFX_Matrix& mtMatrix) {
+ CFWL_ThemeBackground param(iPartBk, this, pGraphics);
+ param.m_matrix = mtMatrix;
+ param.m_PartRect = GetRelativeRect();
+ GetThemeProvider()->DrawBackground(param);
}
-void CFWL_Widget::DrawBorder(CXFA_Graphics* pGraphics,
- CFWL_Part iPartBorder,
- IFWL_ThemeProvider* pTheme,
+void CFWL_Widget::DrawBorder(CFGAS_GEGraphics* pGraphics,
+ CFWL_ThemePart::Part iPartBorder,
const CFX_Matrix& matrix) {
- CFWL_ThemeBackground param;
- param.m_pWidget = this;
- param.m_iPart = iPartBorder;
- param.m_pGraphics = pGraphics;
+ CFWL_ThemeBackground param(iPartBorder, this, pGraphics);
param.m_matrix = matrix;
- param.m_rtPart = GetRelativeRect();
- pTheme->DrawBackground(param);
+ param.m_PartRect = GetRelativeRect();
+ GetThemeProvider()->DrawBackground(param);
}
void CFWL_Widget::NotifyDriver() {
- CFWL_NoteDriver* pDriver = GetOwnerApp()->GetNoteDriver();
+ CFWL_NoteDriver* pDriver = GetFWLApp()->GetNoteDriver();
pDriver->NotifyTargetDestroy(this);
}
@@ -346,10 +303,8 @@ CFX_SizeF CFWL_Widget::GetOffsetFromParent(CFWL_Widget* pParent) {
if (pParent == this)
return CFX_SizeF();
- CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr();
- CFX_SizeF szRet(m_pProperties->m_rtWidget.left,
- m_pProperties->m_rtWidget.top);
-
+ CFX_SizeF szRet(m_WidgetRect.left, m_WidgetRect.top);
+ CFWL_WidgetMgr* pWidgetMgr = GetFWLApp()->GetWidgetMgr();
CFWL_Widget* pDstWidget = GetParent();
while (pDstWidget && pDstWidget != pParent) {
CFX_RectF rtDst = pDstWidget->GetWidgetRect();
@@ -375,10 +330,9 @@ void CFWL_Widget::OnProcessMessage(CFWL_Message* pMessage) {
return;
switch (pMessage->GetType()) {
- case CFWL_Message::Type::Mouse: {
+ case CFWL_Message::Type::kMouse: {
CFWL_MessageMouse* pMsgMouse = static_cast<CFWL_MessageMouse*>(pMessage);
- CFWL_EventMouse evt(pWidget, pWidget);
- evt.m_dwCmd = pMsgMouse->m_dwCmd;
+ CFWL_EventMouse evt(pWidget, pWidget, pMsgMouse->m_dwCmd);
pWidget->DispatchEvent(&evt);
break;
}
@@ -389,9 +343,6 @@ void CFWL_Widget::OnProcessMessage(CFWL_Message* pMessage) {
void CFWL_Widget::OnProcessEvent(CFWL_Event* pEvent) {}
-void CFWL_Widget::OnDrawWidget(CXFA_Graphics* pGraphics,
- const CFX_Matrix& matrix) {}
-
CFWL_Widget::ScopedUpdateLock::ScopedUpdateLock(CFWL_Widget* widget)
: widget_(widget) {
widget_->LockUpdate();
diff --git a/xfa/fwl/cfwl_widget.h b/xfa/fwl/cfwl_widget.h
index a8112e859..8e61c808f 100644
--- a/xfa/fwl/cfwl_widget.h
+++ b/xfa/fwl/cfwl_widget.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,27 +7,42 @@
#ifndef XFA_FWL_CFWL_WIDGET_H_
#define XFA_FWL_CFWL_WIDGET_H_
-#include <memory>
+#include <stdint.h>
#include "core/fxcrt/fx_coordinates.h"
-#include "core/fxcrt/fx_system.h"
-#include "core/fxcrt/observed_ptr.h"
#include "core/fxcrt/unowned_ptr.h"
+#include "core/fxcrt/widestring.h"
+#include "core/fxge/dib/fx_dib.h"
+#include "fxjs/gc/heap.h"
+#include "v8/include/cppgc/garbage-collected.h"
+#include "v8/include/cppgc/macros.h"
+#include "v8/include/cppgc/member.h"
+#include "v8/include/cppgc/prefinalizer.h"
#include "xfa/fde/cfde_data.h"
#include "xfa/fwl/cfwl_themepart.h"
#include "xfa/fwl/cfwl_widgetmgr.h"
-#include "xfa/fwl/cfwl_widgetproperties.h"
#include "xfa/fwl/fwl_widgethit.h"
#include "xfa/fwl/ifwl_widgetdelegate.h"
class CFWL_App;
-class CFWL_AppImp;
class CFWL_Event;
-class CFWL_MessageKey;
class CFWL_Widget;
-class CFWL_WidgetMgr;
class IFWL_ThemeProvider;
+#define FWL_STYLE_WGT_OverLapper 0
+#define FWL_STYLE_WGT_Popup (1L << 0)
+#define FWL_STYLE_WGT_Child (2L << 0)
+#define FWL_STYLE_WGT_WindowTypeMask (3L << 0)
+#define FWL_STYLE_WGT_Border (1L << 2)
+#define FWL_STYLE_WGT_VScroll (1L << 11)
+#define FWL_STYLE_WGT_Group (1L << 22)
+#define FWL_STYLE_WGT_NoBackground (1L << 28)
+
+#define FWL_STATE_WGT_Disabled (1L << 2)
+#define FWL_STATE_WGT_Focused (1L << 4)
+#define FWL_STATE_WGT_Invisible (1L << 5)
+#define FWL_STATE_WGT_MAX 6
+
enum class FWL_Type {
Unknown = 0,
@@ -49,72 +64,80 @@ enum class FWL_Type {
};
// NOTE: CFWL_Widget serves as its own delegate until replaced at runtime.
-class CFWL_Widget : public Observable, public IFWL_WidgetDelegate {
+class CFWL_Widget : public cppgc::GarbageCollected<CFWL_Widget>,
+ public IFWL_WidgetDelegate {
+ CPPGC_USING_PRE_FINALIZER(CFWL_Widget, PreFinalize);
+
public:
- class AdapterIface {
+ class AdapterIface : public cppgc::GarbageCollectedMixin {
public:
- virtual ~AdapterIface() {}
+ virtual ~AdapterIface() = default;
virtual CFX_Matrix GetRotateMatrix() = 0;
virtual void DisplayCaret(bool bVisible, const CFX_RectF* pRtAnchor) = 0;
virtual void GetBorderColorAndThickness(FX_ARGB* cr, float* fWidth) = 0;
};
+ class Properties {
+ public:
+ uint32_t m_dwStyles = FWL_STYLE_WGT_Child; // Mask of FWL_STYLE_*_*.
+ uint32_t m_dwStyleExts = 0; // Mask of FWL_STYLEEXT_*_*.
+ uint32_t m_dwStates = 0; // Mask of FWL_STATE_*_*.
+ };
+
class ScopedUpdateLock {
+ CPPGC_STACK_ALLOCATED(); // Allow raw/unowned pointers.
+
public:
explicit ScopedUpdateLock(CFWL_Widget* widget);
~ScopedUpdateLock();
private:
- UnownedPtr<CFWL_Widget> const widget_;
+ UnownedPtr<CFWL_Widget> const widget_; // Ok, stack-only.
};
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_Widget() override;
+ virtual void PreFinalize();
+ void Trace(cppgc::Visitor* visitor) const override;
+
virtual FWL_Type GetClassID() const = 0;
virtual bool IsForm() const;
virtual CFX_RectF GetAutosizedWidgetRect();
virtual CFX_RectF GetWidgetRect();
virtual CFX_RectF GetClientRect();
- virtual void ModifyStylesEx(uint32_t dwStylesExAdded,
- uint32_t dwStylesExRemoved);
+ virtual void ModifyStyleExts(uint32_t dwStyleExtsAdded,
+ uint32_t dwStyleExtsRemoved);
virtual void SetStates(uint32_t dwStates);
virtual void RemoveStates(uint32_t dwStates);
virtual void Update() = 0;
virtual FWL_WidgetHit HitTest(const CFX_PointF& point);
- virtual void DrawWidget(CXFA_Graphics* pGraphics,
+ virtual void DrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) = 0;
- virtual void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider);
- // IFWL_WidgetDelegate.
+ // IFWL_WidgetDelegate:
void OnProcessMessage(CFWL_Message* pMessage) override;
void OnProcessEvent(CFWL_Event* pEvent) override;
- void OnDrawWidget(CXFA_Graphics* pGraphics,
- const CFX_Matrix& matrix) override;
void InflateWidgetRect(CFX_RectF& rect);
void SetWidgetRect(const CFX_RectF& rect);
- void SetParent(CFWL_Widget* pParent);
-
bool IsVisible() const;
bool IsOverLapper() const;
bool IsPopup() const;
bool IsChild() const;
- CFWL_Widget* GetOwner() { return m_pWidgetMgr->GetOwnerWidget(this); }
+ CFWL_WidgetMgr* GetWidgetMgr() const { return m_pWidgetMgr; }
CFWL_Widget* GetOuter() const { return m_pOuter; }
CFWL_Widget* GetOutmost() const;
void ModifyStyles(uint32_t dwStylesAdded, uint32_t dwStylesRemoved);
- uint32_t GetStylesEx() const;
- uint32_t GetStates() const;
+ uint32_t GetStyleExts() const { return m_Properties.m_dwStyleExts; }
+ uint32_t GetStates() const { return m_Properties.m_dwStates; }
CFX_PointF TransformTo(CFWL_Widget* pWidget, const CFX_PointF& point);
CFX_Matrix GetMatrix() const;
- IFWL_ThemeProvider* GetThemeProvider() const {
- return m_pProperties->m_pThemeProvider.Get();
- }
-
+ IFWL_ThemeProvider* GetThemeProvider() const;
void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; }
IFWL_WidgetDelegate* GetDelegate() {
return m_pDelegate ? m_pDelegate.Get() : this;
@@ -123,18 +146,16 @@ class CFWL_Widget : public Observable, public IFWL_WidgetDelegate {
return m_pDelegate ? m_pDelegate.Get() : this;
}
- const CFWL_App* GetOwnerApp() const { return m_pOwnerApp.Get(); }
- uint32_t GetEventKey() const { return m_nEventKey; }
- void SetEventKey(uint32_t key) { m_nEventKey = key; }
+ CFWL_App* GetFWLApp() const { return m_pFWLApp; }
+ uint64_t GetEventKey() const { return m_nEventKey; }
+ void SetEventKey(uint64_t key) { m_nEventKey = key; }
AdapterIface* GetAdapterIface() const { return m_pAdapterIface; }
void SetAdapterIface(AdapterIface* pItem) { m_pAdapterIface = pItem; }
void RepaintRect(const CFX_RectF& pRect);
protected:
- CFWL_Widget(const CFWL_App* app,
- std::unique_ptr<CFWL_WidgetProperties> properties,
- CFWL_Widget* pOuter);
+ CFWL_Widget(CFWL_App* app, const Properties& properties, CFWL_Widget* pOuter);
bool IsEnabled() const;
bool IsLocked() const { return m_iLock > 0; }
@@ -143,29 +164,20 @@ class CFWL_Widget : public Observable, public IFWL_WidgetDelegate {
float GetCXBorderSize() const;
float GetCYBorderSize() const;
CFX_RectF GetRelativeRect() const;
- IFWL_ThemeProvider* GetAvailableTheme() const;
- CFX_SizeF CalcTextSize(const WideString& wsText,
- IFWL_ThemeProvider* pTheme,
- bool bMultiLine);
+ CFX_SizeF CalcTextSize(const WideString& wsText, bool bMultiLine);
void CalcTextRect(const WideString& wsText,
- IFWL_ThemeProvider* pTheme,
const FDE_TextStyle& dwTTOStyles,
FDE_TextAlignment iTTOAlign,
CFX_RectF* pRect);
void SetGrab(bool bSet);
- void RegisterEventTarget(CFWL_Widget* pEventSource);
void UnregisterEventTarget();
void DispatchEvent(CFWL_Event* pEvent);
- void DrawBorder(CXFA_Graphics* pGraphics,
- CFWL_Part iPartBorder,
- IFWL_ThemeProvider* pTheme,
+ void DrawBorder(CFGAS_GEGraphics* pGraphics,
+ CFWL_ThemePart::Part iPartBorder,
const CFX_Matrix& pMatrix);
- UnownedPtr<const CFWL_App> const m_pOwnerApp;
- UnownedPtr<CFWL_WidgetMgr> const m_pWidgetMgr;
- std::unique_ptr<CFWL_WidgetProperties> m_pProperties;
- CFWL_Widget* m_pOuter;
- int32_t m_iLock = 0;
+ Properties m_Properties;
+ CFX_RectF m_WidgetRect;
private:
void LockUpdate() { m_iLock++; }
@@ -176,16 +188,19 @@ class CFWL_Widget : public Observable, public IFWL_WidgetDelegate {
CFWL_Widget* GetParent() const { return m_pWidgetMgr->GetParentWidget(this); }
CFX_SizeF GetOffsetFromParent(CFWL_Widget* pParent);
- void DrawBackground(CXFA_Graphics* pGraphics,
- CFWL_Part iPartBk,
- IFWL_ThemeProvider* pTheme,
- const CFX_Matrix* pMatrix);
+ void DrawBackground(CFGAS_GEGraphics* pGraphics,
+ CFWL_ThemePart::Part iPartBk,
+ const CFX_Matrix& mtMatrix);
void NotifyDriver();
bool IsParent(CFWL_Widget* pParent);
- uint32_t m_nEventKey = 0;
- AdapterIface* m_pAdapterIface = nullptr;
- UnownedPtr<IFWL_WidgetDelegate> m_pDelegate;
+ int32_t m_iLock = 0;
+ uint64_t m_nEventKey = 0;
+ cppgc::Member<AdapterIface> m_pAdapterIface;
+ cppgc::Member<CFWL_App> const m_pFWLApp;
+ cppgc::Member<CFWL_WidgetMgr> const m_pWidgetMgr;
+ cppgc::Member<IFWL_WidgetDelegate> m_pDelegate;
+ cppgc::Member<CFWL_Widget> const m_pOuter;
};
#endif // XFA_FWL_CFWL_WIDGET_H_
diff --git a/xfa/fwl/cfwl_widgetmgr.cpp b/xfa/fwl/cfwl_widgetmgr.cpp
index cb4143096..b5134156c 100644
--- a/xfa/fwl/cfwl_widgetmgr.cpp
+++ b/xfa/fwl/cfwl_widgetmgr.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,133 +6,72 @@
#include "xfa/fwl/cfwl_widgetmgr.h"
-#include <utility>
-
#include "build/build_config.h"
-#include "third_party/base/ptr_util.h"
+#include "fxjs/gc/container_trace.h"
+#include "third_party/base/check.h"
#include "xfa/fwl/cfwl_app.h"
#include "xfa/fwl/cfwl_message.h"
#include "xfa/fwl/cfwl_notedriver.h"
+#include "xfa/fwl/cfwl_pushbutton.h"
-CFWL_WidgetMgr::CFWL_WidgetMgr(AdapterIface* pAdapterNative)
- : m_pAdapter(pAdapterNative) {
- m_mapWidgetItem[nullptr] = pdfium::MakeUnique<Item>();
+CFWL_WidgetMgr::CFWL_WidgetMgr(AdapterIface* pAdapter, CFWL_App* pApp)
+ : m_pAdapter(pAdapter), m_pApp(pApp) {
+ DCHECK(m_pAdapter);
+ m_mapWidgetItem[nullptr] = cppgc::MakeGarbageCollected<Item>(
+ pApp->GetHeap()->GetAllocationHandle(), nullptr);
}
CFWL_WidgetMgr::~CFWL_WidgetMgr() = default;
-// static
-CFWL_Widget* CFWL_WidgetMgr::NextTab(CFWL_Widget* parent, CFWL_Widget* focus) {
- CFWL_WidgetMgr* pMgr = parent->GetOwnerApp()->GetWidgetMgr();
- CFWL_Widget* child = pMgr->GetFirstChildWidget(parent);
- while (child) {
- CFWL_Widget* bRet = NextTab(child, focus);
- if (bRet)
- return bRet;
-
- child = pMgr->GetNextSiblingWidget(child);
- }
- return nullptr;
+void CFWL_WidgetMgr::Trace(cppgc::Visitor* visitor) const {
+ visitor->Trace(m_pApp);
+ visitor->Trace(m_pAdapter);
+ ContainerTrace(visitor, m_mapWidgetItem);
}
CFWL_Widget* CFWL_WidgetMgr::GetParentWidget(const CFWL_Widget* pWidget) const {
Item* pItem = GetWidgetMgrItem(pWidget);
- return pItem && pItem->pParent ? pItem->pParent->pWidget : nullptr;
-}
-
-CFWL_Widget* CFWL_WidgetMgr::GetOwnerWidget(const CFWL_Widget* pWidget) const {
- Item* pItem = GetWidgetMgrItem(pWidget);
- return pItem && pItem->pOwner ? pItem->pOwner->pWidget : nullptr;
-}
-
-CFWL_Widget* CFWL_WidgetMgr::GetFirstSiblingWidget(CFWL_Widget* pWidget) const {
- Item* pItem = GetWidgetMgrItem(pWidget);
if (!pItem)
return nullptr;
- pItem = pItem->pPrevious;
- while (pItem && pItem->pPrevious)
- pItem = pItem->pPrevious;
- return pItem ? pItem->pWidget : nullptr;
+ Item* pParent = pItem->GetParent();
+ return pParent ? pParent->pWidget : nullptr;
}
CFWL_Widget* CFWL_WidgetMgr::GetPriorSiblingWidget(CFWL_Widget* pWidget) const {
Item* pItem = GetWidgetMgrItem(pWidget);
- return pItem && pItem->pPrevious ? pItem->pPrevious->pWidget : nullptr;
+ if (!pItem)
+ return nullptr;
+
+ Item* pSibling = pItem->GetPrevSibling();
+ return pSibling ? pSibling->pWidget : nullptr;
}
CFWL_Widget* CFWL_WidgetMgr::GetNextSiblingWidget(CFWL_Widget* pWidget) const {
Item* pItem = GetWidgetMgrItem(pWidget);
- return pItem && pItem->pNext ? pItem->pNext->pWidget : nullptr;
-}
+ if (!pItem)
+ return nullptr;
-CFWL_Widget* CFWL_WidgetMgr::GetFirstChildWidget(CFWL_Widget* pWidget) const {
- Item* pItem = GetWidgetMgrItem(pWidget);
- return pItem && pItem->pChild ? pItem->pChild->pWidget : nullptr;
+ Item* pSibling = pItem->GetNextSibling();
+ return pSibling ? pSibling->pWidget : nullptr;
}
-CFWL_Widget* CFWL_WidgetMgr::GetLastChildWidget(CFWL_Widget* pWidget) const {
+CFWL_Widget* CFWL_WidgetMgr::GetFirstChildWidget(CFWL_Widget* pWidget) const {
Item* pItem = GetWidgetMgrItem(pWidget);
if (!pItem)
return nullptr;
- pItem = pItem->pChild;
- while (pItem && pItem->pNext)
- pItem = pItem->pNext;
- return pItem ? pItem->pWidget : nullptr;
+ Item* pChild = pItem->GetFirstChild();
+ return pChild ? pChild->pWidget : nullptr;
}
-CFWL_Widget* CFWL_WidgetMgr::GetSystemFormWidget(CFWL_Widget* pWidget) const {
- Item* pItem = GetWidgetMgrItem(pWidget);
- while (pItem) {
- if (IsAbleNative(pItem->pWidget))
- return pItem->pWidget;
- pItem = pItem->pParent;
- }
- return nullptr;
-}
-
-void CFWL_WidgetMgr::AppendWidget(CFWL_Widget* pWidget) {
+CFWL_Widget* CFWL_WidgetMgr::GetLastChildWidget(CFWL_Widget* pWidget) const {
Item* pItem = GetWidgetMgrItem(pWidget);
if (!pItem)
- return;
- if (!pItem->pParent)
- return;
-
- Item* pChild = pItem->pParent->pChild;
- int32_t i = 0;
- while (pChild) {
- if (pChild == pItem) {
- if (pChild->pPrevious)
- pChild->pPrevious->pNext = pChild->pNext;
- if (pChild->pNext)
- pChild->pNext->pPrevious = pChild->pPrevious;
- if (pItem->pParent->pChild == pItem)
- pItem->pParent->pChild = pItem->pNext;
-
- pItem->pNext = nullptr;
- pItem->pPrevious = nullptr;
- break;
- }
- if (!pChild->pNext)
- break;
-
- pChild = pChild->pNext;
- ++i;
- }
-
- pChild = pItem->pParent->pChild;
- if (pChild) {
- while (pChild->pNext)
- pChild = pChild->pNext;
+ return nullptr;
- pChild->pNext = pItem;
- pItem->pPrevious = pChild;
- } else {
- pItem->pParent->pChild = pItem;
- pItem->pPrevious = nullptr;
- }
- pItem->pNext = nullptr;
+ Item* pChild = pItem->GetLastChild();
+ return pChild ? pChild->pWidget : nullptr;
}
void CFWL_WidgetMgr::RepaintWidget(CFWL_Widget* pWidget,
@@ -147,96 +86,32 @@ void CFWL_WidgetMgr::RepaintWidget(CFWL_Widget* pWidget,
pNative = pOuter;
pOuter = pOuter->GetOuter();
}
- AddRedrawCounts(pNative);
m_pAdapter->RepaintWidget(pNative);
}
void CFWL_WidgetMgr::InsertWidget(CFWL_Widget* pParent, CFWL_Widget* pChild) {
Item* pParentItem = GetWidgetMgrItem(pParent);
if (!pParentItem) {
- auto item = pdfium::MakeUnique<Item>(pParent);
- pParentItem = item.get();
- m_mapWidgetItem[pParent] = std::move(item);
-
- pParentItem->pParent = GetWidgetMgrItem(nullptr);
- AppendWidget(pParent);
+ pParentItem = CreateWidgetMgrItem(pParent);
+ GetWidgetMgrRootItem()->AppendLastChild(pParentItem);
}
-
- Item* pItem = GetWidgetMgrItem(pChild);
- if (!pItem) {
- auto item = pdfium::MakeUnique<Item>(pChild);
- pItem = item.get();
- m_mapWidgetItem[pChild] = std::move(item);
- }
- if (pItem->pParent && pItem->pParent != pParentItem) {
- if (pItem->pPrevious)
- pItem->pPrevious->pNext = pItem->pNext;
- if (pItem->pNext)
- pItem->pNext->pPrevious = pItem->pPrevious;
- if (pItem->pParent->pChild == pItem)
- pItem->pParent->pChild = pItem->pNext;
- }
- pItem->pParent = pParentItem;
- AppendWidget(pChild);
+ Item* pChildItem = GetWidgetMgrItem(pChild);
+ if (!pChildItem)
+ pChildItem = CreateWidgetMgrItem(pChild);
+ pParentItem->AppendLastChild(pChildItem);
}
void CFWL_WidgetMgr::RemoveWidget(CFWL_Widget* pWidget) {
+ DCHECK(pWidget);
Item* pItem = GetWidgetMgrItem(pWidget);
if (!pItem)
return;
- if (pItem->pPrevious)
- pItem->pPrevious->pNext = pItem->pNext;
- if (pItem->pNext)
- pItem->pNext->pPrevious = pItem->pPrevious;
- if (pItem->pParent && pItem->pParent->pChild == pItem)
- pItem->pParent->pChild = pItem->pNext;
-
- Item* pChild = pItem->pChild;
- while (pChild) {
- Item* pNext = pChild->pNext;
- RemoveWidget(pChild->pWidget);
- pChild = pNext;
- }
- m_mapWidgetItem.erase(pWidget);
-}
-
-void CFWL_WidgetMgr::SetOwner(CFWL_Widget* pOwner, CFWL_Widget* pOwned) {
- Item* pParentItem = GetWidgetMgrItem(pOwner);
- if (!pParentItem) {
- auto item = pdfium::MakeUnique<Item>(pOwner);
- pParentItem = item.get();
- m_mapWidgetItem[pOwner] = std::move(item);
- pParentItem->pParent = GetWidgetMgrItem(nullptr);
- AppendWidget(pOwner);
- }
+ while (pItem->GetFirstChild())
+ RemoveWidget(pItem->GetFirstChild()->pWidget);
- Item* pItem = GetWidgetMgrItem(pOwned);
- if (!pItem) {
- auto item = pdfium::MakeUnique<Item>(pOwned);
- pItem = item.get();
- m_mapWidgetItem[pOwned] = std::move(item);
- }
- pItem->pOwner = pParentItem;
-}
-void CFWL_WidgetMgr::SetParent(CFWL_Widget* pParent, CFWL_Widget* pChild) {
- Item* pParentItem = GetWidgetMgrItem(pParent);
- Item* pItem = GetWidgetMgrItem(pChild);
- if (!pItem)
- return;
- if (pItem->pParent && pItem->pParent != pParentItem) {
- if (pItem->pPrevious)
- pItem->pPrevious->pNext = pItem->pNext;
- if (pItem->pNext)
- pItem->pNext->pPrevious = pItem->pPrevious;
- if (pItem->pParent->pChild == pItem)
- pItem->pParent->pChild = pItem->pNext;
-
- pItem->pNext = nullptr;
- pItem->pPrevious = nullptr;
- }
- pItem->pParent = pParentItem;
- AppendWidget(pChild);
+ pItem->RemoveSelfIfParented();
+ m_mapWidgetItem.erase(pWidget);
}
CFWL_Widget* CFWL_WidgetMgr::GetWidgetAtPoint(CFWL_Widget* parent,
@@ -260,45 +135,41 @@ CFWL_Widget* CFWL_WidgetMgr::GetWidgetAtPoint(CFWL_Widget* parent,
}
CFWL_Widget* CFWL_WidgetMgr::GetDefaultButton(CFWL_Widget* pParent) const {
- if ((pParent->GetClassID() == FWL_Type::PushButton) &&
- (pParent->GetStates() & (1 << (FWL_WGTSTATE_MAX + 2)))) {
+ if (pParent->GetClassID() == FWL_Type::PushButton &&
+ (pParent->GetStates() & FWL_STATE_PSB_Default)) {
return pParent;
}
- CFWL_Widget* child =
- pParent->GetOwnerApp()->GetWidgetMgr()->GetFirstChildWidget(pParent);
+ CFWL_Widget* child = GetFirstChildWidget(pParent);
while (child) {
- if ((child->GetClassID() == FWL_Type::PushButton) &&
- (child->GetStates() & (1 << (FWL_WGTSTATE_MAX + 2)))) {
+ if (child->GetClassID() == FWL_Type::PushButton &&
+ (child->GetStates() & FWL_STATE_PSB_Default)) {
return child;
}
if (CFWL_Widget* find = GetDefaultButton(child))
return find;
- child = child->GetOwnerApp()->GetWidgetMgr()->GetNextSiblingWidget(child);
+ child = GetNextSiblingWidget(child);
}
return nullptr;
}
-void CFWL_WidgetMgr::AddRedrawCounts(CFWL_Widget* pWidget) {
- GetWidgetMgrItem(pWidget)->iRedrawCounter++;
-}
-
-void CFWL_WidgetMgr::ResetRedrawCounts(CFWL_Widget* pWidget) {
- GetWidgetMgrItem(pWidget)->iRedrawCounter = 0;
+CFWL_WidgetMgr::Item* CFWL_WidgetMgr::GetWidgetMgrRootItem() const {
+ return GetWidgetMgrItem(nullptr);
}
CFWL_WidgetMgr::Item* CFWL_WidgetMgr::GetWidgetMgrItem(
const CFWL_Widget* pWidget) const {
auto it = m_mapWidgetItem.find(pWidget);
- return it != m_mapWidgetItem.end() ? it->second.get() : nullptr;
+ return it != m_mapWidgetItem.end() ? it->second : nullptr;
}
-bool CFWL_WidgetMgr::IsAbleNative(CFWL_Widget* pWidget) const {
- if (!pWidget || !pWidget->IsForm())
- return false;
-
- return pWidget->IsOverLapper() || pWidget->IsPopup();
+CFWL_WidgetMgr::Item* CFWL_WidgetMgr::CreateWidgetMgrItem(
+ CFWL_Widget* pWidget) {
+ auto* pItem = cppgc::MakeGarbageCollected<Item>(
+ m_pApp->GetHeap()->GetAllocationHandle(), pWidget);
+ m_mapWidgetItem[pWidget] = pItem;
+ return pItem;
}
void CFWL_WidgetMgr::GetAdapterPopupPos(CFWL_Widget* pWidget,
@@ -310,40 +181,32 @@ void CFWL_WidgetMgr::GetAdapterPopupPos(CFWL_Widget* pWidget,
pPopupRect);
}
-void CFWL_WidgetMgr::OnProcessMessageToForm(
- std::unique_ptr<CFWL_Message> pMessage) {
+void CFWL_WidgetMgr::OnProcessMessageToForm(CFWL_Message* pMessage) {
CFWL_Widget* pDstWidget = pMessage->GetDstTarget();
if (!pDstWidget)
return;
- CFWL_NoteDriver* pNoteDriver = pDstWidget->GetOwnerApp()->GetNoteDriver();
- pNoteDriver->ProcessMessage(std::move(pMessage));
+ CFWL_NoteDriver* pNoteDriver = pDstWidget->GetFWLApp()->GetNoteDriver();
+ pNoteDriver->ProcessMessage(pMessage);
}
void CFWL_WidgetMgr::OnDrawWidget(CFWL_Widget* pWidget,
- CXFA_Graphics* pGraphics,
+ CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) {
if (!pWidget || !pGraphics)
return;
- CFX_RectF clipCopy(0, 0, pWidget->GetWidgetRect().Size());
- CFX_RectF clipBounds;
-
pWidget->GetDelegate()->OnDrawWidget(pGraphics, matrix);
- clipBounds = pGraphics->GetClipRect();
- clipCopy = clipBounds;
+ CFX_RectF clipBounds = pGraphics->GetClipRect();
if (!clipBounds.IsEmpty())
- DrawChild(pWidget, clipBounds, pGraphics, &matrix);
-
- GetWidgetMgrItem(pWidget)->iRedrawCounter = 0;
- ResetRedrawCounts(pWidget);
+ DrawChildren(pWidget, clipBounds, pGraphics, matrix);
}
-void CFWL_WidgetMgr::DrawChild(CFWL_Widget* parent,
- const CFX_RectF& rtClip,
- CXFA_Graphics* pGraphics,
- const CFX_Matrix* pMatrix) {
+void CFWL_WidgetMgr::DrawChildren(CFWL_Widget* parent,
+ const CFX_RectF& rtClip,
+ CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix) {
if (!parent)
return;
@@ -360,27 +223,21 @@ void CFWL_WidgetMgr::DrawChild(CFWL_Widget* parent,
CFX_Matrix widgetMatrix;
CFX_RectF clipBounds(rtWidget);
- if (pMatrix)
- widgetMatrix.Concat(*pMatrix);
-
+ widgetMatrix.Concat(mtMatrix);
widgetMatrix.TranslatePrepend(rtWidget.left, rtWidget.top);
if (IFWL_WidgetDelegate* pDelegate = child->GetDelegate())
pDelegate->OnDrawWidget(pGraphics, widgetMatrix);
- DrawChild(child, clipBounds, pGraphics, &widgetMatrix);
+ DrawChildren(child, clipBounds, pGraphics, widgetMatrix);
}
}
-CFWL_WidgetMgr::Item::Item() : CFWL_WidgetMgr::Item(nullptr) {}
+CFWL_WidgetMgr::Item::Item(CFWL_Widget* widget) : pWidget(widget) {}
-CFWL_WidgetMgr::Item::Item(CFWL_Widget* widget)
- : pParent(nullptr),
- pOwner(nullptr),
- pChild(nullptr),
- pPrevious(nullptr),
- pNext(nullptr),
- pWidget(widget),
- iRedrawCounter(0) {}
+CFWL_WidgetMgr::Item::~Item() = default;
-CFWL_WidgetMgr::Item::~Item() {}
+void CFWL_WidgetMgr::Item::Trace(cppgc::Visitor* visitor) const {
+ GCedTreeNode<Item>::Trace(visitor);
+ visitor->Trace(pWidget);
+}
diff --git a/xfa/fwl/cfwl_widgetmgr.h b/xfa/fwl/cfwl_widgetmgr.h
index a401e225f..8383f0f44 100644
--- a/xfa/fwl/cfwl_widgetmgr.h
+++ b/xfa/fwl/cfwl_widgetmgr.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,22 +8,24 @@
#define XFA_FWL_CFWL_WIDGETMGR_H_
#include <map>
-#include <memory>
-#include <vector>
-#include "core/fxcrt/fx_system.h"
-#include "xfa/fxgraphics/cxfa_graphics.h"
+#include "core/fxcrt/fx_coordinates.h"
+#include "fxjs/gc/gced_tree_node.h"
+#include "fxjs/gc/heap.h"
+#include "v8/include/cppgc/garbage-collected.h"
+#include "v8/include/cppgc/member.h"
+#include "v8/include/cppgc/visitor.h"
+class CFGAS_GEGraphics;
+class CFWL_App;
class CFWL_Message;
-class CXFA_Graphics;
-class CFX_Matrix;
class CFWL_Widget;
-class CFWL_WidgetMgr {
+class CFWL_WidgetMgr final : public cppgc::GarbageCollected<CFWL_WidgetMgr> {
public:
- class AdapterIface {
+ class AdapterIface : public cppgc::GarbageCollectedMixin {
public:
- virtual ~AdapterIface() {}
+ virtual ~AdapterIface() = default;
virtual void RepaintWidget(CFWL_Widget* pWidget) = 0;
virtual bool GetPopupPos(CFWL_Widget* pWidget,
float fMinHeight,
@@ -32,35 +34,29 @@ class CFWL_WidgetMgr {
CFX_RectF* pPopupRect) = 0;
};
- explicit CFWL_WidgetMgr(AdapterIface* pAdapterNative);
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_WidgetMgr();
- static CFWL_Widget* NextTab(CFWL_Widget* parent, CFWL_Widget* focus);
+ void Trace(cppgc::Visitor* visitor) const;
- void OnProcessMessageToForm(std::unique_ptr<CFWL_Message> pMessage);
+ void OnProcessMessageToForm(CFWL_Message* pMessage);
void OnDrawWidget(CFWL_Widget* pWidget,
- CXFA_Graphics* pGraphics,
+ CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix);
CFWL_Widget* GetParentWidget(const CFWL_Widget* pWidget) const;
- CFWL_Widget* GetOwnerWidget(const CFWL_Widget* pWidget) const;
CFWL_Widget* GetNextSiblingWidget(CFWL_Widget* pWidget) const;
CFWL_Widget* GetFirstChildWidget(CFWL_Widget* pWidget) const;
- CFWL_Widget* GetSystemFormWidget(CFWL_Widget* pWidget) const;
void RepaintWidget(CFWL_Widget* pWidget, const CFX_RectF& pRect);
void InsertWidget(CFWL_Widget* pParent, CFWL_Widget* pChild);
void RemoveWidget(CFWL_Widget* pWidget);
- void SetOwner(CFWL_Widget* pOwner, CFWL_Widget* pOwned);
- void SetParent(CFWL_Widget* pParent, CFWL_Widget* pChild);
CFWL_Widget* GetWidgetAtPoint(CFWL_Widget* pParent,
const CFX_PointF& point) const;
CFWL_Widget* GetDefaultButton(CFWL_Widget* pParent) const;
- void AddRedrawCounts(CFWL_Widget* pWidget);
-
void GetAdapterPopupPos(CFWL_Widget* pWidget,
float fMinHeight,
float fMaxHeight,
@@ -68,38 +64,38 @@ class CFWL_WidgetMgr {
CFX_RectF* pPopupRect) const;
private:
- class Item {
+ class Item final : public GCedTreeNode<Item> {
public:
- Item();
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
+ ~Item() final;
+
+ // GcedTreeNode:
+ void Trace(cppgc::Visitor* visitor) const override;
+
+ cppgc::Member<CFWL_Widget> const pWidget;
+
+ private:
explicit Item(CFWL_Widget* widget);
- ~Item();
-
- Item* pParent;
- Item* pOwner;
- Item* pChild;
- Item* pPrevious;
- Item* pNext;
- CFWL_Widget* const pWidget;
- std::unique_ptr<CXFA_Graphics> pOffscreen;
- int32_t iRedrawCounter;
};
- CFWL_Widget* GetFirstSiblingWidget(CFWL_Widget* pWidget) const;
+ CFWL_WidgetMgr(AdapterIface* pAdapter, CFWL_App* pApp);
+
CFWL_Widget* GetPriorSiblingWidget(CFWL_Widget* pWidget) const;
CFWL_Widget* GetLastChildWidget(CFWL_Widget* pWidget) const;
- Item* GetWidgetMgrItem(const CFWL_Widget* pWidget) const;
- void AppendWidget(CFWL_Widget* pWidget);
- void ResetRedrawCounts(CFWL_Widget* pWidget);
- void DrawChild(CFWL_Widget* pParent,
- const CFX_RectF& rtClip,
- CXFA_Graphics* pGraphics,
- const CFX_Matrix* pMatrix);
+ Item* GetWidgetMgrRootItem() const;
+ Item* GetWidgetMgrItem(const CFWL_Widget* pWidget) const;
+ Item* CreateWidgetMgrItem(CFWL_Widget* pWidget);
- bool IsAbleNative(CFWL_Widget* pWidget) const;
+ void DrawChildren(CFWL_Widget* pParent,
+ const CFX_RectF& rtClip,
+ CFGAS_GEGraphics* pGraphics,
+ const CFX_Matrix& mtMatrix);
- std::map<const CFWL_Widget*, std::unique_ptr<Item>> m_mapWidgetItem;
- UnownedPtr<AdapterIface> const m_pAdapter;
+ cppgc::Member<AdapterIface> const m_pAdapter;
+ cppgc::Member<CFWL_App> const m_pApp;
+ std::map<cppgc::Member<const CFWL_Widget>, cppgc::Member<Item>>
+ m_mapWidgetItem;
};
#endif // XFA_FWL_CFWL_WIDGETMGR_H_
diff --git a/xfa/fwl/cfwl_widgetproperties.cpp b/xfa/fwl/cfwl_widgetproperties.cpp
deleted file mode 100644
index 4dc3cd557..000000000
--- a/xfa/fwl/cfwl_widgetproperties.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fwl/cfwl_widgetproperties.h"
-
-CFWL_WidgetProperties::CFWL_WidgetProperties() = default;
-
-CFWL_WidgetProperties::~CFWL_WidgetProperties() = default;
diff --git a/xfa/fwl/cfwl_widgetproperties.h b/xfa/fwl/cfwl_widgetproperties.h
deleted file mode 100644
index 414883399..000000000
--- a/xfa/fwl/cfwl_widgetproperties.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FWL_CFWL_WIDGETPROPERTIES_H_
-#define XFA_FWL_CFWL_WIDGETPROPERTIES_H_
-
-#include "core/fxcrt/fx_coordinates.h"
-#include "core/fxcrt/fx_system.h"
-#include "core/fxcrt/unowned_ptr.h"
-#include "xfa/fwl/fwl_widgetdef.h"
-
-class CFWL_Widget;
-class IFWL_ThemeProvider;
-
-class CFWL_WidgetProperties {
- public:
- CFWL_WidgetProperties();
- ~CFWL_WidgetProperties();
-
- uint32_t m_dwStyles = FWL_WGTSTYLE_Child;
- uint32_t m_dwStyleExes = 0;
- uint32_t m_dwStates = 0;
- CFX_RectF m_rtWidget;
- UnownedPtr<IFWL_ThemeProvider> m_pThemeProvider;
- CFWL_Widget* m_pParent = nullptr; // Raw, this class owned by node in tree.
-};
-
-#endif // XFA_FWL_CFWL_WIDGETPROPERTIES_H_
diff --git a/xfa/fwl/fwl_widgetdef.h b/xfa/fwl/fwl_widgetdef.h
index 19eb50837..a44a4421c 100644
--- a/xfa/fwl/fwl_widgetdef.h
+++ b/xfa/fwl/fwl_widgetdef.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,22 +7,10 @@
#ifndef XFA_FWL_FWL_WIDGETDEF_H_
#define XFA_FWL_FWL_WIDGETDEF_H_
-#define FWL_WGTSTYLE_OverLapper 0
-#define FWL_WGTSTYLE_Popup (1L << 0)
-#define FWL_WGTSTYLE_Child (2L << 0)
-#define FWL_WGTSTYLE_WindowTypeMask (3L << 0)
-#define FWL_WGTSTYLE_Border (1L << 2)
-#define FWL_WGTSTYLE_VScroll (1L << 11)
-#define FWL_WGTSTYLE_Group (1L << 22)
-#define FWL_WGTSTYLE_NoBackground (1L << 28)
+#include <stdint.h>
-#define FWL_WGTSTATE_Disabled (1L << 2)
-#define FWL_WGTSTATE_Focused (1L << 4)
-#define FWL_WGTSTATE_Invisible (1L << 5)
-#define FWL_WGTSTATE_MAX (6)
-
-// Same as enum FWL_VKEYCODE in public/fpdf_fwlevent.h, but duplicated to keep
-// xfa/fwl standalone.
+// Same as enum FWL_VKEYCODE in public/fpdf_fwlevent.h, but duplicated here
+// to keep xfa/fwl standalone.
enum XFA_FWL_VKEYCODE {
XFA_FWL_VKEY_Back = 0x08,
XFA_FWL_VKEY_Tab = 0x09,
@@ -195,4 +183,16 @@ enum XFA_FWL_VKEYCODE {
XFA_FWL_VKEY_Unknown = 0,
};
+// Derived from FWL_EVENTFLAG in public/fwl_event.h, but not the same
+// values bit-for-bit, duplicated here to keep XFA standalone.
+enum class XFA_FWL_KeyFlag : uint8_t {
+ kCtrl = 1 << 0,
+ kAlt = 1 << 1,
+ kShift = 1 << 2,
+ kCommand = 1 << 3,
+ kLButton = 1 << 4,
+ kRButton = 1 << 5,
+ kMButton = 1 << 6
+};
+
#endif // XFA_FWL_FWL_WIDGETDEF_H_
diff --git a/xfa/fwl/fwl_widgethit.h b/xfa/fwl/fwl_widgethit.h
index ff5a80670..2de257f2f 100644
--- a/xfa/fwl/fwl_widgethit.h
+++ b/xfa/fwl/fwl_widgethit.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
diff --git a/xfa/fwl/ifwl_themeprovider.cpp b/xfa/fwl/ifwl_themeprovider.cpp
new file mode 100644
index 000000000..e98a3f11b
--- /dev/null
+++ b/xfa/fwl/ifwl_themeprovider.cpp
@@ -0,0 +1,89 @@
+// Copyright 2020 The PDFium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#include "xfa/fwl/ifwl_themeprovider.h"
+
+#include "xfa/fwl/cfwl_widget.h"
+#include "xfa/fwl/theme/cfwl_barcodetp.h"
+#include "xfa/fwl/theme/cfwl_carettp.h"
+#include "xfa/fwl/theme/cfwl_checkboxtp.h"
+#include "xfa/fwl/theme/cfwl_comboboxtp.h"
+#include "xfa/fwl/theme/cfwl_datetimepickertp.h"
+#include "xfa/fwl/theme/cfwl_edittp.h"
+#include "xfa/fwl/theme/cfwl_listboxtp.h"
+#include "xfa/fwl/theme/cfwl_monthcalendartp.h"
+#include "xfa/fwl/theme/cfwl_pictureboxtp.h"
+#include "xfa/fwl/theme/cfwl_pushbuttontp.h"
+#include "xfa/fwl/theme/cfwl_scrollbartp.h"
+
+IFWL_ThemeProvider::IFWL_ThemeProvider(cppgc::Heap* pHeap)
+ : m_pCheckBoxTP(cppgc::MakeGarbageCollected<CFWL_CheckBoxTP>(
+ pHeap->GetAllocationHandle())),
+ m_pListBoxTP(cppgc::MakeGarbageCollected<CFWL_ListBoxTP>(
+ pHeap->GetAllocationHandle())),
+ m_pPictureBoxTP(cppgc::MakeGarbageCollected<CFWL_PictureBoxTP>(
+ pHeap->GetAllocationHandle())),
+ m_pSrollBarTP(cppgc::MakeGarbageCollected<CFWL_ScrollBarTP>(
+ pHeap->GetAllocationHandle())),
+ m_pEditTP(cppgc::MakeGarbageCollected<CFWL_EditTP>(
+ pHeap->GetAllocationHandle())),
+ m_pComboBoxTP(cppgc::MakeGarbageCollected<CFWL_ComboBoxTP>(
+ pHeap->GetAllocationHandle())),
+ m_pMonthCalendarTP(cppgc::MakeGarbageCollected<CFWL_MonthCalendarTP>(
+ pHeap->GetAllocationHandle())),
+ m_pDateTimePickerTP(cppgc::MakeGarbageCollected<CFWL_DateTimePickerTP>(
+ pHeap->GetAllocationHandle())),
+ m_pPushButtonTP(cppgc::MakeGarbageCollected<CFWL_PushButtonTP>(
+ pHeap->GetAllocationHandle())),
+ m_pCaretTP(cppgc::MakeGarbageCollected<CFWL_CaretTP>(
+ pHeap->GetAllocationHandle())),
+ m_pBarcodeTP(cppgc::MakeGarbageCollected<CFWL_BarcodeTP>(
+ pHeap->GetAllocationHandle())) {}
+
+IFWL_ThemeProvider::~IFWL_ThemeProvider() = default;
+
+void IFWL_ThemeProvider::Trace(cppgc::Visitor* visitor) const {
+ visitor->Trace(m_pCheckBoxTP);
+ visitor->Trace(m_pListBoxTP);
+ visitor->Trace(m_pPictureBoxTP);
+ visitor->Trace(m_pSrollBarTP);
+ visitor->Trace(m_pEditTP);
+ visitor->Trace(m_pComboBoxTP);
+ visitor->Trace(m_pMonthCalendarTP);
+ visitor->Trace(m_pDateTimePickerTP);
+ visitor->Trace(m_pPushButtonTP);
+ visitor->Trace(m_pCaretTP);
+ visitor->Trace(m_pBarcodeTP);
+}
+
+CFWL_WidgetTP* IFWL_ThemeProvider::GetTheme(const CFWL_Widget* pWidget) const {
+ switch (pWidget->GetClassID()) {
+ case FWL_Type::CheckBox:
+ return m_pCheckBoxTP;
+ case FWL_Type::ListBox:
+ return m_pListBoxTP;
+ case FWL_Type::PictureBox:
+ return m_pPictureBoxTP;
+ case FWL_Type::ScrollBar:
+ return m_pSrollBarTP;
+ case FWL_Type::Edit:
+ return m_pEditTP;
+ case FWL_Type::ComboBox:
+ return m_pComboBoxTP;
+ case FWL_Type::MonthCalendar:
+ return m_pMonthCalendarTP;
+ case FWL_Type::DateTimePicker:
+ return m_pDateTimePickerTP;
+ case FWL_Type::PushButton:
+ return m_pPushButtonTP;
+ case FWL_Type::Caret:
+ return m_pCaretTP;
+ case FWL_Type::Barcode:
+ return m_pBarcodeTP;
+ default:
+ return nullptr;
+ }
+}
diff --git a/xfa/fwl/ifwl_themeprovider.h b/xfa/fwl/ifwl_themeprovider.h
index 5700d34c4..5a78394e6 100644
--- a/xfa/fwl/ifwl_themeprovider.h
+++ b/xfa/fwl/ifwl_themeprovider.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,17 +9,24 @@
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/retain_ptr.h"
-#include "core/fxge/fx_dib.h"
+#include "core/fxge/dib/fx_dib.h"
+#include "fxjs/gc/heap.h"
+#include "v8/include/cppgc/garbage-collected.h"
+#include "v8/include/cppgc/member.h"
class CFGAS_GEFont;
class CFWL_ThemeBackground;
class CFWL_ThemePart;
class CFWL_ThemeText;
class CFWL_Widget;
+class CFWL_WidgetTP;
-class IFWL_ThemeProvider {
+class IFWL_ThemeProvider : public cppgc::GarbageCollectedMixin {
public:
- virtual ~IFWL_ThemeProvider() = default;
+ virtual ~IFWL_ThemeProvider();
+
+ // GarbageCollectedMixin:
+ void Trace(cppgc::Visitor* visitor) const override;
virtual void DrawBackground(const CFWL_ThemeBackground& pParams) = 0;
virtual void DrawText(const CFWL_ThemeText& pParams) = 0;
@@ -29,13 +36,31 @@ class IFWL_ThemeProvider {
virtual float GetCYBorderSize() const = 0;
virtual CFX_RectF GetUIMargin(const CFWL_ThemePart& pThemePart) const = 0;
virtual float GetFontSize(const CFWL_ThemePart& pThemePart) const = 0;
- virtual RetainPtr<CFGAS_GEFont> GetFont(
- const CFWL_ThemePart& pThemePart) const = 0;
+ virtual RetainPtr<CFGAS_GEFont> GetFont(const CFWL_ThemePart& pThemePart) = 0;
+ virtual RetainPtr<CFGAS_GEFont> GetFWLFont() = 0;
virtual float GetLineHeight(const CFWL_ThemePart& pThemePart) const = 0;
virtual float GetScrollBarWidth() const = 0;
virtual FX_COLORREF GetTextColor(const CFWL_ThemePart& pThemePart) const = 0;
virtual CFX_SizeF GetSpaceAboveBelow(
const CFWL_ThemePart& pThemePart) const = 0;
+
+ protected:
+ explicit IFWL_ThemeProvider(cppgc::Heap* pHeap);
+
+ CFWL_WidgetTP* GetTheme(const CFWL_Widget* pWidget) const;
+
+ private:
+ cppgc::Member<CFWL_WidgetTP> m_pCheckBoxTP;
+ cppgc::Member<CFWL_WidgetTP> m_pListBoxTP;
+ cppgc::Member<CFWL_WidgetTP> m_pPictureBoxTP;
+ cppgc::Member<CFWL_WidgetTP> m_pSrollBarTP;
+ cppgc::Member<CFWL_WidgetTP> m_pEditTP;
+ cppgc::Member<CFWL_WidgetTP> m_pComboBoxTP;
+ cppgc::Member<CFWL_WidgetTP> m_pMonthCalendarTP;
+ cppgc::Member<CFWL_WidgetTP> m_pDateTimePickerTP;
+ cppgc::Member<CFWL_WidgetTP> m_pPushButtonTP;
+ cppgc::Member<CFWL_WidgetTP> m_pCaretTP;
+ cppgc::Member<CFWL_WidgetTP> m_pBarcodeTP;
};
#endif // XFA_FWL_IFWL_THEMEPROVIDER_H_
diff --git a/xfa/fwl/ifwl_widgetdelegate.h b/xfa/fwl/ifwl_widgetdelegate.h
index 17b893397..ef0895f5c 100644
--- a/xfa/fwl/ifwl_widgetdelegate.h
+++ b/xfa/fwl/ifwl_widgetdelegate.h
@@ -1,4 +1,4 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
+// Copyright 2016 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,20 +7,20 @@
#ifndef XFA_FWL_IFWL_WIDGETDELEGATE_H_
#define XFA_FWL_IFWL_WIDGETDELEGATE_H_
-#include <stdint.h>
+#include "v8/include/cppgc/garbage-collected.h"
+class CFGAS_GEGraphics;
class CFWL_Event;
class CFWL_Message;
-class CXFA_Graphics;
class CFX_Matrix;
-class IFWL_WidgetDelegate {
+class IFWL_WidgetDelegate : public cppgc::GarbageCollectedMixin {
public:
virtual ~IFWL_WidgetDelegate() = default;
virtual void OnProcessMessage(CFWL_Message* pMessage) = 0;
virtual void OnProcessEvent(CFWL_Event* pEvent) = 0;
- virtual void OnDrawWidget(CXFA_Graphics* pGraphics,
+ virtual void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
const CFX_Matrix& matrix) = 0;
};
diff --git a/xfa/fwl/theme/cfwl_barcodetp.cpp b/xfa/fwl/theme/cfwl_barcodetp.cpp
index 222d00800..60f5154b9 100644
--- a/xfa/fwl/theme/cfwl_barcodetp.cpp
+++ b/xfa/fwl/theme/cfwl_barcodetp.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,17 +10,17 @@
#include "xfa/fwl/cfwl_themebackground.h"
#include "xfa/fwl/cfwl_widget.h"
-CFWL_BarcodeTP::CFWL_BarcodeTP() {}
+CFWL_BarcodeTP::CFWL_BarcodeTP() = default;
-CFWL_BarcodeTP::~CFWL_BarcodeTP() {}
+CFWL_BarcodeTP::~CFWL_BarcodeTP() = default;
void CFWL_BarcodeTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
- switch (pParams.m_iPart) {
- case CFWL_Part::Border:
- DrawBorder(pParams.m_pGraphics.Get(), pParams.m_rtPart, pParams.m_matrix);
+ switch (pParams.GetPart()) {
+ case CFWL_ThemePart::Part::kBorder:
+ DrawBorder(pParams.GetGraphics(), pParams.m_PartRect, pParams.m_matrix);
break;
- case CFWL_Part::Background:
- FillBackground(pParams.m_pGraphics.Get(), pParams.m_rtPart,
+ case CFWL_ThemePart::Part::kBackground:
+ FillBackground(pParams.GetGraphics(), pParams.m_PartRect,
pParams.m_matrix);
break;
default:
diff --git a/xfa/fwl/theme/cfwl_barcodetp.h b/xfa/fwl/theme/cfwl_barcodetp.h
index 8b88fcd03..e35b9cd24 100644
--- a/xfa/fwl/theme/cfwl_barcodetp.h
+++ b/xfa/fwl/theme/cfwl_barcodetp.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,16 +7,20 @@
#ifndef XFA_FWL_THEME_CFWL_BARCODETP_H_
#define XFA_FWL_THEME_CFWL_BARCODETP_H_
+#include "fxjs/gc/heap.h"
#include "xfa/fwl/theme/cfwl_utils.h"
#include "xfa/fwl/theme/cfwl_widgettp.h"
class CFWL_BarcodeTP final : public CFWL_WidgetTP {
public:
- CFWL_BarcodeTP();
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_BarcodeTP() override;
// CFWL_WidgetTP
void DrawBackground(const CFWL_ThemeBackground& pParams) override;
+
+ private:
+ CFWL_BarcodeTP();
};
#endif // XFA_FWL_THEME_CFWL_BARCODETP_H_
diff --git a/xfa/fwl/theme/cfwl_carettp.cpp b/xfa/fwl/theme/cfwl_carettp.cpp
index 8d32a3728..efad7915a 100644
--- a/xfa/fwl/theme/cfwl_carettp.cpp
+++ b/xfa/fwl/theme/cfwl_carettp.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,25 +6,25 @@
#include "xfa/fwl/theme/cfwl_carettp.h"
-#include "core/fxge/render_defines.h"
+#include "xfa/fgas/graphics/cfgas_gecolor.h"
+#include "xfa/fgas/graphics/cfgas_gegraphics.h"
+#include "xfa/fgas/graphics/cfgas_gepath.h"
#include "xfa/fwl/cfwl_caret.h"
#include "xfa/fwl/cfwl_themebackground.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fxgraphics/cxfa_gecolor.h"
-#include "xfa/fxgraphics/cxfa_gepath.h"
CFWL_CaretTP::CFWL_CaretTP() = default;
CFWL_CaretTP::~CFWL_CaretTP() = default;
void CFWL_CaretTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
- switch (pParams.m_iPart) {
- case CFWL_Part::Background: {
- if (!(pParams.m_dwStates & CFWL_PartState_HightLight))
+ switch (pParams.GetPart()) {
+ case CFWL_ThemePart::Part::kBackground: {
+ if (!(pParams.m_dwStates & CFWL_PartState::kHightLight))
return;
- DrawCaretBK(pParams.m_pGraphics.Get(), pParams.m_dwStates,
- pParams.m_rtPart, pParams.m_matrix);
+ DrawCaretBK(pParams.GetGraphics(), pParams.m_dwStates, pParams.m_PartRect,
+ pParams.m_matrix);
break;
}
default:
@@ -32,12 +32,12 @@ void CFWL_CaretTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
}
}
-void CFWL_CaretTP::DrawCaretBK(CXFA_Graphics* pGraphics,
- uint32_t dwStates,
+void CFWL_CaretTP::DrawCaretBK(CFGAS_GEGraphics* pGraphics,
+ Mask<CFWL_PartState> dwStates,
const CFX_RectF& rect,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
+ CFGAS_GEPath path;
path.AddRectangle(rect.left, rect.top, rect.width, rect.height);
- pGraphics->SetFillColor(CXFA_GEColor(ArgbEncode(255, 0, 0, 0)));
- pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
+ pGraphics->SetFillColor(CFGAS_GEColor(ArgbEncode(255, 0, 0, 0)));
+ pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kWinding, matrix);
}
diff --git a/xfa/fwl/theme/cfwl_carettp.h b/xfa/fwl/theme/cfwl_carettp.h
index a0f9dc5c4..e25df0a46 100644
--- a/xfa/fwl/theme/cfwl_carettp.h
+++ b/xfa/fwl/theme/cfwl_carettp.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,19 +7,23 @@
#ifndef XFA_FWL_THEME_CFWL_CARETTP_H_
#define XFA_FWL_THEME_CFWL_CARETTP_H_
+#include "fxjs/gc/heap.h"
+#include "xfa/fwl/cfwl_themepart.h"
#include "xfa/fwl/theme/cfwl_widgettp.h"
class CFWL_CaretTP final : public CFWL_WidgetTP {
public:
- CFWL_CaretTP();
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_CaretTP() override;
// CFWL_WidgetTP
void DrawBackground(const CFWL_ThemeBackground& pParams) override;
private:
- void DrawCaretBK(CXFA_Graphics* pGraphics,
- uint32_t dwStates,
+ CFWL_CaretTP();
+
+ void DrawCaretBK(CFGAS_GEGraphics* pGraphics,
+ Mask<CFWL_PartState> dwStates,
const CFX_RectF& rect,
const CFX_Matrix& matrix);
};
diff --git a/xfa/fwl/theme/cfwl_checkboxtp.cpp b/xfa/fwl/theme/cfwl_checkboxtp.cpp
index 343638972..439d07bab 100644
--- a/xfa/fwl/theme/cfwl_checkboxtp.cpp
+++ b/xfa/fwl/theme/cfwl_checkboxtp.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,16 +6,19 @@
#include "xfa/fwl/theme/cfwl_checkboxtp.h"
-#include "core/fxge/cfx_pathdata.h"
-#include "core/fxge/render_defines.h"
-#include "third_party/base/ptr_util.h"
+#include <math.h>
+
+#include <iterator>
+
+#include "core/fxge/cfx_path.h"
#include "xfa/fde/cfde_textout.h"
+#include "xfa/fgas/graphics/cfgas_gecolor.h"
+#include "xfa/fgas/graphics/cfgas_gegraphics.h"
+#include "xfa/fgas/graphics/cfgas_gepath.h"
#include "xfa/fwl/cfwl_checkbox.h"
#include "xfa/fwl/cfwl_themebackground.h"
#include "xfa/fwl/cfwl_themetext.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fxgraphics/cxfa_gecolor.h"
-#include "xfa/fxgraphics/cxfa_gepath.h"
namespace {
@@ -23,8 +26,8 @@ constexpr int kSignPath = 100;
CFX_PointF ScaleBezierPoint(const CFX_PointF& point) {
CFX_PointF scaled_point(point);
- scaled_point.x *= FX_BEZIER;
- scaled_point.y *= FX_BEZIER;
+ scaled_point.x *= FXSYS_BEZIER;
+ scaled_point.y *= FXSYS_BEZIER;
return scaled_point;
}
@@ -32,206 +35,197 @@ CFX_PointF ScaleBezierPoint(const CFX_PointF& point) {
CFWL_CheckBoxTP::CFWL_CheckBoxTP() = default;
-CFWL_CheckBoxTP::~CFWL_CheckBoxTP() {
- if (m_pCheckPath)
- m_pCheckPath->Clear();
-}
+CFWL_CheckBoxTP::~CFWL_CheckBoxTP() = default;
void CFWL_CheckBoxTP::DrawText(const CFWL_ThemeText& pParams) {
- EnsureTTOInitialized();
- m_pTextOut->SetTextColor(pParams.m_dwStates & CFWL_PartState_Disabled
+ EnsureTTOInitialized(pParams.GetWidget()->GetThemeProvider());
+ m_pTextOut->SetTextColor(pParams.m_dwStates & CFWL_PartState::kDisabled
? FWLTHEME_CAPACITY_TextDisColor
: FWLTHEME_CAPACITY_TextColor);
CFWL_WidgetTP::DrawText(pParams);
}
-void CFWL_CheckBoxTP::DrawSignCheck(CXFA_Graphics* pGraphics,
+void CFWL_CheckBoxTP::DrawSignCheck(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rtSign,
FX_ARGB argbFill,
const CFX_Matrix& matrix) {
- if (!m_pCheckPath)
- InitCheckPath(rtSign.width);
+ EnsureCheckPathInitialized(rtSign.width);
+ DCHECK(m_pCheckPath);
CFX_Matrix mt;
mt.Translate(rtSign.left, rtSign.top);
mt.Concat(matrix);
- pGraphics->SaveGraphState();
- pGraphics->SetFillColor(CXFA_GEColor(argbFill));
- pGraphics->FillPath(m_pCheckPath.get(), FXFILL_WINDING, &mt);
- pGraphics->RestoreGraphState();
+
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ pGraphics->SetFillColor(CFGAS_GEColor(argbFill));
+ pGraphics->FillPath(*m_pCheckPath, CFX_FillRenderOptions::FillType::kWinding,
+ mt);
}
-void CFWL_CheckBoxTP::DrawSignCircle(CXFA_Graphics* pGraphics,
+void CFWL_CheckBoxTP::DrawSignCircle(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rtSign,
FX_ARGB argbFill,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
+ CFGAS_GEPath path;
path.AddEllipse(rtSign);
- pGraphics->SaveGraphState();
- pGraphics->SetFillColor(CXFA_GEColor(argbFill));
- pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
- pGraphics->RestoreGraphState();
+
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ pGraphics->SetFillColor(CFGAS_GEColor(argbFill));
+ pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kWinding, matrix);
}
-void CFWL_CheckBoxTP::DrawSignCross(CXFA_Graphics* pGraphics,
+void CFWL_CheckBoxTP::DrawSignCross(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rtSign,
FX_ARGB argbFill,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
- float fRight = rtSign.right();
- float fBottom = rtSign.bottom();
+ CFGAS_GEPath path;
+ const float fRight = rtSign.right();
+ const float fBottom = rtSign.bottom();
path.AddLine(rtSign.TopLeft(), CFX_PointF(fRight, fBottom));
path.AddLine(CFX_PointF(rtSign.left, fBottom),
CFX_PointF(fRight, rtSign.top));
- pGraphics->SaveGraphState();
- pGraphics->SetStrokeColor(CXFA_GEColor(argbFill));
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ pGraphics->SetStrokeColor(CFGAS_GEColor(argbFill));
pGraphics->SetLineWidth(1.0f);
- pGraphics->StrokePath(&path, &matrix);
- pGraphics->RestoreGraphState();
+ pGraphics->StrokePath(path, matrix);
}
-void CFWL_CheckBoxTP::DrawSignDiamond(CXFA_Graphics* pGraphics,
+void CFWL_CheckBoxTP::DrawSignDiamond(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rtSign,
FX_ARGB argbFill,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
- float fWidth = rtSign.width;
- float fHeight = rtSign.height;
- float fBottom = rtSign.bottom();
+ CFGAS_GEPath path;
+ const float fWidth = rtSign.width;
+ const float fHeight = rtSign.height;
+ const float fBottom = rtSign.bottom();
path.MoveTo(CFX_PointF(rtSign.left + fWidth / 2, rtSign.top));
path.LineTo(CFX_PointF(rtSign.left, rtSign.top + fHeight / 2));
path.LineTo(CFX_PointF(rtSign.left + fWidth / 2, fBottom));
path.LineTo(CFX_PointF(rtSign.right(), rtSign.top + fHeight / 2));
path.LineTo(CFX_PointF(rtSign.left + fWidth / 2, rtSign.top));
- pGraphics->SaveGraphState();
- pGraphics->SetFillColor(CXFA_GEColor(argbFill));
- pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
- pGraphics->RestoreGraphState();
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ pGraphics->SetFillColor(CFGAS_GEColor(argbFill));
+ pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kWinding, matrix);
}
-void CFWL_CheckBoxTP::DrawSignSquare(CXFA_Graphics* pGraphics,
+void CFWL_CheckBoxTP::DrawSignSquare(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rtSign,
FX_ARGB argbFill,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
+ CFGAS_GEPath path;
path.AddRectangle(rtSign.left, rtSign.top, rtSign.width, rtSign.height);
- pGraphics->SaveGraphState();
- pGraphics->SetFillColor(CXFA_GEColor(argbFill));
- pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
- pGraphics->RestoreGraphState();
+
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ pGraphics->SetFillColor(CFGAS_GEColor(argbFill));
+ pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kWinding, matrix);
}
-void CFWL_CheckBoxTP::DrawSignStar(CXFA_Graphics* pGraphics,
+void CFWL_CheckBoxTP::DrawSignStar(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rtSign,
FX_ARGB argbFill,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
+ CFGAS_GEPath path;
float fBottom = rtSign.bottom();
- float fRadius =
- (rtSign.top - fBottom) / (1 + static_cast<float>(cos(FX_PI / 5.0f)));
+ float fRadius = (rtSign.top - fBottom) / (1 + cosf(FXSYS_PI / 5.0f));
CFX_PointF ptCenter((rtSign.left + rtSign.right()) / 2.0f,
(rtSign.top + fBottom) / 2.0f);
CFX_PointF points[5];
- float fAngel = FX_PI / 10.0f;
- for (int32_t i = 0; i < 5; i++) {
- points[i] =
- ptCenter + CFX_PointF(fRadius * static_cast<float>(cos(fAngel)),
- fRadius * static_cast<float>(sin(fAngel)));
- fAngel += FX_PI * 2 / 5.0f;
+ float fAngle = FXSYS_PI / 10.0f;
+ for (auto& point : points) {
+ point =
+ ptCenter + CFX_PointF(fRadius * cosf(fAngle), fRadius * sinf(fAngle));
+ fAngle += FXSYS_PI * 2 / 5.0f;
}
path.MoveTo(points[0]);
- int32_t nNext = 0;
- for (int32_t j = 0; j < 5; j++) {
- nNext += 2;
- if (nNext >= 5)
- nNext -= 5;
-
- path.LineTo(points[nNext]);
+ int next = 0;
+ for (size_t i = 0; i < std::size(points); ++i) {
+ next = (next + 2) % std::size(points);
+ path.LineTo(points[next]);
}
- pGraphics->SaveGraphState();
- pGraphics->SetFillColor(CXFA_GEColor(argbFill));
- pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
- pGraphics->RestoreGraphState();
+
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ pGraphics->SetFillColor(CFGAS_GEColor(argbFill));
+ pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kWinding, matrix);
}
-void CFWL_CheckBoxTP::InitCheckPath(float fCheckLen) {
- if (!m_pCheckPath) {
- m_pCheckPath = pdfium::MakeUnique<CXFA_GEPath>();
-
- float fWidth = kSignPath;
- float fHeight = -kSignPath;
- float fBottom = kSignPath;
- CFX_PointF pt1(fWidth / 15.0f, fBottom + fHeight * 2 / 5.0f);
- CFX_PointF pt2(fWidth / 4.5f, fBottom + fHeight / 16.0f);
- CFX_PointF pt3(fWidth / 3.0f, fBottom);
- CFX_PointF pt4(fWidth * 14 / 15.0f, fBottom + fHeight * 15 / 16.0f);
- CFX_PointF pt5(fWidth / 3.6f, fBottom + fHeight / 3.5f);
- CFX_PointF pt12(fWidth / 7.0f, fBottom + fHeight * 2 / 7.0f);
- CFX_PointF pt21(fWidth / 5.0f, fBottom + fHeight / 5.0f);
- CFX_PointF pt23(fWidth / 4.4f, fBottom + fHeight * 0 / 16.0f);
- CFX_PointF pt32(fWidth / 4.0f, fBottom);
- CFX_PointF pt34(fWidth * (1 / 7.0f + 7 / 15.0f),
- fBottom + fHeight * 4 / 5.0f);
- CFX_PointF pt43(fWidth * (1 / 7.0f + 7 / 15.0f),
- fBottom + fHeight * 4 / 5.0f);
- CFX_PointF pt45(fWidth * 7 / 15.0f, fBottom + fHeight * 8 / 7.0f);
- CFX_PointF pt54(fWidth / 3.4f, fBottom + fHeight / 3.5f);
- CFX_PointF pt51(fWidth / 3.6f, fBottom + fHeight / 4.0f);
- CFX_PointF pt15(fWidth / 3.5f, fBottom + fHeight * 3.5f / 5.0f);
- m_pCheckPath->MoveTo(pt1);
-
- CFX_PointF p1 = ScaleBezierPoint(pt12 - pt1);
- CFX_PointF p2 = ScaleBezierPoint(pt21 - pt2);
- m_pCheckPath->BezierTo(pt1 + p1, pt2 + p2, pt2);
-
- p1 = ScaleBezierPoint(pt23 - pt2);
- p2 = ScaleBezierPoint(pt32 - pt3);
- m_pCheckPath->BezierTo(pt2 + p1, pt3 + p2, pt3);
-
- p1 = ScaleBezierPoint(pt34 - pt3);
- p2 = ScaleBezierPoint(pt43 - pt4);
- m_pCheckPath->BezierTo(pt3 + p1, pt4 + p2, pt4);
-
- p1 = ScaleBezierPoint(pt45 - pt4);
- p2 = ScaleBezierPoint(pt54 - pt5);
- m_pCheckPath->BezierTo(pt4 + p1, pt5 + p2, pt5);
-
- p1 = ScaleBezierPoint(pt51 - pt5);
- p2 = ScaleBezierPoint(pt15 - pt1);
- m_pCheckPath->BezierTo(pt5 + p1, pt1 + p2, pt1);
-
- float fScale = fCheckLen / kSignPath;
- CFX_Matrix mt;
- mt.Scale(fScale, fScale);
-
- m_pCheckPath->TransformBy(mt);
- }
+void CFWL_CheckBoxTP::EnsureCheckPathInitialized(float fCheckLen) {
+ if (m_pCheckPath)
+ return;
+
+ m_pCheckPath = std::make_unique<CFGAS_GEPath>();
+
+ float fWidth = kSignPath;
+ float fHeight = -kSignPath;
+ float fBottom = kSignPath;
+ CFX_PointF pt1(fWidth / 15.0f, fBottom + fHeight * 2 / 5.0f);
+ CFX_PointF pt2(fWidth / 4.5f, fBottom + fHeight / 16.0f);
+ CFX_PointF pt3(fWidth / 3.0f, fBottom);
+ CFX_PointF pt4(fWidth * 14 / 15.0f, fBottom + fHeight * 15 / 16.0f);
+ CFX_PointF pt5(fWidth / 3.6f, fBottom + fHeight / 3.5f);
+ CFX_PointF pt12(fWidth / 7.0f, fBottom + fHeight * 2 / 7.0f);
+ CFX_PointF pt21(fWidth / 5.0f, fBottom + fHeight / 5.0f);
+ CFX_PointF pt23(fWidth / 4.4f, fBottom + fHeight * 0 / 16.0f);
+ CFX_PointF pt32(fWidth / 4.0f, fBottom);
+ CFX_PointF pt34(fWidth * (1 / 7.0f + 7 / 15.0f),
+ fBottom + fHeight * 4 / 5.0f);
+ CFX_PointF pt43(fWidth * (1 / 7.0f + 7 / 15.0f),
+ fBottom + fHeight * 4 / 5.0f);
+ CFX_PointF pt45(fWidth * 7 / 15.0f, fBottom + fHeight * 8 / 7.0f);
+ CFX_PointF pt54(fWidth / 3.4f, fBottom + fHeight / 3.5f);
+ CFX_PointF pt51(fWidth / 3.6f, fBottom + fHeight / 4.0f);
+ CFX_PointF pt15(fWidth / 3.5f, fBottom + fHeight * 3.5f / 5.0f);
+ m_pCheckPath->MoveTo(pt1);
+
+ CFX_PointF p1 = ScaleBezierPoint(pt12 - pt1);
+ CFX_PointF p2 = ScaleBezierPoint(pt21 - pt2);
+ m_pCheckPath->BezierTo(pt1 + p1, pt2 + p2, pt2);
+
+ p1 = ScaleBezierPoint(pt23 - pt2);
+ p2 = ScaleBezierPoint(pt32 - pt3);
+ m_pCheckPath->BezierTo(pt2 + p1, pt3 + p2, pt3);
+
+ p1 = ScaleBezierPoint(pt34 - pt3);
+ p2 = ScaleBezierPoint(pt43 - pt4);
+ m_pCheckPath->BezierTo(pt3 + p1, pt4 + p2, pt4);
+
+ p1 = ScaleBezierPoint(pt45 - pt4);
+ p2 = ScaleBezierPoint(pt54 - pt5);
+ m_pCheckPath->BezierTo(pt4 + p1, pt5 + p2, pt5);
+
+ p1 = ScaleBezierPoint(pt51 - pt5);
+ p2 = ScaleBezierPoint(pt15 - pt1);
+ m_pCheckPath->BezierTo(pt5 + p1, pt1 + p2, pt1);
+
+ float fScale = fCheckLen / kSignPath;
+ CFX_Matrix mt;
+ mt.Scale(fScale, fScale);
+ m_pCheckPath->TransformBy(mt);
}
void CFWL_CheckBoxTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
- if (pParams.m_iPart != CFWL_Part::CheckBox)
+ if (pParams.GetPart() != CFWL_ThemePart::Part::kCheckBox)
return;
- if ((pParams.m_dwStates & CFWL_PartState_Checked) ||
- (pParams.m_dwStates & CFWL_PartState_Neutral)) {
- DrawCheckSign(pParams.m_pWidget, pParams.m_pGraphics.Get(),
- pParams.m_rtPart, pParams.m_dwStates, pParams.m_matrix);
+ if ((pParams.m_dwStates & CFWL_PartState::kChecked) ||
+ (pParams.m_dwStates & CFWL_PartState::kNeutral)) {
+ DrawCheckSign(pParams.GetWidget(), pParams.GetGraphics(),
+ pParams.m_PartRect, pParams.m_dwStates, pParams.m_matrix);
}
}
void CFWL_CheckBoxTP::DrawCheckSign(CFWL_Widget* pWidget,
- CXFA_Graphics* pGraphics,
+ CFGAS_GEGraphics* pGraphics,
const CFX_RectF& pRtBox,
- int32_t iState,
+ Mask<CFWL_PartState> iState,
const CFX_Matrix& matrix) {
CFX_RectF rtSign(pRtBox);
- uint32_t dwColor = iState & CFWL_PartState_Neutral ? 0xFFA9A9A9 : 0xFF000000;
-
- uint32_t dwStyle = pWidget->GetStylesEx();
+ uint32_t dwColor =
+ iState & CFWL_PartState::kNeutral ? 0xFFA9A9A9 : 0xFF000000;
+ uint32_t dwStyle = pWidget->GetStyleExts();
rtSign.Deflate(rtSign.width / 4, rtSign.height / 4);
switch (dwStyle & FWL_STYLEEXT_CKB_SignShapeMask) {
case FWL_STYLEEXT_CKB_SignShapeCheck:
diff --git a/xfa/fwl/theme/cfwl_checkboxtp.h b/xfa/fwl/theme/cfwl_checkboxtp.h
index e79a693c6..810edda16 100644
--- a/xfa/fwl/theme/cfwl_checkboxtp.h
+++ b/xfa/fwl/theme/cfwl_checkboxtp.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,13 +9,16 @@
#include <memory>
+#include "fxjs/gc/heap.h"
+#include "xfa/fwl/cfwl_themepart.h"
#include "xfa/fwl/theme/cfwl_widgettp.h"
+class CFGAS_GEPath;
class CFWL_Widget;
class CFWL_CheckBoxTP final : public CFWL_WidgetTP {
public:
- CFWL_CheckBoxTP();
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_CheckBoxTP() override;
// CFWL_WidgetTP
@@ -23,39 +26,41 @@ class CFWL_CheckBoxTP final : public CFWL_WidgetTP {
void DrawText(const CFWL_ThemeText& pParams) override;
private:
+ CFWL_CheckBoxTP();
+
void DrawCheckSign(CFWL_Widget* pWidget,
- CXFA_Graphics* pGraphics,
+ CFGAS_GEGraphics* pGraphics,
const CFX_RectF& pRtBox,
- int32_t iState,
+ Mask<CFWL_PartState> iState,
const CFX_Matrix& matrix);
- void DrawSignCheck(CXFA_Graphics* pGraphics,
+ void DrawSignCheck(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rtSign,
FX_ARGB argbFill,
const CFX_Matrix& matrix);
- void DrawSignCircle(CXFA_Graphics* pGraphics,
+ void DrawSignCircle(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rtSign,
FX_ARGB argbFill,
const CFX_Matrix& matrix);
- void DrawSignCross(CXFA_Graphics* pGraphics,
+ void DrawSignCross(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rtSign,
FX_ARGB argbFill,
const CFX_Matrix& matrix);
- void DrawSignDiamond(CXFA_Graphics* pGraphics,
+ void DrawSignDiamond(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rtSign,
FX_ARGB argbFill,
const CFX_Matrix& matrix);
- void DrawSignSquare(CXFA_Graphics* pGraphics,
+ void DrawSignSquare(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rtSign,
FX_ARGB argbFill,
const CFX_Matrix& matrix);
- void DrawSignStar(CXFA_Graphics* pGraphics,
+ void DrawSignStar(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rtSign,
FX_ARGB argbFill,
const CFX_Matrix& matrix);
- void InitCheckPath(float fCheckLen);
+ void EnsureCheckPathInitialized(float fCheckLen);
- std::unique_ptr<CXFA_GEPath> m_pCheckPath;
+ std::unique_ptr<CFGAS_GEPath> m_pCheckPath;
};
#endif // XFA_FWL_THEME_CFWL_CHECKBOXTP_H_
diff --git a/xfa/fwl/theme/cfwl_comboboxtp.cpp b/xfa/fwl/theme/cfwl_comboboxtp.cpp
index 6cc842d64..adf66ec46 100644
--- a/xfa/fwl/theme/cfwl_comboboxtp.cpp
+++ b/xfa/fwl/theme/cfwl_comboboxtp.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,78 +6,48 @@
#include "xfa/fwl/theme/cfwl_comboboxtp.h"
-#include "core/fxge/render_defines.h"
+#include "xfa/fgas/graphics/cfgas_gecolor.h"
+#include "xfa/fgas/graphics/cfgas_gepath.h"
#include "xfa/fwl/cfwl_combobox.h"
#include "xfa/fwl/cfwl_themebackground.h"
#include "xfa/fwl/cfwl_widget.h"
#include "xfa/fwl/ifwl_themeprovider.h"
-#include "xfa/fxgraphics/cxfa_gecolor.h"
-#include "xfa/fxgraphics/cxfa_gepath.h"
CFWL_ComboBoxTP::CFWL_ComboBoxTP() = default;
CFWL_ComboBoxTP::~CFWL_ComboBoxTP() = default;
void CFWL_ComboBoxTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
- switch (pParams.m_iPart) {
- case CFWL_Part::Border: {
- DrawBorder(pParams.m_pGraphics.Get(), pParams.m_rtPart, pParams.m_matrix);
+ switch (pParams.GetPart()) {
+ case CFWL_ThemePart::Part::kBorder: {
+ DrawBorder(pParams.GetGraphics(), pParams.m_PartRect, pParams.m_matrix);
break;
}
- case CFWL_Part::Background: {
- CXFA_GEPath path;
- const CFX_RectF& rect = pParams.m_rtPart;
+ case CFWL_ThemePart::Part::kBackground: {
+ CFGAS_GEPath path;
+ const CFX_RectF& rect = pParams.m_PartRect;
path.AddRectangle(rect.left, rect.top, rect.width, rect.height);
FX_ARGB argb_color;
- switch (pParams.m_dwStates) {
- case CFWL_PartState_Selected:
- argb_color = FWLTHEME_COLOR_BKSelected;
- break;
- case CFWL_PartState_Disabled:
- argb_color = FWLTHEME_COLOR_EDGERB1;
- break;
- default:
- argb_color = 0xFFFFFFFF;
- }
- pParams.m_pGraphics->SaveGraphState();
- pParams.m_pGraphics->SetFillColor(CXFA_GEColor(argb_color));
- pParams.m_pGraphics->FillPath(&path, FXFILL_WINDING, &pParams.m_matrix);
- pParams.m_pGraphics->RestoreGraphState();
- break;
- }
- case CFWL_Part::DropDownButton: {
- DrawDropDownButton(pParams, pParams.m_dwStates, pParams.m_matrix);
- break;
- }
- default:
- break;
- }
-}
+ if (pParams.m_dwStates & CFWL_PartState::kSelected)
+ argb_color = FWLTHEME_COLOR_BKSelected;
+ else if (pParams.m_dwStates & CFWL_PartState::kDisabled)
+ argb_color = FWLTHEME_COLOR_EDGERB1;
+ else
+ argb_color = 0xFFFFFFFF;
-void CFWL_ComboBoxTP::DrawDropDownButton(const CFWL_ThemeBackground& pParams,
- uint32_t dwStates,
- const CFX_Matrix& matrix) {
- FWLTHEME_STATE eState = FWLTHEME_STATE_Normal;
- switch (dwStates) {
- case CFWL_PartState_Normal: {
- eState = FWLTHEME_STATE_Normal;
- break;
- }
- case CFWL_PartState_Hovered: {
- eState = FWLTHEME_STATE_Hover;
- break;
- }
- case CFWL_PartState_Pressed: {
- eState = FWLTHEME_STATE_Pressed;
+ CFGAS_GEGraphics::StateRestorer restorer(pParams.GetGraphics());
+ pParams.GetGraphics()->SetFillColor(CFGAS_GEColor(argb_color));
+ pParams.GetGraphics()->FillPath(
+ path, CFX_FillRenderOptions::FillType::kWinding, pParams.m_matrix);
break;
}
- case CFWL_PartState_Disabled: {
- eState = FWLTHEME_STATE_Disable;
+ case CFWL_ThemePart::Part::kDropDownButton: {
+ DrawArrowBtn(pParams.GetGraphics(), pParams.m_PartRect,
+ FWLTHEME_DIRECTION::kDown, pParams.GetThemeState(),
+ pParams.m_matrix);
break;
}
default:
break;
}
- DrawArrowBtn(pParams.m_pGraphics.Get(), pParams.m_rtPart,
- FWLTHEME_DIRECTION_Down, eState, pParams.m_matrix);
}
diff --git a/xfa/fwl/theme/cfwl_comboboxtp.h b/xfa/fwl/theme/cfwl_comboboxtp.h
index b3a75a53f..87ca2d7d1 100644
--- a/xfa/fwl/theme/cfwl_comboboxtp.h
+++ b/xfa/fwl/theme/cfwl_comboboxtp.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,20 +7,19 @@
#ifndef XFA_FWL_THEME_CFWL_COMBOBOXTP_H_
#define XFA_FWL_THEME_CFWL_COMBOBOXTP_H_
+#include "fxjs/gc/heap.h"
#include "xfa/fwl/theme/cfwl_widgettp.h"
class CFWL_ComboBoxTP final : public CFWL_WidgetTP {
public:
- CFWL_ComboBoxTP();
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_ComboBoxTP() override;
- // CFWL_WidgetTP
+ // CFWL_WidgetTP:
void DrawBackground(const CFWL_ThemeBackground& pParams) override;
private:
- void DrawDropDownButton(const CFWL_ThemeBackground& pParams,
- uint32_t dwStates,
- const CFX_Matrix& matrix);
+ CFWL_ComboBoxTP();
};
#endif // XFA_FWL_THEME_CFWL_COMBOBOXTP_H_
diff --git a/xfa/fwl/theme/cfwl_datetimepickertp.cpp b/xfa/fwl/theme/cfwl_datetimepickertp.cpp
index a185952fb..5562ab1ed 100644
--- a/xfa/fwl/theme/cfwl_datetimepickertp.cpp
+++ b/xfa/fwl/theme/cfwl_datetimepickertp.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,50 +9,22 @@
#include "xfa/fwl/cfwl_datetimepicker.h"
#include "xfa/fwl/cfwl_themebackground.h"
-CFWL_DateTimePickerTP::CFWL_DateTimePickerTP() {}
+CFWL_DateTimePickerTP::CFWL_DateTimePickerTP() = default;
-CFWL_DateTimePickerTP::~CFWL_DateTimePickerTP() {}
+CFWL_DateTimePickerTP::~CFWL_DateTimePickerTP() = default;
void CFWL_DateTimePickerTP::DrawBackground(
const CFWL_ThemeBackground& pParams) {
- switch (pParams.m_iPart) {
- case CFWL_Part::Border:
- DrawBorder(pParams.m_pGraphics.Get(), pParams.m_rtPart, pParams.m_matrix);
+ switch (pParams.GetPart()) {
+ case CFWL_ThemePart::Part::kBorder:
+ DrawBorder(pParams.GetGraphics(), pParams.m_PartRect, pParams.m_matrix);
break;
- case CFWL_Part::DropDownButton:
- DrawDropDownButton(pParams, pParams.m_matrix);
+ case CFWL_ThemePart::Part::kDropDownButton:
+ DrawArrowBtn(pParams.GetGraphics(), pParams.m_PartRect,
+ FWLTHEME_DIRECTION::kDown, pParams.GetThemeState(),
+ pParams.m_matrix);
break;
default:
break;
}
}
-
-void CFWL_DateTimePickerTP::DrawDropDownButton(
- const CFWL_ThemeBackground& pParams,
- const CFX_Matrix& matrix) {
- uint32_t dwStates = pParams.m_dwStates;
- dwStates &= 0x03;
- FWLTHEME_STATE eState = FWLTHEME_STATE_Normal;
- switch (eState & dwStates) {
- case CFWL_PartState_Normal: {
- eState = FWLTHEME_STATE_Normal;
- break;
- }
- case CFWL_PartState_Hovered: {
- eState = FWLTHEME_STATE_Hover;
- break;
- }
- case CFWL_PartState_Pressed: {
- eState = FWLTHEME_STATE_Pressed;
- break;
- }
- case CFWL_PartState_Disabled: {
- eState = FWLTHEME_STATE_Disable;
- break;
- }
- default:
- break;
- }
- DrawArrowBtn(pParams.m_pGraphics.Get(), pParams.m_rtPart,
- FWLTHEME_DIRECTION_Down, eState, matrix);
-}
diff --git a/xfa/fwl/theme/cfwl_datetimepickertp.h b/xfa/fwl/theme/cfwl_datetimepickertp.h
index e7163e039..a9cf41d35 100644
--- a/xfa/fwl/theme/cfwl_datetimepickertp.h
+++ b/xfa/fwl/theme/cfwl_datetimepickertp.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,19 +7,19 @@
#ifndef XFA_FWL_THEME_CFWL_DATETIMEPICKERTP_H_
#define XFA_FWL_THEME_CFWL_DATETIMEPICKERTP_H_
+#include "fxjs/gc/heap.h"
#include "xfa/fwl/theme/cfwl_widgettp.h"
class CFWL_DateTimePickerTP final : public CFWL_WidgetTP {
public:
- CFWL_DateTimePickerTP();
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_DateTimePickerTP() override;
- // CFWL_WidgetTP
+ // CFWL_WidgetTP:
void DrawBackground(const CFWL_ThemeBackground& pParams) override;
private:
- void DrawDropDownButton(const CFWL_ThemeBackground& pParams,
- const CFX_Matrix& matrix);
+ CFWL_DateTimePickerTP();
};
#endif // XFA_FWL_THEME_CFWL_DATETIMEPICKERTP_H_
diff --git a/xfa/fwl/theme/cfwl_edittp.cpp b/xfa/fwl/theme/cfwl_edittp.cpp
index cacdf09bb..401390eea 100644
--- a/xfa/fwl/theme/cfwl_edittp.cpp
+++ b/xfa/fwl/theme/cfwl_edittp.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,67 +6,62 @@
#include "xfa/fwl/theme/cfwl_edittp.h"
-#include "core/fxge/render_defines.h"
+#include "xfa/fgas/graphics/cfgas_gecolor.h"
+#include "xfa/fgas/graphics/cfgas_gegraphics.h"
+#include "xfa/fgas/graphics/cfgas_gepath.h"
#include "xfa/fwl/cfwl_edit.h"
#include "xfa/fwl/cfwl_themebackground.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fxgraphics/cxfa_gecolor.h"
-#include "xfa/fxgraphics/cxfa_gepath.h"
CFWL_EditTP::CFWL_EditTP() = default;
CFWL_EditTP::~CFWL_EditTP() = default;
void CFWL_EditTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
- if (CFWL_Part::CombTextLine == pParams.m_iPart) {
- CFWL_Widget::AdapterIface* pWidget =
- pParams.m_pWidget->GetOutmost()->GetAdapterIface();
- FX_ARGB cr = 0xFF000000;
- float fWidth = 1.0f;
- pWidget->GetBorderColorAndThickness(&cr, &fWidth);
- pParams.m_pGraphics->SetStrokeColor(CXFA_GEColor(cr));
- pParams.m_pGraphics->SetLineWidth(fWidth);
- pParams.m_pGraphics->StrokePath(pParams.m_pPath.Get(), &pParams.m_matrix);
- return;
- }
-
- switch (pParams.m_iPart) {
- case CFWL_Part::Border: {
- DrawBorder(pParams.m_pGraphics.Get(), pParams.m_rtPart, pParams.m_matrix);
+ switch (pParams.GetPart()) {
+ case CFWL_ThemePart::Part::kBorder: {
+ DrawBorder(pParams.GetGraphics(), pParams.m_PartRect, pParams.m_matrix);
break;
}
- case CFWL_Part::Background: {
- if (pParams.m_pPath) {
- CXFA_Graphics* pGraphics = pParams.m_pGraphics.Get();
- pGraphics->SaveGraphState();
- pGraphics->SetFillColor(CXFA_GEColor(FWLTHEME_COLOR_BKSelected));
- pGraphics->FillPath(pParams.m_pPath.Get(), FXFILL_WINDING,
- &pParams.m_matrix);
- pGraphics->RestoreGraphState();
+ case CFWL_ThemePart::Part::kBackground: {
+ CFGAS_GEGraphics* pGraphics = pParams.GetGraphics();
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ const CFGAS_GEPath* pParamsPath = pParams.GetPath();
+ if (pParamsPath) {
+ pGraphics->SetFillColor(CFGAS_GEColor(FWLTHEME_COLOR_BKSelected));
+ pGraphics->FillPath(*pParamsPath,
+ CFX_FillRenderOptions::FillType::kWinding,
+ pParams.m_matrix);
} else {
- CXFA_GEPath path;
- path.AddRectangle(pParams.m_rtPart.left, pParams.m_rtPart.top,
- pParams.m_rtPart.width, pParams.m_rtPart.height);
- CXFA_GEColor cr(FWLTHEME_COLOR_Background);
+ CFGAS_GEPath path;
+ path.AddRectangle(pParams.m_PartRect.left, pParams.m_PartRect.top,
+ pParams.m_PartRect.width, pParams.m_PartRect.height);
+ CFGAS_GEColor cr(FWLTHEME_COLOR_Background);
if (!pParams.m_bStaticBackground) {
- if (pParams.m_dwStates & CFWL_PartState_Disabled)
- cr = CXFA_GEColor(FWLTHEME_COLOR_EDGERB1);
- else if (pParams.m_dwStates & CFWL_PartState_ReadOnly)
- cr = CXFA_GEColor(ArgbEncode(255, 236, 233, 216));
+ if (pParams.m_dwStates & CFWL_PartState::kDisabled)
+ cr = CFGAS_GEColor(FWLTHEME_COLOR_EDGERB1);
+ else if (pParams.m_dwStates & CFWL_PartState::kReadOnly)
+ cr = CFGAS_GEColor(ArgbEncode(255, 236, 233, 216));
else
- cr = CXFA_GEColor(0xFFFFFFFF);
+ cr = CFGAS_GEColor(0xFFFFFFFF);
}
- pParams.m_pGraphics->SaveGraphState();
- pParams.m_pGraphics->SetFillColor(cr);
- pParams.m_pGraphics->FillPath(&path, FXFILL_WINDING, &pParams.m_matrix);
- pParams.m_pGraphics->RestoreGraphState();
+ pGraphics->SetFillColor(cr);
+ pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kWinding,
+ pParams.m_matrix);
}
break;
}
- case CFWL_Part::CombTextLine: {
- pParams.m_pGraphics->SetStrokeColor(CXFA_GEColor(0xFF000000));
- pParams.m_pGraphics->SetLineWidth(1.0f);
- pParams.m_pGraphics->StrokePath(pParams.m_pPath.Get(), &pParams.m_matrix);
+ case CFWL_ThemePart::Part::kCombTextLine: {
+ CFWL_Widget::AdapterIface* pWidget =
+ pParams.GetWidget()->GetOutmost()->GetAdapterIface();
+ FX_ARGB cr = 0xFF000000;
+ float fWidth = 1.0f;
+ pWidget->GetBorderColorAndThickness(&cr, &fWidth);
+ pParams.GetGraphics()->SetStrokeColor(CFGAS_GEColor(cr));
+ pParams.GetGraphics()->SetLineWidth(fWidth);
+ const CFGAS_GEPath* pParamsPath = pParams.GetPath();
+ if (pParamsPath)
+ pParams.GetGraphics()->StrokePath(*pParamsPath, pParams.m_matrix);
break;
}
default:
diff --git a/xfa/fwl/theme/cfwl_edittp.h b/xfa/fwl/theme/cfwl_edittp.h
index b5b58f3b0..e44f30ce8 100644
--- a/xfa/fwl/theme/cfwl_edittp.h
+++ b/xfa/fwl/theme/cfwl_edittp.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,15 +7,19 @@
#ifndef XFA_FWL_THEME_CFWL_EDITTP_H_
#define XFA_FWL_THEME_CFWL_EDITTP_H_
+#include "fxjs/gc/heap.h"
#include "xfa/fwl/theme/cfwl_widgettp.h"
class CFWL_EditTP final : public CFWL_WidgetTP {
public:
- CFWL_EditTP();
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_EditTP() override;
- // CFWL_WidgetTP
+ // CFWL_WidgetTP:
void DrawBackground(const CFWL_ThemeBackground& pParams) override;
+
+ private:
+ CFWL_EditTP();
};
#endif // XFA_FWL_THEME_CFWL_EDITTP_H_
diff --git a/xfa/fwl/theme/cfwl_listboxtp.cpp b/xfa/fwl/theme/cfwl_listboxtp.cpp
index 28b5e3431..db78bf5ee 100644
--- a/xfa/fwl/theme/cfwl_listboxtp.cpp
+++ b/xfa/fwl/theme/cfwl_listboxtp.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,45 +7,45 @@
#include "xfa/fwl/theme/cfwl_listboxtp.h"
#include "build/build_config.h"
-#include "core/fxge/render_defines.h"
+#include "xfa/fgas/graphics/cfgas_gecolor.h"
+#include "xfa/fgas/graphics/cfgas_gegraphics.h"
+#include "xfa/fgas/graphics/cfgas_gepath.h"
#include "xfa/fwl/cfwl_listbox.h"
#include "xfa/fwl/cfwl_themebackground.h"
#include "xfa/fwl/cfwl_widget.h"
-#include "xfa/fxgraphics/cxfa_gecolor.h"
-#include "xfa/fxgraphics/cxfa_gepath.h"
CFWL_ListBoxTP::CFWL_ListBoxTP() = default;
CFWL_ListBoxTP::~CFWL_ListBoxTP() = default;
void CFWL_ListBoxTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
- switch (pParams.m_iPart) {
- case CFWL_Part::Border: {
- DrawBorder(pParams.m_pGraphics.Get(), pParams.m_rtPart, pParams.m_matrix);
+ switch (pParams.GetPart()) {
+ case CFWL_ThemePart::Part::kBorder: {
+ DrawBorder(pParams.GetGraphics(), pParams.m_PartRect, pParams.m_matrix);
break;
}
- case CFWL_Part::Background: {
- FillSolidRect(pParams.m_pGraphics.Get(), ArgbEncode(255, 255, 255, 255),
- pParams.m_rtPart, pParams.m_matrix);
+ case CFWL_ThemePart::Part::kBackground: {
+ FillSolidRect(pParams.GetGraphics(), ArgbEncode(255, 255, 255, 255),
+ pParams.m_PartRect, pParams.m_matrix);
if (pParams.m_pRtData) {
- FillSolidRect(pParams.m_pGraphics.Get(), FWLTHEME_COLOR_Background,
+ FillSolidRect(pParams.GetGraphics(), FWLTHEME_COLOR_Background,
*pParams.m_pRtData, pParams.m_matrix);
}
break;
}
- case CFWL_Part::ListItem: {
- DrawListBoxItem(pParams.m_pGraphics.Get(), pParams.m_dwStates,
- pParams.m_rtPart, pParams.m_pRtData, pParams.m_matrix);
+ case CFWL_ThemePart::Part::kListItem: {
+ DrawListBoxItem(pParams.GetGraphics(), pParams.m_dwStates,
+ pParams.m_PartRect, pParams.m_pRtData, pParams.m_matrix);
break;
}
- case CFWL_Part::Check: {
+ case CFWL_ThemePart::Part::kCheck: {
uint32_t color = 0xFF000000;
- if (pParams.m_dwStates == CFWL_PartState_Checked) {
+ if (pParams.m_dwStates == CFWL_PartState::kChecked) {
color = 0xFFFF0000;
- } else if (pParams.m_dwStates == CFWL_PartState_Normal) {
+ } else if (pParams.m_dwStates == CFWL_PartState::kNormal) {
color = 0xFF0000FF;
}
- FillSolidRect(pParams.m_pGraphics.Get(), color, pParams.m_rtPart,
+ FillSolidRect(pParams.GetGraphics(), color, pParams.m_PartRect,
pParams.m_matrix);
break;
}
@@ -54,24 +54,24 @@ void CFWL_ListBoxTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
}
}
-void CFWL_ListBoxTP::DrawListBoxItem(CXFA_Graphics* pGraphics,
- uint32_t dwStates,
+void CFWL_ListBoxTP::DrawListBoxItem(CFGAS_GEGraphics* pGraphics,
+ Mask<CFWL_PartState> dwStates,
const CFX_RectF& rtItem,
const CFX_RectF* pData,
const CFX_Matrix& matrix) {
- if (dwStates & CFWL_PartState_Selected) {
- pGraphics->SaveGraphState();
- pGraphics->SetFillColor(CXFA_GEColor(FWLTHEME_COLOR_BKSelected));
- CXFA_GEPath path;
-#if defined(OS_MACOSX)
+ if (dwStates & CFWL_PartState::kSelected) {
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ pGraphics->SetFillColor(CFGAS_GEColor(FWLTHEME_COLOR_BKSelected));
+ CFGAS_GEPath path;
+#if BUILDFLAG(IS_APPLE)
path.AddRectangle(rtItem.left, rtItem.top, rtItem.width - 1,
rtItem.height - 1);
#else
path.AddRectangle(rtItem.left, rtItem.top, rtItem.width, rtItem.height);
#endif
- pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
- pGraphics->RestoreGraphState();
+ pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kWinding,
+ matrix);
}
- if ((dwStates & CFWL_PartState_Focused) && pData)
+ if ((dwStates & CFWL_PartState::kFocused) && pData)
DrawFocus(pGraphics, *pData, matrix);
}
diff --git a/xfa/fwl/theme/cfwl_listboxtp.h b/xfa/fwl/theme/cfwl_listboxtp.h
index ee954b884..d85ebf41f 100644
--- a/xfa/fwl/theme/cfwl_listboxtp.h
+++ b/xfa/fwl/theme/cfwl_listboxtp.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,19 +7,23 @@
#ifndef XFA_FWL_THEME_CFWL_LISTBOXTP_H_
#define XFA_FWL_THEME_CFWL_LISTBOXTP_H_
+#include "fxjs/gc/heap.h"
+#include "xfa/fwl/cfwl_themepart.h"
#include "xfa/fwl/theme/cfwl_widgettp.h"
class CFWL_ListBoxTP final : public CFWL_WidgetTP {
public:
- CFWL_ListBoxTP();
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_ListBoxTP() override;
- // CFWL_WidgetTP
+ // CFWL_WidgetTP:
void DrawBackground(const CFWL_ThemeBackground& pParams) override;
private:
- void DrawListBoxItem(CXFA_Graphics* pGraphics,
- uint32_t dwStates,
+ CFWL_ListBoxTP();
+
+ void DrawListBoxItem(CFGAS_GEGraphics* pGraphics,
+ Mask<CFWL_PartState> dwStates,
const CFX_RectF& rtItem,
const CFX_RectF* pData,
const CFX_Matrix& matrix);
diff --git a/xfa/fwl/theme/cfwl_monthcalendartp.cpp b/xfa/fwl/theme/cfwl_monthcalendartp.cpp
index 47ba930f2..0c220fb42 100644
--- a/xfa/fwl/theme/cfwl_monthcalendartp.cpp
+++ b/xfa/fwl/theme/cfwl_monthcalendartp.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,15 +6,15 @@
#include "xfa/fwl/theme/cfwl_monthcalendartp.h"
-#include "core/fxge/render_defines.h"
#include "xfa/fde/cfde_textout.h"
+#include "xfa/fgas/graphics/cfgas_gecolor.h"
+#include "xfa/fgas/graphics/cfgas_gegraphics.h"
+#include "xfa/fgas/graphics/cfgas_gepath.h"
#include "xfa/fwl/cfwl_monthcalendar.h"
#include "xfa/fwl/cfwl_themebackground.h"
#include "xfa/fwl/cfwl_themetext.h"
#include "xfa/fwl/cfwl_widget.h"
#include "xfa/fwl/ifwl_themeprovider.h"
-#include "xfa/fxgraphics/cxfa_gecolor.h"
-#include "xfa/fxgraphics/cxfa_gepath.h"
namespace {
@@ -33,48 +33,48 @@ CFWL_MonthCalendarTP::CFWL_MonthCalendarTP() = default;
CFWL_MonthCalendarTP::~CFWL_MonthCalendarTP() = default;
void CFWL_MonthCalendarTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
- switch (pParams.m_iPart) {
- case CFWL_Part::Border: {
- DrawBorder(pParams.m_pGraphics.Get(), pParams.m_rtPart, pParams.m_matrix);
+ switch (pParams.GetPart()) {
+ case CFWL_ThemePart::Part::kBorder: {
+ DrawBorder(pParams.GetGraphics(), pParams.m_PartRect, pParams.m_matrix);
break;
}
- case CFWL_Part::Background: {
+ case CFWL_ThemePart::Part::kBackground: {
DrawTotalBK(pParams, pParams.m_matrix);
break;
}
- case CFWL_Part::Header: {
+ case CFWL_ThemePart::Part::kHeader: {
DrawHeadBk(pParams, pParams.m_matrix);
break;
}
- case CFWL_Part::LBtn: {
- FWLTHEME_STATE eState = GetState(pParams.m_dwStates);
- DrawArrowBtn(pParams.m_pGraphics.Get(), pParams.m_rtPart,
- FWLTHEME_DIRECTION_Left, eState, pParams.m_matrix);
+ case CFWL_ThemePart::Part::kLBtn: {
+ DrawArrowBtn(pParams.GetGraphics(), pParams.m_PartRect,
+ FWLTHEME_DIRECTION::kLeft, pParams.GetThemeState(),
+ pParams.m_matrix);
break;
}
- case CFWL_Part::RBtn: {
- FWLTHEME_STATE eState = GetState(pParams.m_dwStates);
- DrawArrowBtn(pParams.m_pGraphics.Get(), pParams.m_rtPart,
- FWLTHEME_DIRECTION_Right, eState, pParams.m_matrix);
+ case CFWL_ThemePart::Part::kRBtn: {
+ DrawArrowBtn(pParams.GetGraphics(), pParams.m_PartRect,
+ FWLTHEME_DIRECTION::kRight, pParams.GetThemeState(),
+ pParams.m_matrix);
break;
}
- case CFWL_Part::HSeparator: {
+ case CFWL_ThemePart::Part::kHSeparator: {
DrawHSeparator(pParams, pParams.m_matrix);
break;
}
- case CFWL_Part::DatesIn: {
+ case CFWL_ThemePart::Part::kDatesIn: {
DrawDatesInBK(pParams, pParams.m_matrix);
break;
}
- case CFWL_Part::TodayCircle: {
+ case CFWL_ThemePart::Part::kTodayCircle: {
DrawTodayCircle(pParams, pParams.m_matrix);
break;
}
- case CFWL_Part::DateInCircle: {
+ case CFWL_ThemePart::Part::kDateInCircle: {
DrawDatesInCircle(pParams, pParams.m_matrix);
break;
}
- case CFWL_Part::WeekNumSep: {
+ case CFWL_ThemePart::Part::kWeekNumSep: {
DrawWeekNumSep(pParams, pParams.m_matrix);
break;
}
@@ -84,13 +84,13 @@ void CFWL_MonthCalendarTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
}
void CFWL_MonthCalendarTP::DrawText(const CFWL_ThemeText& pParams) {
- EnsureTTOInitialized();
- if ((pParams.m_iPart == CFWL_Part::DatesIn) &&
- !(pParams.m_dwStates & FWL_ITEMSTATE_MCD_Flag) &&
- (pParams.m_dwStates &
- (CFWL_PartState_Hovered | CFWL_PartState_Selected))) {
+ EnsureTTOInitialized(pParams.GetWidget()->GetThemeProvider());
+ if (pParams.GetPart() == CFWL_ThemePart::Part::kDatesIn &&
+ !(pParams.m_dwStates & CFWL_PartState::kFlagged) &&
+ (pParams.m_dwStates & Mask<CFWL_PartState>{CFWL_PartState::kHovered,
+ CFWL_PartState::kSelected})) {
m_pTextOut->SetTextColor(0xFFFFFFFF);
- } else if (pParams.m_iPart == CFWL_Part::Caption) {
+ } else if (pParams.GetPart() == CFWL_ThemePart::Part::kCaption) {
m_pTextOut->SetTextColor(kCaptionColor);
} else {
m_pTextOut->SetTextColor(0xFF000000);
@@ -100,43 +100,48 @@ void CFWL_MonthCalendarTP::DrawText(const CFWL_ThemeText& pParams) {
void CFWL_MonthCalendarTP::DrawTotalBK(const CFWL_ThemeBackground& pParams,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
- CFX_RectF rtTotal(pParams.m_rtPart);
+ CFGAS_GEPath path;
+ CFX_RectF rtTotal(pParams.m_PartRect);
path.AddRectangle(rtTotal.left, rtTotal.top, rtTotal.width, rtTotal.height);
- pParams.m_pGraphics->SaveGraphState();
- pParams.m_pGraphics->SetFillColor(CXFA_GEColor(kBackgroundColor));
- pParams.m_pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
- pParams.m_pGraphics->RestoreGraphState();
+
+ CFGAS_GEGraphics::StateRestorer restorer(pParams.GetGraphics());
+ pParams.GetGraphics()->SetFillColor(CFGAS_GEColor(kBackgroundColor));
+ pParams.GetGraphics()->FillPath(
+ path, CFX_FillRenderOptions::FillType::kWinding, matrix);
}
void CFWL_MonthCalendarTP::DrawHeadBk(const CFWL_ThemeBackground& pParams,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
- CFX_RectF rtHead = pParams.m_rtPart;
+ CFGAS_GEPath path;
+ CFX_RectF rtHead = pParams.m_PartRect;
path.AddRectangle(rtHead.left, rtHead.top, rtHead.width, rtHead.height);
- pParams.m_pGraphics->SaveGraphState();
- pParams.m_pGraphics->SetFillColor(CXFA_GEColor(kBackgroundColor));
- pParams.m_pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
- pParams.m_pGraphics->RestoreGraphState();
+
+ CFGAS_GEGraphics::StateRestorer restorer(pParams.GetGraphics());
+ pParams.GetGraphics()->SetFillColor(CFGAS_GEColor(kBackgroundColor));
+ pParams.GetGraphics()->FillPath(
+ path, CFX_FillRenderOptions::FillType::kWinding, matrix);
}
void CFWL_MonthCalendarTP::DrawLButton(const CFWL_ThemeBackground& pParams,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
- CFX_RectF rtLBtn = pParams.m_rtPart;
+ CFGAS_GEPath path;
+ CFX_RectF rtLBtn = pParams.m_PartRect;
path.AddRectangle(rtLBtn.left, rtLBtn.top, rtLBtn.width, rtLBtn.height);
- pParams.m_pGraphics->SaveGraphState();
- pParams.m_pGraphics->SetStrokeColor(
- CXFA_GEColor(ArgbEncode(0xff, 205, 219, 243)));
- pParams.m_pGraphics->StrokePath(&path, &matrix);
- if (pParams.m_dwStates & CFWL_PartState_Pressed) {
- pParams.m_pGraphics->SetFillColor(
- CXFA_GEColor(ArgbEncode(0xff, 174, 198, 242)));
- pParams.m_pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
+
+ CFGAS_GEGraphics::StateRestorer restorer(pParams.GetGraphics());
+ pParams.GetGraphics()->SetStrokeColor(
+ CFGAS_GEColor(ArgbEncode(0xff, 205, 219, 243)));
+ pParams.GetGraphics()->StrokePath(path, matrix);
+ if (pParams.m_dwStates & CFWL_PartState::kPressed) {
+ pParams.GetGraphics()->SetFillColor(
+ CFGAS_GEColor(ArgbEncode(0xff, 174, 198, 242)));
+ pParams.GetGraphics()->FillPath(
+ path, CFX_FillRenderOptions::FillType::kWinding, matrix);
} else {
- pParams.m_pGraphics->SetFillColor(
- CXFA_GEColor(ArgbEncode(0xff, 227, 235, 249)));
- pParams.m_pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
+ pParams.GetGraphics()->SetFillColor(
+ CFGAS_GEColor(ArgbEncode(0xff, 227, 235, 249)));
+ pParams.GetGraphics()->FillPath(
+ path, CFX_FillRenderOptions::FillType::kWinding, matrix);
}
path.Clear();
@@ -147,29 +152,31 @@ void CFWL_MonthCalendarTP::DrawLButton(const CFWL_ThemeBackground& pParams,
path.LineTo(CFX_PointF(rtLBtn.left + rtLBtn.Width() / 3 * 2,
rtLBtn.bottom() - rtLBtn.height / 4));
- pParams.m_pGraphics->SetStrokeColor(
- CXFA_GEColor(ArgbEncode(0xff, 50, 104, 205)));
- pParams.m_pGraphics->StrokePath(&path, &matrix);
- pParams.m_pGraphics->RestoreGraphState();
+ pParams.GetGraphics()->SetStrokeColor(
+ CFGAS_GEColor(ArgbEncode(0xff, 50, 104, 205)));
+ pParams.GetGraphics()->StrokePath(path, matrix);
}
void CFWL_MonthCalendarTP::DrawRButton(const CFWL_ThemeBackground& pParams,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
- CFX_RectF rtRBtn = pParams.m_rtPart;
+ CFGAS_GEPath path;
+ CFX_RectF rtRBtn = pParams.m_PartRect;
path.AddRectangle(rtRBtn.left, rtRBtn.top, rtRBtn.width, rtRBtn.height);
- pParams.m_pGraphics->SaveGraphState();
- pParams.m_pGraphics->SetStrokeColor(
- CXFA_GEColor(ArgbEncode(0xff, 205, 219, 243)));
- pParams.m_pGraphics->StrokePath(&path, &matrix);
- if (pParams.m_dwStates & CFWL_PartState_Pressed) {
- pParams.m_pGraphics->SetFillColor(
- CXFA_GEColor(ArgbEncode(0xff, 174, 198, 242)));
- pParams.m_pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
+
+ CFGAS_GEGraphics::StateRestorer restorer(pParams.GetGraphics());
+ pParams.GetGraphics()->SetStrokeColor(
+ CFGAS_GEColor(ArgbEncode(0xff, 205, 219, 243)));
+ pParams.GetGraphics()->StrokePath(path, matrix);
+ if (pParams.m_dwStates & CFWL_PartState::kPressed) {
+ pParams.GetGraphics()->SetFillColor(
+ CFGAS_GEColor(ArgbEncode(0xff, 174, 198, 242)));
+ pParams.GetGraphics()->FillPath(
+ path, CFX_FillRenderOptions::FillType::kWinding, matrix);
} else {
- pParams.m_pGraphics->SetFillColor(
- CXFA_GEColor(ArgbEncode(0xff, 227, 235, 249)));
- pParams.m_pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
+ pParams.GetGraphics()->SetFillColor(
+ CFGAS_GEColor(ArgbEncode(0xff, 227, 235, 249)));
+ pParams.GetGraphics()->FillPath(
+ path, CFX_FillRenderOptions::FillType::kWinding, matrix);
}
path.Clear();
@@ -180,87 +187,80 @@ void CFWL_MonthCalendarTP::DrawRButton(const CFWL_ThemeBackground& pParams,
path.LineTo(CFX_PointF(rtRBtn.left + rtRBtn.Width() / 3,
rtRBtn.bottom() - rtRBtn.height / 4));
- pParams.m_pGraphics->SetStrokeColor(
- CXFA_GEColor(ArgbEncode(0xff, 50, 104, 205)));
- pParams.m_pGraphics->StrokePath(&path, &matrix);
- pParams.m_pGraphics->RestoreGraphState();
+ pParams.GetGraphics()->SetStrokeColor(
+ CFGAS_GEColor(ArgbEncode(0xff, 50, 104, 205)));
+ pParams.GetGraphics()->StrokePath(path, matrix);
}
void CFWL_MonthCalendarTP::DrawHSeparator(const CFWL_ThemeBackground& pParams,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
- CFX_RectF rtHSep = pParams.m_rtPart;
+ CFGAS_GEPath path;
+ CFX_RectF rtHSep = pParams.m_PartRect;
path.MoveTo(CFX_PointF(rtHSep.left, rtHSep.top + rtHSep.height / 2));
path.LineTo(CFX_PointF(rtHSep.right(), rtHSep.top + rtHSep.height / 2));
- pParams.m_pGraphics->SaveGraphState();
- pParams.m_pGraphics->SetStrokeColor(CXFA_GEColor(kSeparatorColor));
- pParams.m_pGraphics->StrokePath(&path, &matrix);
- pParams.m_pGraphics->RestoreGraphState();
+
+ CFGAS_GEGraphics::StateRestorer restorer(pParams.GetGraphics());
+ pParams.GetGraphics()->SetStrokeColor(CFGAS_GEColor(kSeparatorColor));
+ pParams.GetGraphics()->StrokePath(path, matrix);
}
void CFWL_MonthCalendarTP::DrawWeekNumSep(const CFWL_ThemeBackground& pParams,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
- CFX_RectF rtWeekSep = pParams.m_rtPart;
+ CFGAS_GEPath path;
+ CFX_RectF rtWeekSep = pParams.m_PartRect;
path.MoveTo(rtWeekSep.TopLeft());
path.LineTo(rtWeekSep.BottomLeft());
- pParams.m_pGraphics->SaveGraphState();
- pParams.m_pGraphics->SetStrokeColor(CXFA_GEColor(kSeparatorColor));
- pParams.m_pGraphics->StrokePath(&path, &matrix);
- pParams.m_pGraphics->RestoreGraphState();
+
+ CFGAS_GEGraphics::StateRestorer restorer(pParams.GetGraphics());
+ pParams.GetGraphics()->SetStrokeColor(CFGAS_GEColor(kSeparatorColor));
+ pParams.GetGraphics()->StrokePath(path, matrix);
}
void CFWL_MonthCalendarTP::DrawDatesInBK(const CFWL_ThemeBackground& pParams,
const CFX_Matrix& matrix) {
- pParams.m_pGraphics->SaveGraphState();
- if (pParams.m_dwStates & CFWL_PartState_Selected) {
- CXFA_GEPath path;
- CFX_RectF rtSelDay = pParams.m_rtPart;
+ CFGAS_GEGraphics::StateRestorer restorer(pParams.GetGraphics());
+ if (pParams.m_dwStates & CFWL_PartState::kSelected) {
+ CFGAS_GEPath path;
+ CFX_RectF rtSelDay = pParams.m_PartRect;
path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width,
rtSelDay.height);
- pParams.m_pGraphics->SetFillColor(
- CXFA_GEColor(kDatesSelectedBackgroundColor));
- pParams.m_pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
- } else if (pParams.m_dwStates & CFWL_PartState_Hovered) {
- CXFA_GEPath path;
- CFX_RectF rtSelDay = pParams.m_rtPart;
+ pParams.GetGraphics()->SetFillColor(
+ CFGAS_GEColor(kDatesSelectedBackgroundColor));
+ pParams.GetGraphics()->FillPath(
+ path, CFX_FillRenderOptions::FillType::kWinding, matrix);
+ } else if (pParams.m_dwStates & CFWL_PartState::kHovered) {
+ CFGAS_GEPath path;
+ CFX_RectF rtSelDay = pParams.m_PartRect;
path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width,
rtSelDay.height);
- pParams.m_pGraphics->SetFillColor(CXFA_GEColor(kDatesHoverBackgroundColor));
- pParams.m_pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
+ pParams.GetGraphics()->SetFillColor(
+ CFGAS_GEColor(kDatesHoverBackgroundColor));
+ pParams.GetGraphics()->FillPath(
+ path, CFX_FillRenderOptions::FillType::kWinding, matrix);
}
- pParams.m_pGraphics->RestoreGraphState();
}
void CFWL_MonthCalendarTP::DrawDatesInCircle(
const CFWL_ThemeBackground& pParams,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
- CFX_RectF rtSelDay = pParams.m_rtPart;
+ CFGAS_GEPath path;
+ CFX_RectF rtSelDay = pParams.m_PartRect;
path.AddRectangle(rtSelDay.left, rtSelDay.top, rtSelDay.width,
rtSelDay.height);
- pParams.m_pGraphics->SaveGraphState();
- pParams.m_pGraphics->SetStrokeColor(CXFA_GEColor(kDatesCircleColor));
- pParams.m_pGraphics->StrokePath(&path, &matrix);
- pParams.m_pGraphics->RestoreGraphState();
+
+ CFGAS_GEGraphics::StateRestorer restorer(pParams.GetGraphics());
+ pParams.GetGraphics()->SetStrokeColor(CFGAS_GEColor(kDatesCircleColor));
+ pParams.GetGraphics()->StrokePath(path, matrix);
}
void CFWL_MonthCalendarTP::DrawTodayCircle(const CFWL_ThemeBackground& pParams,
const CFX_Matrix& matrix) {
- CXFA_GEPath path;
- CFX_RectF rtTodayCircle = pParams.m_rtPart;
+ CFGAS_GEPath path;
+ CFX_RectF rtTodayCircle = pParams.m_PartRect;
path.AddRectangle(rtTodayCircle.left, rtTodayCircle.top, rtTodayCircle.width,
rtTodayCircle.height);
- pParams.m_pGraphics->SaveGraphState();
- pParams.m_pGraphics->SetStrokeColor(CXFA_GEColor(kDatesCircleColor));
- pParams.m_pGraphics->StrokePath(&path, &matrix);
- pParams.m_pGraphics->RestoreGraphState();
-}
-FWLTHEME_STATE CFWL_MonthCalendarTP::GetState(uint32_t dwFWLStates) {
- if (dwFWLStates & CFWL_PartState_Hovered)
- return FWLTHEME_STATE_Hover;
- if (dwFWLStates & CFWL_PartState_Pressed)
- return FWLTHEME_STATE_Pressed;
- return FWLTHEME_STATE_Normal;
+ CFGAS_GEGraphics::StateRestorer restorer(pParams.GetGraphics());
+ pParams.GetGraphics()->SetStrokeColor(CFGAS_GEColor(kDatesCircleColor));
+ pParams.GetGraphics()->StrokePath(path, matrix);
}
diff --git a/xfa/fwl/theme/cfwl_monthcalendartp.h b/xfa/fwl/theme/cfwl_monthcalendartp.h
index dd82cc1f4..609fa2c39 100644
--- a/xfa/fwl/theme/cfwl_monthcalendartp.h
+++ b/xfa/fwl/theme/cfwl_monthcalendartp.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,18 +7,21 @@
#ifndef XFA_FWL_THEME_CFWL_MONTHCALENDARTP_H_
#define XFA_FWL_THEME_CFWL_MONTHCALENDARTP_H_
+#include "fxjs/gc/heap.h"
#include "xfa/fwl/theme/cfwl_widgettp.h"
class CFWL_MonthCalendarTP final : public CFWL_WidgetTP {
public:
- CFWL_MonthCalendarTP();
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_MonthCalendarTP() override;
- // CFWL_WidgetTP
+ // CFWL_WidgetTP:
void DrawBackground(const CFWL_ThemeBackground& pParams) override;
void DrawText(const CFWL_ThemeText& pParams) override;
private:
+ CFWL_MonthCalendarTP();
+
void DrawTotalBK(const CFWL_ThemeBackground& pParams,
const CFX_Matrix& matrix);
void DrawHeadBk(const CFWL_ThemeBackground& pParams,
@@ -37,7 +40,6 @@ class CFWL_MonthCalendarTP final : public CFWL_WidgetTP {
const CFX_Matrix& matrix);
void DrawWeekNumSep(const CFWL_ThemeBackground& pParams,
const CFX_Matrix& matrix);
- FWLTHEME_STATE GetState(uint32_t dwFWLStates);
};
#endif // XFA_FWL_THEME_CFWL_MONTHCALENDARTP_H_
diff --git a/xfa/fwl/theme/cfwl_pictureboxtp.cpp b/xfa/fwl/theme/cfwl_pictureboxtp.cpp
index 39611bd9d..51b3acbe7 100644
--- a/xfa/fwl/theme/cfwl_pictureboxtp.cpp
+++ b/xfa/fwl/theme/cfwl_pictureboxtp.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -10,14 +10,14 @@
#include "xfa/fwl/cfwl_themebackground.h"
#include "xfa/fwl/cfwl_widget.h"
-CFWL_PictureBoxTP::CFWL_PictureBoxTP() {}
+CFWL_PictureBoxTP::CFWL_PictureBoxTP() = default;
-CFWL_PictureBoxTP::~CFWL_PictureBoxTP() {}
+CFWL_PictureBoxTP::~CFWL_PictureBoxTP() = default;
void CFWL_PictureBoxTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
- switch (pParams.m_iPart) {
- case CFWL_Part::Border:
- DrawBorder(pParams.m_pGraphics.Get(), pParams.m_rtPart, pParams.m_matrix);
+ switch (pParams.GetPart()) {
+ case CFWL_ThemePart::Part::kBorder:
+ DrawBorder(pParams.GetGraphics(), pParams.m_PartRect, pParams.m_matrix);
break;
default:
break;
diff --git a/xfa/fwl/theme/cfwl_pictureboxtp.h b/xfa/fwl/theme/cfwl_pictureboxtp.h
index 4bb295aaa..368d90487 100644
--- a/xfa/fwl/theme/cfwl_pictureboxtp.h
+++ b/xfa/fwl/theme/cfwl_pictureboxtp.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,15 +7,19 @@
#ifndef XFA_FWL_THEME_CFWL_PICTUREBOXTP_H_
#define XFA_FWL_THEME_CFWL_PICTUREBOXTP_H_
+#include "fxjs/gc/heap.h"
#include "xfa/fwl/theme/cfwl_widgettp.h"
class CFWL_PictureBoxTP final : public CFWL_WidgetTP {
public:
- CFWL_PictureBoxTP();
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_PictureBoxTP() override;
- // CFWL_WidgetTP
+ // CFWL_WidgetTP:
void DrawBackground(const CFWL_ThemeBackground& pParams) override;
+
+ private:
+ CFWL_PictureBoxTP();
};
#endif // XFA_FWL_THEME_CFWL_PICTUREBOXTP_H_
diff --git a/xfa/fwl/theme/cfwl_pushbuttontp.cpp b/xfa/fwl/theme/cfwl_pushbuttontp.cpp
index 45144b46e..c9b3c25e7 100644
--- a/xfa/fwl/theme/cfwl_pushbuttontp.cpp
+++ b/xfa/fwl/theme/cfwl_pushbuttontp.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,58 +6,59 @@
#include "xfa/fwl/theme/cfwl_pushbuttontp.h"
-#include "core/fxge/render_defines.h"
+#include "xfa/fgas/graphics/cfgas_gecolor.h"
+#include "xfa/fgas/graphics/cfgas_gegraphics.h"
+#include "xfa/fgas/graphics/cfgas_gepath.h"
#include "xfa/fwl/cfwl_pushbutton.h"
#include "xfa/fwl/cfwl_themebackground.h"
#include "xfa/fwl/cfwl_widget.h"
#include "xfa/fwl/ifwl_themeprovider.h"
-#include "xfa/fxgraphics/cxfa_gecolor.h"
-#include "xfa/fxgraphics/cxfa_gepath.h"
-#define PUSHBUTTON_SIZE_Corner 2
+namespace {
+
+constexpr float kPushbuttonSizeCorner = 2.0f;
+
+} // namespace
CFWL_PushButtonTP::CFWL_PushButtonTP() : m_pThemeData(new PBThemeData) {
SetThemeData();
}
-CFWL_PushButtonTP::~CFWL_PushButtonTP() {}
+CFWL_PushButtonTP::~CFWL_PushButtonTP() = default;
void CFWL_PushButtonTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
- switch (pParams.m_iPart) {
- case CFWL_Part::Border: {
- DrawBorder(pParams.m_pGraphics.Get(), pParams.m_rtPart, pParams.m_matrix);
+ switch (pParams.GetPart()) {
+ case CFWL_ThemePart::Part::kBorder: {
+ DrawBorder(pParams.GetGraphics(), pParams.m_PartRect, pParams.m_matrix);
break;
}
- case CFWL_Part::Background: {
- const CFX_RectF& rect = pParams.m_rtPart;
+ case CFWL_ThemePart::Part::kBackground: {
+ const CFX_RectF& rect = pParams.m_PartRect;
float fRight = rect.right();
float fBottom = rect.bottom();
- CXFA_GEPath strokePath;
+ CFGAS_GEPath strokePath;
strokePath.MoveTo(
- CFX_PointF(rect.left + PUSHBUTTON_SIZE_Corner, rect.top));
- strokePath.LineTo(CFX_PointF(fRight - PUSHBUTTON_SIZE_Corner, rect.top));
- strokePath.LineTo(CFX_PointF(fRight, rect.top + PUSHBUTTON_SIZE_Corner));
- strokePath.LineTo(CFX_PointF(fRight, fBottom - PUSHBUTTON_SIZE_Corner));
- strokePath.LineTo(CFX_PointF(fRight - PUSHBUTTON_SIZE_Corner, fBottom));
- strokePath.LineTo(
- CFX_PointF(rect.left + PUSHBUTTON_SIZE_Corner, fBottom));
+ CFX_PointF(rect.left + kPushbuttonSizeCorner, rect.top));
+ strokePath.LineTo(CFX_PointF(fRight - kPushbuttonSizeCorner, rect.top));
+ strokePath.LineTo(CFX_PointF(fRight, rect.top + kPushbuttonSizeCorner));
+ strokePath.LineTo(CFX_PointF(fRight, fBottom - kPushbuttonSizeCorner));
+ strokePath.LineTo(CFX_PointF(fRight - kPushbuttonSizeCorner, fBottom));
+ strokePath.LineTo(CFX_PointF(rect.left + kPushbuttonSizeCorner, fBottom));
+ strokePath.LineTo(CFX_PointF(rect.left, fBottom - kPushbuttonSizeCorner));
strokePath.LineTo(
- CFX_PointF(rect.left, fBottom - PUSHBUTTON_SIZE_Corner));
+ CFX_PointF(rect.left, rect.top + kPushbuttonSizeCorner));
strokePath.LineTo(
- CFX_PointF(rect.left, rect.top + PUSHBUTTON_SIZE_Corner));
- strokePath.LineTo(
- CFX_PointF(rect.left + PUSHBUTTON_SIZE_Corner, rect.top));
-
- CXFA_GEPath fillPath;
- fillPath.AddSubpath(&strokePath);
+ CFX_PointF(rect.left + kPushbuttonSizeCorner, rect.top));
- CXFA_Graphics* pGraphics = pParams.m_pGraphics.Get();
- pGraphics->SaveGraphState();
+ CFGAS_GEPath fillPath;
+ fillPath.AddSubpath(strokePath);
+ CFGAS_GEGraphics* pGraphics = pParams.GetGraphics();
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
CFX_RectF rtInner(rect);
- rtInner.Deflate(PUSHBUTTON_SIZE_Corner + 1, PUSHBUTTON_SIZE_Corner + 1,
- PUSHBUTTON_SIZE_Corner, PUSHBUTTON_SIZE_Corner);
+ rtInner.Deflate(kPushbuttonSizeCorner + 1, kPushbuttonSizeCorner + 1,
+ kPushbuttonSizeCorner, kPushbuttonSizeCorner);
fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width,
rtInner.height);
@@ -65,20 +66,20 @@ void CFWL_PushButtonTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
FillSolidRect(pGraphics, m_pThemeData->clrEnd[iColor], rect,
pParams.m_matrix);
- pGraphics->SetStrokeColor(CXFA_GEColor(m_pThemeData->clrBorder[iColor]));
- pGraphics->StrokePath(&strokePath, &pParams.m_matrix);
+ pGraphics->SetStrokeColor(CFGAS_GEColor(m_pThemeData->clrBorder[iColor]));
+ pGraphics->StrokePath(strokePath, pParams.m_matrix);
fillPath.Clear();
fillPath.AddRectangle(rtInner.left, rtInner.top, rtInner.width,
rtInner.height);
- pGraphics->SetFillColor(CXFA_GEColor(m_pThemeData->clrFill[iColor]));
- pGraphics->FillPath(&fillPath, FXFILL_WINDING, &pParams.m_matrix);
- if (pParams.m_dwStates & CFWL_PartState_Focused) {
+ pGraphics->SetFillColor(CFGAS_GEColor(m_pThemeData->clrFill[iColor]));
+ pGraphics->FillPath(fillPath, CFX_FillRenderOptions::FillType::kWinding,
+ pParams.m_matrix);
+ if (pParams.m_dwStates & CFWL_PartState::kFocused) {
rtInner.Inflate(1, 1, 0, 0);
DrawFocus(pGraphics, rtInner, pParams.m_matrix);
}
- pGraphics->RestoreGraphState();
break;
}
default:
@@ -109,16 +110,16 @@ void CFWL_PushButtonTP::SetThemeData() {
m_pThemeData->clrFill[4] = ArgbEncode(255, 245, 244, 234);
}
-int32_t CFWL_PushButtonTP::GetColorID(uint32_t dwStates) const {
+int32_t CFWL_PushButtonTP::GetColorID(Mask<CFWL_PartState> dwStates) const {
int32_t color = 0;
- if (dwStates & CFWL_PartState_Disabled)
+ if (dwStates & CFWL_PartState::kDisabled)
color += 4;
- if (dwStates & CFWL_PartState_Default) {
+ if (dwStates & CFWL_PartState::kDefault) {
color += 3;
} else {
- if (dwStates & CFWL_PartState_Hovered)
+ if (dwStates & CFWL_PartState::kHovered)
color += 2;
- if (dwStates & CFWL_PartState_Pressed)
+ if (dwStates & CFWL_PartState::kPressed)
color += 1;
}
return color;
diff --git a/xfa/fwl/theme/cfwl_pushbuttontp.h b/xfa/fwl/theme/cfwl_pushbuttontp.h
index c3079dd25..25d3c08b4 100644
--- a/xfa/fwl/theme/cfwl_pushbuttontp.h
+++ b/xfa/fwl/theme/cfwl_pushbuttontp.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,14 +9,16 @@
#include <memory>
+#include "fxjs/gc/heap.h"
+#include "xfa/fwl/cfwl_themepart.h"
#include "xfa/fwl/theme/cfwl_widgettp.h"
class CFWL_PushButtonTP final : public CFWL_WidgetTP {
public:
- CFWL_PushButtonTP();
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_PushButtonTP() override;
- // CFWL_WidgetTP
+ // CFWL_WidgetTP:
void DrawBackground(const CFWL_ThemeBackground& pParams) override;
private:
@@ -27,14 +29,9 @@ class CFWL_PushButtonTP final : public CFWL_WidgetTP {
FX_ARGB clrFill[5];
};
- void SetTopLineColor(uint32_t* pData);
- void SetLeftLineColor(uint32_t* pData);
- void SetRightLineColor(uint32_t* pData);
- void SetBottomLineColor(uint32_t* pData);
- void SetBackgroudColor(uint32_t* pData);
- void SetCaptionColor(uint32_t* pData);
- void SetCornerColor(uint32_t* pData);
- int32_t GetColorID(uint32_t dwStates) const;
+ CFWL_PushButtonTP();
+
+ int32_t GetColorID(Mask<CFWL_PartState> dwStates) const;
void SetThemeData();
std::unique_ptr<PBThemeData> m_pThemeData;
diff --git a/xfa/fwl/theme/cfwl_scrollbartp.cpp b/xfa/fwl/theme/cfwl_scrollbartp.cpp
index 55adc3edb..4d0c6b731 100644
--- a/xfa/fwl/theme/cfwl_scrollbartp.cpp
+++ b/xfa/fwl/theme/cfwl_scrollbartp.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,64 +6,51 @@
#include "xfa/fwl/theme/cfwl_scrollbartp.h"
-#include "core/fxge/render_defines.h"
+#include "xfa/fgas/graphics/cfgas_gecolor.h"
+#include "xfa/fgas/graphics/cfgas_gegraphics.h"
+#include "xfa/fgas/graphics/cfgas_gepath.h"
#include "xfa/fwl/cfwl_scrollbar.h"
#include "xfa/fwl/cfwl_themebackground.h"
#include "xfa/fwl/cfwl_widget.h"
#include "xfa/fwl/ifwl_themeprovider.h"
-#include "xfa/fxgraphics/cxfa_gecolor.h"
-#include "xfa/fxgraphics/cxfa_gepath.h"
-
-namespace {
-
-const float kPawLength = 12.5f;
-
-} // namespace
CFWL_ScrollBarTP::CFWL_ScrollBarTP() : m_pThemeData(new SBThemeData) {
SetThemeData();
}
-CFWL_ScrollBarTP::~CFWL_ScrollBarTP() {}
+CFWL_ScrollBarTP::~CFWL_ScrollBarTP() = default;
void CFWL_ScrollBarTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
- CFWL_Widget* pWidget = pParams.m_pWidget;
- FWLTHEME_STATE eState = FWLTHEME_STATE_Normal;
- if (pParams.m_dwStates & CFWL_PartState_Hovered)
- eState = FWLTHEME_STATE_Hover;
- else if (pParams.m_dwStates & CFWL_PartState_Pressed)
- eState = FWLTHEME_STATE_Pressed;
- else if (pParams.m_dwStates & CFWL_PartState_Disabled)
- eState = FWLTHEME_STATE_Disable;
-
- CXFA_Graphics* pGraphics = pParams.m_pGraphics.Get();
- bool bVert = !!pWidget->GetStylesEx();
- switch (pParams.m_iPart) {
- case CFWL_Part::ForeArrow: {
- DrawMaxMinBtn(pGraphics, pParams.m_rtPart,
- bVert ? FWLTHEME_DIRECTION_Up : FWLTHEME_DIRECTION_Left,
- eState, pParams.m_matrix);
+ CFWL_Widget* pWidget = pParams.GetWidget();
+ CFGAS_GEGraphics* pGraphics = pParams.GetGraphics();
+ bool bVert = !!pWidget->GetStyleExts();
+ switch (pParams.GetPart()) {
+ case CFWL_ThemePart::Part::kForeArrow: {
+ DrawMaxMinBtn(pGraphics, pParams.m_PartRect,
+ bVert ? FWLTHEME_DIRECTION::kUp : FWLTHEME_DIRECTION::kLeft,
+ pParams.GetThemeState(), pParams.m_matrix);
break;
}
- case CFWL_Part::BackArrow: {
- DrawMaxMinBtn(pGraphics, pParams.m_rtPart,
- bVert ? FWLTHEME_DIRECTION_Down : FWLTHEME_DIRECTION_Right,
- eState, pParams.m_matrix);
+ case CFWL_ThemePart::Part::kBackArrow: {
+ DrawMaxMinBtn(
+ pGraphics, pParams.m_PartRect,
+ bVert ? FWLTHEME_DIRECTION::kDown : FWLTHEME_DIRECTION::kRight,
+ pParams.GetThemeState(), pParams.m_matrix);
break;
}
- case CFWL_Part::Thumb: {
- DrawThumbBtn(pGraphics, pParams.m_rtPart, bVert, eState, true,
- pParams.m_matrix);
+ case CFWL_ThemePart::Part::kThumb: {
+ DrawThumbBtn(pGraphics, pParams.m_PartRect, bVert,
+ pParams.GetThemeState(), pParams.m_matrix);
break;
}
- case CFWL_Part::LowerTrack: {
- DrawTrack(pGraphics, pParams.m_rtPart, bVert, eState, true,
- pParams.m_matrix);
+ case CFWL_ThemePart::Part::kLowerTrack: {
+ DrawTrack(pGraphics, pParams.m_PartRect, bVert, pParams.GetThemeState(),
+ true, pParams.m_matrix);
break;
}
- case CFWL_Part::UpperTrack: {
- DrawTrack(pGraphics, pParams.m_rtPart, bVert, eState, false,
- pParams.m_matrix);
+ case CFWL_ThemePart::Part::kUpperTrack: {
+ DrawTrack(pGraphics, pParams.m_PartRect, bVert, pParams.GetThemeState(),
+ false, pParams.m_matrix);
break;
}
default:
@@ -71,13 +58,12 @@ void CFWL_ScrollBarTP::DrawBackground(const CFWL_ThemeBackground& pParams) {
}
}
-void CFWL_ScrollBarTP::DrawThumbBtn(CXFA_Graphics* pGraphics,
+void CFWL_ScrollBarTP::DrawThumbBtn(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& input_rect,
bool bVert,
FWLTHEME_STATE eState,
- bool bPawButton,
const CFX_Matrix& matrix) {
- if (eState < FWLTHEME_STATE_Normal || eState > FWLTHEME_STATE_Disable)
+ if (eState < FWLTHEME_STATE::kNormal || eState > FWLTHEME_STATE::kDisable)
return;
CFX_RectF rect = input_rect;
@@ -89,163 +75,75 @@ void CFWL_ScrollBarTP::DrawThumbBtn(CXFA_Graphics* pGraphics,
if (rect.IsEmpty(0.1f))
return;
- FillSolidRect(pGraphics, m_pThemeData->clrBtnBK[eState - 1][1], rect, matrix);
-
- pGraphics->SaveGraphState();
+ FillSolidRect(pGraphics,
+ m_pThemeData->clrBtnBK[static_cast<size_t>(eState) - 1][1],
+ rect, matrix);
- CXFA_GEPath path;
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ CFGAS_GEPath path;
path.AddRectangle(rect.left, rect.top, rect.width, rect.height);
- pGraphics->SetStrokeColor(
- CXFA_GEColor(m_pThemeData->clrBtnBorder[eState - 1]));
- pGraphics->StrokePath(&path, &matrix);
- pGraphics->RestoreGraphState();
-}
-
-void CFWL_ScrollBarTP::DrawPaw(CXFA_Graphics* pGraphics,
- const CFX_RectF& rect,
- bool bVert,
- FWLTHEME_STATE eState,
- const CFX_Matrix& matrix) {
- CXFA_GEPath path;
- if (bVert) {
- float fPawLen = kPawLength;
- if (rect.width / 2 <= fPawLen) {
- fPawLen = (rect.width - 6) / 2;
- }
-
- float fX = rect.left + rect.width / 4;
- float fY = rect.top + rect.height / 2;
- path.MoveTo(CFX_PointF(fX, fY - 4));
- path.LineTo(CFX_PointF(fX + fPawLen, fY - 4));
- path.MoveTo(CFX_PointF(fX, fY - 2));
- path.LineTo(CFX_PointF(fX + fPawLen, fY - 2));
- path.MoveTo(CFX_PointF(fX, fY));
- path.LineTo(CFX_PointF(fX + fPawLen, fY));
- path.MoveTo(CFX_PointF(fX, fY + 2));
- path.LineTo(CFX_PointF(fX + fPawLen, fY + 2));
-
- pGraphics->SetLineWidth(1);
- pGraphics->SetStrokeColor(
- CXFA_GEColor(m_pThemeData->clrPawColorLight[eState - 1]));
- pGraphics->StrokePath(&path, nullptr);
- fX++;
-
- path.Clear();
- path.MoveTo(CFX_PointF(fX, fY - 3));
- path.LineTo(CFX_PointF(fX + fPawLen, fY - 3));
- path.MoveTo(CFX_PointF(fX, fY - 1));
- path.LineTo(CFX_PointF(fX + fPawLen, fY - 1));
- path.MoveTo(CFX_PointF(fX, fY + 1));
- path.LineTo(CFX_PointF(fX + fPawLen, fY + 1));
- path.MoveTo(CFX_PointF(fX, fY + 3));
- path.LineTo(CFX_PointF(fX + fPawLen, fY + 3));
-
- pGraphics->SetLineWidth(1);
- pGraphics->SetStrokeColor(
- CXFA_GEColor(m_pThemeData->clrPawColorDark[eState - 1]));
- pGraphics->StrokePath(&path, &matrix);
- } else {
- float fPawLen = kPawLength;
- if (rect.height / 2 <= fPawLen) {
- fPawLen = (rect.height - 6) / 2;
- }
-
- float fX = rect.left + rect.width / 2;
- float fY = rect.top + rect.height / 4;
- path.MoveTo(CFX_PointF(fX - 4, fY));
- path.LineTo(CFX_PointF(fX - 4, fY + fPawLen));
- path.MoveTo(CFX_PointF(fX - 2, fY));
- path.LineTo(CFX_PointF(fX - 2, fY + fPawLen));
- path.MoveTo(CFX_PointF(fX, fY));
- path.LineTo(CFX_PointF(fX, fY + fPawLen));
- path.MoveTo(CFX_PointF(fX + 2, fY));
- path.LineTo(CFX_PointF(fX + 2, fY + fPawLen));
-
- pGraphics->SetLineWidth(1);
- pGraphics->SetStrokeColor(
- CXFA_GEColor(m_pThemeData->clrPawColorLight[eState - 1]));
- pGraphics->StrokePath(&path, &matrix);
- fY++;
-
- path.Clear();
- path.MoveTo(CFX_PointF(fX - 3, fY));
- path.LineTo(CFX_PointF(fX - 3, fY + fPawLen));
- path.MoveTo(CFX_PointF(fX - 1, fY));
- path.LineTo(CFX_PointF(fX - 1, fY + fPawLen));
- path.MoveTo(CFX_PointF(fX + 1, fY));
- path.LineTo(CFX_PointF(fX + 1, fY + fPawLen));
- path.MoveTo(CFX_PointF(fX + 3, fY));
- path.LineTo(CFX_PointF(fX + 3, fY + fPawLen));
-
- pGraphics->SetLineWidth(1);
- pGraphics->SetStrokeColor(
- CXFA_GEColor(m_pThemeData->clrPawColorDark[eState - 1]));
- pGraphics->StrokePath(&path, &matrix);
- }
+ pGraphics->SetStrokeColor(CFGAS_GEColor(
+ m_pThemeData->clrBtnBorder[static_cast<size_t>(eState) - 1]));
+ pGraphics->StrokePath(path, matrix);
}
-void CFWL_ScrollBarTP::DrawTrack(CXFA_Graphics* pGraphics,
+void CFWL_ScrollBarTP::DrawTrack(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
bool bVert,
FWLTHEME_STATE eState,
bool bLowerTrack,
const CFX_Matrix& matrix) {
- if (eState < FWLTHEME_STATE_Normal || eState > FWLTHEME_STATE_Disable)
+ if (eState < FWLTHEME_STATE::kNormal || eState > FWLTHEME_STATE::kDisable)
return;
- pGraphics->SaveGraphState();
- CXFA_GEPath path;
- float fRight = rect.right();
- float fBottom = rect.bottom();
- if (bVert) {
- path.AddRectangle(rect.left, rect.top, 1, rect.height);
- path.AddRectangle(fRight - 1, rect.top, 1, rect.height);
- } else {
- path.AddRectangle(rect.left, rect.top, rect.width, 1);
- path.AddRectangle(rect.left, fBottom - 1, rect.width, 1);
+ {
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ CFGAS_GEPath path;
+ float fRight = rect.right();
+ float fBottom = rect.bottom();
+ if (bVert) {
+ path.AddRectangle(rect.left, rect.top, 1, rect.height);
+ path.AddRectangle(fRight - 1, rect.top, 1, rect.height);
+ } else {
+ path.AddRectangle(rect.left, rect.top, rect.width, 1);
+ path.AddRectangle(rect.left, fBottom - 1, rect.width, 1);
+ }
+ pGraphics->SetFillColor(CFGAS_GEColor(ArgbEncode(255, 238, 237, 229)));
+ pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kWinding,
+ matrix);
+ path.Clear();
+ path.AddRectangle(rect.left + 1, rect.top, rect.width - 2, rect.height);
}
- pGraphics->SetFillColor(CXFA_GEColor(ArgbEncode(255, 238, 237, 229)));
- pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
- path.Clear();
- path.AddRectangle(rect.left + 1, rect.top, rect.width - 2, rect.height);
- pGraphics->RestoreGraphState();
FillSolidRect(pGraphics, m_pThemeData->clrTrackBKEnd, rect, matrix);
}
-void CFWL_ScrollBarTP::DrawMaxMinBtn(CXFA_Graphics* pGraphics,
+void CFWL_ScrollBarTP::DrawMaxMinBtn(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
FWLTHEME_DIRECTION eDict,
FWLTHEME_STATE eState,
const CFX_Matrix& matrix) {
- DrawTrack(pGraphics, rect,
- eDict == FWLTHEME_DIRECTION_Up || eDict == FWLTHEME_DIRECTION_Down,
- eState, true, matrix);
+ DrawTrack(
+ pGraphics, rect,
+ eDict == FWLTHEME_DIRECTION::kUp || eDict == FWLTHEME_DIRECTION::kDown,
+ eState, true, matrix);
CFX_RectF rtArrowBtn = rect;
rtArrowBtn.Deflate(1, 1, 1, 1);
DrawArrowBtn(pGraphics, rtArrowBtn, eDict, eState, matrix);
}
void CFWL_ScrollBarTP::SetThemeData() {
- m_pThemeData->clrPawColorLight[3] = ArgbEncode(0xff, 208, 223, 172);
- m_pThemeData->clrPawColorDark[3] = ArgbEncode(0xff, 140, 157, 115);
- m_pThemeData->clrBtnBK[3][0] = ArgbEncode(0xff, 164, 180, 139);
- m_pThemeData->clrBtnBK[3][1] = ArgbEncode(0xff, 141, 157, 115);
- m_pThemeData->clrBtnBorder[3] = ArgbEncode(0xff, 236, 233, 216);
- m_pThemeData->clrPawColorLight[0] = ArgbEncode(0xff, 238, 244, 254);
- m_pThemeData->clrPawColorDark[0] = ArgbEncode(0xff, 140, 176, 248);
+ m_pThemeData->clrTrackBKStart = ArgbEncode(0xff, 243, 241, 236);
+ m_pThemeData->clrTrackBKEnd = ArgbEncode(0xff, 254, 254, 251);
m_pThemeData->clrBtnBK[0][0] = ArgbEncode(0xff, 197, 213, 252);
m_pThemeData->clrBtnBK[0][1] = ArgbEncode(0xff, 182, 205, 251);
- m_pThemeData->clrBtnBorder[0] = ArgbEncode(0xff, 148, 176, 221);
- m_pThemeData->clrPawColorLight[1] = ArgbEncode(0xff, 252, 253, 255);
- m_pThemeData->clrPawColorDark[1] = ArgbEncode(0xff, 156, 197, 255);
m_pThemeData->clrBtnBK[1][0] = ArgbEncode(0xff, 216, 232, 255);
m_pThemeData->clrBtnBK[1][1] = ArgbEncode(0xff, 204, 225, 255);
- m_pThemeData->clrBtnBorder[1] = ArgbEncode(0xff, 218, 230, 254);
- m_pThemeData->clrPawColorLight[2] = ArgbEncode(0xff, 207, 221, 253);
- m_pThemeData->clrPawColorDark[2] = ArgbEncode(0xff, 131, 158, 216);
m_pThemeData->clrBtnBK[2][0] = ArgbEncode(0xff, 167, 190, 245);
m_pThemeData->clrBtnBK[2][1] = ArgbEncode(0xff, 146, 179, 249);
+ m_pThemeData->clrBtnBK[3][0] = ArgbEncode(0xff, 164, 180, 139);
+ m_pThemeData->clrBtnBK[3][1] = ArgbEncode(0xff, 141, 157, 115);
+ m_pThemeData->clrBtnBorder[0] = ArgbEncode(0xff, 148, 176, 221);
+ m_pThemeData->clrBtnBorder[1] = ArgbEncode(0xff, 218, 230, 254);
m_pThemeData->clrBtnBorder[2] = ArgbEncode(0xff, 124, 159, 211);
- m_pThemeData->clrTrackBKStart = ArgbEncode(0xff, 243, 241, 236);
- m_pThemeData->clrTrackBKEnd = ArgbEncode(0xff, 254, 254, 251);
+ m_pThemeData->clrBtnBorder[3] = ArgbEncode(0xff, 236, 233, 216);
}
diff --git a/xfa/fwl/theme/cfwl_scrollbartp.h b/xfa/fwl/theme/cfwl_scrollbartp.h
index f07d102a6..714cf4d10 100644
--- a/xfa/fwl/theme/cfwl_scrollbartp.h
+++ b/xfa/fwl/theme/cfwl_scrollbartp.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,48 +9,43 @@
#include <memory>
+#include "fxjs/gc/heap.h"
#include "xfa/fwl/theme/cfwl_widgettp.h"
class CFWL_ScrollBarTP final : public CFWL_WidgetTP {
public:
- CFWL_ScrollBarTP();
+ CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED;
~CFWL_ScrollBarTP() override;
- // CFWL_WidgetTP
+ // CFWL_WidgetTP:
void DrawBackground(const CFWL_ThemeBackground& pParams) override;
private:
struct SBThemeData {
FX_ARGB clrTrackBKStart;
FX_ARGB clrTrackBKEnd;
- FX_ARGB clrPawColorLight[4];
- FX_ARGB clrPawColorDark[4];
FX_ARGB clrBtnBK[4][2];
FX_ARGB clrBtnBorder[4];
};
- void DrawThumbBtn(CXFA_Graphics* pGraphics,
+ CFWL_ScrollBarTP();
+
+ void DrawThumbBtn(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
bool bVert,
FWLTHEME_STATE eState,
- bool bPawButton,
const CFX_Matrix& matrix);
- void DrawTrack(CXFA_Graphics* pGraphics,
+ void DrawTrack(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
bool bVert,
FWLTHEME_STATE eState,
bool bLowerTrack,
const CFX_Matrix& matrix);
- void DrawMaxMinBtn(CXFA_Graphics* pGraphics,
+ void DrawMaxMinBtn(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
FWLTHEME_DIRECTION eDict,
FWLTHEME_STATE eState,
const CFX_Matrix& matrix);
- void DrawPaw(CXFA_Graphics* pGraphics,
- const CFX_RectF& rect,
- bool bVert,
- FWLTHEME_STATE eState,
- const CFX_Matrix& matrix);
void SetThemeData();
std::unique_ptr<SBThemeData> m_pThemeData;
diff --git a/xfa/fwl/theme/cfwl_utils.h b/xfa/fwl/theme/cfwl_utils.h
index 8aa9a3c30..37bfc50b7 100644
--- a/xfa/fwl/theme/cfwl_utils.h
+++ b/xfa/fwl/theme/cfwl_utils.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,27 +7,14 @@
#ifndef XFA_FWL_THEME_CFWL_UTILS_H_
#define XFA_FWL_THEME_CFWL_UTILS_H_
-#include "core/fxcrt/fx_system.h"
-
-enum FWLTHEME_EDGE {
- FWLTHEME_EDGE_Flat = 0,
- FWLTHEME_EDGE_Raised,
- FWLTHEME_EDGE_Sunken
-};
-
-enum FWLTHEME_STATE {
- FWLTHEME_STATE_Normal = 1,
- FWLTHEME_STATE_Hover,
- FWLTHEME_STATE_Pressed,
- FWLTHEME_STATE_Disable
-};
-
-enum FWLTHEME_DIRECTION {
- FWLTHEME_DIRECTION_Up = 0,
- FWLTHEME_DIRECTION_Down,
- FWLTHEME_DIRECTION_Left,
- FWLTHEME_DIRECTION_Right
-};
+#include <stdint.h>
+
+#include "core/fxge/dib/fx_dib.h"
+
+// Values matter, used for indexing.
+enum class FWLTHEME_STATE : uint8_t { kNormal = 1, kHover, kPressed, kDisable };
+
+enum class FWLTHEME_DIRECTION : uint8_t { kUp = 0, kDown, kLeft, kRight };
#define FWLTHEME_COLOR_EDGERB1 (ArgbEncode(255, 241, 239, 226))
#define FWLTHEME_COLOR_Background (ArgbEncode(255, 236, 233, 216))
diff --git a/xfa/fwl/theme/cfwl_widgettp.cpp b/xfa/fwl/theme/cfwl_widgettp.cpp
index 27caf99da..8a265fe01 100644
--- a/xfa/fwl/theme/cfwl_widgettp.cpp
+++ b/xfa/fwl/theme/cfwl_widgettp.cpp
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -9,60 +9,47 @@
#include <algorithm>
#include <utility>
-#include "core/fxge/render_defines.h"
-#include "third_party/base/ptr_util.h"
#include "xfa/fde/cfde_textout.h"
-#include "xfa/fgas/font/cfgas_fontmgr.h"
#include "xfa/fgas/font/cfgas_gefont.h"
+#include "xfa/fgas/graphics/cfgas_gecolor.h"
+#include "xfa/fgas/graphics/cfgas_gegraphics.h"
+#include "xfa/fgas/graphics/cfgas_gepath.h"
#include "xfa/fwl/cfwl_themebackground.h"
#include "xfa/fwl/cfwl_themepart.h"
#include "xfa/fwl/cfwl_themetext.h"
#include "xfa/fwl/cfwl_widget.h"
#include "xfa/fwl/cfwl_widgetmgr.h"
#include "xfa/fwl/ifwl_themeprovider.h"
-#include "xfa/fxgraphics/cxfa_gecolor.h"
-#include "xfa/fxgraphics/cxfa_gepath.h"
-#include "xfa/fxgraphics/cxfa_geshading.h"
-
-namespace {
-
-CFWL_FontManager* g_FontManager = nullptr;
-
-} // namespace
CFWL_WidgetTP::CFWL_WidgetTP() = default;
CFWL_WidgetTP::~CFWL_WidgetTP() = default;
+void CFWL_WidgetTP::Trace(cppgc::Visitor* visitor) const {}
+
void CFWL_WidgetTP::DrawBackground(const CFWL_ThemeBackground& pParams) {}
void CFWL_WidgetTP::DrawText(const CFWL_ThemeText& pParams) {
- EnsureTTOInitialized();
- int32_t iLen = pParams.m_wsText.GetLength();
- if (iLen <= 0)
+ EnsureTTOInitialized(pParams.GetWidget()->GetThemeProvider());
+ if (pParams.m_wsText.IsEmpty())
return;
- CXFA_Graphics* pGraphics = pParams.m_pGraphics;
+ CFGAS_GEGraphics* pGraphics = pParams.GetGraphics();
m_pTextOut->SetStyles(pParams.m_dwTTOStyles);
m_pTextOut->SetAlignment(pParams.m_iTTOAlign);
CFX_Matrix matrix = pParams.m_matrix;
matrix.Concat(*pGraphics->GetMatrix());
m_pTextOut->SetMatrix(matrix);
- m_pTextOut->DrawLogicText(pGraphics->GetRenderDevice(),
- WideStringView(pParams.m_wsText.c_str(), iLen),
- pParams.m_rtPart);
-}
-
-const RetainPtr<CFGAS_GEFont>& CFWL_WidgetTP::GetFont() const {
- return m_pFDEFont;
+ m_pTextOut->DrawLogicText(pGraphics->GetRenderDevice(), pParams.m_wsText,
+ pParams.m_PartRect);
}
void CFWL_WidgetTP::InitializeArrowColorData() {
if (m_pColorData)
return;
- m_pColorData = pdfium::MakeUnique<CColorData>();
+ m_pColorData = std::make_unique<CColorData>();
m_pColorData->clrBorder[0] = ArgbEncode(255, 202, 216, 249);
m_pColorData->clrBorder[1] = ArgbEncode(255, 171, 190, 233);
m_pColorData->clrBorder[2] = ArgbEncode(255, 135, 147, 219);
@@ -81,82 +68,81 @@ void CFWL_WidgetTP::InitializeArrowColorData() {
m_pColorData->clrSign[3] = ArgbEncode(255, 128, 128, 128);
}
-void CFWL_WidgetTP::EnsureTTOInitialized() {
+void CFWL_WidgetTP::EnsureTTOInitialized(IFWL_ThemeProvider* pProvider) {
if (m_pTextOut)
return;
- m_pFDEFont = CFWL_FontManager::GetInstance()->FindFont(L"Helvetica", 0, 0);
- m_pTextOut = pdfium::MakeUnique<CFDE_TextOut>();
- m_pTextOut->SetFont(m_pFDEFont);
+ m_pTextOut = std::make_unique<CFDE_TextOut>();
+ m_pTextOut->SetFont(pProvider->GetFWLFont());
m_pTextOut->SetFontSize(FWLTHEME_CAPACITY_FontSize);
m_pTextOut->SetTextColor(FWLTHEME_CAPACITY_TextColor);
}
-void CFWL_WidgetTP::DrawBorder(CXFA_Graphics* pGraphics,
+void CFWL_WidgetTP::DrawBorder(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
const CFX_Matrix& matrix) {
if (!pGraphics)
return;
- CXFA_GEPath path;
+ CFGAS_GEPath path;
path.AddRectangle(rect.left, rect.top, rect.width, rect.height);
path.AddRectangle(rect.left + 1, rect.top + 1, rect.width - 2,
rect.height - 2);
- pGraphics->SaveGraphState();
- pGraphics->SetFillColor(CXFA_GEColor(ArgbEncode(255, 0, 0, 0)));
- pGraphics->FillPath(&path, FXFILL_ALTERNATE, &matrix);
- pGraphics->RestoreGraphState();
+
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ pGraphics->SetFillColor(CFGAS_GEColor(ArgbEncode(255, 0, 0, 0)));
+ pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kEvenOdd, matrix);
}
-void CFWL_WidgetTP::FillBackground(CXFA_Graphics* pGraphics,
+void CFWL_WidgetTP::FillBackground(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
const CFX_Matrix& matrix) {
FillSolidRect(pGraphics, FWLTHEME_COLOR_Background, rect, matrix);
}
-void CFWL_WidgetTP::FillSolidRect(CXFA_Graphics* pGraphics,
+void CFWL_WidgetTP::FillSolidRect(CFGAS_GEGraphics* pGraphics,
FX_ARGB fillColor,
const CFX_RectF& rect,
const CFX_Matrix& matrix) {
if (!pGraphics)
return;
- CXFA_GEPath path;
+ CFGAS_GEPath path;
path.AddRectangle(rect.left, rect.top, rect.width, rect.height);
- pGraphics->SaveGraphState();
- pGraphics->SetFillColor(CXFA_GEColor(fillColor));
- pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
- pGraphics->RestoreGraphState();
+
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ pGraphics->SetFillColor(CFGAS_GEColor(fillColor));
+ pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kWinding, matrix);
}
-void CFWL_WidgetTP::DrawFocus(CXFA_Graphics* pGraphics,
+void CFWL_WidgetTP::DrawFocus(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
const CFX_Matrix& matrix) {
if (!pGraphics)
return;
- CXFA_GEPath path;
+ CFGAS_GEPath path;
path.AddRectangle(rect.left, rect.top, rect.width, rect.height);
- pGraphics->SaveGraphState();
- pGraphics->SetStrokeColor(CXFA_GEColor(0xFF000000));
+
+ CFGAS_GEGraphics::StateRestorer restorer(pGraphics);
+ pGraphics->SetStrokeColor(CFGAS_GEColor(0xFF000000));
static constexpr float kDashPattern[2] = {1, 1};
- pGraphics->SetLineDash(0.0f, kDashPattern, FX_ArraySize(kDashPattern));
- pGraphics->StrokePath(&path, &matrix);
- pGraphics->RestoreGraphState();
+ pGraphics->SetLineDash(0.0f, kDashPattern);
+ pGraphics->StrokePath(path, matrix);
}
-void CFWL_WidgetTP::DrawArrow(CXFA_Graphics* pGraphics,
+void CFWL_WidgetTP::DrawArrow(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
FWLTHEME_DIRECTION eDict,
FX_ARGB argSign,
const CFX_Matrix& matrix) {
bool bVert =
- (eDict == FWLTHEME_DIRECTION_Up || eDict == FWLTHEME_DIRECTION_Down);
+ (eDict == FWLTHEME_DIRECTION::kUp || eDict == FWLTHEME_DIRECTION::kDown);
float fLeft = ((rect.width - (bVert ? 9 : 6)) / 2 + rect.left) + 0.5f;
float fTop = ((rect.height - (bVert ? 6 : 9)) / 2 + rect.top) + 0.5f;
- CXFA_GEPath path;
+ CFGAS_GEPath path;
switch (eDict) {
- case FWLTHEME_DIRECTION_Down: {
+ case FWLTHEME_DIRECTION::kDown:
path.MoveTo(CFX_PointF(fLeft, fTop + 1));
path.LineTo(CFX_PointF(fLeft + 4, fTop + 5));
path.LineTo(CFX_PointF(fLeft + 8, fTop + 1));
@@ -164,8 +150,7 @@ void CFWL_WidgetTP::DrawArrow(CXFA_Graphics* pGraphics,
path.LineTo(CFX_PointF(fLeft + 4, fTop + 3));
path.LineTo(CFX_PointF(fLeft + 1, fTop));
break;
- }
- case FWLTHEME_DIRECTION_Up: {
+ case FWLTHEME_DIRECTION::kUp:
path.MoveTo(CFX_PointF(fLeft, fTop + 4));
path.LineTo(CFX_PointF(fLeft + 4, fTop));
path.LineTo(CFX_PointF(fLeft + 8, fTop + 4));
@@ -173,8 +158,7 @@ void CFWL_WidgetTP::DrawArrow(CXFA_Graphics* pGraphics,
path.LineTo(CFX_PointF(fLeft + 4, fTop + 2));
path.LineTo(CFX_PointF(fLeft + 1, fTop + 5));
break;
- }
- case FWLTHEME_DIRECTION_Right: {
+ case FWLTHEME_DIRECTION::kRight:
path.MoveTo(CFX_PointF(fLeft + 1, fTop));
path.LineTo(CFX_PointF(fLeft + 5, fTop + 4));
path.LineTo(CFX_PointF(fLeft + 1, fTop + 8));
@@ -182,8 +166,7 @@ void CFWL_WidgetTP::DrawArrow(CXFA_Graphics* pGraphics,
path.LineTo(CFX_PointF(fLeft + 3, fTop + 4));
path.LineTo(CFX_PointF(fLeft, fTop + 1));
break;
- }
- case FWLTHEME_DIRECTION_Left: {
+ case FWLTHEME_DIRECTION::kLeft:
path.MoveTo(CFX_PointF(fLeft, fTop + 4));
path.LineTo(CFX_PointF(fLeft + 4, fTop));
path.LineTo(CFX_PointF(fLeft + 5, fTop + 1));
@@ -191,95 +174,34 @@ void CFWL_WidgetTP::DrawArrow(CXFA_Graphics* pGraphics,
path.LineTo(CFX_PointF(fLeft + 5, fTop + 7));
path.LineTo(CFX_PointF(fLeft + 4, fTop + 8));
break;
- }
}
- pGraphics->SetFillColor(CXFA_GEColor(argSign));
- pGraphics->FillPath(&path, FXFILL_WINDING, &matrix);
+ pGraphics->SetFillColor(CFGAS_GEColor(argSign));
+ pGraphics->FillPath(path, CFX_FillRenderOptions::FillType::kWinding, matrix);
}
-void CFWL_WidgetTP::DrawBtn(CXFA_Graphics* pGraphics,
+void CFWL_WidgetTP::DrawBtn(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
FWLTHEME_STATE eState,
const CFX_Matrix& matrix) {
InitializeArrowColorData();
- FillSolidRect(pGraphics, m_pColorData->clrEnd[eState - 1], rect, matrix);
+ FillSolidRect(pGraphics,
+ m_pColorData->clrEnd[static_cast<size_t>(eState) - 1], rect,
+ matrix);
- CXFA_GEPath path;
+ CFGAS_GEPath path;
path.AddRectangle(rect.left, rect.top, rect.width, rect.height);
- pGraphics->SetStrokeColor(CXFA_GEColor(m_pColorData->clrBorder[eState - 1]));
- pGraphics->StrokePath(&path, &matrix);
+ pGraphics->SetStrokeColor(
+ CFGAS_GEColor(m_pColorData->clrBorder[static_cast<size_t>(eState) - 1]));
+ pGraphics->StrokePath(path, matrix);
}
-void CFWL_WidgetTP::DrawArrowBtn(CXFA_Graphics* pGraphics,
+void CFWL_WidgetTP::DrawArrowBtn(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
FWLTHEME_DIRECTION eDict,
FWLTHEME_STATE eState,
const CFX_Matrix& matrix) {
DrawBtn(pGraphics, rect, eState, matrix);
InitializeArrowColorData();
- DrawArrow(pGraphics, rect, eDict, m_pColorData->clrSign[eState - 1], matrix);
-}
-
-CFWL_FontData::CFWL_FontData() : m_dwStyles(0), m_dwCodePage(0) {}
-
-CFWL_FontData::~CFWL_FontData() {}
-
-bool CFWL_FontData::Equal(WideStringView wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t wCodePage) {
- return m_wsFamily == wsFontFamily && m_dwStyles == dwFontStyles &&
- m_dwCodePage == wCodePage;
-}
-
-bool CFWL_FontData::LoadFont(WideStringView wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t dwCodePage) {
- m_wsFamily = wsFontFamily;
- m_dwStyles = dwFontStyles;
- m_dwCodePage = dwCodePage;
- if (!m_pFontMgr) {
- m_pFontMgr = pdfium::MakeUnique<CFGAS_FontMgr>();
- if (!m_pFontMgr->EnumFonts())
- m_pFontMgr = nullptr;
- }
-
- // TODO(tsepez): check usage of c_str() below.
- m_pFont = CFGAS_GEFont::LoadFont(wsFontFamily.unterminated_c_str(),
- dwFontStyles, dwCodePage, m_pFontMgr.get());
- return !!m_pFont;
-}
-
-RetainPtr<CFGAS_GEFont> CFWL_FontData::GetFont() const {
- return m_pFont;
-}
-
-CFWL_FontManager* CFWL_FontManager::GetInstance() {
- if (!g_FontManager)
- g_FontManager = new CFWL_FontManager;
- return g_FontManager;
-}
-
-void CFWL_FontManager::DestroyInstance() {
- delete g_FontManager;
- g_FontManager = nullptr;
+ DrawArrow(pGraphics, rect, eDict,
+ m_pColorData->clrSign[static_cast<size_t>(eState) - 1], matrix);
}
-
-CFWL_FontManager::CFWL_FontManager() = default;
-
-CFWL_FontManager::~CFWL_FontManager() = default;
-
-RetainPtr<CFGAS_GEFont> CFWL_FontManager::FindFont(WideStringView wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t wCodePage) {
- for (const auto& pData : m_FontsArray) {
- if (pData->Equal(wsFontFamily, dwFontStyles, wCodePage))
- return pData->GetFont();
- }
- auto pFontData = pdfium::MakeUnique<CFWL_FontData>();
- if (!pFontData->LoadFont(wsFontFamily, dwFontStyles, wCodePage))
- return nullptr;
-
- m_FontsArray.push_back(std::move(pFontData));
- return m_FontsArray.back()->GetFont();
-}
-
diff --git a/xfa/fwl/theme/cfwl_widgettp.h b/xfa/fwl/theme/cfwl_widgettp.h
index c4fa61a8d..cbb2896e4 100644
--- a/xfa/fwl/theme/cfwl_widgettp.h
+++ b/xfa/fwl/theme/cfwl_widgettp.h
@@ -1,4 +1,4 @@
-// Copyright 2014 PDFium Authors. All rights reserved.
+// Copyright 2014 The PDFium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,110 +8,73 @@
#define XFA_FWL_THEME_CFWL_WIDGETTP_H_
#include <memory>
-#include <vector>
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxcrt/retain_ptr.h"
+#include "core/fxge/dib/fx_dib.h"
+#include "v8/include/cppgc/garbage-collected.h"
#include "xfa/fwl/theme/cfwl_utils.h"
-#include "xfa/fxgraphics/cxfa_graphics.h"
class CFDE_TextOut;
-class CFGAS_FontMgr;
-class CFGAS_GEFont;
+class CFGAS_GEGraphics;
class CFWL_ThemeBackground;
class CFWL_ThemeText;
+class IFWL_ThemeProvider;
-class CFWL_WidgetTP {
+class CFWL_WidgetTP : public cppgc::GarbageCollected<CFWL_WidgetTP> {
public:
virtual ~CFWL_WidgetTP();
virtual void DrawBackground(const CFWL_ThemeBackground& pParams);
virtual void DrawText(const CFWL_ThemeText& pParams);
- const RetainPtr<CFGAS_GEFont>& GetFont() const;
+ // Non-virtual, nothing to trace in subclasses at present.
+ void Trace(cppgc::Visitor* visitor) const;
protected:
struct CColorData {
- FX_ARGB clrBorder[4];
- FX_ARGB clrStart[4];
- FX_ARGB clrEnd[4];
- FX_ARGB clrSign[4];
+ FX_ARGB clrBorder[4]; // Indexed by enum FWLTHEME_STATE - 1.
+ FX_ARGB clrStart[4]; // Indexed by enum FWLTHEME_STATE - 1.
+ FX_ARGB clrEnd[4]; // Indexed by enum FWLTHEME_STATE - 1.
+ FX_ARGB clrSign[4]; // Indexed by enum FWLTHEME_STATE - 1.
};
CFWL_WidgetTP();
void InitializeArrowColorData();
- void EnsureTTOInitialized();
+ void EnsureTTOInitialized(IFWL_ThemeProvider* pProvider);
- void DrawBorder(CXFA_Graphics* pGraphics,
+ void DrawBorder(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
const CFX_Matrix& matrix);
- void FillBackground(CXFA_Graphics* pGraphics,
+ void FillBackground(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
const CFX_Matrix& matrix);
- void FillSolidRect(CXFA_Graphics* pGraphics,
+ void FillSolidRect(CFGAS_GEGraphics* pGraphics,
FX_ARGB fillColor,
const CFX_RectF& rect,
const CFX_Matrix& matrix);
- void DrawFocus(CXFA_Graphics* pGraphics,
+ void DrawFocus(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
const CFX_Matrix& matrix);
- void DrawArrow(CXFA_Graphics* pGraphics,
+ void DrawArrow(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
FWLTHEME_DIRECTION eDict,
FX_ARGB argSign,
const CFX_Matrix& matrix);
- void DrawBtn(CXFA_Graphics* pGraphics,
+ void DrawBtn(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
FWLTHEME_STATE eState,
const CFX_Matrix& matrix);
- void DrawArrowBtn(CXFA_Graphics* pGraphics,
+ void DrawArrowBtn(CFGAS_GEGraphics* pGraphics,
const CFX_RectF& rect,
FWLTHEME_DIRECTION eDict,
FWLTHEME_STATE eState,
const CFX_Matrix& matrix);
std::unique_ptr<CFDE_TextOut> m_pTextOut;
- RetainPtr<CFGAS_GEFont> m_pFDEFont;
std::unique_ptr<CColorData> m_pColorData;
};
-class CFWL_FontData final {
- public:
- CFWL_FontData();
- ~CFWL_FontData();
-
- bool Equal(WideStringView wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t wCodePage);
- bool LoadFont(WideStringView wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t wCodePage);
- RetainPtr<CFGAS_GEFont> GetFont() const;
-
- protected:
- WideString m_wsFamily;
- uint32_t m_dwStyles;
- uint32_t m_dwCodePage;
- std::unique_ptr<CFGAS_FontMgr> m_pFontMgr;
- RetainPtr<CFGAS_GEFont> m_pFont;
-};
-
-class CFWL_FontManager final {
- public:
- static CFWL_FontManager* GetInstance();
- static void DestroyInstance();
-
- RetainPtr<CFGAS_GEFont> FindFont(WideStringView wsFontFamily,
- uint32_t dwFontStyles,
- uint16_t dwCodePage);
-
- private:
- CFWL_FontManager();
- ~CFWL_FontManager();
-
- std::vector<std::unique_ptr<CFWL_FontData>> m_FontsArray;
-};
-
#endif // XFA_FWL_THEME_CFWL_WIDGETTP_H_