1 // Copyright 2013 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/shelf/shelf_bezel_event_filter.h"
7 #include "ash/shelf/shelf_layout_manager.h"
9 #include "ash/wm/coordinate_conversion.h"
10 #include "ui/aura/window.h"
14 ShelfBezelEventFilter::ShelfBezelEventFilter(
15 ShelfLayoutManager* shelf)
17 in_touch_drag_(false) {
18 Shell::GetInstance()->AddPreTargetHandler(this);
21 ShelfBezelEventFilter::~ShelfBezelEventFilter() {
22 Shell::GetInstance()->RemovePreTargetHandler(this);
25 void ShelfBezelEventFilter::OnGestureEvent(
26 ui::GestureEvent* event) {
27 gfx::Point point_in_screen(event->location());
28 aura::Window* target = static_cast<aura::Window*>(event->target());
29 wm::ConvertPointToScreen(target, &point_in_screen);
31 Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen).bounds();
32 if ((!screen.Contains(point_in_screen) &&
33 IsShelfOnBezel(screen, point_in_screen)) ||
35 if (gesture_handler_.ProcessGestureEvent(*event)) {
36 switch (event->type()) {
37 case ui::ET_GESTURE_SCROLL_BEGIN:
38 in_touch_drag_ = true;
40 case ui::ET_GESTURE_SCROLL_END:
41 case ui::ET_SCROLL_FLING_START:
42 in_touch_drag_ = false;
47 event->StopPropagation();
52 bool ShelfBezelEventFilter::IsShelfOnBezel(
53 const gfx::Rect& screen,
54 const gfx::Point& point) const{
55 switch (shelf_->GetAlignment()) {
56 case SHELF_ALIGNMENT_BOTTOM:
57 if (point.y() >= screen.bottom())
60 case SHELF_ALIGNMENT_LEFT:
61 if (point.x() <= screen.x())
64 case SHELF_ALIGNMENT_TOP:
65 if (point.y() <= screen.y())
68 case SHELF_ALIGNMENT_RIGHT:
69 if (point.x() >= screen.right())