Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 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. |
| 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) | f2477e0 | 2013-11-28 11:55:43 +0000 | [diff] [blame] | 9 | #include "ui/aura/window.h" |
Torne (Richard Coles) | 6e8cce6 | 2014-08-19 13:00:08 +0100 | [diff] [blame^] | 10 | #include "ui/wm/core/coordinate_conversion.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 11 | |
| 12 | namespace ash { |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 13 | |
| 14 | ShelfBezelEventFilter::ShelfBezelEventFilter( |
| 15 | ShelfLayoutManager* shelf) |
| 16 | : shelf_(shelf), |
| 17 | in_touch_drag_(false) { |
| 18 | Shell::GetInstance()->AddPreTargetHandler(this); |
| 19 | } |
| 20 | |
| 21 | ShelfBezelEventFilter::~ShelfBezelEventFilter() { |
| 22 | Shell::GetInstance()->RemovePreTargetHandler(this); |
| 23 | } |
| 24 | |
| 25 | void ShelfBezelEventFilter::OnGestureEvent( |
| 26 | ui::GestureEvent* event) { |
Torne (Richard Coles) | f2477e0 | 2013-11-28 11:55:43 +0000 | [diff] [blame] | 27 | gfx::Point point_in_screen(event->location()); |
| 28 | aura::Window* target = static_cast<aura::Window*>(event->target()); |
Torne (Richard Coles) | 6e8cce6 | 2014-08-19 13:00:08 +0100 | [diff] [blame^] | 29 | ::wm::ConvertPointToScreen(target, &point_in_screen); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 30 | gfx::Rect screen = |
Torne (Richard Coles) | f2477e0 | 2013-11-28 11:55:43 +0000 | [diff] [blame] | 31 | Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen).bounds(); |
| 32 | if ((!screen.Contains(point_in_screen) && |
| 33 | IsShelfOnBezel(screen, point_in_screen)) || |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 34 | 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 | |
| 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()) |
| 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) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 76 | } // namespace ash |