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