summaryrefslogtreecommitdiffstats
path: root/mojo/examples
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-25 04:54:52 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-25 04:54:52 +0000
commit26a32e5d3515b013797a7ddffa1be5c6274dcf1c (patch)
tree8f07e618dceaceee35b2cd2c4be3e0a838f33a63 /mojo/examples
parentac7f8b34f6836ac3d939dad34137f393c5e13114 (diff)
downloadchromium_src-26a32e5d3515b013797a7ddffa1be5c6274dcf1c.zip
chromium_src-26a32e5d3515b013797a7ddffa1be5c6274dcf1c.tar.gz
chromium_src-26a32e5d3515b013797a7ddffa1be5c6274dcf1c.tar.bz2
Mojo: Partially implement input events in html_viewer.
This gets positioned mouse events working, including hover effects and selection. This does not solve the navigation issue though; we crash on a CHECK in url_loader_impl.cc. BUG=387172 Review URL: https://codereview.chromium.org/348373003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279591 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/examples')
-rw-r--r--mojo/examples/html_viewer/DEPS5
-rw-r--r--mojo/examples/html_viewer/html_document_view.cc87
-rw-r--r--mojo/examples/html_viewer/html_document_view.h9
-rw-r--r--mojo/examples/window_manager/window_manager.cc2
4 files changed, 99 insertions, 4 deletions
diff --git a/mojo/examples/html_viewer/DEPS b/mojo/examples/html_viewer/DEPS
index 83af040..059a405 100644
--- a/mojo/examples/html_viewer/DEPS
+++ b/mojo/examples/html_viewer/DEPS
@@ -1,6 +1,7 @@
include_rules = [
- "+skia",
"+net/base",
- "+third_party/skia/include",
+ "+skia",
"+third_party/WebKit/public",
+ "+third_party/skia/include",
+ "+ui/events",
]
diff --git a/mojo/examples/html_viewer/html_document_view.cc b/mojo/examples/html_viewer/html_document_view.cc
index da21d3d..b234c15 100644
--- a/mojo/examples/html_viewer/html_document_view.cc
+++ b/mojo/examples/html_viewer/html_document_view.cc
@@ -8,14 +8,17 @@
#include "base/location.h"
#include "base/single_thread_task_runner.h"
#include "base/thread_task_runner_handle.h"
+#include "base/time/time.h"
#include "mojo/examples/html_viewer/webstoragenamespace_impl.h"
#include "mojo/examples/html_viewer/weburlloader_impl.h"
#include "mojo/services/public/cpp/view_manager/node.h"
#include "mojo/services/public/cpp/view_manager/view.h"
+#include "mojo/services/public/cpp/view_manager/view_observer.h"
#include "skia/ext/refptr.h"
#include "third_party/WebKit/public/web/WebConsoleMessage.h"
#include "third_party/WebKit/public/web/WebDocument.h"
#include "third_party/WebKit/public/web/WebElement.h"
+#include "third_party/WebKit/public/web/WebInputEvent.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebScriptSource.h"
#include "third_party/WebKit/public/web/WebSettings.h"
@@ -23,11 +26,42 @@
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkDevice.h"
+#include "ui/events/event_constants.h"
namespace mojo {
namespace examples {
namespace {
+int EventFlagsToWebEventModifiers(int flags) {
+ int modifiers = 0;
+
+ if (flags & ui::EF_SHIFT_DOWN)
+ modifiers |= blink::WebInputEvent::ShiftKey;
+ if (flags & ui::EF_CONTROL_DOWN)
+ modifiers |= blink::WebInputEvent::ControlKey;
+ if (flags & ui::EF_ALT_DOWN)
+ modifiers |= blink::WebInputEvent::AltKey;
+ // TODO(beng): MetaKey/META_MASK
+ if (flags & ui::EF_LEFT_MOUSE_BUTTON)
+ modifiers |= blink::WebInputEvent::LeftButtonDown;
+ if (flags & ui::EF_MIDDLE_MOUSE_BUTTON)
+ modifiers |= blink::WebInputEvent::MiddleButtonDown;
+ if (flags & ui::EF_RIGHT_MOUSE_BUTTON)
+ modifiers |= blink::WebInputEvent::RightButtonDown;
+ if (flags & ui::EF_CAPS_LOCK_DOWN)
+ modifiers |= blink::WebInputEvent::CapsLockOn;
+ return modifiers;
+}
+
+int GetClickCount(int flags) {
+ if (flags & ui::EF_IS_TRIPLE_CLICK)
+ return 3;
+ else if (flags & ui::EF_IS_DOUBLE_CLICK)
+ return 2;
+
+ return 1;
+}
+
void ConfigureSettings(blink::WebSettings* settings) {
settings->setAcceleratedCompositingEnabled(false);
settings->setDefaultFixedFontSize(13);
@@ -44,9 +78,12 @@ HTMLDocumentView::HTMLDocumentView(view_manager::ViewManager* view_manager)
web_view_(NULL),
repaint_pending_(false),
weak_factory_(this) {
+ view_->AddObserver(this);
}
HTMLDocumentView::~HTMLDocumentView() {
+ view_->RemoveObserver(this);
+
if (web_view_)
web_view_->close();
}
@@ -111,6 +148,56 @@ void HTMLDocumentView::didAddMessageToConsole(
printf("### console: %s\n", std::string(message.text.utf8()).c_str());
}
+void HTMLDocumentView::OnViewInputEvent(view_manager::View* view,
+ const EventPtr& event) {
+ if (event->action != ui::ET_MOUSE_PRESSED &&
+ event->action != ui::ET_MOUSE_RELEASED &&
+ event->action != ui::ET_MOUSE_ENTERED &&
+ event->action != ui::ET_MOUSE_EXITED &&
+ event->action != ui::ET_MOUSE_MOVED &&
+ event->action != ui::ET_MOUSE_DRAGGED) {
+ return;
+ }
+
+ blink::WebMouseEvent web_event;
+ web_event.x = event->location->x;
+ web_event.y = event->location->y;
+
+ web_event.modifiers = EventFlagsToWebEventModifiers(event->flags);
+ web_event.timeStampSeconds =
+ base::TimeDelta::FromInternalValue(event->time_stamp).InSecondsF();
+
+ web_event.button = blink::WebMouseEvent::ButtonNone;
+ if (event->flags & ui::EF_LEFT_MOUSE_BUTTON)
+ web_event.button = blink::WebMouseEvent::ButtonLeft;
+ if (event->flags & ui::EF_MIDDLE_MOUSE_BUTTON)
+ web_event.button = blink::WebMouseEvent::ButtonMiddle;
+ if (event->flags & ui::EF_RIGHT_MOUSE_BUTTON)
+ web_event.button = blink::WebMouseEvent::ButtonRight;
+
+ switch (event->action) {
+ case ui::ET_MOUSE_PRESSED:
+ web_event.type = blink::WebInputEvent::MouseDown;
+ web_event.clickCount = GetClickCount(event->flags);
+ break;
+ case ui::ET_MOUSE_RELEASED:
+ web_event.type = blink::WebInputEvent::MouseUp;
+ web_event.clickCount = GetClickCount(event->flags);
+ break;
+ case ui::ET_MOUSE_ENTERED:
+ case ui::ET_MOUSE_EXITED:
+ case ui::ET_MOUSE_MOVED:
+ case ui::ET_MOUSE_DRAGGED:
+ web_event.type = blink::WebInputEvent::MouseMove;
+ break;
+ default:
+ NOTIMPLEMENTED() << "Received unexpected event: " << event->action;
+ break;
+ }
+
+ web_view_->handleInputEvent(web_event);
+}
+
void HTMLDocumentView::Repaint() {
repaint_pending_ = false;
diff --git a/mojo/examples/html_viewer/html_document_view.h b/mojo/examples/html_viewer/html_document_view.h
index 8bea2d2..772a903 100644
--- a/mojo/examples/html_viewer/html_document_view.h
+++ b/mojo/examples/html_viewer/html_document_view.h
@@ -5,7 +5,9 @@
#ifndef MOJO_EXAMPLES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_
#define MOJO_EXAMPLES_HTML_VIEWER_HTML_DOCUMENT_VIEW_H_
+#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
+#include "mojo/services/public/cpp/view_manager/view_observer.h"
#include "mojo/services/public/interfaces/network/url_loader.mojom.h"
#include "third_party/WebKit/public/web/WebFrameClient.h"
#include "third_party/WebKit/public/web/WebViewClient.h"
@@ -22,7 +24,8 @@ namespace examples {
// A view for a single HTML document.
class HTMLDocumentView : public blink::WebViewClient,
- public blink::WebFrameClient {
+ public blink::WebFrameClient,
+ public view_manager::ViewObserver {
public:
explicit HTMLDocumentView(view_manager::ViewManager* view_manager);
virtual ~HTMLDocumentView();
@@ -47,6 +50,10 @@ class HTMLDocumentView : public blink::WebViewClient,
unsigned source_line,
const blink::WebString& stack_trace);
+ // ViewObserver methods:
+ virtual void OnViewInputEvent(view_manager::View* view,
+ const EventPtr& event) OVERRIDE;
+
void Repaint();
view_manager::ViewManager* view_manager_;
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
index 0c5cb12..201af4c 100644
--- a/mojo/examples/window_manager/window_manager.cc
+++ b/mojo/examples/window_manager/window_manager.cc
@@ -118,7 +118,7 @@ class WindowManager : public Application,
ViewManager::Create(this, this);
}
- // Overridden from ViewObserver:
+ // Overridden from ViewObserver:
virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE {
if (event->action == ui::ET_MOUSE_RELEASED) {
std::string app_url;