OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "platform/scroll/Scrollbar.h" | 26 #include "platform/scroll/Scrollbar.h" |
27 | 27 |
28 #include <algorithm> | 28 #include <algorithm> |
29 #include "platform/HostWindow.h" | 29 #include "platform/HostWindow.h" |
30 #include "platform/PlatformGestureEvent.h" | |
31 #include "platform/PlatformMouseEvent.h" | 30 #include "platform/PlatformMouseEvent.h" |
32 #include "platform/geometry/FloatRect.h" | 31 #include "platform/geometry/FloatRect.h" |
33 #include "platform/graphics/paint/CullRect.h" | 32 #include "platform/graphics/paint/CullRect.h" |
34 #include "platform/scroll/ScrollAnimatorBase.h" | 33 #include "platform/scroll/ScrollAnimatorBase.h" |
35 #include "platform/scroll/ScrollableArea.h" | 34 #include "platform/scroll/ScrollableArea.h" |
36 #include "platform/scroll/ScrollbarTheme.h" | 35 #include "platform/scroll/ScrollbarTheme.h" |
| 36 #include "public/platform/WebGestureEvent.h" |
37 | 37 |
38 namespace blink { | 38 namespace blink { |
39 | 39 |
40 Scrollbar::Scrollbar(ScrollableArea* scrollableArea, | 40 Scrollbar::Scrollbar(ScrollableArea* scrollableArea, |
41 ScrollbarOrientation orientation, | 41 ScrollbarOrientation orientation, |
42 ScrollbarControlSize controlSize, | 42 ScrollbarControlSize controlSize, |
43 HostWindow* hostWindow, | 43 HostWindow* hostWindow, |
44 ScrollbarTheme* theme) | 44 ScrollbarTheme* theme) |
45 : m_scrollableArea(scrollableArea), | 45 : m_scrollableArea(scrollableArea), |
46 m_orientation(orientation), | 46 m_orientation(orientation), |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 void Scrollbar::setPressedPart(ScrollbarPart part) { | 313 void Scrollbar::setPressedPart(ScrollbarPart part) { |
314 if (m_pressedPart != NoPart | 314 if (m_pressedPart != NoPart |
315 // When we no longer have a pressed part, we can start drawing a hovered | 315 // When we no longer have a pressed part, we can start drawing a hovered |
316 // state on the hovered part. | 316 // state on the hovered part. |
317 || m_hoveredPart != NoPart) | 317 || m_hoveredPart != NoPart) |
318 setNeedsPaintInvalidation( | 318 setNeedsPaintInvalidation( |
319 static_cast<ScrollbarPart>(m_pressedPart | m_hoveredPart | part)); | 319 static_cast<ScrollbarPart>(m_pressedPart | m_hoveredPart | part)); |
320 m_pressedPart = part; | 320 m_pressedPart = part; |
321 } | 321 } |
322 | 322 |
323 bool Scrollbar::gestureEvent(const PlatformGestureEvent& evt, | 323 bool Scrollbar::gestureEvent(const WebGestureEvent& evt, |
324 bool* shouldUpdateCapture) { | 324 bool* shouldUpdateCapture) { |
325 DCHECK(shouldUpdateCapture); | 325 DCHECK(shouldUpdateCapture); |
326 switch (evt.type()) { | 326 switch (evt.type) { |
327 case PlatformEvent::GestureTapDown: | 327 case WebInputEvent::GestureTapDown: { |
328 setPressedPart(theme().hitTest(*this, evt.position())); | 328 IntPoint position = flooredIntPoint(evt.positionInRootFrame()); |
| 329 setPressedPart(theme().hitTest(*this, position)); |
329 m_pressedPos = orientation() == HorizontalScrollbar | 330 m_pressedPos = orientation() == HorizontalScrollbar |
330 ? convertFromRootFrame(evt.position()).x() | 331 ? convertFromRootFrame(position).x() |
331 : convertFromRootFrame(evt.position()).y(); | 332 : convertFromRootFrame(position).y(); |
332 *shouldUpdateCapture = true; | 333 *shouldUpdateCapture = true; |
333 return true; | 334 return true; |
334 case PlatformEvent::GestureTapDownCancel: | 335 } |
| 336 case WebInputEvent::GestureTapCancel: |
335 if (m_pressedPart != ThumbPart) | 337 if (m_pressedPart != ThumbPart) |
336 return false; | 338 return false; |
337 m_scrollPos = m_pressedPos; | 339 m_scrollPos = m_pressedPos; |
338 return true; | 340 return true; |
339 case PlatformEvent::GestureScrollBegin: | 341 case WebInputEvent::GestureScrollBegin: |
340 switch (evt.source()) { | 342 switch (evt.sourceDevice) { |
341 case PlatformGestureSourceTouchpad: | 343 case WebGestureDeviceTouchpad: |
342 // Update the state on GSB for touchpad since GestureTapDown | 344 // Update the state on GSB for touchpad since GestureTapDown |
343 // is not generated by that device. Touchscreen uses the tap down | 345 // is not generated by that device. Touchscreen uses the tap down |
344 // gesture since the scrollbar enters a visual active state. | 346 // gesture since the scrollbar enters a visual active state. |
345 *shouldUpdateCapture = true; | 347 *shouldUpdateCapture = true; |
346 setPressedPart(NoPart); | 348 setPressedPart(NoPart); |
347 m_pressedPos = 0; | 349 m_pressedPos = 0; |
348 return true; | 350 return true; |
349 case PlatformGestureSourceTouchscreen: | 351 case WebGestureDeviceTouchscreen: |
350 if (m_pressedPart != ThumbPart) | 352 if (m_pressedPart != ThumbPart) |
351 return false; | 353 return false; |
352 m_scrollPos = m_pressedPos; | 354 m_scrollPos = m_pressedPos; |
353 return true; | 355 return true; |
354 default: | 356 default: |
355 ASSERT_NOT_REACHED(); | 357 ASSERT_NOT_REACHED(); |
356 return true; | 358 return true; |
357 } | 359 } |
358 break; | 360 break; |
359 case PlatformEvent::GestureScrollUpdate: | 361 case WebInputEvent::GestureScrollUpdate: |
360 switch (evt.source()) { | 362 switch (evt.sourceDevice) { |
361 case PlatformGestureSourceTouchpad: { | 363 case WebGestureDeviceTouchpad: { |
362 FloatSize delta(-evt.deltaX(), -evt.deltaY()); | 364 FloatSize delta(-evt.deltaXInRootFrame(), -evt.deltaYInRootFrame()); |
363 if (m_scrollableArea && | 365 if (m_scrollableArea && |
364 m_scrollableArea->userScroll(evt.deltaUnits(), delta) | 366 m_scrollableArea |
| 367 ->userScroll(toPlatformScrollGranularity(evt.deltaUnits()), |
| 368 delta) |
365 .didScroll()) { | 369 .didScroll()) { |
366 return true; | 370 return true; |
367 } | 371 } |
368 return false; | 372 return false; |
369 } | 373 } |
370 case PlatformGestureSourceTouchscreen: | 374 case WebGestureDeviceTouchscreen: |
371 if (m_pressedPart != ThumbPart) | 375 if (m_pressedPart != ThumbPart) |
372 return false; | 376 return false; |
373 m_scrollPos += orientation() == HorizontalScrollbar ? evt.deltaX() | 377 m_scrollPos += orientation() == HorizontalScrollbar |
374 : evt.deltaY(); | 378 ? evt.deltaXInRootFrame() |
| 379 : evt.deltaYInRootFrame(); |
375 moveThumb(m_scrollPos, false); | 380 moveThumb(m_scrollPos, false); |
376 return true; | 381 return true; |
377 default: | 382 default: |
378 ASSERT_NOT_REACHED(); | 383 ASSERT_NOT_REACHED(); |
379 return true; | 384 return true; |
380 } | 385 } |
381 break; | 386 break; |
382 case PlatformEvent::GestureScrollEnd: | 387 case WebInputEvent::GestureScrollEnd: |
383 case PlatformEvent::GestureLongPress: | 388 case WebInputEvent::GestureLongPress: |
384 case PlatformEvent::GestureFlingStart: | 389 case WebInputEvent::GestureFlingStart: |
385 m_scrollPos = 0; | 390 m_scrollPos = 0; |
386 m_pressedPos = 0; | 391 m_pressedPos = 0; |
387 setPressedPart(NoPart); | 392 setPressedPart(NoPart); |
388 return false; | 393 return false; |
389 case PlatformEvent::GestureTap: { | 394 case WebInputEvent::GestureTap: { |
390 if (m_pressedPart != ThumbPart && m_pressedPart != NoPart && | 395 if (m_pressedPart != ThumbPart && m_pressedPart != NoPart && |
391 m_scrollableArea && | 396 m_scrollableArea && |
392 m_scrollableArea | 397 m_scrollableArea |
393 ->userScroll( | 398 ->userScroll( |
394 pressedPartScrollGranularity(), | 399 pressedPartScrollGranularity(), |
395 toScrollDelta(pressedPartScrollDirectionPhysical(), 1)) | 400 toScrollDelta(pressedPartScrollDirectionPhysical(), 1)) |
396 .didScroll()) { | 401 .didScroll()) { |
397 return true; | 402 return true; |
398 } | 403 } |
399 m_scrollPos = 0; | 404 m_scrollPos = 0; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 invalidParts = AllParts; | 628 invalidParts = AllParts; |
624 if (invalidParts & ~ThumbPart) | 629 if (invalidParts & ~ThumbPart) |
625 m_trackNeedsRepaint = true; | 630 m_trackNeedsRepaint = true; |
626 if (invalidParts & ThumbPart) | 631 if (invalidParts & ThumbPart) |
627 m_thumbNeedsRepaint = true; | 632 m_thumbNeedsRepaint = true; |
628 if (m_scrollableArea) | 633 if (m_scrollableArea) |
629 m_scrollableArea->setScrollbarNeedsPaintInvalidation(orientation()); | 634 m_scrollableArea->setScrollbarNeedsPaintInvalidation(orientation()); |
630 } | 635 } |
631 | 636 |
632 } // namespace blink | 637 } // namespace blink |
OLD | NEW |