| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2008, The Android Open Source Project | 2 * Copyright 2008, The Android Open Source Project |
| 3 * Copyright (C) 2012 Research In Motion Limited. All rights reserved. | 3 * Copyright (C) 2012 Research In Motion Limited. 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 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above copyright | 10 * * Redistributions in binary form must reproduce the above copyright |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 TouchTargetAndDispatchResultTypeMax)); | 192 TouchTargetAndDispatchResultTypeMax)); |
| 193 rootDocumentListenerHistogram.count( | 193 rootDocumentListenerHistogram.count( |
| 194 static_cast<TouchTargetAndDispatchResultType>(result)); | 194 static_cast<TouchTargetAndDispatchResultType>(result)); |
| 195 } | 195 } |
| 196 | 196 |
| 197 } // namespace | 197 } // namespace |
| 198 | 198 |
| 199 TouchEvent::TouchEvent() | 199 TouchEvent::TouchEvent() |
| 200 : m_causesScrollingIfUncanceled(false), | 200 : m_causesScrollingIfUncanceled(false), |
| 201 m_firstTouchMoveOrStart(false), | 201 m_firstTouchMoveOrStart(false), |
| 202 m_defaultPreventedBeforeCurrentTarget(false) {} | 202 m_defaultPreventedBeforeCurrentTarget(false), |
| 203 m_currentTouchAction(TouchActionAuto) {} |
| 203 | 204 |
| 204 TouchEvent::TouchEvent(TouchList* touches, | 205 TouchEvent::TouchEvent(TouchList* touches, |
| 205 TouchList* targetTouches, | 206 TouchList* targetTouches, |
| 206 TouchList* changedTouches, | 207 TouchList* changedTouches, |
| 207 const AtomicString& type, | 208 const AtomicString& type, |
| 208 AbstractView* view, | 209 AbstractView* view, |
| 209 PlatformEvent::Modifiers modifiers, | 210 PlatformEvent::Modifiers modifiers, |
| 210 bool cancelable, | 211 bool cancelable, |
| 211 bool causesScrollingIfUncanceled, | 212 bool causesScrollingIfUncanceled, |
| 212 bool firstTouchMoveOrStart, | 213 bool firstTouchMoveOrStart, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 233 m_currentTouchAction(currentTouchAction) {} | 234 m_currentTouchAction(currentTouchAction) {} |
| 234 | 235 |
| 235 TouchEvent::TouchEvent(const AtomicString& type, | 236 TouchEvent::TouchEvent(const AtomicString& type, |
| 236 const TouchEventInit& initializer) | 237 const TouchEventInit& initializer) |
| 237 : UIEventWithKeyState(type, initializer), | 238 : UIEventWithKeyState(type, initializer), |
| 238 m_touches(TouchList::create(initializer.touches())), | 239 m_touches(TouchList::create(initializer.touches())), |
| 239 m_targetTouches(TouchList::create(initializer.targetTouches())), | 240 m_targetTouches(TouchList::create(initializer.targetTouches())), |
| 240 m_changedTouches(TouchList::create(initializer.changedTouches())), | 241 m_changedTouches(TouchList::create(initializer.changedTouches())), |
| 241 m_causesScrollingIfUncanceled(false), | 242 m_causesScrollingIfUncanceled(false), |
| 242 m_firstTouchMoveOrStart(false), | 243 m_firstTouchMoveOrStart(false), |
| 243 m_defaultPreventedBeforeCurrentTarget(false) {} | 244 m_defaultPreventedBeforeCurrentTarget(false), |
| 245 m_currentTouchAction(TouchActionAuto) {} |
| 244 | 246 |
| 245 TouchEvent::~TouchEvent() {} | 247 TouchEvent::~TouchEvent() {} |
| 246 | 248 |
| 247 const AtomicString& TouchEvent::interfaceName() const { | 249 const AtomicString& TouchEvent::interfaceName() const { |
| 248 return EventNames::TouchEvent; | 250 return EventNames::TouchEvent; |
| 249 } | 251 } |
| 250 | 252 |
| 251 bool TouchEvent::isTouchEvent() const { | 253 bool TouchEvent::isTouchEvent() const { |
| 252 return true; | 254 return true; |
| 253 } | 255 } |
| 254 | 256 |
| 255 void TouchEvent::preventDefault() { | 257 void TouchEvent::preventDefault() { |
| 256 UIEventWithKeyState::preventDefault(); | 258 UIEventWithKeyState::preventDefault(); |
| 257 | 259 |
| 258 // A common developer error is to wait too long before attempting to stop | 260 // A common developer error is to wait too long before attempting to stop |
| 259 // scrolling by consuming a touchmove event. Generate a warning if this | 261 // scrolling by consuming a touchmove event. Generate a warning if this |
| 260 // event is uncancelable. | 262 // event is uncancelable. |
| 261 if (!cancelable() && handlingPassive() == PassiveMode::NotPassive && view() && | 263 String warningMessage; |
| 262 view()->isLocalDOMWindow() && view()->frame()) { | 264 switch (handlingPassive()) { |
| 265 case PassiveMode::NotPassive: |
| 266 if (!cancelable()) { |
| 267 warningMessage = "Ignored attempt to cancel a " + type() + |
| 268 " event with cancelable=false, for example " |
| 269 "because scrolling is in progress and " |
| 270 "cannot be interrupted."; |
| 271 } |
| 272 break; |
| 273 case PassiveMode::PassiveForcedDocumentLevel: |
| 274 // Only enable the warning when the current touch action is auto because |
| 275 // an author may use touch action but call preventDefault for interop with |
| 276 // browsers that don't support touch-action. |
| 277 if (m_currentTouchAction == TouchActionAuto) { |
| 278 warningMessage = |
| 279 "Unable to preventDefault inside passive event listener due to " |
| 280 "target being treated as passive. See " |
| 281 "https://www.chromestatus.com/features/5093566007214080"; |
| 282 } |
| 283 break; |
| 284 default: |
| 285 break; |
| 286 } |
| 287 |
| 288 if (!warningMessage.isEmpty() && view() && view()->isLocalDOMWindow() && |
| 289 view()->frame()) { |
| 263 toLocalDOMWindow(view())->frame()->console().addMessage( | 290 toLocalDOMWindow(view())->frame()->console().addMessage( |
| 264 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, | 291 ConsoleMessage::create(JSMessageSource, WarningMessageLevel, |
| 265 "Ignored attempt to cancel a " + type() + | 292 warningMessage)); |
| 266 " event with cancelable=false, for example " | |
| 267 "because scrolling is in progress and " | |
| 268 "cannot be interrupted.")); | |
| 269 } | 293 } |
| 270 | 294 |
| 271 if ((type() == EventTypeNames::touchstart || | 295 if ((type() == EventTypeNames::touchstart || |
| 272 type() == EventTypeNames::touchmove) && | 296 type() == EventTypeNames::touchmove) && |
| 273 view() && view()->frame() && m_currentTouchAction == TouchActionAuto) { | 297 view() && view()->frame() && m_currentTouchAction == TouchActionAuto) { |
| 274 switch (handlingPassive()) { | 298 switch (handlingPassive()) { |
| 275 case PassiveMode::NotPassiveDefault: | 299 case PassiveMode::NotPassiveDefault: |
| 276 UseCounter::count(view()->frame(), | 300 UseCounter::count(view()->frame(), |
| 277 UseCounter::TouchEventPreventedNoTouchAction); | 301 UseCounter::TouchEventPreventedNoTouchAction); |
| 278 break; | 302 break; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 return toTouchEvent(EventDispatchMediator::event()); | 348 return toTouchEvent(EventDispatchMediator::event()); |
| 325 } | 349 } |
| 326 | 350 |
| 327 DispatchEventResult TouchEventDispatchMediator::dispatchEvent( | 351 DispatchEventResult TouchEventDispatchMediator::dispatchEvent( |
| 328 EventDispatcher& dispatcher) const { | 352 EventDispatcher& dispatcher) const { |
| 329 event().eventPath().adjustForTouchEvent(event()); | 353 event().eventPath().adjustForTouchEvent(event()); |
| 330 return dispatcher.dispatch(); | 354 return dispatcher.dispatch(); |
| 331 } | 355 } |
| 332 | 356 |
| 333 } // namespace blink | 357 } // namespace blink |
| OLD | NEW |