OLD | NEW |
---|---|
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 int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) { | |
15 if (p1->GetLayoutOrder() == p2->GetLayoutOrder()) | |
Tom Sepez
2015/10/21 19:32:59
just return p1->GetLayouOrder() - p2->GetLayoutOrd
Lei Zhang
2015/10/22 06:56:22
Oh yes, it's 2 vs 5!
| |
16 return 0; | |
17 return (p1->GetLayoutOrder() < p2->GetLayoutOrder()) ? -1 : 1; | |
18 } | |
19 | |
20 } // namespace | |
21 | |
12 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { | 22 CPDFSDK_AnnotHandlerMgr::CPDFSDK_AnnotHandlerMgr(CPDFDoc_Environment* pApp) { |
13 m_pApp = pApp; | 23 m_pApp = pApp; |
14 | 24 |
15 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); | 25 CPDFSDK_BFAnnotHandler* pHandler = new CPDFSDK_BFAnnotHandler(m_pApp); |
16 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); | 26 pHandler->SetFormFiller(m_pApp->GetIFormFiller()); |
17 RegisterAnnotHandler(pHandler); | 27 RegisterAnnotHandler(pHandler); |
18 } | 28 } |
19 | 29 |
20 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { | 30 CPDFSDK_AnnotHandlerMgr::~CPDFSDK_AnnotHandlerMgr() { |
21 for (int i = 0; i < m_Handlers.GetSize(); i++) { | 31 for (int i = 0; i < m_Handlers.GetSize(); i++) { |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, | 652 FX_BOOL CPDFSDK_BFAnnotHandler::HitTest(CPDFSDK_PageView* pPageView, |
643 CPDFSDK_Annot* pAnnot, | 653 CPDFSDK_Annot* pAnnot, |
644 const CPDF_Point& point) { | 654 const CPDF_Point& point) { |
645 ASSERT(pPageView); | 655 ASSERT(pPageView); |
646 ASSERT(pAnnot); | 656 ASSERT(pAnnot); |
647 | 657 |
648 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot); | 658 CPDF_Rect rect = GetViewBBox(pPageView, pAnnot); |
649 return rect.Contains(point.x, point.y); | 659 return rect.Contains(point.x, point.y); |
650 } | 660 } |
651 | 661 |
652 // CReader_AnnotIteratorEx | 662 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView, |
663 bool bReverse) | |
664 : m_bReverse(bReverse) { | |
665 const std::vector<CPDFSDK_Annot*>& annots = pPageView->GetAnnotList(); | |
666 for (auto it = annots.rbegin(); it != annots.rend(); ++it) | |
Tom Sepez
2015/10/21 19:32:58
Do we care what order we traverse the annots if we
Lei Zhang
2015/10/22 06:56:22
Apparently we do. Probably for z-ordering. If I fl
| |
667 m_iteratorAnnotList.push_back(*it); | |
668 InsertSort(); | |
653 | 669 |
654 CPDFSDK_AnnotIterator::CPDFSDK_AnnotIterator(CPDFSDK_PageView* pPageView, | 670 CPDFSDK_Annot* pTopMostAnnot = pPageView->GetFocusAnnot(); |
655 FX_BOOL bReverse, | 671 if (!pTopMostAnnot) |
656 FX_BOOL bIgnoreTopmost /*=FALSE*/, | 672 return; |
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 | 673 |
667 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(const CPDFSDK_Annot* pCurrent) { | 674 for (auto it = m_iteratorAnnotList.begin(); it != m_iteratorAnnotList.end(); |
Tom Sepez
2015/10/21 19:32:58
can we use std::find or some such?
Lei Zhang
2015/10/22 06:56:22
Done.
| |
668 int index = -1; | 675 ++it) { |
669 int nCount = m_pIteratorAnnotList.GetSize(); | 676 CPDFSDK_Annot* pReaderAnnot = *it; |
670 if (pCurrent) { | 677 if (pReaderAnnot == pTopMostAnnot) { |
671 for (int i = 0; i < nCount; i++) { | 678 m_iteratorAnnotList.erase(it); |
Tom Sepez
2015/10/21 19:32:58
Yeah, lets make traversal O(n^2) just for grins.
Lei Zhang
2015/10/22 06:56:22
But it's dead code, so that's O(0) right?
| |
672 CPDFSDK_Annot* pReaderAnnot = | 679 m_iteratorAnnotList.insert(m_iteratorAnnotList.begin(), pReaderAnnot); |
673 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i); | 680 break; |
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 | |
715 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(int& index) { | |
716 int nCount = m_pIteratorAnnotList.GetSize(); | |
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 | |
733 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(const CPDFSDK_Annot* pCurrent) { | |
734 return (m_bReverse) ? PrevAnnot(pCurrent) : NextAnnot(pCurrent); | |
735 } | |
736 | |
737 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(const CPDFSDK_Annot* pCurrent) { | |
738 return (m_bReverse) ? NextAnnot(pCurrent) : PrevAnnot(pCurrent); | |
739 } | |
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 } | 681 } |
763 } | 682 } |
764 } | 683 } |
765 | 684 |
766 int LyOrderCompare(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) { | 685 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 } | 686 } |
773 | 687 |
774 FX_BOOL CPDFSDK_AnnotIterator::InitIteratorAnnotList( | 688 CPDFSDK_Annot* CPDFSDK_AnnotIterator::NextAnnot(size_t* index) { |
775 CPDFSDK_PageView* pPageView, | 689 const size_t oldIndex = *index; |
Tom Sepez
2015/10/21 19:32:58
there's got to be a simpler way to write this.
Lei Zhang
2015/10/22 06:56:22
Done.
| |
776 CFX_PtrArray* pAnnotList) { | 690 if (oldIndex >= m_iteratorAnnotList.size()) |
777 ASSERT(pPageView); | 691 return nullptr; |
778 | 692 |
779 if (pAnnotList == NULL) { | 693 ++(*index); |
780 pAnnotList = pPageView->GetAnnotList(); | 694 return m_iteratorAnnotList[oldIndex]; |
781 } | 695 } |
782 | 696 |
783 m_pIteratorAnnotList.RemoveAll(); | 697 CPDFSDK_Annot* CPDFSDK_AnnotIterator::PrevAnnot(size_t* index) { |
784 if (!pAnnotList) | 698 if (m_iteratorAnnotList.empty() || *index >= m_iteratorAnnotList.size()) |
Tom Sepez
2015/10/21 19:32:58
Wouldn't the empty() check be redundant if size()
Lei Zhang
2015/10/22 06:56:22
Done.
| |
785 return FALSE; | 699 return nullptr; |
786 | 700 |
787 CPDFSDK_Annot* pTopMostAnnot = | 701 const size_t oldIndex = m_iteratorAnnotList.size() - *index - 1; |
788 (m_bIgnoreTopmost) ? NULL : pPageView->GetFocusAnnot(); | 702 ++(*index); |
703 return m_iteratorAnnotList[oldIndex]; | |
704 } | |
789 | 705 |
790 int nCount = pAnnotList->GetSize(); | 706 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Next(size_t* index) { |
707 return m_bReverse ? PrevAnnot(index) : NextAnnot(index); | |
708 } | |
791 | 709 |
792 for (int i = nCount - 1; i >= 0; i--) { | 710 CPDFSDK_Annot* CPDFSDK_AnnotIterator::Prev(size_t* index) { |
793 CPDFSDK_Annot* pReaderAnnot = (CPDFSDK_Annot*)pAnnotList->GetAt(i); | 711 return m_bReverse ? NextAnnot(index) : PrevAnnot(index); |
794 m_pIteratorAnnotList.Add(pReaderAnnot); | 712 } |
795 } | |
796 | 713 |
797 InsertSort(m_pIteratorAnnotList, &LyOrderCompare); | 714 void CPDFSDK_AnnotIterator::InsertSort() { |
Tom Sepez
2015/10/21 19:32:58
WHY???
Lei Zhang
2015/10/22 06:56:22
I was lazy and didn't really want to deal with it.
| |
715 for (size_t i = 1; i < m_iteratorAnnotList.size(); ++i) { | |
716 if (LyOrderCompare((CPDFSDK_Annot*)(m_iteratorAnnotList[i]), | |
717 (CPDFSDK_Annot*)(m_iteratorAnnotList[i - 1])) < 0) { | |
718 int j = i - 1; | |
719 CPDFSDK_Annot* pTemp = m_iteratorAnnotList[i]; | |
798 | 720 |
799 if (pTopMostAnnot) { | 721 do { |
800 for (int i = 0; i < nCount; i++) { | 722 m_iteratorAnnotList[j + 1] = m_iteratorAnnotList[j]; |
801 CPDFSDK_Annot* pReaderAnnot = | 723 } while (--j >= 0 && LyOrderCompare(pTemp, m_iteratorAnnotList[j]) < 0); |
802 (CPDFSDK_Annot*)m_pIteratorAnnotList.GetAt(i); | 724 |
803 if (pReaderAnnot == pTopMostAnnot) { | 725 m_iteratorAnnotList[j + 1] = pTemp; |
804 m_pIteratorAnnotList.RemoveAt(i); | |
805 m_pIteratorAnnotList.InsertAt(0, pReaderAnnot); | |
806 break; | |
807 } | |
808 } | 726 } |
809 } | 727 } |
810 | |
811 return TRUE; | |
812 } | 728 } |
OLD | NEW |