1 // Copyright 2018 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_MODULES_MEDIA_CONTROLS_ELEMENTS_MEDIA_CONTROL_POPUP_MENU_ELEMENT_H_
6 #define THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIA_CONTROLS_ELEMENTS_MEDIA_CONTROL_POPUP_MENU_ELEMENT_H_
7 
8 #include "third_party/blink/renderer/modules/media_controls/elements/media_control_div_element.h"
9 
10 namespace blink {
11 
12 class MediaControlsImpl;
13 
14 class MediaControlPopupMenuElement : public MediaControlDivElement {
15  public:
16   ~MediaControlPopupMenuElement() override;
17 
18   void SetIsWanted(bool) override;
19 
20   // Callback run when an item is selected from the popup menu.
21   virtual void OnItemSelected();
22 
23   // Node override.
24   void DefaultEventHandler(Event&) override;
25   bool KeepEventInNode(const Event&) const override;
26   void RemovedFrom(ContainerNode&) override;
27 
28   void Trace(Visitor*) override;
29 
30   // When clicking the scroll bar, chrome will find its first focusable parent
31   // and focus on it. In order to prevent popup menu from losing focus (which
32   // will close the menu), we are setting the popup menu support focus and mouse
33   // focusable.
IsMouseFocusable()34   bool IsMouseFocusable() const override { return true; }
SupportsFocus()35   bool SupportsFocus() const override { return true; }
36 
37  protected:
38   MediaControlPopupMenuElement(MediaControlsImpl&);
39 
40   void SetPosition();
41 
42  private:
43   class EventListener;
44 
45   Element* PopupAnchor() const;
46 
47   void HideIfNotFocused();
48 
49   bool FocusListItemIfDisplayed(Node* node);
50   void SelectFirstItem();
51 
52   // Actions called by the EventListener object when specific evenst are
53   // received.
54   void SelectNextItem();
55   void SelectPreviousitem();
56   void CloseFromKeyboard();
57 
58   Member<EventListener> event_listener_;
59   Member<Element> last_focused_element_;
60 };
61 
62 }  // namespace blink
63 
64 #endif  // THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIA_CONTROLS_ELEMENTS_MEDIA_CONTROL_POPUP_MENU_ELEMENT_H_
65