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

Side by Side Diff: xfa/fwl/cfwl_widget.cpp

Issue 2560873005: Cleanup CFWL_Widget code to return CFX_RectFs where appropriate (Closed)
Patch Set: Created 4 years 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
OLDNEW
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
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
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))
Tom Sepez 2016/12/08 19:16:20 nice.
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
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
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 = rect.top = 0;
Tom Sepez 2016/12/08 19:16:20 nit: separate lines.
dsinclair 2016/12/08 19:20:47 Done.
356 return rect;
364 } 357 }
365 358
366 void* CFWL_Widget::GetThemeCapacity(CFWL_WidgetCapacity dwCapacity) { 359 void* CFWL_Widget::GetThemeCapacity(CFWL_WidgetCapacity dwCapacity) {
367 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); 360 IFWL_ThemeProvider* pTheme = GetAvailableTheme();
368 if (!pTheme) 361 if (!pTheme)
369 return nullptr; 362 return nullptr;
370 363
371 CFWL_ThemePart part; 364 CFWL_ThemePart part;
372 part.m_pWidget = this; 365 part.m_pWidget = this;
373 return pTheme->GetCapacity(&part, dwCapacity); 366 return pTheme->GetCapacity(&part, dwCapacity);
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 const CFWL_App* pApp = GetOwnerApp(); 588 const CFWL_App* pApp = GetOwnerApp();
596 if (!pApp) 589 if (!pApp)
597 return; 590 return;
598 591
599 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver(); 592 CFWL_NoteDriver* pNoteDriver = pApp->GetNoteDriver();
600 if (!pNoteDriver) 593 if (!pNoteDriver)
601 return; 594 return;
602 pNoteDriver->SendEvent(pEvent); 595 pNoteDriver->SendEvent(pEvent);
603 } 596 }
604 597
605 void CFWL_Widget::Repaint(const CFX_RectF* pRect) { 598 void CFWL_Widget::Repaint() {
606 if (pRect) {
607 m_pWidgetMgr->RepaintWidget(this, pRect);
608 return;
609 }
610 CFX_RectF rect; 599 CFX_RectF rect;
611 rect = m_pProperties->m_rtWidget; 600 rect = m_pProperties->m_rtWidget;
612 rect.left = rect.top = 0; 601 rect.left = rect.top = 0;
Tom Sepez 2016/12/08 19:16:20 ditto
dsinclair 2016/12/08 19:20:47 Done.
613 m_pWidgetMgr->RepaintWidget(this, &rect); 602 RepaintRect(rect);
603 }
604
605 void CFWL_Widget::RepaintRect(const CFX_RectF& pRect) {
606 m_pWidgetMgr->RepaintWidget(this, pRect);
614 } 607 }
615 608
616 void CFWL_Widget::DrawBackground(CFX_Graphics* pGraphics, 609 void CFWL_Widget::DrawBackground(CFX_Graphics* pGraphics,
617 CFWL_Part iPartBk, 610 CFWL_Part iPartBk,
618 IFWL_ThemeProvider* pTheme, 611 IFWL_ThemeProvider* pTheme,
619 const CFX_Matrix* pMatrix) { 612 const CFX_Matrix* pMatrix) {
620 CFX_RectF rtRelative;
621 GetRelativeRect(rtRelative);
622 CFWL_ThemeBackground param; 613 CFWL_ThemeBackground param;
623 param.m_pWidget = this; 614 param.m_pWidget = this;
624 param.m_iPart = iPartBk; 615 param.m_iPart = iPartBk;
625 param.m_pGraphics = pGraphics; 616 param.m_pGraphics = pGraphics;
626 if (pMatrix) 617 if (pMatrix)
627 param.m_matrix.Concat(*pMatrix, true); 618 param.m_matrix.Concat(*pMatrix, true);
628 param.m_rtPart = rtRelative; 619 param.m_rtPart = GetRelativeRect();
629 pTheme->DrawBackground(&param); 620 pTheme->DrawBackground(&param);
630 } 621 }
631 622
632 void CFWL_Widget::DrawBorder(CFX_Graphics* pGraphics, 623 void CFWL_Widget::DrawBorder(CFX_Graphics* pGraphics,
633 CFWL_Part iPartBorder, 624 CFWL_Part iPartBorder,
634 IFWL_ThemeProvider* pTheme, 625 IFWL_ThemeProvider* pTheme,
635 const CFX_Matrix* pMatrix) { 626 const CFX_Matrix* pMatrix) {
636 CFX_RectF rtRelative;
637 GetRelativeRect(rtRelative);
638 CFWL_ThemeBackground param; 627 CFWL_ThemeBackground param;
639 param.m_pWidget = this; 628 param.m_pWidget = this;
640 param.m_iPart = iPartBorder; 629 param.m_iPart = iPartBorder;
641 param.m_pGraphics = pGraphics; 630 param.m_pGraphics = pGraphics;
642 if (pMatrix) 631 if (pMatrix)
643 param.m_matrix.Concat(*pMatrix, true); 632 param.m_matrix.Concat(*pMatrix, true);
644 param.m_rtPart = rtRelative; 633 param.m_rtPart = GetRelativeRect();
645 pTheme->DrawBackground(&param); 634 pTheme->DrawBackground(&param);
646 } 635 }
647 636
648 void CFWL_Widget::DrawEdge(CFX_Graphics* pGraphics, 637 void CFWL_Widget::DrawEdge(CFX_Graphics* pGraphics,
649 CFWL_Part iPartEdge, 638 CFWL_Part iPartEdge,
650 IFWL_ThemeProvider* pTheme, 639 IFWL_ThemeProvider* pTheme,
651 const CFX_Matrix* pMatrix) { 640 const CFX_Matrix* pMatrix) {
652 CFX_RectF rtEdge;
653 GetEdgeRect(rtEdge);
654 CFWL_ThemeBackground param; 641 CFWL_ThemeBackground param;
655 param.m_pWidget = this; 642 param.m_pWidget = this;
656 param.m_iPart = iPartEdge; 643 param.m_iPart = iPartEdge;
657 param.m_pGraphics = pGraphics; 644 param.m_pGraphics = pGraphics;
658 if (pMatrix) 645 if (pMatrix)
659 param.m_matrix.Concat(*pMatrix, true); 646 param.m_matrix.Concat(*pMatrix, true);
660 param.m_rtPart = rtEdge; 647 param.m_rtPart = GetEdgeRect();
661 pTheme->DrawBackground(&param); 648 pTheme->DrawBackground(&param);
662 } 649 }
663 650
664 void CFWL_Widget::NotifyDriver() { 651 void CFWL_Widget::NotifyDriver() {
665 const CFWL_App* pApp = GetOwnerApp(); 652 const CFWL_App* pApp = GetOwnerApp();
666 if (!pApp) 653 if (!pApp)
667 return; 654 return;
668 655
669 CFWL_NoteDriver* pDriver = 656 CFWL_NoteDriver* pDriver =
670 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); 657 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 } 707 }
721 default: 708 default:
722 break; 709 break;
723 } 710 }
724 } 711 }
725 712
726 void CFWL_Widget::OnProcessEvent(CFWL_Event* pEvent) {} 713 void CFWL_Widget::OnProcessEvent(CFWL_Event* pEvent) {}
727 714
728 void CFWL_Widget::OnDrawWidget(CFX_Graphics* pGraphics, 715 void CFWL_Widget::OnDrawWidget(CFX_Graphics* pGraphics,
729 const CFX_Matrix* pMatrix) {} 716 const CFX_Matrix* pMatrix) {}
OLDNEW
« no previous file with comments | « xfa/fwl/cfwl_widget.h ('k') | xfa/fwl/cfwl_widgetmgr.h » ('j') | xfa/fxfa/app/xfa_fwladapter.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698