Skip to content

Commit

Permalink
Bug 669200 - Various widget changes to support two new types of plugi…
Browse files Browse the repository at this point in the history
…n widget. r=roc
  • Loading branch information
jmathies committed Nov 12, 2014
1 parent b66f6f1 commit a323270
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 92 deletions.
2 changes: 1 addition & 1 deletion layout/base/nsLayoutUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2597,7 +2597,7 @@ nsLayoutUtils::TransformFrameRectToAncestor(nsIFrame* aFrame,
static nsIntPoint GetWidgetOffset(nsIWidget* aWidget, nsIWidget*& aRootWidget) {
nsIntPoint offset(0, 0);
while ((aWidget->WindowType() == eWindowType_child ||
aWidget->WindowType() == eWindowType_plugin)) {
aWidget->IsPlugin())) {
nsIWidget* parent = aWidget->GetParent();
if (!parent) {
break;
Expand Down
2 changes: 1 addition & 1 deletion view/nsViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ nsViewManager::InvalidateWidgetArea(nsView *aWidgetView,
NS_ASSERTION(view != aWidgetView, "will recur infinitely");
nsWindowType type = childWidget->WindowType();
if (view && childWidget->IsVisible() && type != eWindowType_popup) {
NS_ASSERTION(type == eWindowType_plugin,
NS_ASSERTION(childWidget->IsPlugin(),
"Only plugin or popup widgets can be children!");

// We do not need to invalidate in plugin widgets, but we should
Expand Down
23 changes: 23 additions & 0 deletions widget/PuppetWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,29 @@ PuppetWidget::Resize(double aWidth,
return NS_OK;
}

nsresult
PuppetWidget::ConfigureChildren(const nsTArray<Configuration>& aConfigurations)
{
for (uint32_t i = 0; i < aConfigurations.Length(); ++i) {
const Configuration& configuration = aConfigurations[i];
PuppetWidget* w = static_cast<PuppetWidget*>(configuration.mChild);
NS_ASSERTION(w->GetParent() == this,
"Configured widget is not a child");
w->SetWindowClipRegion(configuration.mClipRegion, true);
nsIntRect bounds;
w->GetBounds(bounds);
if (bounds.Size() != configuration.mBounds.Size()) {
w->Resize(configuration.mBounds.x, configuration.mBounds.y,
configuration.mBounds.width, configuration.mBounds.height,
true);
} else if (bounds.TopLeft() != configuration.mBounds.TopLeft()) {
w->Move(configuration.mBounds.x, configuration.mBounds.y);
}
w->SetWindowClipRegion(configuration.mClipRegion, false);
}
return NS_OK;
}

NS_IMETHODIMP
PuppetWidget::SetFocus(bool aRaise)
{
Expand Down
14 changes: 7 additions & 7 deletions widget/PuppetWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ namespace widget {

struct AutoCacheNativeKeyCommands;

class PuppetWidget MOZ_FINAL : public nsBaseWidget,
public nsSupportsWeakReference
class PuppetWidget : public nsBaseWidget,
public nsSupportsWeakReference
{
typedef mozilla::dom::TabChild TabChild;
typedef mozilla::gfx::DrawTarget DrawTarget;
Expand Down Expand Up @@ -106,9 +106,7 @@ class PuppetWidget MOZ_FINAL : public nsBaseWidget,

NS_IMETHOD SetFocus(bool aRaise = false);

// PuppetWidgets don't care about children.
virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations)
{ return NS_OK; }
virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations);

NS_IMETHOD Invalidate(const nsIntRect& aRect);

Expand Down Expand Up @@ -195,6 +193,10 @@ class PuppetWidget MOZ_FINAL : public nsBaseWidget,
mDefaultScale = -1;
}

protected:
bool mEnabled;
bool mVisible;

private:
nsresult Paint();

Expand Down Expand Up @@ -228,8 +230,6 @@ class PuppetWidget MOZ_FINAL : public nsBaseWidget,
nsRefPtr<PuppetWidget> mChild;
nsIntRegion mDirtyRegion;
nsRevocableEventPtr<PaintTask> mPaintTask;
bool mEnabled;
bool mVisible;
// XXX/cjones: keeping this around until we teach LayerManager to do
// retained-content-only transactions
mozilla::RefPtr<DrawTarget> mDrawTarget;
Expand Down
21 changes: 15 additions & 6 deletions widget/gtk/nsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3626,6 +3626,8 @@ nsWindow::Create(nsIWidget *aParent,
}
break;
case eWindowType_plugin:
case eWindowType_plugin_ipc_chrome:
case eWindowType_plugin_ipc_content:
case eWindowType_child: {
if (parentMozContainer) {
mGdkWindow = CreateGdkWindow(parentGdkWindow, parentMozContainer);
Expand Down Expand Up @@ -4085,6 +4087,13 @@ nsWindow::GetTransparencyMode()
nsresult
nsWindow::ConfigureChildren(const nsTArray<Configuration>& aConfigurations)
{
// If this is a remotely updated widget we receive clipping, position, and
// size information from a source other than our owner. Don't let our parent
// update this information.
if (mWindowType == eWindowType_plugin_ipc_chrome) {
return NS_OK;
}

for (uint32_t i = 0; i < aConfigurations.Length(); ++i) {
const Configuration& configuration = aConfigurations[i];
nsWindow* w = static_cast<nsWindow*>(configuration.mChild);
Expand Down Expand Up @@ -4152,7 +4161,7 @@ GetIntRects(pixman_region32& aRegion, nsTArray<nsIntRect>* aRects)
}
}

void
nsresult
nsWindow::SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,
bool aIntersectWithExisting)
{
Expand All @@ -4176,7 +4185,7 @@ nsWindow::SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,
// need to set the clip even if it is equal.
if (mClipRects &&
pixman_region32_equal(&intersectRegion, &existingRegion)) {
return;
return NS_OK;
}

if (!pixman_region32_equal(&intersectRegion, &newRegion)) {
Expand All @@ -4186,10 +4195,10 @@ nsWindow::SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,
}

if (!StoreWindowClipRegion(*newRects))
return;
return NS_OK;

if (!mGdkWindow)
return;
return NS_OK;

#if (MOZ_WIDGET_GTK == 2)
GdkRegion *region = gdk_region_new(); // aborts on OOM
Expand All @@ -4212,8 +4221,8 @@ nsWindow::SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,
gdk_window_shape_combine_region(mGdkWindow, region, 0, 0);
cairo_region_destroy(region);
#endif
return;

return NS_OK;
}

void
Expand Down
5 changes: 2 additions & 3 deletions widget/gtk/nsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ class nsWindow : public nsBaseWidget, public nsSupportsWeakReference
NS_IMETHOD CaptureRollupEvents(nsIRollupListener *aListener,
bool aDoCapture);
NS_IMETHOD GetAttention(int32_t aCycleCount);

virtual nsresult SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,
bool aIntersectWithExisting) MOZ_OVERRIDE;
virtual bool HasPendingInputEvent();

NS_IMETHOD MakeFullScreen(bool aFullScreen);
Expand Down Expand Up @@ -340,8 +341,6 @@ class nsWindow : public nsBaseWidget, public nsSupportsWeakReference
GdkEventButton* aGdkEvent);
bool DispatchCommandEvent(nsIAtom* aCommand);
bool DispatchContentCommandEvent(int32_t aMsg);
void SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,
bool aIntersectWithExisting);
bool CheckForRollup(gdouble aMouseX, gdouble aMouseY,
bool aIsWheel, bool aAlwaysRollup);
bool GetDragInfo(mozilla::WidgetMouseEvent* aMouseEvent,
Expand Down
3 changes: 3 additions & 0 deletions widget/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ EXPORTS += [
'GfxInfoBase.h',
'GfxInfoCollector.h',
'InputData.h',
'nsBaseScreen.h',
'nsBaseWidget.h',
'nsIDeviceContextSpec.h',
'nsIPluginWidget.h',
'nsIRollupListener.h',
Expand All @@ -105,6 +107,7 @@ EXPORTS += [
'nsPrintOptionsImpl.h',
'nsWidgetInitData.h',
'nsWidgetsCID.h',
'PuppetWidget.h',
]

EXPORTS.mozilla += [
Expand Down
53 changes: 53 additions & 0 deletions widget/nsBaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,59 @@ nsBaseWidget::GetWindowClipRegion(nsTArray<nsIntRect>* aRects)
}
}

const nsIntRegion
nsBaseWidget::RegionFromArray(const nsTArray<nsIntRect>& aRects)
{
nsIntRegion region;
for (uint32_t i = 0; i < aRects.Length(); ++i) {
region.Or(region, aRects[i]);
}
return region;
}

void
nsBaseWidget::ArrayFromRegion(const nsIntRegion& aRegion, nsTArray<nsIntRect>& aRects)
{
const nsIntRect* r;
for (nsIntRegionRectIterator iter(aRegion); (r = iter.Next());) {
aRects.AppendElement(*r);
}
}

nsresult
nsBaseWidget::SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,
bool aIntersectWithExisting)
{
if (!aIntersectWithExisting) {
nsBaseWidget::StoreWindowClipRegion(aRects);
} else {
// In this case still early return if nothing changed.
if (mClipRects && mClipRectCount == aRects.Length() &&
memcmp(mClipRects,
aRects.Elements(),
sizeof(nsIntRect)*mClipRectCount) == 0) {
return NS_OK;
}

// get current rects
nsTArray<nsIntRect> currentRects;
GetWindowClipRegion(&currentRects);
// create region from them
nsIntRegion currentRegion = RegionFromArray(currentRects);
// create region from new rects
nsIntRegion newRegion = RegionFromArray(aRects);
// intersect regions
nsIntRegion intersection;
intersection.And(currentRegion, newRegion);
// create int rect array from intersection
nsTArray<nsIntRect> rects;
ArrayFromRegion(intersection, rects);
// store
nsBaseWidget::StoreWindowClipRegion(rects);
}
return NS_OK;
}

//-------------------------------------------------------------------------
//
// Set window shadow style
Expand Down
4 changes: 4 additions & 0 deletions widget/nsBaseWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ class nsBaseWidget : public nsIWidget
NS_IMETHOD SetModal(bool aModal);
virtual uint32_t GetMaxTouchPoints() const;
NS_IMETHOD SetWindowClass(const nsAString& xulWinType);
virtual nsresult SetWindowClipRegion(const nsTArray<nsIntRect>& aRects, bool aIntersectWithExisting);
// Return whether this widget interprets parameters to Move and Resize APIs
// as "global display pixels" rather than "device pixels", and therefore
// applies its GetDefaultScale() value to them before using them as mBounds
Expand Down Expand Up @@ -299,6 +300,9 @@ class nsBaseWidget : public nsIWidget
nsDeviceContext *aContext,
nsWidgetInitData *aInitData);

const nsIntRegion RegionFromArray(const nsTArray<nsIntRect>& aRects);
void ArrayFromRegion(const nsIntRegion& aRegion, nsTArray<nsIntRect>& aRects);

virtual nsIContent* GetLastRollup()
{
return mLastRollup;
Expand Down
15 changes: 13 additions & 2 deletions widget/nsIWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ typedef void* nsNativeWidget;
#endif

#define NS_IWIDGET_IID \
{ 0xcfe7543b, 0x8c0e, 0x40c3, \
{ 0x9a, 0x6d, 0x77, 0x6e, 0x84, 0x8a, 0x7c, 0xfc } };
{ 0x13239ca, 0xaf3f, 0x4f27, \
{ 0xaf, 0x83, 0x47, 0xa9, 0x82, 0x3d, 0x99, 0xee } };

/*
* Window shadow styles
Expand Down Expand Up @@ -1273,6 +1273,15 @@ class nsIWidget : public nsISupports {
*/
nsWindowType WindowType() { return mWindowType; }

/**
* Determines if this widget is one of the three types of plugin widgets.
*/
bool IsPlugin() {
return mWindowType == eWindowType_plugin ||
mWindowType == eWindowType_plugin_ipc_chrome ||
mWindowType == eWindowType_plugin_ipc_content;
}

/**
* Set the transparency mode of the top-level window containing this widget.
* So, e.g., if you call this on the widget for an IFRAME, the top level
Expand Down Expand Up @@ -1325,6 +1334,8 @@ class nsIWidget : public nsISupports {
* moved in that order.
*/
virtual nsresult ConfigureChildren(const nsTArray<Configuration>& aConfigurations) = 0;
virtual nsresult SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,
bool aIntersectWithExisting) = 0;

/**
* Appends to aRects the rectangles constituting this widget's clip
Expand Down
20 changes: 11 additions & 9 deletions widget/nsWidgetInitData.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
* these.
*/
enum nsWindowType {
eWindowType_toplevel, // default top level window
eWindowType_dialog, // top level window but usually handled differently
// by the OS
eWindowType_popup, // used for combo boxes, etc
eWindowType_child, // child windows (contained inside a window on the
// desktop (has no border))
eWindowType_invisible, // windows that are invisible or offscreen
eWindowType_plugin, // plugin window
eWindowType_sheet // MacOSX sheet (special dialog class)
eWindowType_toplevel, // default top level window
eWindowType_dialog, // top level window but usually handled differently
// by the OS
eWindowType_popup, // used for combo boxes, etc
eWindowType_child, // child windows (contained inside a window on the
// desktop (has no border))
eWindowType_invisible, // windows that are invisible or offscreen
eWindowType_plugin, // plugin window
eWindowType_plugin_ipc_chrome, // chrome side native widget for plugins (e10s)
eWindowType_plugin_ipc_content, // content side puppet widget for plugins (e10s)
eWindowType_sheet, // MacOSX sheet (special dialog class)
};

/**
Expand Down
6 changes: 3 additions & 3 deletions widget/windows/WinMouseScrollHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ MouseScrollHandler::ProcessNativeMouseWheelMessage(nsWindowBase* aWidget,
// message on its parent window. However, note that the DOM event may
// cause accessing the plugin. Therefore, we should unlock the plugin
// process by using PostMessage().
if (destWindow->WindowType() == eWindowType_plugin) {
if (destWindow->IsPlugin()) {
destWindow = destWindow->GetParentWindowBase(false);
if (!destWindow) {
PR_LOG(gMouseScrollLog, PR_LOG_ALWAYS,
Expand Down Expand Up @@ -501,7 +501,7 @@ MouseScrollHandler::ProcessNativeMouseWheelMessage(nsWindowBase* aWidget,
// it on parent window. However, note that the DOM event may cause accessing
// the plugin. Therefore, we should unlock the plugin process by using
// PostMessage().
if (aWidget->WindowType() == eWindowType_plugin &&
if (aWidget->IsPlugin() &&
aWidget->GetWindowHandle() == pluginWnd) {
nsWindowBase* destWindow = aWidget->GetParentWindowBase(false);
if (!destWindow) {
Expand Down Expand Up @@ -1532,7 +1532,7 @@ MouseScrollHandler::SynthesizingEvent::NativeMessageReceived(nsWindowBase* aWidg
}
// If the target window is not ours and received window is our plugin
// window, it comes from child window of the plugin.
if (aWidget && aWidget->WindowType() == eWindowType_plugin &&
if (aWidget && aWidget->IsPlugin() &&
!WinUtils::GetNSWindowBasePtr(mWnd)) {
return;
}
Expand Down
Loading

0 comments on commit a323270

Please sign in to comment.