summaryrefslogtreecommitdiffstats
path: root/chrome/views/view.cc
diff options
context:
space:
mode:
authorbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-16 00:37:56 +0000
committerbeng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-09-16 00:37:56 +0000
commit82739cfe200335e53c66b36e6b467c32294f7ef0 (patch)
tree32436525bb71a6ac93124da4e1dcc4b8c0bc48ed /chrome/views/view.cc
parent0ae7d14ea97bdb4170948521144de57059eb4eeb (diff)
downloadchromium_src-82739cfe200335e53c66b36e6b467c32294f7ef0.zip
chromium_src-82739cfe200335e53c66b36e6b467c32294f7ef0.tar.gz
chromium_src-82739cfe200335e53c66b36e6b467c32294f7ef0.tar.bz2
Allow Views to support an optional hit-test mask. Make hittest use this.
Make GetViewForPoint call HitTest instead of rolling its own crude hit testing. Update custom-shaped views to use this framework instead of overriding hittest themselves. B=2273 Review URL: http://codereview.chromium.org/3051 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2255 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views/view.cc')
-rw-r--r--chrome/views/view.cc41
1 files changed, 27 insertions, 14 deletions
diff --git a/chrome/views/view.cc b/chrome/views/view.cc
index 45543cc..18dfd65 100644
--- a/chrome/views/view.cc
+++ b/chrome/views/view.cc
@@ -12,9 +12,11 @@
#include "base/logging.h"
#include "base/message_loop.h"
+#include "base/scoped_handle.h"
#include "base/string_util.h"
#include "chrome/common/drag_drop_types.h"
#include "chrome/common/gfx/chrome_canvas.h"
+#include "chrome/common/gfx/path.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/os_exchange_data.h"
#include "chrome/views/accessibility/accessible_wrapper.h"
@@ -712,6 +714,14 @@ bool View::IsProcessingPaint() const {
}
#endif
+bool View::HasHitTestMask() const {
+ return false;
+}
+
+void View::GetHitTestMask(gfx::Path* mask) const {
+ DCHECK(mask);
+}
+
void View::ViewHierarchyChanged(bool is_add, View *parent, View *child) {
}
@@ -768,16 +778,13 @@ View* View::GetViewForPoint(const CPoint& point, bool can_create_floating) {
// tightly encloses the specified point.
for (int i = GetChildViewCount() - 1 ; i >= 0 ; --i) {
View* child = GetChildViewAt(i);
- if (!child->IsVisible()) {
+ if (!child->IsVisible())
continue;
- }
- CRect bounds;
- child->GetBounds(&bounds, APPLY_MIRRORING_TRANSFORMATION);
- if (bounds.PtInRect(point)) {
- CPoint cl(point);
- cl.Offset(-bounds.left, -bounds.top);
- return child->GetViewForPoint(cl, true);
- }
+
+ CPoint point_in_child_coords(point);
+ View::ConvertPointToView(this, child, &point_in_child_coords);
+ if (child->HitTest(point_in_child_coords))
+ return child->GetViewForPoint(point_in_child_coords, true);
}
// We haven't found a view for the point. Try to create floating views
@@ -1437,13 +1444,19 @@ bool View::IsVisibleInRootView() const {
return false;
}
-bool View::HitTest(const CPoint &l) const {
- if (l.x >= 0 && l.x < static_cast<int>(GetWidth()) &&
- l.y >= 0 && l.y < static_cast<int>(GetHeight())) {
+bool View::HitTest(const CPoint& l) const {
+ if (l.x >= 0 && l.x < GetWidth() && l.y >= 0 && l.y < GetHeight()) {
+ if (HasHitTestMask()) {
+ gfx::Path mask;
+ GetHitTestMask(&mask);
+ ScopedHRGN rgn(mask.CreateHRGN());
+ return !!PtInRegion(rgn, l.x, l.y);
+ }
+ // No mask, but inside our bounds.
return true;
- } else {
- return false;
}
+ // Outside our bounds.
+ return false;
}
HCURSOR View::GetCursorForPoint(Event::EventType event_type, int x, int y) {