32 #include "FocusController.h" |
32 #include "FocusController.h" |
33 #include "PlatformScrollbar.h" |
33 #include "PlatformScrollbar.h" |
34 #include "WebScrollbarDrawer.h" |
34 #include "WebScrollbarDrawer.h" |
35 #include "RenderObject.h" |
35 #include "RenderObject.h" |
36 #include "WebScrollingDeceleratorGH.h" |
36 #include "WebScrollingDeceleratorGH.h" |
37 #include "pluginskin.h" |
37 |
38 #include "WebKitLogger.h" |
38 #include "WebKitLogger.h" |
39 using namespace WebCore; |
39 using namespace WebCore; |
|
40 using namespace RT_GestureHelper; |
40 // constants |
41 // constants |
41 const int KPageOverviewScrollPeriodic = 20 * 1000; // Update frequently for faster, smoother scrolling |
42 const int KPageOverviewScrollPeriodic = 20 * 1000; // Update frequently for faster, smoother scrolling |
42 const int KMicroInterval = 300000; |
43 const int KMicroInterval = 300000; |
43 const int KPageOverviewScrollStart = 1000; |
44 const int KPageOverviewScrollStart = 1000; |
44 const int KCancelDecelerationTimeout = 200000; //Decelerate only if flicked KCancelDecelerationTimeout microsec after last drag event. |
45 const int KCancelDecelerationTimeout = 200000; //Decelerate only if flicked KCancelDecelerationTimeout microsec after last drag event. |
45 |
46 |
46 #ifdef BRDO_PERF_IMPROVEMENTS_ENABLED_FF |
|
47 const int KScrollIntervalTimeout = 30000; // scroll timer interval in microseconds |
|
48 #else |
|
49 const int KScrollIntervalTimeout = 40000; // scroll timer interval in microseconds |
47 const int KScrollIntervalTimeout = 40000; // scroll timer interval in microseconds |
50 #endif |
|
51 |
|
52 const int KAngularDeviationThreshold = 160; // % deviation ignored from minor axis of motion(120 means 20 %) |
48 const int KAngularDeviationThreshold = 160; // % deviation ignored from minor axis of motion(120 means 20 %) |
53 const int KScrollThresholdPixels = 10; // scrolls only if delta is above this threshold |
49 const int KScrollThresholdPixels = 10; // scrolls only if delta is above this threshold |
54 const int KScrollDirectionBoundary = 30; // Bound around focal point within which scrolling locks in X or Y states |
50 const int KScrollDirectionBoundary = 30; // Bound around focal point within which scrolling locks in X or Y states |
55 const float KTanOfThresholdAngle = 0.46; // tan of 25 degree |
51 const float KTanOfThresholdAngle = 0.46; // tan of 25 degree |
56 |
52 |
135 // The constructor that can contain code that might leave. |
125 // The constructor that can contain code that might leave. |
136 // ----------------------------------------------------------------------------- |
126 // ----------------------------------------------------------------------------- |
137 // |
127 // |
138 void WebPageScrollHandler::constructL() |
128 void WebPageScrollHandler::constructL() |
139 { |
129 { |
140 m_scrollTimer = CPeriodic::NewL(CActive::EPriorityUserInput); |
130 m_scrollTimer = CPeriodic::NewL(CActive::EPriorityUserInput - 1); |
141 m_pageOverviewScrollPeriodic = CPeriodic::NewL(CActive::EPriorityUserInput); |
131 m_pageOverviewScrollPeriodic = CPeriodic::NewL(CActive::EPriorityUserInput - 1); |
142 m_lastPosition = TPoint(0, 0); |
132 m_lastPosition = TPoint(0, 0); |
143 m_scrollbarDrawer = WebScrollbarDrawer::NewL(); |
133 m_scrollbarDrawer = WebScrollbarDrawer::NewL(); |
144 if(AknLayoutUtils::PenEnabled()) { |
134 if(AknLayoutUtils::PenEnabled()) { |
145 m_touchScrolling = true; |
135 m_touchScrolling = true; |
146 m_scrollDirectionState = ScrollDirectionUnassigned; |
136 m_scrollDirectionState = ScrollDirectionUnassigned; |
380 if (m_scrollableView.m_scrollingElement) { |
370 if (m_scrollableView.m_scrollingElement) { |
381 bool shouldScrollVertically = false; |
371 bool shouldScrollVertically = false; |
382 bool shouldScrollHorizontally = false; |
372 bool shouldScrollHorizontally = false; |
383 WebFrame* frame = kit(m_scrollableView.m_scrollingElement->document()->frame()); |
373 WebFrame* frame = kit(m_scrollableView.m_scrollingElement->document()->frame()); |
384 RenderObject* render = m_scrollableView.m_scrollingElement->renderer(); |
374 RenderObject* render = m_scrollableView.m_scrollingElement->renderer(); |
385 if(render) //check if render exits before using it |
375 __ASSERT_DEBUG(render->isScrollable(), User::Panic(_L(""), KErrGeneral)); |
386 { |
376 if (aScrollDelta.iY) |
387 __ASSERT_DEBUG(render->isScrollable(), User::Panic(_L(""), KErrGeneral)); |
377 shouldScrollVertically = !render->scroll(ScrollDown, ScrollByPixel, frame->frameView()->toDocCoords(aScrollDelta).iY / 100); |
388 if (aScrollDelta.iY) |
378 if (aScrollDelta.iX) |
389 shouldScrollVertically = !render->scroll(ScrollDown, ScrollByPixel, frame->frameView()->toDocCoords(aScrollDelta).iY / 100); |
379 shouldScrollHorizontally = !render->scroll(ScrollRight, ScrollByPixel, frame->frameView()->toDocCoords(aScrollDelta).iX / 100); |
390 if (aScrollDelta.iX) |
380 |
391 shouldScrollHorizontally = !render->scroll(ScrollRight, ScrollByPixel, frame->frameView()->toDocCoords(aScrollDelta).iX / 100); |
|
392 } |
|
393 TPoint scrollPos = frame->frameView()->contentPos(); |
381 TPoint scrollPos = frame->frameView()->contentPos(); |
394 TPoint newscrollDelta = frame->frameView()->toDocCoords(aScrollDelta); |
382 TPoint newscrollDelta = frame->frameView()->toDocCoords(aScrollDelta); |
395 m_currentNormalizedPosition += newscrollDelta; |
383 m_currentNormalizedPosition += newscrollDelta; |
396 |
384 |
397 if (shouldScrollHorizontally) { |
385 if (shouldScrollHorizontally) { |
402 } |
390 } |
403 |
391 |
404 |
392 |
405 if (shouldScrollVertically || shouldScrollHorizontally){ |
393 if (shouldScrollVertically || shouldScrollHorizontally){ |
406 if (m_scrollableView.m_frameView->needScroll(scrollPos)) { |
394 if (m_scrollableView.m_frameView->needScroll(scrollPos)) { |
407 frame->frameView()->scrollTo(scrollPos, ETrue); |
395 frame->frameView()->scrollTo(scrollPos); |
408 updateScrollbars(scrollPos, newscrollDelta); |
396 updateScrollbars(scrollPos, newscrollDelta); |
409 core(frame)->sendScrollEvent(); |
397 core(frame)->sendScrollEvent(); |
410 } |
398 } |
411 } |
399 } |
412 else { |
400 else { |
429 m_lastPosition = m_currentPosition; |
417 m_lastPosition = m_currentPosition; |
430 m_currentNormalizedPosition.iX = m_scrollableView.contentPos().iX * 100; |
418 m_currentNormalizedPosition.iX = m_scrollableView.contentPos().iX * 100; |
431 m_currentNormalizedPosition.iY = m_scrollableView.contentPos().iY * 100; |
419 m_currentNormalizedPosition.iY = m_scrollableView.contentPos().iY * 100; |
432 } |
420 } |
433 else { |
421 else { |
434 |
422 |
435 m_scrollableView.m_frameView->scrollTo(scrollPos, ETrue); |
423 m_scrollableView.m_frameView->scrollTo(scrollPos); |
436 m_lastPosition = m_currentPosition; |
424 m_lastPosition = m_currentPosition; |
437 #ifndef BRDO_USE_GESTURE_HELPER |
425 #ifndef BRDO_USE_GESTURE_HELPER |
438 m_decel->updatePos(); |
426 m_decel->updatePos(); |
439 #endif |
427 #endif |
440 // update scroll bars |
428 // update scroll bars |
569 TPoint pt = frame->frameView()->viewCoordsInFrameCoords(aNewPosition); |
557 TPoint pt = frame->frameView()->viewCoordsInFrameCoords(aNewPosition); |
570 Element* e = core(frame)->document()->elementFromPoint(pt.iX, pt.iY); |
558 Element* e = core(frame)->document()->elementFromPoint(pt.iX, pt.iY); |
571 Element* currElement = NULL; |
559 Element* currElement = NULL; |
572 if(!e) return NULL; |
560 if(!e) return NULL; |
573 RenderObject* render = e->renderer(); |
561 RenderObject* render = e->renderer(); |
574 if(render) { |
562 if (render && render->isScrollable()) { |
575 RenderLayer* layer = render->enclosingLayer(); |
563 RenderLayer* layer = render->enclosingLayer(); |
576 Element* parent = e; |
564 Element* parent = e; |
577 |
565 currElement = e; |
578 if (e->isControl()) { |
566 while (!currElement->isControl() && parent && parent->renderer() && parent->renderer()->enclosingLayer() == layer) { |
579 if (render->isScrollable()) { |
567 currElement = parent; |
580 currElement = e; |
568 Node* pn = parent; |
581 } |
569 do { |
582 } |
570 pn = pn->parent(); |
583 else { |
571 } while (pn && !pn->isElementNode()); |
584 while (parent && parent->renderer()) { |
572 parent = static_cast<Element*>(pn); |
585 if (parent->renderer()->isScrollable()) { |
|
586 currElement = parent; |
|
587 break; |
|
588 } |
|
589 parent = static_cast<Element*>(parent->parent()); |
|
590 } |
|
591 } |
573 } |
592 if (currElement) { |
574 if (currElement) { |
593 //check for current element which is scrollable |
|
594 currElement->ref(); |
575 currElement->ref(); |
595 m_scrollableView.m_scrollingElement = currElement; |
576 m_scrollableView.m_scrollingElement = currElement; |
596 m_scrollableView.m_frameView = NULL; |
577 m_scrollableView.m_frameView = NULL; |
597 return true; |
578 return true; |
598 } |
579 } |
599 } |
580 } |
600 return false; |
581 return false; |
601 } |
582 } |
602 |
583 |
603 |
584 |
604 void WebPageScrollHandler::scrollPageOverviewGH() |
585 void WebPageScrollHandler::scrollPageOverviewGH() |
613 m_webView->mainFrame()->frameView()->scrollTo(TPoint(xInDoc, yInDoc)); |
594 m_webView->mainFrame()->frameView()->scrollTo(TPoint(xInDoc, yInDoc)); |
614 |
595 |
615 } |
596 } |
616 |
597 |
617 |
598 |
618 void WebPageScrollHandler::handleScrollingGH(const TStmGestureEvent& aGesture) |
599 void WebPageScrollHandler::handleScrollingGH(const TGestureEvent& aEvent) |
619 { |
600 { |
620 TPoint newPos = aGesture.CurrentPos(); |
601 TPoint newPos = aEvent.CurrentPos(); |
621 m_currentPosition = newPos; |
602 m_currentPosition = newPos; |
622 if (m_webView->inPageViewMode()) { |
603 if (m_webView->inPageViewMode()) { |
623 if (!m_pageOverviewScrollPeriodic->IsActive()){ |
604 if (!m_pageOverviewScrollPeriodic->IsActive()){ |
624 m_pageOverviewScrollPeriodic->Start( 0, KPageOverviewScrollPeriodic, |
605 m_pageOverviewScrollPeriodic->Start( 0, KPageOverviewScrollPeriodic, |
625 TCallBack(&pageOverviewScrollCallback, this)); |
606 TCallBack(&pageOverviewScrollCallback, this)); |
631 setupScrolling(newPos); |
612 setupScrolling(newPos); |
632 } |
613 } |
633 } |
614 } |
634 |
615 |
635 |
616 |
636 void WebPageScrollHandler::handleTouchDownGH(const TStmGestureEvent& aGesture) |
617 void WebPageScrollHandler::handleTouchDownGH(const TGestureEvent& aEvent) |
637 { |
618 { |
638 TPoint newPos = aGesture.CurrentPos(); |
619 TPoint newPos = aEvent.CurrentPos(); |
639 m_lastMoveEventTime = 0; |
620 m_lastMoveEventTime = 0; |
640 m_lastPosition = newPos; |
621 m_lastPosition = newPos; |
641 m_currentPosition = newPos; |
622 m_currentPosition = newPos; |
642 m_webView->setViewIsScrolling(false); |
623 m_webView->setViewIsScrolling(false); |
643 m_webView->toggleRepaintTimer(true); |
624 m_webView->toggleRepaintTimer(true); |
648 m_scrollableView.m_scrollingElement = NULL; |
629 m_scrollableView.m_scrollingElement = NULL; |
649 m_scrollableView.m_frameView = NULL; |
630 m_scrollableView.m_frameView = NULL; |
650 } |
631 } |
651 |
632 |
652 |
633 |
653 void WebPageScrollHandler::handleTouchUpGH(const TStmGestureEvent& aGesture) |
634 void WebPageScrollHandler::handleTouchUpGH(const TGestureEvent& aEvent) |
654 { |
635 { |
655 bool decelDoesScrollbars = false; |
636 bool decelDoesScrollbars = false; |
656 TPoint newPos = aGesture.CurrentPos(); |
637 TPoint newPos = aEvent.CurrentPos(); |
657 |
638 |
658 if (m_webView->inPageViewMode()) { |
639 if (m_webView->inPageViewMode()) { |
659 if (m_pageOverviewScrollPeriodic->IsActive()){ |
640 if (m_pageOverviewScrollPeriodic->IsActive()){ |
660 m_pageOverviewScrollPeriodic->Cancel(); |
641 m_pageOverviewScrollPeriodic->Cancel(); |
661 } |
642 } |
662 m_webView->closePageView(); |
643 m_webView->closePageView(); |
663 PluginSkin* plugin = m_webView->mainFrame()->focusedPlugin(); |
|
664 if(plugin) |
|
665 plugin->setPluginWinClipedRect(); |
|
666 scrollPageOverviewGH(); |
644 scrollPageOverviewGH(); |
667 m_webView->setViewIsScrolling(false); |
645 m_webView->setViewIsScrolling(false); |
668 m_webView->toggleRepaintTimer(true); |
646 m_webView->toggleRepaintTimer(true); |
669 } |
647 } |
670 else { |
648 else { |
671 m_scrollTimer->Cancel(); |
649 m_scrollTimer->Cancel(); |
672 m_lastPosition = TPoint(0, 0); |
650 m_lastPosition = TPoint(0, 0); |
673 decelDoesScrollbars = startDeceleration(aGesture); |
651 decelDoesScrollbars = startDeceleration(aEvent); |
674 |
652 |
675 if (m_webView->viewIsScrolling()) { |
653 if (m_webView->viewIsScrolling()) { |
676 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
654 Frame* frame = m_webView->page()->focusController()->focusedOrMainFrame(); |
677 frame->bridge()->sendScrollEvent(); |
655 frame->bridge()->sendScrollEvent(); |
678 } |
656 } |
686 m_lastMoveEventTime = 0; |
664 m_lastMoveEventTime = 0; |
687 } |
665 } |
688 } |
666 } |
689 |
667 |
690 |
668 |
691 bool WebPageScrollHandler::startDeceleration(const TStmGestureEvent& aGesture) |
669 bool WebPageScrollHandler::startDeceleration(const TGestureEvent& aEvent) |
692 { |
670 { |
693 bool started = false; |
671 bool started = false; |
694 TRealPoint gstSpeed = aGesture.Speed(); |
672 TRealPoint gstSpeed = aEvent.Speed(); |
695 if (Abs(gstSpeed.iX / gstSpeed.iY) <= KTanOfThresholdAngle) { |
673 if (Abs(gstSpeed.iX / gstSpeed.iY) <= KTanOfThresholdAngle) { |
696 gstSpeed.iX = 0; |
674 gstSpeed.iX = 0; |
697 } |
675 } |
698 |
676 |
699 if (Abs(gstSpeed.iY / gstSpeed.iX) <= KTanOfThresholdAngle) { |
677 if (Abs(gstSpeed.iY / gstSpeed.iX) <= KTanOfThresholdAngle) { |
700 gstSpeed.iY = 0; |
678 gstSpeed.iY = 0; |
701 } |
679 } |
702 |
680 |
703 if ((Abs(gstSpeed.iX) > 0) || (Abs(gstSpeed.iY) > 0)) { |
681 if ((Abs(gstSpeed.iX) > 0) || (Abs(gstSpeed.iY) > 0)) { |
704 started = m_decelGH->startDecel(gstSpeed, m_scrollbarDrawer); |
682 m_decelGH->startDecel(gstSpeed, m_scrollbarDrawer); |
705 } |
683 started = true; |
|
684 } |
|
685 |
|
686 |
706 return started; |
687 return started; |
707 } |
688 } |
708 |
689 |
709 void WebPageScrollHandler::stopScrolling() |
|
710 { |
|
711 if (m_scrollTimer && m_scrollTimer->IsActive()) { |
|
712 m_scrollTimer->Cancel(); |
|
713 } |
|
714 if (m_scrollbarDrawer) { |
|
715 m_scrollbarDrawer->fadeScrollbar(); |
|
716 } |
|
717 m_webView->setViewIsScrolling(false); |
|
718 } |
|
719 // End of File |
690 // End of File |