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

Side by Side Diff: ui/views/widget/root_view.cc

Issue 395563002: Make RootView::DispatchGestureEvent() non-virtual (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed nit Created 6 years, 5 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
« no previous file with comments | « ui/views/widget/root_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/views/widget/root_view.h" 5 #include "ui/views/widget/root_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // that event type has been refactored, and then 255 // that event type has been refactored, and then
256 // eventually remove this function altogether. See 256 // eventually remove this function altogether. See
257 // crbug.com/348083. 257 // crbug.com/348083.
258 if (event->IsKeyEvent()) 258 if (event->IsKeyEvent())
259 return EventProcessor::OnEventFromSource(event); 259 return EventProcessor::OnEventFromSource(event);
260 else if (event->IsScrollEvent()) 260 else if (event->IsScrollEvent())
261 return EventProcessor::OnEventFromSource(event); 261 return EventProcessor::OnEventFromSource(event);
262 else if (event->IsTouchEvent()) 262 else if (event->IsTouchEvent())
263 NOTREACHED() << "Touch events should not be sent to RootView."; 263 NOTREACHED() << "Touch events should not be sent to RootView.";
264 else if (event->IsGestureEvent()) 264 else if (event->IsGestureEvent())
265 DispatchGestureEvent(static_cast<ui::GestureEvent*>(event)); 265 DispatchGestureEvent(event->AsGestureEvent());
266 else if (event->IsMouseEvent()) 266 else if (event->IsMouseEvent())
267 NOTREACHED() << "Should not be called with a MouseEvent."; 267 NOTREACHED() << "Should not be called with a MouseEvent.";
268 else 268 else
269 NOTREACHED() << "Invalid event type."; 269 NOTREACHED() << "Invalid event type.";
270 270
271 return DispatchDetails(); 271 return DispatchDetails();
272 } 272 }
273 273
274 //////////////////////////////////////////////////////////////////////////////// 274 ////////////////////////////////////////////////////////////////////////////////
275 // RootView, View overrides: 275 // RootView, View overrides:
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 } 549 }
550 550
551 void RootView::UpdateParentLayer() { 551 void RootView::UpdateParentLayer() {
552 if (layer()) 552 if (layer())
553 ReparentLayer(gfx::Vector2d(GetMirroredX(), y()), widget_->GetLayer()); 553 ReparentLayer(gfx::Vector2d(GetMirroredX(), y()), widget_->GetLayer());
554 } 554 }
555 555
556 //////////////////////////////////////////////////////////////////////////////// 556 ////////////////////////////////////////////////////////////////////////////////
557 // RootView, protected: 557 // RootView, protected:
558 558
559 void RootView::ViewHierarchyChanged(
560 const ViewHierarchyChangedDetails& details) {
561 widget_->ViewHierarchyChanged(details);
562
563 if (!details.is_add) {
564 if (!explicit_mouse_handler_ && mouse_pressed_handler_ == details.child)
565 mouse_pressed_handler_ = NULL;
566 if (mouse_move_handler_ == details.child)
567 mouse_move_handler_ = NULL;
568 if (gesture_handler_ == details.child)
569 gesture_handler_ = NULL;
570 if (scroll_gesture_handler_ == details.child)
571 scroll_gesture_handler_ = NULL;
572 if (event_dispatch_target_ == details.child)
573 event_dispatch_target_ = NULL;
574 if (old_dispatch_target_ == details.child)
575 old_dispatch_target_ = NULL;
576 }
577 }
578
579 void RootView::VisibilityChanged(View* /*starting_from*/, bool is_visible) {
580 if (!is_visible) {
581 // When the root view is being hidden (e.g. when widget is minimized)
582 // handlers are reset, so that after it is reshown, events are not captured
583 // by old handlers.
584 explicit_mouse_handler_ = false;
585 mouse_pressed_handler_ = NULL;
586 mouse_move_handler_ = NULL;
587 gesture_handler_ = NULL;
588 scroll_gesture_handler_ = NULL;
589 event_dispatch_target_ = NULL;
590 old_dispatch_target_ = NULL;
591 }
592 }
593
594 void RootView::OnPaint(gfx::Canvas* canvas) {
595 if (!layer() || !layer()->fills_bounds_opaquely())
596 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
597
598 View::OnPaint(canvas);
599 }
600
601 gfx::Vector2d RootView::CalculateOffsetToAncestorWithLayer(
602 ui::Layer** layer_parent) {
603 gfx::Vector2d offset(View::CalculateOffsetToAncestorWithLayer(layer_parent));
604 if (!layer() && layer_parent)
605 *layer_parent = widget_->GetLayer();
606 return offset;
607 }
608
609 View::DragInfo* RootView::GetDragInfo() {
610 return &drag_info_;
611 }
612
613 ////////////////////////////////////////////////////////////////////////////////
614 // RootView, private:
615
616 // Input -----------------------------------------------------------------------
617
559 void RootView::DispatchGestureEvent(ui::GestureEvent* event) { 618 void RootView::DispatchGestureEvent(ui::GestureEvent* event) {
560 if (gesture_handler_) { 619 if (gesture_handler_) {
561 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during 620 // |gesture_handler_| (or |scroll_gesture_handler_|) can be deleted during
562 // processing. 621 // processing.
563 View* handler = scroll_gesture_handler_ && 622 View* handler = scroll_gesture_handler_ &&
564 (event->IsScrollGestureEvent() || event->IsFlingScrollEvent()) ? 623 (event->IsScrollGestureEvent() || event->IsFlingScrollEvent()) ?
565 scroll_gesture_handler_ : gesture_handler_; 624 scroll_gesture_handler_ : gesture_handler_;
566 ui::GestureEvent handler_event(*event, static_cast<View*>(this), handler); 625 ui::GestureEvent handler_event(*event, static_cast<View*>(this), handler);
567 ui::EventDispatchDetails dispatch_details = 626 ui::EventDispatchDetails dispatch_details =
568 DispatchEvent(handler, &handler_event); 627 DispatchEvent(handler, &handler_event);
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 return; 744 return;
686 } 745 }
687 746
688 // The gesture event wasn't processed. Go up the view hierarchy and 747 // The gesture event wasn't processed. Go up the view hierarchy and
689 // dispatch the gesture event. 748 // dispatch the gesture event.
690 } 749 }
691 750
692 gesture_handler_ = NULL; 751 gesture_handler_ = NULL;
693 } 752 }
694 753
695 void RootView::ViewHierarchyChanged(
696 const ViewHierarchyChangedDetails& details) {
697 widget_->ViewHierarchyChanged(details);
698
699 if (!details.is_add) {
700 if (!explicit_mouse_handler_ && mouse_pressed_handler_ == details.child)
701 mouse_pressed_handler_ = NULL;
702 if (mouse_move_handler_ == details.child)
703 mouse_move_handler_ = NULL;
704 if (gesture_handler_ == details.child)
705 gesture_handler_ = NULL;
706 if (scroll_gesture_handler_ == details.child)
707 scroll_gesture_handler_ = NULL;
708 if (event_dispatch_target_ == details.child)
709 event_dispatch_target_ = NULL;
710 if (old_dispatch_target_ == details.child)
711 old_dispatch_target_ = NULL;
712 }
713 }
714
715 void RootView::VisibilityChanged(View* /*starting_from*/, bool is_visible) {
716 if (!is_visible) {
717 // When the root view is being hidden (e.g. when widget is minimized)
718 // handlers are reset, so that after it is reshown, events are not captured
719 // by old handlers.
720 explicit_mouse_handler_ = false;
721 mouse_pressed_handler_ = NULL;
722 mouse_move_handler_ = NULL;
723 gesture_handler_ = NULL;
724 scroll_gesture_handler_ = NULL;
725 event_dispatch_target_ = NULL;
726 old_dispatch_target_ = NULL;
727 }
728 }
729
730 void RootView::OnPaint(gfx::Canvas* canvas) {
731 if (!layer() || !layer()->fills_bounds_opaquely())
732 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
733
734 View::OnPaint(canvas);
735 }
736
737 gfx::Vector2d RootView::CalculateOffsetToAncestorWithLayer(
738 ui::Layer** layer_parent) {
739 gfx::Vector2d offset(View::CalculateOffsetToAncestorWithLayer(layer_parent));
740 if (!layer() && layer_parent)
741 *layer_parent = widget_->GetLayer();
742 return offset;
743 }
744
745 View::DragInfo* RootView::GetDragInfo() {
746 return &drag_info_;
747 }
748
749 ////////////////////////////////////////////////////////////////////////////////
750 // RootView, private:
751
752 // Input -----------------------------------------------------------------------
753
754 void RootView::UpdateCursor(const ui::MouseEvent& event) { 754 void RootView::UpdateCursor(const ui::MouseEvent& event) {
755 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) { 755 if (!(event.flags() & ui::EF_IS_NON_CLIENT)) {
756 View* v = GetEventHandlerForPoint(event.location()); 756 View* v = GetEventHandlerForPoint(event.location());
757 ui::MouseEvent me(event, static_cast<View*>(this), v); 757 ui::MouseEvent me(event, static_cast<View*>(this), v);
758 widget_->SetCursor(v->GetCursor(me)); 758 widget_->SetCursor(v->GetCursor(me));
759 } 759 }
760 } 760 }
761 761
762 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) { 762 void RootView::SetMouseLocationAndFlags(const ui::MouseEvent& event) {
763 last_mouse_event_flags_ = event.flags(); 763 last_mouse_event_flags_ = event.flags();
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 808
809 #ifndef NDEBUG 809 #ifndef NDEBUG
810 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_)); 810 DCHECK(!event_dispatch_target_ || Contains(event_dispatch_target_));
811 #endif 811 #endif
812 812
813 return details; 813 return details;
814 } 814 }
815 815
816 } // namespace internal 816 } // namespace internal
817 } // namespace views 817 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/root_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698