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

Side by Side Diff: fpdfsdk/src/fsdk_annothandler.cpp

Issue 1411203007: Cleanup parts of CPDFSDK_AnnotIterator and CPDFSDK_PageView. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 5 years, 2 months 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "../include/fsdk_define.h" 7 #include "../include/fsdk_define.h"
8 #include "../include/fsdk_mgr.h" 8 #include "../include/fsdk_mgr.h"
9 #include "../include/formfiller/FFL_FormFiller.h" 9 #include "../include/formfiller/FFL_FormFiller.h"
10 #include "../include/fsdk_annothandler.h" 10 #include "../include/fsdk_annothandler.h"
11 11
12 namespace {
13
14 typedef int (*AI_COMPARE)(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2);
15
16 int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
17 if (p1->GetLayoutOrder() == p2->GetLayoutOrder())
18 return 0;
19 return (p1->GetLayoutOrder() < p2->GetLayoutOrder()) ? -1 : 1;
20 }
21
22 } // namespace
23
12 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { 24 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) {
13 m_pApp = pApp; 25 m_pApp = pApp;
14 26
15 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); 27 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp);
16 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); 28 pHandler->SetFormFiller(m_pApp->GetIFormFiller());
17 RegisterAnnotHandler(pHandler); 29 RegisterAnnotHandler(pHandler);
18 } 30 }
19 31
20 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { 32 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() {
21 for (int i = 0; i < m_Handlers.GetSize(); i++) { 33 for (int i = 0; i < m_Handlers.GetSize(); i++) {
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, 654 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView,
643 CPDFSDK_Annot* pAnnot, 655 CPDFSDK_Annot* pAnnot,
644 const CPDF_Point& point) { 656 const CPDF_Point& point) {
645 ASSERT(pPageView); 657 ASSERT(pPageView);
646 ASSERT(pAnnot); 658 ASSERT(pAnnot);
647 659
648 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot); 660 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot);
649 return rect.Contains(point.x, point.y); 661 return rect.Contains(point.x, point.y);
650 } 662 }
651 663
652 // CReader_AnnotIteratorEx 664 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView,
665 bool bReverse)
666 : m_bReverse(bReverse) {
667 CFX_PtrArray* pAnnotList = pPageView->GetAnnotList();
668 if (!pAnnotList)
669 return;
653 670
654 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView, 671 CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot();
655 FX_BOOL bReverse,
656 FX_BOOL bIgnoreTopmost /*=FALSE*/,
657 FX_BOOL bCircle /*=FALSE*/,
658 CFX_PtrArray* pList /*=NULL*/) {
659 ASSERT(pPageView);
660 m_bReverse = bReverse;
661 m_bIgnoreTopmost = bIgnoreTopmost;
662 m_bCircle = bCircle;
663 m_pIteratorAnnotList.RemoveAll();
664 InitIteratorAnnotList(pPageView, pList);
665 }
666 672
667 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(const CPDFSDK_Annot* pCurrent) { 673 const int nCount = pAnnotList->GetSize();
668 int index = -1; 674 for (int i = nCount - 1; i >= 0; --i)
669 int nCount = m_pIteratorAnnotList.GetSize(); 675 m_pIteratorAnnotList.Add(static_cast<CPDFSDK_Annot*>(pAnnotList->GetAt(i)));
670 if (pCurrent) { 676 InsertSort();
671 for (int i = 0; i < nCount; i++) {
672 CPDFSDK_Annot* pReaderAnnot =
673 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
674 if (pReaderAnnot == pCurrent) {
675 index = i;
676 break;
677 }
678 }
679 }
680 return NextAnnot(index);
681 }
682 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(const CPDFSDK_Annot* pCurrent) {
683 int index = -1;
684 int nCount = m_pIteratorAnnotList.GetSize();
685 if (pCurrent) {
686 for (int i = 0; i < nCount; i++) {
687 CPDFSDK_Annot* pReaderAnnot =
688 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i);
689 if (pReaderAnnot == pCurrent) {
690 index = i;
691 break;
692 }
693 }
694 }
695 return PrevAnnot(index);
696 }
697 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(int& index) {
698 int nCount = m_pIteratorAnnotList.GetSize();
699 if (nCount <= 0)
700 index = -1;
701 else {
702 if (index < 0) {
703 index = 0;
704 } else {
705 if (m_bCircle) {
706 index = (index < nCount - 1) ? (index + 1) : 0;
707 } else {
708 index = (index < nCount - 1) ? (index + 1) : -1;
709 }
710 }
711 }
712 return (index < 0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
713 }
714 677
715 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(int& index) { 678 if (!pTopMostAnnot)
716 int nCount = m_pIteratorAnnotList.GetSize(); 679 return;
717 if (nCount <= 0)
718 index = -1;
719 else {
720 if (index < 0) {
721 index = nCount - 1;
722 } else {
723 if (m_bCircle) {
724 index = (index > 0) ? (index - 1) : nCount - 1;
725 } else {
726 index = (index > 0) ? (index - 1) : -1;
727 }
728 }
729 }
730 return (index < 0) ? NULL : (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(index);
731 }
732 680
733 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(const CPDFSDK_Annot* pCurrent) { 681 for (int i = 0; i < nCount; ++i) {
734 return (m_bReverse) ? PrevAnnot(pCurrent) : NextAnnot(pCurrent); 682 CPDFSDK_Annot* pReaderAnnot =
735 } 683 static_cast<CPDFSDK_Annot*>(m_pIteratorAnnotList.GetAt(i));
736 684 if (pReaderAnnot == pTopMostAnnot) {
737 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent) { 685 m_pIteratorAnnotList.RemoveAt(i);
738 return (m_bReverse) ? NextAnnot(pCurrent) : PrevAnnot(pCurrent); 686 m_pIteratorAnnotList.InsertAt(0, pReaderAnnot);
739 } 687 break;
740
741 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(int& index) {
742 return (m_bReverse) ? PrevAnnot(index) : NextAnnot(index);
743 }
744
745 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int& index) {
746 return (m_bReverse) ? NextAnnot(index) : PrevAnnot(index);
747 }
748
749 void CPDFSDK_AnnotIterator::InsertSort(CFX_PtrArray& arrayList,
750 AI_COMPARE pCompare) {
751 for (int i = 1; i < arrayList.GetSize(); i++) {
752 if (pCompare((CPDFSDK_Annot*)(arrayList[i]),
753 (CPDFSDK_Annot*)(arrayList[i - 1])) < 0) {
754 int j = i - 1;
755 CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)arrayList[i];
756
757 do {
758 arrayList[j + 1] = arrayList[j];
759 } while (--j >= 0 && pCompare(pTemp, (CPDFSDK_Annot*)arrayList[j]) < 0);
760
761 arrayList[j + 1] = pTemp;
762 } 688 }
763 } 689 }
764 } 690 }
765 691
766 int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) { 692 CPDFSDK_AnnotIterator::~CPDFSDK_AnnotIterator() {
767 if (p1->GetLayoutOrder() < p2->GetLayoutOrder())
768 return -1;
769 if (p1->GetLayoutOrder() > p2->GetLayoutOrder())
770 return 1;
771 return 0;
772 } 693 }
773 694
774 FX_BOOL CPDFSDK_AnnotIterator::InitIteratorAnnotList( 695 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(int* index) {
775 CPDFSDK_PageView* pPageView, 696 int nCount = m_pIteratorAnnotList.GetSize();
776 CFX_PtrArray* pAnnotList) { 697 if (nCount <= 0) {
777 ASSERT(pPageView); 698 *index = -1;
778 699 return nullptr;
779 if (pAnnotList == NULL) {
780 pAnnotList = pPageView->GetAnnotList();
781 } 700 }
782 701
783 m_pIteratorAnnotList.RemoveAll(); 702 if (*index < 0)
784 if (!pAnnotList) 703 *index = 0;
785 return FALSE; 704 else
705 *index = (*index < nCount - 1) ? (*index + 1) : -1;
786 706
787 CPDFSDK_Annot* pTopMostAnnot = 707 if (*index < 0)
788 (m_bIgnoreTopmost) ? NULL : pPageView->GetFocusAnnot(); 708 return nullptr;
709 return static_cast<CPDFSDK_Annot*>(m_pIteratorAnnotList.GetAt(*index));
710 }
789 711
790 int nCount = pAnnotList->GetSize(); 712 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(int* index) {
791 713 int nCount = m_pIteratorAnnotList.GetSize();
792 for (int i = nCount - 1; i >= 0; i--) { 714 if (nCount <= 0) {
793 CPDFSDK_Annot* pReaderAnnot = (CPDFSDK_Annot*)pAnnotList->GetAt(i); 715 *index = -1;
794 m_pIteratorAnnotList.Add(pReaderAnnot); 716 return nullptr;
795 } 717 }
796 718
797 InsertSort(m_pIteratorAnnotList, &LyOrderCompare); 719 if (*index < 0)
720 *index = nCount - 1;
721 else
722 *index = (*index > 0) ? (*index - 1) : -1;
798 723
799 if (pTopMostAnnot) { 724 if (*index < 0)
800 for (int i = 0; i < nCount; i++) { 725 return nullptr;
801 CPDFSDK_Annot* pReaderAnnot = 726 return static_cast<CPDFSDK_Annot*>(m_pIteratorAnnotList.GetAt(*index));
802 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i); 727 }
803 if (pReaderAnnot == pTopMostAnnot) { 728
804 m_pIteratorAnnotList.RemoveAt(i); 729 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(int* index) {
805 m_pIteratorAnnotList.InsertAt(0, pReaderAnnot); 730 return m_bReverse ? PrevAnnot(index) : NextAnnot(index);
806 break; 731 }
807 } 732
733 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(int* index) {
734 return m_bReverse ? NextAnnot(index) : PrevAnnot(index);
735 }
736
737 void CPDFSDK_AnnotIterator::InsertSort() {
738 for (int i = 1; i < m_pIteratorAnnotList.GetSize(); ++i) {
739 if (LyOrderCompare((CPDFSDK_Annot*)(m_pIteratorAnnotList[i]),
740 (CPDFSDK_Annot*)(m_pIteratorAnnotList[i - 1])) < 0) {
741 int j = i - 1;
742 CPDFSDK_Annot* pTemp = (CPDFSDK_Annot*)m_pIteratorAnnotList[i];
743
744 do {
745 m_pIteratorAnnotList[j + 1] = m_pIteratorAnnotList[j];
746 } while (--j >= 0 &&
747 LyOrderCompare(pTemp, (CPDFSDK_Annot*)m_pIteratorAnnotList[j]) <
748 0);
749
750 m_pIteratorAnnotList[j + 1] = pTemp;
808 } 751 }
809 } 752 }
810
811 return TRUE;
812 } 753 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698