Skip to content

Commit

Permalink
[embedlite] Add support for setting view margins.
Browse files Browse the repository at this point in the history
The idea is that the view does not necessarily have to cover the whole
window. An example of such use case is when the browser wants to show
some sort of overlay chrome on top of the view. In such case we don't
want to resize the compositing surface, but we'd like the engine to
avoid painting any content on the area covered by chrome.

Signed-off-by: Piotr Tworek <piotr.tworek@jollamobile.com>
  • Loading branch information
tworaz committed Sep 29, 2015
1 parent dc89a06 commit acbc7d2
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 16 deletions.
6 changes: 6 additions & 0 deletions embedding/embedlite/EmbedLiteView.cpp
Expand Up @@ -205,6 +205,12 @@ EmbedLiteView::RenderToImage(unsigned char* aData, int imgW, int imgH, int strid
return mWindow->RenderToImage(aData, imgW, imgH, stride, depth);
}

void
EmbedLiteView::SetMargins(int top, int right, int bottom, int left)
{
unused << mViewParent->SendSetMargins(top, right, bottom, left);
}

void
EmbedLiteView::SetViewSize(int width, int height)
{
Expand Down
2 changes: 2 additions & 0 deletions embedding/embedlite/EmbedLiteView.h
Expand Up @@ -97,6 +97,8 @@ class EmbedLiteView
virtual void PinchUpdate(int x, int y, float scale);
virtual void PinchEnd(int x, int y, float scale);

virtual void SetMargins(int top, int right, int bottom, int left);

// Setup renderable view size
virtual void SetViewSize(int width, int height); // XXX: Remove, EmbedLiteViews always cover the whole window

Expand Down
1 change: 1 addition & 0 deletions embedding/embedlite/PEmbedLiteView.ipdl
Expand Up @@ -39,6 +39,7 @@ child:
SetIsActive(bool aIsActive);
SetIsFocused(bool aIsFocused);
SetThrottlePainting(bool aThrottle);
SetMargins(int top, int right, int bottom, int left);
SuspendTimeouts();
ResumeTimeouts();
AsyncScrollDOMEvent(gfxRect contentRect, gfxSize scrollSize);
Expand Down
25 changes: 24 additions & 1 deletion embedding/embedlite/embedshared/EmbedLitePuppetWidget.cpp
Expand Up @@ -90,6 +90,7 @@ EmbedLitePuppetWidget::EmbedLitePuppetWidget(EmbedLiteWindowBaseChild* window,
, mIMEComposing(false)
, mParent(nullptr)
, mRotation(ROTATION_0)
, mMargins(0, 0, 0, 0)
{
MOZ_COUNT_CTOR(EmbedLitePuppetWidget);
LOGT("this:%p", this);
Expand Down Expand Up @@ -169,6 +170,24 @@ EmbedLitePuppetWidget::SetRotation(mozilla::ScreenRotation rotation)
#endif
}

void
EmbedLitePuppetWidget::SetMargins(const nsIntMargin& margins)
{
mMargins = margins;
for (ChildrenArray::size_type i = 0; i < mChildren.Length(); i++) {
mChildren[i]->SetMargins(margins);
}
}

void
EmbedLitePuppetWidget::UpdateSize()
{
Resize(mNaturalBounds.width, mNaturalBounds.height, true);
#ifdef DEBUG
DumpWidgetTree();
#endif
}

NS_IMETHODIMP
EmbedLitePuppetWidget::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
Expand All @@ -189,6 +208,7 @@ EmbedLitePuppetWidget::Create(nsIWidget* aParent,
}
mRotation = parent ? parent->mRotation : mRotation;
mBounds = parent ? parent->mBounds : aRect;
mMargins = parent ? parent->mMargins : mMargins;
mNaturalBounds = parent ? parent->mNaturalBounds : aRect;

BaseCreate(aParent, aRect, aInitData);
Expand Down Expand Up @@ -315,6 +335,7 @@ EmbedLitePuppetWidget::Resize(double aWidth, double aHeight, bool aRepaint)
} else {
mBounds.SizeTo(nsIntSize(NSToIntRound(aHeight), NSToIntRound(aWidth)));
}
mBounds.Deflate(mMargins);

for (ObserverArray::size_type i = 0; i < mObservers.Length(); ++i) {
mObservers[i]->WidgetBoundsChanged(mBounds);
Expand Down Expand Up @@ -770,11 +791,13 @@ EmbedLitePuppetWidget::LogWidget(EmbedLitePuppetWidget *widget, int index, int i
{
char spaces[] = " ";
spaces[indent < 20 ? indent : 20] = 0;
printf_stderr("%s [% 2d] [%p] size: [(%d, %d), (%3d, %3d)], "
printf_stderr("%s [% 2d] [%p] size: [(%d, %d), (%3d, %3d)], margins: [%d, %d, %d, %d], "
"visible: %d, type: %d, rotation: %d, observers: %zu\n",
spaces, index, widget,
widget->mBounds.x, widget->mBounds.y,
widget->mBounds.width, widget->mBounds.height,
widget->mMargins.top, widget->mMargins.right,
widget->mMargins.bottom, widget->mMargins.left,
widget->mVisible, widget->mWindowType,
widget->mRotation * 90, widget->mObservers.Length());
}
Expand Down
3 changes: 3 additions & 0 deletions embedding/embedlite/embedshared/EmbedLitePuppetWidget.h
Expand Up @@ -173,6 +173,8 @@ class EmbedLitePuppetWidget : public nsBaseWidget
virtual nsIWidget* GetParent(void) override;

void SetRotation(mozilla::ScreenRotation);
void SetMargins(const nsIntMargin& marins);
void UpdateSize();

void AddObserver(EmbedLitePuppetWidgetObserver*);
void RemoveObserver(EmbedLitePuppetWidgetObserver*);
Expand Down Expand Up @@ -211,6 +213,7 @@ class EmbedLitePuppetWidget : public nsBaseWidget
EmbedLitePuppetWidget* mParent;
mozilla::ScreenRotation mRotation;
nsIntRect mNaturalBounds;
nsIntMargin mMargins;
ObserverArray mObservers;
};

Expand Down
46 changes: 34 additions & 12 deletions embedding/embedlite/embedshared/EmbedLiteViewBaseChild.cpp
Expand Up @@ -27,6 +27,7 @@
#include "nsIDOMDocument.h"
#include "nsIPresShell.h"
#include "nsIScriptSecurityManager.h"
#include "nsISelectionController.h"
#include "mozilla/Preferences.h"
#include "EmbedLiteAppService.h"
#include "nsIWidgetListener.h"
Expand Down Expand Up @@ -83,6 +84,7 @@ EmbedLiteViewBaseChild::EmbedLiteViewBaseChild(const uint32_t& aWindowId, const
, mWindow(nullptr)
, mViewResized(false)
, mWindowObserverRegistered(false)
, mMargins(0, 0, 0, 0)
, mDispatchSynthMouseEvents(true)
, mIMEComposing(false)
, mPendingTouchPreventedBlockId(0)
Expand All @@ -109,12 +111,12 @@ EmbedLiteViewBaseChild::~EmbedLiteViewBaseChild()
NS_ASSERTION(mControllerListeners.IsEmpty(), "Controller listeners list is not empty...");
if (mInitWindowTask) {
mInitWindowTask->Cancel();
mInitWindowTask = nullptr;
}
if (mWindowObserverRegistered) {
mWindow->GetWidget()->RemoveObserver(this);
}
mWindow = nullptr;
mInitWindowTask = nullptr;
}

void
Expand All @@ -136,8 +138,9 @@ bool EmbedLiteViewBaseChild::RecvDestroy()
mHelper->Unload();
if (mChrome)
mChrome->RemoveEventHandler();
if (mWidget)
if (mWidget) {
mWidget->Destroy();
}
mWebBrowser = nullptr;
mChrome = nullptr;
mDOMWindow = nullptr;
Expand All @@ -156,10 +159,6 @@ EmbedLiteViewBaseChild::InitGeckoWindow(const uint32_t& parentId, const bool& is
LOGT("parentID: %u", parentId);
nsresult rv;

MOZ_ASSERT(mWindow->GetWidget());
mWindow->GetWidget()->AddObserver(this);
mWindowObserverRegistered = true;

mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
return;
Expand All @@ -180,6 +179,7 @@ EmbedLiteViewBaseChild::InitGeckoWindow(const uint32_t& parentId, const bool& is
rv = mWidget->Create(mWindow->GetWidget(), 0, naturalBounds, &widgetInit);
if (NS_FAILED(rv)) {
NS_ERROR("Failed to create widget for EmbedLiteView");
mWidget = nullptr;
return;
}

Expand Down Expand Up @@ -264,6 +264,16 @@ EmbedLiteViewBaseChild::InitGeckoWindow(const uint32_t& parentId, const bool& is
gfxSize size(bounds.width, bounds.height);
mHelper->ReportSizeUpdate(size);

MOZ_ASSERT(mWindow->GetWidget());
mWindow->GetWidget()->AddObserver(this);
mWindowObserverRegistered = true;

if (mMargins != nsIntMargin()) {
EmbedLitePuppetWidget* widget = static_cast<EmbedLitePuppetWidget*>(mWidget.get());
widget->SetMargins(mMargins);
widget->UpdateSize();
}

OnGeckoWindowInitialized();

unused << SendInitialized();
Expand Down Expand Up @@ -339,9 +349,9 @@ EmbedLiteViewBaseChild::ZoomToRect(const uint32_t& aPresShellId,

bool
EmbedLiteViewBaseChild::UpdateZoomConstraints(const uint32_t& aPresShellId,
const ViewID& aViewId,
const bool& aIsRoot,
const ZoomConstraints& aConstraints)
const ViewID& aViewId,
const bool& aIsRoot,
const ZoomConstraints& aConstraints)
{
return SendUpdateZoomConstraints(aPresShellId,
aViewId,
Expand Down Expand Up @@ -528,6 +538,19 @@ EmbedLiteViewBaseChild::RecvSetThrottlePainting(const bool& aThrottle)
return true;
}

bool
EmbedLiteViewBaseChild::RecvSetMargins(const int& aTop, const int& aRight,
const int& aBottom, const int& aLeft)
{
mMargins = nsIntMargin(aTop, aRight, aBottom, aLeft);
if (mWidget) {
EmbedLitePuppetWidget* widget = static_cast<EmbedLitePuppetWidget*>(mWidget.get());
widget->SetMargins(mMargins);
widget->UpdateSize();
}
return true;
}

bool
EmbedLiteViewBaseChild::RecvSuspendTimeouts()
{
Expand Down Expand Up @@ -1087,12 +1110,11 @@ void EmbedLiteViewBaseChild::WidgetBoundsChanged(const nsIntRect& aSize)
LOGT("sz[%g,%g]", aSize.width, aSize.height);
mViewResized = true;

if (!mWebBrowser) {
return;
}
MOZ_ASSERT(mHelper && mWebBrowser);

nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(mWebBrowser);
baseWindow->SetPositionAndSize(0, 0, aSize.width, aSize.height, true);
baseWindow->SetVisibility(true);

gfxSize size(aSize.width, aSize.height);
mHelper->ReportSizeUpdate(size);
Expand Down
4 changes: 3 additions & 1 deletion embedding/embedlite/embedshared/EmbedLiteViewBaseChild.h
Expand Up @@ -121,6 +121,7 @@ class EmbedLiteViewBaseChild : public PEmbedLiteViewChild,
virtual bool RecvSetIsActive(const bool&) override;
virtual bool RecvSetIsFocused(const bool&) override;
virtual bool RecvSetThrottlePainting(const bool&) override;
virtual bool RecvSetMargins(const int&, const int&, const int&, const int&) override;
virtual bool RecvSuspendTimeouts() override;
virtual bool RecvResumeTimeouts() override;
virtual bool RecvLoadFrameScript(const nsString&) override;
Expand Down Expand Up @@ -155,7 +156,7 @@ class EmbedLiteViewBaseChild : public PEmbedLiteViewChild,
virtual void OnGeckoWindowInitialized() {}

// EmbedLitePuppetWidgetObserver
virtual void WidgetBoundsChanged(const nsIntRect&) override;
void WidgetBoundsChanged(const nsIntRect&) override;

private:
friend class TabChildHelper;
Expand All @@ -176,6 +177,7 @@ class EmbedLiteViewBaseChild : public PEmbedLiteViewChild,
nsCOMPtr<nsIWebNavigation> mWebNavigation;
bool mViewResized;
bool mWindowObserverRegistered;
nsIntMargin mMargins;

nsRefPtr<TabChildHelper> mHelper;
bool mDispatchSynthMouseEvents;
Expand Down
Expand Up @@ -69,7 +69,7 @@ bool EmbedLiteWindowBaseChild::RecvSetContentOrientation(const mozilla::ScreenRo
if (mWidget) {
EmbedLitePuppetWidget* widget = static_cast<EmbedLitePuppetWidget*>(mWidget.get());
widget->SetRotation(aRotation);
widget->Resize(mSize.width, mSize.height, true);
widget->UpdateSize();
}
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion embedding/embedlite/embedthread/EmbedContentController.cpp
Expand Up @@ -112,7 +112,8 @@ void EmbedContentController::SendAsyncScrollDOMEvent(bool aIsRoot,
aScrollableSize.width, aScrollableSize.height);
gfxRect rect(aContentRect.x, aContentRect.y, aContentRect.width, aContentRect.height);
gfxSize size(aScrollableSize.width, aScrollableSize.height);
if (mRenderFrame && aIsRoot && !GetListener()->SendAsyncScrollDOMEvent(rect, size)) {

if (mRenderFrame && !GetListener()->SendAsyncScrollDOMEvent(rect, size)) {
unused << mRenderFrame->SendAsyncScrollDOMEvent(rect, size);
}
}
Expand Down

0 comments on commit acbc7d2

Please sign in to comment.