Make CPWL_Wnd::GetParent() a protected method.
Add helper method to return ancestors for public use. This
consolidates some duplicated logic.
Change-Id: I3c9dab83577c4196a5a633e594b6dc14b346c279
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/99430
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp
index b8093c6..4a37278 100644
--- a/fpdfsdk/pwl/cpwl_wnd.cpp
+++ b/fpdfsdk/pwl/cpwl_wnd.cpp
@@ -68,13 +68,9 @@
}
void SetFocus(CPWL_Wnd* pWnd) {
- m_KeyboardPaths.clear();
+ m_KeyboardPaths = pWnd->GetAncestors();
m_pMainKeyboardWnd = pWnd;
- CPWL_Wnd* pParent = pWnd;
- while (pParent) {
- m_KeyboardPaths.emplace_back(pParent);
- pParent = pParent->GetParentWindow();
- }
+
// Note, pWnd may get destroyed in the OnSetFocus call.
pWnd->OnSetFocus();
}
@@ -93,13 +89,7 @@
m_KeyboardPaths.clear();
}
- void SetCapture(CPWL_Wnd* pWnd) {
- m_MousePaths.clear();
- while (pWnd) {
- m_MousePaths.emplace_back(pWnd);
- pWnd = pWnd->GetParentWindow();
- }
- }
+ void SetCapture(CPWL_Wnd* pWnd) { m_MousePaths = pWnd->GetAncestors(); }
void ReleaseCapture() { m_MousePaths.clear(); }
@@ -543,6 +533,14 @@
return m_pAttachedData ? m_pAttachedData->Clone() : nullptr;
}
+std::vector<UnownedPtr<CPWL_Wnd>> CPWL_Wnd::GetAncestors() {
+ std::vector<UnownedPtr<CPWL_Wnd>> results;
+ for (CPWL_Wnd* pWnd = this; pWnd; pWnd = pWnd->GetParentWindow()) {
+ results.emplace_back(pWnd);
+ }
+ return results;
+}
+
bool CPWL_Wnd::WndHitTest(const CFX_PointF& point) const {
return IsValid() && IsVisible() && GetWindowRect().Contains(point);
}
diff --git a/fpdfsdk/pwl/cpwl_wnd.h b/fpdfsdk/pwl/cpwl_wnd.h
index 3f4931a..f346e52 100644
--- a/fpdfsdk/pwl/cpwl_wnd.h
+++ b/fpdfsdk/pwl/cpwl_wnd.h
@@ -201,11 +201,11 @@
void RemoveFlag(uint32_t dwFlags);
void SetClipRect(const CFX_FloatRect& rect);
- CPWL_Wnd* GetParentWindow() const { return m_pParent.Get(); }
IPWL_FillerNotify::PerWindowData* GetAttachedData() const {
return m_pAttachedData.get();
}
std::unique_ptr<IPWL_FillerNotify::PerWindowData> CloneAttachedData() const;
+ std::vector<UnownedPtr<CPWL_Wnd>> GetAncestors();
bool WndHitTest(const CFX_PointF& point) const;
bool ClientHitTest(const CFX_PointF& point) const;
@@ -241,6 +241,7 @@
return m_CreationParams.pFillerNotify.Get();
}
+ CPWL_Wnd* GetParentWindow() const { return m_pParent.Get(); }
CPWL_ScrollBar* GetVScrollBar() const;
// Returns |true| iff this instance is still allocated.