| OLD | NEW |
| 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/cfwl_widgetmgr.h" | 7 #include "xfa/fwl/cfwl_widgetmgr.h" |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 const int kNeedRepaintHitPiece = 3; | 21 const int kNeedRepaintHitPiece = 3; |
| 22 | 22 |
| 23 struct FWL_NEEDREPAINTHITDATA { | 23 struct FWL_NEEDREPAINTHITDATA { |
| 24 CFX_PointF hitPoint; | 24 CFX_PointF hitPoint; |
| 25 bool bNotNeedRepaint; | 25 bool bNotNeedRepaint; |
| 26 bool bNotContainByDirty; | 26 bool bNotContainByDirty; |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 bool FWL_UseOffscreen(CFWL_Widget* pWidget) { | |
| 32 #if (_FX_OS_ == _FX_MACOSX_) | |
| 33 return false; | |
| 34 #else | |
| 35 return !!(pWidget->GetStyles() & FWL_WGTSTYLE_Offscreen); | |
| 36 #endif | |
| 37 } | |
| 38 | |
| 39 CFWL_WidgetMgr::CFWL_WidgetMgr(CXFA_FFApp* pAdapterNative) | 31 CFWL_WidgetMgr::CFWL_WidgetMgr(CXFA_FFApp* pAdapterNative) |
| 40 : m_dwCapability(0), m_pAdapter(pAdapterNative->GetWidgetMgr(this)) { | 32 : m_dwCapability(0), m_pAdapter(pAdapterNative->GetWidgetMgr(this)) { |
| 41 ASSERT(m_pAdapter); | 33 ASSERT(m_pAdapter); |
| 42 m_mapWidgetItem[nullptr] = pdfium::MakeUnique<Item>(); | 34 m_mapWidgetItem[nullptr] = pdfium::MakeUnique<Item>(); |
| 43 #if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) | 35 #if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) |
| 44 m_rtScreen.Reset(); | 36 m_rtScreen.Reset(); |
| 45 #endif | 37 #endif |
| 46 } | 38 } |
| 47 | 39 |
| 48 CFWL_WidgetMgr::~CFWL_WidgetMgr() {} | 40 CFWL_WidgetMgr::~CFWL_WidgetMgr() {} |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if (pItem->pParent->pChild == pItem) | 247 if (pItem->pParent->pChild == pItem) |
| 256 pItem->pParent->pChild = pItem->pNext; | 248 pItem->pParent->pChild = pItem->pNext; |
| 257 | 249 |
| 258 pItem->pNext = nullptr; | 250 pItem->pNext = nullptr; |
| 259 pItem->pPrevious = nullptr; | 251 pItem->pPrevious = nullptr; |
| 260 } | 252 } |
| 261 pItem->pParent = pParentItem; | 253 pItem->pParent = pParentItem; |
| 262 AppendWidget(pChild); | 254 AppendWidget(pChild); |
| 263 } | 255 } |
| 264 | 256 |
| 265 void CFWL_WidgetMgr::SetWidgetRect_Native(CFWL_Widget* pWidget, | |
| 266 const CFX_RectF& rect) { | |
| 267 if (!FWL_UseOffscreen(pWidget)) | |
| 268 return; | |
| 269 | |
| 270 Item* pItem = GetWidgetMgrItem(pWidget); | |
| 271 pItem->iRedrawCounter++; | |
| 272 if (pItem->pOffscreen) { | |
| 273 CFX_RenderDevice* pDevice = pItem->pOffscreen->GetRenderDevice(); | |
| 274 if (pDevice && pDevice->GetBitmap()) { | |
| 275 CFX_DIBitmap* pBitmap = pDevice->GetBitmap(); | |
| 276 if (pBitmap->GetWidth() - rect.width > 1 || | |
| 277 pBitmap->GetHeight() - rect.height > 1) { | |
| 278 pItem->pOffscreen.reset(); | |
| 279 } | |
| 280 } | |
| 281 } | |
| 282 #if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) | |
| 283 pItem->bOutsideChanged = !m_rtScreen.Contains(rect); | |
| 284 #endif | |
| 285 } | |
| 286 | |
| 287 CFWL_Widget* CFWL_WidgetMgr::GetWidgetAtPoint(CFWL_Widget* parent, | 257 CFWL_Widget* CFWL_WidgetMgr::GetWidgetAtPoint(CFWL_Widget* parent, |
| 288 FX_FLOAT x, | 258 FX_FLOAT x, |
| 289 FX_FLOAT y) { | 259 FX_FLOAT y) { |
| 290 if (!parent) | 260 if (!parent) |
| 291 return nullptr; | 261 return nullptr; |
| 292 | 262 |
| 293 FX_FLOAT x1; | 263 FX_FLOAT x1; |
| 294 FX_FLOAT y1; | 264 FX_FLOAT y1; |
| 295 CFWL_Widget* child = GetLastChildWidget(parent); | 265 CFWL_Widget* child = GetLastChildWidget(parent); |
| 296 while (child) { | 266 while (child) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 307 x1 -= bounds.left; | 277 x1 -= bounds.left; |
| 308 y1 -= bounds.top; | 278 y1 -= bounds.top; |
| 309 return GetWidgetAtPoint(child, x1, y1); | 279 return GetWidgetAtPoint(child, x1, y1); |
| 310 } | 280 } |
| 311 } | 281 } |
| 312 child = GetPriorSiblingWidget(child); | 282 child = GetPriorSiblingWidget(child); |
| 313 } | 283 } |
| 314 return parent; | 284 return parent; |
| 315 } | 285 } |
| 316 | 286 |
| 317 void CFWL_WidgetMgr::NotifySizeChanged(CFWL_Widget* pForm, | |
| 318 FX_FLOAT fx, | |
| 319 FX_FLOAT fy) { | |
| 320 if (FWL_UseOffscreen(pForm)) | |
| 321 GetWidgetMgrItem(pForm)->pOffscreen.reset(); | |
| 322 } | |
| 323 | |
| 324 CFWL_Widget* CFWL_WidgetMgr::NextTab(CFWL_Widget* parent, | 287 CFWL_Widget* CFWL_WidgetMgr::NextTab(CFWL_Widget* parent, |
| 325 CFWL_Widget* focus, | 288 CFWL_Widget* focus, |
| 326 bool& bFind) { | 289 bool& bFind) { |
| 327 CFWL_WidgetMgr* pMgr = parent->GetOwnerApp()->GetWidgetMgr(); | 290 CFWL_WidgetMgr* pMgr = parent->GetOwnerApp()->GetWidgetMgr(); |
| 328 CFWL_Widget* child = pMgr->GetFirstChildWidget(parent); | 291 CFWL_Widget* child = pMgr->GetFirstChildWidget(parent); |
| 329 while (child) { | 292 while (child) { |
| 330 if (focus == child) | 293 if (focus == child) |
| 331 bFind = true; | 294 bFind = true; |
| 332 | 295 |
| 333 CFWL_Widget* bRet = NextTab(child, focus, bFind); | 296 CFWL_Widget* bRet = NextTab(child, focus, bFind); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 pNoteDriver->UnqueueMessage(pTopLoop); | 421 pNoteDriver->UnqueueMessage(pTopLoop); |
| 459 #endif | 422 #endif |
| 460 } | 423 } |
| 461 | 424 |
| 462 void CFWL_WidgetMgr::OnDrawWidget(CFWL_Widget* pWidget, | 425 void CFWL_WidgetMgr::OnDrawWidget(CFWL_Widget* pWidget, |
| 463 CFX_Graphics* pGraphics, | 426 CFX_Graphics* pGraphics, |
| 464 const CFX_Matrix* pMatrix) { | 427 const CFX_Matrix* pMatrix) { |
| 465 if (!pWidget || !pGraphics) | 428 if (!pWidget || !pGraphics) |
| 466 return; | 429 return; |
| 467 | 430 |
| 468 CFX_Graphics* pTemp = DrawWidgetBefore(pWidget, pGraphics, pMatrix); | |
| 469 CFX_RectF clipCopy = pWidget->GetWidgetRect(); | 431 CFX_RectF clipCopy = pWidget->GetWidgetRect(); |
| 470 clipCopy.left = clipCopy.top = 0; | 432 clipCopy.left = clipCopy.top = 0; |
| 471 | 433 |
| 472 if (UseOffscreenDirect(pWidget)) { | |
| 473 DrawWidgetAfter(pWidget, pGraphics, clipCopy, pMatrix); | |
| 474 return; | |
| 475 } | |
| 476 CFX_RectF clipBounds; | 434 CFX_RectF clipBounds; |
| 477 | 435 |
| 478 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ || \ | 436 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN64_ || \ |
| 479 _FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_ANDROID_ | 437 _FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_ANDROID_ |
| 480 pWidget->GetDelegate()->OnDrawWidget(pTemp, pMatrix); | 438 pWidget->GetDelegate()->OnDrawWidget(pGraphics, pMatrix); |
| 481 pGraphics->GetClipRect(clipBounds); | 439 pGraphics->GetClipRect(clipBounds); |
| 482 clipCopy = clipBounds; | 440 clipCopy = clipBounds; |
| 483 #elif _FX_OS_ == _FX_MACOSX_ | 441 #elif _FX_OS_ == _FX_MACOSX_ |
| 484 if (IsFormDisabled()) { | 442 if (IsFormDisabled()) { |
| 485 pWidget->GetDelegate()->OnDrawWidget(pTemp, pMatrix); | 443 pWidget->GetDelegate()->OnDrawWidget(pGraphics, pMatrix); |
| 486 pGraphics->GetClipRect(clipBounds); | 444 pGraphics->GetClipRect(clipBounds); |
| 487 clipCopy = clipBounds; | 445 clipCopy = clipBounds; |
| 488 } else { | 446 } else { |
| 489 clipBounds.Set(pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d); | 447 clipBounds.Set(pMatrix->a, pMatrix->b, pMatrix->c, pMatrix->d); |
| 490 const_cast<CFX_Matrix*>(pMatrix)->SetIdentity(); // FIXME: const cast. | 448 const_cast<CFX_Matrix*>(pMatrix)->SetIdentity(); // FIXME: const cast. |
| 491 pWidget->GetDelegate()->OnDrawWidget(pTemp, pMatrix); | 449 pWidget->GetDelegate()->OnDrawWidget(pGraphics, pMatrix); |
| 492 } | 450 } |
| 493 #endif // _FX_OS_ == _FX_MACOSX_ | 451 #endif // _FX_OS_ == _FX_MACOSX_ |
| 494 | 452 |
| 495 if (!IsFormDisabled()) | 453 if (!IsFormDisabled()) |
| 496 clipBounds.Intersect(pWidget->GetClientRect()); | 454 clipBounds.Intersect(pWidget->GetClientRect()); |
| 497 if (!clipBounds.IsEmpty()) | 455 if (!clipBounds.IsEmpty()) |
| 498 DrawChild(pWidget, clipBounds, pTemp, pMatrix); | 456 DrawChild(pWidget, clipBounds, pGraphics, pMatrix); |
| 499 | 457 |
| 500 DrawWidgetAfter(pWidget, pGraphics, clipCopy, pMatrix); | 458 GetWidgetMgrItem(pWidget)->iRedrawCounter = 0; |
| 501 ResetRedrawCounts(pWidget); | 459 ResetRedrawCounts(pWidget); |
| 502 } | 460 } |
| 503 | 461 |
| 504 void CFWL_WidgetMgr::DrawChild(CFWL_Widget* parent, | 462 void CFWL_WidgetMgr::DrawChild(CFWL_Widget* parent, |
| 505 const CFX_RectF& rtClip, | 463 const CFX_RectF& rtClip, |
| 506 CFX_Graphics* pGraphics, | 464 CFX_Graphics* pGraphics, |
| 507 const CFX_Matrix* pMatrix) { | 465 const CFX_Matrix* pMatrix) { |
| 508 if (!parent) | 466 if (!parent) |
| 509 return; | 467 return; |
| 510 | 468 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 } | 502 } |
| 545 if (!bFormDisable) | 503 if (!bFormDisable) |
| 546 pGraphics->RestoreGraphState(); | 504 pGraphics->RestoreGraphState(); |
| 547 | 505 |
| 548 DrawChild(child, clipBounds, pGraphics, | 506 DrawChild(child, clipBounds, pGraphics, |
| 549 bFormDisable ? &widgetMatrix : pMatrix); | 507 bFormDisable ? &widgetMatrix : pMatrix); |
| 550 child = GetNextSiblingWidget(child); | 508 child = GetNextSiblingWidget(child); |
| 551 } | 509 } |
| 552 } | 510 } |
| 553 | 511 |
| 554 CFX_Graphics* CFWL_WidgetMgr::DrawWidgetBefore(CFWL_Widget* pWidget, | |
| 555 CFX_Graphics* pGraphics, | |
| 556 const CFX_Matrix* pMatrix) { | |
| 557 if (!FWL_UseOffscreen(pWidget)) | |
| 558 return pGraphics; | |
| 559 | |
| 560 Item* pItem = GetWidgetMgrItem(pWidget); | |
| 561 if (!pItem->pOffscreen) { | |
| 562 pItem->pOffscreen = pdfium::MakeUnique<CFX_Graphics>(); | |
| 563 CFX_RectF rect = pWidget->GetWidgetRect(); | |
| 564 pItem->pOffscreen->Create((int32_t)rect.width, (int32_t)rect.height, | |
| 565 FXDIB_Argb); | |
| 566 } | |
| 567 CFX_RectF rect; | |
| 568 pGraphics->GetClipRect(rect); | |
| 569 pItem->pOffscreen->SetClipRect(rect); | |
| 570 return pItem->pOffscreen.get(); | |
| 571 } | |
| 572 | |
| 573 void CFWL_WidgetMgr::DrawWidgetAfter(CFWL_Widget* pWidget, | |
| 574 CFX_Graphics* pGraphics, | |
| 575 CFX_RectF& rtClip, | |
| 576 const CFX_Matrix* pMatrix) { | |
| 577 if (FWL_UseOffscreen(pWidget)) { | |
| 578 Item* pItem = GetWidgetMgrItem(pWidget); | |
| 579 pGraphics->Transfer(pItem->pOffscreen.get(), rtClip.left, rtClip.top, | |
| 580 rtClip, pMatrix); | |
| 581 #ifdef _WIN32 | |
| 582 pItem->pOffscreen->ClearClip(); | |
| 583 #endif | |
| 584 } | |
| 585 Item* pItem = GetWidgetMgrItem(pWidget); | |
| 586 pItem->iRedrawCounter = 0; | |
| 587 } | |
| 588 | |
| 589 bool CFWL_WidgetMgr::IsNeedRepaint(CFWL_Widget* pWidget, | 512 bool CFWL_WidgetMgr::IsNeedRepaint(CFWL_Widget* pWidget, |
| 590 CFX_Matrix* pMatrix, | 513 CFX_Matrix* pMatrix, |
| 591 const CFX_RectF& rtDirty) { | 514 const CFX_RectF& rtDirty) { |
| 592 Item* pItem = GetWidgetMgrItem(pWidget); | 515 Item* pItem = GetWidgetMgrItem(pWidget); |
| 593 if (pItem && pItem->iRedrawCounter > 0) { | 516 if (pItem && pItem->iRedrawCounter > 0) { |
| 594 pItem->iRedrawCounter = 0; | 517 pItem->iRedrawCounter = 0; |
| 595 return true; | 518 return true; |
| 596 } | 519 } |
| 597 | 520 |
| 598 CFX_RectF rtWidget = pWidget->GetWidgetRect(); | 521 CFX_RectF rtWidget = pWidget->GetWidgetRect(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 } | 600 } |
| 678 if (repaintPoint > 0) | 601 if (repaintPoint > 0) |
| 679 return true; | 602 return true; |
| 680 | 603 |
| 681 pMatrix->TransformRect(rtChilds); | 604 pMatrix->TransformRect(rtChilds); |
| 682 if (rtChilds.Contains(rtDirty) || rtChilds.Contains(rtWidget)) | 605 if (rtChilds.Contains(rtDirty) || rtChilds.Contains(rtWidget)) |
| 683 return false; | 606 return false; |
| 684 return true; | 607 return true; |
| 685 } | 608 } |
| 686 | 609 |
| 687 bool CFWL_WidgetMgr::UseOffscreenDirect(CFWL_Widget* pWidget) const { | |
| 688 Item* pItem = GetWidgetMgrItem(pWidget); | |
| 689 if (!FWL_UseOffscreen(pWidget) || !(pItem->pOffscreen)) | |
| 690 return false; | |
| 691 | |
| 692 #if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) | |
| 693 if (pItem->bOutsideChanged) { | |
| 694 CFX_RectF r = pWidget->GetWidgetRect(); | |
| 695 CFX_RectF temp(m_rtScreen); | |
| 696 temp.Deflate(50, 50); | |
| 697 if (!temp.Contains(r)) | |
| 698 return false; | |
| 699 | |
| 700 pItem->bOutsideChanged = false; | |
| 701 } | |
| 702 #endif | |
| 703 | |
| 704 return pItem->iRedrawCounter == 0; | |
| 705 } | |
| 706 | |
| 707 CFWL_WidgetMgr::Item::Item() : CFWL_WidgetMgr::Item(nullptr) {} | 610 CFWL_WidgetMgr::Item::Item() : CFWL_WidgetMgr::Item(nullptr) {} |
| 708 | 611 |
| 709 CFWL_WidgetMgr::Item::Item(CFWL_Widget* widget) | 612 CFWL_WidgetMgr::Item::Item(CFWL_Widget* widget) |
| 710 : pParent(nullptr), | 613 : pParent(nullptr), |
| 711 pOwner(nullptr), | 614 pOwner(nullptr), |
| 712 pChild(nullptr), | 615 pChild(nullptr), |
| 713 pPrevious(nullptr), | 616 pPrevious(nullptr), |
| 714 pNext(nullptr), | 617 pNext(nullptr), |
| 715 pWidget(widget), | 618 pWidget(widget), |
| 716 iRedrawCounter(0) | 619 iRedrawCounter(0) |
| 717 #if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) | 620 #if (_FX_OS_ == _FX_WIN32_DESKTOP_) || (_FX_OS_ == _FX_WIN64_) |
| 718 , | 621 , |
| 719 bOutsideChanged(false) | 622 bOutsideChanged(false) |
| 720 #endif | 623 #endif |
| 721 { | 624 { |
| 722 } | 625 } |
| 723 | 626 |
| 724 CFWL_WidgetMgr::Item::~Item() {} | 627 CFWL_WidgetMgr::Item::~Item() {} |
| OLD | NEW |