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.
5 #include "ui/wm/core/easy_resize_window_targeter.h"
7 #include "ui/aura/window.h"
8 #include "ui/gfx/geometry/insets_f.h"
9 #include "ui/gfx/geometry/rect.h"
10 #include "ui/wm/public/transient_window_client.h"
14 EasyResizeWindowTargeter::EasyResizeWindowTargeter(
15 aura::Window* container,
16 const gfx::Insets& mouse_extend,
17 const gfx::Insets& touch_extend)
18 : container_(container),
19 mouse_extend_(mouse_extend),
20 touch_extend_(touch_extend) {
23 EasyResizeWindowTargeter::~EasyResizeWindowTargeter() {
26 bool EasyResizeWindowTargeter::EventLocationInsideBounds(
27 ui::EventTarget* target,
28 const ui::LocatedEvent& event) const {
29 aura::Window* window = static_cast<aura::Window*>(target);
30 if (ShouldUseExtendedBounds(window)) {
31 // Note that |event|'s location is in |window|'s parent's coordinate system,
32 // so convert it to |window|'s coordinate system first.
33 gfx::Point point = event.location();
35 aura::Window::ConvertPointToTarget(window->parent(), window, &point);
37 gfx::Rect bounds(window->bounds().size());
38 if (event.IsTouchEvent() || event.IsGestureEvent())
39 bounds.Inset(touch_extend_);
41 bounds.Inset(mouse_extend_);
43 return bounds.Contains(point);
45 return WindowTargeter::EventLocationInsideBounds(window, event);
48 bool EasyResizeWindowTargeter::ShouldUseExtendedBounds(
49 const aura::Window* window) const {
50 // Use the extended bounds only for immediate child windows of |container_|.
51 // Use the default targetter otherwise.
52 if (window->parent() != container_)
55 aura::client::TransientWindowClient* transient_window_client =
56 aura::client::GetTransientWindowClient();
57 return !transient_window_client ||
58 !transient_window_client->GetTransientParent(window) ||
59 transient_window_client->GetTransientParent(window) == container_;