1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef nsSearchControlFrame_h__
8 #define nsSearchControlFrame_h__
9 
10 #include "mozilla/Attributes.h"
11 #include "nsTextControlFrame.h"
12 #include "nsIAnonymousContentCreator.h"
13 #include "mozilla/RefPtr.h"
14 
15 class nsITextControlFrame;
16 class nsPresContext;
17 
18 namespace mozilla {
19 enum class PseudoStyleType : uint8_t;
20 class PresShell;
21 namespace dom {
22 class Element;
23 }  // namespace dom
24 }  // namespace mozilla
25 
26 /**
27  * This frame type is used for <input type=search>.
28  */
29 class nsSearchControlFrame final : public nsTextControlFrame {
30   friend nsIFrame* NS_NewSearchControlFrame(mozilla::PresShell* aPresShell,
31                                             ComputedStyle* aStyle);
32 
33   using PseudoStyleType = mozilla::PseudoStyleType;
34   using Element = mozilla::dom::Element;
35 
36   explicit nsSearchControlFrame(ComputedStyle* aStyle,
37                                 nsPresContext* aPresContext);
38 
39  public:
40   NS_DECL_QUERYFRAME
41   NS_DECL_FRAMEARENA_HELPERS(nsSearchControlFrame)
42 
43   void DestroyFrom(nsIFrame* aDestructRoot,
44                    PostDestroyData& aPostDestroyData) override;
45 
46   // nsIAnonymousContentCreator
47   nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
48   void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
49                                 uint32_t aFilter) override;
50 
51 #ifdef DEBUG_FRAME_DUMP
GetFrameName(nsAString & aResult)52   nsresult GetFrameName(nsAString& aResult) const override {
53     return MakeFrameName(u"SearchControl"_ns, aResult);
54   }
55 #endif
56 
GetAnonClearButton()57   Element* GetAnonClearButton() const { return mClearButton; }
58 
59   /**
60    * Update visbility of the clear button depending on the value
61    */
62   void UpdateClearButtonState();
63 
64  private:
65   // See nsSearchControlFrame::CreateAnonymousContent of a description of these
66   RefPtr<Element> mClearButton;
67 };
68 
69 #endif  // nsSearchControlFrame_h__
70