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

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

Issue 9309110: Refactored MouseWatcher to allow regions other than Views to (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor cleanup Created 8 years, 10 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 (c) 2011 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/mouse_watcher_view_host.h"
6
7 #include "ui/gfx/screen.h"
8 #include "ui/views/view.h"
9 #include "ui/views/widget/widget.h"
10
11 namespace views {
12
13 MouseWatcherViewHost::MouseWatcherViewHost(View* view,
14 const gfx::Insets& hot_zone_insets)
15 : view_(view),
16 hot_zone_insets_(hot_zone_insets) {
17 }
18
19 MouseWatcherViewHost::~MouseWatcherViewHost() {
20 }
21
22 bool MouseWatcherViewHost::Contains(
23 const gfx::Point& screen_point, MouseEventType type) {
sky 2012/02/06 16:03:34 nit: each param on its own line.
DaveMoore 2012/02/06 17:10:16 Done.
24 bool in_view = IsCursorInViewZone(screen_point);
25 if (!in_view || (type == MOUSE_EXITED && !IsMouseOverWindow()))
26 return false;
27 return true;
28 }
29
30 // Returns whether or not the cursor is currently in the view's "zone" which
31 // is defined as a slightly larger region than the view.
32 bool MouseWatcherViewHost::IsCursorInViewZone(const gfx::Point& screen_point) {
33 gfx::Rect bounds = view_->GetLocalBounds();
34 gfx::Point view_topleft(bounds.origin());
35 View::ConvertPointToScreen(view_, &view_topleft);
36 bounds.set_origin(view_topleft);
37 bounds.SetRect(view_topleft.x() - hot_zone_insets_.left(),
38 view_topleft.y() - hot_zone_insets_.top(),
39 bounds.width() + hot_zone_insets_.width(),
40 bounds.height() + hot_zone_insets_.height());
41
42 return bounds.Contains(screen_point.x(), screen_point.y());
43 }
44
45 // Returns true if the mouse is over the view's window.
46 bool MouseWatcherViewHost::IsMouseOverWindow() {
47 Widget* widget = view_->GetWidget();
48 if (!widget)
49 return false;
50
51 return gfx::Screen::GetWindowAtCursorScreenPoint() ==
52 widget->GetNativeWindow();
53 }
54
55 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698