OLD | NEW |
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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
6 | 6 |
7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 return HitTestRect(gfx::Rect(point, gfx::Size(1, 1))); | 947 return HitTestRect(gfx::Rect(point, gfx::Size(1, 1))); |
948 } | 948 } |
949 | 949 |
950 bool View::HitTestRect(const gfx::Rect& rect) const { | 950 bool View::HitTestRect(const gfx::Rect& rect) const { |
951 // If no ViewTargeter is installed on |this|, use the ViewTargeter installed | 951 // If no ViewTargeter is installed on |this|, use the ViewTargeter installed |
952 // on our root view instead. | 952 // on our root view instead. |
953 ViewTargeter* view_targeter = targeter(); | 953 ViewTargeter* view_targeter = targeter(); |
954 if (!view_targeter) | 954 if (!view_targeter) |
955 view_targeter = GetWidget()->GetRootView()->targeter(); | 955 view_targeter = GetWidget()->GetRootView()->targeter(); |
956 CHECK(view_targeter); | 956 CHECK(view_targeter); |
957 | 957 return view_targeter->DoesIntersectRect(this, rect); |
958 // TODO(tdanderson): The check for !HasHitTestMask() is temporary. Remove | |
959 // the check along with the duplicated code below once all | |
960 // of the masked views subclass MaskedViewDelegate. | |
961 // HasHitTestMask() and GetHitTestMaskDeprecated() can also | |
962 // be removed from the View interface at that time. | |
963 if (!HasHitTestMask()) | |
964 return view_targeter->DoesIntersectRect(this, rect); | |
965 | |
966 if (GetLocalBounds().Intersects(rect)) { | |
967 gfx::Path mask; | |
968 HitTestSource source = HIT_TEST_SOURCE_MOUSE; | |
969 if (!views::UsePointBasedTargeting(rect)) | |
970 source = HIT_TEST_SOURCE_TOUCH; | |
971 GetHitTestMaskDeprecated(source, &mask); | |
972 SkRegion clip_region; | |
973 clip_region.setRect(0, 0, width(), height()); | |
974 SkRegion mask_region; | |
975 return mask_region.setPath(mask, clip_region) && | |
976 mask_region.intersects(RectToSkIRect(rect)); | |
977 } | |
978 // Outside our bounds. | |
979 return false; | |
980 } | 958 } |
981 | 959 |
982 bool View::IsMouseHovered() { | 960 bool View::IsMouseHovered() { |
983 // If we haven't yet been placed in an onscreen view hierarchy, we can't be | 961 // If we haven't yet been placed in an onscreen view hierarchy, we can't be |
984 // hovered. | 962 // hovered. |
985 if (!GetWidget()) | 963 if (!GetWidget()) |
986 return false; | 964 return false; |
987 | 965 |
988 // If mouse events are disabled, then the mouse cursor is invisible and | 966 // If mouse events are disabled, then the mouse cursor is invisible and |
989 // is therefore not hovering over this button. | 967 // is therefore not hovering over this button. |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1585 // the front. | 1563 // the front. |
1586 for (Views::reverse_iterator it(children_.rbegin()); | 1564 for (Views::reverse_iterator it(children_.rbegin()); |
1587 it != children_.rend(); ++it) { | 1565 it != children_.rend(); ++it) { |
1588 (*it)->ReorderChildLayers(parent_layer); | 1566 (*it)->ReorderChildLayers(parent_layer); |
1589 } | 1567 } |
1590 } | 1568 } |
1591 } | 1569 } |
1592 | 1570 |
1593 // Input ----------------------------------------------------------------------- | 1571 // Input ----------------------------------------------------------------------- |
1594 | 1572 |
1595 bool View::HasHitTestMask() const { | |
1596 return false; | |
1597 } | |
1598 | |
1599 void View::GetHitTestMaskDeprecated(HitTestSource source, | |
1600 gfx::Path* mask) const { | |
1601 DCHECK(mask); | |
1602 } | |
1603 | |
1604 View::DragInfo* View::GetDragInfo() { | 1573 View::DragInfo* View::GetDragInfo() { |
1605 return parent_ ? parent_->GetDragInfo() : NULL; | 1574 return parent_ ? parent_->GetDragInfo() : NULL; |
1606 } | 1575 } |
1607 | 1576 |
1608 // Focus ----------------------------------------------------------------------- | 1577 // Focus ----------------------------------------------------------------------- |
1609 | 1578 |
1610 void View::OnFocus() { | 1579 void View::OnFocus() { |
1611 // TODO(beng): Investigate whether it's possible for us to move this to | 1580 // TODO(beng): Investigate whether it's possible for us to move this to |
1612 // Focus(). | 1581 // Focus(). |
1613 // By default, we clear the native focus. This ensures that no visible native | 1582 // By default, we clear the native focus. This ensures that no visible native |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2506 // Message the RootView to do the drag and drop. That way if we're removed | 2475 // Message the RootView to do the drag and drop. That way if we're removed |
2507 // the RootView can detect it and avoid calling us back. | 2476 // the RootView can detect it and avoid calling us back. |
2508 gfx::Point widget_location(event.location()); | 2477 gfx::Point widget_location(event.location()); |
2509 ConvertPointToWidget(this, &widget_location); | 2478 ConvertPointToWidget(this, &widget_location); |
2510 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2479 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2511 // WARNING: we may have been deleted. | 2480 // WARNING: we may have been deleted. |
2512 return true; | 2481 return true; |
2513 } | 2482 } |
2514 | 2483 |
2515 } // namespace views | 2484 } // namespace views |
OLD | NEW |