Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : /**
7 : * This frame type is used for input type=date, time, month, week, and
8 : * datetime-local.
9 : *
10 : * NOTE: some of the above-mentioned input types are still to-be-implemented.
11 : * See nsCSSFrameConstructor::FindInputData, as well as bug 1286182 (date),
12 : * bug 1306215 (month), bug 1306216 (week) and bug 1306217 (datetime-local).
13 : */
14 :
15 : #ifndef nsDateTimeControlFrame_h__
16 : #define nsDateTimeControlFrame_h__
17 :
18 : #include "mozilla/Attributes.h"
19 : #include "nsContainerFrame.h"
20 : #include "nsIAnonymousContentCreator.h"
21 : #include "nsCOMPtr.h"
22 :
23 : namespace mozilla {
24 : namespace dom {
25 : struct DateTimeValue;
26 : } // namespace dom
27 : } // namespace mozilla
28 :
29 0 : class nsDateTimeControlFrame final : public nsContainerFrame,
30 : public nsIAnonymousContentCreator
31 : {
32 : typedef mozilla::dom::DateTimeValue DateTimeValue;
33 :
34 : explicit nsDateTimeControlFrame(nsStyleContext* aContext);
35 :
36 : public:
37 : friend nsIFrame* NS_NewDateTimeControlFrame(nsIPresShell* aPresShell,
38 : nsStyleContext* aContext);
39 :
40 : void ContentStatesChanged(mozilla::EventStates aStates) override;
41 : void DestroyFrom(nsIFrame* aDestructRoot) override;
42 :
43 : NS_DECL_QUERYFRAME
44 0 : NS_DECL_FRAMEARENA_HELPERS(nsDateTimeControlFrame)
45 :
46 : #ifdef DEBUG_FRAME_DUMP
47 0 : nsresult GetFrameName(nsAString& aResult) const override {
48 0 : return MakeFrameName(NS_LITERAL_STRING("DateTimeControl"), aResult);
49 : }
50 : #endif
51 :
52 0 : bool IsFrameOfType(uint32_t aFlags) const override
53 : {
54 0 : return nsContainerFrame::IsFrameOfType(aFlags &
55 0 : ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
56 : }
57 :
58 : // Reflow
59 : nscoord GetMinISize(gfxContext* aRenderingContext) override;
60 :
61 : nscoord GetPrefISize(gfxContext* aRenderingContext) override;
62 :
63 : void Reflow(nsPresContext* aPresContext,
64 : ReflowOutput& aDesiredSize,
65 : const ReflowInput& aReflowState,
66 : nsReflowStatus& aStatus) override;
67 :
68 : // nsIAnonymousContentCreator
69 : nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
70 : void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
71 : uint32_t aFilter) override;
72 :
73 : nsresult AttributeChanged(int32_t aNameSpaceID, nsIAtom* aAttribute,
74 : int32_t aModType) override;
75 :
76 : void OnValueChanged();
77 : void OnMinMaxStepAttrChanged();
78 : void SetValueFromPicker(const DateTimeValue& aValue);
79 : void HandleFocusEvent();
80 : void HandleBlurEvent();
81 : void SetPickerState(bool aOpen);
82 : bool HasBadInput();
83 :
84 : private:
85 : class SyncDisabledStateEvent;
86 : friend class SyncDisabledStateEvent;
87 0 : class SyncDisabledStateEvent : public mozilla::Runnable
88 : {
89 : public:
90 0 : explicit SyncDisabledStateEvent(nsDateTimeControlFrame* aFrame)
91 0 : : mozilla::Runnable("nsDateTimeControlFrame::SyncDisabledStateEvent")
92 0 : , mFrame(aFrame)
93 0 : {}
94 :
95 0 : NS_IMETHOD Run() override
96 : {
97 : nsDateTimeControlFrame* frame =
98 0 : static_cast<nsDateTimeControlFrame*>(mFrame.GetFrame());
99 0 : NS_ENSURE_STATE(frame);
100 :
101 0 : frame->SyncDisabledState();
102 0 : return NS_OK;
103 : }
104 :
105 : private:
106 : WeakFrame mFrame;
107 : };
108 :
109 : /**
110 : * Sync the disabled state of the anonymous children up with our content's.
111 : */
112 : void SyncDisabledState();
113 :
114 : // Anonymous child which is bound via XBL to an element that wraps the input
115 : // area and reset button.
116 : nsCOMPtr<nsIContent> mInputAreaContent;
117 : };
118 :
119 : #endif // nsDateTimeControlFrame_h__
|