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

Side by Side Diff: xfa/fxfa/app/xfa_fftext.cpp

Issue 2031873003: Get rid of NULLs in xfa/ (Closed) Base URL: https://pdfium.googlesource.com/pdfium@nullptr_fpdfsdk
Patch Set: Created 4 years, 6 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/fxfa/app/xfa_fftext.h ('k') | xfa/fxfa/app/xfa_fftextedit.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/fxfa/app/xfa_fftext.h" 7 #include "xfa/fxfa/app/xfa_fftext.h"
8 8
9 #include "xfa/fwl/core/fwl_widgetdef.h" 9 #include "xfa/fwl/core/fwl_widgetdef.h"
10 #include "xfa/fxfa/app/xfa_ffdraw.h" 10 #include "xfa/fxfa/app/xfa_ffdraw.h"
(...skipping 21 matching lines...) Expand all
32 mtRotate.Concat(*pMatrix); 32 mtRotate.Concat(*pMatrix);
33 } 33 }
34 CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus); 34 CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus);
35 CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); 35 CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout();
36 if (pTextLayout) { 36 if (pTextLayout) {
37 CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice(); 37 CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice();
38 CFX_RectF rtText; 38 CFX_RectF rtText;
39 GetRectWithoutRotate(rtText); 39 GetRectWithoutRotate(rtText);
40 if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) { 40 if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) {
41 CXFA_LayoutItem* pItem = this; 41 CXFA_LayoutItem* pItem = this;
42 if (pItem->GetPrev() == NULL && pItem->GetNext() == NULL) { 42 if (!pItem->GetPrev() && !pItem->GetNext()) {
43 XFA_RectWidthoutMargin(rtText, mgWidget); 43 XFA_RectWidthoutMargin(rtText, mgWidget);
44 } else { 44 } else {
45 FX_FLOAT fLeftInset, fRightInset, fTopInset = 0, fBottomInset = 0; 45 FX_FLOAT fLeftInset, fRightInset, fTopInset = 0, fBottomInset = 0;
46 mgWidget.GetLeftInset(fLeftInset); 46 mgWidget.GetLeftInset(fLeftInset);
47 mgWidget.GetRightInset(fRightInset); 47 mgWidget.GetRightInset(fRightInset);
48 if (pItem->GetPrev() == NULL) { 48 if (!pItem->GetPrev()) {
49 mgWidget.GetTopInset(fTopInset); 49 mgWidget.GetTopInset(fTopInset);
50 } else if (pItem->GetNext() == NULL) { 50 } else if (!pItem->GetNext()) {
51 mgWidget.GetBottomInset(fBottomInset); 51 mgWidget.GetBottomInset(fBottomInset);
52 } 52 }
53 rtText.Deflate(fLeftInset, fTopInset, fRightInset, fBottomInset); 53 rtText.Deflate(fLeftInset, fTopInset, fRightInset, fBottomInset);
54 } 54 }
55 } 55 }
56 CFX_Matrix mt; 56 CFX_Matrix mt;
57 mt.Set(1, 0, 0, 1, rtText.left, rtText.top); 57 mt.Set(1, 0, 0, 1, rtText.left, rtText.top);
58 CFX_RectF rtClip = rtText; 58 CFX_RectF rtClip = rtText;
59 mtRotate.TransformRect(rtClip); 59 mtRotate.TransformRect(rtClip);
60 mt.Concat(mtRotate); 60 mt.Concat(mtRotate);
61 pTextLayout->DrawString(pRenderDevice, mt, rtClip, GetIndex()); 61 pTextLayout->DrawString(pRenderDevice, mt, rtClip, GetIndex());
62 } 62 }
63 } 63 }
64 } 64 }
65 FX_BOOL CXFA_FFText::IsLoaded() { 65 FX_BOOL CXFA_FFText::IsLoaded() {
66 CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); 66 CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout();
67 return pTextLayout && !pTextLayout->m_bHasBlock; 67 return pTextLayout && !pTextLayout->m_bHasBlock;
68 } 68 }
69 FX_BOOL CXFA_FFText::PerformLayout() { 69 FX_BOOL CXFA_FFText::PerformLayout() {
70 CXFA_FFDraw::PerformLayout(); 70 CXFA_FFDraw::PerformLayout();
71 CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); 71 CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout();
72 if (!pTextLayout) { 72 if (!pTextLayout) {
73 return FALSE; 73 return FALSE;
74 } 74 }
75 if (!pTextLayout->m_bHasBlock) { 75 if (!pTextLayout->m_bHasBlock) {
76 return TRUE; 76 return TRUE;
77 } 77 }
78 pTextLayout->m_Blocks.RemoveAll(); 78 pTextLayout->m_Blocks.RemoveAll();
79 CXFA_LayoutItem* pItem = this; 79 CXFA_LayoutItem* pItem = this;
80 if (pItem->GetPrev() == NULL && pItem->GetNext() == NULL) { 80 if (!pItem->GetPrev() && !pItem->GetNext()) {
81 return TRUE; 81 return TRUE;
82 } 82 }
83 pItem = pItem->GetFirst(); 83 pItem = pItem->GetFirst();
84 while (pItem) { 84 while (pItem) {
85 CFX_RectF rtText; 85 CFX_RectF rtText;
86 pItem->GetRect(rtText); 86 pItem->GetRect(rtText);
87 if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) { 87 if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) {
88 if (pItem->GetPrev() == NULL) { 88 if (!pItem->GetPrev()) {
89 FX_FLOAT fTopInset; 89 FX_FLOAT fTopInset;
90 mgWidget.GetTopInset(fTopInset); 90 mgWidget.GetTopInset(fTopInset);
91 rtText.height -= fTopInset; 91 rtText.height -= fTopInset;
92 } else if (pItem->GetNext() == NULL) { 92 } else if (!pItem->GetNext()) {
93 FX_FLOAT fBottomInset; 93 FX_FLOAT fBottomInset;
94 mgWidget.GetBottomInset(fBottomInset); 94 mgWidget.GetBottomInset(fBottomInset);
95 rtText.height -= fBottomInset; 95 rtText.height -= fBottomInset;
96 } 96 }
97 } 97 }
98 pTextLayout->ItemBlocks(rtText, pItem->GetIndex()); 98 pTextLayout->ItemBlocks(rtText, pItem->GetIndex());
99 pItem = pItem->GetNext(); 99 pItem = pItem->GetNext();
100 } 100 }
101 pTextLayout->m_bHasBlock = FALSE; 101 pTextLayout->m_bHasBlock = FALSE;
102 return TRUE; 102 return TRUE;
103 } 103 }
104 FX_BOOL CXFA_FFText::OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { 104 FX_BOOL CXFA_FFText::OnLButtonDown(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) {
105 CFX_RectF rtBox; 105 CFX_RectF rtBox;
106 GetRectWithoutRotate(rtBox); 106 GetRectWithoutRotate(rtBox);
107 if (!rtBox.Contains(fx, fy)) { 107 if (!rtBox.Contains(fx, fy)) {
108 return FALSE; 108 return FALSE;
109 } 109 }
110 const FX_WCHAR* wsURLContent = GetLinkURLAtPoint(fx, fy); 110 const FX_WCHAR* wsURLContent = GetLinkURLAtPoint(fx, fy);
111 if (NULL == wsURLContent) { 111 if (!wsURLContent)
112 return FALSE; 112 return FALSE;
113 } 113
114 SetButtonDown(TRUE); 114 SetButtonDown(TRUE);
115 return TRUE; 115 return TRUE;
116 } 116 }
117
117 FX_BOOL CXFA_FFText::OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { 118 FX_BOOL CXFA_FFText::OnMouseMove(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) {
118 CFX_RectF rtBox; 119 CFX_RectF rtBox;
119 GetRectWithoutRotate(rtBox); 120 GetRectWithoutRotate(rtBox);
120 if (!rtBox.Contains(fx, fy)) { 121 if (!rtBox.Contains(fx, fy))
121 return FALSE; 122 return FALSE;
122 } 123 return !!GetLinkURLAtPoint(fx, fy);
123 const FX_WCHAR* wsURLContent = GetLinkURLAtPoint(fx, fy);
124 if (NULL == wsURLContent) {
125 return FALSE;
126 }
127 return TRUE;
128 } 124 }
125
129 FX_BOOL CXFA_FFText::OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) { 126 FX_BOOL CXFA_FFText::OnLButtonUp(uint32_t dwFlags, FX_FLOAT fx, FX_FLOAT fy) {
130 if (!IsButtonDown()) { 127 if (!IsButtonDown()) {
131 return FALSE; 128 return FALSE;
132 } 129 }
133 SetButtonDown(FALSE); 130 SetButtonDown(FALSE);
134 const FX_WCHAR* wsURLContent = GetLinkURLAtPoint(fx, fy); 131 const FX_WCHAR* wsURLContent = GetLinkURLAtPoint(fx, fy);
135 if (NULL == wsURLContent) { 132 if (!wsURLContent)
136 return FALSE; 133 return FALSE;
137 } 134
138 CXFA_FFDoc* pDoc = GetDoc(); 135 CXFA_FFDoc* pDoc = GetDoc();
139 pDoc->GetDocProvider()->GotoURL(pDoc, wsURLContent, FALSE); 136 pDoc->GetDocProvider()->GotoURL(pDoc, wsURLContent, FALSE);
140 return TRUE; 137 return TRUE;
141 } 138 }
139
142 FWL_WidgetHit CXFA_FFText::OnHitTest(FX_FLOAT fx, FX_FLOAT fy) { 140 FWL_WidgetHit CXFA_FFText::OnHitTest(FX_FLOAT fx, FX_FLOAT fy) {
143 CFX_RectF rtBox; 141 CFX_RectF rtBox;
144 GetRectWithoutRotate(rtBox); 142 GetRectWithoutRotate(rtBox);
145 if (!rtBox.Contains(fx, fy)) 143 if (!rtBox.Contains(fx, fy))
146 return FWL_WidgetHit::Unknown; 144 return FWL_WidgetHit::Unknown;
147 if (!GetLinkURLAtPoint(fx, fy)) 145 if (!GetLinkURLAtPoint(fx, fy))
148 return FWL_WidgetHit::Unknown; 146 return FWL_WidgetHit::Unknown;
149 return FWL_WidgetHit::HyperLink; 147 return FWL_WidgetHit::HyperLink;
150 } 148 }
151 const FX_WCHAR* CXFA_FFText::GetLinkURLAtPoint(FX_FLOAT fx, FX_FLOAT fy) { 149 const FX_WCHAR* CXFA_FFText::GetLinkURLAtPoint(FX_FLOAT fx, FX_FLOAT fy) {
152 CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); 150 CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout();
153 if (NULL == pTextLayout) { 151 if (!pTextLayout)
154 return NULL; 152 return nullptr;
155 } 153
156 FX_FLOAT x(fx), y(fy); 154 FX_FLOAT x(fx), y(fy);
157 FWLToClient(x, y); 155 FWLToClient(x, y);
158 const CXFA_PieceLineArray* pPieceLines = pTextLayout->GetPieceLines(); 156 const CXFA_PieceLineArray* pPieceLines = pTextLayout->GetPieceLines();
159 int32_t iCount = pPieceLines->GetSize(); 157 int32_t iCount = pPieceLines->GetSize();
160 for (int32_t i = 0; i < iCount; i++) { 158 for (int32_t i = 0; i < iCount; i++) {
161 CXFA_PieceLine* pPieceLine = pPieceLines->GetAt(i); 159 CXFA_PieceLine* pPieceLine = pPieceLines->GetAt(i);
162 int32_t iPieces = pPieceLine->m_textPieces.GetSize(); 160 int32_t iPieces = pPieceLine->m_textPieces.GetSize();
163 for (int32_t j = 0; j < iPieces; j++) { 161 for (int32_t j = 0; j < iPieces; j++) {
164 XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(j); 162 XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(j);
165 if (pPiece->pLinkData && pPiece->rtPiece.Contains(x, y)) { 163 if (pPiece->pLinkData && pPiece->rtPiece.Contains(x, y)) {
166 return pPiece->pLinkData->GetLinkURL(); 164 return pPiece->pLinkData->GetLinkURL();
167 } 165 }
168 } 166 }
169 } 167 }
170 return NULL; 168 return nullptr;
171 } 169 }
172 void CXFA_FFText::FWLToClient(FX_FLOAT& fx, FX_FLOAT& fy) { 170 void CXFA_FFText::FWLToClient(FX_FLOAT& fx, FX_FLOAT& fy) {
173 CFX_RectF rtWidget; 171 CFX_RectF rtWidget;
174 GetRectWithoutRotate(rtWidget); 172 GetRectWithoutRotate(rtWidget);
175 fx -= rtWidget.left; 173 fx -= rtWidget.left;
176 fy -= rtWidget.top; 174 fy -= rtWidget.top;
177 } 175 }
OLDNEW
« no previous file with comments | « xfa/fxfa/app/xfa_fftext.h ('k') | xfa/fxfa/app/xfa_fftextedit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698