• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #include "xfa/fwl/cfwl_combobox.h"
8 
9 #include <algorithm>
10 #include <memory>
11 #include <utility>
12 
13 #include "third_party/base/ptr_util.h"
14 #include "xfa/fde/cfde_texteditengine.h"
15 #include "xfa/fde/cfde_textout.h"
16 #include "xfa/fwl/cfwl_app.h"
17 #include "xfa/fwl/cfwl_event.h"
18 #include "xfa/fwl/cfwl_eventselectchanged.h"
19 #include "xfa/fwl/cfwl_listbox.h"
20 #include "xfa/fwl/cfwl_messagekey.h"
21 #include "xfa/fwl/cfwl_messagekillfocus.h"
22 #include "xfa/fwl/cfwl_messagemouse.h"
23 #include "xfa/fwl/cfwl_messagesetfocus.h"
24 #include "xfa/fwl/cfwl_notedriver.h"
25 #include "xfa/fwl/cfwl_themebackground.h"
26 #include "xfa/fwl/cfwl_themepart.h"
27 #include "xfa/fwl/cfwl_themetext.h"
28 #include "xfa/fwl/cfwl_widgetmgr.h"
29 #include "xfa/fwl/fwl_widgetdef.h"
30 #include "xfa/fwl/ifwl_themeprovider.h"
31 
CFWL_ComboBox(const CFWL_App * app)32 CFWL_ComboBox::CFWL_ComboBox(const CFWL_App* app)
33     : CFWL_Widget(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr) {
34   InitComboList();
35   InitComboEdit();
36 }
37 
38 CFWL_ComboBox::~CFWL_ComboBox() = default;
39 
GetClassID() const40 FWL_Type CFWL_ComboBox::GetClassID() const {
41   return FWL_Type::ComboBox;
42 }
43 
AddString(const WideString & wsText)44 void CFWL_ComboBox::AddString(const WideString& wsText) {
45   m_pListBox->AddString(wsText);
46 }
47 
RemoveAt(int32_t iIndex)48 void CFWL_ComboBox::RemoveAt(int32_t iIndex) {
49   m_pListBox->RemoveAt(iIndex);
50 }
51 
RemoveAll()52 void CFWL_ComboBox::RemoveAll() {
53   m_pListBox->DeleteAll();
54 }
55 
ModifyStylesEx(uint32_t dwStylesExAdded,uint32_t dwStylesExRemoved)56 void CFWL_ComboBox::ModifyStylesEx(uint32_t dwStylesExAdded,
57                                    uint32_t dwStylesExRemoved) {
58   if (!m_pEdit)
59     InitComboEdit();
60 
61   bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown);
62   bool bDelDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown);
63 
64   dwStylesExRemoved &= ~FWL_STYLEEXT_CMB_DropDown;
65   m_pProperties->m_dwStyleExes |= FWL_STYLEEXT_CMB_DropDown;
66 
67   if (bAddDropDown)
68     m_pEdit->ModifyStylesEx(0, FWL_STYLEEXT_EDT_ReadOnly);
69   else if (bDelDropDown)
70     m_pEdit->ModifyStylesEx(FWL_STYLEEXT_EDT_ReadOnly, 0);
71   CFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved);
72 }
73 
Update()74 void CFWL_ComboBox::Update() {
75   if (m_iLock)
76     return;
77   if (m_pEdit)
78     ResetEditAlignment();
79   ResetTheme();
80   Layout();
81 }
82 
HitTest(const CFX_PointF & point)83 FWL_WidgetHit CFWL_ComboBox::HitTest(const CFX_PointF& point) {
84   CFX_RectF rect(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width,
85                  m_pProperties->m_rtWidget.height);
86   if (rect.Contains(point))
87     return FWL_WidgetHit::Edit;
88   if (m_rtBtn.Contains(point))
89     return FWL_WidgetHit::Client;
90   if (IsDropListVisible()) {
91     rect = m_pListBox->GetWidgetRect();
92     if (rect.Contains(point))
93       return FWL_WidgetHit::Client;
94   }
95   return FWL_WidgetHit::Unknown;
96 }
97 
DrawWidget(CXFA_Graphics * pGraphics,const CFX_Matrix & matrix)98 void CFWL_ComboBox::DrawWidget(CXFA_Graphics* pGraphics,
99                                const CFX_Matrix& matrix) {
100   IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get();
101   pGraphics->SaveGraphState();
102   pGraphics->ConcatMatrix(&matrix);
103   if (!m_rtBtn.IsEmpty(0.1f)) {
104     CFWL_ThemeBackground param;
105     param.m_pWidget = this;
106     param.m_iPart = CFWL_Part::DropDownButton;
107     param.m_dwStates = m_iBtnState;
108     param.m_pGraphics = pGraphics;
109     param.m_rtPart = m_rtBtn;
110     pTheme->DrawBackground(param);
111   }
112   pGraphics->RestoreGraphState();
113 
114   if (m_pEdit) {
115     CFX_RectF rtEdit = m_pEdit->GetWidgetRect();
116     CFX_Matrix mt(1, 0, 0, 1, rtEdit.left, rtEdit.top);
117     mt.Concat(matrix);
118     m_pEdit->DrawWidget(pGraphics, mt);
119   }
120   if (m_pListBox && IsDropListVisible()) {
121     CFX_RectF rtList = m_pListBox->GetWidgetRect();
122     CFX_Matrix mt(1, 0, 0, 1, rtList.left, rtList.top);
123     mt.Concat(matrix);
124     m_pListBox->DrawWidget(pGraphics, mt);
125   }
126 }
127 
SetThemeProvider(IFWL_ThemeProvider * pThemeProvider)128 void CFWL_ComboBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
129   if (!pThemeProvider)
130     return;
131 
132   m_pProperties->m_pThemeProvider = pThemeProvider;
133   if (m_pListBox)
134     m_pListBox->SetThemeProvider(pThemeProvider);
135   if (m_pEdit)
136     m_pEdit->SetThemeProvider(pThemeProvider);
137 }
138 
GetTextByIndex(int32_t iIndex) const139 WideString CFWL_ComboBox::GetTextByIndex(int32_t iIndex) const {
140   CFWL_ListItem* pItem = static_cast<CFWL_ListItem*>(
141       m_pListBox->GetItem(m_pListBox.get(), iIndex));
142   return pItem ? pItem->GetText() : WideString();
143 }
144 
SetCurSel(int32_t iSel)145 void CFWL_ComboBox::SetCurSel(int32_t iSel) {
146   int32_t iCount = m_pListBox->CountItems(nullptr);
147   bool bClearSel = iSel < 0 || iSel >= iCount;
148   if (IsDropDownStyle() && m_pEdit) {
149     if (bClearSel) {
150       m_pEdit->SetText(WideString());
151     } else {
152       CFWL_ListItem* hItem = m_pListBox->GetItem(this, iSel);
153       m_pEdit->SetText(hItem ? hItem->GetText() : WideString());
154     }
155     m_pEdit->Update();
156   }
157   m_iCurSel = bClearSel ? -1 : iSel;
158 }
159 
SetStates(uint32_t dwStates)160 void CFWL_ComboBox::SetStates(uint32_t dwStates) {
161   if (IsDropDownStyle() && m_pEdit)
162     m_pEdit->SetStates(dwStates);
163   if (m_pListBox)
164     m_pListBox->SetStates(dwStates);
165   CFWL_Widget::SetStates(dwStates);
166 }
167 
RemoveStates(uint32_t dwStates)168 void CFWL_ComboBox::RemoveStates(uint32_t dwStates) {
169   if (IsDropDownStyle() && m_pEdit)
170     m_pEdit->RemoveStates(dwStates);
171   if (m_pListBox)
172     m_pListBox->RemoveStates(dwStates);
173   CFWL_Widget::RemoveStates(dwStates);
174 }
175 
SetEditText(const WideString & wsText)176 void CFWL_ComboBox::SetEditText(const WideString& wsText) {
177   if (!m_pEdit)
178     return;
179 
180   m_pEdit->SetText(wsText);
181   m_pEdit->Update();
182 }
183 
GetEditText() const184 WideString CFWL_ComboBox::GetEditText() const {
185   if (m_pEdit)
186     return m_pEdit->GetText();
187   if (!m_pListBox)
188     return WideString();
189 
190   CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel);
191   return hItem ? hItem->GetText() : WideString();
192 }
193 
OpenDropDownList(bool bActivate)194 void CFWL_ComboBox::OpenDropDownList(bool bActivate) {
195   ShowDropList(bActivate);
196 }
197 
GetBBox() const198 CFX_RectF CFWL_ComboBox::GetBBox() const {
199   CFX_RectF rect = m_pProperties->m_rtWidget;
200   if (!m_pListBox || !IsDropListVisible())
201     return rect;
202 
203   CFX_RectF rtList = m_pListBox->GetWidgetRect();
204   rtList.Offset(rect.left, rect.top);
205   rect.Union(rtList);
206   return rect;
207 }
208 
EditModifyStylesEx(uint32_t dwStylesExAdded,uint32_t dwStylesExRemoved)209 void CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded,
210                                        uint32_t dwStylesExRemoved) {
211   if (m_pEdit)
212     m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved);
213 }
214 
ShowDropList(bool bActivate)215 void CFWL_ComboBox::ShowDropList(bool bActivate) {
216   if (IsDropListVisible() == bActivate)
217     return;
218 
219   if (bActivate) {
220     CFWL_Event preEvent(CFWL_Event::Type::PreDropDown, this);
221     DispatchEvent(&preEvent);
222     if (!preEvent.GetSrcTarget())
223       return;
224 
225     CFWL_ComboList* pComboList = m_pListBox.get();
226     int32_t iItems = pComboList->CountItems(nullptr);
227     if (iItems < 1)
228       return;
229 
230     ResetListItemAlignment();
231     pComboList->ChangeSelected(m_iCurSel);
232 
233     float fItemHeight = pComboList->CalcItemHeight();
234     float fBorder = GetCXBorderSize();
235     float fPopupMin = 0.0f;
236     if (iItems > 3)
237       fPopupMin = fItemHeight * 3 + fBorder * 2;
238 
239     float fPopupMax = fItemHeight * iItems + fBorder * 2;
240     CFX_RectF rtList(m_rtClient.left, 0, m_pProperties->m_rtWidget.width, 0);
241     GetPopupPos(fPopupMin, fPopupMax, m_pProperties->m_rtWidget, &rtList);
242 
243     m_pListBox->SetWidgetRect(rtList);
244     m_pListBox->Update();
245   }
246 
247   if (bActivate) {
248     m_pListBox->RemoveStates(FWL_WGTSTATE_Invisible);
249     CFWL_Event postEvent(CFWL_Event::Type::PostDropDown, this);
250     DispatchEvent(&postEvent);
251   } else {
252     m_pListBox->SetStates(FWL_WGTSTATE_Invisible);
253   }
254 
255   CFX_RectF rect = m_pListBox->GetWidgetRect();
256   rect.Inflate(2, 2);
257   RepaintRect(rect);
258 }
259 
MatchEditText()260 void CFWL_ComboBox::MatchEditText() {
261   WideString wsText = m_pEdit->GetText();
262   int32_t iMatch = m_pListBox->MatchItem(wsText.AsStringView());
263   if (iMatch != m_iCurSel) {
264     m_pListBox->ChangeSelected(iMatch);
265     if (iMatch >= 0)
266       SyncEditText(iMatch);
267   } else if (iMatch >= 0) {
268     m_pEdit->SetSelected();
269   }
270   m_iCurSel = iMatch;
271 }
272 
SyncEditText(int32_t iListItem)273 void CFWL_ComboBox::SyncEditText(int32_t iListItem) {
274   CFWL_ListItem* hItem = m_pListBox->GetItem(this, iListItem);
275   m_pEdit->SetText(hItem ? hItem->GetText() : WideString());
276   m_pEdit->Update();
277   m_pEdit->SetSelected();
278 }
279 
Layout()280 void CFWL_ComboBox::Layout() {
281   m_rtClient = GetClientRect();
282   m_rtContent = m_rtClient;
283   IFWL_ThemeProvider* theme = GetAvailableTheme();
284   if (!theme)
285     return;
286 
287   float borderWidth = 1;
288   float fBtn = theme->GetScrollBarWidth();
289   if (!(GetStylesEx() & FWL_STYLEEXT_CMB_ReadOnly)) {
290     m_rtBtn =
291         CFX_RectF(m_rtClient.right() - fBtn, m_rtClient.top + borderWidth,
292                   fBtn - borderWidth, m_rtClient.height - 2 * borderWidth);
293   }
294 
295   CFWL_ThemePart part;
296   part.m_pWidget = this;
297   CFX_RectF pUIMargin = theme->GetUIMargin(part);
298   m_rtContent.Deflate(pUIMargin.left, pUIMargin.top, pUIMargin.width,
299                       pUIMargin.height);
300 
301   if (!IsDropDownStyle() || !m_pEdit)
302     return;
303 
304   CFX_RectF rtEdit(m_rtContent.left, m_rtContent.top, m_rtContent.width - fBtn,
305                    m_rtContent.height);
306   m_pEdit->SetWidgetRect(rtEdit);
307 
308   if (m_iCurSel >= 0) {
309     CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel);
310     ScopedUpdateLock update_lock(m_pEdit.get());
311     m_pEdit->SetText(hItem ? hItem->GetText() : WideString());
312   }
313   m_pEdit->Update();
314 }
315 
ResetTheme()316 void CFWL_ComboBox::ResetTheme() {
317   if (!m_pProperties->m_pThemeProvider)
318     m_pProperties->m_pThemeProvider = GetAvailableTheme();
319 
320   IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider.Get();
321   if (m_pListBox && !m_pListBox->GetThemeProvider())
322     m_pListBox->SetThemeProvider(pTheme);
323   if (m_pEdit && !m_pEdit->GetThemeProvider())
324     m_pEdit->SetThemeProvider(pTheme);
325 }
326 
ResetEditAlignment()327 void CFWL_ComboBox::ResetEditAlignment() {
328   if (!m_pEdit)
329     return;
330 
331   uint32_t dwAdd = 0;
332   switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditHAlignMask) {
333     case FWL_STYLEEXT_CMB_EditHCenter: {
334       dwAdd |= FWL_STYLEEXT_EDT_HCenter;
335       break;
336     }
337     default: {
338       dwAdd |= FWL_STYLEEXT_EDT_HNear;
339       break;
340     }
341   }
342   switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditVAlignMask) {
343     case FWL_STYLEEXT_CMB_EditVCenter: {
344       dwAdd |= FWL_STYLEEXT_EDT_VCenter;
345       break;
346     }
347     case FWL_STYLEEXT_CMB_EditVFar: {
348       dwAdd |= FWL_STYLEEXT_EDT_VFar;
349       break;
350     }
351     default: {
352       dwAdd |= FWL_STYLEEXT_EDT_VNear;
353       break;
354     }
355   }
356   if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_EditJustified)
357     dwAdd |= FWL_STYLEEXT_EDT_Justified;
358 
359   m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask |
360                                      FWL_STYLEEXT_EDT_HAlignModeMask |
361                                      FWL_STYLEEXT_EDT_VAlignMask);
362 }
363 
ResetListItemAlignment()364 void CFWL_ComboBox::ResetListItemAlignment() {
365   if (!m_pListBox)
366     return;
367 
368   uint32_t dwAdd = 0;
369   switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemAlignMask) {
370     case FWL_STYLEEXT_CMB_ListItemCenterAlign: {
371       dwAdd |= FWL_STYLEEXT_LTB_CenterAlign;
372       break;
373     }
374     default: {
375       dwAdd |= FWL_STYLEEXT_LTB_LeftAlign;
376       break;
377     }
378   }
379   m_pListBox->ModifyStylesEx(dwAdd, FWL_STYLEEXT_CMB_ListItemAlignMask);
380 }
381 
ProcessSelChanged(bool bLButtonUp)382 void CFWL_ComboBox::ProcessSelChanged(bool bLButtonUp) {
383   m_iCurSel = m_pListBox->GetItemIndex(this, m_pListBox->GetSelItem(0));
384   if (!IsDropDownStyle()) {
385     RepaintRect(m_rtClient);
386     return;
387   }
388 
389   CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel);
390   if (!hItem)
391     return;
392   if (m_pEdit) {
393     m_pEdit->SetText(hItem->GetText());
394     m_pEdit->Update();
395     m_pEdit->SetSelected();
396   }
397 
398   CFWL_EventSelectChanged ev(this);
399   ev.bLButtonUp = bLButtonUp;
400   DispatchEvent(&ev);
401 }
402 
InitComboList()403 void CFWL_ComboBox::InitComboList() {
404   if (m_pListBox)
405     return;
406 
407   auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>();
408   prop->m_pParent = this;
409   prop->m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll;
410   prop->m_dwStates = FWL_WGTSTATE_Invisible;
411   prop->m_pThemeProvider = m_pProperties->m_pThemeProvider;
412   m_pListBox = pdfium::MakeUnique<CFWL_ComboList>(m_pOwnerApp.Get(),
413                                                   std::move(prop), this);
414 }
415 
InitComboEdit()416 void CFWL_ComboBox::InitComboEdit() {
417   if (m_pEdit)
418     return;
419 
420   auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>();
421   prop->m_pParent = this;
422   prop->m_pThemeProvider = m_pProperties->m_pThemeProvider;
423 
424   m_pEdit = pdfium::MakeUnique<CFWL_ComboEdit>(m_pOwnerApp.Get(),
425                                                std::move(prop), this);
426   m_pEdit->SetOuter(this);
427 }
428 
OnProcessMessage(CFWL_Message * pMessage)429 void CFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) {
430   if (!pMessage)
431     return;
432 
433   bool backDefault = true;
434   switch (pMessage->GetType()) {
435     case CFWL_Message::Type::SetFocus: {
436       backDefault = false;
437       OnFocusChanged(pMessage, true);
438       break;
439     }
440     case CFWL_Message::Type::KillFocus: {
441       backDefault = false;
442       OnFocusChanged(pMessage, false);
443       break;
444     }
445     case CFWL_Message::Type::Mouse: {
446       backDefault = false;
447       CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
448       switch (pMsg->m_dwCmd) {
449         case FWL_MouseCommand::LeftButtonDown:
450           OnLButtonDown(pMsg);
451           break;
452         case FWL_MouseCommand::LeftButtonUp:
453           OnLButtonUp(pMsg);
454           break;
455         default:
456           break;
457       }
458       break;
459     }
460     case CFWL_Message::Type::Key: {
461       backDefault = false;
462       CFWL_MessageKey* pKey = static_cast<CFWL_MessageKey*>(pMessage);
463       if (pKey->m_dwCmd == FWL_KeyCommand::KeyUp)
464         break;
465       if (IsDropListVisible() && pKey->m_dwCmd == FWL_KeyCommand::KeyDown) {
466         bool bListKey = pKey->m_dwKeyCode == XFA_FWL_VKEY_Up ||
467                         pKey->m_dwKeyCode == XFA_FWL_VKEY_Down ||
468                         pKey->m_dwKeyCode == XFA_FWL_VKEY_Return ||
469                         pKey->m_dwKeyCode == XFA_FWL_VKEY_Escape;
470         if (bListKey) {
471           m_pListBox->GetDelegate()->OnProcessMessage(pMessage);
472           break;
473         }
474       }
475       OnKey(pKey);
476       break;
477     }
478     default:
479       break;
480   }
481   // Dst target could be |this|, continue only if not destroyed by above.
482   if (backDefault && pMessage->GetDstTarget())
483     CFWL_Widget::OnProcessMessage(pMessage);
484 }
485 
OnProcessEvent(CFWL_Event * pEvent)486 void CFWL_ComboBox::OnProcessEvent(CFWL_Event* pEvent) {
487   CFWL_Event::Type type = pEvent->GetType();
488   if (type == CFWL_Event::Type::Scroll) {
489     CFWL_EventScroll* pScrollEvent = static_cast<CFWL_EventScroll*>(pEvent);
490     CFWL_EventScroll pScrollEv(this);
491     pScrollEv.m_iScrollCode = pScrollEvent->m_iScrollCode;
492     pScrollEv.m_fPos = pScrollEvent->m_fPos;
493     DispatchEvent(&pScrollEv);
494   } else if (type == CFWL_Event::Type::TextWillChange) {
495     CFWL_Event pTemp(CFWL_Event::Type::EditChanged, this);
496     DispatchEvent(&pTemp);
497   }
498 }
499 
OnDrawWidget(CXFA_Graphics * pGraphics,const CFX_Matrix & matrix)500 void CFWL_ComboBox::OnDrawWidget(CXFA_Graphics* pGraphics,
501                                  const CFX_Matrix& matrix) {
502   DrawWidget(pGraphics, matrix);
503 }
504 
OnLButtonUp(CFWL_MessageMouse * pMsg)505 void CFWL_ComboBox::OnLButtonUp(CFWL_MessageMouse* pMsg) {
506   if (m_rtBtn.Contains(pMsg->m_pos))
507     m_iBtnState = CFWL_PartState_Hovered;
508   else
509     m_iBtnState = CFWL_PartState_Normal;
510 
511   RepaintRect(m_rtBtn);
512 }
513 
OnLButtonDown(CFWL_MessageMouse * pMsg)514 void CFWL_ComboBox::OnLButtonDown(CFWL_MessageMouse* pMsg) {
515   bool bDropDown = IsDropListVisible();
516   CFX_RectF& rtBtn = bDropDown ? m_rtBtn : m_rtClient;
517   if (!rtBtn.Contains(pMsg->m_pos))
518     return;
519 
520   if (IsDropListVisible()) {
521     ShowDropList(false);
522     return;
523   }
524   if (m_pEdit)
525     MatchEditText();
526   ShowDropList(true);
527 }
528 
OnFocusChanged(CFWL_Message * pMsg,bool bSet)529 void CFWL_ComboBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) {
530   if (bSet) {
531     m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
532     if ((m_pEdit->GetStates() & FWL_WGTSTATE_Focused) == 0) {
533       CFWL_MessageSetFocus msg(nullptr, m_pEdit.get());
534       m_pEdit->GetDelegate()->OnProcessMessage(&msg);
535     }
536   } else {
537     m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
538     ShowDropList(false);
539     CFWL_MessageKillFocus msg(m_pEdit.get());
540     m_pEdit->GetDelegate()->OnProcessMessage(&msg);
541   }
542 }
543 
OnKey(CFWL_MessageKey * pMsg)544 void CFWL_ComboBox::OnKey(CFWL_MessageKey* pMsg) {
545   uint32_t dwKeyCode = pMsg->m_dwKeyCode;
546   const bool bUp = dwKeyCode == XFA_FWL_VKEY_Up;
547   const bool bDown = dwKeyCode == XFA_FWL_VKEY_Down;
548   if (bUp || bDown) {
549     CFWL_ComboList* pComboList = m_pListBox.get();
550     int32_t iCount = pComboList->CountItems(nullptr);
551     if (iCount < 1)
552       return;
553 
554     bool bMatchEqual = false;
555     int32_t iCurSel = m_iCurSel;
556     if (m_pEdit) {
557       WideString wsText = m_pEdit->GetText();
558       iCurSel = pComboList->MatchItem(wsText.AsStringView());
559       if (iCurSel >= 0) {
560         CFWL_ListItem* item = m_pListBox->GetSelItem(iCurSel);
561         bMatchEqual = wsText == (item ? item->GetText() : WideString());
562       }
563     }
564     if (iCurSel < 0) {
565       iCurSel = 0;
566     } else if (bMatchEqual) {
567       if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1))
568         return;
569       if (bUp)
570         iCurSel--;
571       else
572         iCurSel++;
573     }
574     m_iCurSel = iCurSel;
575     SyncEditText(m_iCurSel);
576     return;
577   }
578   if (m_pEdit)
579     m_pEdit->GetDelegate()->OnProcessMessage(pMsg);
580 }
581 
GetPopupPos(float fMinHeight,float fMaxHeight,const CFX_RectF & rtAnchor,CFX_RectF * pPopupRect)582 void CFWL_ComboBox::GetPopupPos(float fMinHeight,
583                                 float fMaxHeight,
584                                 const CFX_RectF& rtAnchor,
585                                 CFX_RectF* pPopupRect) {
586   m_pWidgetMgr->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor,
587                                    pPopupRect);
588 }
589