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/core/easy_resize_window_targeter.h"
6 
7 #include <algorithm>
8 
9 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/client/transient_window_client.h"
11 #include "ui/aura/window.h"
12 #include "ui/events/event.h"
13 #include "ui/gfx/geometry/insets.h"
14 
15 namespace wm {
16 
EasyResizeWindowTargeter(const gfx::Insets & mouse_extend,const gfx::Insets & touch_extend)17 EasyResizeWindowTargeter::EasyResizeWindowTargeter(
18     const gfx::Insets& mouse_extend,
19     const gfx::Insets& touch_extend) {
20   SetInsets(mouse_extend, touch_extend);
21 }
22 
~EasyResizeWindowTargeter()23 EasyResizeWindowTargeter::~EasyResizeWindowTargeter() {}
24 
EventLocationInsideBounds(aura::Window * target,const ui::LocatedEvent & event) const25 bool EasyResizeWindowTargeter::EventLocationInsideBounds(
26     aura::Window* target,
27     const ui::LocatedEvent& event) const {
28   return WindowTargeter::EventLocationInsideBounds(target, event);
29 }
30 
ShouldUseExtendedBounds(const aura::Window * w) const31 bool EasyResizeWindowTargeter::ShouldUseExtendedBounds(
32     const aura::Window* w) const {
33   DCHECK(window());
34   // Use the extended bounds only for immediate child windows of window().
35   // Use the default targeter otherwise.
36   if (w->parent() != window())
37     return false;
38 
39   // Only resizable windows benefit from the extended hit-test region.
40   if ((w->GetProperty(aura::client::kResizeBehaviorKey) &
41        aura::client::kResizeBehaviorCanResize) == 0) {
42     return false;
43   }
44 
45   // For transient children use extended bounds if a transient parent or if
46   // transient parent's parent is a top level window in window().
47   aura::client::TransientWindowClient* transient_window_client =
48       aura::client::GetTransientWindowClient();
49   const aura::Window* transient_parent =
50       transient_window_client ? transient_window_client->GetTransientParent(w)
51                               : nullptr;
52   return !transient_parent || transient_parent == window() ||
53          transient_parent->parent() == window();
54 }
55 
56 }  // namespace wm
57