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/public/easy_resize_window_targeter.h"
7 #include "ui/aura/client/transient_window_client.h"
8 #include "ui/aura/window.h"
9 #include "ui/gfx/geometry/insets_f.h"
10 #include "ui/gfx/geometry/rect.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(
28 const ui::LocatedEvent& event) const {
29 if (ShouldUseExtendedBounds(window)) {
30 // Note that |event|'s location is in |window|'s parent's coordinate system,
31 // so convert it to |window|'s coordinate system first.
32 gfx::Point point = event.location();
34 aura::Window::ConvertPointToTarget(window->parent(), window, &point);
36 gfx::Rect bounds(window->bounds().size());
37 if (event.IsTouchEvent() || event.IsGestureEvent())
38 bounds.Inset(touch_extend_);
40 bounds.Inset(mouse_extend_);
42 return bounds.Contains(point);
44 return WindowTargeter::EventLocationInsideBounds(window, event);
47 bool EasyResizeWindowTargeter::ShouldUseExtendedBounds(
48 const aura::Window* window) const {
49 // Use the extended bounds only for immediate child windows of |container_|.
50 // Use the default targetter otherwise.
51 if (window->parent() != container_)
54 aura::client::TransientWindowClient* transient_window_client =
55 aura::client::GetTransientWindowClient();
56 return !transient_window_client ||
57 !transient_window_client->GetTransientParent(window) ||
58 transient_window_client->GetTransientParent(window) == container_;