2011-02-23 04:45:13 +01:00
|
|
|
// Copyright (c) 2011 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.
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/dom_event_impl.h"
|
|
|
|
#include "libcef/cef_thread.h"
|
|
|
|
#include "libcef/dom_document_impl.h"
|
2011-02-23 04:45:13 +01:00
|
|
|
|
|
|
|
#include "base/logging.h"
|
2013-02-26 00:44:37 +01:00
|
|
|
#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
|
2011-02-23 04:45:13 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMEvent.h"
|
|
|
|
|
|
|
|
using WebKit::WebDOMEvent;
|
|
|
|
using WebKit::WebString;
|
|
|
|
|
|
|
|
|
|
|
|
CefDOMEventImpl::CefDOMEventImpl(CefRefPtr<CefDOMDocumentImpl> document,
|
|
|
|
const WebKit::WebDOMEvent& event)
|
2012-01-10 00:46:23 +01:00
|
|
|
: document_(document),
|
|
|
|
event_(event) {
|
2011-02-23 04:45:13 +01:00
|
|
|
DCHECK(!event_.isNull());
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefDOMEventImpl::~CefDOMEventImpl() {
|
2011-02-23 04:45:13 +01:00
|
|
|
REQUIRE_UIT();
|
|
|
|
DCHECK(event_.isNull());
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefString CefDOMEventImpl::GetType() {
|
2011-02-23 04:45:13 +01:00
|
|
|
CefString str;
|
|
|
|
if (!VerifyContext())
|
|
|
|
return str;
|
|
|
|
|
|
|
|
const WebString& type = event_.type();
|
|
|
|
if (!type.isNull())
|
|
|
|
str = type;
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefDOMEventImpl::Category CefDOMEventImpl::GetCategory() {
|
2011-02-23 04:45:13 +01:00
|
|
|
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;
|
|
|
|
if (event_.isBeforeLoadEvent())
|
|
|
|
flags |= DOM_EVENT_CATEGORY_BEFORE_LOAD;
|
|
|
|
|
|
|
|
return static_cast<Category>(flags);
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefDOMEventImpl::Phase CefDOMEventImpl::GetPhase() {
|
2011-02-23 04:45:13 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefDOMEventImpl::CanBubble() {
|
2011-02-23 04:45:13 +01:00
|
|
|
if (!VerifyContext())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return event_.bubbles();
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefDOMEventImpl::CanCancel() {
|
2011-02-23 04:45:13 +01:00
|
|
|
if (!VerifyContext())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return event_.cancelable();
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRefPtr<CefDOMDocument> CefDOMEventImpl::GetDocument() {
|
2011-02-23 04:45:13 +01:00
|
|
|
if (!VerifyContext())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return document_.get();
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRefPtr<CefDOMNode> CefDOMEventImpl::GetTarget() {
|
2011-02-23 04:45:13 +01:00
|
|
|
if (!VerifyContext())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return document_->GetOrCreateNode(event_.target());
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
CefRefPtr<CefDOMNode> CefDOMEventImpl::GetCurrentTarget() {
|
2011-02-23 04:45:13 +01:00
|
|
|
if (!VerifyContext())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return document_->GetOrCreateNode(event_.currentTarget());
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
void CefDOMEventImpl::Detach() {
|
2011-02-23 15:56:10 +01:00
|
|
|
// If you hit this assert it means that you are keeping references to this
|
|
|
|
// event object beyond the valid scope.
|
2012-01-10 00:46:23 +01:00
|
|
|
DCHECK_EQ(GetRefCt(), 1);
|
2011-02-23 15:56:10 +01:00
|
|
|
|
2011-02-23 04:45:13 +01:00
|
|
|
document_ = NULL;
|
|
|
|
event_.assign(WebDOMEvent());
|
|
|
|
}
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
bool CefDOMEventImpl::VerifyContext() {
|
2011-02-23 04:45:13 +01:00
|
|
|
if (!document_.get()) {
|
|
|
|
NOTREACHED();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!document_->VerifyContext())
|
|
|
|
return false;
|
2012-01-10 00:46:23 +01:00
|
|
|
if (event_.isNull()) {
|
2011-02-23 04:45:13 +01:00
|
|
|
NOTREACHED();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|