1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/resize_handle_window_targeter.h"
#include "ash/ash_constants.h"
#include "ash/wm/immersive_fullscreen_controller.h"
#include "ash/wm/window_state.h"
#include "ui/aura/window.h"
namespace ash {
ResizeHandleWindowTargeter::ResizeHandleWindowTargeter(
aura::Window* window,
ImmersiveFullscreenController* controller)
: window_(window),
immersive_controller_(controller) {
wm::WindowState* window_state = wm::GetWindowState(window_);
OnPostWindowStateTypeChange(window_state, wm::WINDOW_STATE_TYPE_DEFAULT);
window_state->AddObserver(this);
window_->AddObserver(this);
}
ResizeHandleWindowTargeter::~ResizeHandleWindowTargeter() {
if (window_) {
window_->RemoveObserver(this);
wm::GetWindowState(window_)->RemoveObserver(this);
}
}
void ResizeHandleWindowTargeter::OnPostWindowStateTypeChange(
wm::WindowState* window_state,
wm::WindowStateType old_type) {
if (window_state->IsMaximizedOrFullscreen()) {
frame_border_inset_ = gfx::Insets();
} else {
frame_border_inset_ = gfx::Insets(kResizeInsideBoundsSize,
kResizeInsideBoundsSize,
kResizeInsideBoundsSize,
kResizeInsideBoundsSize);
}
}
void ResizeHandleWindowTargeter::OnWindowDestroying(aura::Window* window) {
CHECK_EQ(window_, window);
wm::GetWindowState(window_)->RemoveObserver(this);
window_ = NULL;
}
ui::EventTarget* ResizeHandleWindowTargeter::FindTargetForLocatedEvent(
ui::EventTarget* root,
ui::LocatedEvent* event) {
aura::Window* window = static_cast<aura::Window*>(root);
if (window == window_) {
gfx::Insets insets;
if (immersive_controller_ && immersive_controller_->IsEnabled() &&
!immersive_controller_->IsRevealed() &&
event->IsTouchEvent()) {
// If the window is in immersive fullscreen, and top-of-window views are
// not revealed, then touch events towards the top of the window
// should not reach the child window so that touch gestures can be used to
// reveal the top-of-windows views. This is needed because the child
// window may consume touch events and prevent touch-scroll gesture from
// being generated.
insets = gfx::Insets(kImmersiveFullscreenTopEdgeInset, 0, 0, 0);
} else {
// If the event falls very close to the inside of the frame border, then
// target the window itself, so that the window can be resized easily.
insets = frame_border_inset_;
}
if (!insets.empty()) {
gfx::Rect bounds = gfx::Rect(window_->bounds().size());
bounds.Inset(insets);
if (!bounds.Contains(event->location()))
return window_;
}
}
return aura::WindowTargeter::FindTargetForLocatedEvent(root, event);
}
bool ResizeHandleWindowTargeter::SubtreeShouldBeExploredForEvent(
ui::EventTarget* target,
const ui::LocatedEvent& event) {
if (target == window_) {
// Defer to the parent's targeter on whether |window_| should be able to
// receive the event.
ui::EventTarget* parent = target->GetParentTarget();
if (parent) {
ui::EventTargeter* targeter = parent->GetEventTargeter();
if (targeter)
return targeter->SubtreeShouldBeExploredForEvent(target, event);
}
}
return aura::WindowTargeter::SubtreeShouldBeExploredForEvent(target, event);
}
} // namespace ash
|