summaryrefslogtreecommitdiff
path: root/core/fpdfdoc/cpdf_annot.cpp
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-12-13 10:28:47 -0800
committerCommit bot <commit-bot@chromium.org>2016-12-13 10:28:47 -0800
commit05b4fc1227f5b6d39a3a65daf915a92ea3b749f4 (patch)
tree681b1f98593fb3923b46dff4f58a627aeb131d40 /core/fpdfdoc/cpdf_annot.cpp
parent8df02348924f66e14131aa378abc6c6ea7a352b6 (diff)
downloadpdfium-05b4fc1227f5b6d39a3a65daf915a92ea3b749f4.tar.xz
Use CFX_MaybeOwned<> in CPDF_Annot.
Avoid another unique_ptr release and a separate flag. Review-Url: https://codereview.chromium.org/2570913002
Diffstat (limited to 'core/fpdfdoc/cpdf_annot.cpp')
-rw-r--r--core/fpdfdoc/cpdf_annot.cpp35
1 files changed, 16 insertions, 19 deletions
diff --git a/core/fpdfdoc/cpdf_annot.cpp b/core/fpdfdoc/cpdf_annot.cpp
index 70c6b8d3c4..38e5b5fc8b 100644
--- a/core/fpdfdoc/cpdf_annot.cpp
+++ b/core/fpdfdoc/cpdf_annot.cpp
@@ -63,20 +63,16 @@ CPDF_Form* AnnotGetMatrix(const CPDF_Page* pPage,
CPDF_Annot::CPDF_Annot(std::unique_ptr<CPDF_Dictionary> pDict,
CPDF_Document* pDocument)
- : m_bOwnedAnnotDict(true),
- m_pAnnotDict(pDict.release()),
- m_pDocument(pDocument) {
+ : m_pAnnotDict(std::move(pDict)), m_pDocument(pDocument) {
Init();
}
CPDF_Annot::CPDF_Annot(CPDF_Dictionary* pDict, CPDF_Document* pDocument)
- : m_bOwnedAnnotDict(false), m_pAnnotDict(pDict), m_pDocument(pDocument) {
+ : m_pAnnotDict(pDict), m_pDocument(pDocument) {
Init();
}
CPDF_Annot::~CPDF_Annot() {
- if (m_bOwnedAnnotDict)
- delete m_pAnnotDict;
ClearCachedAP();
}
@@ -88,28 +84,29 @@ void CPDF_Annot::Init() {
}
void CPDF_Annot::GenerateAPIfNeeded() {
- if (!ShouldGenerateAPForAnnotation(m_pAnnotDict))
+ if (!ShouldGenerateAPForAnnotation(m_pAnnotDict.Get()))
return;
+ CPDF_Dictionary* pDict = m_pAnnotDict.Get();
bool result = false;
if (m_nSubtype == CPDF_Annot::Subtype::CIRCLE)
- result = CPVT_GenerateAP::GenerateCircleAP(m_pDocument, m_pAnnotDict);
+ result = CPVT_GenerateAP::GenerateCircleAP(m_pDocument, pDict);
else if (m_nSubtype == CPDF_Annot::Subtype::HIGHLIGHT)
- result = CPVT_GenerateAP::GenerateHighlightAP(m_pDocument, m_pAnnotDict);
+ result = CPVT_GenerateAP::GenerateHighlightAP(m_pDocument, pDict);
else if (m_nSubtype == CPDF_Annot::Subtype::INK)
- result = CPVT_GenerateAP::GenerateInkAP(m_pDocument, m_pAnnotDict);
+ result = CPVT_GenerateAP::GenerateInkAP(m_pDocument, pDict);
else if (m_nSubtype == CPDF_Annot::Subtype::POPUP)
- result = CPVT_GenerateAP::GeneratePopupAP(m_pDocument, m_pAnnotDict);
+ result = CPVT_GenerateAP::GeneratePopupAP(m_pDocument, pDict);
else if (m_nSubtype == CPDF_Annot::Subtype::SQUARE)
- result = CPVT_GenerateAP::GenerateSquareAP(m_pDocument, m_pAnnotDict);
+ result = CPVT_GenerateAP::GenerateSquareAP(m_pDocument, pDict);
else if (m_nSubtype == CPDF_Annot::Subtype::SQUIGGLY)
- result = CPVT_GenerateAP::GenerateSquigglyAP(m_pDocument, m_pAnnotDict);
+ result = CPVT_GenerateAP::GenerateSquigglyAP(m_pDocument, pDict);
else if (m_nSubtype == CPDF_Annot::Subtype::STRIKEOUT)
- result = CPVT_GenerateAP::GenerateStrikeOutAP(m_pDocument, m_pAnnotDict);
+ result = CPVT_GenerateAP::GenerateStrikeOutAP(m_pDocument, pDict);
else if (m_nSubtype == CPDF_Annot::Subtype::TEXT)
- result = CPVT_GenerateAP::GenerateTextAP(m_pDocument, m_pAnnotDict);
+ result = CPVT_GenerateAP::GenerateTextAP(m_pDocument, pDict);
else if (m_nSubtype == CPDF_Annot::Subtype::UNDERLINE)
- result = CPVT_GenerateAP::GenerateUnderlineAP(m_pDocument, m_pAnnotDict);
+ result = CPVT_GenerateAP::GenerateUnderlineAP(m_pDocument, pDict);
if (result) {
m_pAnnotDict->SetNewFor<CPDF_Boolean>(kPDFiumKey_HasGeneratedAP, result);
@@ -118,7 +115,7 @@ void CPDF_Annot::GenerateAPIfNeeded() {
}
bool CPDF_Annot::ShouldDrawAnnotation() {
- if (IsAnnotationHidden(m_pAnnotDict))
+ if (IsAnnotationHidden(m_pAnnotDict.Get()))
return false;
if (m_nSubtype == CPDF_Annot::Subtype::POPUP && !m_bOpenState)
@@ -142,7 +139,7 @@ CFX_FloatRect CPDF_Annot::RectForDrawing() const {
bool bShouldUseQuadPointsCoords =
m_bIsTextMarkupAnnotation && m_bHasGeneratedAP;
if (bShouldUseQuadPointsCoords)
- return RectFromQuadPoints(m_pAnnotDict);
+ return RectFromQuadPoints(m_pAnnotDict.Get());
return m_pAnnotDict->GetRectFor("Rect");
}
@@ -199,7 +196,7 @@ CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict,
}
CPDF_Form* CPDF_Annot::GetAPForm(const CPDF_Page* pPage, AppearanceMode mode) {
- CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pAnnotDict, mode);
+ CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pAnnotDict.Get(), mode);
if (!pStream)
return nullptr;