7#include "fpdfsdk/pwl/cpwl_wnd.h"
13#include "build/build_config.h"
14#include "core/fxcrt/stl_util.h"
15#include "core/fxge/cfx_renderdevice.h"
16#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
17#include "public/fpdf_fwlevent.h"
18#include "third_party/base/check.h"
19#include "third_party/base/check_op.h"
20#include "third_party/base/containers/contains.h"
24constexpr float kDefaultFontSize = 9.0f;
61 return pWnd && pdfium::Contains(m_MousePaths, pWnd);
65 return pWnd == m_pMainKeyboardWnd;
69 return pWnd && pdfium::Contains(m_KeyboardPaths, pWnd);
76 m_KeyboardPaths = pWnd->GetAncestors();
77 m_pMainKeyboardWnd = pWnd;
84 ObservedPtr<SharedCaptureFocusState> observed_ptr(
this);
85 if (!m_KeyboardPaths.empty()) {
86 CPWL_Wnd* pWnd = m_KeyboardPaths.front();
93 m_pMainKeyboardWnd =
nullptr;
94 m_KeyboardPaths.clear();
98 if (pWnd == m_pOwnerWnd) {
99 m_pOwnerWnd =
nullptr;
101 if (pWnd == m_pMainKeyboardWnd) {
102 m_pMainKeyboardWnd =
nullptr;
104 auto mouse_it = std::find(m_MousePaths.begin(), m_MousePaths.end(), pWnd);
105 if (mouse_it != m_MousePaths.end()) {
106 m_MousePaths.erase(mouse_it);
109 std::find(m_KeyboardPaths.begin(), m_KeyboardPaths.end(), pWnd);
110 if (keyboard_it != m_KeyboardPaths.end()) {
111 m_KeyboardPaths.erase(keyboard_it);
118 std::vector<UnownedPtr<CPWL_Wnd>> m_MousePaths;
119 std::vector<UnownedPtr<CPWL_Wnd>> m_KeyboardPaths;
144#if BUILDFLAG(IS_APPLE)
145 return IsMETAKeyDown(nFlag);
153 std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData)
163 m_CreationParams.rcRectWnd.Normalize();
164 m_rcWindow = m_CreationParams.rcRectWnd;
165 m_rcClip
= m_rcWindow;
170 CreateSharedCaptureFocusState();
174 CreateVScrollBar(ccp);
190 if (m_CreationParams.pProvider.Get() == provider)
191 m_CreationParams.pProvider.Reset();
198 m_pVScrollBar =
nullptr;
199 while (!m_Children.empty()) {
200 std::unique_ptr<CPWL_Wnd> pChild = std::move(m_Children.back());
201 m_Children.pop_back();
205 m_pParent->RemoveChild(
this);
208 DestroySharedCaptureFocusState();
230 m_CreationParams.rcRectWnd = m_rcWindow;
246 DrawChildAppearance(pDevice, mtUser2Device);
273 for (
const auto& pChild : m_Children) {
274 pChild->DrawAppearance(pDevice, mtUser2Device);
282 ObservedPtr<
CPWL_Wnd> this_observed(
this);
293 GetFillerNotify()->InvalidateRect(m_pAttachedData.get(), rcWin);
294 return !!this_observed;
302 for (
const auto& pChild : m_Children) {
303 if (IsWndCaptureKeyboard(pChild.get()))
304 return pChild->OnKeyDown(nKeyCode, nFlag);
314 for (
const auto& pChild : m_Children) {
315 if (IsWndCaptureKeyboard(pChild.get()))
316 return pChild->OnChar(nChar, nFlag);
321#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name)
322 bool CPWL_Wnd::mouse_method_name(Mask<FWL_EVENTFLAG> nFlag,
323 const CFX_PointF& point) {
324 if (!IsValid() || !IsVisible())
326 if (IsWndCaptureMouse(this)) {
327 for (const auto& pChild : m_Children) {
328 if (IsWndCaptureMouse(pChild.get())) {
329 return pChild->mouse_method_name(nFlag, point);
335 for (const auto& pChild : m_Children) {
336 if (pChild->WndHitTest(point)) {
337 return pChild->mouse_method_name(nFlag, point);
340 if (WndHitTest(point))
349#undef PWL_IMPLEMENT_MOUSE_METHOD
353 const CFX_PointF& point) {
394 const CFX_PointF& point,
395 const CFX_Vector& delta) {
403 for (
const auto& pChild : m_Children) {
404 if (IsWndCaptureKeyboard(pChild.get()))
405 return pChild->OnMouseWheel(nFlag, point, delta);
411 DCHECK(!pWnd->m_pParent);
412 pWnd->m_pParent =
this;
413 m_Children.push_back(std::move(pWnd));
417 DCHECK_EQ(pWnd->m_pParent,
this);
419 std::find(m_Children.begin(), m_Children.end(), MakeFakeUniquePtr(pWnd));
420 if (it == m_Children.end())
425 m_Children.erase(it);
458 return CFX_PointF((rcClient
.left + rcClient
.right) * 0.5f,
463 return (m_CreationParams.dwFlags & dwFlags) != 0;
467 m_CreationParams.dwFlags &= ~dwFlags;
471 return m_CreationParams.sBackgroundColor;
475 return m_CreationParams.sTextColor;
479 return m_CreationParams.nBorderStyle;
483 return HasFlag(
PWS_BORDER) ? m_CreationParams.dwBorderWidth : 0;
491 return HasFlag(
PWS_BORDER) ? m_CreationParams.sBorderColor : CFX_Color();
495 return m_CreationParams.sDash;
499 return HasFlag(
PWS_VSCROLL) ? m_pVScrollBar :
nullptr;
512 auto pBar = std::make_unique<CPWL_ScrollBar>(scp, CloneAttachedData());
513 m_pVScrollBar = pBar.get();
514 AddChild(std::move(pBar));
515 m_pVScrollBar->Realize();
519 if (SharedCaptureFocusState* pSharedState = GetSharedCaptureFocusState()) {
525 for (
const auto& pChild : m_Children)
526 pChild->ReleaseCapture();
528 if (SharedCaptureFocusState* pSharedState = GetSharedCaptureFocusState()) {
534 if (SharedCaptureFocusState* pSharedState = GetSharedCaptureFocusState()) {
543 if (SharedCaptureFocusState* pSharedState = GetSharedCaptureFocusState()) {
556 return m_pAttachedData ? m_pAttachedData->Clone() :
nullptr;
560 std::vector<UnownedPtr<CPWL_Wnd>> results;
562 results.emplace_back(pWnd);
579 ObservedPtr<
CPWL_Wnd> this_observed(
this);
580 for (
const auto& pChild : m_Children) {
581 if (!pChild->SetVisible(bVisible)) {
584 if (!this_observed) {
589 if (bVisible != m_bVisible) {
590 m_bVisible = bVisible;
629 ObservedPtr<
CPWL_Wnd> this_observed(
this);
630 pVSB
->Move(rcVScroll,
true,
false);
631 if (!this_observed) {
645void CPWL_Wnd::CreateSharedCaptureFocusState() {
646 if (!m_CreationParams.pSharedCaptureFocusState) {
647 m_CreationParams.pSharedCaptureFocusState =
648 new SharedCaptureFocusState(
this);
652void CPWL_Wnd::DestroySharedCaptureFocusState() {
653 SharedCaptureFocusState* pSharedCaptureFocusState =
654 GetSharedCaptureFocusState();
655 if (!pSharedCaptureFocusState) {
661 delete pSharedCaptureFocusState;
667 return m_CreationParams.pSharedCaptureFocusState;
675 SharedCaptureFocusState* pCtrl = GetSharedCaptureFocusState();
680 SharedCaptureFocusState* pCtrl = GetSharedCaptureFocusState();
685 SharedCaptureFocusState* pCtrl = GetSharedCaptureFocusState();
699 return m_CreationParams.fFontSize;
703 m_CreationParams.fFontSize = fFontSize;
707 switch (nBorderStyle) {
718 switch (nBorderStyle) {
729 return m_CreationParams.nTransparency;
733 for (
const auto& pChild : m_Children)
734 pChild->SetTransparency(nTransparency);
736 m_CreationParams.nTransparency = nTransparency;
bool Contains(const CFX_PointF &point) const
constexpr CFX_FloatRect(float l, float b, float r, float t)
constexpr CFX_FloatRect()=default
void Intersect(const CFX_FloatRect &other_rect)
void Inflate(float x, float y)
CFX_FloatRect & operator=(const CFX_FloatRect &that)=default
void Deflate(float x, float y)
bool Contains(const CFX_FloatRect &other_rect) const
CFX_FloatRect GetDeflated(float x, float y) const
void Union(const CFX_FloatRect &other_rect)
CFX_FloatRect TransformRect(const CFX_FloatRect &rect) const
void Concat(const CFX_Matrix &right)
void DrawBorder(const CFX_Matrix *pUser2Device, const CFX_FloatRect &rect, float fWidth, const CFX_Color &color, const CFX_Color &crLeftTop, const CFX_Color &crRightBottom, BorderStyle nStyle, int32_t nTransparency)
void DrawFillRect(const CFX_Matrix *pUser2Device, const CFX_FloatRect &rect, const CFX_Color &color, int32_t nTransparency)
CreateParams(const CreateParams &other)
IPWL_FillerNotify::CursorStyle eCursorType
CreateParams(CFX_Timer::HandlerIface *timer_handler, IPWL_FillerNotify *filler_notify, ProviderIface *provider)
CFX_Color sBackgroundColor
virtual CFX_Matrix GetWindowMatrix(const IPWL_FillerNotify::PerWindowData *pAttached)=0
bool IsOwnedByWnd(const CPWL_Wnd *pWnd) const
void RemoveWnd(CPWL_Wnd *pWnd)
SharedCaptureFocusState(const CPWL_Wnd *pOwnerWnd)
void SetCapture(CPWL_Wnd *pWnd)
bool IsMainCaptureKeyboard(const CPWL_Wnd *pWnd) const
bool IsWndCaptureKeyboard(const CPWL_Wnd *pWnd) const
bool IsWndCaptureMouse(const CPWL_Wnd *pWnd) const
~SharedCaptureFocusState()=default
void SetFocus(CPWL_Wnd *pWnd)
CFX_Matrix GetWindowMatrix() const
static bool IsPlatformShortcutKey(Mask< FWL_EVENTFLAG > nFlag)
static bool IsCTRLKeyDown(Mask< FWL_EVENTFLAG > nFlag)
virtual bool OnMouseWheel(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point, const CFX_Vector &delta)
virtual bool SelectAllText()
virtual void ScrollWindowVertically(float pos)
virtual bool OnRButtonDown(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
bool InvalidateRectMove(const CFX_FloatRect &rcOld, const CFX_FloatRect &rcNew)
bool ClientHitTest(const CFX_PointF &point) const
static bool IsALTKeyDown(Mask< FWL_EVENTFLAG > nFlag)
CFX_Color GetBorderColor() const
const CFX_FloatRect & GetClipRect() const
BorderStyle GetBorderStyle() const
virtual void NotifyMouseMove(CPWL_Wnd *child, const CFX_PointF &pos)
virtual bool OnChar(uint16_t nChar, Mask< FWL_EVENTFLAG > nFlag)
bool WndHitTest(const CFX_PointF &point) const
virtual void ReplaceAndKeepSelection(const WideString &text)
CFX_PointF GetCenterPoint() const
void RemoveFlag(uint32_t dwFlags)
CFX_Color GetBackgroundColor() const
std::vector< UnownedPtr< CPWL_Wnd > > GetAncestors()
IPWL_FillerNotify * GetFillerNotify() const
bool HasFlag(uint32_t dwFlags) const
virtual CFX_FloatRect GetClientRect() const
virtual WideString GetSelectedText()
CFX_FloatRect GetWindowRect() const
bool IsCaptureMouse() const
CPWL_Wnd * GetParentWindow() const
virtual void NotifyLButtonDown(CPWL_Wnd *child, const CFX_PointF &pos)
void SetTransparency(int32_t nTransparency)
CPWL_Wnd(const CreateParams &cp, std::unique_ptr< IPWL_FillerNotify::PerWindowData > pAttachedData)
virtual bool RepositionChildWnd()
void InvalidateProvider(ProviderIface *provider)
static bool IsSHIFTKeyDown(Mask< FWL_EVENTFLAG > nFlag)
virtual bool OnRButtonUp(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
virtual bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlag)
int32_t GetBorderWidth() const
CreateParams * GetCreationParams()
virtual float GetFontSize() const
CFX_Color GetBorderRightBottomColor(BorderStyle nBorderStyle) const
virtual void SetScrollInfo(const PWL_SCROLL_INFO &info)
virtual bool InvalidateRect(const CFX_FloatRect *pRect)
virtual void CreateChildWnd(const CreateParams &cp)
virtual CFX_FloatRect GetFocusRect() const
virtual bool SetVisible(bool bVisible)
virtual void ReplaceSelection(const WideString &text)
IPWL_FillerNotify::PerWindowData * GetAttachedData() const
const CPWL_Dash & GetBorderDash() const
virtual void OnSetFocus()
virtual void SetFontSize(float fFontSize)
int32_t GetInnerBorderWidth() const
int32_t GetTransparency()
bool IsWndCaptureMouse(const CPWL_Wnd *pWnd) const
virtual void SetScrollPosition(float pos)
virtual void DrawThisAppearance(CFX_RenderDevice *pDevice, const CFX_Matrix &mtUser2Device)
ProviderIface * GetProvider() const
bool Move(const CFX_FloatRect &rcNew, bool bReset, bool bRefresh)
void SetClipRect(const CFX_FloatRect &rect)
bool IsWndCaptureKeyboard(const CPWL_Wnd *pWnd) const
CFX_Color GetBorderLeftTopColor(BorderStyle nBorderStyle) const
static const CFX_Color kDefaultWhiteColor
virtual void OnKillFocus()
std::unique_ptr< IPWL_FillerNotify::PerWindowData > CloneAttachedData() const
CFX_Color GetTextColor() const
virtual void NotifyLButtonUp(CPWL_Wnd *child, const CFX_PointF &pos)
CPWL_ScrollBar * GetVScrollBar() const
static const CFX_Color kDefaultBlackColor
static bool IsMETAKeyDown(Mask< FWL_EVENTFLAG > nFlag)
void AddChild(std::unique_ptr< CPWL_Wnd > pWnd)
void DrawAppearance(CFX_RenderDevice *pDevice, const CFX_Matrix &mtUser2Device)
void RemoveChild(CPWL_Wnd *pWnd)
virtual WideString GetText()
virtual void SetCursor(CursorStyle nCursorStyle)=0
#define PWL_IMPLEMENT_MOUSE_METHOD(mouse_method_name)
#define PWS_AUTOTRANSPARENT
#define PWS_NOREFRESHCLIP
@ FWL_EVENTFLAG_ControlKey
CFX_Color operator/(float fColorDivide) const
CFX_Color & operator=(const CFX_Color &that)=default
constexpr CFX_Color(Type type=CFX_Color::Type::kTransparent, float color1=0.0f, float color2=0.0f, float color3=0.0f, float color4=0.0f)
CPWL_Dash(int32_t dash, int32_t gap, int32_t phase)