Replace WTF::move with WTFMove
[WebKit-https.git] / Source / WebCore / html / BaseChooserOnlyDateAndTimeInputType.cpp
1 /*
2  * Copyright (C) 2012 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1.  Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  * 2.  Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #if ENABLE(DATE_AND_TIME_INPUT_TYPES)
28 #include "BaseChooserOnlyDateAndTimeInputType.h"
29
30 #include "Chrome.h"
31 #include "HTMLDivElement.h"
32 #include "HTMLInputElement.h"
33 #include "Page.h"
34 #include "RenderElement.h"
35 #include "ScriptController.h"
36 #include "ShadowRoot.h"
37
38 namespace WebCore {
39
40 BaseChooserOnlyDateAndTimeInputType::~BaseChooserOnlyDateAndTimeInputType()
41 {
42     closeDateTimeChooser();
43 }
44
45 void BaseChooserOnlyDateAndTimeInputType::handleDOMActivateEvent(Event*)
46 {
47     if (element().isDisabledOrReadOnly() || !element().renderer() || !ScriptController::processingUserGesture())
48         return;
49
50     if (m_dateTimeChooser)
51         return;
52     if (!element().document().page())
53         return;
54     DateTimeChooserParameters parameters;
55     if (!element().setupDateTimeChooserParameters(parameters))
56         return;
57 }
58
59 void BaseChooserOnlyDateAndTimeInputType::createShadowSubtree()
60 {
61     DEPRECATED_DEFINE_STATIC_LOCAL(AtomicString, valueContainerPseudo, ("-webkit-date-and-time-value", AtomicString::ConstructFromLiteral));
62
63     Ref<HTMLDivElement> valueContainer = HTMLDivElement::create(element().document());
64     valueContainer->setPseudo(valueContainerPseudo);
65     element().userAgentShadowRoot()->appendChild(WTFMove(valueContainer));
66     updateAppearance();
67 }
68
69 void BaseChooserOnlyDateAndTimeInputType::updateAppearance()
70 {
71     Node* node = element().userAgentShadowRoot()->firstChild();
72     if (!is<HTMLElement>(node))
73         return;
74     String displayValue = visibleValue();
75     if (displayValue.isEmpty()) {
76         // Need to put something to keep text baseline.
77         displayValue = ASCIILiteral(" ");
78     }
79     downcast<HTMLElement>(*node).setInnerText(displayValue, ASSERT_NO_EXCEPTION);
80 }
81
82 void BaseChooserOnlyDateAndTimeInputType::setValue(const String& value, bool valueChanged, TextFieldEventBehavior eventBehavior)
83 {
84     BaseDateAndTimeInputType::setValue(value, valueChanged, eventBehavior);
85     if (valueChanged)
86         updateAppearance();
87 }
88
89 void BaseChooserOnlyDateAndTimeInputType::detach()
90 {
91     closeDateTimeChooser();
92 }
93
94 void BaseChooserOnlyDateAndTimeInputType::didChooseValue(const String& value)
95 {
96     element().setValue(value, DispatchInputAndChangeEvent);
97 }
98
99 void BaseChooserOnlyDateAndTimeInputType::didEndChooser()
100 {
101     m_dateTimeChooser = nullptr;
102 }
103
104 void BaseChooserOnlyDateAndTimeInputType::closeDateTimeChooser()
105 {
106     if (m_dateTimeChooser)
107         m_dateTimeChooser->endChooser();
108 }
109
110 void BaseChooserOnlyDateAndTimeInputType::handleKeydownEvent(KeyboardEvent* event)
111 {
112     BaseClickableWithKeyInputType::handleKeydownEvent(element(), event);
113 }
114
115 void BaseChooserOnlyDateAndTimeInputType::handleKeypressEvent(KeyboardEvent* event)
116 {
117     BaseClickableWithKeyInputType::handleKeypressEvent(element(), event);
118 }
119
120 void BaseChooserOnlyDateAndTimeInputType::handleKeyupEvent(KeyboardEvent* event)
121 {
122     BaseClickableWithKeyInputType::handleKeyupEvent(*this, event);
123 }
124
125 void BaseChooserOnlyDateAndTimeInputType::accessKeyAction(bool sendMouseEvents)
126 {
127     BaseDateAndTimeInputType::accessKeyAction(sendMouseEvents);
128     BaseClickableWithKeyInputType::accessKeyAction(element(), sendMouseEvents);
129 }
130
131 bool BaseChooserOnlyDateAndTimeInputType::isMouseFocusable() const
132 {
133     return element().isTextFormControlFocusable();
134 }
135
136 }
137 #endif