Commit e17503d8 authored by Yuanyao Zhong's avatar Yuanyao Zhong Committed by Commit Bot

Adding filtering for handling touch events in RenderWidgetHostViewAura.

Bug: b/73285025
Change-Id: I052cf918edb3cf15d3c6576c39adfbd6475ed93e
Reviewed-on: https://chromium-review.googlesource.com/955956Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Yuanyao Zhong <yyzhong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542963}
parent bea0f046
......@@ -14,17 +14,46 @@
namespace chromecast {
namespace shell {
class TouchBlocker : public ui::EventHandler, public aura::WindowObserver {
public:
explicit TouchBlocker(aura::Window* window) : window_(window) {
DCHECK(window_);
window_->AddObserver(this);
window_->AddPreTargetHandler(this);
}
~TouchBlocker() override {
if (window_) {
window_->RemoveObserver(this);
window_->RemovePreTargetHandler(this);
}
}
private:
// Overriden from ui::EventHandler.
void OnTouchEvent(ui::TouchEvent* touch) override { touch->SetHandled(); }
// Overriden from aura::WindowObserver.
void OnWindowDestroyed(aura::Window* window) override { window_ = nullptr; }
aura::Window* window_;
DISALLOW_COPY_AND_ASSIGN(TouchBlocker);
};
// static
std::unique_ptr<CastContentWindow> CastContentWindow::Create(
CastContentWindow::Delegate* /* delegate */,
bool /* is_headless */,
bool /* enable_touch_input */) {
return base::WrapUnique(new CastContentWindowAura());
CastContentWindow::Delegate* delegate,
bool is_headless,
bool enable_touch_input) {
return base::WrapUnique(new CastContentWindowAura(enable_touch_input));
}
CastContentWindowAura::CastContentWindowAura() = default;
CastContentWindowAura::~CastContentWindowAura() = default;
CastContentWindowAura::CastContentWindowAura(bool is_touch_enabled)
: is_touch_enabled_(is_touch_enabled), touch_blocker_() {}
void CastContentWindowAura::CreateWindowForWebContents(
content::WebContents* web_contents,
CastWindowManager* window_manager,
......@@ -34,6 +63,11 @@ void CastContentWindowAura::CreateWindowForWebContents(
gfx::NativeView window = web_contents->GetNativeView();
window_manager->SetWindowId(window, CastWindowManager::APP);
window_manager->AddWindow(window);
if (!is_touch_enabled_) {
touch_blocker_ = std::make_unique<TouchBlocker>(window);
}
if (is_visible) {
window->Show();
} else {
......
......@@ -15,6 +15,8 @@ class WebContents;
namespace chromecast {
namespace shell {
class TouchBlocker;
class CastContentWindowAura : public CastContentWindow {
public:
~CastContentWindowAura() override;
......@@ -28,7 +30,10 @@ class CastContentWindowAura : public CastContentWindow {
friend class CastContentWindow;
// This class should only be instantiated by CastContentWindow::Create.
CastContentWindowAura();
CastContentWindowAura(bool is_touch_enabled);
const bool is_touch_enabled_;
std::unique_ptr<TouchBlocker> touch_blocker_;
DISALLOW_COPY_AND_ASSIGN(CastContentWindowAura);
};
......
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