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

Unified 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: quick nit Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/masked_view_targeter.h ('k') | ui/views/view_targeter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/masked_view_targeter.cc
diff --git a/ui/views/masked_view_targeter.cc b/ui/views/masked_view_targeter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..112df676808c4d2759388657c6f484fc71fe53bf
--- /dev/null
+++ b/ui/views/masked_view_targeter.cc
@@ -0,0 +1,46 @@
+// 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_view_targeter.h"
+
+#include "ui/gfx/path.h"
+#include "ui/gfx/skia_util.h"
+#include "ui/views/view.h"
+
+namespace views {
+
+MaskedViewTargeter::MaskedViewTargeter(View* masked_view)
+ : masked_view_(masked_view) {
+}
+
+MaskedViewTargeter::~MaskedViewTargeter() {
+}
+
+bool MaskedViewTargeter::EventLocationInsideBounds(
+ ui::EventTarget* target,
+ const ui::LocatedEvent& event) const {
+ View* view = static_cast<View*>(target);
+ if (view == masked_view_) {
+ gfx::Path mask;
+ if (!GetHitTestMask(view, &mask))
+ return ViewTargeter::EventLocationInsideBounds(view, event);
+
+ gfx::Size size = view->bounds().size();
+ SkRegion clip_region;
+ clip_region.setRect(0, 0, size.width(), size.height());
+
+ gfx::RectF bounds_f = ViewTargeter::BoundsForEvent(event);
+ if (view->parent())
+ View::ConvertRectToTarget(view->parent(), view, &bounds_f);
+ gfx::Rect bounds = gfx::ToEnclosingRect(bounds_f);
+
+ SkRegion mask_region;
+ return mask_region.setPath(mask, clip_region) &&
+ mask_region.intersects(RectToSkIRect(bounds));
+ }
+
+ return ViewTargeter::EventLocationInsideBounds(view, event);
+}
+
+} // namespace views
« no previous file with comments | « ui/views/masked_view_targeter.h ('k') | ui/views/view_targeter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698