blob: 4c65f304504038ebee620e624417091d4f65a175 [file] [log] [blame]
// Copyright 2018 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 CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_UNHANDLED_TAP_WEB_CONTENTS_OBSERVER_H_
#define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_UNHANDLED_TAP_WEB_CONTENTS_OBSERVER_H_
#include "base/macros.h"
#include "content/public/browser/web_contents_user_data.h"
namespace contextual_search {
typedef base::RepeatingCallback<
void(int x_px, int y_px, int font_size_dips, int text_run_length)>
UnhandledTapCallback;
// Binds a Mojo unhandled-tap notifier message-handler to the frame host
// observed by this observer.
// TODO(donnd): remove this as part of removal of all Tap gesture support
// after a migration to triggering using Longpress.
class UnhandledTapWebContentsObserver
: public content::WebContentsUserData<UnhandledTapWebContentsObserver> {
public:
// Creates an observer for the given |web_contents| that binds a Mojo request
// for an endpoint to the UnhandledTapNotifier service. This will create an
// instance of the contextual_search::CreateUnhandledTapNotifierImpl to handle
// those messages.
explicit UnhandledTapWebContentsObserver(content::WebContents* web_contents);
~UnhandledTapWebContentsObserver() override;
void set_device_scale_factor(float factor) { device_scale_factor_ = factor; }
float device_scale_factor() const { return device_scale_factor_; }
void set_unhandled_tap_callback(UnhandledTapCallback callback) {
unhandled_tap_callback_ = callback;
}
UnhandledTapCallback unhandled_tap_callback() const {
return unhandled_tap_callback_;
}
private:
friend class content::WebContentsUserData<UnhandledTapWebContentsObserver>;
// Scale factor to convert from dips to pixels for tap coordinates when
// calling back through the given |unhandled_tap_callback_|.
float device_scale_factor_;
UnhandledTapCallback unhandled_tap_callback_;
WEB_CONTENTS_USER_DATA_KEY_DECL();
DISALLOW_COPY_AND_ASSIGN(UnhandledTapWebContentsObserver);
};
} // namespace contextual_search
#endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_UNHANDLED_TAP_WEB_CONTENTS_OBSERVER_H_