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 "ash/wm/resize_handle_window_targeter.h"
7 #include "ash/ash_constants.h"
8 #include "ash/wm/immersive_fullscreen_controller.h"
9 #include "ash/wm/window_state.h"
10 #include "ui/aura/window.h"
11 #include "ui/events/event.h"
15 ResizeHandleWindowTargeter::ResizeHandleWindowTargeter(
17 ImmersiveFullscreenController
* controller
)
19 immersive_controller_(controller
) {
20 wm::WindowState
* window_state
= wm::GetWindowState(window_
);
21 OnPostWindowStateTypeChange(window_state
, wm::WINDOW_STATE_TYPE_DEFAULT
);
22 window_state
->AddObserver(this);
23 window_
->AddObserver(this);
26 ResizeHandleWindowTargeter::~ResizeHandleWindowTargeter() {
28 window_
->RemoveObserver(this);
29 wm::GetWindowState(window_
)->RemoveObserver(this);
33 void ResizeHandleWindowTargeter::OnPostWindowStateTypeChange(
34 wm::WindowState
* window_state
,
35 wm::WindowStateType old_type
) {
36 if (window_state
->IsMaximizedOrFullscreen()) {
37 frame_border_inset_
= gfx::Insets();
39 frame_border_inset_
= gfx::Insets(kResizeInsideBoundsSize
,
40 kResizeInsideBoundsSize
,
41 kResizeInsideBoundsSize
,
42 kResizeInsideBoundsSize
);
46 void ResizeHandleWindowTargeter::OnWindowDestroying(aura::Window
* window
) {
47 CHECK_EQ(window_
, window
);
48 wm::GetWindowState(window_
)->RemoveObserver(this);
52 aura::Window
* ResizeHandleWindowTargeter::FindTargetForLocatedEvent(
54 ui::LocatedEvent
* event
) {
55 if (window
== window_
) {
57 if (immersive_controller_
&& immersive_controller_
->IsEnabled() &&
58 !immersive_controller_
->IsRevealed() &&
59 event
->IsTouchEvent()) {
60 // If the window is in immersive fullscreen, and top-of-window views are
61 // not revealed, then touch events towards the top of the window
62 // should not reach the child window so that touch gestures can be used to
63 // reveal the top-of-windows views. This is needed because the child
64 // window may consume touch events and prevent touch-scroll gesture from
66 insets
= gfx::Insets(kImmersiveFullscreenTopEdgeInset
, 0, 0, 0);
68 // If the event falls very close to the inside of the frame border, then
69 // target the window itself, so that the window can be resized easily.
70 insets
= frame_border_inset_
;
73 if (!insets
.empty()) {
74 gfx::Rect bounds
= gfx::Rect(window_
->bounds().size());
76 if (!bounds
.Contains(event
->location()))
80 return aura::WindowTargeter::FindTargetForLocatedEvent(window
, event
);
83 bool ResizeHandleWindowTargeter::SubtreeShouldBeExploredForEvent(
85 const ui::LocatedEvent
& event
) {
86 if (window
== window_
) {
87 // Defer to the parent's targeter on whether |window_| should be able to
89 ui::EventTarget
* parent
=
90 static_cast<ui::EventTarget
*>(window
)->GetParentTarget();
92 aura::WindowTargeter
* targeter
=
93 static_cast<aura::WindowTargeter
*>(parent
->GetEventTargeter());
95 return targeter
->SubtreeShouldBeExploredForEvent(window
, event
);
98 return aura::WindowTargeter::SubtreeShouldBeExploredForEvent(window
, event
);