Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2068)

Unified Diff: core/src/fpdfdoc/doc_formcontrol.cpp

Issue 1432863004: Cleanup CPDF_ApSettings and CJS_Parameters. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: core/src/fpdfdoc/doc_formcontrol.cpp
diff --git a/core/src/fpdfdoc/doc_formcontrol.cpp b/core/src/fpdfdoc/doc_formcontrol.cpp
index 35329f9e059023f27287b7542fe77900850e2fa1..0ba748da490b4e977b569c332517d8e5f8234429 100644
--- a/core/src/fpdfdoc/doc_formcontrol.cpp
+++ b/core/src/fpdfdoc/doc_formcontrol.cpp
@@ -188,56 +188,48 @@ CPDF_FormControl::HighlightingMode CPDF_FormControl::GetHighlightingMode() {
}
return Invert;
}
-CPDF_ApSettings CPDF_FormControl::GetMK(FX_BOOL bCreate) {
Tom Sepez 2015/11/10 17:28:04 Confirmed bCreate is always passed as FALSE.
Lei Zhang 2015/11/11 02:27:56 Acknowledged.
- if (!m_pWidgetDict) {
- return NULL;
- }
- CPDF_ApSettings mk = m_pWidgetDict->GetDict(FX_BSTRC("MK"));
- if (!mk && bCreate) {
- mk = CPDF_Dictionary::Create();
- if (mk == NULL) {
- return NULL;
- }
- m_pWidgetDict->SetAt(FX_BSTRC("MK"), mk);
- }
- return mk;
+
+CPDF_ApSettings CPDF_FormControl::GetMK() {
+ return CPDF_ApSettings(m_pWidgetDict ? m_pWidgetDict->GetDict(FX_BSTRC("MK"))
+ : nullptr);
}
+
FX_BOOL CPDF_FormControl::HasMKEntry(CFX_ByteString csEntry) {
- CPDF_ApSettings mk = GetMK(FALSE);
+ CPDF_ApSettings mk = GetMK();
Tom Sepez 2015/11/10 17:28:04 nit: how about just return GetMK().GetRotation();
Lei Zhang 2015/11/11 02:27:55 Done.
return mk.HasMKEntry(csEntry);
}
int CPDF_FormControl::GetRotation() {
- CPDF_ApSettings mk = GetMK(FALSE);
+ CPDF_ApSettings mk = GetMK();
return mk.GetRotation();
}
FX_ARGB CPDF_FormControl::GetColor(int& iColorType, CFX_ByteString csEntry) {
- CPDF_ApSettings mk = GetMK(FALSE);
+ CPDF_ApSettings mk = GetMK();
return mk.GetColor(iColorType, csEntry);
}
FX_FLOAT CPDF_FormControl::GetOriginalColor(int index, CFX_ByteString csEntry) {
- CPDF_ApSettings mk = GetMK(FALSE);
+ CPDF_ApSettings mk = GetMK();
return mk.GetOriginalColor(index, csEntry);
}
void CPDF_FormControl::GetOriginalColor(int& iColorType,
FX_FLOAT fc[4],
CFX_ByteString csEntry) {
- CPDF_ApSettings mk = GetMK(FALSE);
+ CPDF_ApSettings mk = GetMK();
mk.GetOriginalColor(iColorType, fc, csEntry);
}
CFX_WideString CPDF_FormControl::GetCaption(CFX_ByteString csEntry) {
- CPDF_ApSettings mk = GetMK(FALSE);
+ CPDF_ApSettings mk = GetMK();
return mk.GetCaption(csEntry);
}
CPDF_Stream* CPDF_FormControl::GetIcon(CFX_ByteString csEntry) {
- CPDF_ApSettings mk = GetMK(FALSE);
+ CPDF_ApSettings mk = GetMK();
return mk.GetIcon(csEntry);
}
CPDF_IconFit CPDF_FormControl::GetIconFit() {
- CPDF_ApSettings mk = GetMK(FALSE);
+ CPDF_ApSettings mk = GetMK();
return mk.GetIconFit();
}
int CPDF_FormControl::GetTextPosition() {
- CPDF_ApSettings mk = GetMK(FALSE);
+ CPDF_ApSettings mk = GetMK();
return mk.GetTextPosition();
}
CPDF_Action CPDF_FormControl::GetAction() {
@@ -330,29 +322,28 @@ int CPDF_FormControl::GetControlAlignment() {
}
return pObj->GetInteger();
}
-FX_BOOL CPDF_ApSettings::HasMKEntry(const CFX_ByteStringC& csEntry) {
- if (m_pDict == NULL) {
- return FALSE;
- }
- return m_pDict->KeyExist(csEntry);
+
+CPDF_ApSettings::CPDF_ApSettings(CPDF_Dictionary* pDict) : m_pDict(pDict) {}
+
+FX_BOOL CPDF_ApSettings::HasMKEntry(const CFX_ByteStringC& csEntry) const {
Tom Sepez 2015/11/10 17:28:04 can this be just bool?
Lei Zhang 2015/11/11 02:27:55 Done.
+ return m_pDict ? m_pDict->KeyExist(csEntry) : FALSE;
Tom Sepez 2015/11/10 17:28:04 nit: just return m_pDict && m_pDict->KeyExit(csEnt
Lei Zhang 2015/11/11 02:27:55 Done.
}
-int CPDF_ApSettings::GetRotation() {
- if (m_pDict == NULL) {
- return 0;
- }
- return m_pDict->GetInteger(FX_BSTRC("R"));
+
+int CPDF_ApSettings::GetRotation() const {
+ return m_pDict ? m_pDict->GetInteger(FX_BSTRC("R")) : 0;
}
+
FX_ARGB CPDF_ApSettings::GetColor(int& iColorType,
- const CFX_ByteStringC& csEntry) {
+ const CFX_ByteStringC& csEntry) const {
iColorType = COLORTYPE_TRANSPARENT;
- if (m_pDict == NULL) {
+ if (!m_pDict)
return 0;
- }
- FX_ARGB color = 0;
+
CPDF_Array* pEntry = m_pDict->GetArray(csEntry);
- if (pEntry == NULL) {
- return color;
- }
+ if (!pEntry)
+ return 0;
+
+ FX_ARGB color = 0;
FX_DWORD dwCount = pEntry->GetCount();
if (dwCount == 1) {
iColorType = COLORTYPE_GRAY;
@@ -377,20 +368,20 @@ FX_ARGB CPDF_ApSettings::GetColor(int& iColorType,
}
return color;
}
-FX_FLOAT CPDF_ApSettings::GetOriginalColor(int index,
- const CFX_ByteStringC& csEntry) {
- if (m_pDict == NULL) {
+
+FX_FLOAT CPDF_ApSettings::GetOriginalColor(
+ int index,
+ const CFX_ByteStringC& csEntry) const {
+ if (!m_pDict)
return 0;
- }
+
CPDF_Array* pEntry = m_pDict->GetArray(csEntry);
- if (pEntry != NULL) {
- return pEntry->GetNumber(index);
- }
- return 0;
+ return pEntry ? pEntry->GetNumber(index) : 0;
}
+
void CPDF_ApSettings::GetOriginalColor(int& iColorType,
FX_FLOAT fc[4],
- const CFX_ByteStringC& csEntry) {
+ const CFX_ByteStringC& csEntry) const {
iColorType = COLORTYPE_TRANSPARENT;
for (int i = 0; i < 4; i++) {
fc[i] = 0;
@@ -419,28 +410,21 @@ void CPDF_ApSettings::GetOriginalColor(int& iColorType,
fc[3] = pEntry->GetNumber(3);
}
}
-CFX_WideString CPDF_ApSettings::GetCaption(const CFX_ByteStringC& csEntry) {
- CFX_WideString csCaption;
- if (m_pDict == NULL) {
- return csCaption;
- }
- return m_pDict->GetUnicodeText(csEntry);
+
+CFX_WideString CPDF_ApSettings::GetCaption(
+ const CFX_ByteStringC& csEntry) const {
+ return m_pDict ? m_pDict->GetUnicodeText(csEntry) : CFX_WideString();
}
-CPDF_Stream* CPDF_ApSettings::GetIcon(const CFX_ByteStringC& csEntry) {
- if (m_pDict == NULL) {
- return NULL;
- }
- return m_pDict->GetStream(csEntry);
+
+CPDF_Stream* CPDF_ApSettings::GetIcon(const CFX_ByteStringC& csEntry) const {
+ return m_pDict ? m_pDict->GetStream(csEntry) : nullptr;
}
-CPDF_IconFit CPDF_ApSettings::GetIconFit() {
- if (m_pDict == NULL) {
- return NULL;
- }
- return m_pDict->GetDict(FX_BSTRC("IF"));
+
+CPDF_IconFit CPDF_ApSettings::GetIconFit() const {
+ return m_pDict ? m_pDict->GetDict(FX_BSTRC("IF")) : nullptr;
}
-int CPDF_ApSettings::GetTextPosition() {
- if (m_pDict == NULL) {
- return TEXTPOS_CAPTION;
- }
- return m_pDict->GetInteger(FX_BSTRC("TP"), TEXTPOS_CAPTION);
+
+int CPDF_ApSettings::GetTextPosition() const {
+ return m_pDict ? m_pDict->GetInteger(FX_BSTRC("TP"), TEXTPOS_CAPTION)
+ : TEXTPOS_CAPTION;
}

Powered by Google App Engine
This is Rietveld 408576698