Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/forms/nsRangeFrame.h
Line
Count
Source (jump to first uncovered line)
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 nsRangeFrame_h___
8
#define nsRangeFrame_h___
9
10
#include "mozilla/Attributes.h"
11
#include "mozilla/Decimal.h"
12
#include "mozilla/EventForwards.h"
13
#include "nsContainerFrame.h"
14
#include "nsIAnonymousContentCreator.h"
15
#include "nsIDOMEventListener.h"
16
#include "nsCOMPtr.h"
17
18
class nsDisplayRangeFocusRing;
19
20
namespace mozilla {
21
namespace dom {
22
class Event;
23
} // namespace mozilla
24
} // namespace dom
25
26
class nsRangeFrame final : public nsContainerFrame,
27
                           public nsIAnonymousContentCreator
28
{
29
  friend nsIFrame*
30
  NS_NewRangeFrame(nsIPresShell* aPresShell, ComputedStyle* aStyle);
31
32
  friend class nsDisplayRangeFocusRing;
33
34
  explicit nsRangeFrame(ComputedStyle* aStyle);
35
  virtual ~nsRangeFrame();
36
37
  typedef mozilla::CSSPseudoElementType CSSPseudoElementType;
38
  typedef mozilla::dom::Element Element;
39
40
public:
41
  NS_DECL_QUERYFRAME
42
  NS_DECL_FRAMEARENA_HELPERS(nsRangeFrame)
43
44
  // nsIFrame overrides
45
  virtual void Init(nsIContent*       aContent,
46
                    nsContainerFrame* aParent,
47
                    nsIFrame*         aPrevInFlow) override;
48
49
  virtual void DestroyFrom(nsIFrame* aDestructRoot, PostDestroyData& aPostDestroyData) override;
50
51
  void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
52
                        const nsDisplayListSet& aLists) override;
53
54
  virtual void Reflow(nsPresContext*           aPresContext,
55
                      ReflowOutput&     aDesiredSize,
56
                      const ReflowInput& aReflowInput,
57
                      nsReflowStatus&          aStatus) override;
58
59
#ifdef DEBUG_FRAME_DUMP
60
  virtual nsresult GetFrameName(nsAString& aResult) const override {
61
    return MakeFrameName(NS_LITERAL_STRING("Range"), aResult);
62
  }
63
#endif
64
65
#ifdef ACCESSIBILITY
66
  virtual mozilla::a11y::AccType AccessibleType() override;
67
#endif
68
69
  // nsIAnonymousContentCreator
70
  virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
71
  virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
72
                                        uint32_t aFilter) override;
73
74
  virtual nsresult AttributeChanged(int32_t  aNameSpaceID,
75
                                    nsAtom* aAttribute,
76
                                    int32_t  aModType) override;
77
78
  virtual mozilla::LogicalSize
79
  ComputeAutoSize(gfxContext*                 aRenderingContext,
80
                  mozilla::WritingMode        aWM,
81
                  const mozilla::LogicalSize& aCBSize,
82
                  nscoord                     aAvailableISize,
83
                  const mozilla::LogicalSize& aMargin,
84
                  const mozilla::LogicalSize& aBorder,
85
                  const mozilla::LogicalSize& aPadding,
86
                  ComputeSizeFlags            aFlags) override;
87
88
  virtual nscoord GetMinISize(gfxContext *aRenderingContext) override;
89
  virtual nscoord GetPrefISize(gfxContext *aRenderingContext) override;
90
91
  virtual bool IsFrameOfType(uint32_t aFlags) const override
92
0
  {
93
0
    return nsContainerFrame::IsFrameOfType(aFlags &
94
0
      ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
95
0
  }
96
97
  ComputedStyle* GetAdditionalComputedStyle(int32_t aIndex) const override;
98
  void SetAdditionalComputedStyle(int32_t aIndex,
99
                                  ComputedStyle* aComputedStyle) override;
100
101
  /**
102
   * Returns true if the slider's thumb moves horizontally, or else false if it
103
   * moves vertically.
104
   */
105
  bool IsHorizontal() const;
106
107
  /**
108
   * Returns true if the slider is oriented along the inline axis.
109
   */
110
0
  bool IsInlineOriented() const {
111
0
    return IsHorizontal() != GetWritingMode().IsVertical();
112
0
  }
113
114
  /**
115
   * Returns true if the slider's thumb moves right-to-left for increasing
116
   * values; only relevant when IsHorizontal() is true.
117
   */
118
0
  bool IsRightToLeft() const {
119
0
    MOZ_ASSERT(IsHorizontal());
120
0
    mozilla::WritingMode wm = GetWritingMode();
121
0
    return wm.IsVertical() ? wm.IsVerticalRL() : !wm.IsBidiLTR();
122
0
  }
123
124
  double GetMin() const;
125
  double GetMax() const;
126
  double GetValue() const;
127
128
  /**
129
   * Returns the input element's value as a fraction of the difference between
130
   * the input's minimum and its maximum (i.e. returns 0.0 when the value is
131
   * the same as the minimum, and returns 1.0 when the value is the same as the
132
   * maximum).
133
   */
134
  double GetValueAsFractionOfRange();
135
136
  /**
137
   * Returns whether the frame and its child should use the native style.
138
   */
139
  bool ShouldUseNativeStyle() const;
140
141
  mozilla::Decimal GetValueAtEventPoint(mozilla::WidgetGUIEvent* aEvent);
142
143
  /**
144
   * Helper that's used when the value of the range changes to reposition the
145
   * thumb, resize the range-progress element, and schedule a repaint. (This
146
   * does not reflow, since the position and size of the thumb and
147
   * range-progress element do not affect the position or size of any other
148
   * frames.)
149
   */
150
  void UpdateForValueChange();
151
152
private:
153
154
  nsresult MakeAnonymousDiv(Element** aResult,
155
                            CSSPseudoElementType aPseudoType,
156
                            nsTArray<ContentInfo>& aElements);
157
158
  // Helper function which reflows the anonymous div frames.
159
  void ReflowAnonymousContent(nsPresContext*           aPresContext,
160
                              ReflowOutput&     aDesiredSize,
161
                              const ReflowInput& aReflowInput);
162
163
  void DoUpdateThumbPosition(nsIFrame* aThumbFrame,
164
                             const nsSize& aRangeSize);
165
166
  void DoUpdateRangeProgressFrame(nsIFrame* aProgressFrame,
167
                                  const nsSize& aRangeSize);
168
169
  /**
170
   * The div used to show the ::-moz-range-track pseudo-element.
171
   * @see nsRangeFrame::CreateAnonymousContent
172
   */
173
  nsCOMPtr<Element> mTrackDiv;
174
175
  /**
176
   * The div used to show the ::-moz-range-progress pseudo-element, which is
177
   * used to (optionally) style the specific chunk of track leading up to the
178
   * thumb's current position.
179
   * @see nsRangeFrame::CreateAnonymousContent
180
   */
181
  nsCOMPtr<Element> mProgressDiv;
182
183
  /**
184
   * The div used to show the ::-moz-range-thumb pseudo-element.
185
   * @see nsRangeFrame::CreateAnonymousContent
186
   */
187
  nsCOMPtr<Element> mThumbDiv;
188
189
  /**
190
   * Cached ComputedStyle for -moz-focus-outer CSS pseudo-element style.
191
   */
192
  RefPtr<ComputedStyle> mOuterFocusStyle;
193
194
  class DummyTouchListener final : public nsIDOMEventListener
195
  {
196
  private:
197
0
    ~DummyTouchListener() {}
198
199
  public:
200
    NS_DECL_ISUPPORTS
201
202
    NS_IMETHOD HandleEvent(mozilla::dom::Event* aEvent) override
203
0
    {
204
0
      return NS_OK;
205
0
    }
206
  };
207
208
  /**
209
   * A no-op touch-listener used for APZ purposes (see nsRangeFrame::Init).
210
   */
211
  RefPtr<DummyTouchListener> mDummyTouchListener;
212
};
213
214
#endif