[Cronet] Add support for Proxy Auto Config (PAC) script
[chromium-blink-merge.git] / ui / views / mouse_watcher_view_host.cc
blob54412cf10d5613531c6abcd1490d2301bc006b16
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.
5 #include "ui/views/mouse_watcher_view_host.h"
7 #include "ui/gfx/screen.h"
8 #include "ui/views/view.h"
9 #include "ui/views/widget/widget.h"
11 namespace views {
13 MouseWatcherViewHost::MouseWatcherViewHost(View* view,
14 const gfx::Insets& hot_zone_insets)
15 : view_(view),
16 hot_zone_insets_(hot_zone_insets) {
19 MouseWatcherViewHost::~MouseWatcherViewHost() {
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;
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());
43 return bounds.Contains(screen_point.x(), screen_point.y());
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;
52 return gfx::Screen::GetScreenFor(widget->GetNativeView())->
53 GetWindowUnderCursor() == widget->GetNativeWindow();
56 } // namespace views