1 // Copyright (c) 2014 The Chromium 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 #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_INTERNAL_POPUP_MENU_H_
6 #define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_INTERNAL_POPUP_MENU_H_
7 
8 #include "third_party/blink/renderer/core/core_export.h"
9 #include "third_party/blink/renderer/core/html/forms/popup_menu.h"
10 #include "third_party/blink/renderer/core/page/page_popup_client.h"
11 
12 namespace blink {
13 
14 class ChromeClient;
15 class CSSFontSelector;
16 class PagePopup;
17 class HTMLElement;
18 class HTMLHRElement;
19 class HTMLOptGroupElement;
20 class HTMLOptionElement;
21 class HTMLSelectElement;
22 
23 // InternalPopupMenu is a PopupMenu implementation for platforms other than
24 // macOS and Android. The UI is built with an HTML page inside a PagePopup.
25 class CORE_EXPORT InternalPopupMenu final : public PopupMenu,
26                                             public PagePopupClient {
27  public:
28   InternalPopupMenu(ChromeClient*, HTMLSelectElement&);
29   ~InternalPopupMenu() override;
30   void Trace(Visitor*) override;
31 
32   void Update();
33 
34   void Dispose();
35 
36  private:
37   FRIEND_TEST_ALL_PREFIXES(InternalPopupMenuTest, ShowSelectDisplayNone);
38 
39   class ItemIterationContext;
40   void AddOption(ItemIterationContext&, HTMLOptionElement&);
41   void AddOptGroup(ItemIterationContext&, HTMLOptGroupElement&);
42   void AddSeparator(ItemIterationContext&, HTMLHRElement&);
43   void AddElementStyle(ItemIterationContext&, HTMLElement&);
44 
45   // PopupMenu functions:
46   void Show() override;
47   void Hide() override;
48   void DisconnectClient() override;
49   void UpdateFromElement(UpdateReason) override;
50 
51   // PagePopupClient functions:
52   void WriteDocument(SharedBuffer*) override;
53   CSSFontSelector* CreateCSSFontSelector(Document& popup_document) override;
54   void SetValueAndClosePopup(int, const String&) override;
55   void SetValue(const String&) override;
56   void CancelPopup() override;
57   Element& OwnerElement() override;
58   ChromeClient& GetChromeClient() override;
ZoomFactor()59   float ZoomFactor() override { return 1.0; }
60   Locale& GetLocale() override;
61   void DidClosePopup() override;
62 
63   Member<ChromeClient> chrome_client_;
64   Member<HTMLSelectElement> owner_element_;
65   PagePopup* popup_;
66   bool needs_update_;
67 };
68 
69 }  // namespace blink
70 
71 #endif  // THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FORMS_INTERNAL_POPUP_MENU_H_
72