1 /*
2  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3  *           (C) 1999 Antti Koivisto (koivisto@kde.org)
4  *           (C) 2001 Dirk Mueller (mueller@kde.org)
5  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All
6  * rights reserved.
7  *           (C) 2006 Alexey Proskuryakov (ap@nypop.com)
8  * Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
9  * Copyright (C) 2009, 2010, 2011, 2012 Google Inc. All rights reserved.
10  * Copyright (C) 2012 Samsung Electronics. All rights reserved.
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Library General Public
14  * License as published by the Free Software Foundation; either
15  * version 2 of the License, or (at your option) any later version.
16  *
17  * This library is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20  * Library General Public License for more details.
21  *
22  * You should have received a copy of the GNU Library General Public License
23  * along with this library; see the file COPYING.LIB.  If not, write to
24  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25  * Boston, MA 02110-1301, USA.
26  *
27  */
28 
29 #include "third_party/blink/renderer/core/html/forms/input_type_view.h"
30 
31 #include "third_party/blink/renderer/core/dom/focus_params.h"
32 #include "third_party/blink/renderer/core/dom/node_computed_style.h"
33 #include "third_party/blink/renderer/core/dom/shadow_root.h"
34 #include "third_party/blink/renderer/core/events/keyboard_event.h"
35 #include "third_party/blink/renderer/core/html/forms/form_controller.h"
36 #include "third_party/blink/renderer/core/html/forms/html_form_element.h"
37 #include "third_party/blink/renderer/core/html/forms/html_input_element.h"
38 #include "third_party/blink/renderer/core/layout/layout_object.h"
39 
40 namespace blink {
41 
WillBeDestroyed()42 void InputTypeView::WillBeDestroyed() {
43   will_be_destroyed_ = true;
44 }
45 
46 InputTypeView::~InputTypeView() = default;
47 
Trace(Visitor * visitor) const48 void InputTypeView::Trace(Visitor* visitor) const {
49   visitor->Trace(element_);
50 }
51 
SizeShouldIncludeDecoration(int,int & preferred_size) const52 bool InputTypeView::SizeShouldIncludeDecoration(int,
53                                                 int& preferred_size) const {
54   preferred_size = GetElement().size();
55   return false;
56 }
57 
HandleClickEvent(MouseEvent &)58 void InputTypeView::HandleClickEvent(MouseEvent&) {}
59 
HandleMouseDownEvent(MouseEvent &)60 void InputTypeView::HandleMouseDownEvent(MouseEvent&) {}
61 
HandleKeydownEvent(KeyboardEvent &)62 void InputTypeView::HandleKeydownEvent(KeyboardEvent&) {}
63 
HandleKeypressEvent(KeyboardEvent &)64 void InputTypeView::HandleKeypressEvent(KeyboardEvent&) {}
65 
HandleKeyupEvent(KeyboardEvent &)66 void InputTypeView::HandleKeyupEvent(KeyboardEvent&) {}
67 
HandleBeforeTextInsertedEvent(BeforeTextInsertedEvent &)68 void InputTypeView::HandleBeforeTextInsertedEvent(BeforeTextInsertedEvent&) {}
69 
HandleDOMActivateEvent(Event &)70 void InputTypeView::HandleDOMActivateEvent(Event&) {}
71 
ForwardEvent(Event &)72 void InputTypeView::ForwardEvent(Event&) {}
73 
DispatchSimulatedClickIfActive(KeyboardEvent & event) const74 void InputTypeView::DispatchSimulatedClickIfActive(KeyboardEvent& event) const {
75   if (GetElement().IsActive())
76     GetElement().DispatchSimulatedClick(&event);
77   event.SetDefaultHandled();
78 }
79 
AccessKeyAction(bool)80 void InputTypeView::AccessKeyAction(bool) {
81   GetElement().focus(FocusParams(SelectionBehaviorOnFocus::kReset,
82                                  mojom::blink::FocusType::kNone, nullptr));
83 }
84 
ShouldSubmitImplicitly(const Event & event)85 bool InputTypeView::ShouldSubmitImplicitly(const Event& event) {
86   auto* keyboard_event = DynamicTo<KeyboardEvent>(event);
87   return keyboard_event && event.type() == event_type_names::kKeypress &&
88          keyboard_event->charCode() == '\r';
89 }
90 
FormForSubmission() const91 HTMLFormElement* InputTypeView::FormForSubmission() const {
92   return GetElement().Form();
93 }
94 
TypeShouldForceLegacyLayout() const95 bool InputTypeView::TypeShouldForceLegacyLayout() const {
96   return false;
97 }
98 
CreateLayoutObject(const ComputedStyle & style,LegacyLayout legacy) const99 LayoutObject* InputTypeView::CreateLayoutObject(const ComputedStyle& style,
100                                                 LegacyLayout legacy) const {
101   return LayoutObject::CreateObject(&GetElement(), style, legacy);
102 }
103 
CustomStyleForLayoutObject(ComputedStyle &)104 void InputTypeView::CustomStyleForLayoutObject(ComputedStyle&) {}
105 
ComputedTextDirection()106 TextDirection InputTypeView::ComputedTextDirection() {
107   return GetElement().ComputedStyleRef().Direction();
108 }
109 
Blur()110 void InputTypeView::Blur() {
111   GetElement().DefaultBlur();
112 }
113 
HasCustomFocusLogic() const114 bool InputTypeView::HasCustomFocusLogic() const {
115   return true;
116 }
117 
HandleBlurEvent()118 void InputTypeView::HandleBlurEvent() {}
119 
HandleFocusInEvent(Element *,mojom::blink::FocusType)120 void InputTypeView::HandleFocusInEvent(Element*, mojom::blink::FocusType) {}
121 
StartResourceLoading()122 void InputTypeView::StartResourceLoading() {}
123 
ClosePopupView()124 void InputTypeView::ClosePopupView() {}
125 
HasOpenedPopup() const126 bool InputTypeView::HasOpenedPopup() const {
127   return false;
128 }
129 
NeedsShadowSubtree() const130 bool InputTypeView::NeedsShadowSubtree() const {
131   return true;
132 }
133 
CreateShadowSubtree()134 void InputTypeView::CreateShadowSubtree() {}
135 
DestroyShadowSubtree()136 void InputTypeView::DestroyShadowSubtree() {
137   if (ShadowRoot* root = GetElement().UserAgentShadowRoot())
138     root->RemoveChildren();
139 }
140 
UploadButton() const141 HTMLInputElement* InputTypeView::UploadButton() const {
142   return nullptr;
143 }
144 
FileStatusText() const145 String InputTypeView::FileStatusText() const {
146   return String();
147 }
148 
AltAttributeChanged()149 void InputTypeView::AltAttributeChanged() {}
150 
SrcAttributeChanged()151 void InputTypeView::SrcAttributeChanged() {}
152 
MinOrMaxAttributeChanged()153 void InputTypeView::MinOrMaxAttributeChanged() {}
154 
StepAttributeChanged()155 void InputTypeView::StepAttributeChanged() {}
156 
WillDispatchClick()157 ClickHandlingState* InputTypeView::WillDispatchClick() {
158   return nullptr;
159 }
160 
DidDispatchClick(Event &,const ClickHandlingState &)161 void InputTypeView::DidDispatchClick(Event&, const ClickHandlingState&) {}
162 
UpdateView()163 void InputTypeView::UpdateView() {}
164 
MultipleAttributeChanged()165 void InputTypeView::MultipleAttributeChanged() {}
166 
DisabledAttributeChanged()167 void InputTypeView::DisabledAttributeChanged() {}
168 
ReadonlyAttributeChanged()169 void InputTypeView::ReadonlyAttributeChanged() {}
170 
RequiredAttributeChanged()171 void InputTypeView::RequiredAttributeChanged() {}
172 
ValueAttributeChanged()173 void InputTypeView::ValueAttributeChanged() {}
174 
DidSetValue(const String &,bool)175 void InputTypeView::DidSetValue(const String&, bool) {}
176 
SubtreeHasChanged()177 void InputTypeView::SubtreeHasChanged() {
178   NOTREACHED();
179 }
180 
ListAttributeTargetChanged()181 void InputTypeView::ListAttributeTargetChanged() {}
182 
CapsLockStateMayHaveChanged()183 void InputTypeView::CapsLockStateMayHaveChanged() {}
184 
ShouldDrawCapsLockIndicator() const185 bool InputTypeView::ShouldDrawCapsLockIndicator() const {
186   return false;
187 }
188 
UpdateClearButtonVisibility()189 void InputTypeView::UpdateClearButtonVisibility() {}
190 
UpdatePlaceholderText()191 void InputTypeView::UpdatePlaceholderText() {}
192 
PopupRootAXObject()193 AXObject* InputTypeView::PopupRootAXObject() {
194   return nullptr;
195 }
196 
SaveFormControlState() const197 FormControlState InputTypeView::SaveFormControlState() const {
198   String current_value = GetElement().value();
199   if (current_value == GetElement().DefaultValue())
200     return FormControlState();
201   return FormControlState(current_value);
202 }
203 
RestoreFormControlState(const FormControlState & state)204 void InputTypeView::RestoreFormControlState(const FormControlState& state) {
205   GetElement().setValue(state[0]);
206 }
207 
IsDraggedSlider() const208 bool InputTypeView::IsDraggedSlider() const {
209   return false;
210 }
211 
HasBadInput() const212 bool InputTypeView::HasBadInput() const {
213   return false;
214 }
215 
Trace(Visitor * visitor) const216 void ClickHandlingState::Trace(Visitor* visitor) const {
217   visitor->Trace(checked_radio_button);
218   EventDispatchHandlingState::Trace(visitor);
219 }
220 
221 }  // namespace blink
222