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 16 matching lines...) Expand all Loading... | |
| 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/dom/shadow/ShadowRoot.h" |
| 35 #include "core/events/Event.h" | 35 #include "core/events/Event.h" |
| 36 #include "core/events/MouseEvent.h" | 36 #include "core/events/MouseEvent.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 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 return mediaSliderThumbShadowPartId(); | 294 return mediaSliderThumbShadowPartId(); |
| 293 default: | 295 default: |
| 294 return sliderThumbShadowPartId(); | 296 return sliderThumbShadowPartId(); |
| 295 } | 297 } |
| 296 } | 298 } |
| 297 | 299 |
| 298 // -------------------------------- | 300 // -------------------------------- |
| 299 | 301 |
| 300 inline SliderContainerElement::SliderContainerElement(Document& document) | 302 inline SliderContainerElement::SliderContainerElement(Document& document) |
| 301 : HTMLDivElement(document) | 303 : HTMLDivElement(document) |
| 304 , m_hasTouchEventHandler(false) | |
| 305 , m_touchStarted(false) | |
| 306 , m_slidingDirection(NoMove) | |
| 302 { | 307 { |
| 303 } | 308 } |
| 304 | 309 |
| 305 DEFINE_NODE_FACTORY(SliderContainerElement) | 310 DEFINE_NODE_FACTORY(SliderContainerElement) |
| 306 | 311 |
| 312 HTMLInputElement* SliderContainerElement::hostInput() const | |
| 313 { | |
| 314 return toHTMLInputElement(shadowHost()); | |
| 315 } | |
| 316 | |
| 307 LayoutObject* SliderContainerElement::createLayoutObject(const ComputedStyle&) | 317 LayoutObject* SliderContainerElement::createLayoutObject(const ComputedStyle&) |
| 308 { | 318 { |
| 309 return new LayoutSliderContainer(this); | 319 return new LayoutSliderContainer(this); |
| 310 } | 320 } |
| 311 | 321 |
| 322 void SliderContainerElement::defaultEventHandler(Event* event) | |
| 323 { | |
| 324 if (event->isTouchEvent()) { | |
| 325 handleTouchEvent(toTouchEvent(event)); | |
| 326 return; | |
| 327 } | |
| 328 } | |
| 329 | |
| 330 void SliderContainerElement::handleTouchEvent(TouchEvent* event) | |
| 331 { | |
| 332 HTMLInputElement* input = toHTMLInputElement(shadowHost()); | |
|
tkent
2016/08/22 06:00:48
HTMLInputElement* input = hostInput();
| |
| 333 if (input->isDisabledOrReadOnly()) | |
| 334 return; | |
| 335 | |
| 336 if (event->type() == EventTypeNames::touchend) { | |
| 337 input->dispatchFormControlChangeEvent(); | |
| 338 event->setDefaultHandled(); | |
| 339 m_slidingDirection = NoMove; | |
| 340 m_touchStarted = false; | |
| 341 return; | |
| 342 } | |
| 343 | |
| 344 if (!canSlide()) { | |
| 345 return; | |
| 346 } | |
| 347 | |
| 348 TouchList* touches = event->targetTouches(); | |
| 349 SliderThumbElement* thumb = toSliderThumbElement(input->userAgentShadowRoot( )->getElementById(ShadowElementNames::sliderThumb())); | |
|
tkent
2016/08/22 06:00:48
toSliderThumbElement(treeScope()->getElementById(S
| |
| 350 if (touches->length() == 1) { | |
| 351 if (event->type() == EventTypeNames::touchstart) { | |
| 352 m_startPoint = touches->item(0)->absoluteLocation(); | |
| 353 m_slidingDirection = NoMove; | |
| 354 m_touchStarted = true; | |
| 355 thumb->setPositionFromPoint(touches->item(0)->absoluteLocation()); | |
| 356 } else if (m_touchStarted) { | |
| 357 LayoutPoint currentPoint = touches->item(0)->absoluteLocation(); | |
| 358 if (m_slidingDirection == NoMove) { | |
| 359 m_slidingDirection = getDirection(currentPoint, m_startPoint); | |
| 360 } | |
| 361 if (m_slidingDirection != NoMove && canSlide()) { | |
|
tkent
2016/08/22 06:00:48
m_slidingDirection==NoMove was already check. So
| |
| 362 thumb->setPositionFromPoint(touches->item(0)->absoluteLocation() ); | |
| 363 event->setDefaultHandled(); | |
| 364 } | |
| 365 } | |
| 366 } | |
| 367 } | |
| 368 | |
| 369 SliderContainerElement::Direction SliderContainerElement::getDirection(LayoutPoi nt& point1, LayoutPoint& point2) | |
| 370 { | |
| 371 if (point1 == point2) { | |
| 372 return NoMove; | |
| 373 } | |
| 374 if ((point1.x() - point2.x()).abs() >= (point1.y() - point2.y()).abs()) { | |
| 375 return Horizontal; | |
| 376 } | |
| 377 return Vertical; | |
| 378 } | |
| 379 | |
| 380 bool SliderContainerElement::canSlide() | |
| 381 { | |
| 382 DCHECK(hostInput()->layoutObject()); | |
| 383 const ComputedStyle& sliderStyle = hostInput()->layoutObject()->styleRef(); | |
| 384 const TransformOperations& transforms = sliderStyle.transform(); | |
| 385 int transformSize = transforms.size(); | |
| 386 if (transformSize > 0) { | |
| 387 for (int i = 0; i < transformSize; ++i) { | |
| 388 if (transforms.at(i)->type() == TransformOperation::Rotate) { | |
| 389 return true; | |
| 390 } | |
| 391 } | |
| 392 } | |
| 393 if ((m_slidingDirection == Vertical && sliderStyle.appearance() == SliderHor izontalPart) || (m_slidingDirection == Horizontal && sliderStyle.appearance() == SliderVerticalPart)) { | |
| 394 return false; | |
| 395 } | |
| 396 return true; | |
| 397 } | |
| 398 | |
| 312 const AtomicString& SliderContainerElement::shadowPseudoId() const | 399 const AtomicString& SliderContainerElement::shadowPseudoId() const |
| 313 { | 400 { |
| 314 DEFINE_STATIC_LOCAL(const AtomicString, mediaSliderContainer, ("-webkit-medi a-slider-container")); | 401 DEFINE_STATIC_LOCAL(const AtomicString, mediaSliderContainer, ("-webkit-medi a-slider-container")); |
| 315 DEFINE_STATIC_LOCAL(const AtomicString, sliderContainer, ("-webkit-slider-co ntainer")); | 402 DEFINE_STATIC_LOCAL(const AtomicString, sliderContainer, ("-webkit-slider-co ntainer")); |
| 316 | 403 |
| 317 if (!shadowHost() || !shadowHost()->layoutObject()) | 404 if (!shadowHost() || !shadowHost()->layoutObject()) |
| 318 return sliderContainer; | 405 return sliderContainer; |
| 319 | 406 |
| 320 const ComputedStyle& sliderStyle = shadowHost()->layoutObject()->styleRef(); | 407 const ComputedStyle& sliderStyle = shadowHost()->layoutObject()->styleRef(); |
| 321 switch (sliderStyle.appearance()) { | 408 switch (sliderStyle.appearance()) { |
| 322 case MediaSliderPart: | 409 case MediaSliderPart: |
| 323 case MediaSliderThumbPart: | 410 case MediaSliderThumbPart: |
| 324 case MediaVolumeSliderPart: | 411 case MediaVolumeSliderPart: |
| 325 case MediaVolumeSliderThumbPart: | 412 case MediaVolumeSliderThumbPart: |
| 326 case MediaFullScreenVolumeSliderPart: | 413 case MediaFullScreenVolumeSliderPart: |
| 327 case MediaFullScreenVolumeSliderThumbPart: | 414 case MediaFullScreenVolumeSliderThumbPart: |
| 328 return mediaSliderContainer; | 415 return mediaSliderContainer; |
| 329 default: | 416 default: |
| 330 return sliderContainer; | 417 return sliderContainer; |
| 331 } | 418 } |
| 332 } | 419 } |
| 333 | 420 |
| 421 void SliderContainerElement::updateTouchEventHandlerRegistry() | |
| 422 { | |
| 423 if (m_hasTouchEventHandler) { | |
| 424 return; | |
| 425 } | |
| 426 if (document().frameHost() && document().lifecycle().state() < DocumentLifec ycle::Stopping) { | |
| 427 EventHandlerRegistry& registry = document().frameHost()->eventHandlerReg istry(); | |
| 428 registry.didAddEventHandler(*this, EventHandlerRegistry::TouchStartOrMov eEventPassive); | |
| 429 m_hasTouchEventHandler = true; | |
| 430 } | |
| 431 } | |
| 432 | |
| 433 void SliderContainerElement::didMoveToNewDocument(Document& oldDocument) | |
| 434 { | |
| 435 updateTouchEventHandlerRegistry(); | |
| 436 HTMLElement::didMoveToNewDocument(oldDocument); | |
| 437 } | |
| 438 | |
| 439 void SliderContainerElement::parseAttribute(const QualifiedName& name, const Ato micString& oldValue, const AtomicString& value) | |
| 440 { | |
| 441 HTMLElement::parseAttribute(name, oldValue, value); | |
| 442 updateTouchEventHandlerRegistry(); | |
|
tkent
2016/08/22 06:00:48
I think we can move this to RangeInputType::create
| |
| 443 } | |
| 444 | |
| 445 void SliderContainerElement::removeAllEventListeners() | |
| 446 { | |
| 447 Node::removeAllEventListeners(); | |
| 448 m_hasTouchEventHandler = false; | |
| 449 } | |
| 450 | |
| 334 } // namespace blink | 451 } // namespace blink |
| OLD | NEW |