Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009 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 are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #include "core/html/shadow/SliderThumbElement.h" | 32 #include "core/html/shadow/SliderThumbElement.h" |
| 33 | 33 |
| 34 #include "core/dom/shadow/ShadowRoot.h" | |
| 34 #include "core/events/Event.h" | 35 #include "core/events/Event.h" |
| 35 #include "core/events/MouseEvent.h" | 36 #include "core/events/MouseEvent.h" |
| 36 #include "core/dom/shadow/ShadowRoot.h" | 37 #include "core/events/TouchEvent.h" |
| 38 #include "core/frame/EventHandlerRegistry.h" | |
| 37 #include "core/frame/LocalFrame.h" | 39 #include "core/frame/LocalFrame.h" |
| 38 #include "core/html/HTMLInputElement.h" | 40 #include "core/html/HTMLInputElement.h" |
| 39 #include "core/html/forms/StepRange.h" | 41 #include "core/html/forms/StepRange.h" |
| 40 #include "core/html/parser/HTMLParserIdioms.h" | 42 #include "core/html/parser/HTMLParserIdioms.h" |
| 41 #include "core/html/shadow/ShadowElementNames.h" | 43 #include "core/html/shadow/ShadowElementNames.h" |
| 42 #include "core/input/EventHandler.h" | 44 #include "core/input/EventHandler.h" |
| 43 #include "core/layout/LayoutSliderContainer.h" | 45 #include "core/layout/LayoutSliderContainer.h" |
| 44 #include "core/layout/LayoutSliderThumb.h" | 46 #include "core/layout/LayoutSliderThumb.h" |
| 45 #include "core/layout/LayoutTheme.h" | 47 #include "core/layout/LayoutTheme.h" |
| 46 | 48 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 return mediaSliderThumbShadowPartId(); | 292 return mediaSliderThumbShadowPartId(); |
| 291 default: | 293 default: |
| 292 return sliderThumbShadowPartId(); | 294 return sliderThumbShadowPartId(); |
| 293 } | 295 } |
| 294 } | 296 } |
| 295 | 297 |
| 296 // -------------------------------- | 298 // -------------------------------- |
| 297 | 299 |
| 298 inline SliderContainerElement::SliderContainerElement(Document& document) | 300 inline SliderContainerElement::SliderContainerElement(Document& document) |
| 299 : HTMLDivElement(document) | 301 : HTMLDivElement(document) |
| 302 , m_hasTouchEventHandler(false) | |
| 300 { | 303 { |
| 301 } | 304 } |
| 302 | 305 |
| 303 DEFINE_NODE_FACTORY(SliderContainerElement) | 306 DEFINE_NODE_FACTORY(SliderContainerElement) |
| 304 | 307 |
| 305 LayoutObject* SliderContainerElement::createLayoutObject(const ComputedStyle&) | 308 LayoutObject* SliderContainerElement::createLayoutObject(const ComputedStyle&) |
| 306 { | 309 { |
| 307 return new LayoutSliderContainer(this); | 310 return new LayoutSliderContainer(this); |
| 308 } | 311 } |
| 309 | 312 |
| 313 void SliderContainerElement::defaultEventHandler(Event* event) | |
| 314 { | |
| 315 if (event->isTouchEvent()) { | |
| 316 handleTouchEvent(toTouchEvent(event)); | |
| 317 return; | |
| 318 } | |
| 319 } | |
| 320 | |
| 321 void SliderContainerElement::handleTouchEvent(TouchEvent* event) | |
| 322 { | |
| 323 HTMLInputElement* input = toHTMLInputElement(shadowHost()); | |
| 324 if (input->isDisabledOrReadOnly()) | |
| 325 return; | |
| 326 | |
| 327 if (event->type() == EventTypeNames::touchend) { | |
| 328 input->dispatchFormControlChangeEvent(); | |
| 329 event->setDefaultHandled(); | |
| 330 return; | |
| 331 } | |
| 332 | |
| 333 TouchList* touches = event->targetTouches(); | |
| 334 SliderThumbElement* thumb = toSliderThumbElement(input->userAgentShadowRoot( )->getElementById(ShadowElementNames::sliderThumb())); | |
| 335 if (touches->length() == 1) { | |
| 336 thumb->setPositionFromPoint(touches->item(0)->absoluteLocation()); | |
| 337 } | |
| 338 } | |
| 339 | |
| 310 const AtomicString& SliderContainerElement::shadowPseudoId() const | 340 const AtomicString& SliderContainerElement::shadowPseudoId() const |
| 311 { | 341 { |
| 312 DEFINE_STATIC_LOCAL(const AtomicString, mediaSliderContainer, ("-webkit-medi a-slider-container")); | 342 DEFINE_STATIC_LOCAL(const AtomicString, mediaSliderContainer, ("-webkit-medi a-slider-container")); |
| 313 DEFINE_STATIC_LOCAL(const AtomicString, sliderContainer, ("-webkit-slider-co ntainer")); | 343 DEFINE_STATIC_LOCAL(const AtomicString, sliderContainer, ("-webkit-slider-co ntainer")); |
| 314 | 344 |
| 315 if (!shadowHost() || !shadowHost()->layoutObject()) | 345 if (!shadowHost() || !shadowHost()->layoutObject()) |
| 316 return sliderContainer; | 346 return sliderContainer; |
| 317 | 347 |
| 318 const ComputedStyle& sliderStyle = shadowHost()->layoutObject()->styleRef(); | 348 const ComputedStyle& sliderStyle = shadowHost()->layoutObject()->styleRef(); |
| 319 switch (sliderStyle.appearance()) { | 349 switch (sliderStyle.appearance()) { |
| 320 case MediaSliderPart: | 350 case MediaSliderPart: |
| 321 case MediaSliderThumbPart: | 351 case MediaSliderThumbPart: |
| 322 case MediaVolumeSliderPart: | 352 case MediaVolumeSliderPart: |
| 323 case MediaVolumeSliderThumbPart: | 353 case MediaVolumeSliderThumbPart: |
| 324 case MediaFullScreenVolumeSliderPart: | 354 case MediaFullScreenVolumeSliderPart: |
| 325 case MediaFullScreenVolumeSliderThumbPart: | 355 case MediaFullScreenVolumeSliderThumbPart: |
| 326 return mediaSliderContainer; | 356 return mediaSliderContainer; |
| 327 default: | 357 default: |
| 328 return sliderContainer; | 358 return sliderContainer; |
| 329 } | 359 } |
| 330 } | 360 } |
| 331 | 361 |
| 362 void SliderContainerElement::updateTouchEventHandlerRegistry() | |
| 363 { | |
| 364 if (m_hasTouchEventHandler) { | |
| 365 return; | |
| 366 } | |
| 367 if (document().frameHost() && document().lifecycle().state() < DocumentLifec ycle::Stopping) { | |
| 368 EventHandlerRegistry& registry = document().frameHost()->eventHandlerReg istry(); | |
| 369 registry.didAddEventHandler(*this, EventHandlerRegistry::TouchStartOrMov eEventPassive); | |
| 370 m_hasTouchEventHandler = true; | |
| 371 } | |
| 372 } | |
| 373 | |
| 374 void SliderContainerElement::didMoveToNewDocument(Document& oldDocument) | |
| 375 { | |
| 376 updateTouchEventHandlerRegistry(); | |
| 377 HTMLElement::didMoveToNewDocument(oldDocument); | |
| 378 } | |
| 379 | |
| 380 void SliderContainerElement::parserDidSetAttributes() | |
|
tkent
2016/08/17 01:32:00
Why is it necessary though parseAttribute() calls
| |
| 381 { | |
| 382 updateTouchEventHandlerRegistry(); | |
| 383 } | |
| 384 | |
| 385 void SliderContainerElement::parseAttribute(const QualifiedName& name, const Ato micString& oldValue, const AtomicString& value) | |
| 386 { | |
| 387 HTMLElement::parseAttribute(name, oldValue, value); | |
| 388 updateTouchEventHandlerRegistry(); | |
|
tkent
2016/08/17 01:32:00
Why do we need to call updateTouchEventHandlerRegi
| |
| 389 } | |
| 390 | |
| 391 void SliderContainerElement::removeAllEventListeners() | |
| 392 { | |
| 393 Node::removeAllEventListeners(); | |
| 394 m_hasTouchEventHandler = false; | |
| 395 } | |
| 396 | |
| 332 } // namespace blink | 397 } // namespace blink |
| OLD | NEW |