OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/shelf/shelf_bezel_event_filter.h" | 5 #include "ash/shelf/shelf_bezel_event_handler.h" |
6 | 6 |
7 #include "ash/shelf/shelf_layout_manager.h" | 7 #include "ash/common/shelf/wm_shelf.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/display/display.h" | 10 #include "ui/display/display.h" |
11 #include "ui/display/screen.h" | 11 #include "ui/display/screen.h" |
| 12 #include "ui/events/event.h" |
12 #include "ui/gfx/geometry/point.h" | 13 #include "ui/gfx/geometry/point.h" |
13 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
14 #include "ui/wm/core/coordinate_conversion.h" | 15 #include "ui/wm/core/coordinate_conversion.h" |
15 | 16 |
16 namespace ash { | 17 namespace ash { |
17 | 18 |
18 ShelfBezelEventFilter::ShelfBezelEventFilter( | 19 ShelfBezelEventHandler::ShelfBezelEventHandler(WmShelf* shelf) |
19 ShelfLayoutManager* shelf_layout_manager) | 20 : shelf_(shelf), in_touch_drag_(false) { |
20 : shelf_layout_manager_(shelf_layout_manager), in_touch_drag_(false) { | |
21 Shell::GetInstance()->AddPreTargetHandler(this); | 21 Shell::GetInstance()->AddPreTargetHandler(this); |
22 } | 22 } |
23 | 23 |
24 ShelfBezelEventFilter::~ShelfBezelEventFilter() { | 24 ShelfBezelEventHandler::~ShelfBezelEventHandler() { |
25 Shell::GetInstance()->RemovePreTargetHandler(this); | 25 Shell::GetInstance()->RemovePreTargetHandler(this); |
26 } | 26 } |
27 | 27 |
28 void ShelfBezelEventFilter::OnGestureEvent(ui::GestureEvent* event) { | 28 void ShelfBezelEventHandler::OnGestureEvent(ui::GestureEvent* event) { |
29 gfx::Point point_in_screen(event->location()); | 29 gfx::Point point_in_screen(event->location()); |
30 aura::Window* target = static_cast<aura::Window*>(event->target()); | 30 aura::Window* target = static_cast<aura::Window*>(event->target()); |
31 ::wm::ConvertPointToScreen(target, &point_in_screen); | 31 ::wm::ConvertPointToScreen(target, &point_in_screen); |
32 gfx::Rect screen = display::Screen::GetScreen() | 32 gfx::Rect screen = display::Screen::GetScreen() |
33 ->GetDisplayNearestPoint(point_in_screen) | 33 ->GetDisplayNearestPoint(point_in_screen) |
34 .bounds(); | 34 .bounds(); |
35 if ((!screen.Contains(point_in_screen) && | 35 if ((!screen.Contains(point_in_screen) && |
36 IsShelfOnBezel(screen, point_in_screen)) || | 36 IsShelfOnBezel(screen, point_in_screen)) || |
37 in_touch_drag_) { | 37 in_touch_drag_) { |
38 if (shelf_layout_manager_->ProcessGestureEvent(*event)) { | 38 if (shelf_->ProcessGestureEvent(*event)) { |
39 switch (event->type()) { | 39 switch (event->type()) { |
40 case ui::ET_GESTURE_SCROLL_BEGIN: | 40 case ui::ET_GESTURE_SCROLL_BEGIN: |
41 in_touch_drag_ = true; | 41 in_touch_drag_ = true; |
42 break; | 42 break; |
43 case ui::ET_GESTURE_SCROLL_END: | 43 case ui::ET_GESTURE_SCROLL_END: |
44 case ui::ET_SCROLL_FLING_START: | 44 case ui::ET_SCROLL_FLING_START: |
45 in_touch_drag_ = false; | 45 in_touch_drag_ = false; |
46 break; | 46 break; |
47 default: | 47 default: |
48 break; | 48 break; |
49 } | 49 } |
50 event->StopPropagation(); | 50 event->StopPropagation(); |
51 } | 51 } |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 bool ShelfBezelEventFilter::IsShelfOnBezel(const gfx::Rect& screen, | 55 bool ShelfBezelEventHandler::IsShelfOnBezel(const gfx::Rect& screen, |
56 const gfx::Point& point) const { | 56 const gfx::Point& point) const { |
57 return shelf_layout_manager_->SelectValueForShelfAlignment( | 57 switch (shelf_->GetAlignment()) { |
58 point.y() >= screen.bottom(), point.x() <= screen.x(), | 58 case SHELF_ALIGNMENT_BOTTOM: |
59 point.x() >= screen.right()); | 59 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| 60 return point.y() >= screen.bottom(); |
| 61 case SHELF_ALIGNMENT_LEFT: |
| 62 return point.x() <= screen.x(); |
| 63 case SHELF_ALIGNMENT_RIGHT: |
| 64 return point.x() >= screen.right(); |
| 65 } |
| 66 NOTREACHED(); |
| 67 return false; |
60 } | 68 } |
61 | 69 |
62 } // namespace ash | 70 } // namespace ash |
OLD | NEW |