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