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

Side by Side Diff: xfa/fwl/basewidget/fwl_editimp.cpp

Issue 1980293004: Pass objects instead of strings for undo/redo records. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « xfa/fwl/basewidget/fwl_editimp.h ('k') | xfa/fwl/basewidget/ifwl_combobox.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "xfa/fwl/basewidget/fwl_editimp.h" 7 #include "xfa/fwl/basewidget/fwl_editimp.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 141 }
142 FX_BOOL IFWL_Edit::Cut(CFX_WideString& wsCut) { 142 FX_BOOL IFWL_Edit::Cut(CFX_WideString& wsCut) {
143 return static_cast<CFWL_EditImp*>(GetImpl())->Cut(wsCut); 143 return static_cast<CFWL_EditImp*>(GetImpl())->Cut(wsCut);
144 } 144 }
145 FX_BOOL IFWL_Edit::Paste(const CFX_WideString& wsPaste) { 145 FX_BOOL IFWL_Edit::Paste(const CFX_WideString& wsPaste) {
146 return static_cast<CFWL_EditImp*>(GetImpl())->Paste(wsPaste); 146 return static_cast<CFWL_EditImp*>(GetImpl())->Paste(wsPaste);
147 } 147 }
148 FX_BOOL IFWL_Edit::Delete() { 148 FX_BOOL IFWL_Edit::Delete() {
149 return static_cast<CFWL_EditImp*>(GetImpl())->Delete(); 149 return static_cast<CFWL_EditImp*>(GetImpl())->Delete();
150 } 150 }
151 FX_BOOL IFWL_Edit::Redo(const CFX_ByteStringC& bsRecord) { 151 FX_BOOL IFWL_Edit::Redo(const IFDE_TxtEdtDoRecord* pRecord) {
152 return static_cast<CFWL_EditImp*>(GetImpl())->Redo(bsRecord); 152 return static_cast<CFWL_EditImp*>(GetImpl())->Redo(pRecord);
153 } 153 }
154 FX_BOOL IFWL_Edit::Undo(const CFX_ByteStringC& bsRecord) { 154 FX_BOOL IFWL_Edit::Undo(const IFDE_TxtEdtDoRecord* pRecord) {
155 return static_cast<CFWL_EditImp*>(GetImpl())->Undo(bsRecord); 155 return static_cast<CFWL_EditImp*>(GetImpl())->Undo(pRecord);
156 } 156 }
157 FX_BOOL IFWL_Edit::Undo() { 157 FX_BOOL IFWL_Edit::Undo() {
158 return static_cast<CFWL_EditImp*>(GetImpl())->Undo(); 158 return static_cast<CFWL_EditImp*>(GetImpl())->Undo();
159 } 159 }
160 FX_BOOL IFWL_Edit::Redo() { 160 FX_BOOL IFWL_Edit::Redo() {
161 return static_cast<CFWL_EditImp*>(GetImpl())->Redo(); 161 return static_cast<CFWL_EditImp*>(GetImpl())->Redo();
162 } 162 }
163 FX_BOOL IFWL_Edit::CanUndo() { 163 FX_BOOL IFWL_Edit::CanUndo() {
164 return static_cast<CFWL_EditImp*>(GetImpl())->CanUndo(); 164 return static_cast<CFWL_EditImp*>(GetImpl())->CanUndo();
165 } 165 }
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 return FALSE; 742 return FALSE;
743 743
744 int32_t nCount = m_pEdtEngine->CountSelRanges(); 744 int32_t nCount = m_pEdtEngine->CountSelRanges();
745 if (nCount < 1) 745 if (nCount < 1)
746 return FALSE; 746 return FALSE;
747 747
748 m_pEdtEngine->Delete(0); 748 m_pEdtEngine->Delete(0);
749 return TRUE; 749 return TRUE;
750 } 750 }
751 751
752 FX_BOOL CFWL_EditImp::Redo(const CFX_ByteStringC& bsRecord) { 752 FX_BOOL CFWL_EditImp::Redo(const IFDE_TxtEdtDoRecord* pRecord) {
753 if (!m_pEdtEngine) 753 if (!m_pEdtEngine)
754 return FALSE; 754 return FALSE;
755 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoRedoUndo) 755 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoRedoUndo)
756 return TRUE; 756 return TRUE;
757 return m_pEdtEngine->Redo(bsRecord); 757 return m_pEdtEngine->Redo(pRecord);
758 } 758 }
759 759
760 FX_BOOL CFWL_EditImp::Undo(const CFX_ByteStringC& bsRecord) { 760 FX_BOOL CFWL_EditImp::Undo(const IFDE_TxtEdtDoRecord* pRecord) {
761 if (!m_pEdtEngine) 761 if (!m_pEdtEngine)
762 return FALSE; 762 return FALSE;
763 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoRedoUndo) 763 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoRedoUndo)
764 return TRUE; 764 return TRUE;
765 return m_pEdtEngine->Undo(bsRecord); 765 return m_pEdtEngine->Undo(pRecord);
766 } 766 }
767 767
768 FX_BOOL CFWL_EditImp::Undo() { 768 FX_BOOL CFWL_EditImp::Undo() {
769 if (!CanUndo()) 769 if (!CanUndo())
770 return FALSE; 770 return FALSE;
771 771 return Undo(m_DoRecords[m_iCurRecord--].get());
772 CFX_ByteString bsRecord = m_RecordArr[m_iCurRecord--];
773 return Undo(bsRecord.AsStringC());
774 } 772 }
775 773
776 FX_BOOL CFWL_EditImp::Redo() { 774 FX_BOOL CFWL_EditImp::Redo() {
777 if (!CanRedo()) 775 if (!CanRedo())
778 return FALSE; 776 return FALSE;
779 777 return Redo(m_DoRecords[++m_iCurRecord].get());
780 CFX_ByteString bsRecord = m_RecordArr[++m_iCurRecord];
781 return Redo(bsRecord.AsStringC());
782 } 778 }
783 779
784 FX_BOOL CFWL_EditImp::CanUndo() { 780 FX_BOOL CFWL_EditImp::CanUndo() {
785 return m_iCurRecord >= 0; 781 return m_iCurRecord >= 0;
786 } 782 }
787 783
788 FX_BOOL CFWL_EditImp::CanRedo() { 784 FX_BOOL CFWL_EditImp::CanRedo() {
789 return m_iCurRecord < m_RecordArr.GetSize() - 1; 785 return m_iCurRecord < m_DoRecords.size() - 1;
Lei Zhang 2016/05/19 23:46:48 When I tried to roll DEPS, this failed on the Chro
790 } 786 }
791 787
792 FWL_Error CFWL_EditImp::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) { 788 FWL_Error CFWL_EditImp::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) {
793 if (!m_pEdtEngine) 789 if (!m_pEdtEngine)
794 return FWL_Error::Indefinite; 790 return FWL_Error::Indefinite;
795 791
796 FDE_TXTEDTPARAMS* pParams = m_pEdtEngine->GetEditParams(); 792 FDE_TXTEDTPARAMS* pParams = m_pEdtEngine->GetEditParams();
797 pParams->fTabWidth = fTabWidth; 793 pParams->fTabWidth = fTabWidth;
798 pParams->bTabEquidistant = bEquidistant; 794 pParams->bTabEquidistant = bEquidistant;
799 return FWL_Error::Succeeded; 795 return FWL_Error::Succeeded;
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 int32_t nPurpose) { 920 int32_t nPurpose) {
925 CFDE_TxtEdtEngine* pEdtEngine = m_pEdtEngine; 921 CFDE_TxtEdtEngine* pEdtEngine = m_pEdtEngine;
926 IFDE_TxtEdtPage* pPage = pEdtEngine->GetPage(nPageIndex); 922 IFDE_TxtEdtPage* pPage = pEdtEngine->GetPage(nPageIndex);
927 if (!pPage) 923 if (!pPage)
928 return FALSE; 924 return FALSE;
929 pPage->UnloadPage(nullptr); 925 pPage->UnloadPage(nullptr);
930 return TRUE; 926 return TRUE;
931 } 927 }
932 928
933 void CFWL_EditImp::On_AddDoRecord(CFDE_TxtEdtEngine* pEdit, 929 void CFWL_EditImp::On_AddDoRecord(CFDE_TxtEdtEngine* pEdit,
934 const CFX_ByteStringC& bsDoRecord) { 930 IFDE_TxtEdtDoRecord* pRecord) {
935 AddDoRecord(bsDoRecord); 931 AddDoRecord(pRecord);
936 } 932 }
937 933
938 FX_BOOL CFWL_EditImp::On_Validate(CFDE_TxtEdtEngine* pEdit, 934 FX_BOOL CFWL_EditImp::On_Validate(CFDE_TxtEdtEngine* pEdit,
939 CFX_WideString& wsText) { 935 CFX_WideString& wsText) {
940 IFWL_Widget* pDst = GetOuter(); 936 IFWL_Widget* pDst = GetOuter();
941 if (!pDst) { 937 if (!pDst) {
942 pDst = m_pInterface; 938 pDst = m_pInterface;
943 } 939 }
944 CFWL_EvtEdtValidate event; 940 CFWL_EvtEdtValidate event;
945 event.pDstWidget = pDst; 941 event.pDstWidget = pDst;
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
1461 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine); 1457 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine);
1462 } 1458 }
1463 FX_BOOL CFWL_EditImp::IsContentHeightOverflow() { 1459 FX_BOOL CFWL_EditImp::IsContentHeightOverflow() {
1464 if (!m_pEdtEngine) 1460 if (!m_pEdtEngine)
1465 return FALSE; 1461 return FALSE;
1466 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(0); 1462 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(0);
1467 if (!pPage) 1463 if (!pPage)
1468 return FALSE; 1464 return FALSE;
1469 return pPage->GetContentsBox().height > m_rtEngine.height + 1.0f; 1465 return pPage->GetContentsBox().height > m_rtEngine.height + 1.0f;
1470 } 1466 }
1471 int32_t CFWL_EditImp::AddDoRecord(const CFX_ByteStringC& bsDoRecord) { 1467 int32_t CFWL_EditImp::AddDoRecord(IFDE_TxtEdtDoRecord* pRecord) {
1472 int32_t nCount = m_RecordArr.GetSize(); 1468 int32_t nCount = m_DoRecords.size();
1473 if (m_iCurRecord == nCount - 1) { 1469 if (m_iCurRecord == nCount - 1) {
1474 if (nCount == m_iMaxRecord) { 1470 if (nCount == m_iMaxRecord) {
1475 m_RecordArr.RemoveAt(0); 1471 m_DoRecords.pop_front();
1476 m_iCurRecord--; 1472 m_iCurRecord--;
1477 } 1473 }
1478 } else { 1474 } else {
1479 for (int32_t i = nCount - 1; i > m_iCurRecord; i--) { 1475 m_DoRecords.erase(m_DoRecords.begin() + m_iCurRecord + 1,
Tom Sepez 2016/05/17 21:24:38 Maybe m_iCurRecord should itself be an iterator.
dsinclair 2016/05/18 13:09:06 Filed pdfium:494 to track.
1480 m_RecordArr.RemoveAt(i); 1476 m_DoRecords.end());
1481 }
1482 } 1477 }
1483 m_RecordArr.Add(CFX_ByteString(bsDoRecord)); 1478
1484 return m_iCurRecord = m_RecordArr.GetSize() - 1; 1479 m_DoRecords.push_back(std::unique_ptr<IFDE_TxtEdtDoRecord>(pRecord));
1480 m_iCurRecord = m_DoRecords.size() - 1;
1481 return m_iCurRecord;
1485 } 1482 }
1486 void CFWL_EditImp::Layout() { 1483 void CFWL_EditImp::Layout() {
1487 GetClientRect(m_rtClient); 1484 GetClientRect(m_rtClient);
1488 m_rtEngine = m_rtClient; 1485 m_rtEngine = m_rtClient;
1489 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( 1486 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>(
1490 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); 1487 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
1491 if (!pfWidth) 1488 if (!pfWidth)
1492 return; 1489 return;
1493 FX_FLOAT fWidth = *pfWidth; 1490 FX_FLOAT fWidth = *pfWidth;
1494 if (!m_pOuter) { 1491 if (!m_pOuter) {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1729 m_pCaret.reset(IFWL_Caret::Create(prop, m_pInterface)); 1726 m_pCaret.reset(IFWL_Caret::Create(prop, m_pInterface));
1730 m_pCaret->Initialize(); 1727 m_pCaret->Initialize();
1731 m_pCaret->SetParent(m_pInterface); 1728 m_pCaret->SetParent(m_pInterface);
1732 m_pCaret->SetStates(m_pProperties->m_dwStates); 1729 m_pCaret->SetStates(m_pProperties->m_dwStates);
1733 } 1730 }
1734 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret) == 1731 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret) ==
1735 0) { 1732 0) {
1736 m_pCaret.reset(); 1733 m_pCaret.reset();
1737 } 1734 }
1738 } 1735 }
1736
1739 void CFWL_EditImp::ClearRecord() { 1737 void CFWL_EditImp::ClearRecord() {
1740 m_iCurRecord = -1; 1738 m_iCurRecord = -1;
1741 m_RecordArr.RemoveAll(); 1739 m_DoRecords.clear();
1742 } 1740 }
1741
1743 void CFWL_EditImp::ProcessInsertError(int32_t iError) { 1742 void CFWL_EditImp::ProcessInsertError(int32_t iError) {
1744 switch (iError) { 1743 switch (iError) {
1745 case -2: { 1744 case -2: {
1746 CFWL_EvtEdtTextFull textFullEvent; 1745 CFWL_EvtEdtTextFull textFullEvent;
1747 textFullEvent.m_pSrcTarget = m_pInterface; 1746 textFullEvent.m_pSrcTarget = m_pInterface;
1748 DispatchEvent(&textFullEvent); 1747 DispatchEvent(&textFullEvent);
1749 break; 1748 break;
1750 } 1749 }
1751 default: {} 1750 default: {}
1752 } 1751 }
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
2190 } 2189 }
2191 CFX_RectF rect; 2190 CFX_RectF rect;
2192 m_pOwner->GetWidgetRect(rect); 2191 m_pOwner->GetWidgetRect(rect);
2193 CFX_RectF rtInvalidate; 2192 CFX_RectF rtInvalidate;
2194 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); 2193 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2);
2195 m_pOwner->Repaint(&rtInvalidate); 2194 m_pOwner->Repaint(&rtInvalidate);
2196 } 2195 }
2197 return TRUE; 2196 return TRUE;
2198 } 2197 }
2199 void CFWL_EditImpDelegate::DoCursor(CFWL_MsgMouse* pMsg) {} 2198 void CFWL_EditImpDelegate::DoCursor(CFWL_MsgMouse* pMsg) {}
OLDNEW
« no previous file with comments | « xfa/fwl/basewidget/fwl_editimp.h ('k') | xfa/fwl/basewidget/ifwl_combobox.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698