cef/libcef/renderer/dom_event_impl.cc

155 lines
3.9 KiB
C++
Raw Normal View History

// Copyright (c) 2012 The Chromium Embedded Framework 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 "libcef/renderer/dom_event_impl.h"
#include "libcef/renderer/dom_document_impl.h"
#include "libcef/renderer/thread_util.h"
#include "base/logging.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/web/WebDOMEvent.h"
using blink::WebDOMEvent;
using blink::WebString;
CefDOMEventImpl::CefDOMEventImpl(CefRefPtr<CefDOMDocumentImpl> document,
const blink::WebDOMEvent& event)
: document_(document),
event_(event) {
DCHECK(!event_.isNull());
}
CefDOMEventImpl::~CefDOMEventImpl() {
CEF_REQUIRE_RT();
DCHECK(event_.isNull());
}
CefString CefDOMEventImpl::GetType() {
CefString str;
if (!VerifyContext())
return str;
const WebString& type = event_.type();
if (!type.isNull())
str = type;
return str;
}
CefDOMEventImpl::Category CefDOMEventImpl::GetCategory() {
if (!VerifyContext())
return DOM_EVENT_CATEGORY_UNKNOWN;
int flags = 0;
if (event_.isUIEvent())
flags |= DOM_EVENT_CATEGORY_UI;
if (event_.isMouseEvent())
flags |= DOM_EVENT_CATEGORY_MOUSE;
if (event_.isMutationEvent())
flags |= DOM_EVENT_CATEGORY_MUTATION;
if (event_.isKeyboardEvent())
flags |= DOM_EVENT_CATEGORY_KEYBOARD;
if (event_.isTextEvent())
flags |= DOM_EVENT_CATEGORY_TEXT;
if (event_.isCompositionEvent())
flags |= DOM_EVENT_CATEGORY_COMPOSITION;
if (event_.isDragEvent())
flags |= DOM_EVENT_CATEGORY_DRAG;
if (event_.isClipboardEvent())
flags |= DOM_EVENT_CATEGORY_CLIPBOARD;
if (event_.isMessageEvent())
flags |= DOM_EVENT_CATEGORY_MESSAGE;
if (event_.isWheelEvent())
flags |= DOM_EVENT_CATEGORY_WHEEL;
if (event_.isBeforeTextInsertedEvent())
flags |= DOM_EVENT_CATEGORY_BEFORE_TEXT_INSERTED;
if (event_.isOverflowEvent())
flags |= DOM_EVENT_CATEGORY_OVERFLOW;
if (event_.isPageTransitionEvent())
flags |= DOM_EVENT_CATEGORY_PAGE_TRANSITION;
if (event_.isPopStateEvent())
flags |= DOM_EVENT_CATEGORY_POPSTATE;
if (event_.isProgressEvent())
flags |= DOM_EVENT_CATEGORY_PROGRESS;
if (event_.isXMLHttpRequestProgressEvent())
flags |= DOM_EVENT_CATEGORY_XMLHTTPREQUEST_PROGRESS;
return static_cast<Category>(flags);
}
CefDOMEventImpl::Phase CefDOMEventImpl::GetPhase() {
if (!VerifyContext())
return DOM_EVENT_PHASE_UNKNOWN;
switch (event_.eventPhase()) {
case WebDOMEvent::CapturingPhase:
return DOM_EVENT_PHASE_CAPTURING;
case WebDOMEvent::AtTarget:
return DOM_EVENT_PHASE_AT_TARGET;
case WebDOMEvent::BubblingPhase:
return DOM_EVENT_PHASE_BUBBLING;
}
return DOM_EVENT_PHASE_UNKNOWN;
}
bool CefDOMEventImpl::CanBubble() {
if (!VerifyContext())
return false;
return event_.bubbles();
}
bool CefDOMEventImpl::CanCancel() {
if (!VerifyContext())
return false;
return event_.cancelable();
}
CefRefPtr<CefDOMDocument> CefDOMEventImpl::GetDocument() {
if (!VerifyContext())
return NULL;
return document_.get();
}
CefRefPtr<CefDOMNode> CefDOMEventImpl::GetTarget() {
if (!VerifyContext())
return NULL;
return document_->GetOrCreateNode(event_.target());
}
CefRefPtr<CefDOMNode> CefDOMEventImpl::GetCurrentTarget() {
if (!VerifyContext())
return NULL;
return document_->GetOrCreateNode(event_.currentTarget());
}
void CefDOMEventImpl::Detach() {
// If you hit this assert it means that you are keeping references to this
// event object beyond the valid scope.
Introduce the use of Chromium types (issue #1336). Changes to the CEF public API: - Add base::Bind, base::Callback, base::Lock, base::WeakPtr, scoped_refptr, scoped_ptr and supporting types. - Add include/wrapper/cef_closure_task.h helpers for converting a base::Closure to a CefTask. - Change CefRefPtr to extend scoped_refptr. -- Change CefBase method signatures to match RefCountedThreadSafeBase. - Change IMPLEMENT_REFCOUNTING to use base::AtomicRefCount*. -- Remove the CefAtomic* functions. -- IMPLEMENT_REFCOUNTING now enforces via a compile-time error that the correct class name was passed to the macro. - Change IMPLEMENT_LOCKING to use base::Lock. -- Remove the CefCriticalSection class. -- Deprecate the IMPLEMENT_LOCKING macro. -- base::Lock will DCHECK() in Debug builds if lock usage is reentrant. - Move include/internal/cef_tuple.h to include/base/cef_tuple.h. - Allow an empty |callback| parameter passed to CefBeginTracing. Changes to the CEF implementation: - Fix incorrect names passed to the IMPLEMENT_REFCOUNTING macro. - Fix instances of reentrant locking in the CefXmlObject and CefRequest implementations. - Remove use of the IMPLEMENT_LOCKING macro. Changes to cef_unittests: - Add tests/unittests/chromium_includes.h and always include it first from unit test .cc files to avoid name conflicts with Chromium types. - Fix wrong header include ordering. - Remove use of the IMPLEMENT_LOCKING macro. Changes to cefclient and cefsimple: - Use base::Bind and cef_closure_task.h instead of NewCefRunnable*. - Remove use of the IMPEMENT_LOCKING macro. - Fix incorrect/unnecessary locking. - Add additional runtime thread checks. - Windows: Perform actions on the UI thread instead of the main thread when running in multi-threaded-message-loop mode to avoid excessive locking. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1769 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
2014-07-15 00:18:51 +02:00
DCHECK(HasOneRef());
document_ = NULL;
event_.assign(WebDOMEvent());
}
bool CefDOMEventImpl::VerifyContext() {
if (!document_.get()) {
NOTREACHED();
return false;
}
if (!document_->VerifyContext())
return false;
if (event_.isNull()) {
NOTREACHED();
return false;
}
return true;
}