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

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

Issue 1803723002: Move xfa/src up to xfa/. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 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/src/fxfa/app/xfa_fftext.h ('k') | xfa/src/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
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/src/fxfa/app/xfa_fftext.h"
8
9 #include "xfa/include/fwl/core/fwl_widgetdef.h"
10 #include "xfa/include/fxgraphics/fx_graphics.h"
11 #include "xfa/src/fxfa/app/xfa_ffapp.h"
12 #include "xfa/src/fxfa/app/xfa_ffdoc.h"
13 #include "xfa/src/fxfa/app/xfa_ffdraw.h"
14 #include "xfa/src/fxfa/app/xfa_ffpageview.h"
15 #include "xfa/src/fxfa/app/xfa_ffwidget.h"
16 #include "xfa/src/fxfa/app/xfa_textlayout.h"
17
18 CXFA_FFText::CXFA_FFText(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc)
19 : CXFA_FFDraw(pPageView, pDataAcc) {}
20 CXFA_FFText::~CXFA_FFText() {}
21 void CXFA_FFText::RenderWidget(CFX_Graphics* pGS,
22 CFX_Matrix* pMatrix,
23 FX_DWORD dwStatus,
24 int32_t iRotate) {
25 if (!IsMatchVisibleStatus(dwStatus)) {
26 return;
27 }
28 {
29 CFX_Matrix mtRotate;
30 GetRotateMatrix(mtRotate);
31 if (pMatrix) {
32 mtRotate.Concat(*pMatrix);
33 }
34 CXFA_FFWidget::RenderWidget(pGS, &mtRotate, dwStatus);
35 CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout();
36 if (pTextLayout) {
37 CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice();
38 CFX_RectF rtText;
39 GetRectWithoutRotate(rtText);
40 if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) {
41 CXFA_LayoutItem* pItem = this;
42 if (pItem->GetPrev() == NULL && pItem->GetNext() == NULL) {
43 XFA_RectWidthoutMargin(rtText, mgWidget);
44 } else {
45 FX_FLOAT fLeftInset, fRightInset, fTopInset = 0, fBottomInset = 0;
46 mgWidget.GetLeftInset(fLeftInset);
47 mgWidget.GetRightInset(fRightInset);
48 if (pItem->GetPrev() == NULL) {
49 mgWidget.GetTopInset(fTopInset);
50 } else if (pItem->GetNext() == NULL) {
51 mgWidget.GetBottomInset(fBottomInset);
52 }
53 rtText.Deflate(fLeftInset, fTopInset, fRightInset, fBottomInset);
54 }
55 }
56 CFX_Matrix mt;
57 mt.Set(1, 0, 0, 1, rtText.left, rtText.top);
58 CFX_RectF rtClip = rtText;
59 mtRotate.TransformRect(rtClip);
60 mt.Concat(mtRotate);
61 pTextLayout->DrawString(pRenderDevice, mt, rtClip, GetIndex());
62 }
63 }
64 }
65 FX_BOOL CXFA_FFText::IsLoaded() {
66 CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout();
67 return pTextLayout && !pTextLayout->m_bHasBlock;
68 }
69 FX_BOOL CXFA_FFText::PerformLayout() {
70 CXFA_FFDraw::PerformLayout();
71 CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout();
72 if (!pTextLayout) {
73 return FALSE;
74 }
75 if (!pTextLayout->m_bHasBlock) {
76 return TRUE;
77 }
78 pTextLayout->m_Blocks.RemoveAll();
79 CXFA_LayoutItem* pItem = this;
80 if (pItem->GetPrev() == NULL && pItem->GetNext() == NULL) {
81 return TRUE;
82 }
83 pItem = pItem->GetFirst();
84 while (pItem) {
85 CFX_RectF rtText;
86 pItem->GetRect(rtText);
87 if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) {
88 if (pItem->GetPrev() == NULL) {
89 FX_FLOAT fTopInset;
90 mgWidget.GetTopInset(fTopInset);
91 rtText.height -= fTopInset;
92 } else if (pItem->GetNext() == NULL) {
93 FX_FLOAT fBottomInset;
94 mgWidget.GetBottomInset(fBottomInset);
95 rtText.height -= fBottomInset;
96 }
97 }
98 pTextLayout->ItemBlocks(rtText, pItem->GetIndex());
99 pItem = pItem->GetNext();
100 }
101 pTextLayout->m_bHasBlock = FALSE;
102 return TRUE;
103 }
104 FX_BOOL CXFA_FFText::OnLButtonDown(FX_DWORD dwFlags, FX_FLOAT fx, FX_FLOAT fy) {
105 CFX_RectF rtBox;
106 GetRectWithoutRotate(rtBox);
107 if (!rtBox.Contains(fx, fy)) {
108 return FALSE;
109 }
110 const FX_WCHAR* wsURLContent = GetLinkURLAtPoint(fx, fy);
111 if (NULL == wsURLContent) {
112 return FALSE;
113 }
114 SetButtonDown(TRUE);
115 return TRUE;
116 }
117 FX_BOOL CXFA_FFText::OnMouseMove(FX_DWORD dwFlags, FX_FLOAT fx, FX_FLOAT fy) {
118 CFX_RectF rtBox;
119 GetRectWithoutRotate(rtBox);
120 if (!rtBox.Contains(fx, fy)) {
121 return FALSE;
122 }
123 const FX_WCHAR* wsURLContent = GetLinkURLAtPoint(fx, fy);
124 if (NULL == wsURLContent) {
125 return FALSE;
126 }
127 return TRUE;
128 }
129 FX_BOOL CXFA_FFText::OnLButtonUp(FX_DWORD dwFlags, FX_FLOAT fx, FX_FLOAT fy) {
130 if (!IsButtonDown()) {
131 return FALSE;
132 }
133 SetButtonDown(FALSE);
134 const FX_WCHAR* wsURLContent = GetLinkURLAtPoint(fx, fy);
135 if (NULL == wsURLContent) {
136 return FALSE;
137 }
138 CXFA_FFDoc* pDoc = GetDoc();
139 pDoc->GetDocProvider()->GotoURL(pDoc, CFX_WideStringC(wsURLContent), FALSE);
140 return TRUE;
141 }
142 FX_DWORD CXFA_FFText::OnHitTest(FX_FLOAT fx, FX_FLOAT fy) {
143 CFX_RectF rtBox;
144 GetRectWithoutRotate(rtBox);
145 if (!rtBox.Contains(fx, fy)) {
146 return FWL_WGTHITTEST_Unknown;
147 }
148 if (!GetLinkURLAtPoint(fx, fy)) {
149 return FWL_WGTHITTEST_Unknown;
150 }
151 return FWL_WGTHITTEST_HyperLink;
152 }
153 const FX_WCHAR* CXFA_FFText::GetLinkURLAtPoint(FX_FLOAT fx, FX_FLOAT fy) {
154 CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout();
155 if (NULL == pTextLayout) {
156 return NULL;
157 }
158 FX_FLOAT x(fx), y(fy);
159 FWLToClient(x, y);
160 const CXFA_PieceLineArray* pPieceLines = pTextLayout->GetPieceLines();
161 int32_t iCount = pPieceLines->GetSize();
162 for (int32_t i = 0; i < iCount; i++) {
163 CXFA_PieceLine* pPieceLine = pPieceLines->GetAt(i);
164 int32_t iPieces = pPieceLine->m_textPieces.GetSize();
165 for (int32_t j = 0; j < iPieces; j++) {
166 XFA_TextPiece* pPiece = pPieceLine->m_textPieces.GetAt(j);
167 if (pPiece->pLinkData && pPiece->rtPiece.Contains(x, y)) {
168 return pPiece->pLinkData->GetLinkURL();
169 }
170 }
171 }
172 return NULL;
173 }
174 void CXFA_FFText::FWLToClient(FX_FLOAT& fx, FX_FLOAT& fy) {
175 CFX_RectF rtWidget;
176 GetRectWithoutRotate(rtWidget);
177 fx -= rtWidget.left;
178 fy -= rtWidget.top;
179 }
OLDNEW
« no previous file with comments | « xfa/src/fxfa/app/xfa_fftext.h ('k') | xfa/src/fxfa/app/xfa_fftextedit.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698