5b48c81351d01d7ec6cdc3b5463584548e41c60a
[platform/framework/web/crosswalk.git] / src / ui / wm / core / easy_resize_window_targeter.cc
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.
4
5 #include "ui/wm/public/easy_resize_window_targeter.h"
6
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"
11
12 namespace wm {
13
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) {
21 }
22
23 EasyResizeWindowTargeter::~EasyResizeWindowTargeter() {
24 }
25
26 bool EasyResizeWindowTargeter::EventLocationInsideBounds(
27     aura::Window* window,
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();
33     if (window->parent())
34       aura::Window::ConvertPointToTarget(window->parent(), window, &point);
35
36     gfx::Rect bounds(window->bounds().size());
37     if (event.IsTouchEvent() || event.IsGestureEvent())
38       bounds.Inset(touch_extend_);
39     else
40       bounds.Inset(mouse_extend_);
41
42     return bounds.Contains(point);
43   }
44   return WindowTargeter::EventLocationInsideBounds(window, event);
45 }
46
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_)
52     return false;
53
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_;
59 }
60
61 }  // namespace wm