| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 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/wm/gestures/border_gesture_handler.h" | |
| 6 | |
| 7 #include "ash/root_window_controller.h" | |
| 8 #include "ash/shelf/shelf_layout_manager.h" | |
| 9 #include "ash/shelf/shelf_types.h" | |
| 10 #include "ash/shelf/shelf_widget.h" | |
| 11 #include "ash/shell.h" | |
| 12 #include "base/command_line.h" | |
| 13 #include "base/string_util.h" | |
| 14 #include "base/strings/string_number_conversions.h" | |
| 15 #include "ui/aura/root_window.h" | |
| 16 #include "ui/base/events/event.h" | |
| 17 #include "ui/base/ui_base_switches.h" | |
| 18 #include "ui/gfx/screen.h" | |
| 19 | |
| 20 namespace ash { | |
| 21 namespace internal { | |
| 22 | |
| 23 BorderGestureHandler::BorderGestureHandler() | |
| 24 : orientation_(BORDER_SCROLL_ORIENTATION_UNSET) { | |
| 25 } | |
| 26 | |
| 27 BorderGestureHandler::~BorderGestureHandler() { | |
| 28 } | |
| 29 | |
| 30 bool BorderGestureHandler::ProcessGestureEvent(aura::Window* target, | |
| 31 const ui::GestureEvent& event) { | |
| 32 switch (event.type()) { | |
| 33 case ui::ET_GESTURE_SCROLL_BEGIN: | |
| 34 return HandleBorderGestureStart(target, event); | |
| 35 case ui::ET_GESTURE_SCROLL_UPDATE: | |
| 36 if (start_location_.any() && | |
| 37 DetermineGestureOrientation(event)) | |
| 38 return HandleBorderGestureUpdate(target, event); | |
| 39 break; | |
| 40 case ui::ET_GESTURE_SCROLL_END: | |
| 41 case ui::ET_SCROLL_FLING_START: | |
| 42 return HandleBorderGestureEnd(target, event); | |
| 43 default: | |
| 44 break; | |
| 45 } | |
| 46 // If the event is outside of the display region and targetted at the root | |
| 47 // window then it is on a bezel and not in another window. All bezel events | |
| 48 // should be consumed here since no other part of the stack handles them. | |
| 49 gfx::Rect screen = | |
| 50 Shell::GetScreen()->GetDisplayNearestWindow(target).bounds(); | |
| 51 if (!screen.Contains(event.location()) && | |
| 52 target == target->GetRootWindow()) | |
| 53 return true; | |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 bool BorderGestureHandler::HandleLauncherControl( | |
| 58 const ui::GestureEvent& event) { | |
| 59 ShelfLayoutManager* shelf = | |
| 60 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); | |
| 61 switch (shelf->GetAlignment()) { | |
| 62 case SHELF_ALIGNMENT_BOTTOM: | |
| 63 if (start_location_.test(BORDER_LOCATION_BOTTOM)) | |
| 64 return shelf_handler_.ProcessGestureEvent(event); | |
| 65 break; | |
| 66 case SHELF_ALIGNMENT_LEFT: | |
| 67 if (start_location_.test(BORDER_LOCATION_LEFT)) | |
| 68 return shelf_handler_.ProcessGestureEvent(event); | |
| 69 break; | |
| 70 case SHELF_ALIGNMENT_TOP: | |
| 71 if (start_location_.test(BORDER_LOCATION_TOP)) | |
| 72 return shelf_handler_.ProcessGestureEvent(event); | |
| 73 break; | |
| 74 case SHELF_ALIGNMENT_RIGHT: | |
| 75 if (start_location_.test(BORDER_LOCATION_RIGHT)) | |
| 76 return shelf_handler_.ProcessGestureEvent(event); | |
| 77 break; | |
| 78 } | |
| 79 return false; | |
| 80 } | |
| 81 | |
| 82 bool BorderGestureHandler::HandleBorderGestureStart( | |
| 83 aura::Window* target, | |
| 84 const ui::GestureEvent& event) { | |
| 85 orientation_ = BORDER_SCROLL_ORIENTATION_UNSET; | |
| 86 start_location_.reset(); | |
| 87 | |
| 88 gfx::Rect screen = | |
| 89 Shell::GetScreen()->GetDisplayNearestWindow(target).bounds(); | |
| 90 GestureStartInTargetArea(screen, event); | |
| 91 | |
| 92 if (start_location_.any()) | |
| 93 return HandleLauncherControl(event); | |
| 94 return false; | |
| 95 } | |
| 96 | |
| 97 bool BorderGestureHandler::HandleBorderGestureUpdate( | |
| 98 aura::Window* target, | |
| 99 const ui::GestureEvent& event) { | |
| 100 if (IsGestureInLauncherOrientation(event)) | |
| 101 return HandleLauncherControl(event); | |
| 102 return false; | |
| 103 } | |
| 104 | |
| 105 bool BorderGestureHandler::HandleBorderGestureEnd( | |
| 106 aura::Window* target, | |
| 107 const ui::GestureEvent& event) { | |
| 108 bool ret_val = HandleLauncherControl(event); | |
| 109 start_location_.reset(); | |
| 110 return ret_val; | |
| 111 } | |
| 112 | |
| 113 void BorderGestureHandler::GestureStartInTargetArea( | |
| 114 const gfx::Rect& screen, | |
| 115 const ui::GestureEvent& event) { | |
| 116 if (event.y() > screen.bottom()) | |
| 117 start_location_[BORDER_LOCATION_BOTTOM] = 1; | |
| 118 if (event.x() < screen.x()) | |
| 119 start_location_[BORDER_LOCATION_LEFT] = 1; | |
| 120 if (event.y() < screen.y()) | |
| 121 start_location_[BORDER_LOCATION_TOP] = 1; | |
| 122 if (event.x() > screen.right()) | |
| 123 start_location_[BORDER_LOCATION_RIGHT] = 1; | |
| 124 } | |
| 125 | |
| 126 bool BorderGestureHandler::DetermineGestureOrientation( | |
| 127 const ui::GestureEvent& event) { | |
| 128 if (orientation_ == BORDER_SCROLL_ORIENTATION_UNSET) { | |
| 129 if (!event.details().scroll_x() && !event.details().scroll_y()) | |
| 130 return false; | |
| 131 orientation_ = abs(event.details().scroll_y()) > | |
| 132 abs(event.details().scroll_x()) ? | |
| 133 BORDER_SCROLL_ORIENTATION_VERTICAL : | |
| 134 BORDER_SCROLL_ORIENTATION_HORIZONTAL; | |
| 135 } | |
| 136 return true; | |
| 137 } | |
| 138 | |
| 139 bool BorderGestureHandler::IsGestureInLauncherOrientation( | |
| 140 const ui::GestureEvent& event) { | |
| 141 BorderScrollOrientation new_orientation = abs(event.details().scroll_y()) > | |
| 142 abs(event.details().scroll_x()) ? | |
| 143 BORDER_SCROLL_ORIENTATION_VERTICAL : BORDER_SCROLL_ORIENTATION_HORIZONTAL; | |
| 144 if (new_orientation != orientation_) | |
| 145 return false; | |
| 146 | |
| 147 ShelfLayoutManager* shelf = | |
| 148 Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); | |
| 149 switch (shelf->GetAlignment()) { | |
| 150 case SHELF_ALIGNMENT_BOTTOM: | |
| 151 if (orientation_ == BORDER_SCROLL_ORIENTATION_VERTICAL) | |
| 152 return true; | |
| 153 break; | |
| 154 case SHELF_ALIGNMENT_LEFT: | |
| 155 if (orientation_ == BORDER_SCROLL_ORIENTATION_HORIZONTAL) | |
| 156 return true; | |
| 157 break; | |
| 158 case SHELF_ALIGNMENT_TOP: | |
| 159 if (orientation_ == BORDER_SCROLL_ORIENTATION_VERTICAL) | |
| 160 return true; | |
| 161 break; | |
| 162 case SHELF_ALIGNMENT_RIGHT: | |
| 163 if (orientation_ == BORDER_SCROLL_ORIENTATION_HORIZONTAL) | |
| 164 return true; | |
| 165 break; | |
| 166 } | |
| 167 return false; | |
| 168 } | |
| 169 | |
| 170 } // namespace internal | |
| 171 } // namespace ash | |
| OLD | NEW |