cc: Initialize wait_for_beginframe_interval in tests.
[chromium-blink-merge.git] / ash / wm / resize_handle_window_targeter.cc
blob8ee6924cd31bf5afbe2cad074fcf80ad5f949301
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"
13 namespace ash {
15 ResizeHandleWindowTargeter::ResizeHandleWindowTargeter(
16 aura::Window* window,
17 ImmersiveFullscreenController* controller)
18 : window_(window),
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() {
27 if (window_) {
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();
38 } else {
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);
49 window_ = NULL;
52 aura::Window* ResizeHandleWindowTargeter::FindTargetForLocatedEvent(
53 aura::Window* window,
54 ui::LocatedEvent* event) {
55 if (window == window_) {
56 gfx::Insets insets;
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
65 // being generated.
66 insets = gfx::Insets(kImmersiveFullscreenTopEdgeInset, 0, 0, 0);
67 } else {
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());
75 bounds.Inset(insets);
76 if (!bounds.Contains(event->location()))
77 return window_;
80 return aura::WindowTargeter::FindTargetForLocatedEvent(window, event);
83 bool ResizeHandleWindowTargeter::SubtreeShouldBeExploredForEvent(
84 aura::Window* window,
85 const ui::LocatedEvent& event) {
86 if (window == window_) {
87 // Defer to the parent's targeter on whether |window_| should be able to
88 // receive the event.
89 ui::EventTarget* parent =
90 static_cast<ui::EventTarget*>(window)->GetParentTarget();
91 if (parent) {
92 aura::WindowTargeter* targeter =
93 static_cast<aura::WindowTargeter*>(parent->GetEventTargeter());
94 if (targeter)
95 return targeter->SubtreeShouldBeExploredForEvent(window, event);
98 return aura::WindowTargeter::SubtreeShouldBeExploredForEvent(window, event);
101 } // namespace ash