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

Side by Side Diff: ui/views/masked_view_targeter.cc

Issue 286933014: Introduce the MaskedViewTargeter class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/views/masked_view_targeter.h"
6
7 #include "ui/gfx/path.h"
8 #include "ui/gfx/skia_util.h"
9 #include "ui/views/view.h"
10
11 namespace views {
12
13 MaskedViewTargeter::MaskedViewTargeter(View* masked_view)
14 : masked_view_(masked_view) {
15 }
16
17 MaskedViewTargeter::~MaskedViewTargeter() {}
18
19 bool MaskedViewTargeter::EventLocationInsideBounds(
20 ui::EventTarget* target,
21 const ui::LocatedEvent& event) const {
22 View* view = static_cast<View*>(target);
23 if (view == masked_view_) {
24 gfx::Path mask;
25 if (!GetHitTestMask(view, &mask))
26 return ViewTargeter::EventLocationInsideBounds(view, event);
27
28 gfx::Size size = view->bounds().size();
29 SkRegion clip_region;
30 clip_region.setRect(0, 0, size.width(), size.height());
31
32 gfx::RectF bounds_f = ViewTargeter::BoundsForEvent(event);
33 if (view->parent())
34 View::ConvertRectToTarget(view->parent(), view, &bounds_f);
35 gfx::Rect bounds = gfx::ToEnclosingRect(bounds_f);
36
37 SkRegion mask_region;
38 return mask_region.setPath(mask, clip_region) &&
39 mask_region.intersects(RectToSkIRect(bounds));
40 }
41
42 return ViewTargeter::EventLocationInsideBounds(view, event);
43 }
44
45 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698