Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1243)

Side by Side Diff: chrome/browser/renderer_host/render_widget_host_view_views.cc

Issue 6347002: touch: Return an enum from OnTouchEvent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/renderer_host/render_widget_host_view_views.h" 5 #include "chrome/browser/renderer_host/render_widget_host_view_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 #if 0 662 #if 0
663 TODO(bryeung): key bindings 663 TODO(bryeung): key bindings
664 if (!event.skip_in_browser && 664 if (!event.skip_in_browser &&
665 key_bindings_handler_->Match(event, &edit_commands)) { 665 key_bindings_handler_->Match(event, &edit_commands)) {
666 host_->ForwardEditCommandsForNextKeyEvent(edit_commands); 666 host_->ForwardEditCommandsForNextKeyEvent(edit_commands);
667 } 667 }
668 #endif 668 #endif
669 host_->ForwardKeyboardEvent(event); 669 host_->ForwardKeyboardEvent(event);
670 } 670 }
671 671
672 bool RenderWidgetHostViewViews::OnTouchEvent(const views::TouchEvent& e) { 672 views::View::TouchStatus RenderWidgetHostViewViews::OnTouchEvent(
673 const views::TouchEvent& e) {
673 // Update the list of touch points first. 674 // Update the list of touch points first.
674 WebKit::WebTouchPoint* point = NULL; 675 WebKit::WebTouchPoint* point = NULL;
676 TouchStatus status = TOUCH_STATUS_UNKNOWN;
675 677
676 switch (e.GetType()) { 678 switch (e.GetType()) {
677 case views::Event::ET_TOUCH_PRESSED: 679 case views::Event::ET_TOUCH_PRESSED:
678 // Add a new touch point. 680 // Add a new touch point.
679 if (touch_event_.touchPointsLength < 681 if (touch_event_.touchPointsLength <
680 WebTouchEvent::touchPointsLengthCap) { 682 WebTouchEvent::touchPointsLengthCap) {
681 point = &touch_event_.touchPoints[touch_event_.touchPointsLength++]; 683 point = &touch_event_.touchPoints[touch_event_.touchPointsLength++];
682 point->id = e.identity(); 684 point->id = e.identity();
685
686 if (touch_event_.touchPointsLength == 1) {
687 // A new touch sequence has started.
688 status = TOUCH_STATUS_START;
689 }
683 } 690 }
684 break; 691 break;
685 case views::Event::ET_TOUCH_RELEASED: 692 case views::Event::ET_TOUCH_RELEASED:
686 case views::Event::ET_TOUCH_CANCELLED: 693 case views::Event::ET_TOUCH_CANCELLED:
687 case views::Event::ET_TOUCH_MOVED: { 694 case views::Event::ET_TOUCH_MOVED: {
688 // The touch point should have been added to the event from an earlier 695 // The touch point should have been added to the event from an earlier
689 // _PRESSED event. So find that. 696 // _PRESSED event. So find that.
690 // At the moment, only a maximum of 4 touch-points are allowed. So a 697 // At the moment, only a maximum of 4 touch-points are allowed. So a
691 // simple loop should be sufficient. 698 // simple loop should be sufficient.
692 for (int i = 0; i < WebTouchEvent::touchPointsLengthCap; ++i) { 699 for (int i = 0; i < WebTouchEvent::touchPointsLengthCap; ++i) {
693 point = touch_event_.touchPoints + i; 700 point = touch_event_.touchPoints + i;
694 if (point->id == e.identity()) { 701 if (point->id == e.identity()) {
695 break; 702 break;
696 } 703 }
697 point = NULL; 704 point = NULL;
698 } 705 }
699 DCHECK(point != NULL) << "Touchpoint not found for event " << e.GetType();
700 break; 706 break;
701 } 707 }
702 default: 708 default:
703 DLOG(WARNING) << "Unknown touch event " << e.GetType(); 709 DLOG(WARNING) << "Unknown touch event " << e.GetType();
704 break; 710 break;
705 } 711 }
706 712
707 if (!point) 713 if (!point)
708 return false; 714 return TOUCH_STATUS_UNKNOWN;
715
716 if (status != TOUCH_STATUS_START)
717 status = TOUCH_STATUS_CONTINUE;
709 718
710 // Update the location and state of the point. 719 // Update the location and state of the point.
711 UpdateTouchPointPosition(&e, GetPosition(), point); 720 UpdateTouchPointPosition(&e, GetPosition(), point);
712 point->state = TouchPointStateFromEvent(&e); 721 point->state = TouchPointStateFromEvent(&e);
713 722
714 // Mark the rest of the points as stationary. 723 // Mark the rest of the points as stationary.
715 for (int i = 0; i < touch_event_.touchPointsLength; ++i) { 724 for (int i = 0; i < touch_event_.touchPointsLength; ++i) {
716 WebKit::WebTouchPoint* iter = touch_event_.touchPoints + i; 725 WebKit::WebTouchPoint* iter = touch_event_.touchPoints + i;
717 if (iter != point) { 726 if (iter != point) {
718 iter->state = WebKit::WebTouchPoint::StateStationary; 727 iter->state = WebKit::WebTouchPoint::StateStationary;
719 } 728 }
720 } 729 }
721 730
722 // Update the type of the touch event. 731 // Update the type of the touch event.
723 touch_event_.type = TouchEventTypeFromEvent(&e); 732 touch_event_.type = TouchEventTypeFromEvent(&e);
724 touch_event_.timeStampSeconds = base::Time::Now().ToDoubleT(); 733 touch_event_.timeStampSeconds = base::Time::Now().ToDoubleT();
725 734
726 // The event and all the touches have been updated. Dispatch. 735 // The event and all the touches have been updated. Dispatch.
727 host_->ForwardTouchEvent(touch_event_); 736 host_->ForwardTouchEvent(touch_event_);
728 737
729 // If the touch was released, then remove it from the list of touch points. 738 // If the touch was released, then remove it from the list of touch points.
730 if (e.GetType() == views::Event::ET_TOUCH_RELEASED) { 739 if (e.GetType() == views::Event::ET_TOUCH_RELEASED) {
731 --touch_event_.touchPointsLength; 740 --touch_event_.touchPointsLength;
732 for (int i = point - touch_event_.touchPoints; 741 for (int i = point - touch_event_.touchPoints;
733 i < touch_event_.touchPointsLength; 742 i < touch_event_.touchPointsLength;
734 ++i) { 743 ++i) {
735 touch_event_.touchPoints[i] = touch_event_.touchPoints[i + 1]; 744 touch_event_.touchPoints[i] = touch_event_.touchPoints[i + 1];
736 } 745 }
746 if (touch_event_.touchPointsLength == 0)
747 status = TOUCH_STATUS_END;
748 } else if (e.GetType() == views::Event::ET_TOUCH_CANCELLED) {
749 status = TOUCH_STATUS_CANCEL;
737 } 750 }
738 751
739 return true; 752 return status;
740 } 753 }
741 754
742 // static 755 // static
743 RenderWidgetHostView* 756 RenderWidgetHostView*
744 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView( 757 RenderWidgetHostView::GetRenderWidgetHostViewFromNativeView(
745 gfx::NativeView widget) { 758 gfx::NativeView widget) {
746 gpointer user_data = g_object_get_data(G_OBJECT(widget), 759 gpointer user_data = g_object_get_data(G_OBJECT(widget),
747 kRenderWidgetHostViewKey); 760 kRenderWidgetHostViewKey);
748 return reinterpret_cast<RenderWidgetHostView*>(user_data); 761 return reinterpret_cast<RenderWidgetHostView*>(user_data);
749 } 762 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/render_widget_host_view_views.h ('k') | views/focus/accelerator_handler_touch.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698