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

Side by Side Diff: ui/views/view.cc

Issue 10827198: Change View::HitTest to View::HitTestRect (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed errors reported by trybots Created 8 years, 4 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
« no previous file with comments | « ui/views/view.h ('k') | ui/views/view_unittest.cc » ('j') | 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/view.h" 5 #include "ui/views/view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "third_party/skia/include/core/SkRect.h" 15 #include "third_party/skia/include/core/SkRect.h"
16 #include "ui/base/accessibility/accessibility_types.h" 16 #include "ui/base/accessibility/accessibility_types.h"
17 #include "ui/base/dragdrop/drag_drop_types.h" 17 #include "ui/base/dragdrop/drag_drop_types.h"
18 #include "ui/compositor/compositor.h" 18 #include "ui/compositor/compositor.h"
19 #include "ui/compositor/layer.h" 19 #include "ui/compositor/layer.h"
20 #include "ui/compositor/layer_animator.h" 20 #include "ui/compositor/layer_animator.h"
21 #include "ui/gfx/canvas.h" 21 #include "ui/gfx/canvas.h"
22 #include "ui/gfx/interpolated_transform.h" 22 #include "ui/gfx/interpolated_transform.h"
23 #include "ui/gfx/path.h" 23 #include "ui/gfx/path.h"
24 #include "ui/gfx/point3.h" 24 #include "ui/gfx/point3.h"
25 #include "ui/gfx/skia_util.h"
25 #include "ui/gfx/transform.h" 26 #include "ui/gfx/transform.h"
26 #include "ui/views/background.h" 27 #include "ui/views/background.h"
27 #include "ui/views/context_menu_controller.h" 28 #include "ui/views/context_menu_controller.h"
28 #include "ui/views/drag_controller.h" 29 #include "ui/views/drag_controller.h"
29 #include "ui/views/layout/layout_manager.h" 30 #include "ui/views/layout/layout_manager.h"
30 #include "ui/views/views_delegate.h" 31 #include "ui/views/views_delegate.h"
31 #include "ui/views/widget/native_widget_private.h" 32 #include "ui/views/widget/native_widget_private.h"
32 #include "ui/views/widget/root_view.h" 33 #include "ui/views/widget/root_view.h"
33 #include "ui/views/widget/tooltip_manager.h" 34 #include "ui/views/widget/tooltip_manager.h"
34 #include "ui/views/widget/widget.h" 35 #include "ui/views/widget/widget.h"
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 View* View::GetEventHandlerForPoint(const gfx::Point& point) { 751 View* View::GetEventHandlerForPoint(const gfx::Point& point) {
751 // Walk the child Views recursively looking for the View that most 752 // Walk the child Views recursively looking for the View that most
752 // tightly encloses the specified point. 753 // tightly encloses the specified point.
753 for (int i = child_count() - 1; i >= 0; --i) { 754 for (int i = child_count() - 1; i >= 0; --i) {
754 View* child = child_at(i); 755 View* child = child_at(i);
755 if (!child->visible()) 756 if (!child->visible())
756 continue; 757 continue;
757 758
758 gfx::Point point_in_child_coords(point); 759 gfx::Point point_in_child_coords(point);
759 View::ConvertPointToView(this, child, &point_in_child_coords); 760 View::ConvertPointToView(this, child, &point_in_child_coords);
760 if (child->HitTest(point_in_child_coords)) 761 if (child->HitTestPoint(point_in_child_coords))
761 return child->GetEventHandlerForPoint(point_in_child_coords); 762 return child->GetEventHandlerForPoint(point_in_child_coords);
762 } 763 }
763 return this; 764 return this;
764 } 765 }
765 766
766 gfx::NativeCursor View::GetCursor(const MouseEvent& event) { 767 gfx::NativeCursor View::GetCursor(const MouseEvent& event) {
767 #if defined(OS_WIN) && !defined(USE_AURA) 768 #if defined(OS_WIN) && !defined(USE_AURA)
768 static HCURSOR arrow = LoadCursor(NULL, IDC_ARROW); 769 static HCURSOR arrow = LoadCursor(NULL, IDC_ARROW);
769 return arrow; 770 return arrow;
770 #else 771 #else
771 return gfx::kNullCursor; 772 return gfx::kNullCursor;
772 #endif 773 #endif
773 } 774 }
774 775
775 bool View::HitTest(const gfx::Point& l) const { 776 bool View::HitTestPoint(const gfx::Point& point) const {
776 if (GetLocalBounds().Contains(l)) { 777 return HitTestRect(gfx::Rect(point, gfx::Size(1, 1)));
778 }
779
780 bool View::HitTestRect(const gfx::Rect& rect) const {
781 if (GetLocalBounds().Intersects(rect)) {
777 if (HasHitTestMask()) { 782 if (HasHitTestMask()) {
778 gfx::Path mask; 783 gfx::Path mask;
779 GetHitTestMask(&mask); 784 GetHitTestMask(&mask);
780 #if defined(USE_AURA) 785 #if defined(USE_AURA)
781 // TODO: should we use this every where? 786 // TODO: should we use this every where?
782 SkRegion clip_region; 787 SkRegion clip_region;
783 clip_region.setRect(0, 0, width(), height()); 788 clip_region.setRect(0, 0, width(), height());
784 SkRegion mask_region; 789 SkRegion mask_region;
785 return mask_region.setPath(mask, clip_region) && 790 return mask_region.setPath(mask, clip_region) &&
786 mask_region.contains(l.x(), l.y()); 791 mask_region.intersects(RectToSkIRect(rect));
787 #elif defined(OS_WIN) 792 #elif defined(OS_WIN)
788 base::win::ScopedRegion rgn(mask.CreateNativeRegion()); 793 base::win::ScopedRegion rgn(mask.CreateNativeRegion());
789 return !!PtInRegion(rgn, l.x(), l.y()); 794 const RECT r(rect.ToRECT());
795 return RectInRegion(rgn, &r) != 0;
790 #endif 796 #endif
791 } 797 }
792 // No mask, but inside our bounds. 798 // No mask, but inside our bounds.
793 return true; 799 return true;
794 } 800 }
795 // Outside our bounds. 801 // Outside our bounds.
796 return false; 802 return false;
797 } 803 }
798 804
799 bool View::OnMousePressed(const MouseEvent& event) { 805 bool View::OnMousePressed(const MouseEvent& event) {
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 1895
1890 Widget* widget = GetWidget(); 1896 Widget* widget = GetWidget();
1891 if (widget) 1897 if (widget)
1892 widget->UpdateRootLayers(); 1898 widget->UpdateRootLayers();
1893 } 1899 }
1894 1900
1895 // Input ----------------------------------------------------------------------- 1901 // Input -----------------------------------------------------------------------
1896 1902
1897 bool View::ProcessMousePressed(const MouseEvent& event, DragInfo* drag_info) { 1903 bool View::ProcessMousePressed(const MouseEvent& event, DragInfo* drag_info) {
1898 int drag_operations = 1904 int drag_operations =
1899 (enabled_ && event.IsOnlyLeftMouseButton() && HitTest(event.location())) ? 1905 (enabled_ && event.IsOnlyLeftMouseButton() &&
1900 GetDragOperations(event.location()) : 0; 1906 HitTestPoint(event.location())) ?
1907 GetDragOperations(event.location()) : 0;
1901 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? 1908 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ?
1902 context_menu_controller_ : 0; 1909 context_menu_controller_ : 0;
1903 1910
1904 const bool enabled = enabled_; 1911 const bool enabled = enabled_;
1905 const bool result = OnMousePressed(event); 1912 const bool result = OnMousePressed(event);
1906 // WARNING: we may have been deleted, don't use any View variables. 1913 // WARNING: we may have been deleted, don't use any View variables.
1907 1914
1908 if (!enabled) 1915 if (!enabled)
1909 return result; 1916 return result;
1910 1917
(...skipping 24 matching lines...) Expand all
1935 // WARNING: we may have been deleted. 1942 // WARNING: we may have been deleted.
1936 return (context_menu_controller != NULL) || possible_drag; 1943 return (context_menu_controller != NULL) || possible_drag;
1937 } 1944 }
1938 1945
1939 void View::ProcessMouseReleased(const MouseEvent& event) { 1946 void View::ProcessMouseReleased(const MouseEvent& event) {
1940 if (context_menu_controller_ && event.IsOnlyRightMouseButton()) { 1947 if (context_menu_controller_ && event.IsOnlyRightMouseButton()) {
1941 // Assume that if there is a context menu controller we won't be deleted 1948 // Assume that if there is a context menu controller we won't be deleted
1942 // from mouse released. 1949 // from mouse released.
1943 gfx::Point location(event.location()); 1950 gfx::Point location(event.location());
1944 OnMouseReleased(event); 1951 OnMouseReleased(event);
1945 if (HitTest(location)) { 1952 if (HitTestPoint(location)) {
1946 ConvertPointToScreen(this, &location); 1953 ConvertPointToScreen(this, &location);
1947 ShowContextMenu(location, true); 1954 ShowContextMenu(location, true);
1948 } 1955 }
1949 } else { 1956 } else {
1950 OnMouseReleased(event); 1957 OnMouseReleased(event);
1951 } 1958 }
1952 // WARNING: we may have been deleted. 1959 // WARNING: we may have been deleted.
1953 } 1960 }
1954 1961
1955 ui::TouchStatus View::ProcessTouchEvent(const TouchEvent& event) { 1962 ui::TouchStatus View::ProcessTouchEvent(const TouchEvent& event) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 gfx::Point widget_location(event.location()); 2113 gfx::Point widget_location(event.location());
2107 ConvertPointToWidget(this, &widget_location); 2114 ConvertPointToWidget(this, &widget_location);
2108 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations); 2115 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations);
2109 return true; 2116 return true;
2110 #else 2117 #else
2111 return false; 2118 return false;
2112 #endif // !defined(OS_MACOSX) 2119 #endif // !defined(OS_MACOSX)
2113 } 2120 }
2114 2121
2115 } // namespace views 2122 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/view.h ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698