Skip to content

Commit

Permalink
Adapt EmbedLiteViewBaseChild
Browse files Browse the repository at this point in the history
  • Loading branch information
rainemak committed Dec 19, 2016
1 parent 7f20b6d commit 817c7a6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 60 deletions.
112 changes: 55 additions & 57 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseChild.cpp
Expand Up @@ -13,6 +13,7 @@
#include "nsEmbedCID.h"
#include "nsIBaseWindow.h"
#include "EmbedLitePuppetWidget.h"
#include "nsGlobalWindow.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDOMWindow.h"
#include "nsNetUtil.h"
Expand Down Expand Up @@ -83,6 +84,10 @@ EmbedLiteViewBaseChild::EmbedLiteViewBaseChild(const uint32_t& aWindowId, const
: mId(aId)
, mOuterId(0)
, mWindow(nullptr)
, mWebBrowser(nullptr)
, mChrome(nullptr)
, mDOMWindow(nullptr)
, mWebNavigation(nullptr)
, mViewResized(false)
, mWindowObserverRegistered(false)
, mIsFocused(false)
Expand Down Expand Up @@ -219,11 +224,16 @@ EmbedLiteViewBaseChild::InitGeckoWindow(const uint32_t& parentId, const bool& is
NS_ERROR("Failed to get the content DOM window!");
}

mDOMWindow = do_QueryInterface(domWindow);
if (!mDOMWindow) {
nsCOMPtr<nsPIDOMWindow> pWindow = do_QueryInterface(domWindow);
if(!pWindow) {
NS_ERROR("Got stuck with DOMWindow!");
}

mDOMWindow = do_QueryInterface(pWindow->GetPrivateRoot());
if (!mDOMWindow) {
NS_ERROR("Got stuck with root DOMWindow!");
}

mozilla::dom::AutoNoJSAPI nojsapi;
nsCOMPtr<nsIDOMWindowUtils> utils = do_GetInterface(mDOMWindow);
utils->GetOuterWindowID(&mOuterId);
Expand Down Expand Up @@ -501,7 +511,9 @@ bool EmbedLiteViewBaseChild::RecvScrollTo(const int &x, const int &y)
if (!mDOMWindow) {
return false;
}
mDOMWindow->ScrollTo(x, y);

nsGlobalWindow* window = nsGlobalWindow::Cast(mDOMWindow);
window->ScrollTo(x, y);
return true;
}

Expand All @@ -511,7 +523,8 @@ bool EmbedLiteViewBaseChild::RecvScrollBy(const int &x, const int &y)
return false;
}

mDOMWindow->ScrollBy(x, y);
nsGlobalWindow* window = nsGlobalWindow::Cast(mDOMWindow);
window->ScrollBy(x, y);
return true;
}

Expand All @@ -537,7 +550,10 @@ EmbedLiteViewBaseChild::RecvSetIsActive(const bool& aIsActive)
widget->SetActive(aIsActive);
}


mWebBrowser->SetIsActive(aIsActive);
// Do same stuff that there is in nsPresShell.cpp:10670

mWidget->Show(aIsActive);

nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(mWebBrowser);
Expand Down Expand Up @@ -799,8 +815,7 @@ EmbedLiteViewBaseChild::RecvHandleDoubleTap(const CSSPoint& aPoint,
const Modifiers &aModifiers,
const ScrollableLayerGuid& aGuid)
{
CSSPoint cssPoint = APZCCallbackHelper::ApplyCallbackTransform(
aPoint, aGuid, GetPresShellResolution());
CSSPoint cssPoint = APZCCallbackHelper::ApplyCallbackTransform(aPoint, aGuid);

for (unsigned int i = 0; i < mControllerListeners.Length(); i++) {
mControllerListeners[i]->HandleDoubleTap(cssPoint, aModifiers, aGuid);
Expand All @@ -825,14 +840,13 @@ EmbedLiteViewBaseChild::RecvHandleSingleTap(const CSSPoint& aPoint,
// this way we can get focus and actual compositing node working properly in future composition
nsPoint offset;
nsCOMPtr<nsIWidget> widget = mHelper->GetWidget(&offset);
WidgetCompositionEvent event(true, NS_COMPOSITION_END, widget);
WidgetCompositionEvent event(true, eCompositionEnd, widget);
InitEvent(event, nullptr);
APZCCallbackHelper::DispatchWidgetEvent(event);
mIMEComposing = false;
}

CSSPoint cssPoint = APZCCallbackHelper::ApplyCallbackTransform(
aPoint, aGuid, GetPresShellResolution());
CSSPoint cssPoint = APZCCallbackHelper::ApplyCallbackTransform(aPoint, aGuid);

for (unsigned int i = 0; i < mControllerListeners.Length(); i++) {
mControllerListeners[i]->HandleSingleTap(cssPoint, aModifiers, aGuid);
Expand All @@ -847,7 +861,8 @@ EmbedLiteViewBaseChild::RecvHandleSingleTap(const CSSPoint& aPoint,

if (sHandleDefaultAZPC.singleTap) {
LayoutDevicePoint pt = cssPoint * mWidget->GetDefaultScale();
APZCCallbackHelper::FireSingleTapEvent(pt, mHelper->WebWidget());
Modifiers m;
APZCCallbackHelper::FireSingleTapEvent(pt, m, mHelper->WebWidget());
}

return true;
Expand All @@ -858,8 +873,7 @@ EmbedLiteViewBaseChild::RecvHandleLongTap(const CSSPoint& aPoint,
const ScrollableLayerGuid& aGuid,
const uint64_t& aInputBlockId)
{
CSSPoint cssPoint = APZCCallbackHelper::ApplyCallbackTransform(
aPoint, aGuid, GetPresShellResolution());
CSSPoint cssPoint = APZCCallbackHelper::ApplyCallbackTransform(aPoint, aGuid);

for (unsigned int i = 0; i < mControllerListeners.Length(); i++) {
mControllerListeners[i]->HandleLongTap(cssPoint, 0, aGuid, aInputBlockId);
Expand Down Expand Up @@ -909,15 +923,15 @@ EmbedLiteViewBaseChild::RecvHandleTextEvent(const nsString& commit, const nsStri
}

if (StartComposite) {
WidgetCompositionEvent event(true, NS_COMPOSITION_START, widget);
WidgetCompositionEvent event(true, eCompositionStart, widget);
InitEvent(event, nullptr);
APZCCallbackHelper::DispatchWidgetEvent(event);
}

if (StartComposite || ChangeComposite || EndComposite) {

{
WidgetCompositionEvent event(true, NS_COMPOSITION_CHANGE, widget);
WidgetCompositionEvent event(true, eCompositionChange, widget);
InitEvent(event, nullptr);
event.mData = pushStr;

Expand All @@ -941,15 +955,15 @@ EmbedLiteViewBaseChild::RecvHandleTextEvent(const nsString& commit, const nsStri
nsFocusManager* DOMFocusManager = nsFocusManager::GetFocusManager();
nsIContent* mTarget = DOMFocusManager->GetFocusedContent();

InternalEditorInputEvent inputEvent(true, NS_EDITOR_INPUT, widget);
InternalEditorInputEvent inputEvent(true, eEditorInput, widget);
inputEvent.time = static_cast<uint64_t>(PR_Now() / 1000);
inputEvent.mIsComposing = mIMEComposing;
nsEventStatus status = nsEventStatus_eIgnore;
ps->HandleEventWithTarget(&inputEvent, nullptr, mTarget, &status);
}

if (EndComposite) {
WidgetCompositionEvent event(true, NS_COMPOSITION_END, widget);
WidgetCompositionEvent event(true, eCompositionEnd, widget);
InitEvent(event, nullptr);
APZCCallbackHelper::DispatchWidgetEvent(event);
}
Expand Down Expand Up @@ -1029,24 +1043,24 @@ EmbedLiteViewBaseChild::RecvInputDataTouchEvent(const ScrollableLayerGuid& aGuid
{
LOGT();
WidgetTouchEvent localEvent;

if (!mHelper->ConvertMutiTouchInputToEvent(aData, localEvent)) {
return true;
}

APZCCallbackHelper::ApplyCallbackTransform(localEvent, aGuid,
mWidget->GetDefaultScale(), GetPresShellResolution());
APZCCallbackHelper::ApplyCallbackTransform(localEvent, aGuid, mWidget->GetDefaultScale());
nsEventStatus status =
APZCCallbackHelper::DispatchWidgetEvent(localEvent);

nsCOMPtr<nsPIDOMWindow> outerWindow = do_GetInterface(mWebNavigation);
nsCOMPtr<nsPIDOMWindow> innerWindow = outerWindow->GetCurrentInnerWindow();
if (innerWindow && innerWindow->HasTouchEventListeners()) {
if (innerWindow /*&& innerWindow->HasTouchEventListeners()*/ ) {
SendContentReceivedInputBlock(aGuid, mPendingTouchPreventedBlockId,
nsIPresShell::gPreventMouseEvents);
false /*nsIPresShell::gPreventMouseEvents*/);
}
mPendingTouchPreventedBlockId = aInputBlockId;

static bool sDispatchMouseEvents;
static bool sDispatchMouseEvents = false;
static bool sDispatchMouseEventsCached = false;
if (!sDispatchMouseEventsCached) {
sDispatchMouseEventsCached = true;
Expand Down Expand Up @@ -1125,22 +1139,15 @@ EmbedLiteViewBaseChild::OnSecurityChanged(const char* aStatus, uint32_t aState)
NS_IMETHODIMP
EmbedLiteViewBaseChild::OnFirstPaint(int32_t aX, int32_t aY)
{
nsresult rv = NS_OK;
nsCOMPtr <nsIDOMWindow> window;
rv = mWebBrowser->GetContentDOMWindow(getter_AddRefs(window));

nsCOMPtr<nsIDOMDocument> ddoc;
window->GetDocument(getter_AddRefs(ddoc));
NS_ENSURE_TRUE(ddoc, NS_OK);

nsCOMPtr<nsIDocument> doc;
doc = do_QueryInterface(ddoc, &rv);
NS_ENSURE_TRUE(doc, NS_OK);

nsIPresShell* presShell = doc->GetShell();
if (presShell) {
nscolor bgcolor = presShell->GetCanvasBackground();
Unused << SendSetBackgroundColor(bgcolor);
if (mDOMWindow) {
nsCOMPtr<nsIDocShell> docShell = mDOMWindow->GetDocShell();
if (docShell) {
nsCOMPtr<nsIPresShell> presShell = docShell->GetPresShell();
if (presShell) {
nscolor bgcolor = presShell->GetCanvasBackground();
Unused << SendSetBackgroundColor(bgcolor);
}
}
}

return SendOnFirstPaint(aX, aY) ? NS_OK : NS_ERROR_FAILURE;
Expand Down Expand Up @@ -1174,46 +1181,37 @@ EmbedLiteViewBaseChild::OnUpdateDisplayPort()
bool
EmbedLiteViewBaseChild::GetScrollIdentifiers(uint32_t *aPresShellIdOut, mozilla::layers::FrameMetrics::ViewID *aViewIdOut)
{
nsCOMPtr<nsIDOMDocument> domDoc;
mWebNavigation->GetDocument(getter_AddRefs(domDoc));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
nsCOMPtr<nsIDocument> doc(mHelper->GetDocument());
return APZCCallbackHelper::GetOrCreateScrollIdentifiers(doc->GetDocumentElement(), aPresShellIdOut, aViewIdOut);
}

float
EmbedLiteViewBaseChild::GetPresShellResolution() const
{
nsCOMPtr<nsIDocument> document(GetDocument());
nsCOMPtr<nsIDocument> document(mHelper->GetDocument());
nsIPresShell* shell = document->GetShell();
if (!shell) {
return 1.0f;
}
return shell->GetResolution();
}

already_AddRefed<nsIDocument>
EmbedLiteViewBaseChild::GetDocument() const
{
nsCOMPtr<nsIDOMDocument> domDoc;
mWebNavigation->GetDocument(getter_AddRefs(domDoc));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
return doc.forget();
}

void
EmbedLiteViewBaseChild::DispatchSynthesizedMouseEvent(const WidgetTouchEvent& aEvent)
{
if (nsIPresShell::gPreventMouseEvents) {
return;
}
// TODO : how should we handle now global mouse event prevent.
// if (nsIPresShell::gPreventMouseEvents) {
// return;
// }

if (aEvent.message == NS_TOUCH_END) {
if (aEvent.mMessage == eTouchEnd) {
int64_t time = aEvent.time;
MOZ_ASSERT(aEvent.touches.Length() == 1);
LayoutDevicePoint pt = aEvent.touches[0]->mRefPoint;
APZCCallbackHelper::DispatchSynthesizedMouseEvent(NS_MOUSE_MOVE, time, pt, aEvent.widget);
APZCCallbackHelper::DispatchSynthesizedMouseEvent(NS_MOUSE_BUTTON_DOWN, time, pt, aEvent.widget);
APZCCallbackHelper::DispatchSynthesizedMouseEvent(NS_MOUSE_BUTTON_UP, time, pt, aEvent.widget);
Modifiers m;
APZCCallbackHelper::DispatchSynthesizedMouseEvent(eMouseMove, time, pt, m, aEvent.widget);
APZCCallbackHelper::DispatchSynthesizedMouseEvent(eMouseDown, time, pt, m, aEvent.widget);
APZCCallbackHelper::DispatchSynthesizedMouseEvent(eMouseUp, time, pt, m, aEvent.widget);
}
}

Expand Down
4 changes: 1 addition & 3 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseChild.h
Expand Up @@ -164,8 +164,6 @@ class EmbedLiteViewBaseChild : public PEmbedLiteViewChild,

// Get the pres shell resolution of the document in this tab.
float GetPresShellResolution() const;
// Get the Document for the top-level window in this tab.
already_AddRefed<nsIDocument> GetDocument() const;

void DispatchSynthesizedMouseEvent(const WidgetTouchEvent&);

Expand All @@ -187,7 +185,7 @@ class EmbedLiteViewBaseChild : public PEmbedLiteViewChild,
nsCOMPtr<nsIWidget> mWidget;
nsCOMPtr<nsIWebBrowser> mWebBrowser;
RefPtr<WebBrowserChrome> mChrome;
nsCOMPtr<nsIDOMWindow> mDOMWindow;
nsCOMPtr<nsPIDOMWindow> mDOMWindow;
nsCOMPtr<nsIWebNavigation> mWebNavigation;
bool mViewResized;
bool mWindowObserverRegistered;
Expand Down

0 comments on commit 817c7a6

Please sign in to comment.