Skip to content

Commit

Permalink
Reland "[Fuchsia] Add support for selectively enabling input types."
Browse files Browse the repository at this point in the history
This is a reland of 4898ea4

Adds a missing export directive which was breaking component builds.

Original change's description:
> [Fuchsia] Add support for selectively enabling input types.
>
> * Implements the FIDL ConfigureInputTypes() API, for embedder control
> over whether input events should be routed to web content or ignored.
> * Transitions CastRunner to use ConfigureInputTypes().
> * Removes the deprecated SetInputEnabled() method.
>
> Bug: 1031776
> Change-Id: I54e0b5c3b5a92935e6860e037edc6bc5a92eaa42
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1956154
> Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
> Reviewed-by: David Dorwin <ddorwin@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#755219}

TBR=ddorwin@chromium.org

Bug: 1031776
Change-Id: Ia0047b56ce7ac8b28b25d0853f4d772d94cec68b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2132854
Reviewed-by: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: David Dorwin <ddorwin@chromium.org>
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755450}
  • Loading branch information
Kevin Marshall authored and Commit Bot committed Apr 1, 2020
1 parent d5dd5e9 commit cab6669
Show file tree
Hide file tree
Showing 11 changed files with 436 additions and 69 deletions.
5 changes: 3 additions & 2 deletions fuchsia/engine/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ component("web_engine_core") {
"browser/context_impl.h",
"browser/cookie_manager_impl.cc",
"browser/cookie_manager_impl.h",
"browser/discarding_event_filter.cc",
"browser/discarding_event_filter.h",
"browser/event_filter.cc",
"browser/event_filter.h",
"browser/frame_impl.cc",
"browser/frame_impl.h",
"browser/frame_layout_manager.cc",
Expand Down Expand Up @@ -276,6 +276,7 @@ test("web_engine_unittests") {
sources = [
"browser/ax_tree_converter_unittest.cc",
"browser/cookie_manager_impl_unittest.cc",
"browser/event_filter_unittest.cc",
"browser/frame_impl_unittest.cc",
"browser/url_request_rewrite_rules_manager_unittest.cc",
"common/web_engine_url_loader_throttle_unittest.cc",
Expand Down
17 changes: 0 additions & 17 deletions fuchsia/engine/browser/discarding_event_filter.cc

This file was deleted.

36 changes: 0 additions & 36 deletions fuchsia/engine/browser/discarding_event_filter.h

This file was deleted.

148 changes: 148 additions & 0 deletions fuchsia/engine/browser/event_filter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// Copyright 2019 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 "fuchsia/engine/browser/event_filter.h"

#include <limits>

#include "ui/events/event.h"

namespace {

using fuchsia::web::InputTypes;

const uint64_t kInputTypeNone = 0;
const uint64_t kInputTypeAll = std::numeric_limits<uint64_t>::max();

static_assert(
std::is_same<uint64_t,
std::underlying_type<fuchsia::web::InputTypes>::type>::value,
"InputTypes is not an uint64.");

} // namespace

EventFilter::EventFilter() {
// Allow all inputs by default.
ConfigureInputTypes(fuchsia::web::InputTypes::ALL,
fuchsia::web::AllowInputState::ALLOW);
}

EventFilter::~EventFilter() = default;

void EventFilter::ConfigureInputTypes(fuchsia::web::InputTypes types,
fuchsia::web::AllowInputState allow) {
// If |types| contains ALL, all other type bits are superseded.
if (allow == fuchsia::web::AllowInputState::ALLOW) {
if (static_cast<uint64_t>(types) &
static_cast<uint64_t>(fuchsia::web::InputTypes::ALL)) {
enabled_input_types_ = kInputTypeAll;
enable_unknown_types_ = true;
} else {
enabled_input_types_ |= static_cast<uint64_t>(types);
}
} else {
if (static_cast<uint64_t>(types) &
static_cast<uint64_t>(fuchsia::web::InputTypes::ALL)) {
enabled_input_types_ = kInputTypeNone;
enable_unknown_types_ = false;
} else {
enabled_input_types_ &= static_cast<uint64_t>(~types);
}
}
}

void EventFilter::OnEvent(ui::Event* event) {
if (!IsEventAllowed(event->type())) {
event->StopPropagation();
return;
}

// Allow base class to route |event| to event type-specific handlers.
ui::EventHandler::OnEvent(event);
}

void EventFilter::OnGestureEvent(ui::GestureEvent* event) {
if (!IsEventAllowed(event->type())) {
event->StopPropagation();
return;
}

ui::EventHandler::OnGestureEvent(event);
}

bool EventFilter::IsEventAllowed(ui::EventType type) {
switch (type) {
case ui::ET_KEY_PRESSED:
case ui::ET_KEY_RELEASED:
return IsTypeEnabled(InputTypes::KEY);

case ui::ET_MOUSE_PRESSED:
case ui::ET_MOUSE_DRAGGED:
case ui::ET_MOUSE_RELEASED:
return IsTypeEnabled(InputTypes::MOUSE_CLICK);

case ui::ET_MOUSE_MOVED:
case ui::ET_MOUSE_ENTERED:
case ui::ET_MOUSE_EXITED:
return IsTypeEnabled(InputTypes::MOUSE_MOVE);

case ui::ET_MOUSEWHEEL:
return IsTypeEnabled(InputTypes::MOUSE_WHEEL);

case ui::ET_GESTURE_TAP:
case ui::ET_GESTURE_TAP_DOWN:
case ui::ET_GESTURE_TAP_CANCEL:
case ui::ET_GESTURE_TAP_UNCONFIRMED:
case ui::ET_GESTURE_DOUBLE_TAP:
case ui::ET_GESTURE_TWO_FINGER_TAP:
case ui::ET_GESTURE_LONG_PRESS:
case ui::ET_GESTURE_LONG_TAP:
return IsTypeEnabled(InputTypes::GESTURE_TAP);

case ui::ET_GESTURE_PINCH_BEGIN:
case ui::ET_GESTURE_PINCH_END:
case ui::ET_GESTURE_PINCH_UPDATE:
return IsTypeEnabled(InputTypes::GESTURE_PINCH);

case ui::ET_GESTURE_SCROLL_BEGIN:
case ui::ET_GESTURE_SCROLL_END:
case ui::ET_GESTURE_SCROLL_UPDATE:
case ui::ET_GESTURE_SWIPE:
case ui::ET_SCROLL:
case ui::ET_SCROLL_FLING_START:
case ui::ET_SCROLL_FLING_CANCEL:
return IsTypeEnabled(InputTypes::GESTURE_DRAG);

// Allow low-level touch events and non-input control messages to pass
// through unimpeded.
case ui::ET_TOUCH_RELEASED:
case ui::ET_TOUCH_PRESSED:
case ui::ET_TOUCH_MOVED:
case ui::ET_TOUCH_CANCELLED:
case ui::ET_DROP_TARGET_EVENT:
case ui::ET_GESTURE_SHOW_PRESS:
case ui::ET_GESTURE_BEGIN:
case ui::ET_GESTURE_END:
case ui::ET_CANCEL_MODE:
case ui::ET_MOUSE_CAPTURE_CHANGED:
return true;

case ui::ET_UMA_DATA:
NOTREACHED(); // ChromeOS only.
break;

case ui::ET_LAST:
NOTREACHED();
FALLTHROUGH;

case ui::ET_UNKNOWN:
break;
}

return enable_unknown_types_;
}

bool EventFilter::IsTypeEnabled(InputTypes type) const {
return (enabled_input_types_ & static_cast<uint64_t>(type));
}
48 changes: 48 additions & 0 deletions fuchsia/engine/browser/event_filter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2019 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 FUCHSIA_ENGINE_BROWSER_EVENT_FILTER_H_
#define FUCHSIA_ENGINE_BROWSER_EVENT_FILTER_H_

#include <fuchsia/web/cpp/fidl.h>
#include <memory>

#include "base/macros.h"
#include "fuchsia/engine/web_engine_export.h"
#include "ui/events/event_handler.h"
#include "ui/events/types/event_type.h"

// Event filter which can be configured to drop all events, or certain kinds of
// events.
class WEB_ENGINE_EXPORT EventFilter : public ui::EventHandler {
public:
EventFilter();
~EventFilter() override;

EventFilter(const EventFilter&) = delete;
EventFilter& operator=(const EventFilter&) = delete;

void ConfigureInputTypes(fuchsia::web::InputTypes types,
fuchsia::web::AllowInputState allow);

private:
friend class EventFilterTest;

bool IsEventAllowed(ui::EventType type);

// Returns whether |type| is set in the |enabled_input_types_| bitmask.
bool IsTypeEnabled(fuchsia::web::InputTypes type) const;

// ui::EventRewriter implementation.
void OnEvent(ui::Event* event) final;
void OnGestureEvent(ui::GestureEvent* event) final;

uint64_t enabled_input_types_ = 0;

// Allows input events not mapped to fuchsia::web::InputTypes entries
// to be processed. Set by allowing or denying fuchsia::web::InputTypes::ALL.
bool enable_unknown_types_ = true;
};

#endif // FUCHSIA_ENGINE_BROWSER_EVENT_FILTER_H_
Loading

0 comments on commit cab6669

Please sign in to comment.