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_widget.h" | 7 #include "xfa/fwl/cfwl_widget.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <utility> | 10 #include <utility> |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 } | 85 } |
86 | 86 |
87 void CFWL_Widget::SetWidgetRect(const CFX_RectF& rect) { | 87 void CFWL_Widget::SetWidgetRect(const CFX_RectF& rect) { |
88 m_pProperties->m_rtWidget = rect; | 88 m_pProperties->m_rtWidget = rect; |
89 if (IsChild()) | 89 if (IsChild()) |
90 return; | 90 return; |
91 | 91 |
92 m_pWidgetMgr->SetWidgetRect_Native(this, rect); | 92 m_pWidgetMgr->SetWidgetRect_Native(this, rect); |
93 } | 93 } |
94 | 94 |
95 void CFWL_Widget::GetClientRect(CFX_RectF& rect) { | 95 CFX_RectF CFWL_Widget::GetClientRect() { |
96 GetEdgeRect(rect); | 96 CFX_RectF rect = GetEdgeRect(); |
97 if (HasEdge()) { | 97 if (HasEdge()) { |
98 FX_FLOAT fEdge = GetEdgeWidth(); | 98 FX_FLOAT fEdge = GetEdgeWidth(); |
99 rect.Deflate(fEdge, fEdge); | 99 rect.Deflate(fEdge, fEdge); |
100 } | 100 } |
| 101 return rect; |
101 } | 102 } |
102 | 103 |
103 void CFWL_Widget::SetParent(CFWL_Widget* pParent) { | 104 void CFWL_Widget::SetParent(CFWL_Widget* pParent) { |
104 m_pProperties->m_pParent = pParent; | 105 m_pProperties->m_pParent = pParent; |
105 m_pWidgetMgr->SetParent(pParent, this); | 106 m_pWidgetMgr->SetParent(pParent, this); |
106 } | 107 } |
107 | 108 |
108 uint32_t CFWL_Widget::GetStyles() const { | 109 uint32_t CFWL_Widget::GetStyles() const { |
109 return m_pProperties->m_dwStyles; | 110 return m_pProperties->m_dwStyles; |
110 } | 111 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 child = widgetMgr->GetNextSiblingWidget(child); | 156 child = widgetMgr->GetNextSiblingWidget(child); |
156 } | 157 } |
157 return; | 158 return; |
158 } | 159 } |
159 | 160 |
160 void CFWL_Widget::RemoveStates(uint32_t dwStates) { | 161 void CFWL_Widget::RemoveStates(uint32_t dwStates) { |
161 m_pProperties->m_dwStates &= ~dwStates; | 162 m_pProperties->m_dwStates &= ~dwStates; |
162 } | 163 } |
163 | 164 |
164 FWL_WidgetHit CFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 165 FWL_WidgetHit CFWL_Widget::HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
165 CFX_RectF rtClient; | 166 if (GetClientRect().Contains(fx, fy)) |
166 GetClientRect(rtClient); | |
167 if (rtClient.Contains(fx, fy)) | |
168 return FWL_WidgetHit::Client; | 167 return FWL_WidgetHit::Client; |
169 if (HasEdge()) { | 168 if (HasEdge() && GetEdgeRect().Contains(fx, fy)) |
170 CFX_RectF rtEdge; | 169 return FWL_WidgetHit::Edge; |
171 GetEdgeRect(rtEdge); | 170 if (HasBorder() && GetRelativeRect().Contains(fx, fy)) |
172 if (rtEdge.Contains(fx, fy)) | 171 return FWL_WidgetHit::Border; |
173 return FWL_WidgetHit::Edge; | |
174 } | |
175 if (HasBorder()) { | |
176 CFX_RectF rtRelative; | |
177 GetRelativeRect(rtRelative); | |
178 if (rtRelative.Contains(fx, fy)) | |
179 return FWL_WidgetHit::Border; | |
180 } | |
181 return FWL_WidgetHit::Unknown; | 172 return FWL_WidgetHit::Unknown; |
182 } | 173 } |
183 | 174 |
184 void CFWL_Widget::TransformTo(CFWL_Widget* pWidget, | 175 void CFWL_Widget::TransformTo(CFWL_Widget* pWidget, |
185 FX_FLOAT& fx, | 176 FX_FLOAT& fx, |
186 FX_FLOAT& fy) { | 177 FX_FLOAT& fy) { |
187 if (m_pWidgetMgr->IsFormDisabled()) { | 178 if (m_pWidgetMgr->IsFormDisabled()) { |
188 CFX_SizeF szOffset; | 179 CFX_SizeF szOffset; |
189 if (IsParent(pWidget)) { | 180 if (IsParent(pWidget)) { |
190 szOffset = GetOffsetFromParent(pWidget); | 181 szOffset = GetOffsetFromParent(pWidget); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 301 } |
311 | 302 |
312 bool CFWL_Widget::IsChild() const { | 303 bool CFWL_Widget::IsChild() const { |
313 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Child); | 304 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Child); |
314 } | 305 } |
315 | 306 |
316 bool CFWL_Widget::IsOffscreen() const { | 307 bool CFWL_Widget::IsOffscreen() const { |
317 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Offscreen); | 308 return !!(m_pProperties->m_dwStyles & FWL_WGTSTYLE_Offscreen); |
318 } | 309 } |
319 | 310 |
320 void CFWL_Widget::GetEdgeRect(CFX_RectF& rtEdge) { | 311 CFX_RectF CFWL_Widget::GetEdgeRect() { |
321 rtEdge = m_pProperties->m_rtWidget; | 312 CFX_RectF rtEdge = m_pProperties->m_rtWidget; |
322 rtEdge.left = rtEdge.top = 0; | 313 rtEdge.left = rtEdge.top = 0; |
323 if (HasBorder()) { | 314 if (HasBorder()) { |
324 FX_FLOAT fCX = GetBorderSize(true); | 315 FX_FLOAT fCX = GetBorderSize(true); |
325 FX_FLOAT fCY = GetBorderSize(false); | 316 FX_FLOAT fCY = GetBorderSize(false); |
326 rtEdge.Deflate(fCX, fCY); | 317 rtEdge.Deflate(fCX, fCY); |
327 } | 318 } |
| 319 return rtEdge; |
328 } | 320 } |
329 | 321 |
330 FX_FLOAT CFWL_Widget::GetBorderSize(bool bCX) { | 322 FX_FLOAT CFWL_Widget::GetBorderSize(bool bCX) { |
331 FX_FLOAT* pfBorder = static_cast<FX_FLOAT*>(GetThemeCapacity( | 323 FX_FLOAT* pfBorder = static_cast<FX_FLOAT*>(GetThemeCapacity( |
332 bCX ? CFWL_WidgetCapacity::CXBorder : CFWL_WidgetCapacity::CYBorder)); | 324 bCX ? CFWL_WidgetCapacity::CXBorder : CFWL_WidgetCapacity::CYBorder)); |
333 if (!pfBorder) | 325 if (!pfBorder) |
334 return 0; | 326 return 0; |
335 return *pfBorder; | 327 return *pfBorder; |
336 } | 328 } |
337 | 329 |
(...skipping 13 matching lines...) Expand all Loading... |
351 break; | 343 break; |
352 } | 344 } |
353 } | 345 } |
354 if (dwCapacity != CFWL_WidgetCapacity::None) { | 346 if (dwCapacity != CFWL_WidgetCapacity::None) { |
355 FX_FLOAT* fRet = static_cast<FX_FLOAT*>(GetThemeCapacity(dwCapacity)); | 347 FX_FLOAT* fRet = static_cast<FX_FLOAT*>(GetThemeCapacity(dwCapacity)); |
356 return fRet ? *fRet : 0; | 348 return fRet ? *fRet : 0; |
357 } | 349 } |
358 return 0; | 350 return 0; |
359 } | 351 } |
360 | 352 |
361 void CFWL_Widget::GetRelativeRect(CFX_RectF& rect) { | 353 CFX_RectF CFWL_Widget::GetRelativeRect() { |
362 rect = m_pProperties->m_rtWidget; | 354 CFX_RectF rect = m_pProperties->m_rtWidget; |
363 rect.left = rect.top = 0; | 355 rect.left = 0; |
| 356 rect.top = 0; |
| 357 return rect; |
364 } | 358 } |
365 | 359 |
366 void* CFWL_Widget::GetThemeCapacity(CFWL_WidgetCapacity dwCapacity) { | 360 void* CFWL_Widget::GetThemeCapacity(CFWL_WidgetCapacity dwCapacity) { |
367 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); | 361 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); |
368 if (!pTheme) | 362 if (!pTheme) |
369 return nullptr; | 363 return nullptr; |
370 | 364 |
371 CFWL_ThemePart part; | 365 CFWL_ThemePart part; |
372 part.m_pWidget = this; | 366 part.m_pWidget = this; |
373 return pTheme->GetCapacity(&part, dwCapacity); | 367 return pTheme->GetCapacity(&part, dwCapacity); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
595 const CFWL_App* pApp = GetOwnerApp(); | 589 const CFWL_App* pApp = GetOwnerApp(); |
596 if (!pApp) | 590 if (!pApp) |
597 return; | 591 return; |
598 | 592 |
599 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); | 593 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); |
600 if (!pNoteDriver) | 594 if (!pNoteDriver) |
601 return; | 595 return; |
602 pNoteDriver->SendEvent(pEvent); | 596 pNoteDriver->SendEvent(pEvent); |
603 } | 597 } |
604 | 598 |
605 void CFWL_Widget::Repaint(const CFX_RectF* pRect) { | 599 void CFWL_Widget::Repaint() { |
606 if (pRect) { | |
607 m_pWidgetMgr->RepaintWidget(this, pRect); | |
608 return; | |
609 } | |
610 CFX_RectF rect; | 600 CFX_RectF rect; |
611 rect = m_pProperties->m_rtWidget; | 601 rect = m_pProperties->m_rtWidget; |
612 rect.left = rect.top = 0; | 602 rect.left = 0; |
613 m_pWidgetMgr->RepaintWidget(this, &rect); | 603 rect.top = 0; |
| 604 RepaintRect(rect); |
| 605 } |
| 606 |
| 607 void CFWL_Widget::RepaintRect(const CFX_RectF& pRect) { |
| 608 m_pWidgetMgr->RepaintWidget(this, pRect); |
614 } | 609 } |
615 | 610 |
616 void CFWL_Widget::DrawBackground(CFX_Graphics* pGraphics, | 611 void CFWL_Widget::DrawBackground(CFX_Graphics* pGraphics, |
617 CFWL_Part iPartBk, | 612 CFWL_Part iPartBk, |
618 IFWL_ThemeProvider* pTheme, | 613 IFWL_ThemeProvider* pTheme, |
619 const CFX_Matrix* pMatrix) { | 614 const CFX_Matrix* pMatrix) { |
620 CFX_RectF rtRelative; | |
621 GetRelativeRect(rtRelative); | |
622 CFWL_ThemeBackground param; | 615 CFWL_ThemeBackground param; |
623 param.m_pWidget = this; | 616 param.m_pWidget = this; |
624 param.m_iPart = iPartBk; | 617 param.m_iPart = iPartBk; |
625 param.m_pGraphics = pGraphics; | 618 param.m_pGraphics = pGraphics; |
626 if (pMatrix) | 619 if (pMatrix) |
627 param.m_matrix.Concat(*pMatrix, true); | 620 param.m_matrix.Concat(*pMatrix, true); |
628 param.m_rtPart = rtRelative; | 621 param.m_rtPart = GetRelativeRect(); |
629 pTheme->DrawBackground(¶m); | 622 pTheme->DrawBackground(¶m); |
630 } | 623 } |
631 | 624 |
632 void CFWL_Widget::DrawBorder(CFX_Graphics* pGraphics, | 625 void CFWL_Widget::DrawBorder(CFX_Graphics* pGraphics, |
633 CFWL_Part iPartBorder, | 626 CFWL_Part iPartBorder, |
634 IFWL_ThemeProvider* pTheme, | 627 IFWL_ThemeProvider* pTheme, |
635 const CFX_Matrix* pMatrix) { | 628 const CFX_Matrix* pMatrix) { |
636 CFX_RectF rtRelative; | |
637 GetRelativeRect(rtRelative); | |
638 CFWL_ThemeBackground param; | 629 CFWL_ThemeBackground param; |
639 param.m_pWidget = this; | 630 param.m_pWidget = this; |
640 param.m_iPart = iPartBorder; | 631 param.m_iPart = iPartBorder; |
641 param.m_pGraphics = pGraphics; | 632 param.m_pGraphics = pGraphics; |
642 if (pMatrix) | 633 if (pMatrix) |
643 param.m_matrix.Concat(*pMatrix, true); | 634 param.m_matrix.Concat(*pMatrix, true); |
644 param.m_rtPart = rtRelative; | 635 param.m_rtPart = GetRelativeRect(); |
645 pTheme->DrawBackground(¶m); | 636 pTheme->DrawBackground(¶m); |
646 } | 637 } |
647 | 638 |
648 void CFWL_Widget::DrawEdge(CFX_Graphics* pGraphics, | 639 void CFWL_Widget::DrawEdge(CFX_Graphics* pGraphics, |
649 CFWL_Part iPartEdge, | 640 CFWL_Part iPartEdge, |
650 IFWL_ThemeProvider* pTheme, | 641 IFWL_ThemeProvider* pTheme, |
651 const CFX_Matrix* pMatrix) { | 642 const CFX_Matrix* pMatrix) { |
652 CFX_RectF rtEdge; | |
653 GetEdgeRect(rtEdge); | |
654 CFWL_ThemeBackground param; | 643 CFWL_ThemeBackground param; |
655 param.m_pWidget = this; | 644 param.m_pWidget = this; |
656 param.m_iPart = iPartEdge; | 645 param.m_iPart = iPartEdge; |
657 param.m_pGraphics = pGraphics; | 646 param.m_pGraphics = pGraphics; |
658 if (pMatrix) | 647 if (pMatrix) |
659 param.m_matrix.Concat(*pMatrix, true); | 648 param.m_matrix.Concat(*pMatrix, true); |
660 param.m_rtPart = rtEdge; | 649 param.m_rtPart = GetEdgeRect(); |
661 pTheme->DrawBackground(¶m); | 650 pTheme->DrawBackground(¶m); |
662 } | 651 } |
663 | 652 |
664 void CFWL_Widget::NotifyDriver() { | 653 void CFWL_Widget::NotifyDriver() { |
665 const CFWL_App* pApp = GetOwnerApp(); | 654 const CFWL_App* pApp = GetOwnerApp(); |
666 if (!pApp) | 655 if (!pApp) |
667 return; | 656 return; |
668 | 657 |
669 CFWL_NoteDriver* pDriver = | 658 CFWL_NoteDriver* pDriver = |
670 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | 659 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 } | 709 } |
721 default: | 710 default: |
722 break; | 711 break; |
723 } | 712 } |
724 } | 713 } |
725 | 714 |
726 void CFWL_Widget::OnProcessEvent(CFWL_Event* pEvent) {} | 715 void CFWL_Widget::OnProcessEvent(CFWL_Event* pEvent) {} |
727 | 716 |
728 void CFWL_Widget::OnDrawWidget(CFX_Graphics* pGraphics, | 717 void CFWL_Widget::OnDrawWidget(CFX_Graphics* pGraphics, |
729 const CFX_Matrix* pMatrix) {} | 718 const CFX_Matrix* pMatrix) {} |
OLD | NEW |