This source file includes following definitions.
- scroll_y_
- ProcessScrollEvent
- ProcessGestureEvent
#include "ash/wm/gestures/overview_gesture_handler.h"
#include "ash/metrics/user_metrics_recorder.h"
#include "ash/shell.h"
#include "ash/wm/coordinate_conversion.h"
#include "ash/wm/overview/window_selector_controller.h"
#include "ui/aura/window.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/screen.h"
namespace ash {
namespace {
const int kTopBezelExtraPixels = 5;
const float kSwipeThresholdPixels = 300;
}
OverviewGestureHandler::OverviewGestureHandler()
: in_top_bezel_gesture_(false),
scroll_x_(0),
scroll_y_(0) {
}
OverviewGestureHandler::~OverviewGestureHandler() {
}
bool OverviewGestureHandler::ProcessScrollEvent(const ui::ScrollEvent& event) {
if (event.type() == ui::ET_SCROLL_FLING_START ||
event.type() == ui::ET_SCROLL_FLING_CANCEL ||
event.finger_count() != 3) {
scroll_x_ = scroll_y_ = 0;
return false;
}
scroll_x_ += event.x_offset();
scroll_y_ += event.y_offset();
if (std::fabs(scroll_x_) >= std::fabs(scroll_y_)) {
scroll_x_ = scroll_y_ = 0;
return false;
}
Shell* shell = Shell::GetInstance();
if (shell->window_selector_controller()->IsSelecting()) {
if (scroll_y_ < 0)
scroll_x_ = scroll_y_ = 0;
if (scroll_y_ < kSwipeThresholdPixels)
return false;
} else {
if (scroll_y_ > 0)
scroll_x_ = scroll_y_ = 0;
if (scroll_y_ > -kSwipeThresholdPixels)
return false;
}
scroll_x_ = scroll_y_ = 0;
shell->metrics()->RecordUserMetricsAction(UMA_TOUCHPAD_GESTURE_OVERVIEW);
shell->window_selector_controller()->ToggleOverview();
return true;
}
bool OverviewGestureHandler::ProcessGestureEvent(
const ui::GestureEvent& event) {
if (event.type() == ui::ET_GESTURE_BEGIN &&
event.details().touch_points() == 1) {
gfx::Point point_in_screen(event.location());
aura::Window* target = static_cast<aura::Window*>(event.target());
wm::ConvertPointToScreen(target, &point_in_screen);
in_top_bezel_gesture_ = !Shell::GetScreen()->GetDisplayNearestPoint(
point_in_screen).bounds().y() + kTopBezelExtraPixels >
point_in_screen.y();
return false;
}
if (!in_top_bezel_gesture_ ||
event.type() != ui::ET_GESTURE_MULTIFINGER_SWIPE ||
!event.details().swipe_down() ||
event.details().touch_points() != 3) {
return false;
}
Shell* shell = Shell::GetInstance();
shell->metrics()->RecordUserMetricsAction(UMA_GESTURE_OVERVIEW);
shell->window_selector_controller()->ToggleOverview();
return true;
}
}