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

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

Issue 851853002: It is time. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Trying to reup because the last upload failed. Created 5 years, 11 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
« no previous file with comments | « ui/views/mouse_watcher_view_host.h ('k') | ui/views/native_cursor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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,
24 MouseEventType type) {
25 bool in_view = IsCursorInViewZone(screen_point);
26 if (!in_view || (type == MOUSE_EXIT && !IsMouseOverWindow()))
27 return false;
28 return true;
29 }
30
31 // Returns whether or not the cursor is currently in the view's "zone" which
32 // is defined as a slightly larger region than the view.
33 bool MouseWatcherViewHost::IsCursorInViewZone(const gfx::Point& screen_point) {
34 gfx::Rect bounds = view_->GetLocalBounds();
35 gfx::Point view_topleft(bounds.origin());
36 View::ConvertPointToScreen(view_, &view_topleft);
37 bounds.set_origin(view_topleft);
38 bounds.SetRect(view_topleft.x() - hot_zone_insets_.left(),
39 view_topleft.y() - hot_zone_insets_.top(),
40 bounds.width() + hot_zone_insets_.width(),
41 bounds.height() + hot_zone_insets_.height());
42
43 return bounds.Contains(screen_point.x(), screen_point.y());
44 }
45
46 // Returns true if the mouse is over the view's window.
47 bool MouseWatcherViewHost::IsMouseOverWindow() {
48 Widget* widget = view_->GetWidget();
49 if (!widget)
50 return false;
51
52 return gfx::Screen::GetScreenFor(widget->GetNativeView())->
53 GetWindowUnderCursor() == widget->GetNativeWindow();
54 }
55
56 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mouse_watcher_view_host.h ('k') | ui/views/native_cursor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698