Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 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 | |
Dan Sinclair | 24ef633 | 2017-07-24 10:52:57 -0400 | [diff] [blame] | 7 | #include "xfa/fxfa/cxfa_fftext.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 8 | |
dsinclair | 447b1f3 | 2016-12-08 10:06:32 -0800 | [diff] [blame] | 9 | #include "xfa/fwl/fwl_widgetdef.h" |
| 10 | #include "xfa/fwl/fwl_widgethit.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 11 | #include "xfa/fxfa/cxfa_ffapp.h" |
| 12 | #include "xfa/fxfa/cxfa_ffdoc.h" |
Dan Sinclair | 24ef633 | 2017-07-24 10:52:57 -0400 | [diff] [blame] | 13 | #include "xfa/fxfa/cxfa_ffdraw.h" |
Dan Sinclair | 80c4878 | 2017-03-23 12:11:20 -0400 | [diff] [blame] | 14 | #include "xfa/fxfa/cxfa_ffpageview.h" |
| 15 | #include "xfa/fxfa/cxfa_ffwidget.h" |
Dan Sinclair | 24ef633 | 2017-07-24 10:52:57 -0400 | [diff] [blame] | 16 | #include "xfa/fxfa/cxfa_linkuserdata.h" |
| 17 | #include "xfa/fxfa/cxfa_pieceline.h" |
| 18 | #include "xfa/fxfa/cxfa_textlayout.h" |
| 19 | #include "xfa/fxfa/cxfa_textpiece.h" |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 20 | #include "xfa/fxgraphics/cxfa_graphics.h" |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 21 | |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 22 | CXFA_FFText::CXFA_FFText(CXFA_WidgetAcc* pDataAcc) : CXFA_FFDraw(pDataAcc) {} |
| 23 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 24 | CXFA_FFText::~CXFA_FFText() {} |
dan sinclair | aaf0bdc | 2017-02-04 10:16:21 -0500 | [diff] [blame] | 25 | |
Dan Sinclair | 2b918c8 | 2017-07-13 14:47:10 -0400 | [diff] [blame] | 26 | void CXFA_FFText::RenderWidget(CXFA_Graphics* pGS, |
Lei Zhang | 7c9d4c2 | 2017-08-17 13:53:52 -0700 | [diff] [blame] | 27 | const CFX_Matrix& matrix, |
dsinclair | 9d6ca99 | 2016-06-16 10:51:56 -0700 | [diff] [blame] | 28 | uint32_t dwStatus) { |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 29 | if (!IsMatchVisibleStatus(dwStatus)) |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 30 | return; |
Dan Sinclair | bba2a7c | 2017-02-07 16:36:39 -0500 | [diff] [blame] | 31 | |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 32 | CFX_Matrix mtRotate = GetRotateMatrix(); |
Lei Zhang | 7c9d4c2 | 2017-08-17 13:53:52 -0700 | [diff] [blame] | 33 | mtRotate.Concat(matrix); |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 34 | |
Lei Zhang | 7c9d4c2 | 2017-08-17 13:53:52 -0700 | [diff] [blame] | 35 | CXFA_FFWidget::RenderWidget(pGS, mtRotate, dwStatus); |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 36 | |
| 37 | CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); |
| 38 | if (!pTextLayout) |
| 39 | return; |
| 40 | |
| 41 | CFX_RenderDevice* pRenderDevice = pGS->GetRenderDevice(); |
| 42 | CFX_RectF rtText = GetRectWithoutRotate(); |
| 43 | if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) { |
| 44 | CXFA_LayoutItem* pItem = this; |
| 45 | if (!pItem->GetPrev() && !pItem->GetNext()) { |
| 46 | XFA_RectWidthoutMargin(rtText, mgWidget); |
| 47 | } else { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 48 | float fLeftInset; |
| 49 | float fRightInset; |
| 50 | float fTopInset = 0; |
| 51 | float fBottomInset = 0; |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 52 | mgWidget.GetLeftInset(fLeftInset); |
| 53 | mgWidget.GetRightInset(fRightInset); |
| 54 | if (!pItem->GetPrev()) |
| 55 | mgWidget.GetTopInset(fTopInset); |
| 56 | else if (!pItem->GetNext()) |
| 57 | mgWidget.GetBottomInset(fBottomInset); |
| 58 | |
| 59 | rtText.Deflate(fLeftInset, fTopInset, fRightInset, fBottomInset); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 60 | } |
| 61 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 62 | |
| 63 | CFX_Matrix mt(1, 0, 0, 1, rtText.left, rtText.top); |
Jane Liu | 878b27d | 2017-08-22 10:50:06 -0400 | [diff] [blame] | 64 | CFX_RectF rtClip = mtRotate.TransformRect(rtText); |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 65 | mt.Concat(mtRotate); |
| 66 | pTextLayout->DrawString(pRenderDevice, mt, rtClip, GetIndex()); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 67 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 68 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 69 | bool CXFA_FFText::IsLoaded() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 70 | CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); |
| 71 | return pTextLayout && !pTextLayout->m_bHasBlock; |
| 72 | } |
Dan Sinclair | ed991c7 | 2017-04-24 16:26:11 -0400 | [diff] [blame] | 73 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 74 | bool CXFA_FFText::PerformLayout() { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 75 | CXFA_FFDraw::PerformLayout(); |
| 76 | CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); |
Tom Sepez | fcc309e | 2017-03-24 14:19:11 -0700 | [diff] [blame] | 77 | if (!pTextLayout) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 78 | return false; |
Tom Sepez | fcc309e | 2017-03-24 14:19:11 -0700 | [diff] [blame] | 79 | if (!pTextLayout->m_bHasBlock) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 80 | return true; |
Tom Sepez | fcc309e | 2017-03-24 14:19:11 -0700 | [diff] [blame] | 81 | |
| 82 | pTextLayout->m_Blocks.clear(); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 83 | CXFA_LayoutItem* pItem = this; |
Dan Sinclair | ed991c7 | 2017-04-24 16:26:11 -0400 | [diff] [blame] | 84 | if (!pItem->GetPrev() && !pItem->GetNext()) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 85 | return true; |
Dan Sinclair | ed991c7 | 2017-04-24 16:26:11 -0400 | [diff] [blame] | 86 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 87 | pItem = pItem->GetFirst(); |
| 88 | while (pItem) { |
Dan Sinclair | c222907 | 2017-02-07 09:04:28 -0500 | [diff] [blame] | 89 | CFX_RectF rtText = pItem->GetRect(false); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 90 | if (CXFA_Margin mgWidget = m_pDataAcc->GetMargin()) { |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 91 | if (!pItem->GetPrev()) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 92 | float fTopInset; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 93 | mgWidget.GetTopInset(fTopInset); |
| 94 | rtText.height -= fTopInset; |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 95 | } else if (!pItem->GetNext()) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 96 | float fBottomInset; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 97 | mgWidget.GetBottomInset(fBottomInset); |
| 98 | rtText.height -= fBottomInset; |
| 99 | } |
| 100 | } |
| 101 | pTextLayout->ItemBlocks(rtText, pItem->GetIndex()); |
| 102 | pItem = pItem->GetNext(); |
| 103 | } |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 104 | pTextLayout->m_bHasBlock = false; |
| 105 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 106 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 107 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 108 | bool CXFA_FFText::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) { |
| 109 | if (!GetRectWithoutRotate().Contains(point)) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 110 | return false; |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 111 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 112 | const wchar_t* wsURLContent = GetLinkURLAtPoint(point); |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 113 | if (!wsURLContent) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 114 | return false; |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 115 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 116 | SetButtonDown(true); |
| 117 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 118 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 119 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 120 | bool CXFA_FFText::OnMouseMove(uint32_t dwFlags, const CFX_PointF& point) { |
| 121 | return GetRectWithoutRotate().Contains(point) && !!GetLinkURLAtPoint(point); |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 122 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 123 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 124 | bool CXFA_FFText::OnLButtonUp(uint32_t dwFlags, const CFX_PointF& point) { |
| 125 | if (!IsButtonDown()) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 126 | return false; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 127 | |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 128 | SetButtonDown(false); |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 129 | const wchar_t* wsURLContent = GetLinkURLAtPoint(point); |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 130 | if (!wsURLContent) |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 131 | return false; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 132 | |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 133 | CXFA_FFDoc* pDoc = GetDoc(); |
dsinclair | 577ad2c | 2016-09-22 10:20:43 -0700 | [diff] [blame] | 134 | pDoc->GetDocEnvironment()->GotoURL(pDoc, wsURLContent); |
tsepez | d19e912 | 2016-11-02 15:43:18 -0700 | [diff] [blame] | 135 | return true; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 136 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 137 | |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 138 | FWL_WidgetHit CXFA_FFText::OnHitTest(const CFX_PointF& point) { |
| 139 | if (!GetRectWithoutRotate().Contains(point)) |
dsinclair | 89fcde8 | 2016-05-03 13:00:25 -0700 | [diff] [blame] | 140 | return FWL_WidgetHit::Unknown; |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 141 | if (!GetLinkURLAtPoint(point)) |
dsinclair | 89fcde8 | 2016-05-03 13:00:25 -0700 | [diff] [blame] | 142 | return FWL_WidgetHit::Unknown; |
| 143 | return FWL_WidgetHit::HyperLink; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 144 | } |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 145 | |
Dan Sinclair | 812e96c | 2017-03-13 16:43:37 -0400 | [diff] [blame] | 146 | const wchar_t* CXFA_FFText::GetLinkURLAtPoint(const CFX_PointF& point) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 147 | CXFA_TextLayout* pTextLayout = m_pDataAcc->GetTextLayout(); |
tsepez | 783a7e0 | 2017-01-17 11:05:57 -0800 | [diff] [blame] | 148 | if (!pTextLayout) |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 149 | return nullptr; |
tsepez | 783a7e0 | 2017-01-17 11:05:57 -0800 | [diff] [blame] | 150 | |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 151 | CFX_RectF rect = GetRectWithoutRotate(); |
tsepez | 783a7e0 | 2017-01-17 11:05:57 -0800 | [diff] [blame] | 152 | for (const auto& pPieceLine : *pTextLayout->GetPieceLines()) { |
| 153 | for (const auto& pPiece : pPieceLine->m_textPieces) { |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 154 | if (pPiece->pLinkData && |
Dan Sinclair | b45ea1f | 2017-02-21 14:27:59 -0500 | [diff] [blame] | 155 | pPiece->rtPiece.Contains(point - rect.TopLeft())) { |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 156 | return pPiece->pLinkData->GetLinkURL(); |
Dan Sinclair | 1b08df1 | 2017-02-09 09:17:20 -0500 | [diff] [blame] | 157 | } |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 158 | } |
| 159 | } |
dsinclair | 85d1f2c | 2016-06-23 12:40:16 -0700 | [diff] [blame] | 160 | return nullptr; |
Dan Sinclair | 1770c02 | 2016-03-14 14:14:16 -0400 | [diff] [blame] | 161 | } |