forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reland "[Fuchsia] Add support for selectively enabling input types."
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
Showing
11 changed files
with
436 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
Oops, something went wrong.