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

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: 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
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->HitTest(gfx::Rect(point_in_child_coords, gfx::Size(0, 0))))
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::HitTest(const gfx::Rect& r) const {
776 if (GetLocalBounds().Contains(l)) { 777 if (r.IsEmpty() ?
778 GetLocalBounds().Contains(r.x(), r.y()) :
779 GetLocalBounds().Intersects(r)) {
tdanderson 2012/08/07 16:18:28 I made the decision to represent a point using a r
sky 2012/08/07 20:11:43 I like whatever is easiest all around. If you say
tdanderson 2012/08/08 23:47:51 I have gone with 1x1 instead of 0x0 so that HitTes
777 if (HasHitTestMask()) { 780 if (HasHitTestMask()) {
778 gfx::Path mask; 781 gfx::Path mask;
779 GetHitTestMask(&mask); 782 GetHitTestMask(&mask);
780 #if defined(USE_AURA) 783 #if defined(USE_AURA)
781 // TODO: should we use this every where? 784 // TODO: should we use this every where?
782 SkRegion clip_region; 785 SkRegion clip_region;
783 clip_region.setRect(0, 0, width(), height()); 786 clip_region.setRect(0, 0, width(), height());
784 SkRegion mask_region; 787 SkRegion mask_region;
785 return mask_region.setPath(mask, clip_region) && 788 if (!mask_region.setPath(mask, clip_region))
786 mask_region.contains(l.x(), l.y()); 789 return false;
790 if (r.IsEmpty())
791 return mask_region.contains(r.x(), r.y());
792 return mask_region.intersects(RectToSkIRect(r));
787 #elif defined(OS_WIN) 793 #elif defined(OS_WIN)
788 base::win::ScopedRegion rgn(mask.CreateNativeRegion()); 794 base::win::ScopedRegion rgn(mask.CreateNativeRegion());
789 return !!PtInRegion(rgn, l.x(), l.y()); 795 if (r.IsEmpty())
796 return !!PtInRegion(rgn, r.x(), r.y());
797 const RECT* rect(r.x(), r.y(), r.width(), r.height());
798 return !!RectInRegion(rgn, rect);
tdanderson 2012/08/07 16:18:28 I have not tested that above two lines of code are
sky 2012/08/07 20:11:43 I don't think they are. Shouldn't rect be a value
tdanderson 2012/08/08 23:47:51 Changed. (I thought that the !! was needed to forc
sky 2012/08/09 00:30:14 It is, I'm suggesting coverting to == or !=
tdanderson 2012/08/09 16:16:46 Done.
790 #endif 799 #endif
791 } 800 }
792 // No mask, but inside our bounds. 801 // No mask, but inside our bounds.
793 return true; 802 return true;
794 } 803 }
795 // Outside our bounds. 804 // Outside our bounds.
796 return false; 805 return false;
797 } 806 }
798 807
799 bool View::OnMousePressed(const MouseEvent& event) { 808 bool View::OnMousePressed(const MouseEvent& event) {
(...skipping 1089 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 1898
1890 Widget* widget = GetWidget(); 1899 Widget* widget = GetWidget();
1891 if (widget) 1900 if (widget)
1892 widget->UpdateRootLayers(); 1901 widget->UpdateRootLayers();
1893 } 1902 }
1894 1903
1895 // Input ----------------------------------------------------------------------- 1904 // Input -----------------------------------------------------------------------
1896 1905
1897 bool View::ProcessMousePressed(const MouseEvent& event, DragInfo* drag_info) { 1906 bool View::ProcessMousePressed(const MouseEvent& event, DragInfo* drag_info) {
1898 int drag_operations = 1907 int drag_operations =
1899 (enabled_ && event.IsOnlyLeftMouseButton() && HitTest(event.location())) ? 1908 (enabled_ &&
1900 GetDragOperations(event.location()) : 0; 1909 event.IsOnlyLeftMouseButton() &&
1910 HitTest(gfx::Rect(event.location(), gfx::Size(0, 0)))) ?
1911 GetDragOperations(event.location()) : 0;
1901 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ? 1912 ContextMenuController* context_menu_controller = event.IsRightMouseButton() ?
1902 context_menu_controller_ : 0; 1913 context_menu_controller_ : 0;
1903 1914
1904 const bool enabled = enabled_; 1915 const bool enabled = enabled_;
1905 const bool result = OnMousePressed(event); 1916 const bool result = OnMousePressed(event);
1906 // WARNING: we may have been deleted, don't use any View variables. 1917 // WARNING: we may have been deleted, don't use any View variables.
1907 1918
1908 if (!enabled) 1919 if (!enabled)
1909 return result; 1920 return result;
1910 1921
(...skipping 24 matching lines...) Expand all
1935 // WARNING: we may have been deleted. 1946 // WARNING: we may have been deleted.
1936 return (context_menu_controller != NULL) || possible_drag; 1947 return (context_menu_controller != NULL) || possible_drag;
1937 } 1948 }
1938 1949
1939 void View::ProcessMouseReleased(const MouseEvent& event) { 1950 void View::ProcessMouseReleased(const MouseEvent& event) {
1940 if (context_menu_controller_ && event.IsOnlyRightMouseButton()) { 1951 if (context_menu_controller_ && event.IsOnlyRightMouseButton()) {
1941 // Assume that if there is a context menu controller we won't be deleted 1952 // Assume that if there is a context menu controller we won't be deleted
1942 // from mouse released. 1953 // from mouse released.
1943 gfx::Point location(event.location()); 1954 gfx::Point location(event.location());
1944 OnMouseReleased(event); 1955 OnMouseReleased(event);
1945 if (HitTest(location)) { 1956 if (HitTest(gfx::Rect(location, gfx::Size(0, 0)))) {
1946 ConvertPointToScreen(this, &location); 1957 ConvertPointToScreen(this, &location);
1947 ShowContextMenu(location, true); 1958 ShowContextMenu(location, true);
1948 } 1959 }
1949 } else { 1960 } else {
1950 OnMouseReleased(event); 1961 OnMouseReleased(event);
1951 } 1962 }
1952 // WARNING: we may have been deleted. 1963 // WARNING: we may have been deleted.
1953 } 1964 }
1954 1965
1955 ui::TouchStatus View::ProcessTouchEvent(const TouchEvent& event) { 1966 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()); 2117 gfx::Point widget_location(event.location());
2107 ConvertPointToWidget(this, &widget_location); 2118 ConvertPointToWidget(this, &widget_location);
2108 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations); 2119 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations);
2109 return true; 2120 return true;
2110 #else 2121 #else
2111 return false; 2122 return false;
2112 #endif // !defined(OS_MACOSX) 2123 #endif // !defined(OS_MACOSX)
2113 } 2124 }
2114 2125
2115 } // namespace views 2126 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698