Commit 92f3f7d0 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Remove ShelfBezelEventHandler

This is no longer necessary.

Bug: 984347
Test: updated the test. no functional change.

Change-Id: Ia1ae37b6ed9a84af49ce5e6ab3025f0d9cb13ece
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1704314Reviewed-by: default avatarManu Cornet <manucornet@chromium.org>
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678299}
parent 44fbbbf8
......@@ -564,8 +564,6 @@ component("ash") {
"shelf/shelf_background_animator.cc",
"shelf/shelf_background_animator.h",
"shelf/shelf_background_animator_observer.h",
"shelf/shelf_bezel_event_handler.cc",
"shelf/shelf_bezel_event_handler.h",
"shelf/shelf_bubble.cc",
"shelf/shelf_bubble.h",
"shelf/shelf_button.cc",
......
......@@ -13,7 +13,6 @@
#include "ash/public/cpp/shelf_model.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/root_window_controller.h"
#include "ash/shelf/shelf_bezel_event_handler.h"
#include "ash/shelf/shelf_controller.h"
#include "ash/shelf/shelf_focus_cycler.h"
#include "ash/shelf/shelf_layout_manager.h"
......@@ -34,8 +33,7 @@ namespace ash {
// Forwards mouse and gesture events to ShelfLayoutManager for auto-hide.
class Shelf::AutoHideEventHandler : public ui::EventHandler {
public:
explicit AutoHideEventHandler(ShelfLayoutManager* shelf_layout_manager)
: shelf_layout_manager_(shelf_layout_manager) {
explicit AutoHideEventHandler(Shelf* shelf) : shelf_(shelf) {
Shell::Get()->AddPreTargetHandler(this);
}
~AutoHideEventHandler() override {
......@@ -44,16 +42,36 @@ class Shelf::AutoHideEventHandler : public ui::EventHandler {
// ui::EventHandler:
void OnMouseEvent(ui::MouseEvent* event) override {
shelf_layout_manager_->UpdateAutoHideForMouseEvent(
shelf_->shelf_layout_manager()->UpdateAutoHideForMouseEvent(
event, static_cast<aura::Window*>(event->target()));
}
void OnGestureEvent(ui::GestureEvent* event) override {
shelf_layout_manager_->ProcessGestureEventOfAutoHideShelf(
shelf_->shelf_layout_manager()->ProcessGestureEventOfAutoHideShelf(
event, static_cast<aura::Window*>(event->target()));
}
void OnTouchEvent(ui::TouchEvent* event) override {
if (shelf_->auto_hide_behavior() != SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS)
return;
// The event target should be the shelf widget.
aura::Window* target = static_cast<aura::Window*>(event->target());
if (target != Shelf::ForWindow(target)->shelf_widget()->GetNativeView())
return;
// The touch-pressing event may hide the shelf. Lock the shelf's auto hide
// state to give the shelf a chance to handle the touch event before it
// being hidden.
ShelfLayoutManager* shelf_layout_manager = shelf_->shelf_layout_manager();
if (event->type() == ui::ET_TOUCH_PRESSED && shelf_->IsVisible()) {
shelf_layout_manager->LockAutoHideState(true);
} else if (event->type() == ui::ET_TOUCH_RELEASED ||
event->type() == ui::ET_TOUCH_CANCELLED) {
shelf_layout_manager->LockAutoHideState(false);
}
}
private:
ShelfLayoutManager* shelf_layout_manager_;
Shelf* shelf_;
DISALLOW_COPY_AND_ASSIGN(AutoHideEventHandler);
};
......@@ -61,7 +79,6 @@ class Shelf::AutoHideEventHandler : public ui::EventHandler {
Shelf::Shelf()
: shelf_locking_manager_(this),
bezel_event_handler_(std::make_unique<ShelfBezelEventHandler>(this)),
shelf_focus_cycler_(std::make_unique<ShelfFocusCycler>(this)) {}
Shelf::~Shelf() = default;
......@@ -347,7 +364,6 @@ ShelfView* Shelf::GetShelfViewForTesting() {
void Shelf::WillDeleteShelfLayoutManager() {
// Clear event handlers that might forward events to the destroyed instance.
auto_hide_event_handler_.reset();
bezel_event_handler_.reset();
DCHECK(shelf_layout_manager_);
shelf_layout_manager_->RemoveObserver(this);
......@@ -360,8 +376,7 @@ void Shelf::WillChangeVisibilityState(ShelfVisibilityState new_state) {
if (new_state != SHELF_AUTO_HIDE) {
auto_hide_event_handler_.reset();
} else if (!auto_hide_event_handler_) {
auto_hide_event_handler_ =
std::make_unique<AutoHideEventHandler>(shelf_layout_manager());
auto_hide_event_handler_ = std::make_unique<AutoHideEventHandler>(this);
}
}
......
......@@ -30,7 +30,6 @@ class MouseEvent;
namespace ash {
enum class AnimationChangeType;
class ShelfBezelEventHandler;
class ShelfFocusCycler;
class ShelfLayoutManager;
class ShelfLayoutManagerTest;
......@@ -221,9 +220,6 @@ class ASH_EXPORT Shelf : public ShelfLayoutManagerObserver {
// Forwards mouse and gesture events to ShelfLayoutManager for auto-hide.
std::unique_ptr<AutoHideEventHandler> auto_hide_event_handler_;
// Forwards touch gestures on a bezel sensor to the shelf.
std::unique_ptr<ShelfBezelEventHandler> bezel_event_handler_;
// Hands focus off to different parts of the shelf.
std::unique_ptr<ShelfFocusCycler> shelf_focus_cycler_;
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/shelf/shelf_bezel_event_handler.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_layout_manager.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ui/aura/window.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/events/event.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/wm/core/coordinate_conversion.h"
namespace ash {
ShelfBezelEventHandler::ShelfBezelEventHandler(Shelf* shelf)
: shelf_(shelf), in_touch_drag_(false) {
Shell::Get()->AddPreTargetHandler(this);
}
ShelfBezelEventHandler::~ShelfBezelEventHandler() {
Shell::Get()->RemovePreTargetHandler(this);
}
void ShelfBezelEventHandler::OnGestureEvent(ui::GestureEvent* event) {
gfx::Point point_in_screen(event->location());
aura::Window* target = static_cast<aura::Window*>(event->target());
::wm::ConvertPointToScreen(target, &point_in_screen);
gfx::Rect screen = display::Screen::GetScreen()
->GetDisplayNearestPoint(point_in_screen)
.bounds();
if ((!screen.Contains(point_in_screen) &&
IsShelfOnBezel(screen, point_in_screen)) ||
in_touch_drag_) {
if (shelf_->ProcessGestureEvent(*event)) {
switch (event->type()) {
case ui::ET_GESTURE_SCROLL_BEGIN:
in_touch_drag_ = true;
break;
case ui::ET_GESTURE_SCROLL_END:
case ui::ET_SCROLL_FLING_START:
in_touch_drag_ = false;
break;
default:
break;
}
event->StopPropagation();
}
}
}
void ShelfBezelEventHandler::OnTouchEvent(ui::TouchEvent* event) {
if (shelf_->auto_hide_behavior() != SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS)
return;
// The event target should be the shelf widget.
aura::Window* target = static_cast<aura::Window*>(event->target());
if (target != Shelf::ForWindow(target)->shelf_widget()->GetNativeView())
return;
// The touch-pressing event may hide the shelf. Lock the shelf's auto hide
// state to give the shelf a chance to handle the touch event before it being
// hidden.
ShelfLayoutManager* shelf_layout_manager = shelf_->shelf_layout_manager();
if (event->type() == ui::ET_TOUCH_PRESSED && shelf_->IsVisible()) {
shelf_layout_manager->LockAutoHideState(true);
} else if (event->type() == ui::ET_TOUCH_RELEASED ||
event->type() == ui::ET_TOUCH_CANCELLED) {
shelf_layout_manager->LockAutoHideState(false);
}
}
bool ShelfBezelEventHandler::IsShelfOnBezel(const gfx::Rect& screen,
const gfx::Point& point) const {
switch (shelf_->alignment()) {
case SHELF_ALIGNMENT_BOTTOM:
case SHELF_ALIGNMENT_BOTTOM_LOCKED:
return point.y() >= screen.bottom();
case SHELF_ALIGNMENT_LEFT:
return point.x() <= screen.x();
case SHELF_ALIGNMENT_RIGHT:
return point.x() >= screen.right();
}
NOTREACHED();
return false;
}
} // namespace ash
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SHELF_SHELF_BEZEL_EVENT_HANDLER_H_
#define ASH_SHELF_SHELF_BEZEL_EVENT_HANDLER_H_
#include "base/macros.h"
#include "ui/events/event_handler.h"
namespace gfx {
class Point;
class Rect;
}
namespace ash {
class Shelf;
// Forwards touch gestures on a bezel sensor to the shelf.
class ShelfBezelEventHandler : public ui::EventHandler {
public:
explicit ShelfBezelEventHandler(Shelf* shelf);
~ShelfBezelEventHandler() override;
// Overridden from ui::EventHandler:
void OnGestureEvent(ui::GestureEvent* event) override;
void OnTouchEvent(ui::TouchEvent* event) override;
private:
bool IsShelfOnBezel(const gfx::Rect& screen, const gfx::Point& point) const;
Shelf* shelf_;
bool in_touch_drag_;
DISALLOW_COPY_AND_ASSIGN(ShelfBezelEventHandler);
};
} // namespace ash
#endif // ASH_SHELF_SHELF_BEZEL_EVENT_HANDLER_H_
......@@ -726,16 +726,9 @@ void ShelfLayoutManagerTest::RunGestureDragTests(
EXPECT_EQ(window_bounds_with_noshelf.ToString(), window->bounds().ToString());
EXPECT_EQ(shelf_hidden.ToString(),
GetShelfWidget()->GetWindowBoundsInScreen().ToString());
// Swipe up from below the shelf where a bezel would be, this should show the
// shelf.
// Swipe up from the bottom of the shelf, this should show the shelf.
gfx::Point below_start = edge_to_hide;
if (shelf->IsHorizontalAlignment())
below_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().bottom() - 1);
else if (SHELF_ALIGNMENT_LEFT == shelf->alignment())
below_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().x());
else if (SHELF_ALIGNMENT_RIGHT == shelf->alignment())
below_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().right() - 1);
generator->GestureScrollSequence(below_start, edge_to_show, kTimeDelta,
generator->GestureScrollSequence(edge_to_hide, edge_to_show, kTimeDelta,
kNumScrollSteps);
EXPECT_EQ(SHELF_AUTO_HIDE, shelf->GetVisibilityState());
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
......@@ -2247,8 +2240,9 @@ TEST_F(ShelfLayoutManagerTest, ShelfAnimatesToVisibleWhenGestureInComplete) {
ui::ScopedAnimationDurationScaleMode regular_animations(
ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION);
gfx::Point start =
GetShelfWidget()->GetWindowBoundsInScreen().CenterPoint();
display::Display display =
display::Screen::GetScreen()->GetPrimaryDisplay();
gfx::Point start = display.bounds().bottom_center();
gfx::Point end(start.x(), start.y() - 100);
ui::test::EventGenerator* generator = GetEventGenerator();
......@@ -2286,11 +2280,8 @@ TEST_F(ShelfLayoutManagerTest, ShelfAnimatesToHiddenWhenGestureOutComplete) {
// Show the shelf first.
display::Display display =
display::Screen::GetScreen()->GetPrimaryDisplay();
const int half_width = display.bounds().width() / 2;
const int bottom_edge = display.bounds().bottom();
generator->MoveMouseTo(half_width,
bottom_edge - kHiddenShelfInScreenPortion / 2);
ShelfAnimationWaiter waiter1(visible_bounds);
generator->MoveMouseTo(display.bounds().bottom_center());
waiter1.WaitTillDoneAnimating();
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState());
......@@ -2842,7 +2833,6 @@ TEST_F(ShelfLayoutManagerTest, SwipeUpAutoHideHiddenShelf) {
const int time_deltas[] = {10, 50, 100, 500};
const int num_scroll_steps[] = {2, 5, 10, 50};
const int y_bezel_start_offsets[] = {5, 10, 50};
const int x_offsets[] = {10, 20, 50};
const int y_offsets[] = {70, 100, 300, 500};
......@@ -2850,21 +2840,17 @@ TEST_F(ShelfLayoutManagerTest, SwipeUpAutoHideHiddenShelf) {
for (int num_scroll_steps : num_scroll_steps) {
for (int x_offset : x_offsets) {
for (int y_offset : y_offsets) {
for (int y_bezel_start_offset : y_bezel_start_offsets) {
const gfx::Point start(display_bounds.bottom_center() +
gfx::Vector2d(0, y_bezel_start_offset));
const gfx::Point end(start + gfx::Vector2d(x_offset, -y_offset));
generator->GestureScrollSequence(
start, end, base::TimeDelta::FromMilliseconds(time_delta),
num_scroll_steps);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState())
<< "Failure to show shelf after a swipe up in " << time_delta
<< "ms, " << num_scroll_steps << " steps, "
<< y_bezel_start_offset << " Y bezel start offset, " << x_offset
<< " X-offset and " << y_offset << " Y-offset.";
generator->GestureTapAt(tap_to_hide_shelf_location);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
const gfx::Point start(display_bounds.bottom_center());
const gfx::Point end(start + gfx::Vector2d(x_offset, -y_offset));
generator->GestureScrollSequence(
start, end, base::TimeDelta::FromMilliseconds(time_delta),
num_scroll_steps);
EXPECT_EQ(SHELF_AUTO_HIDE_SHOWN, shelf->GetAutoHideState())
<< "Failure to show shelf after a swipe up in " << time_delta
<< "ms, " << num_scroll_steps << " steps, " << x_offset
<< " X-offset and " << y_offset << " Y-offset.";
generator->GestureTapAt(tap_to_hide_shelf_location);
EXPECT_EQ(SHELF_AUTO_HIDE_HIDDEN, shelf->GetAutoHideState());
}
}
}
......
......@@ -86,8 +86,9 @@ void AshTestHelper::SetUp(const InitParams& init_params,
// lap with the native mouse cursor.
if (!command_line_->GetProcessCommandLine()->HasSwitch(
::switches::kHostWindowBounds)) {
// TODO(oshima): Disable native events instead of adding offset.
command_line_->GetProcessCommandLine()->AppendSwitchASCII(
::switches::kHostWindowBounds, "1+1-800x600");
::switches::kHostWindowBounds, "10+10-800x600");
}
// Pre shell creation config init.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment