2010-08-20 16:24:40 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
* vim: sw=2 ts=8 et :
|
|
|
|
*/
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at:
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* The Mozilla Foundation
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Chris Jones <jones.chris.g@gmail.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2010-09-23 20:28:15 -07:00
|
|
|
#include "mozilla/dom/PBrowserChild.h"
|
2010-08-20 16:24:40 -07:00
|
|
|
#include "BasicLayers.h"
|
2011-08-09 12:38:27 -07:00
|
|
|
#if defined(MOZ_ENABLE_D3D10_LAYER)
|
|
|
|
# include "LayerManagerD3D10.h"
|
|
|
|
#endif
|
2010-08-20 16:24:40 -07:00
|
|
|
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "PuppetWidget.h"
|
|
|
|
|
|
|
|
using namespace mozilla::layers;
|
|
|
|
using namespace mozilla::widget;
|
2010-09-23 20:28:15 -07:00
|
|
|
using namespace mozilla::dom;
|
2010-08-20 16:24:40 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
InvalidateRegion(nsIWidget* aWidget, const nsIntRegion& aRegion)
|
|
|
|
{
|
|
|
|
nsIntRegionRectIterator it(aRegion);
|
|
|
|
while(const nsIntRect* r = it.Next()) {
|
2011-12-23 19:52:21 -08:00
|
|
|
aWidget->Invalidate(*r);
|
2010-08-20 16:24:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ already_AddRefed<nsIWidget>
|
2010-09-23 20:28:15 -07:00
|
|
|
nsIWidget::CreatePuppetWidget(PBrowserChild *aTabChild)
|
2010-08-20 16:24:40 -07:00
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(nsIWidget::UsePuppetWidgets(),
|
|
|
|
"PuppetWidgets not allowed in this configuration");
|
|
|
|
|
2010-09-23 20:28:15 -07:00
|
|
|
nsCOMPtr<nsIWidget> widget = new PuppetWidget(aTabChild);
|
2010-08-20 16:24:40 -07:00
|
|
|
return widget.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
2011-02-23 09:45:09 -08:00
|
|
|
static bool
|
|
|
|
IsPopup(const nsWidgetInitData* aInitData)
|
|
|
|
{
|
|
|
|
return aInitData && aInitData->mWindowType == eWindowType_popup;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
MightNeedIMEFocus(const nsWidgetInitData* aInitData)
|
|
|
|
{
|
|
|
|
// In the puppet-widget world, popup widgets are just dummies and
|
|
|
|
// shouldn't try to mess with IME state.
|
|
|
|
return !IsPopup(aInitData);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-20 16:24:40 -07:00
|
|
|
// Arbitrary, fungible.
|
|
|
|
const size_t PuppetWidget::kMaxDimension = 4000;
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(PuppetWidget, nsBaseWidget,
|
|
|
|
nsISupportsWeakReference)
|
|
|
|
|
2010-09-23 20:28:15 -07:00
|
|
|
PuppetWidget::PuppetWidget(PBrowserChild *aTabChild)
|
|
|
|
: mTabChild(aTabChild)
|
2010-12-02 17:24:04 -08:00
|
|
|
, mDPI(-1)
|
2010-08-20 16:24:40 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(PuppetWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
PuppetWidget::~PuppetWidget()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(PuppetWidget);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetWidget::Create(nsIWidget *aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext *aContext,
|
2010-08-20 16:24:40 -07:00
|
|
|
nsWidgetInitData *aInitData)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!aNativeParent, "got a non-Puppet native parent");
|
|
|
|
|
2011-10-25 08:05:32 -07:00
|
|
|
BaseCreate(nsnull, aRect, aHandleEventFunction, aContext, aInitData);
|
2010-08-20 16:24:40 -07:00
|
|
|
|
|
|
|
mBounds = aRect;
|
2011-10-17 07:59:28 -07:00
|
|
|
mEnabled = true;
|
|
|
|
mVisible = true;
|
2010-08-20 16:24:40 -07:00
|
|
|
|
|
|
|
mSurface = gfxPlatform::GetPlatform()
|
|
|
|
->CreateOffscreenSurface(gfxIntSize(1, 1),
|
2010-09-16 14:34:53 -07:00
|
|
|
gfxASurface::ContentFromFormat(gfxASurface::ImageFormatARGB32));
|
2010-08-20 16:24:40 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
mIMEComposing = false;
|
2011-02-23 09:45:09 -08:00
|
|
|
if (MightNeedIMEFocus(aInitData)) {
|
|
|
|
PRUint32 chromeSeqno;
|
|
|
|
mTabChild->SendNotifyIMEFocus(false, &mIMEPreference, &chromeSeqno);
|
|
|
|
mIMELastBlurSeqno = mIMELastReceivedSeqno = chromeSeqno;
|
|
|
|
}
|
2010-09-23 20:28:15 -07:00
|
|
|
|
2010-08-20 16:24:40 -07:00
|
|
|
PuppetWidget* parent = static_cast<PuppetWidget*>(aParent);
|
|
|
|
if (parent) {
|
|
|
|
parent->SetChild(this);
|
2010-08-20 16:24:41 -07:00
|
|
|
mLayerManager = parent->GetLayerManager();
|
2010-08-20 16:24:40 -07:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 07:59:28 -07:00
|
|
|
Resize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, false);
|
2010-08-20 16:24:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIWidget>
|
|
|
|
PuppetWidget::CreateChild(const nsIntRect &aRect,
|
|
|
|
EVENT_CALLBACK aHandleEventFunction,
|
2011-04-16 18:22:44 -07:00
|
|
|
nsDeviceContext *aContext,
|
2010-08-20 16:24:40 -07:00
|
|
|
nsWidgetInitData *aInitData,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aForceUseIWidgetParent)
|
2010-08-20 16:24:40 -07:00
|
|
|
{
|
2011-02-23 09:45:09 -08:00
|
|
|
bool isPopup = IsPopup(aInitData);
|
2010-09-23 20:28:15 -07:00
|
|
|
nsCOMPtr<nsIWidget> widget = nsIWidget::CreatePuppetWidget(mTabChild);
|
2010-08-20 16:24:40 -07:00
|
|
|
return ((widget &&
|
2010-09-09 14:52:20 -07:00
|
|
|
NS_SUCCEEDED(widget->Create(isPopup ? nsnull: this, nsnull, aRect,
|
2010-08-20 16:24:40 -07:00
|
|
|
aHandleEventFunction,
|
2011-10-25 08:05:32 -07:00
|
|
|
aContext, aInitData))) ?
|
2010-08-20 16:24:40 -07:00
|
|
|
widget.forget() : nsnull);
|
|
|
|
}
|
|
|
|
|
2010-08-20 16:24:40 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetWidget::Destroy()
|
|
|
|
{
|
2011-03-29 13:14:44 -07:00
|
|
|
Base::OnDestroy();
|
2010-08-20 16:24:40 -07:00
|
|
|
Base::Destroy();
|
|
|
|
mPaintTask.Revoke();
|
|
|
|
mChild = nsnull;
|
2010-12-06 18:05:25 -08:00
|
|
|
if (mLayerManager) {
|
|
|
|
mLayerManager->Destroy();
|
|
|
|
}
|
2010-08-20 16:24:40 -07:00
|
|
|
mLayerManager = nsnull;
|
2010-09-23 20:28:15 -07:00
|
|
|
mTabChild = nsnull;
|
2010-08-20 16:24:40 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-20 16:24:40 -07:00
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
PuppetWidget::Show(bool aState)
|
2010-08-20 16:24:40 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(mEnabled,
|
|
|
|
"does it make sense to Show()/Hide() a disabled widget?");
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool wasVisible = mVisible;
|
2010-08-20 16:24:40 -07:00
|
|
|
mVisible = aState;
|
|
|
|
|
|
|
|
if (!wasVisible && mVisible) {
|
2011-10-17 07:59:28 -07:00
|
|
|
Resize(mBounds.width, mBounds.height, false);
|
2010-08-20 16:24:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetWidget::Resize(PRInt32 aWidth,
|
|
|
|
PRInt32 aHeight,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aRepaint)
|
2010-08-20 16:24:40 -07:00
|
|
|
{
|
|
|
|
nsIntRect oldBounds = mBounds;
|
|
|
|
mBounds.SizeTo(nsIntSize(aWidth, aHeight));
|
|
|
|
|
|
|
|
if (mChild) {
|
|
|
|
return mChild->Resize(aWidth, aHeight, aRepaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: roc says that |aRepaint| dictates whether or not to
|
|
|
|
// invalidate the expanded area
|
|
|
|
if (oldBounds.Size() < mBounds.Size() && aRepaint) {
|
|
|
|
nsIntRegion dirty(mBounds);
|
|
|
|
dirty.Sub(dirty, oldBounds);
|
|
|
|
InvalidateRegion(this, dirty);
|
|
|
|
}
|
|
|
|
|
2011-04-18 20:07:23 -07:00
|
|
|
if (!oldBounds.IsEqualEdges(mBounds)) {
|
2010-08-20 16:24:40 -07:00
|
|
|
DispatchResizeEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
PuppetWidget::SetFocus(bool aRaise)
|
2010-08-20 16:24:40 -07:00
|
|
|
{
|
|
|
|
// XXX/cjones: someone who knows about event handling needs to
|
|
|
|
// decide how this should work.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-12-23 19:52:21 -08:00
|
|
|
PuppetWidget::Invalidate(const nsIntRect& aRect)
|
2010-08-20 16:24:40 -07:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
2011-12-23 19:52:21 -08:00
|
|
|
debug_DumpInvalidate(stderr, this, &aRect,
|
2010-08-20 16:24:40 -07:00
|
|
|
nsCAutoString("PuppetWidget"), nsnull);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (mChild) {
|
2011-12-23 19:52:21 -08:00
|
|
|
return mChild->Invalidate(aRect);
|
2010-08-20 16:24:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mDirtyRegion.Or(mDirtyRegion, aRect);
|
|
|
|
|
2011-12-23 19:52:21 -08:00
|
|
|
if (!mDirtyRegion.IsEmpty() && !mPaintTask.IsPending()) {
|
2010-08-20 16:24:40 -07:00
|
|
|
mPaintTask = new PaintTask(this);
|
|
|
|
return NS_DispatchToCurrentThread(mPaintTask.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-09-23 20:28:15 -07:00
|
|
|
void
|
|
|
|
PuppetWidget::InitEvent(nsGUIEvent& event, nsIntPoint* aPoint)
|
|
|
|
{
|
|
|
|
if (nsnull == aPoint) {
|
|
|
|
event.refPoint.x = 0;
|
|
|
|
event.refPoint.y = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// use the point override if provided
|
|
|
|
event.refPoint.x = aPoint->x;
|
|
|
|
event.refPoint.y = aPoint->y;
|
|
|
|
}
|
|
|
|
event.time = PR_Now() / 1000;
|
|
|
|
}
|
|
|
|
|
2010-08-20 16:24:40 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetWidget::DispatchEvent(nsGUIEvent* event, nsEventStatus& aStatus)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
debug_DumpEvent(stdout, event->widget, event,
|
|
|
|
nsCAutoString("PuppetWidget"), nsnull);
|
|
|
|
#endif
|
|
|
|
|
2011-02-09 12:13:18 -08:00
|
|
|
NS_ABORT_IF_FALSE(!mChild || mChild->mWindowType == eWindowType_popup,
|
|
|
|
"Unexpected event dispatch!");
|
|
|
|
|
2010-08-20 16:24:40 -07:00
|
|
|
aStatus = nsEventStatus_eIgnore;
|
2011-02-09 12:13:18 -08:00
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(mViewCallback, "No view callback!");
|
|
|
|
|
|
|
|
if (event->message == NS_COMPOSITION_START) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mIMEComposing = true;
|
2011-02-09 12:13:18 -08:00
|
|
|
}
|
|
|
|
switch (event->eventStructType) {
|
|
|
|
case NS_COMPOSITION_EVENT:
|
|
|
|
mIMELastReceivedSeqno = static_cast<nsCompositionEvent*>(event)->seqno;
|
|
|
|
if (mIMELastReceivedSeqno < mIMELastBlurSeqno)
|
|
|
|
return NS_OK;
|
|
|
|
break;
|
|
|
|
case NS_TEXT_EVENT:
|
|
|
|
mIMELastReceivedSeqno = static_cast<nsTextEvent*>(event)->seqno;
|
|
|
|
if (mIMELastReceivedSeqno < mIMELastBlurSeqno)
|
|
|
|
return NS_OK;
|
|
|
|
break;
|
|
|
|
case NS_SELECTION_EVENT:
|
|
|
|
mIMELastReceivedSeqno = static_cast<nsSelectionEvent*>(event)->seqno;
|
|
|
|
if (mIMELastReceivedSeqno < mIMELastBlurSeqno)
|
|
|
|
return NS_OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aStatus = (*mViewCallback)(event);
|
|
|
|
|
|
|
|
if (event->message == NS_COMPOSITION_END) {
|
2011-10-17 07:59:28 -07:00
|
|
|
mIMEComposing = false;
|
2010-08-20 16:24:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
LayerManager*
|
2011-08-09 12:38:26 -07:00
|
|
|
PuppetWidget::GetLayerManager(PLayersChild* aShadowManager,
|
|
|
|
LayersBackend aBackendHint,
|
|
|
|
LayerManagerPersistence aPersistence,
|
|
|
|
bool* aAllowRetaining)
|
2010-08-20 16:24:40 -07:00
|
|
|
{
|
|
|
|
if (!mLayerManager) {
|
2011-08-09 12:38:27 -07:00
|
|
|
// The backend hint is a temporary placeholder until Azure, when
|
|
|
|
// all content-process layer managers will be BasicLayerManagers.
|
|
|
|
#if defined(MOZ_ENABLE_D3D10_LAYER)
|
|
|
|
if (LayerManager::LAYERS_D3D10 == aBackendHint) {
|
|
|
|
nsRefPtr<LayerManagerD3D10> m = new LayerManagerD3D10(this);
|
|
|
|
m->AsShadowForwarder()->SetShadowManager(aShadowManager);
|
|
|
|
if (m->Initialize()) {
|
|
|
|
mLayerManager = m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (!mLayerManager) {
|
|
|
|
mLayerManager = new BasicShadowLayerManager(this);
|
|
|
|
mLayerManager->AsShadowForwarder()->SetShadowManager(aShadowManager);
|
|
|
|
}
|
2010-08-20 16:24:40 -07:00
|
|
|
}
|
2010-10-15 03:34:29 -07:00
|
|
|
if (aAllowRetaining) {
|
|
|
|
*aAllowRetaining = true;
|
|
|
|
}
|
2010-08-20 16:24:40 -07:00
|
|
|
return mLayerManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxASurface*
|
|
|
|
PuppetWidget::GetThebesSurface()
|
|
|
|
{
|
|
|
|
return mSurface;
|
|
|
|
}
|
|
|
|
|
2010-09-23 20:28:15 -07:00
|
|
|
nsresult
|
2011-09-28 23:19:26 -07:00
|
|
|
PuppetWidget::IMEEndComposition(bool aCancel)
|
2010-09-23 20:28:15 -07:00
|
|
|
{
|
|
|
|
nsEventStatus status;
|
2011-10-17 07:59:28 -07:00
|
|
|
nsTextEvent textEvent(true, NS_TEXT_TEXT, this);
|
2010-09-23 20:28:15 -07:00
|
|
|
InitEvent(textEvent, nsnull);
|
2011-02-23 08:21:07 -08:00
|
|
|
textEvent.seqno = mIMELastReceivedSeqno;
|
2010-12-15 11:22:15 -08:00
|
|
|
// SendEndIMEComposition is always called since ResetInputState
|
|
|
|
// should always be called even if we aren't composing something.
|
2010-09-23 20:28:15 -07:00
|
|
|
if (!mTabChild ||
|
|
|
|
!mTabChild->SendEndIMEComposition(aCancel, &textEvent.theText)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2010-12-15 11:22:15 -08:00
|
|
|
|
|
|
|
if (!mIMEComposing)
|
|
|
|
return NS_OK;
|
|
|
|
|
2010-09-23 20:28:15 -07:00
|
|
|
DispatchEvent(&textEvent, status);
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsCompositionEvent compEvent(true, NS_COMPOSITION_END, this);
|
2010-09-23 20:28:15 -07:00
|
|
|
InitEvent(compEvent, nsnull);
|
2011-02-23 08:21:07 -08:00
|
|
|
compEvent.seqno = mIMELastReceivedSeqno;
|
2010-09-23 20:28:15 -07:00
|
|
|
DispatchEvent(&compEvent, status);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetWidget::ResetInputState()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return IMEEndComposition(false);
|
2010-09-23 20:28:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetWidget::CancelComposition()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return IMEEndComposition(true);
|
2010-09-23 20:28:15 -07:00
|
|
|
}
|
|
|
|
|
2011-11-27 03:51:52 -08:00
|
|
|
NS_IMETHODIMP_(void)
|
|
|
|
PuppetWidget::SetInputContext(const InputContext& aContext,
|
|
|
|
const InputContextAction& aAction)
|
2010-09-23 20:28:15 -07:00
|
|
|
{
|
2011-11-27 03:51:52 -08:00
|
|
|
if (!mTabChild) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-27 03:51:53 -08:00
|
|
|
mTabChild->SendSetInputContext(
|
|
|
|
static_cast<PRInt32>(aContext.mIMEState.mEnabled),
|
|
|
|
static_cast<PRInt32>(aContext.mIMEState.mOpen),
|
|
|
|
aContext.mHTMLInputType,
|
|
|
|
aContext.mActionHint,
|
|
|
|
static_cast<PRInt32>(aAction.mCause),
|
|
|
|
static_cast<PRInt32>(aAction.mFocusChange));
|
2010-09-23 20:28:15 -07:00
|
|
|
}
|
|
|
|
|
2011-11-27 03:51:52 -08:00
|
|
|
NS_IMETHODIMP_(InputContext)
|
|
|
|
PuppetWidget::GetInputContext()
|
2010-09-23 20:28:15 -07:00
|
|
|
{
|
2011-11-27 03:51:52 -08:00
|
|
|
InputContext context;
|
|
|
|
if (mTabChild) {
|
2011-11-27 03:51:53 -08:00
|
|
|
PRInt32 enabled, open;
|
|
|
|
mTabChild->SendGetInputContext(&enabled, &open);
|
|
|
|
context.mIMEState.mEnabled = static_cast<IMEState::Enabled>(enabled);
|
|
|
|
context.mIMEState.mOpen = static_cast<IMEState::Open>(open);
|
2011-11-27 03:51:52 -08:00
|
|
|
}
|
|
|
|
return context;
|
2010-09-23 20:28:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-28 23:19:26 -07:00
|
|
|
PuppetWidget::OnIMEFocusChange(bool aFocus)
|
2010-09-23 20:28:15 -07:00
|
|
|
{
|
|
|
|
if (!mTabChild)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (aFocus) {
|
|
|
|
nsEventStatus status;
|
2011-10-17 07:59:28 -07:00
|
|
|
nsQueryContentEvent queryEvent(true, NS_QUERY_TEXT_CONTENT, this);
|
2010-09-23 20:28:15 -07:00
|
|
|
InitEvent(queryEvent, nsnull);
|
|
|
|
// Query entire content
|
|
|
|
queryEvent.InitForQueryTextContent(0, PR_UINT32_MAX);
|
|
|
|
DispatchEvent(&queryEvent, status);
|
|
|
|
|
|
|
|
if (queryEvent.mSucceeded) {
|
|
|
|
mTabChild->SendNotifyIMETextHint(queryEvent.mReply.mString);
|
|
|
|
}
|
2010-09-23 20:28:15 -07:00
|
|
|
} else {
|
|
|
|
// ResetInputState might not have been called yet
|
|
|
|
ResetInputState();
|
2010-09-23 20:28:15 -07:00
|
|
|
}
|
|
|
|
|
2010-10-01 07:17:37 -07:00
|
|
|
PRUint32 chromeSeqno;
|
2011-10-17 07:59:28 -07:00
|
|
|
mIMEPreference.mWantUpdates = false;
|
|
|
|
mIMEPreference.mWantHints = false;
|
2010-10-01 07:17:37 -07:00
|
|
|
if (!mTabChild->SendNotifyIMEFocus(aFocus, &mIMEPreference, &chromeSeqno))
|
2010-09-23 20:28:15 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (aFocus) {
|
|
|
|
if (!mIMEPreference.mWantUpdates && !mIMEPreference.mWantHints)
|
|
|
|
// call OnIMEFocusChange on blur but no other updates
|
|
|
|
return NS_SUCCESS_IME_NO_UPDATES;
|
|
|
|
OnIMESelectionChange(); // Update selection
|
2010-10-01 07:17:37 -07:00
|
|
|
} else {
|
|
|
|
mIMELastBlurSeqno = chromeSeqno;
|
2010-09-23 20:28:15 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetWidget::OnIMETextChange(PRUint32 aStart, PRUint32 aEnd, PRUint32 aNewEnd)
|
|
|
|
{
|
|
|
|
if (!mTabChild)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mIMEPreference.mWantHints) {
|
|
|
|
nsEventStatus status;
|
2011-10-17 07:59:28 -07:00
|
|
|
nsQueryContentEvent queryEvent(true, NS_QUERY_TEXT_CONTENT, this);
|
2010-09-23 20:28:15 -07:00
|
|
|
InitEvent(queryEvent, nsnull);
|
|
|
|
queryEvent.InitForQueryTextContent(0, PR_UINT32_MAX);
|
|
|
|
DispatchEvent(&queryEvent, status);
|
|
|
|
|
|
|
|
if (queryEvent.mSucceeded) {
|
|
|
|
mTabChild->SendNotifyIMETextHint(queryEvent.mReply.mString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mIMEPreference.mWantUpdates) {
|
|
|
|
mTabChild->SendNotifyIMETextChange(aStart, aEnd, aNewEnd);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetWidget::OnIMESelectionChange(void)
|
|
|
|
{
|
|
|
|
if (!mTabChild)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
if (mIMEPreference.mWantUpdates) {
|
|
|
|
nsEventStatus status;
|
2011-10-17 07:59:28 -07:00
|
|
|
nsQueryContentEvent queryEvent(true, NS_QUERY_SELECTED_TEXT, this);
|
2010-09-23 20:28:15 -07:00
|
|
|
InitEvent(queryEvent, nsnull);
|
|
|
|
DispatchEvent(&queryEvent, status);
|
|
|
|
|
|
|
|
if (queryEvent.mSucceeded) {
|
2010-10-01 07:17:37 -07:00
|
|
|
mTabChild->SendNotifyIMESelection(mIMELastReceivedSeqno,
|
|
|
|
queryEvent.GetSelectionStart(),
|
2010-09-23 20:28:15 -07:00
|
|
|
queryEvent.GetSelectionEnd());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-21 17:32:43 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetWidget::SetCursor(nsCursor aCursor)
|
|
|
|
{
|
|
|
|
if (!mTabChild ||
|
|
|
|
!mTabChild->SendSetCursor(aCursor)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-20 16:24:40 -07:00
|
|
|
nsresult
|
|
|
|
PuppetWidget::DispatchPaintEvent()
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(!mDirtyRegion.IsEmpty(), "paint event logic messed up");
|
|
|
|
|
|
|
|
nsIntRect dirtyRect = mDirtyRegion.GetBounds();
|
2011-10-17 07:59:28 -07:00
|
|
|
nsPaintEvent event(true, NS_PAINT, this);
|
2010-08-20 16:24:40 -07:00
|
|
|
event.refPoint.x = dirtyRect.x;
|
2011-12-20 22:42:00 -08:00
|
|
|
event.refPoint.y = dirtyRect.y;
|
2010-08-20 16:24:40 -07:00
|
|
|
event.region = mDirtyRegion;
|
2011-10-17 07:59:28 -07:00
|
|
|
event.willSendDidPaint = true;
|
2010-08-20 16:24:40 -07:00
|
|
|
|
|
|
|
// reset repaint tracking
|
|
|
|
mDirtyRegion.SetEmpty();
|
|
|
|
mPaintTask.Revoke();
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
debug_DumpPaintEvent(stderr, this, &event,
|
|
|
|
nsCAutoString("PuppetWidget"), nsnull);
|
|
|
|
#endif
|
|
|
|
|
2011-08-09 12:38:27 -07:00
|
|
|
if (LayerManager::LAYERS_D3D10 == mLayerManager->GetBackendType()) {
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
} else {
|
|
|
|
nsRefPtr<gfxContext> ctx = new gfxContext(mSurface);
|
|
|
|
AutoLayerManagerSetup setupLayerManager(this, ctx,
|
|
|
|
BasicLayerManager::BUFFER_NONE);
|
|
|
|
DispatchEvent(&event, status);
|
|
|
|
}
|
2010-08-20 16:24:40 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
nsPaintEvent didPaintEvent(true, NS_DID_PAINT, this);
|
2010-08-20 16:24:40 -07:00
|
|
|
DispatchEvent(&didPaintEvent, status);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PuppetWidget::DispatchResizeEvent()
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
nsSizeEvent event(true, NS_SIZE, this);
|
2010-08-20 16:24:40 -07:00
|
|
|
|
|
|
|
nsIntRect rect = mBounds; // copy in case something messes with it
|
|
|
|
event.windowSize = ▭
|
|
|
|
event.refPoint.x = rect.x;
|
|
|
|
event.refPoint.y = rect.y;
|
|
|
|
event.mWinWidth = rect.width;
|
|
|
|
event.mWinHeight = rect.height;
|
|
|
|
|
|
|
|
nsEventStatus status;
|
|
|
|
return DispatchEvent(&event, status);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PuppetWidget::SetChild(PuppetWidget* aChild)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(this != aChild, "can't parent a widget to itself");
|
|
|
|
NS_ABORT_IF_FALSE(!aChild->mChild,
|
|
|
|
"fake widget 'hierarchy' only expected to have one level");
|
|
|
|
|
|
|
|
mChild = aChild;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PuppetWidget::PaintTask::Run()
|
|
|
|
{
|
|
|
|
if (mWidget) {
|
|
|
|
mWidget->DispatchPaintEvent();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-12-02 17:24:04 -08:00
|
|
|
float
|
|
|
|
PuppetWidget::GetDPI()
|
|
|
|
{
|
|
|
|
if (mDPI < 0) {
|
|
|
|
NS_ABORT_IF_FALSE(mTabChild, "Need TabChild to get the DPI from!");
|
|
|
|
mTabChild->SendGetDPI(&mDPI);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mDPI;
|
|
|
|
}
|
|
|
|
|
2011-08-31 12:01:38 -07:00
|
|
|
void*
|
|
|
|
PuppetWidget::GetNativeData(PRUint32 aDataType)
|
|
|
|
{
|
|
|
|
switch (aDataType) {
|
|
|
|
case NS_NATIVE_SHAREABLE_WINDOW: {
|
|
|
|
NS_ABORT_IF_FALSE(mTabChild, "Need TabChild to get the nativeWindow from!");
|
|
|
|
mozilla::WindowsHandle nativeData = nsnull;
|
|
|
|
mTabChild->SendGetWidgetNativeData(&nativeData);
|
|
|
|
return (void*)nativeData;
|
|
|
|
}
|
|
|
|
case NS_NATIVE_WINDOW:
|
|
|
|
case NS_NATIVE_DISPLAY:
|
|
|
|
case NS_NATIVE_PLUGIN_PORT:
|
|
|
|
case NS_NATIVE_GRAPHIC:
|
|
|
|
case NS_NATIVE_SHELLWIDGET:
|
|
|
|
case NS_NATIVE_WIDGET:
|
|
|
|
NS_WARNING("nsWindow::GetNativeData not implemented for this type");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_WARNING("nsWindow::GetNativeData called with bad value");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2010-08-20 16:24:40 -07:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|