diff options
author | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-07 13:36:31 +0000 |
---|---|---|
committer | sadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-07 13:36:31 +0000 |
commit | f562a36006fc9e1c74c18c5c13fa594d93fadffd (patch) | |
tree | 5d4a5f0da3f3f47ddb52b361e9c072554e3bd455 /ui/wm | |
parent | c5be8d67a355904dd9e9904b5f5943283a8dfe4f (diff) | |
download | chromium_src-f562a36006fc9e1c74c18c5c13fa594d93fadffd.zip chromium_src-f562a36006fc9e1c74c18c5c13fa594d93fadffd.tar.gz chromium_src-f562a36006fc9e1c74c18c5c13fa594d93fadffd.tar.bz2 |
aura: Add a window-targeter for windows with hit-test masks.
Use the masked-window targeter for the touch-selection handlers. Subsequent
patches will install similar targeters for the other windows that use hit-test
masks, which will allow getting rid of some hit-test mask related API from aura
and views.
BUG=318879
R=ben@chromium.org
Review URL: https://codereview.chromium.org/122573005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243287 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/wm')
-rw-r--r-- | ui/wm/core/masked_window_targeter.cc | 41 | ||||
-rw-r--r-- | ui/wm/public/masked_window_targeter.h | 38 | ||||
-rw-r--r-- | ui/wm/wm.gyp | 2 |
3 files changed, 81 insertions, 0 deletions
diff --git a/ui/wm/core/masked_window_targeter.cc b/ui/wm/core/masked_window_targeter.cc new file mode 100644 index 0000000..3de6140 --- /dev/null +++ b/ui/wm/core/masked_window_targeter.cc @@ -0,0 +1,41 @@ +// 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/wm/public/masked_window_targeter.h" + +#include "ui/aura/window.h" +#include "ui/gfx/path.h" + +namespace wm { + +MaskedWindowTargeter::MaskedWindowTargeter(aura::Window* masked_window) + : masked_window_(masked_window) { +} + +MaskedWindowTargeter::~MaskedWindowTargeter() {} + +bool MaskedWindowTargeter::EventLocationInsideBounds( + aura::Window* window, + const ui::LocatedEvent& event) const { + if (window == masked_window_) { + gfx::Path mask; + GetHitTestMask(window, &mask); + + gfx::Size size = window->bounds().size(); + SkRegion clip_region; + clip_region.setRect(0, 0, size.width(), size.height()); + + gfx::Point point = event.location(); + if (window->parent()) + aura::Window::ConvertPointToTarget(window->parent(), window, &point); + + SkRegion mask_region; + return mask_region.setPath(mask, clip_region) && + mask_region.contains(point.x(), point.y()); + } + + return WindowTargeter::EventLocationInsideBounds(window, event); +} + +} // namespace wm diff --git a/ui/wm/public/masked_window_targeter.h b/ui/wm/public/masked_window_targeter.h new file mode 100644 index 0000000..c5b4d88 --- /dev/null +++ b/ui/wm/public/masked_window_targeter.h @@ -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_WM_PUBLIC_MASKED_WINDOW_TARGETER_H_ +#define UI_WM_PUBLIC_MASKED_WINDOW_TARGETER_H_ + +#include "ui/aura/window_targeter.h" + +namespace gfx { +class Path; +} + +namespace wm { + +class MaskedWindowTargeter : public aura::WindowTargeter { + public: + explicit MaskedWindowTargeter(aura::Window* masked_window); + virtual ~MaskedWindowTargeter(); + + protected: + // Sets the hit-test mask for |window| in |mask| (in |window|'s local + // coordinate system). + virtual void GetHitTestMask(aura::Window* window, gfx::Path* mask) const = 0; + + // aura::WindowTargeter: + virtual bool EventLocationInsideBounds( + aura::Window* window, + const ui::LocatedEvent& event) const OVERRIDE; + + aura::Window* masked_window_; + + DISALLOW_COPY_AND_ASSIGN(MaskedWindowTargeter); +}; + +} // namespace wm + +#endif // UI_WM_PUBLIC_MASKED_WINDOW_TARGETER_H_ diff --git a/ui/wm/wm.gyp b/ui/wm/wm.gyp index 725d9ea..6071fac 100644 --- a/ui/wm/wm.gyp +++ b/ui/wm/wm.gyp @@ -17,7 +17,9 @@ ], 'sources': [ 'core/easy_resize_window_targeter.cc', + 'core/masked_window_targeter.cc', 'public/easy_resize_window_targeter.h', + 'public/masked_window_targeter.h', 'public/window_types.h', ], }, |