forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ViewTargeterDelegate and MaskedTargeterDelegate
These two classes define the default hit-testing behaviour for views with and without hit-test masks. Views wishing to define their own hit-testing behaviour will extend one of these classes. BUG=388838 TEST=ViewTargeterTest.DoesIntersectRect Review URL: https://codereview.chromium.org/336953005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280713 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
tdanderson@chromium.org
committed
Jul 1, 2014
1 parent
f0f8e08
commit 8a6d7ef
Showing
14 changed files
with
246 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ui/views/masked_targeter_delegate.h" | ||
|
||
#include "ui/gfx/path.h" | ||
#include "ui/gfx/skia_util.h" | ||
#include "ui/views/view.h" | ||
|
||
namespace views { | ||
|
||
bool MaskedTargeterDelegate::DoesIntersectRect(const View* target, | ||
const gfx::Rect& rect) const { | ||
// Early return if |rect| does not even intersect the rectangular bounds | ||
// of |target|. | ||
if (!ViewTargeterDelegate::DoesIntersectRect(target, rect)) | ||
return false; | ||
|
||
// Early return if |mask| is not a valid hit test mask. | ||
gfx::Path mask; | ||
if (!GetHitTestMask(&mask)) | ||
return false; | ||
|
||
// Return whether or not |rect| intersects the custom hit test mask | ||
// of |target|. | ||
SkRegion clip_region; | ||
clip_region.setRect(0, 0, target->width(), target->height()); | ||
SkRegion mask_region; | ||
return mask_region.setPath(mask, clip_region) && | ||
mask_region.intersects(RectToSkIRect(rect)); | ||
} | ||
|
||
} // namespace views |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef UI_VIEWS_MASKED_TARGETER_DELEGATE_H_ | ||
#define UI_VIEWS_MASKED_TARGETER_DELEGATE_H_ | ||
|
||
#include "ui/base/ui_base_types.h" | ||
#include "ui/views/view_targeter_delegate.h" | ||
#include "ui/views/views_export.h" | ||
|
||
namespace gfx { | ||
class Path; | ||
class Rect; | ||
} | ||
|
||
namespace views { | ||
class View; | ||
|
||
// Defines the default behaviour for hit-testing a rectangular region against | ||
// the bounds of a View having a custom-shaped hit test mask. Views define | ||
// such a mask by extending this class. | ||
class VIEWS_EXPORT MaskedTargeterDelegate : public ViewTargeterDelegate { | ||
public: | ||
MaskedTargeterDelegate() {} | ||
virtual ~MaskedTargeterDelegate() {} | ||
|
||
// Sets the hit-test mask for the view which implements this interface, | ||
// in that view's local coordinate space. Returns whether a valid mask | ||
// has been set in |mask|. | ||
virtual bool GetHitTestMask(gfx::Path* mask) const = 0; | ||
|
||
// ViewTargeterDelegate: | ||
virtual bool DoesIntersectRect(const View* target, | ||
const gfx::Rect& rect) const OVERRIDE; | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(MaskedTargeterDelegate); | ||
}; | ||
|
||
} // namespace views | ||
|
||
#endif // UI_VIEWS_MASKED_TARGETER_DELEGATE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ui/views/view.h" | ||
#include "ui/views/view_targeter_delegate.h" | ||
|
||
namespace views { | ||
|
||
bool ViewTargeterDelegate::DoesIntersectRect(const View* target, | ||
const gfx::Rect& rect) const { | ||
return target->GetLocalBounds().Intersects(rect); | ||
} | ||
|
||
} // namespace views |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef UI_VIEWS_VIEW_TARGETER_DELEGATE_H_ | ||
#define UI_VIEWS_VIEW_TARGETER_DELEGATE_H_ | ||
|
||
#include "base/macros.h" | ||
#include "ui/views/views_export.h" | ||
|
||
namespace gfx { | ||
class Rect; | ||
} | ||
|
||
namespace views { | ||
class View; | ||
|
||
// Defines the default behaviour for hit-testing a rectangular region against | ||
// the bounds of a View. Subclasses of View wishing to define custom | ||
// hit-testing behaviour can extend this class. | ||
class VIEWS_EXPORT ViewTargeterDelegate { | ||
public: | ||
ViewTargeterDelegate() {} | ||
virtual ~ViewTargeterDelegate() {} | ||
|
||
// Returns true if the bounds of |target| intersects |rect|, where |rect| | ||
// is in the local coodinate space of |target|. Overrides of this method by | ||
// a View subclass should enforce DCHECK_EQ(this, target). | ||
virtual bool DoesIntersectRect(const View* target, | ||
const gfx::Rect& rect) const; | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(ViewTargeterDelegate); | ||
}; | ||
|
||
} // namespace views | ||
|
||
#endif // UI_VIEWS_VIEW_TARGETER_DELEGATE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.