blob: 9906602dd1030d085ec8c46e71e6ac41cecd1bbe [file] [log] [blame]
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +01001// 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.
4
5#include "ash/shelf/shelf_bezel_event_filter.h"
6
7#include "ash/shelf/shelf_layout_manager.h"
8#include "ash/shell.h"
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +00009#include "ui/aura/window.h"
Torne (Richard Coles)6e8cce62014-08-19 13:00:08 +010010#include "ui/wm/core/coordinate_conversion.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010011
12namespace ash {
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010013
14ShelfBezelEventFilter::ShelfBezelEventFilter(
15 ShelfLayoutManager* shelf)
16 : shelf_(shelf),
17 in_touch_drag_(false) {
18 Shell::GetInstance()->AddPreTargetHandler(this);
19}
20
21ShelfBezelEventFilter::~ShelfBezelEventFilter() {
22 Shell::GetInstance()->RemovePreTargetHandler(this);
23}
24
25void ShelfBezelEventFilter::OnGestureEvent(
26 ui::GestureEvent* event) {
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +000027 gfx::Point point_in_screen(event->location());
28 aura::Window* target = static_cast<aura::Window*>(event->target());
Torne (Richard Coles)6e8cce62014-08-19 13:00:08 +010029 ::wm::ConvertPointToScreen(target, &point_in_screen);
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010030 gfx::Rect screen =
Torne (Richard Coles)f2477e02013-11-28 11:55:43 +000031 Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen).bounds();
32 if ((!screen.Contains(point_in_screen) &&
33 IsShelfOnBezel(screen, point_in_screen)) ||
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010034 in_touch_drag_) {
35 if (gesture_handler_.ProcessGestureEvent(*event)) {
36 switch (event->type()) {
37 case ui::ET_GESTURE_SCROLL_BEGIN:
38 in_touch_drag_ = true;
39 break;
40 case ui::ET_GESTURE_SCROLL_END:
41 case ui::ET_SCROLL_FLING_START:
42 in_touch_drag_ = false;
43 break;
44 default:
45 break;
46 }
47 event->StopPropagation();
48 }
49 }
50}
51
52bool 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())
58 return true;
59 break;
60 case SHELF_ALIGNMENT_LEFT:
61 if (point.x() <= screen.x())
62 return true;
63 break;
64 case SHELF_ALIGNMENT_TOP:
65 if (point.y() <= screen.y())
66 return true;
67 break;
68 case SHELF_ALIGNMENT_RIGHT:
69 if (point.x() >= screen.right())
70 return true;
71 break;
72 }
73 return false;
74}
75
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010076} // namespace ash