Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: Source/core/html/shadow/SpinButtonElement.cpp

Issue 196933006: Do not dispatch 'change' events during pressing spin buttons for input[type=number]. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Replaced detach functionality when input loses focus Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 53 }
54 54
55 PassRefPtr<SpinButtonElement> SpinButtonElement::create(Document& document, Spin ButtonOwner& spinButtonOwner) 55 PassRefPtr<SpinButtonElement> SpinButtonElement::create(Document& document, Spin ButtonOwner& spinButtonOwner)
56 { 56 {
57 RefPtr<SpinButtonElement> element = adoptRef(new SpinButtonElement(document, spinButtonOwner)); 57 RefPtr<SpinButtonElement> element = adoptRef(new SpinButtonElement(document, spinButtonOwner));
58 element->setShadowPseudoId(AtomicString("-webkit-inner-spin-button", AtomicS tring::ConstructFromLiteral)); 58 element->setShadowPseudoId(AtomicString("-webkit-inner-spin-button", AtomicS tring::ConstructFromLiteral));
59 element->setAttribute(idAttr, ShadowElementNames::spinButton()); 59 element->setAttribute(idAttr, ShadowElementNames::spinButton());
60 return element.release(); 60 return element.release();
61 } 61 }
62 62
63 void SpinButtonElement::detach(const AttachContext& context) 63 void SpinButtonElement::setFocus(bool status)
64 { 64 {
65 releaseCapture(); 65 if (!status)
66 HTMLDivElement::detach(context); 66 releaseCapture();
tkent 2014/04/04 01:31:46 I think this code won't work. SpinButtonElement ne
Habib Virji 2014/04/04 09:24:05 Done.
67 ContainerNode::setFocus(status);
67 } 68 }
68 69
69 void SpinButtonElement::defaultEventHandler(Event* event) 70 void SpinButtonElement::defaultEventHandler(Event* event)
70 { 71 {
71 if (!event->isMouseEvent()) { 72 if (!event->isMouseEvent()) {
72 if (!event->defaultHandled()) 73 if (!event->defaultHandled())
73 HTMLDivElement::defaultEventHandler(event); 74 HTMLDivElement::defaultEventHandler(event);
74 return; 75 return;
75 } 76 }
76 77
(...skipping 22 matching lines...) Expand all
99 m_spinButtonOwner->focusAndSelectSpinButtonOwner(); 100 m_spinButtonOwner->focusAndSelectSpinButtonOwner();
100 if (renderer()) { 101 if (renderer()) {
101 if (m_upDownState != Indeterminate) { 102 if (m_upDownState != Indeterminate) {
102 // A JavaScript event handler called in doStepAction() below 103 // A JavaScript event handler called in doStepAction() below
103 // might change the element state and we might need to 104 // might change the element state and we might need to
104 // cancel the repeating timer by the state change. If we 105 // cancel the repeating timer by the state change. If we
105 // started the timer after doStepAction(), we would have no 106 // started the timer after doStepAction(), we would have no
106 // chance to cancel the timer. 107 // chance to cancel the timer.
107 startRepeatingTimer(); 108 startRepeatingTimer();
108 doStepAction(m_upDownState == Up ? 1 : -1); 109 doStepAction(m_upDownState == Up ? 1 : -1);
110 if (m_spinButtonOwner)
111 m_spinButtonOwner->spinButtonDidReleaseMouseCapture();
109 } 112 }
110 } 113 }
111 event->setDefaultHandled(); 114 event->setDefaultHandled();
112 } 115 }
113 } else if (mouseEvent->type() == EventTypeNames::mouseup && mouseEvent->butt on() == LeftButton) { 116 } else if (mouseEvent->type() == EventTypeNames::mouseup && mouseEvent->butt on() == LeftButton) {
114 stopRepeatingTimer(); 117 releaseCapture();
115 } else if (event->type() == EventTypeNames::mousemove) { 118 } else if (event->type() == EventTypeNames::mousemove) {
116 if (box->pixelSnappedBorderBoxRect().contains(local)) { 119 if (box->pixelSnappedBorderBoxRect().contains(local)) {
117 if (!m_capturing) { 120 if (!m_capturing) {
118 if (LocalFrame* frame = document().frame()) { 121 if (LocalFrame* frame = document().frame()) {
119 frame->eventHandler().setCapturingMouseEventsNode(this); 122 frame->eventHandler().setCapturingMouseEventsNode(this);
120 m_capturing = true; 123 m_capturing = true;
121 if (Page* page = document().page()) 124 if (Page* page = document().page())
122 page->chrome().registerPopupOpeningObserver(this); 125 page->chrome().registerPopupOpeningObserver(this);
123 } 126 }
124 } 127 }
125 UpDownState oldUpDownState = m_upDownState; 128 UpDownState oldUpDownState = m_upDownState;
126 m_upDownState = (local.y() < box->height() / 2) ? Up : Down; 129 m_upDownState = (local.y() < box->height() / 2) ? Up : Down;
127 if (m_upDownState != oldUpDownState) 130 if (m_upDownState != oldUpDownState)
128 renderer()->repaint(); 131 renderer()->repaint();
129 } else { 132 } else {
130 releaseCapture(); 133 releaseCapture();
131 m_upDownState = Indeterminate; 134 m_upDownState = Indeterminate;
132 } 135 }
136 } else if (event->type() == EventTypeNames::mouseout) {
tkent 2014/04/04 01:31:46 Why is this block necessary? Doesn't the above rel
Habib Virji 2014/04/04 09:24:05 Done.
137 if (m_capturing) { // In order to check that spin button is under focus
138 if (m_spinButtonOwner)
139 m_spinButtonOwner->spinButtonDidReleaseMouseCapture();
140 }
133 } 141 }
134 142
135 if (!event->defaultHandled()) 143 if (!event->defaultHandled())
136 HTMLDivElement::defaultEventHandler(event); 144 HTMLDivElement::defaultEventHandler(event);
137 } 145 }
138 146
139 void SpinButtonElement::willOpenPopup() 147 void SpinButtonElement::willOpenPopup()
140 { 148 {
141 releaseCapture(); 149 releaseCapture();
142 m_upDownState = Indeterminate; 150 m_upDownState = Indeterminate;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 { 199 {
192 stopRepeatingTimer(); 200 stopRepeatingTimer();
193 if (m_capturing) { 201 if (m_capturing) {
194 if (LocalFrame* frame = document().frame()) { 202 if (LocalFrame* frame = document().frame()) {
195 frame->eventHandler().setCapturingMouseEventsNode(nullptr); 203 frame->eventHandler().setCapturingMouseEventsNode(nullptr);
196 m_capturing = false; 204 m_capturing = false;
197 if (Page* page = document().page()) 205 if (Page* page = document().page())
198 page->chrome().unregisterPopupOpeningObserver(this); 206 page->chrome().unregisterPopupOpeningObserver(this);
199 } 207 }
200 } 208 }
209 if (m_spinButtonOwner)
210 m_spinButtonOwner->spinButtonDidReleaseMouseCapture();
211
201 } 212 }
202 213
203 bool SpinButtonElement::matchesReadOnlyPseudoClass() const 214 bool SpinButtonElement::matchesReadOnlyPseudoClass() const
204 { 215 {
205 return shadowHost()->matchesReadOnlyPseudoClass(); 216 return shadowHost()->matchesReadOnlyPseudoClass();
206 } 217 }
207 218
208 bool SpinButtonElement::matchesReadWritePseudoClass() const 219 bool SpinButtonElement::matchesReadWritePseudoClass() const
209 { 220 {
210 return shadowHost()->matchesReadWritePseudoClass(); 221 return shadowHost()->matchesReadWritePseudoClass();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 m_upDownState = Indeterminate; 259 m_upDownState = Indeterminate;
249 HTMLDivElement::setHovered(flag); 260 HTMLDivElement::setHovered(flag);
250 } 261 }
251 262
252 bool SpinButtonElement::shouldRespondToMouseEvents() 263 bool SpinButtonElement::shouldRespondToMouseEvents()
253 { 264 {
254 return !m_spinButtonOwner || m_spinButtonOwner->shouldSpinButtonRespondToMou seEvents(); 265 return !m_spinButtonOwner || m_spinButtonOwner->shouldSpinButtonRespondToMou seEvents();
255 } 266 }
256 267
257 } 268 }
OLDNEW
« Source/core/html/forms/TextFieldInputType.cpp ('K') | « Source/core/html/shadow/SpinButtonElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698